83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\Invoice\TaskType;
|
|
use App\Models\Invoice;
|
|
use App\Models\Package;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class InvoiceFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Invoice::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function definition()
|
|
{
|
|
\mt_srand();
|
|
$lines = \mt_rand(2, 9);
|
|
$tasks = [];
|
|
$total = 0;
|
|
$totalDays = 0;
|
|
for ($i = 0; $i < $lines; $i++) {
|
|
$days = 0.125 * $this->faker->numberBetween(1, 4);
|
|
$type = \collect(TaskType::toArray())->random();
|
|
$amount = 0;
|
|
switch ($type) {
|
|
case TaskType::web():
|
|
$amount = $days * $type->price;
|
|
break;
|
|
case TaskType::seo():
|
|
$amount = $days * $type->price;
|
|
break;
|
|
case TaskType::package():
|
|
$amount = $days * (\optional(Package::query()->inRandomOrder()->first())->amount ??
|
|
$this->faker->randomFloat(null, 150, 650));
|
|
break;
|
|
case TaskType::package():
|
|
$amount = $days * $this->faker->randomFloat(null, 150, 650);
|
|
break;
|
|
}
|
|
$totalDays += $days;
|
|
$total += $amount;
|
|
/** @var \App\Enums\Invoice\TaskType */
|
|
$taskType = \collect(TaskType::toArray())->random();
|
|
$tasks[] = \array_merge(Invoice::getTaskStructure(), [
|
|
'desc' => $this->faker->words(9, true),
|
|
'days' => $days,
|
|
'type' => $taskType->value,
|
|
'amount' => $amount,
|
|
'package' => 1
|
|
]);
|
|
} //end for
|
|
|
|
return [
|
|
'firstname' => $this->faker->firstName,
|
|
'lastname' => $this->faker->lastName,
|
|
'object' => $this->faker->words(3, true),
|
|
// * constructed object
|
|
'tasks' => $tasks,
|
|
// * constructed object result
|
|
'total' => $total,
|
|
// * constructed object result
|
|
'total_days' => $totalDays,
|
|
'comment' => $this->faker->text(\rand(20, 40)),
|
|
'show_days' => $this->faker->boolean(75),
|
|
'signed_date' => $this->faker->boolean(25) ?
|
|
$this->faker->dateTimeBetween('-1 year', '+1 year') : null,
|
|
'sent_client_date' => $this->faker->boolean(25) ?
|
|
$this->faker->dateTimeBetween('-1 year', '+1 year') : null,
|
|
'sent_accounting_date' => $this->faker->boolean(25) ?
|
|
$this->faker->dateTimeBetween('-1 year', '+1 year') : null,
|
|
];
|
|
}
|
|
}
|