faker->numberBetween(1, 4); $type = \collect(TaskTypeEnum::cases())->random(); $amount = 0; switch ($type) { case TaskTypeEnum::web: $amount = $days * $type->price; break; case TaskTypeEnum::seo: $amount = $days * $type->price; break; case TaskTypeEnum::package: $amount = $days * (\optional(Package::query()->inRandomOrder()->first())->amount ?? $this->faker->randomFloat(null, 150, 650)); break; case TaskTypeEnum::package: $amount = $days * $this->faker->randomFloat(null, 150, 650); break; } $this->totalDays += $days; $this->total += $amount; /** @var \App\Enums\Invoices\TaskTypeEnum */ $this->tasks[] = \array_merge(Invoice::getTaskStructure(), [ 'desc' => $this->faker->words(9, true), 'days' => $days, 'type' => \collect(TaskTypeEnum::cases())->random()->value, 'amount' => $amount, 'package' => 1 ]); /** Dates */ $this->signedDateBoolean = $this->faker->boolean(25); $this->sentClientDateBoolean = $this->faker->boolean(25); $this->sentAccountingDateBoolean = $this->faker->boolean(25); } //end for } /** * Define the model's default state. * * @return array */ public function definition() { $this->customData(); return [ 'firstname' => $this->faker->firstName, 'lastname' => $this->faker->lastName, 'object' => $this->faker->words(3, true), // * constructed object 'tasks' => $this->tasks, // * constructed object result 'total' => $this->total, // * constructed object result 'total_days' => $this->totalDays, 'comment' => $this->faker->text(\rand(20, 40)), 'show_days' => $this->faker->boolean(75), 'signed_date' => $this->signedDateBoolean ? $this->faker->dateTimeBetween('-1 year', '+1 year') : null, 'sent_client_date' => $this->signedDateBoolean && $this->sentClientDateBoolean ? $this->faker->dateTimeBetween('-1 year', '+1 year') : null, 'sent_accounting_date' => $this->signedDateBoolean && $this->sentClientDateBoolean && $this->sentAccountingDateBoolean ? $this->faker->dateTimeBetween('-1 year', '+1 year') : null, 'status' => $this->signedDateBoolean && $this->sentClientDateBoolean && $this->sentAccountingDateBoolean ? InvoiceStatusEnum::archived : InvoiceStatusEnum::opened, ]; } }