Files
InvoiceShelf/database/factories/EstimateItemFactory.php
T
Darko Gjorgjijoski 5ef7804e60 refactor: adopt modular domain architecture (#747)
* refactor: stabilize model identities for domain migration

* refactor: extract module platform context

* refactor: assign models to domain contexts

* refactor: extract ai platform context

* refactor: extract storage platform context

* refactor: extract mail platform context

* refactor: extract pdf platform context

* refactor: extract operations platform context

* refactor: move installation into operations platform

* refactor: extract money domain context

* refactor: extract taxation domain context

* refactor: extract catalog domain context

* refactor: extract metadata domain context

* refactor: extract reporting domain context

* refactor: extract purchases domain context

* refactor: extract receivables domain context

* refactor: extract accounts domain context

* refactor: complete reporting statement boundary

* refactor: extract contacts domain context

* refactor: extract sales domain context

* refactor: remove legacy application layers

* fix: migrate legacy bouncer role identities
2026-08-05 17:40:03 +02:00

58 lines
2.2 KiB
PHP

<?php
namespace Database\Factories;
use App\Domains\Accounts\Models\User;
use App\Domains\Catalog\Models\Item;
use App\Domains\Sales\Models\Estimate;
use App\Domains\Sales\Models\EstimateItem;
use Illuminate\Database\Eloquent\Factories\Factory;
class EstimateItemFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = EstimateItem::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'item_id' => Item::factory(),
'name' => function (array $item) {
return Item::find($item['item_id'])->name;
},
'description' => function (array $item) {
return Item::find($item['item_id'])->description;
},
'price' => function (array $item) {
return Item::find($item['item_id'])->price;
},
'estimate_id' => Estimate::factory(),
'quantity' => $this->faker->randomDigitNotNull(),
'company_id' => User::find(1)->companies()->first()->id,
'tax' => $this->faker->randomDigitNotNull(),
'total' => function (array $item) {
return $item['price'] * $item['quantity'];
},
'discount_type' => $this->faker->randomElement(['percentage', 'fixed']),
'discount_val' => function (array $estimate) {
return $estimate['discount_type'] == 'percentage' ? $this->faker->numberBetween($min = 0, $max = 100) : $this->faker->randomDigitNotNull();
},
'discount' => function (array $estimate) {
return $estimate['discount_type'] == 'percentage' ? (($estimate['discount_val'] * $estimate['total']) / 100) : $estimate['discount_val'];
},
'exchange_rate' => $this->faker->randomDigitNotNull(),
'base_discount_val' => $this->faker->randomDigitNotNull(),
'base_price' => $this->faker->randomDigitNotNull(),
'base_total' => $this->faker->randomDigitNotNull(),
'base_tax' => $this->faker->randomDigitNotNull(),
];
}
}