feat: implement currency rates tracking with models, migrations and views
هذا الالتزام موجود في:
40
database/factories/CityFactory.php
Normal file
40
database/factories/CityFactory.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\City;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\City>
|
||||
*/
|
||||
class CityFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->randomElement(City::supportedCities()),
|
||||
];
|
||||
}
|
||||
|
||||
public function sanaa()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => City::SANAA,
|
||||
'label' => 'صنعاء',
|
||||
]);
|
||||
}
|
||||
|
||||
public function aden()
|
||||
{
|
||||
return $this->state([
|
||||
'name' => City::ADEN,
|
||||
'label' => 'عدن',
|
||||
]);
|
||||
}
|
||||
}
|
||||
56
database/factories/CurrencyFactory.php
Normal file
56
database/factories/CurrencyFactory.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Currency;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Currency>
|
||||
*/
|
||||
class CurrencyFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$code = fake()->randomElement(Currency::supportedCurrencies());
|
||||
|
||||
$name = match ($code) {
|
||||
Currency::USD => 'دولار أمريكي',
|
||||
Currency::SAR => 'ريال سعودي',
|
||||
};
|
||||
|
||||
$symbol = match ($code) {
|
||||
Currency::USD => '$',
|
||||
Currency::SAR => '﷼',
|
||||
};
|
||||
|
||||
return [
|
||||
'code' => $code,
|
||||
'name' => $name,
|
||||
'symbol' => $symbol,
|
||||
];
|
||||
}
|
||||
|
||||
public function saudiRial()
|
||||
{
|
||||
return $this->state([
|
||||
'code' => Currency::SAR,
|
||||
'name' => 'ريال سعودي',
|
||||
'symbol' => '﷼',
|
||||
]);
|
||||
}
|
||||
|
||||
public function usdDollar()
|
||||
{
|
||||
return $this->state([
|
||||
'code' => Currency::USD,
|
||||
'name' => 'دولار أمريكي',
|
||||
'symbol' => '$',
|
||||
]);
|
||||
}
|
||||
}
|
||||
63
database/factories/RateFactory.php
Normal file
63
database/factories/RateFactory.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\Currency;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Rate>
|
||||
*/
|
||||
class RateFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'currency_id' => Currency::factory(),
|
||||
'city_id' => City::factory(),
|
||||
|
||||
'buy_price' => fn ($attributes) => $attributes['currency_id'] == Currency::SAR
|
||||
? fake()->randomFloat(2, 1, 300)
|
||||
: fake()->randomFloat(2, 500, 1000),
|
||||
'sell_price' => fn ($attributes) => $attributes['currency_id'] == Currency::SAR
|
||||
? fake()->randomFloat(2, 1, 300)
|
||||
: fake()->randomFloat(2, 500, 1000),
|
||||
|
||||
'date' => fake()->dateTimeBetween('-20 days', 'today'),
|
||||
];
|
||||
}
|
||||
|
||||
public function withDate($date)
|
||||
{
|
||||
return $this->state([
|
||||
'date' => $date,
|
||||
]);
|
||||
}
|
||||
|
||||
public function today()
|
||||
{
|
||||
return $this->state([
|
||||
'date' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function yesterday()
|
||||
{
|
||||
return $this->state([
|
||||
'date' => now()->subDay(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function last20Days()
|
||||
{
|
||||
return $this->state([
|
||||
'date' => fake()->unique()->dateTimeBetween('-20 days', 'yesterday'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم