70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Offer;
|
|
use App\Models\OfferVersion;
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\OfferVersion>
|
|
*/
|
|
class OfferVersionFactory extends Factory
|
|
{
|
|
protected $model = OfferVersion::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
// `Offer::factory()` legt V1 in OfferFactory::afterCreating an — V2+ ist
|
|
// pro (offer_id, version_no) unique.
|
|
return [
|
|
'offer_id' => Offer::factory(),
|
|
'version_no' => 2,
|
|
'status' => OfferVersion::STATUS_DRAFT,
|
|
'valid_until' => null,
|
|
'total_price' => fake()->randomFloat(2, 100, 15_000),
|
|
'headline' => fake()->sentence(4),
|
|
'intro_text' => '<p>' . fake()->paragraph() . '</p>',
|
|
'itinerary_text' => null,
|
|
'closing_text' => null,
|
|
'template_id' => null,
|
|
'pdf_path' => null,
|
|
'pdf_archived' => false,
|
|
'sent_at' => null,
|
|
'accepted_at' => null,
|
|
'accepted_via' => null,
|
|
'template_document_ids' => null,
|
|
'created_by' => User::factory(),
|
|
];
|
|
}
|
|
|
|
public function forOffer(Offer $offer, int $versionNo = 2): static
|
|
{
|
|
return $this->state(function (array $a) use ($offer, $versionNo) {
|
|
return [
|
|
'offer_id' => $offer->id,
|
|
'version_no' => $versionNo,
|
|
'created_by' => $offer->created_by,
|
|
];
|
|
});
|
|
}
|
|
|
|
public function versionSent(): static
|
|
{
|
|
return $this->state([
|
|
'status' => OfferVersion::STATUS_SENT,
|
|
'sent_at' => now(),
|
|
]);
|
|
}
|
|
|
|
public function versionAccepted(): static
|
|
{
|
|
return $this->state([
|
|
'status' => OfferVersion::STATUS_ACCEPTED,
|
|
'sent_at' => now(),
|
|
'accepted_at' => now(),
|
|
'accepted_via' => OfferVersion::ACCEPTED_VIA_ADMIN,
|
|
]);
|
|
}
|
|
}
|