diff --git a/database/factories/ArticleFactory.php b/database/factories/ArticleFactory.php index 023308b..70ba13e 100644 --- a/database/factories/ArticleFactory.php +++ b/database/factories/ArticleFactory.php @@ -15,6 +15,7 @@ class ArticleFactory extends Factory public function definition(): array { $title = $this->faker->sentence(6); + $status = $this->faker->randomElement(ArticleStatus::cases()); return [ 'author_id' => User::factory(), @@ -22,19 +23,27 @@ public function definition(): array 'slug' => Str::slug($title.'-'.$this->faker->unique()->randomNumber()), 'excerpt' => $this->faker->paragraph(), 'content' => $this->faker->paragraphs(3, true), - 'status' => ArticleStatus::PUBLISHED, - 'published_at' => $this->faker->optional()->dateTimeBetween('-10 days', 'now'), + 'status' => $status, + 'published_at' => $status === ArticleStatus::PUBLISHED + ? $this->faker->dateTimeBetween('-10 days', 'now') + : null, 'views' => $this->faker->numberBetween(0, 1000), ]; } public function draft(): Factory { - return $this->state(fn () => ['status' => ArticleStatus::DRAFT, 'published_at' => null]); + return $this->state(fn () => [ + 'status' => ArticleStatus::DRAFT, + 'published_at' => null, + ]); } public function published(): Factory { - return $this->state(fn () => ['status' => ArticleStatus::PUBLISHED, 'published_at' => now()]); + return $this->state(fn () => [ + 'status' => ArticleStatus::PUBLISHED, + 'published_at' => now(), + ]); } } diff --git a/database/factories/CustomerFactory.php b/database/factories/CustomerFactory.php index 691b2cd..018a93d 100644 --- a/database/factories/CustomerFactory.php +++ b/database/factories/CustomerFactory.php @@ -14,12 +14,22 @@ public function definition(): array { return [ 'name' => $this->faker->name(), - 'phone_number' => fake()->randomElement([ - fake()->numerify('0812 #### ###'), - fake()->numerify('0812 #### ####'), - fake()->numerify('0812 #### #####'), + 'phone_number' => $this->faker->randomElement([ + $this->faker->numerify('0812 #### ###'), + $this->faker->numerify('0812 #### ####'), + $this->faker->numerify('0812 #### #####'), ]), 'gender' => $this->faker->randomElement(Gender::cases()), ]; } + + public function male(): Factory + { + return $this->state(fn () => ['gender' => Gender::MALE]); + } + + public function female(): Factory + { + return $this->state(fn () => ['gender' => Gender::FEMALE]); + } } diff --git a/database/factories/EmployeeFactory.php b/database/factories/EmployeeFactory.php index f656c04..2cf269c 100644 --- a/database/factories/EmployeeFactory.php +++ b/database/factories/EmployeeFactory.php @@ -16,25 +16,18 @@ public function definition(): array return [ 'full_name' => $this->faker->name(), 'code' => Employee::generateEmployeeCode(), - 'phone_number' => fake()->randomElement([ - fake()->numerify('0812 #### ###'), - fake()->numerify('0812 #### ####'), - fake()->numerify('0812 #### #####'), + 'phone_number' => $this->faker->randomElement([ + $this->faker->numerify('0812 #### ###'), + $this->faker->numerify('0812 #### ####'), + $this->faker->numerify('0812 #### #####'), ]), 'base_salary' => $this->faker->randomNumber(6), 'address' => $this->faker->address(), 'birthdate' => $this->faker->dateTimeBetween('-60 years', '-18 years')->format('Y-m-d'), 'hire_date' => $this->faker->date(), 'resign_date' => $this->faker->optional()->date(), - 'gender' => fake()->randomElement([ - Gender::MALE, - Gender::FEMALE, - ]), - 'status' => fake()->randomElement([ - EmploymentStatus::PERMANENT, - EmploymentStatus::CONTRACT, - EmploymentStatus::INTERN, - ]), + 'gender' => $this->faker->randomElement(Gender::cases()), + 'status' => $this->faker->randomElement(EmploymentStatus::cases()), ]; } diff --git a/database/factories/ExpenseFactory.php b/database/factories/ExpenseFactory.php index 585a678..13d088c 100644 --- a/database/factories/ExpenseFactory.php +++ b/database/factories/ExpenseFactory.php @@ -19,7 +19,7 @@ public function definition(): array 'outlet_id' => Outlet::factory(), 'amount' => $this->faker->numberBetween(10000, 200000), 'description' => $this->faker->sentence(6), - 'type' => ExpenseType::OPERATIONAL, + 'type' => $this->faker->randomElement(ExpenseType::cases()), ]; } diff --git a/database/factories/OrderFactory.php b/database/factories/OrderFactory.php index 889470e..8d269cc 100644 --- a/database/factories/OrderFactory.php +++ b/database/factories/OrderFactory.php @@ -37,8 +37,8 @@ public function definition(): array 'subtotal' => $subtotal, 'discount' => $discount, 'total' => $total, - 'channel' => fake()->randomElement(OrderChannel::cases()), - 'status' => fake()->randomElement(OrderStatus::cases()), + 'channel' => $this->faker->randomElement(OrderChannel::cases()), + 'status' => $this->faker->randomElement(OrderStatus::cases()), 'ordered_at' => $this->faker->dateTimeBetween('-1 year', 'now'), ]; } @@ -171,12 +171,18 @@ public function withoutDiscount(): Factory public function today(): Factory { - return $this->state(fn () => ['ordered_at' => now(), 'created_at' => now()]); + return $this->state(fn () => [ + 'ordered_at' => now(), + 'created_at' => now(), + ]); } public function yesterday(): Factory { - return $this->state(fn () => tap(now()->subDay(), fn ($d) => null) && ['ordered_at' => $d = now()->subDay(), 'created_at' => $d]); + return $this->state(fn () => tap(now()->subDay(), fn ($d) => null) && [ + 'ordered_at' => $d = now()->subDay(), + 'created_at' => $d, + ]); } public function thisWeek(): Factory diff --git a/database/factories/OutletFactory.php b/database/factories/OutletFactory.php index 524273a..e25466a 100644 --- a/database/factories/OutletFactory.php +++ b/database/factories/OutletFactory.php @@ -14,21 +14,16 @@ public function definition(): array { return [ 'name' => $this->faker->company(), - 'phone_number' => sprintf( - '%04d %04d %03d', - $this->faker->numberBetween(8000, 8999), - $this->faker->numberBetween(1000, 9999), - $this->faker->numberBetween(100, 999) - ), + 'phone_number' => $this->faker->randomElement([ + $this->faker->numerify('0812 #### ###'), + $this->faker->numerify('0812 #### ####'), + $this->faker->numerify('0812 #### #####'), + ]), 'address' => $this->faker->address(), 'landmark' => $this->faker->streetName(), 'maps_url' => 'https://goo.gl/maps/'.$this->faker->regexify('[A-Za-z0-9]{6,10}'), 'opened_date' => $this->faker->date(), - 'status' => fake()->randomElement([ - OutletStatus::OPERATIONAL, - OutletStatus::UNDER_CONSTRUCTION, - OutletStatus::TERMINATED, - ]), + 'status' => $this->faker->randomElement(OutletStatus::cases()), ]; } diff --git a/database/factories/PaymentFactory.php b/database/factories/PaymentFactory.php index db99226..ca231a4 100644 --- a/database/factories/PaymentFactory.php +++ b/database/factories/PaymentFactory.php @@ -18,10 +18,10 @@ public function definition(): array return [ 'order_id' => Order::factory(), 'user_id' => User::factory(), - 'method' => PaymentMethod::CASH, + 'method' => $this->faker->randomElement(PaymentMethod::cases()), 'amount' => $this->faker->numberBetween(20000, 400000), 'paid_at' => $this->faker->dateTimeBetween('-7 days', 'now'), - 'status' => PaymentStatus::PENDING, + 'status' => $this->faker->randomElement(PaymentStatus::cases()), ]; } diff --git a/database/factories/PayrollAdjustmentFactory.php b/database/factories/PayrollAdjustmentFactory.php index 058a09e..ceb0d70 100644 --- a/database/factories/PayrollAdjustmentFactory.php +++ b/database/factories/PayrollAdjustmentFactory.php @@ -15,7 +15,7 @@ public function definition(): array { return [ 'payroll_id' => Payroll::factory(), - 'type' => SalaryAdjustmentType::BONUS, + 'type' => $this->faker->randomElement(SalaryAdjustmentType::cases()), 'description' => $this->faker->sentence(4), 'amount' => $this->faker->numberBetween(50000, 500000), ]; diff --git a/database/factories/PayrollFactory.php b/database/factories/PayrollFactory.php index 79eefdc..ca8db12 100644 --- a/database/factories/PayrollFactory.php +++ b/database/factories/PayrollFactory.php @@ -17,6 +17,8 @@ public function definition(): array $bonus = $this->faker->numberBetween(0, 2000000); $deduction = $this->faker->numberBetween(0, 500000); + $isPaid = $this->faker->randomElement(IsPaid::cases()); + return [ 'user_id' => User::factory(), 'period_month' => $this->faker->date('Y-m'), @@ -24,8 +26,10 @@ public function definition(): array 'bonus' => $bonus, 'deduction' => $deduction, 'total_salary' => $base + $bonus - $deduction, - 'is_paid' => IsPaid::NOT_PAID, - 'paid_at' => null, + 'is_paid' => $isPaid, + 'paid_at' => $isPaid === IsPaid::PAID + ? $this->faker->dateTimeBetween('-3 days', 'now') + : null, ]; } @@ -36,4 +40,12 @@ public function paid(): Factory 'paid_at' => $this->faker->dateTimeBetween('-3 days', 'now'), ]); } + + public function notPaid(): Factory + { + return $this->state(fn () => [ + 'is_paid' => IsPaid::NOT_PAID, + 'paid_at' => null, + ]); + } } diff --git a/database/factories/PerfumeFactory.php b/database/factories/PerfumeFactory.php index 260e502..1eb5ff0 100644 --- a/database/factories/PerfumeFactory.php +++ b/database/factories/PerfumeFactory.php @@ -21,7 +21,7 @@ public function definition(): array 'name' => Str::title($name), 'slug' => Str::slug($name.'-'.$this->faker->unique()->randomNumber()), 'sku' => strtoupper($this->faker->unique()->bothify('PER-#####')), - 'concentration' => Concentration::EXTRAIT_DE_PERFUME, + 'concentration' => $this->faker->randomElement(Concentration::cases()), 'cost_price' => $this->faker->numberBetween(50000, 250000), 'sale_price' => $this->faker->numberBetween(80000, 400000), 'point_per_ml' => $this->faker->numberBetween(1, 30), diff --git a/database/factories/PointRecordFactory.php b/database/factories/PointRecordFactory.php index c486e69..26892d1 100644 --- a/database/factories/PointRecordFactory.php +++ b/database/factories/PointRecordFactory.php @@ -21,17 +21,17 @@ public function definition(): array 'change' => $change, 'type' => PointRecordType::REWARD, 'description' => $this->faker->sentence(4), - 'is_addition' => $isAddition, + 'is_addition' => true, ]; } public function reward(): Factory { - return $this->state(fn () => ['type' => PointRecordType::REWARD, 'is_addition' => true]); + return $this->state(fn () => ['type' => PointRecordType::REWARD]); } - public function redemption(): Factory + public function tier(): Factory { - return $this->state(fn () => ['type' => PointRecordType::REDEMPTION, 'is_addition' => false]); + return $this->state(fn () => ['type' => PointRecordType::TIER]); } } diff --git a/database/factories/PriceRequestFactory.php b/database/factories/PriceRequestFactory.php index 18ee993..bf9022c 100644 --- a/database/factories/PriceRequestFactory.php +++ b/database/factories/PriceRequestFactory.php @@ -13,26 +13,39 @@ class PriceRequestFactory extends Factory public function definition(): array { + $status = $this->faker->randomElement(PriceRequestStatus::cases()); + return [ 'user_id' => User::factory(), 'module' => $this->faker->randomElement(['product', 'perfume', 'bottle']), - 'status' => PriceRequestStatus::PENDING, - 'finalized_at' => null, + 'status' => $status, + 'finalized_at' => $status === PriceRequestStatus::PENDING + ? null + : $this->faker->dateTime(), ]; } public function pending(): Factory { - return $this->state(fn () => ['status' => PriceRequestStatus::PENDING, 'finalized_at' => null]); + return $this->state(fn () => [ + 'status' => PriceRequestStatus::PENDING, + 'finalized_at' => null, + ]); } public function approved(): Factory { - return $this->state(fn () => ['status' => PriceRequestStatus::APPROVED, 'finalized_at' => $this->faker->dateTime()]); + return $this->state(fn () => [ + 'status' => PriceRequestStatus::APPROVED, + 'finalized_at' => $this->faker->dateTime(), + ]); } public function rejected(): Factory { - return $this->state(fn () => ['status' => PriceRequestStatus::REJECTED, 'finalized_at' => $this->faker->dateTime()]); + return $this->state(fn () => [ + 'status' => PriceRequestStatus::REJECTED, + 'finalized_at' => $this->faker->dateTime(), + ]); } } diff --git a/database/factories/StockOpnameFactory.php b/database/factories/StockOpnameFactory.php index aeb6bb1..6f965c5 100644 --- a/database/factories/StockOpnameFactory.php +++ b/database/factories/StockOpnameFactory.php @@ -16,7 +16,7 @@ public function definition(): array return [ 'outlet_id' => Outlet::factory(), 'period_month' => $this->faker->date('Y-m'), - 'status' => StockOpnameStatus::DRAFT, + 'status' => $this->faker->randomElement(StockOpnameStatus::cases()), 'note' => $this->faker->optional()->sentence(8), ]; } @@ -26,8 +26,18 @@ public function draft(): Factory return $this->state(fn () => ['status' => StockOpnameStatus::DRAFT]); } - public function finalized(): Factory + public function process(): Factory { - return $this->state(fn () => ['status' => StockOpnameStatus::FINALIZED]); + return $this->state(fn () => ['status' => StockOpnameStatus::PROCESS]); + } + + public function pendingApproval(): Factory + { + return $this->state(fn () => ['status' => StockOpnameStatus::PENDING_APPROVAL]); + } + + public function completed(): Factory + { + return $this->state(fn () => ['status' => StockOpnameStatus::COMPLETED]); } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 11a1224..63d8bc2 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -15,9 +15,9 @@ public function definition(): array { return [ 'email' => $this->faker->unique()->safeEmail(), - 'username' => fake()->unique()->regexify('[A-Za-z0-9]{8}'), + 'username' => $this->faker->unique()->regexify('[A-Za-z0-9]{8}'), 'password' => Hash::make(config('myconfig.password_default')), - '', + 'status' => $this->faker->randomElement(UserStatus::cases()), ]; }