From 3b965a39d201f63a354b57e1119ea08e679bdf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=87ak=C4=B1rel?= Date: Fri, 25 Dec 2020 19:25:38 +0300 Subject: [PATCH] Seperate Document Import/Export files into Invoice/Bill --- app/Abstracts/Export.php | 8 +-- app/Abstracts/Import.php | 10 --- app/BulkActions/Purchases/Bills.php | 4 +- app/BulkActions/Sales/Invoices.php | 4 +- app/Exports/Document/Documents.php | 40 ------------ .../Document/Sheets/DocumentHistories.php | 54 ---------------- .../Document/Sheets/DocumentTotals.php | 55 ---------------- app/Exports/Purchases/Bills.php | 33 ++++++++++ .../Purchases/Sheets/BillHistories.php | 43 +++++++++++++ .../Sheets/BillItemTaxes.php} | 22 ++----- .../Sheets/BillItems.php} | 22 ++----- app/Exports/Purchases/Sheets/BillTotals.php | 44 +++++++++++++ .../Purchases/Sheets/BillTransactions.php | 63 +++++++++++++++++++ app/Exports/Purchases/Sheets/Bills.php | 59 +++++++++++++++++ app/Exports/Sales/Invoices.php | 33 ++++++++++ app/Exports/Sales/Sheets/InvoiceHistories.php | 43 +++++++++++++ app/Exports/Sales/Sheets/InvoiceItemTaxes.php | 45 +++++++++++++ app/Exports/Sales/Sheets/InvoiceItems.php | 46 ++++++++++++++ app/Exports/Sales/Sheets/InvoiceTotals.php | 44 +++++++++++++ .../Sheets/InvoiceTransactions.php} | 20 ++---- .../Sheets/Invoices.php} | 26 +++----- app/Http/Controllers/Purchases/Bills.php | 8 +-- app/Http/Controllers/Sales/Invoices.php | 8 +-- app/Imports/Document/Documents.php | 37 ----------- .../Document/Sheets/DocumentTotals.php | 45 ------------- .../Document/Sheets/DocumentTransactions.php | 46 -------------- app/Imports/Document/Sheets/Documents.php | 56 ----------------- app/Imports/Purchases/Bills.php | 26 ++++++++ .../Sheets/BillHistories.php} | 20 +++--- .../Sheets/BillItemTaxes.php} | 24 +++---- .../Sheets/BillItems.php} | 18 +++--- app/Imports/Purchases/Sheets/BillTotals.php | 41 ++++++++++++ .../Purchases/Sheets/BillTransactions.php | 41 ++++++++++++ app/Imports/Purchases/Sheets/Bills.php | 45 +++++++++++++ app/Imports/Sales/Invoices.php | 27 ++++++++ app/Imports/Sales/Sheets/InvoiceHistories.php | 49 +++++++++++++++ app/Imports/Sales/Sheets/InvoiceItemTaxes.php | 62 ++++++++++++++++++ app/Imports/Sales/Sheets/InvoiceItems.php | 50 +++++++++++++++ app/Imports/Sales/Sheets/InvoiceTotals.php | 41 ++++++++++++ .../Sales/Sheets/InvoiceTransactions.php | 41 ++++++++++++ app/Imports/Sales/Sheets/Invoices.php | 45 +++++++++++++ modules/BC21/Exports/Purchases/Bills.php | 18 ------ modules/BC21/Exports/Sales/Invoices.php | 18 ------ modules/BC21/Imports/Purchases/Bills.php | 18 ------ modules/BC21/Imports/Sales/Invoices.php | 18 ------ 45 files changed, 981 insertions(+), 539 deletions(-) delete mode 100644 app/Exports/Document/Documents.php delete mode 100644 app/Exports/Document/Sheets/DocumentHistories.php delete mode 100644 app/Exports/Document/Sheets/DocumentTotals.php create mode 100644 app/Exports/Purchases/Bills.php create mode 100644 app/Exports/Purchases/Sheets/BillHistories.php rename app/Exports/{Document/Sheets/DocumentItemTaxes.php => Purchases/Sheets/BillItemTaxes.php} (51%) rename app/Exports/{Document/Sheets/DocumentItems.php => Purchases/Sheets/BillItems.php} (51%) create mode 100644 app/Exports/Purchases/Sheets/BillTotals.php create mode 100644 app/Exports/Purchases/Sheets/BillTransactions.php create mode 100644 app/Exports/Purchases/Sheets/Bills.php create mode 100644 app/Exports/Sales/Invoices.php create mode 100644 app/Exports/Sales/Sheets/InvoiceHistories.php create mode 100644 app/Exports/Sales/Sheets/InvoiceItemTaxes.php create mode 100644 app/Exports/Sales/Sheets/InvoiceItems.php create mode 100644 app/Exports/Sales/Sheets/InvoiceTotals.php rename app/Exports/{Document/Sheets/DocumentTransactions.php => Sales/Sheets/InvoiceTransactions.php} (69%) rename app/Exports/{Document/Sheets/Documents.php => Sales/Sheets/Invoices.php} (58%) delete mode 100644 app/Imports/Document/Documents.php delete mode 100644 app/Imports/Document/Sheets/DocumentTotals.php delete mode 100644 app/Imports/Document/Sheets/DocumentTransactions.php delete mode 100644 app/Imports/Document/Sheets/Documents.php create mode 100644 app/Imports/Purchases/Bills.php rename app/Imports/{Document/Sheets/DocumentHistories.php => Purchases/Sheets/BillHistories.php} (51%) rename app/Imports/{Document/Sheets/DocumentItemTaxes.php => Purchases/Sheets/BillItemTaxes.php} (54%) rename app/Imports/{Document/Sheets/DocumentItems.php => Purchases/Sheets/BillItems.php} (58%) create mode 100644 app/Imports/Purchases/Sheets/BillTotals.php create mode 100644 app/Imports/Purchases/Sheets/BillTransactions.php create mode 100644 app/Imports/Purchases/Sheets/Bills.php create mode 100644 app/Imports/Sales/Invoices.php create mode 100644 app/Imports/Sales/Sheets/InvoiceHistories.php create mode 100644 app/Imports/Sales/Sheets/InvoiceItemTaxes.php create mode 100644 app/Imports/Sales/Sheets/InvoiceItems.php create mode 100644 app/Imports/Sales/Sheets/InvoiceTotals.php create mode 100644 app/Imports/Sales/Sheets/InvoiceTransactions.php create mode 100644 app/Imports/Sales/Sheets/Invoices.php delete mode 100644 modules/BC21/Exports/Purchases/Bills.php delete mode 100644 modules/BC21/Exports/Sales/Invoices.php delete mode 100644 modules/BC21/Imports/Purchases/Bills.php delete mode 100644 modules/BC21/Imports/Sales/Invoices.php diff --git a/app/Abstracts/Export.php b/app/Abstracts/Export.php index a70bb8bc7..2bf1c0cd2 100644 --- a/app/Abstracts/Export.php +++ b/app/Abstracts/Export.php @@ -15,15 +15,9 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W { public $ids; - /** - * @var string - */ - protected $type; - - public function __construct($ids = null, string $type = '') + public function __construct($ids = null) { $this->ids = $ids; - $this->type = $type; } public function title(): string diff --git a/app/Abstracts/Import.php b/app/Abstracts/Import.php index 7e6664ac0..775565c50 100644 --- a/app/Abstracts/Import.php +++ b/app/Abstracts/Import.php @@ -25,16 +25,6 @@ abstract class Import implements ToModel, SkipsOnError, SkipsOnFailure, WithBatc public $empty_field = 'empty---'; - /** - * @var string - */ - protected $type; - - public function __construct(string $type = '') - { - $this->type = $type; - } - public function map($row): array { $row['company_id'] = session('company_id'); diff --git a/app/BulkActions/Purchases/Bills.php b/app/BulkActions/Purchases/Bills.php index e70680ab3..3e0d6d1cb 100644 --- a/app/BulkActions/Purchases/Bills.php +++ b/app/BulkActions/Purchases/Bills.php @@ -5,7 +5,7 @@ namespace App\BulkActions\Purchases; use App\Abstracts\BulkAction; use App\Events\Document\DocumentCancelled; use App\Events\Document\DocumentReceived; -use App\Exports\Document\Documents as Export; +use App\Exports\Purchases\Bills as Export; use App\Jobs\Banking\CreateBankingDocumentTransaction; use App\Jobs\Document\CreateDocumentHistory; use App\Jobs\Document\DeleteDocument; @@ -100,6 +100,6 @@ class Bills extends BulkAction { $selected = $this->getSelectedInput($request); - return \Excel::download(new Export($selected, Document::BILL_TYPE), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx'); + return \Excel::download(new Export($selected), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx'); } } diff --git a/app/BulkActions/Sales/Invoices.php b/app/BulkActions/Sales/Invoices.php index 6b2662100..0e92bb3ed 100644 --- a/app/BulkActions/Sales/Invoices.php +++ b/app/BulkActions/Sales/Invoices.php @@ -7,7 +7,7 @@ use App\Events\Document\DocumentCancelled; use App\Events\Document\DocumentCreated; use App\Events\Document\DocumentSent; use App\Events\Document\PaymentReceived; -use App\Exports\Document\Documents as Export; +use App\Exports\Sales\Invoices as Export; use App\Jobs\Document\DeleteDocument; use App\Models\Document\Document; @@ -103,6 +103,6 @@ class Invoices extends BulkAction { $selected = $this->getSelectedInput($request); - return \Excel::download(new Export($selected, Document::INVOICE_TYPE), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx'); + return \Excel::download(new Export($selected), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx'); } } diff --git a/app/Exports/Document/Documents.php b/app/Exports/Document/Documents.php deleted file mode 100644 index 5b265c6ab..000000000 --- a/app/Exports/Document/Documents.php +++ /dev/null @@ -1,40 +0,0 @@ -ids = $ids; - $this->type = $type; - } - - public function sheets(): array - { - return [ - Str::plural($this->type) => new Base($this->ids, $this->type), - $this->type . '_items' => new DocumentItems($this->ids, $this->type), - $this->type . '_item_taxes' => new DocumentItemTaxes($this->ids, $this->type), - $this->type . '_histories' => new DocumentHistories($this->ids, $this->type), - $this->type . '_totals' => new DocumentTotals($this->ids, $this->type), - $this->type . '_transactions' => new DocumentTransactions($this->ids, $this->type), - ]; - } -} diff --git a/app/Exports/Document/Sheets/DocumentHistories.php b/app/Exports/Document/Sheets/DocumentHistories.php deleted file mode 100644 index 46db9846e..000000000 --- a/app/Exports/Document/Sheets/DocumentHistories.php +++ /dev/null @@ -1,54 +0,0 @@ -type}()->with('document')->usingSearchString(request('search')); - - if (!empty($this->ids)) { - $model->whereIn('document_id', (array) $this->ids); - } - - return $model->cursor(); - } - - public function map($model): array - { - $document = $model->document; - - if (empty($document)) { - return []; - } - - if ($this->type === Document::INVOICE_TYPE) { - $model->invoice_number = $document->document_number; - } else { - $model->bill_number = $document->document_number; - } - - return parent::map($model); - } - - public function fields(): array - { - return [ - $this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number', - 'status', - 'notify', - 'description', - ]; - } - - public function title(): string - { - return Str::replaceFirst('document', $this->type, parent::title()); - } -} diff --git a/app/Exports/Document/Sheets/DocumentTotals.php b/app/Exports/Document/Sheets/DocumentTotals.php deleted file mode 100644 index 7460530a0..000000000 --- a/app/Exports/Document/Sheets/DocumentTotals.php +++ /dev/null @@ -1,55 +0,0 @@ -type}()->with('document')->usingSearchString(request('search')); - - if (!empty($this->ids)) { - $model->whereIn('document_id', (array) $this->ids); - } - - return $model->cursor(); - } - - public function map($model): array - { - $document = $model->document; - - if (empty($document)) { - return []; - } - - if ($this->type === Document::INVOICE_TYPE) { - $model->invoice_number = $document->document_number; - } else { - $model->bill_number = $document->document_number; - } - - return parent::map($model); - } - - public function fields(): array - { - return [ - $this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number', - 'code', - 'name', - 'amount', - 'sort_order', - ]; - } - - public function title(): string - { - return Str::replaceFirst('document', $this->type, parent::title()); - } -} diff --git a/app/Exports/Purchases/Bills.php b/app/Exports/Purchases/Bills.php new file mode 100644 index 000000000..6396c969a --- /dev/null +++ b/app/Exports/Purchases/Bills.php @@ -0,0 +1,33 @@ +ids = $ids; + } + + public function sheets(): array + { + return [ + 'bills' => new Base($this->ids), + 'bill_items' => new BillItems($this->ids), + 'bill_item_taxes' => new BillItemTaxes($this->ids), + 'bill_histories' => new BillHistories($this->ids), + 'bill_totals' => new BillTotals($this->ids), + 'bill_transactions' => new BillTransactions($this->ids), + ]; + } +} diff --git a/app/Exports/Purchases/Sheets/BillHistories.php b/app/Exports/Purchases/Sheets/BillHistories.php new file mode 100644 index 000000000..df1e70cf2 --- /dev/null +++ b/app/Exports/Purchases/Sheets/BillHistories.php @@ -0,0 +1,43 @@ +with('document')->usingSearchString(request('search')); + + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); + } + + return $model->cursor(); + } + + public function map($model): array + { + $document = $model->document; + + if (empty($document)) { + return []; + } + + $model->bill_number = $document->document_number; + + return parent::map($model); + } + + public function fields(): array + { + return [ + 'bill_number', + 'status', + 'notify', + 'description', + ]; + } +} diff --git a/app/Exports/Document/Sheets/DocumentItemTaxes.php b/app/Exports/Purchases/Sheets/BillItemTaxes.php similarity index 51% rename from app/Exports/Document/Sheets/DocumentItemTaxes.php rename to app/Exports/Purchases/Sheets/BillItemTaxes.php index 92351fad1..13e24d9ba 100644 --- a/app/Exports/Document/Sheets/DocumentItemTaxes.php +++ b/app/Exports/Purchases/Sheets/BillItemTaxes.php @@ -1,17 +1,15 @@ type}()->with('document', 'item', 'tax')->usingSearchString(request('search')); + $model = Model::bill()->with('document', 'item', 'tax')->usingSearchString(request('search')); if (!empty($this->ids)) { $model->whereIn('document_id', (array) $this->ids); @@ -28,12 +26,7 @@ class DocumentItemTaxes extends Export return []; } - if ($this->type === Document::INVOICE_TYPE) { - $model->invoice_number = $document->document_number; - } else { - $model->bill_number = $document->document_number; - } - + $model->bill_number = $document->document_number; $model->item_name = $model->item->name; $model->tax_rate = $model->tax->rate; @@ -43,15 +36,10 @@ class DocumentItemTaxes extends Export public function fields(): array { return [ - $this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number', + 'bill_number', 'item_name', 'tax_rate', 'amount', ]; } - - public function title(): string - { - return Str::replaceFirst('document', $this->type, parent::title()); - } } diff --git a/app/Exports/Document/Sheets/DocumentItems.php b/app/Exports/Purchases/Sheets/BillItems.php similarity index 51% rename from app/Exports/Document/Sheets/DocumentItems.php rename to app/Exports/Purchases/Sheets/BillItems.php index cdd5579b6..cc468f29a 100644 --- a/app/Exports/Document/Sheets/DocumentItems.php +++ b/app/Exports/Purchases/Sheets/BillItems.php @@ -1,17 +1,15 @@ type}()->with('document', 'item')->usingSearchString(request('search')); + $model = Model::bill()->with('document', 'item')->usingSearchString(request('search')); if (!empty($this->ids)) { $model->whereIn('document_id', (array) $this->ids); @@ -28,12 +26,7 @@ class DocumentItems extends Export return []; } - if ($this->type === Document::INVOICE_TYPE) { - $model->invoice_number = $document->document_number; - } else { - $model->bill_number = $document->document_number; - } - + $model->bill_number = $document->document_number; $model->item_name = $model->item->name; return parent::map($model); @@ -42,7 +35,7 @@ class DocumentItems extends Export public function fields(): array { return [ - $this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number', + 'bill_number', 'item_name', 'quantity', 'price', @@ -50,9 +43,4 @@ class DocumentItems extends Export 'tax', ]; } - - public function title(): string - { - return Str::replaceFirst('document', $this->type, parent::title()); - } } diff --git a/app/Exports/Purchases/Sheets/BillTotals.php b/app/Exports/Purchases/Sheets/BillTotals.php new file mode 100644 index 000000000..6dc80b71a --- /dev/null +++ b/app/Exports/Purchases/Sheets/BillTotals.php @@ -0,0 +1,44 @@ +with('document')->usingSearchString(request('search')); + + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); + } + + return $model->cursor(); + } + + public function map($model): array + { + $document = $model->document; + + if (empty($document)) { + return []; + } + + $model->bill_number = $document->document_number; + + return parent::map($model); + } + + public function fields(): array + { + return [ + 'bill_number', + 'code', + 'name', + 'amount', + 'sort_order', + ]; + } +} diff --git a/app/Exports/Purchases/Sheets/BillTransactions.php b/app/Exports/Purchases/Sheets/BillTransactions.php new file mode 100644 index 000000000..54be9dbe3 --- /dev/null +++ b/app/Exports/Purchases/Sheets/BillTransactions.php @@ -0,0 +1,63 @@ +bill()->isDocument()->usingSearchString(request('search')); + + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); + } + + return $model->cursor(); + } + + public function map($model): array + { + $document = $model->document; + + if (empty($document)) { + return []; + } + + $model->bill_number = $document->document_number; + $model->account_name = $model->account->name; + $model->category_name = $model->category->name; + $model->contact_email = $model->contact->email; + + return parent::map($model); + } + + public function fields(): array + { + return [ + 'bill_number', + 'paid_at', + 'amount', + 'currency_code', + 'currency_rate', + 'account_name', + 'contact_email', + 'category_name', + 'description', + 'payment_method', + 'reference', + 'reconciled', + ]; + } + + public function columnFormats(): array + { + return [ + 'B' => NumberFormat::FORMAT_DATE_YYYYMMDD, + ]; + } +} diff --git a/app/Exports/Purchases/Sheets/Bills.php b/app/Exports/Purchases/Sheets/Bills.php new file mode 100644 index 000000000..31ae588d6 --- /dev/null +++ b/app/Exports/Purchases/Sheets/Bills.php @@ -0,0 +1,59 @@ +with('category')->usingSearchString(request('search')); + + if (!empty($this->ids)) { + $model->whereIn('id', (array) $this->ids); + } + + return $model->cursor(); + } + + public function map($model): array + { + $model->category_name = $model->category->name; + $model->bill_number = $model->document_number; + $model->billed_at = $model->issued_at; + + return parent::map($model); + } + + public function fields(): array + { + return [ + 'bill_number', + 'order_number', + 'status', + 'billed_at', + 'due_at', + 'amount', + 'currency_code', + 'currency_rate', + 'category_name', + 'contact_name', + 'contact_email', + 'contact_tax_number', + 'contact_phone', + 'contact_address', + 'notes', + ]; + } + + public function columnFormats(): array + { + return [ + 'D' => NumberFormat::FORMAT_DATE_YYYYMMDD, + 'E' => NumberFormat::FORMAT_DATE_YYYYMMDD, + ]; + } +} diff --git a/app/Exports/Sales/Invoices.php b/app/Exports/Sales/Invoices.php new file mode 100644 index 000000000..00c8349f4 --- /dev/null +++ b/app/Exports/Sales/Invoices.php @@ -0,0 +1,33 @@ +ids = $ids; + } + + public function sheets(): array + { + return [ + 'invoices' => new Base($this->ids), + 'invoice_items' => new InvoiceItems($this->ids), + 'invoice_item_taxes' => new InvoiceItemTaxes($this->ids), + 'invoice_histories' => new InvoiceHistories($this->ids), + 'invoice_totals' => new InvoiceTotals($this->ids), + 'invoice_transactions' => new InvoiceTransactions($this->ids), + ]; + } +} diff --git a/app/Exports/Sales/Sheets/InvoiceHistories.php b/app/Exports/Sales/Sheets/InvoiceHistories.php new file mode 100644 index 000000000..c0c0bf9c3 --- /dev/null +++ b/app/Exports/Sales/Sheets/InvoiceHistories.php @@ -0,0 +1,43 @@ +with('document')->usingSearchString(request('search')); + + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); + } + + return $model->cursor(); + } + + public function map($model): array + { + $document = $model->document; + + if (empty($document)) { + return []; + } + + $model->invoice_number = $document->document_number; + + return parent::map($model); + } + + public function fields(): array + { + return [ + 'invoice_number', + 'status', + 'notify', + 'description', + ]; + } +} diff --git a/app/Exports/Sales/Sheets/InvoiceItemTaxes.php b/app/Exports/Sales/Sheets/InvoiceItemTaxes.php new file mode 100644 index 000000000..666432cbf --- /dev/null +++ b/app/Exports/Sales/Sheets/InvoiceItemTaxes.php @@ -0,0 +1,45 @@ +with('document', 'item', 'tax')->usingSearchString(request('search')); + + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); + } + + return $model->cursor(); + } + + public function map($model): array + { + $document = $model->document; + + if (empty($document)) { + return []; + } + + $model->invoice_number = $document->document_number; + $model->item_name = $model->item->name; + $model->tax_rate = $model->tax->rate; + + return parent::map($model); + } + + public function fields(): array + { + return [ + 'invoice_number', + 'item_name', + 'tax_rate', + 'amount', + ]; + } +} diff --git a/app/Exports/Sales/Sheets/InvoiceItems.php b/app/Exports/Sales/Sheets/InvoiceItems.php new file mode 100644 index 000000000..2c6c1c045 --- /dev/null +++ b/app/Exports/Sales/Sheets/InvoiceItems.php @@ -0,0 +1,46 @@ +with('document', 'item')->usingSearchString(request('search')); + + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); + } + + return $model->cursor(); + } + + public function map($model): array + { + $document = $model->document; + + if (empty($document)) { + return []; + } + + $model->invoice_number = $document->document_number; + $model->item_name = $model->item->name; + + return parent::map($model); + } + + public function fields(): array + { + return [ + 'invoice_number', + 'item_name', + 'quantity', + 'price', + 'total', + 'tax', + ]; + } +} diff --git a/app/Exports/Sales/Sheets/InvoiceTotals.php b/app/Exports/Sales/Sheets/InvoiceTotals.php new file mode 100644 index 000000000..11e098ad4 --- /dev/null +++ b/app/Exports/Sales/Sheets/InvoiceTotals.php @@ -0,0 +1,44 @@ +with('document')->usingSearchString(request('search')); + + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); + } + + return $model->cursor(); + } + + public function map($model): array + { + $document = $model->document; + + if (empty($document)) { + return []; + } + + $model->invoice_number = $document->document_number; + + return parent::map($model); + } + + public function fields(): array + { + return [ + 'invoice_number', + 'code', + 'name', + 'amount', + 'sort_order', + ]; + } +} diff --git a/app/Exports/Document/Sheets/DocumentTransactions.php b/app/Exports/Sales/Sheets/InvoiceTransactions.php similarity index 69% rename from app/Exports/Document/Sheets/DocumentTransactions.php rename to app/Exports/Sales/Sheets/InvoiceTransactions.php index 8a2647015..dff86c8be 100644 --- a/app/Exports/Document/Sheets/DocumentTransactions.php +++ b/app/Exports/Sales/Sheets/InvoiceTransactions.php @@ -1,6 +1,6 @@ {$this->type}()->isDocument()->usingSearchString(request('search')); + $model = Model::with('account', 'category', 'contact', 'document')->invoice()->isDocument()->usingSearchString(request('search')); if (!empty($this->ids)) { $model->whereIn('document_id', (array) $this->ids); @@ -30,12 +30,7 @@ class DocumentTransactions extends Export implements WithColumnFormatting return []; } - if ($this->type === Document::INVOICE_TYPE) { - $model->invoice_number = $document->document_number; - } else { - $model->bill_number = $document->document_number; - } - + $model->invoice_number = $document->document_number; $model->account_name = $model->account->name; $model->category_name = $model->category->name; $model->contact_email = $model->contact->email; @@ -46,7 +41,7 @@ class DocumentTransactions extends Export implements WithColumnFormatting public function fields(): array { return [ - $this->type === Document::INVOICE_TYPE ? 'invoice_number' : 'bill_number', + 'invoice_number', 'paid_at', 'amount', 'currency_code', @@ -67,9 +62,4 @@ class DocumentTransactions extends Export implements WithColumnFormatting 'B' => NumberFormat::FORMAT_DATE_YYYYMMDD, ]; } - - public function title(): string - { - return Str::replaceFirst('document', $this->type, parent::title()); - } } diff --git a/app/Exports/Document/Sheets/Documents.php b/app/Exports/Sales/Sheets/Invoices.php similarity index 58% rename from app/Exports/Document/Sheets/Documents.php rename to app/Exports/Sales/Sheets/Invoices.php index c5d5b8505..81319c97f 100644 --- a/app/Exports/Document/Sheets/Documents.php +++ b/app/Exports/Sales/Sheets/Invoices.php @@ -1,17 +1,16 @@ type}()->with('category')->usingSearchString(request('search')); + $model = Model::invoice()->with('category')->usingSearchString(request('search')); if (!empty($this->ids)) { $model->whereIn('id', (array) $this->ids); @@ -23,14 +22,8 @@ class Documents extends Export public function map($model): array { $model->category_name = $model->category->name; - - if ($this->type === Model::INVOICE_TYPE) { - $model->invoice_number = $model->document_number; - $model->invoiced_at = $model->issued_at; - } else { - $model->bill_number = $model->document_number; - $model->billed_at = $model->issued_at; - } + $model->invoice_number = $model->document_number; + $model->invoiced_at = $model->issued_at; return parent::map($model); } @@ -38,10 +31,10 @@ class Documents extends Export public function fields(): array { return [ - $this->type === Model::INVOICE_TYPE ? 'invoice_number' : 'bill_number', + 'invoice_number', 'order_number', 'status', - $this->type === Model::INVOICE_TYPE ? 'invoiced_at' : 'billed_at', + 'invoiced_at', 'due_at', 'amount', 'currency_code', @@ -57,11 +50,6 @@ class Documents extends Export ]; } - public function title(): string - { - return Str::replaceFirst('document', $this->type, parent::title()); - } - public function columnFormats(): array { return [ diff --git a/app/Http/Controllers/Purchases/Bills.php b/app/Http/Controllers/Purchases/Bills.php index a36cd190c..64aa526d9 100644 --- a/app/Http/Controllers/Purchases/Bills.php +++ b/app/Http/Controllers/Purchases/Bills.php @@ -3,10 +3,10 @@ namespace App\Http\Controllers\Purchases; use App\Abstracts\Http\Controller; -use App\Exports\Document\Documents as Export; +use App\Exports\Purchases\Bills as Export; use App\Http\Requests\Common\Import as ImportRequest; use App\Http\Requests\Document\Document as Request; -use App\Imports\Document\Documents as Import; +use App\Imports\Purchases\Bills as Import; use App\Jobs\Banking\CreateBankingDocumentTransaction; use App\Jobs\Document\CreateDocument; use App\Jobs\Document\DeleteDocument; @@ -131,7 +131,7 @@ class Bills extends Controller public function import(ImportRequest $request) { try { - \Excel::import(new Import(Document::BILL_TYPE), $request->file('import')); + \Excel::import(new Import(), $request->file('import')); } catch (\Maatwebsite\Excel\Exceptions\SheetNotFoundException $e) { flash($e->getMessage())->error()->important(); @@ -219,7 +219,7 @@ class Bills extends Controller */ public function export() { - return \Excel::download(new Export(null, Document::BILL_TYPE), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx'); + return \Excel::download(new Export(), \Str::filename(trans_choice('general.bills', 2)) . '.xlsx'); } /** diff --git a/app/Http/Controllers/Sales/Invoices.php b/app/Http/Controllers/Sales/Invoices.php index 7715b0a5d..927647ae0 100644 --- a/app/Http/Controllers/Sales/Invoices.php +++ b/app/Http/Controllers/Sales/Invoices.php @@ -3,10 +3,10 @@ namespace App\Http\Controllers\Sales; use App\Abstracts\Http\Controller; -use App\Exports\Document\Documents as Export; +use App\Exports\Sales\Invoices as Export; use App\Http\Requests\Common\Import as ImportRequest; use App\Http\Requests\Document\Document as Request; -use App\Imports\Document\Documents as Import; +use App\Imports\Sales\Invoices as Import; use App\Jobs\Document\CreateDocument; use App\Jobs\Document\DeleteDocument; use App\Jobs\Document\DuplicateDocument; @@ -131,7 +131,7 @@ class Invoices extends Controller public function import(ImportRequest $request) { try { - \Excel::import(new Import(Document::INVOICE_TYPE), $request->file('import')); + \Excel::import(new Import(), $request->file('import')); } catch (\Maatwebsite\Excel\Exceptions\SheetNotFoundException $e) { flash($e->getMessage())->error()->important(); @@ -219,7 +219,7 @@ class Invoices extends Controller */ public function export() { - return \Excel::download(new Export(null, Document::INVOICE_TYPE), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx'); + return \Excel::download(new Export(), \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx'); } /** diff --git a/app/Imports/Document/Documents.php b/app/Imports/Document/Documents.php deleted file mode 100644 index 09ca47965..000000000 --- a/app/Imports/Document/Documents.php +++ /dev/null @@ -1,37 +0,0 @@ -type = $type; - } - - public function sheets(): array - { - return [ - Str::plural($this->type) => new Base($this->type), - $this->type . '_items' => new DocumentItems($this->type), - $this->type . '_item_taxes' => new DocumentItemTaxes($this->type), - $this->type . '_histories' => new DocumentHistories($this->type), - $this->type . '_totals' => new DocumentTotals($this->type), - $this->type . '_transactions' => new DocumentTransactions($this->type), - ]; - } -} diff --git a/app/Imports/Document/Sheets/DocumentTotals.php b/app/Imports/Document/Sheets/DocumentTotals.php deleted file mode 100644 index c241877eb..000000000 --- a/app/Imports/Document/Sheets/DocumentTotals.php +++ /dev/null @@ -1,45 +0,0 @@ -isEmpty($row, $this->type . '_number')) { - return []; - } - - $row = parent::map($row); - - $row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first(); - $row['type'] = $this->type; - - return $row; - } - - public function rules(): array - { - $rules = (new Request())->rules(); - - if ($this->type === Document::INVOICE_TYPE) { - $rules['invoice_number'] = 'required|string'; - } else { - $rules['bill_number'] = 'required|string'; - } - - unset($rules['invoice_id'], $rules['bill_id']); - - return $rules; - } -} diff --git a/app/Imports/Document/Sheets/DocumentTransactions.php b/app/Imports/Document/Sheets/DocumentTransactions.php deleted file mode 100644 index 293082275..000000000 --- a/app/Imports/Document/Sheets/DocumentTransactions.php +++ /dev/null @@ -1,46 +0,0 @@ -isEmpty($row, $this->type . '_number')) { - return []; - } - - $row = parent::map($row); - - $row['type'] = $this->type === Document::INVOICE_TYPE ? 'income' : 'expense'; - $row['account_id'] = $this->getAccountId($row); - $row['category_id'] = $this->getCategoryId($row, $this->type === Document::INVOICE_TYPE ? 'income' : 'expense'); - $row['contact_id'] = $this->getContactId($row, $this->type === Document::INVOICE_TYPE ? 'customer' : 'vendor'); - $row['document_id'] = $this->getDocumentId($row); - - return $row; - } - - public function rules(): array - { - $rules = (new Request())->rules(); - - if ($this->type === Document::INVOICE_TYPE) { - $rules['invoice_number'] = 'required|string'; - } else { - $rules['bill_number'] = 'required|string'; - } - - return $rules; - } -} diff --git a/app/Imports/Document/Sheets/Documents.php b/app/Imports/Document/Sheets/Documents.php deleted file mode 100644 index dabb03d33..000000000 --- a/app/Imports/Document/Sheets/Documents.php +++ /dev/null @@ -1,56 +0,0 @@ -isEmpty($row, $this->type . '_number')) { - return []; - } - - $row = parent::map($row); - - if ($this->type === Model::INVOICE_TYPE) { - $row['document_number'] = $row['invoice_number']; - $row['issued_at'] = $row['invoiced_at']; - } else { - $row['document_number'] = $row['bill_number']; - $row['issued_at'] = $row['billed_at']; - } - - $row['category_id'] = $this->getCategoryId($row, $this->type === Model::INVOICE_TYPE ? 'income' : 'expense'); - $row['contact_id'] = $this->getContactId($row, $this->type === Model::INVOICE_TYPE ? 'customer' : 'vendor'); - $row['type'] = $this->type; - - return $row; - } - - public function rules(): array - { - $rules = (new Request())->rules(); - - if ($this->type === Model::INVOICE_TYPE) { - $rules['invoice_number'] = Str::replaceFirst('unique:documents,NULL', 'unique:documents,document_number', $rules['document_number']); - $rules['invoiced_at'] = $rules['issued_at']; - } else { - $rules['bill_number'] = Str::replaceFirst('unique:documents,NULL', 'unique:documents,document_number', $rules['document_number']); - $rules['billed_at'] = $rules['issued_at']; - } - - unset($rules['document_number'], $rules['issued_at'], $rules['type']); - - return $rules; - } -} diff --git a/app/Imports/Purchases/Bills.php b/app/Imports/Purchases/Bills.php new file mode 100644 index 000000000..ca871a727 --- /dev/null +++ b/app/Imports/Purchases/Bills.php @@ -0,0 +1,26 @@ + new Base(), + 'bill_items' => new BillItems(), + 'bill_item_taxes' => new BillItemTaxes(), + 'bill_histories' => new BillHistories(), + 'bill_totals' => new BillTotals(), + 'bill_transactions' => new BillTransactions(), + ]; + } +} diff --git a/app/Imports/Document/Sheets/DocumentHistories.php b/app/Imports/Purchases/Sheets/BillHistories.php similarity index 51% rename from app/Imports/Document/Sheets/DocumentHistories.php rename to app/Imports/Purchases/Sheets/BillHistories.php index 5cf6a5a04..8252c2d15 100644 --- a/app/Imports/Document/Sheets/DocumentHistories.php +++ b/app/Imports/Purchases/Sheets/BillHistories.php @@ -1,18 +1,18 @@ type . '_number'] == $this->empty_field) { + if ($row['bill_number'] === $this->empty_field) { return null; } @@ -21,17 +21,17 @@ class DocumentHistories extends Import public function map($row): array { - if ($this->isEmpty($row, $this->type . '_number')) { + if ($this->isEmpty($row, 'bill_number')) { return []; } $row = parent::map($row); - $row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first(); + $row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first(); $row['notify'] = (int) $row['notify']; - $row['type'] = $this->type; + $row['type'] = Document::BILL_TYPE; return $row; } @@ -40,13 +40,9 @@ class DocumentHistories extends Import { $rules = (new Request())->rules(); - if ($this->type === Document::INVOICE_TYPE) { - $rules['invoice_number'] = 'required|string'; - } else { - $rules['bill_number'] = 'required|string'; - } + $rules['bill_number'] = 'required|string'; - unset($rules['invoice_id'], $rules['bill_id']); + unset($rules['bill_id']); return $rules; } diff --git a/app/Imports/Document/Sheets/DocumentItemTaxes.php b/app/Imports/Purchases/Sheets/BillItemTaxes.php similarity index 54% rename from app/Imports/Document/Sheets/DocumentItemTaxes.php rename to app/Imports/Purchases/Sheets/BillItemTaxes.php index eca751e87..ce40d346e 100644 --- a/app/Imports/Document/Sheets/DocumentItemTaxes.php +++ b/app/Imports/Purchases/Sheets/BillItemTaxes.php @@ -1,6 +1,6 @@ type . '_number'] == $this->empty_field) { + if ($row['bill_number'] === $this->empty_field) { return null; } @@ -23,17 +23,17 @@ class DocumentItemTaxes extends Import public function map($row): array { - if ($this->isEmpty($row, $this->type . '_number')) { + if ($this->isEmpty($row, 'bill_number')) { return []; } $row = parent::map($row); - $row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first(); + $row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first(); - if (empty($row[$this->type . '_item_id']) && !empty($row['item_name'])) { + if (empty($row['bill_item_id']) && !empty($row['item_name'])) { $item_id = Item::name($row['item_name'])->pluck('id')->first(); - $row[$this->type . '_item_id'] = DocumentItem::{$this->type}()->where('item_id', $item_id)->pluck('id')->first(); + $row['bill_item_id'] = DocumentItem::bill()->where('item_id', $item_id)->pluck('id')->first(); } $row['tax_id'] = $this->getTaxId($row); @@ -44,7 +44,7 @@ class DocumentItemTaxes extends Import $row['amount'] = (double) $row['amount']; - $row['type'] = $this->type; + $row['type'] = Document::BILL_TYPE; return $row; } @@ -53,13 +53,9 @@ class DocumentItemTaxes extends Import { $rules = (new Request())->rules(); - if ($this->type === Document::INVOICE_TYPE) { - $rules['invoice_number'] = 'required|string'; - } else { - $rules['bill_number'] = 'required|string'; - } + $rules['bill_number'] = 'required|string'; - unset($rules['invoice_id'], $rules['bill_id']); + unset($rules['bill_id']); return $rules; } diff --git a/app/Imports/Document/Sheets/DocumentItems.php b/app/Imports/Purchases/Sheets/BillItems.php similarity index 58% rename from app/Imports/Document/Sheets/DocumentItems.php rename to app/Imports/Purchases/Sheets/BillItems.php index 42c5c5ef6..885b3d3ce 100644 --- a/app/Imports/Document/Sheets/DocumentItems.php +++ b/app/Imports/Purchases/Sheets/BillItems.php @@ -1,13 +1,13 @@ isEmpty($row, $this->type . '_number')) { + if ($this->isEmpty($row, 'bill_number')) { return []; } $row = parent::map($row); - $row['document_id'] = (int) Document::{$this->type}()->number($row[$this->type . '_number'])->pluck('id')->first(); + $row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first(); if (empty($row['item_id']) && !empty($row['item_name'])) { $row['item_id'] = $this->getItemIdFromName($row); @@ -32,7 +32,7 @@ class DocumentItems extends Import $row['tax'] = (double) $row['tax']; $row['tax_id'] = 0; - $row['type'] = $this->type; + $row['type'] = Document::BILL_TYPE; return $row; } @@ -41,13 +41,9 @@ class DocumentItems extends Import { $rules = (new Request())->rules(); - if ($this->type === Document::INVOICE_TYPE) { - $rules['invoice_number'] = 'required|string'; - } else { - $rules['bill_number'] = 'required|string'; - } + $rules['bill_number'] = 'required|string'; - unset($rules['invoice_id'], $rules['bill_id']); + unset($rules['bill_id']); return $rules; } diff --git a/app/Imports/Purchases/Sheets/BillTotals.php b/app/Imports/Purchases/Sheets/BillTotals.php new file mode 100644 index 000000000..54a256f8e --- /dev/null +++ b/app/Imports/Purchases/Sheets/BillTotals.php @@ -0,0 +1,41 @@ +isEmpty($row, 'bill_number')) { + return []; + } + + $row = parent::map($row); + + $row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first(); + $row['type'] = Document::BILL_TYPE; + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['bill_number'] = 'required|string'; + + unset($rules['bill_id']); + + return $rules; + } +} diff --git a/app/Imports/Purchases/Sheets/BillTransactions.php b/app/Imports/Purchases/Sheets/BillTransactions.php new file mode 100644 index 000000000..f1c718a5c --- /dev/null +++ b/app/Imports/Purchases/Sheets/BillTransactions.php @@ -0,0 +1,41 @@ +isEmpty($row, 'bill_number')) { + return []; + } + + $row = parent::map($row); + + $row['type'] = 'expense'; + $row['account_id'] = $this->getAccountId($row); + $row['category_id'] = $this->getCategoryId($row, 'expense'); + $row['contact_id'] = $this->getContactId($row, 'vendor'); + $row['document_id'] = $this->getDocumentId($row); + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['bill_number'] = 'required|string'; + + return $rules; + } +} diff --git a/app/Imports/Purchases/Sheets/Bills.php b/app/Imports/Purchases/Sheets/Bills.php new file mode 100644 index 000000000..b8e177be7 --- /dev/null +++ b/app/Imports/Purchases/Sheets/Bills.php @@ -0,0 +1,45 @@ +isEmpty($row, 'bill_number')) { + return []; + } + + $row = parent::map($row); + + $row['document_number'] = $row['bill_number']; + $row['issued_at'] = $row['billed_at']; + $row['category_id'] = $this->getCategoryId($row, 'expense'); + $row['contact_id'] = $this->getContactId($row, 'vendor'); + $row['type'] = Model::BILL_TYPE; + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['bill_number'] = Str::replaceFirst('unique:documents,NULL', 'unique:documents,document_number', $rules['document_number']); + $rules['billed_at'] = $rules['issued_at']; + + unset($rules['document_number'], $rules['issued_at'], $rules['type']); + + return $rules; + } +} diff --git a/app/Imports/Sales/Invoices.php b/app/Imports/Sales/Invoices.php new file mode 100644 index 000000000..863381dac --- /dev/null +++ b/app/Imports/Sales/Invoices.php @@ -0,0 +1,27 @@ + new Base(), + 'invoice_items' => new InvoiceItems(), + 'invoice_item_taxes' => new InvoiceItemTaxes(), + 'invoice_histories' => new InvoiceHistories(), + 'invoice_totals' => new InvoiceTotals(), + 'invoice_transactions' => new InvoiceTransactions(), + ]; + } +} diff --git a/app/Imports/Sales/Sheets/InvoiceHistories.php b/app/Imports/Sales/Sheets/InvoiceHistories.php new file mode 100644 index 000000000..e00d7680e --- /dev/null +++ b/app/Imports/Sales/Sheets/InvoiceHistories.php @@ -0,0 +1,49 @@ +empty_field) { + return null; + } + + return new Model($row); + } + + public function map($row): array + { + if ($this->isEmpty($row, 'invoice_number')) { + return []; + } + + $row = parent::map($row); + + $row['document_id'] = (int) Document::invoice()->number($row['invoice_number'])->pluck('id')->first(); + + $row['notify'] = (int) $row['notify']; + + $row['type'] = Document::INVOICE_TYPE; + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['invoice_number'] = 'required|string'; + + unset($rules['invoice_id']); + + return $rules; + } +} diff --git a/app/Imports/Sales/Sheets/InvoiceItemTaxes.php b/app/Imports/Sales/Sheets/InvoiceItemTaxes.php new file mode 100644 index 000000000..cb7ea7186 --- /dev/null +++ b/app/Imports/Sales/Sheets/InvoiceItemTaxes.php @@ -0,0 +1,62 @@ +empty_field) { + return null; + } + + return new Model($row); + } + + public function map($row): array + { + if ($this->isEmpty($row, 'invoice_number')) { + return []; + } + + $row = parent::map($row); + + $row['document_id'] = (int) Document::invoice()->number($row['invoice_number'])->pluck('id')->first(); + + if (empty($row['invoice_item_id']) && !empty($row['item_name'])) { + $item_id = Item::name($row['item_name'])->pluck('id')->first(); + $row['invoice_item_id'] = DocumentItem::invoice()->where('item_id', $item_id)->pluck('id')->first(); + } + + $row['tax_id'] = $this->getTaxId($row); + + if (empty($row['name']) && !empty($row['item_name'])) { + $row['name'] = $row['item_name']; + } + + $row['amount'] = (double) $row['amount']; + + $row['type'] = Document::INVOICE_TYPE; + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['invoice_number'] = 'required|string'; + + unset($rules['invoice_id']); + + return $rules; + } +} diff --git a/app/Imports/Sales/Sheets/InvoiceItems.php b/app/Imports/Sales/Sheets/InvoiceItems.php new file mode 100644 index 000000000..36f068cd1 --- /dev/null +++ b/app/Imports/Sales/Sheets/InvoiceItems.php @@ -0,0 +1,50 @@ +isEmpty($row, 'invoice_number')) { + return []; + } + + $row = parent::map($row); + + $row['document_id'] = (int) Document::invoice()->number($row['invoice_number'])->pluck('id')->first(); + + if (empty($row['item_id']) && !empty($row['item_name'])) { + $row['item_id'] = $this->getItemIdFromName($row); + + $row['name'] = $row['item_name']; + } + + $row['tax'] = (double) $row['tax']; + $row['tax_id'] = 0; + $row['type'] = Document::INVOICE_TYPE; + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['invoice_number'] = 'required|string'; + + unset($rules['invoice_id']); + + return $rules; + } +} diff --git a/app/Imports/Sales/Sheets/InvoiceTotals.php b/app/Imports/Sales/Sheets/InvoiceTotals.php new file mode 100644 index 000000000..0ecc65c4f --- /dev/null +++ b/app/Imports/Sales/Sheets/InvoiceTotals.php @@ -0,0 +1,41 @@ +isEmpty($row, 'invoice_number')) { + return []; + } + + $row = parent::map($row); + + $row['document_id'] = (int) Document::invoice()->number($row['invoice_number'])->pluck('id')->first(); + $row['type'] = Document::INVOICE_TYPE; + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['invoice_number'] = 'required|string'; + + unset($rules['invoice_id']); + + return $rules; + } +} diff --git a/app/Imports/Sales/Sheets/InvoiceTransactions.php b/app/Imports/Sales/Sheets/InvoiceTransactions.php new file mode 100644 index 000000000..2c5e94b11 --- /dev/null +++ b/app/Imports/Sales/Sheets/InvoiceTransactions.php @@ -0,0 +1,41 @@ +isEmpty($row, 'invoice_number')) { + return []; + } + + $row = parent::map($row); + + $row['type'] = 'income'; + $row['account_id'] = $this->getAccountId($row); + $row['category_id'] = $this->getCategoryId($row, 'income'); + $row['contact_id'] = $this->getContactId($row, 'customer'); + $row['document_id'] = $this->getDocumentId($row); + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['invoice_number'] = 'required|string'; + + return $rules; + } +} diff --git a/app/Imports/Sales/Sheets/Invoices.php b/app/Imports/Sales/Sheets/Invoices.php new file mode 100644 index 000000000..89c997505 --- /dev/null +++ b/app/Imports/Sales/Sheets/Invoices.php @@ -0,0 +1,45 @@ +isEmpty($row, 'invoice_number')) { + return []; + } + + $row = parent::map($row); + + $row['document_number'] = $row['invoice_number']; + $row['issued_at'] = $row['invoiced_at']; + $row['category_id'] = $this->getCategoryId($row, 'income'); + $row['contact_id'] = $this->getContactId($row, 'customer'); + $row['type'] = Model::INVOICE_TYPE; + + return $row; + } + + public function rules(): array + { + $rules = (new Request())->rules(); + + $rules['invoice_number'] = Str::replaceFirst('unique:documents,NULL', 'unique:documents,document_number', $rules['document_number']); + $rules['invoiced_at'] = $rules['issued_at']; + + unset($rules['document_number'], $rules['issued_at'], $rules['type']); + + return $rules; + } +} diff --git a/modules/BC21/Exports/Purchases/Bills.php b/modules/BC21/Exports/Purchases/Bills.php deleted file mode 100644 index 3741b33e7..000000000 --- a/modules/BC21/Exports/Purchases/Bills.php +++ /dev/null @@ -1,18 +0,0 @@ -