akaunting 3.0 (the last dance)

This commit is contained in:
Burak Civan
2022-06-01 10:15:55 +03:00
parent cead09f6d4
commit d9c0764572
3812 changed files with 126831 additions and 102949 deletions

View File

@ -14,12 +14,15 @@ use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Document\Document as Model;
use App\Models\Setting\Tax;
use App\Traits\Documents;
use App\Utilities\Date;
use App\Utilities\Overrider;
use Illuminate\Database\Eloquent\Factories\Factory;
class Document extends AbstractFactory
{
use Documents;
/**
* The name of the factory's corresponding model.
*
@ -35,7 +38,7 @@ class Document extends AbstractFactory
public function definition()
{
$issued_at = $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s');
$due_at = Date::parse($issued_at)->addDays($this->faker->randomNumber(3))->format('Y-m-d H:i:s');
$due_at = Date::parse($issued_at)->addDays($this->faker->randomNumber(2))->format('Y-m-d H:i:s');
return [
'company_id' => $this->company->id,
@ -54,30 +57,28 @@ class Document extends AbstractFactory
*/
public function invoice(): Factory
{
return $this->state(function (array $attributes): array {
$contacts = Contact::customer()->enabled()->get();
$contacts = Contact::customer()->enabled()->get();
if ($contacts->count()) {
$contact = $contacts->random(1)->first();
} else {
$contact = Contact::factory()->customer()->enabled()->create();
}
if ($contacts->count()) {
$contact = $contacts->random(1)->first();
} else {
$contact = Contact::factory()->customer()->enabled()->create();
}
$statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled'];
$statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled'];
return [
'type' => Model::INVOICE_TYPE,
'document_number' => setting('invoice.number_prefix') . $this->faker->randomNumber(setting('invoice.number_digit')),
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
'contact_id' => $contact->id,
'contact_name' => $contact->name,
'contact_email' => $contact->email,
'contact_tax_number' => $contact->tax_number,
'contact_phone' => $contact->phone,
'contact_address' => $contact->address,
'status' => $this->faker->randomElement($statuses),
];
});
return $this->state([
'type' => Model::INVOICE_TYPE,
'document_number' => $this->getNextDocumentNumber(Model::INVOICE_TYPE),
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
'contact_id' => $contact->id,
'contact_name' => $contact->name,
'contact_email' => $contact->email,
'contact_tax_number' => $contact->tax_number,
'contact_phone' => $contact->phone,
'contact_address' => $contact->address,
'status' => $this->faker->randomElement($statuses),
]);
}
/**
@ -85,30 +86,28 @@ class Document extends AbstractFactory
*/
public function bill(): Factory
{
return $this->state(function (array $attributes): array {
$contacts = Contact::vendor()->enabled()->get();
$contacts = Contact::vendor()->enabled()->get();
if ($contacts->count()) {
$contact = $contacts->random(1)->first();
} else {
$contact = Contact::factory()->vendor()->enabled()->create();
}
if ($contacts->count()) {
$contact = $contacts->random(1)->first();
} else {
$contact = Contact::factory()->vendor()->enabled()->create();
}
$statuses = ['draft', 'received', 'partial', 'paid', 'cancelled'];
$statuses = ['draft', 'received', 'partial', 'paid', 'cancelled'];
return [
'type' => Model::BILL_TYPE,
'document_number' => setting('bill.number_prefix') . $this->faker->randomNumber(setting('bill.number_digit')),
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
'contact_id' => $contact->id,
'contact_name' => $contact->name,
'contact_email' => $contact->email,
'contact_tax_number' => $contact->tax_number,
'contact_phone' => $contact->phone,
'contact_address' => $contact->address,
'status' => $this->faker->randomElement($statuses),
];
});
return $this->state([
'type' => Model::BILL_TYPE,
'document_number' => $this->getNextDocumentNumber(Model::BILL_TYPE),
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
'contact_id' => $contact->id,
'contact_name' => $contact->name,
'contact_email' => $contact->email,
'contact_tax_number' => $contact->tax_number,
'contact_phone' => $contact->phone,
'contact_address' => $contact->address,
'status' => $this->faker->randomElement($statuses),
]);
}
/**
@ -202,10 +201,15 @@ class Document extends AbstractFactory
*/
public function recurring()
{
$type = $this->getRawAttribute('type') . '-recurring';
return $this->state([
'type' => $type,
'document_number' => $this->getNextDocumentNumber($type),
'recurring_started_at' => $this->getRawAttribute('issued_at'),
'recurring_frequency' => 'daily',
'recurring_interval' => '1',
'recurring_count' => '7',
'recurring_limit_count' => '7',
]);
}
@ -216,43 +220,41 @@ class Document extends AbstractFactory
*/
public function items()
{
return $this->state(function (array $attributes) {
$amount = $this->faker->randomFloat(2, 1, 1000);
$amount = $this->faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = Tax::factory()->enabled()->create();
}
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = Tax::factory()->enabled()->create();
}
$items = Item::enabled()->get();
$items = Item::enabled()->get();
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = Item::factory()->enabled()->create();
}
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = Item::factory()->enabled()->create();
}
$items = [
[
'type' => $attributes['type'],
'name' => $item->name,
'description' => $this->faker->text,
'item_id' => $item->id,
'tax_ids' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => setting('default.currency'),
],
];
$items = [
[
'type' => $this->getRawAttribute('type'),
'name' => $item->name,
'description' => $this->faker->text,
'item_id' => $item->id,
'tax_ids' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => setting('default.currency'),
],
];
return [
'items' => $items,
'recurring_frequency' => 'no',
];
});
return $this->state([
'items' => $items,
'recurring_frequency' => 'no',
]);
}
/**
@ -291,6 +293,7 @@ class Document extends AbstractFactory
$items = [
[
'type' => $document->type,
'name' => $item->name,
'description' => $this->faker->text,
'item_id' => $item->id,
@ -327,7 +330,7 @@ class Document extends AbstractFactory
case 'paid':
$payment_request = [
'paid_at' => $updated_document->due_at,
'type' => config('type.' . $document->type . '.transaction_type'),
'type' => config('type.document.' . $document->type . '.transaction_type'),
];
if ($init_status === 'partial') {