fix sample data
This commit is contained in:
parent
a2aee0b031
commit
9e08909af3
@ -57,28 +57,30 @@ class Document extends AbstractFactory
|
|||||||
*/
|
*/
|
||||||
public function invoice(): Factory
|
public function invoice(): Factory
|
||||||
{
|
{
|
||||||
$contacts = Contact::customer()->enabled()->get();
|
return $this->state(function (array $attributes): array {
|
||||||
|
$contacts = Contact::customer()->enabled()->get();
|
||||||
|
|
||||||
if ($contacts->count()) {
|
if ($contacts->count()) {
|
||||||
$contact = $contacts->random(1)->first();
|
$contact = $contacts->random(1)->first();
|
||||||
} else {
|
} else {
|
||||||
$contact = Contact::factory()->customer()->enabled()->create();
|
$contact = Contact::factory()->customer()->enabled()->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
$statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled'];
|
$statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled'];
|
||||||
|
|
||||||
return $this->state([
|
return [
|
||||||
'type' => Model::INVOICE_TYPE,
|
'type' => Model::INVOICE_TYPE,
|
||||||
'document_number' => $this->getNextDocumentNumber(Model::INVOICE_TYPE),
|
'document_number' => $this->getDocumentNumber(Model::INVOICE_TYPE),
|
||||||
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
||||||
'contact_id' => $contact->id,
|
'contact_id' => $contact->id,
|
||||||
'contact_name' => $contact->name,
|
'contact_name' => $contact->name,
|
||||||
'contact_email' => $contact->email,
|
'contact_email' => $contact->email,
|
||||||
'contact_tax_number' => $contact->tax_number,
|
'contact_tax_number' => $contact->tax_number,
|
||||||
'contact_phone' => $contact->phone,
|
'contact_phone' => $contact->phone,
|
||||||
'contact_address' => $contact->address,
|
'contact_address' => $contact->address,
|
||||||
'status' => $this->faker->randomElement($statuses),
|
'status' => $this->faker->randomElement($statuses),
|
||||||
]);
|
];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,28 +88,30 @@ class Document extends AbstractFactory
|
|||||||
*/
|
*/
|
||||||
public function bill(): Factory
|
public function bill(): Factory
|
||||||
{
|
{
|
||||||
$contacts = Contact::vendor()->enabled()->get();
|
return $this->state(function (array $attributes): array {
|
||||||
|
$contacts = Contact::vendor()->enabled()->get();
|
||||||
|
|
||||||
if ($contacts->count()) {
|
if ($contacts->count()) {
|
||||||
$contact = $contacts->random(1)->first();
|
$contact = $contacts->random(1)->first();
|
||||||
} else {
|
} else {
|
||||||
$contact = Contact::factory()->vendor()->enabled()->create();
|
$contact = Contact::factory()->vendor()->enabled()->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
$statuses = ['draft', 'received', 'partial', 'paid', 'cancelled'];
|
$statuses = ['draft', 'received', 'partial', 'paid', 'cancelled'];
|
||||||
|
|
||||||
return $this->state([
|
return [
|
||||||
'type' => Model::BILL_TYPE,
|
'type' => Model::BILL_TYPE,
|
||||||
'document_number' => $this->getNextDocumentNumber(Model::BILL_TYPE),
|
'document_number' => $this->getDocumentNumber(Model::BILL_TYPE),
|
||||||
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
||||||
'contact_id' => $contact->id,
|
'contact_id' => $contact->id,
|
||||||
'contact_name' => $contact->name,
|
'contact_name' => $contact->name,
|
||||||
'contact_email' => $contact->email,
|
'contact_email' => $contact->email,
|
||||||
'contact_tax_number' => $contact->tax_number,
|
'contact_tax_number' => $contact->tax_number,
|
||||||
'contact_phone' => $contact->phone,
|
'contact_phone' => $contact->phone,
|
||||||
'contact_address' => $contact->address,
|
'contact_address' => $contact->address,
|
||||||
'status' => $this->faker->randomElement($statuses),
|
'status' => $this->faker->randomElement($statuses),
|
||||||
]);
|
];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,7 +209,7 @@ class Document extends AbstractFactory
|
|||||||
|
|
||||||
return $this->state([
|
return $this->state([
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'document_number' => $this->getNextDocumentNumber($type),
|
'document_number' => $this->getDocumentNumber($type),
|
||||||
'recurring_started_at' => $this->getRawAttribute('issued_at'),
|
'recurring_started_at' => $this->getRawAttribute('issued_at'),
|
||||||
'recurring_frequency' => 'daily',
|
'recurring_frequency' => 'daily',
|
||||||
'recurring_interval' => '1',
|
'recurring_interval' => '1',
|
||||||
@ -257,6 +261,19 @@ class Document extends AbstractFactory
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get document number
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getDocumentNumber($type)
|
||||||
|
{
|
||||||
|
$document_number = $this->getNextDocumentNumber($type);
|
||||||
|
|
||||||
|
$this->increaseNextDocumentNumber($type);
|
||||||
|
|
||||||
|
return $document_number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the model factory.
|
* Configure the model factory.
|
||||||
*
|
*
|
||||||
|
@ -40,7 +40,7 @@ class Transaction extends Factory
|
|||||||
return [
|
return [
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $this->company->id,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'number' => $this->getNextTransactionNumber(),
|
'number' => $this->getNumber(),
|
||||||
'account_id' => setting('default.account'),
|
'account_id' => setting('default.account'),
|
||||||
'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'),
|
'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'),
|
||||||
'amount' => $this->faker->randomFloat(2, 1, 1000),
|
'amount' => $this->faker->randomFloat(2, 1, 1000),
|
||||||
@ -89,7 +89,7 @@ class Transaction extends Factory
|
|||||||
{
|
{
|
||||||
return $this->state([
|
return $this->state([
|
||||||
'type' => $this->getRawAttribute('type') . '-recurring',
|
'type' => $this->getRawAttribute('type') . '-recurring',
|
||||||
'number' => $this->getNextTransactionNumber('-recurring'),
|
'number' => $this->getNumber('-recurring'),
|
||||||
'recurring_started_at' => $this->getRawAttribute('paid_at'),
|
'recurring_started_at' => $this->getRawAttribute('paid_at'),
|
||||||
'recurring_frequency' => 'daily',
|
'recurring_frequency' => 'daily',
|
||||||
'recurring_custom_frequency' => 'daily',
|
'recurring_custom_frequency' => 'daily',
|
||||||
@ -101,4 +101,17 @@ class Transaction extends Factory
|
|||||||
'real_type' => $this->getRawAttribute('type'),
|
'real_type' => $this->getRawAttribute('type'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get transaction number
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getNumber($suffix = '')
|
||||||
|
{
|
||||||
|
$number = $this->getNextTransactionNumber($suffix);
|
||||||
|
|
||||||
|
$this->increaseNextTransactionNumber($suffix);
|
||||||
|
|
||||||
|
return $number;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user