44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
||
|
||
namespace Database\Factories;
|
||
|
||
use App\Models\PurchaseOrderModel;
|
||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
||
/**
|
||
* 采购单工厂(无需 Faker)
|
||
*
|
||
* @extends Factory<PurchaseOrderModel>
|
||
*/
|
||
class PurchaseOrderModelFactory extends Factory
|
||
{
|
||
protected $model = PurchaseOrderModel::class;
|
||
|
||
private static int $sequence = 0;
|
||
|
||
public function definition(): array
|
||
{
|
||
$seq = ++self::$sequence;
|
||
|
||
return [
|
||
'purchase_no' => 'PO' . str_pad((string) $seq, 12, '0', STR_PAD_LEFT),
|
||
'purchase_date' => now()->toDateString(),
|
||
'status' => PurchaseOrderModel::STATUS_PENDING,
|
||
'total_quantity' => 0,
|
||
'total_weight' => 0,
|
||
'estimate_amount' => 0,
|
||
'actual_amount' => 0,
|
||
'operator_id' => 0,
|
||
'remark' => '',
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 指定采购日期
|
||
*/
|
||
public function onDate(string $date): static
|
||
{
|
||
return $this->state(fn () => ['purchase_date' => $date]);
|
||
}
|
||
}
|