From 569f6c314f142b8982d03ec4cf923cd0f335bad1 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Mon, 20 Jan 2020 02:05:40 +0300 Subject: [PATCH] export abstract --- app/Abstracts/Export.php | 55 +++++++++++++++++++ app/Exports/Banking/Transactions.php | 35 +----------- app/Exports/Common/Items.php | 35 +----------- app/Exports/Purchases/Payments.php | 41 +------------- .../Purchases/Sheets/BillHistories.php | 36 ++---------- .../Purchases/Sheets/BillItemTaxes.php | 37 ++----------- app/Exports/Purchases/Sheets/BillItems.php | 34 ++---------- app/Exports/Purchases/Sheets/BillTotals.php | 36 ++---------- .../Purchases/Sheets/BillTransactions.php | 45 ++------------- app/Exports/Purchases/Sheets/Bills.php | 46 +--------------- app/Exports/Purchases/Vendors.php | 38 +------------ app/Exports/Sales/Customers.php | 38 +------------ app/Exports/Sales/Revenues.php | 41 +------------- app/Exports/Sales/Sheets/InvoiceHistories.php | 36 ++---------- app/Exports/Sales/Sheets/InvoiceItemTaxes.php | 37 ++----------- app/Exports/Sales/Sheets/InvoiceItems.php | 39 ++----------- app/Exports/Sales/Sheets/InvoiceTotals.php | 37 ++----------- .../Sales/Sheets/InvoiceTransactions.php | 45 ++------------- app/Exports/Sales/Sheets/Invoices.php | 46 +--------------- 19 files changed, 129 insertions(+), 628 deletions(-) create mode 100644 app/Abstracts/Export.php diff --git a/app/Abstracts/Export.php b/app/Abstracts/Export.php new file mode 100644 index 000000000..42ee10d06 --- /dev/null +++ b/app/Abstracts/Export.php @@ -0,0 +1,55 @@ +ids = $ids; + } + + public function title(): string + { + return Str::snake((new \ReflectionClass($this))->getShortName()); + } + + public function fields(): array + { + return []; + } + + public function map($model): array + { + $map = []; + + $date_fields = ['paid_at', 'invoiced_at', 'billed_at', 'due_at', 'issued_at', 'created_at']; + + foreach ($this->fields() as $field) { + $value = $model->$field; + + if (in_array($field, $date_fields)) { + $value = Date::parse($value)->format('Y-m-d'); + } + + $map[] = $value; + } + + return $map; + } + + public function headings(): array + { + return $this->fields(); + } +} diff --git a/app/Exports/Banking/Transactions.php b/app/Exports/Banking/Transactions.php index 23df77af7..d991e6a22 100644 --- a/app/Exports/Banking/Transactions.php +++ b/app/Exports/Banking/Transactions.php @@ -2,41 +2,17 @@ namespace App\Exports\Banking; +use App\Abstracts\Export; use App\Models\Banking\Transaction as Model; -use Jenssegers\Date\Date; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class Transactions implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class Transactions extends Export { public function collection() { return Model::usingSearchString(request('search'))->get(); } - public function map($model): array - { - return [ - $model->type, - Date::parse($model->paid_at)->format('Y-m-d'), - $model->amount, - $model->currency_code, - $model->currency_rate, - $model->account_id, - $model->document_id, - $model->contact_id, - $model->category_id, - $model->description, - $model->payment_method, - $model->reference, - $model->reconciled, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'type', @@ -54,9 +30,4 @@ class Transactions implements FromCollection, ShouldAutoSize, WithHeadings, With 'reconciled', ]; } - - public function title(): string - { - return 'transactions'; - } } diff --git a/app/Exports/Common/Items.php b/app/Exports/Common/Items.php index f13b60008..6c7bd6127 100644 --- a/app/Exports/Common/Items.php +++ b/app/Exports/Common/Items.php @@ -2,22 +2,11 @@ namespace App\Exports\Common; +use App\Abstracts\Export; use App\Models\Common\Item as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class Items implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class Items extends Export { - public $ids; - - public function __construct($ids = null) - { - $this->ids = $ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); @@ -29,20 +18,7 @@ class Items implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping return $model->get(); } - public function map($model): array - { - return [ - $model->name, - $model->description, - $model->sale_price, - $model->purchase_price, - $model->category_id, - $model->tax_id, - $model->enabled, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'name', @@ -54,9 +30,4 @@ class Items implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping 'enabled', ]; } - - public function title(): string - { - return 'items'; - } } diff --git a/app/Exports/Purchases/Payments.php b/app/Exports/Purchases/Payments.php index 7b9deae7c..48a1a8288 100644 --- a/app/Exports/Purchases/Payments.php +++ b/app/Exports/Purchases/Payments.php @@ -2,23 +2,11 @@ namespace App\Exports\Purchases; +use App\Abstracts\Export; use App\Models\Banking\Transaction as Model; -use Jenssegers\Date\Date; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class Payments implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class Payments extends Export { - public $ids; - - public function __construct($ids = null) - { - $this->ids = $ids; - } - public function collection() { $model = Model::type('expense')->usingSearchString(request('search')); @@ -30,25 +18,7 @@ class Payments implements FromCollection, ShouldAutoSize, WithHeadings, WithMapp return $model->get(); } - public function map($model): array - { - return [ - Date::parse($model->paid_at)->format('Y-m-d'), - $model->amount, - $model->currency_code, - $model->currency_rate, - $model->account_id, - $model->document_id, - $model->contact_id, - $model->category_id, - $model->description, - $model->payment_method, - $model->reference, - $model->reconciled, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'paid_at', @@ -65,9 +35,4 @@ class Payments implements FromCollection, ShouldAutoSize, WithHeadings, WithMapp 'reconciled', ]; } - - public function title(): string - { - return 'payments'; - } } diff --git a/app/Exports/Purchases/Sheets/BillHistories.php b/app/Exports/Purchases/Sheets/BillHistories.php index e0703bd0f..177bfbd9c 100644 --- a/app/Exports/Purchases/Sheets/BillHistories.php +++ b/app/Exports/Purchases/Sheets/BillHistories.php @@ -2,44 +2,23 @@ namespace App\Exports\Purchases\Sheets; +use App\Abstracts\Export; use App\Models\Purchase\BillHistory as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class BillHistories implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class BillHistories extends Export { - public $bill_ids; - - public function __construct($bill_ids = null) - { - $this->bill_ids = $bill_ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); - if (!empty($this->bill_ids)) { - $model->whereIn('bill_id', (array) $this->bill_ids); + if (!empty($this->ids)) { + $model->whereIn('bill_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - $model->bill_id, - $model->status, - $model->notify, - $model->description, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'bill_id', @@ -48,9 +27,4 @@ class BillHistories implements FromCollection, ShouldAutoSize, WithHeadings, Wit 'description', ]; } - - public function title(): string - { - return 'bill_histories'; - } } diff --git a/app/Exports/Purchases/Sheets/BillItemTaxes.php b/app/Exports/Purchases/Sheets/BillItemTaxes.php index 21413344b..46ff81c08 100644 --- a/app/Exports/Purchases/Sheets/BillItemTaxes.php +++ b/app/Exports/Purchases/Sheets/BillItemTaxes.php @@ -2,45 +2,23 @@ namespace App\Exports\Purchases\Sheets; +use App\Abstracts\Export; use App\Models\Purchase\BillItemTax as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class BillItemTaxes implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class BillItemTaxes extends Export { - public $bill_ids; - - public function __construct($bill_ids = null) - { - $this->bill_ids = $bill_ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); - if (!empty($this->bill_ids)) { - $model->whereIn('bill_id', (array) $this->bill_ids); + if (!empty($this->ids)) { + $model->whereIn('bill_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - $model->bill_id, - $model->bill_item_id, - $model->tax_id, - $model->name, - $model->amount, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'bill_id', @@ -50,9 +28,4 @@ class BillItemTaxes implements FromCollection, ShouldAutoSize, WithHeadings, Wit 'amount', ]; } - - public function title(): string - { - return 'bill_item_taxes'; - } } diff --git a/app/Exports/Purchases/Sheets/BillItems.php b/app/Exports/Purchases/Sheets/BillItems.php index 50444dc87..aa847e6cc 100644 --- a/app/Exports/Purchases/Sheets/BillItems.php +++ b/app/Exports/Purchases/Sheets/BillItems.php @@ -2,6 +2,7 @@ namespace App\Exports\Purchases\Sheets; +use App\Abstracts\Export; use App\Models\Purchase\BillItem as Model; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; @@ -9,40 +10,20 @@ use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithTitle; -class BillItems implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class BillItems extends Export { - public $bill_ids; - - public function __construct($bill_ids = null) - { - $this->bill_ids = $bill_ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); - if (!empty($this->bill_ids)) { - $model->whereIn('bill_id', (array) $this->bill_ids); + if (!empty($this->ids)) { + $model->whereIn('bill_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - $model->bill_id, - $model->item_id, - $model->name, - $model->quantity, - $model->price, - $model->total, - $model->tax, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'bill_id', @@ -54,9 +35,4 @@ class BillItems implements FromCollection, ShouldAutoSize, WithHeadings, WithMap 'tax', ]; } - - public function title(): string - { - return 'bill_items'; - } } diff --git a/app/Exports/Purchases/Sheets/BillTotals.php b/app/Exports/Purchases/Sheets/BillTotals.php index 6ca68395f..2cc0ea82f 100644 --- a/app/Exports/Purchases/Sheets/BillTotals.php +++ b/app/Exports/Purchases/Sheets/BillTotals.php @@ -2,45 +2,24 @@ namespace App\Exports\Purchases\Sheets; +use App\Abstracts\Export; use App\Models\Purchase\BillTotal as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class BillTotals implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class BillTotals extends Export { - public $bill_ids; - - public function __construct($bill_ids = null) - { - $this->bill_ids = $bill_ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); - if (!empty($this->bill_ids)) { - $model->whereIn('bill_id', (array) $this->bill_ids); + if (!empty($this->ids)) { + $model->whereIn('bill_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - $model->bill_id, - $model->code, - $model->name, - $model->amount, - $model->sort_order, - ]; - } - public function headings(): array + public function fields(): array { return [ 'bill_id', @@ -50,9 +29,4 @@ class BillTotals implements FromCollection, ShouldAutoSize, WithHeadings, WithMa 'sort_order', ]; } - - public function title(): string - { - return 'bill_totals'; - } } diff --git a/app/Exports/Purchases/Sheets/BillTransactions.php b/app/Exports/Purchases/Sheets/BillTransactions.php index c3eeb2421..7325ad2b6 100644 --- a/app/Exports/Purchases/Sheets/BillTransactions.php +++ b/app/Exports/Purchases/Sheets/BillTransactions.php @@ -2,53 +2,23 @@ namespace App\Exports\Purchases\Sheets; +use App\Abstracts\Export; use App\Models\Banking\Transaction as Model; -use Jenssegers\Date\Date; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class BillTransactions implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class BillTransactions extends Export { - public $bill_ids; - - public function __construct($bill_ids = null) - { - $this->bill_ids = $bill_ids; - } - public function collection() { $model = Model::type('expense')->isDocument()->usingSearchString(request('search')); - if (!empty($this->bill_ids)) { - $model->whereIn('document_id', (array) $this->bill_ids); + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - Date::parse($model->paid_at)->format('Y-m-d'), - $model->amount, - $model->currency_code, - $model->currency_rate, - $model->account_id, - $model->document_id, - $model->contact_id, - $model->category_id, - $model->description, - $model->payment_method, - $model->reference, - $model->reconciled, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'paid_at', @@ -65,9 +35,4 @@ class BillTransactions implements FromCollection, ShouldAutoSize, WithHeadings, 'reconciled', ]; } - - public function title(): string - { - return 'bill_transactions'; - } } diff --git a/app/Exports/Purchases/Sheets/Bills.php b/app/Exports/Purchases/Sheets/Bills.php index 06a93a897..6e674c6aa 100644 --- a/app/Exports/Purchases/Sheets/Bills.php +++ b/app/Exports/Purchases/Sheets/Bills.php @@ -2,23 +2,11 @@ namespace App\Exports\Purchases\Sheets; +use App\Abstracts\Export; use App\Models\Purchase\Bill as Model; -use Jenssegers\Date\Date; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class Bills implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class Bills extends Export { - public $ids; - - public function __construct($ids = null) - { - $this->ids = $ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); @@ -30,30 +18,7 @@ class Bills implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping return $model->get(); } - public function map($model): array - { - return [ - $model->bill_number, - $model->order_number, - $model->status, - Date::parse($model->billed_at)->format('Y-m-d'), - Date::parse($model->due_at)->format('Y-m-d'), - $model->amount, - $model->currency_code, - $model->currency_rate, - $model->category_id, - $model->contact_id, - $model->contact_name, - $model->contact_email, - $model->contact_tax_number, - $model->contact_phone, - $model->contact_address, - $model->notes, - $model->footer, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'bill_number', @@ -75,9 +40,4 @@ class Bills implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping 'footer', ]; } - - public function title(): string - { - return 'bills'; - } } diff --git a/app/Exports/Purchases/Vendors.php b/app/Exports/Purchases/Vendors.php index f0e5ef763..061c24503 100644 --- a/app/Exports/Purchases/Vendors.php +++ b/app/Exports/Purchases/Vendors.php @@ -2,22 +2,11 @@ namespace App\Exports\Purchases; +use App\Abstracts\Export; use App\Models\Common\Contact as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class Vendors implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class Vendors extends Export { - public $ids; - - public function __construct($ids = null) - { - $this->ids = $ids; - } - public function collection() { $model = Model::type('vendor')->usingSearchString(request('search')); @@ -29,23 +18,7 @@ class Vendors implements FromCollection, ShouldAutoSize, WithHeadings, WithMappi return $model->get(); } - public function map($model): array - { - return [ - $model->name, - $model->email, - $model->tax_number, - $model->phone, - $model->address, - $model->website, - $model->currency_code, - $model->reference, - $model->enabled, - $model->user_id, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'name', @@ -60,9 +33,4 @@ class Vendors implements FromCollection, ShouldAutoSize, WithHeadings, WithMappi 'user_id', ]; } - - public function title(): string - { - return 'vendors'; - } } diff --git a/app/Exports/Sales/Customers.php b/app/Exports/Sales/Customers.php index 850316567..90defda81 100644 --- a/app/Exports/Sales/Customers.php +++ b/app/Exports/Sales/Customers.php @@ -2,22 +2,11 @@ namespace App\Exports\Sales; +use App\Abstracts\Export; use App\Models\Common\Contact as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class Customers implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class Customers extends Export { - public $ids; - - public function __construct($ids = null) - { - $this->ids = $ids; - } - public function collection() { $model = Model::type('customer')->usingSearchString(request('search')); @@ -29,23 +18,7 @@ class Customers implements FromCollection, ShouldAutoSize, WithHeadings, WithMap return $model->get(); } - public function map($model): array - { - return [ - $model->name, - $model->email, - $model->tax_number, - $model->phone, - $model->address, - $model->website, - $model->currency_code, - $model->reference, - $model->enabled, - $model->user_id, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'name', @@ -60,9 +33,4 @@ class Customers implements FromCollection, ShouldAutoSize, WithHeadings, WithMap 'user_id', ]; } - - public function title(): string - { - return 'customers'; - } } diff --git a/app/Exports/Sales/Revenues.php b/app/Exports/Sales/Revenues.php index 5211006eb..dd592bcbf 100644 --- a/app/Exports/Sales/Revenues.php +++ b/app/Exports/Sales/Revenues.php @@ -2,23 +2,11 @@ namespace App\Exports\Sales; +use App\Abstracts\Export; use App\Models\Banking\Transaction as Model; -use Jenssegers\Date\Date; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class Revenues implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class Revenues extends Export { - public $ids; - - public function __construct($ids = null) - { - $this->ids = $ids; - } - public function collection() { $model = Model::type('income')->usingSearchString(request('search')); @@ -30,25 +18,7 @@ class Revenues implements FromCollection, ShouldAutoSize, WithHeadings, WithMapp return $model->get(); } - public function map($model): array - { - return [ - Date::parse($model->paid_at)->format('Y-m-d'), - $model->amount, - $model->currency_code, - $model->currency_rate, - $model->account_id, - $model->document_id, - $model->contact_id, - $model->category_id, - $model->description, - $model->payment_method, - $model->reference, - $model->reconciled, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'paid_at', @@ -65,9 +35,4 @@ class Revenues implements FromCollection, ShouldAutoSize, WithHeadings, WithMapp 'reconciled', ]; } - - public function title(): string - { - return 'revenues'; - } } diff --git a/app/Exports/Sales/Sheets/InvoiceHistories.php b/app/Exports/Sales/Sheets/InvoiceHistories.php index 3de04f568..7acdc0475 100644 --- a/app/Exports/Sales/Sheets/InvoiceHistories.php +++ b/app/Exports/Sales/Sheets/InvoiceHistories.php @@ -2,44 +2,23 @@ namespace App\Exports\Sales\Sheets; +use App\Abstracts\Export; use App\Models\Sale\InvoiceHistory as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class InvoiceHistories implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class InvoiceHistories extends Export { - public $invoice_ids; - - public function __construct($invoice_ids = null) - { - $this->invoice_ids = $invoice_ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); - if (!empty($this->invoice_ids)) { - $model->whereIn('invoice_id', (array) $this->invoice_ids); + if (!empty($this->ids)) { + $model->whereIn('invoice_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - $model->invoice_id, - $model->status, - $model->notify, - $model->description, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'invoice_id', @@ -48,9 +27,4 @@ class InvoiceHistories implements FromCollection, ShouldAutoSize, WithHeadings, 'description', ]; } - - public function title(): string - { - return 'invoice_histories'; - } } diff --git a/app/Exports/Sales/Sheets/InvoiceItemTaxes.php b/app/Exports/Sales/Sheets/InvoiceItemTaxes.php index 533089cd0..e5ff48592 100644 --- a/app/Exports/Sales/Sheets/InvoiceItemTaxes.php +++ b/app/Exports/Sales/Sheets/InvoiceItemTaxes.php @@ -2,45 +2,23 @@ namespace App\Exports\Sales\Sheets; +use App\Abstracts\Export; use App\Models\Sale\InvoiceItemTax as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class InvoiceItemTaxes implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class InvoiceItemTaxes extends Export { - public $invoice_ids; - - public function __construct($invoice_ids = null) - { - $this->invoice_ids = $invoice_ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); - if (!empty($this->invoice_ids)) { - $model->whereIn('invoice_id', (array) $this->invoice_ids); + if (!empty($this->ids)) { + $model->whereIn('invoice_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - $model->invoice_id, - $model->invoice_item_id, - $model->tax_id, - $model->name, - $model->amount, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'invoice_id', @@ -50,9 +28,4 @@ class InvoiceItemTaxes implements FromCollection, ShouldAutoSize, WithHeadings, 'amount', ]; } - - public function title(): string - { - return 'invoice_item_taxes'; - } } diff --git a/app/Exports/Sales/Sheets/InvoiceItems.php b/app/Exports/Sales/Sheets/InvoiceItems.php index 7c166fa10..bcbe876e5 100644 --- a/app/Exports/Sales/Sheets/InvoiceItems.php +++ b/app/Exports/Sales/Sheets/InvoiceItems.php @@ -2,47 +2,23 @@ namespace App\Exports\Sales\Sheets; +use App\Abstracts\Export; use App\Models\Sale\InvoiceItem as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class InvoiceItems implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class InvoiceItems extends Export { - public $invoice_ids; - - public function __construct($invoice_ids = null) - { - $this->invoice_ids = $invoice_ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); - if (!empty($this->invoice_ids)) { - $model->whereIn('invoice_id', (array) $this->invoice_ids); + if (!empty($this->ids)) { + $model->whereIn('invoice_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - $model->invoice_id, - $model->item_id, - $model->name, - $model->quantity, - $model->price, - $model->total, - $model->tax, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'invoice_id', @@ -54,9 +30,4 @@ class InvoiceItems implements FromCollection, ShouldAutoSize, WithHeadings, With 'tax', ]; } - - public function title(): string - { - return 'invoice_items'; - } } diff --git a/app/Exports/Sales/Sheets/InvoiceTotals.php b/app/Exports/Sales/Sheets/InvoiceTotals.php index ee02f6843..461d95517 100644 --- a/app/Exports/Sales/Sheets/InvoiceTotals.php +++ b/app/Exports/Sales/Sheets/InvoiceTotals.php @@ -2,45 +2,23 @@ namespace App\Exports\Sales\Sheets; +use App\Abstracts\Export; use App\Models\Sale\InvoiceTotal as Model; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class InvoiceTotals implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class InvoiceTotals extends Export { - public $invoice_ids; - - public function __construct($invoice_ids = null) - { - $this->invoice_ids = $invoice_ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); - if (!empty($this->invoice_ids)) { - $model->whereIn('invoice_id', (array) $this->invoice_ids); + if (!empty($this->ids)) { + $model->whereIn('invoice_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - $model->invoice_id, - $model->code, - $model->name, - $model->amount, - $model->sort_order, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'invoice_id', @@ -50,9 +28,4 @@ class InvoiceTotals implements FromCollection, ShouldAutoSize, WithHeadings, Wit 'sort_order', ]; } - - public function title(): string - { - return 'invoice_totals'; - } } diff --git a/app/Exports/Sales/Sheets/InvoiceTransactions.php b/app/Exports/Sales/Sheets/InvoiceTransactions.php index e6182d2d5..7a3beb61c 100644 --- a/app/Exports/Sales/Sheets/InvoiceTransactions.php +++ b/app/Exports/Sales/Sheets/InvoiceTransactions.php @@ -2,53 +2,23 @@ namespace App\Exports\Sales\Sheets; +use App\Abstracts\Export; use App\Models\Banking\Transaction as Model; -use Jenssegers\Date\Date; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class InvoiceTransactions implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class InvoiceTransactions extends Export { - public $invoice_ids; - - public function __construct($invoice_ids = null) - { - $this->invoice_ids = $invoice_ids; - } - public function collection() { $model = Model::type('income')->isDocument()->usingSearchString(request('search')); - if (!empty($this->invoice_ids)) { - $model->whereIn('document_id', (array) $this->invoice_ids); + if (!empty($this->ids)) { + $model->whereIn('document_id', (array) $this->ids); } return $model->get(); } - public function map($model): array - { - return [ - Date::parse($model->paid_at)->format('Y-m-d'), - $model->amount, - $model->currency_code, - $model->currency_rate, - $model->account_id, - $model->document_id, - $model->contact_id, - $model->category_id, - $model->description, - $model->payment_method, - $model->reference, - $model->reconciled, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'paid_at', @@ -65,9 +35,4 @@ class InvoiceTransactions implements FromCollection, ShouldAutoSize, WithHeading 'reconciled', ]; } - - public function title(): string - { - return 'invoice_transactions'; - } } diff --git a/app/Exports/Sales/Sheets/Invoices.php b/app/Exports/Sales/Sheets/Invoices.php index bd48703d5..de56cebde 100644 --- a/app/Exports/Sales/Sheets/Invoices.php +++ b/app/Exports/Sales/Sheets/Invoices.php @@ -2,23 +2,11 @@ namespace App\Exports\Sales\Sheets; +use App\Abstracts\Export; use App\Models\Sale\Invoice as Model; -use Jenssegers\Date\Date; -use Maatwebsite\Excel\Concerns\FromCollection; -use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use Maatwebsite\Excel\Concerns\WithHeadings; -use Maatwebsite\Excel\Concerns\WithMapping; -use Maatwebsite\Excel\Concerns\WithTitle; -class Invoices implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping, WithTitle +class Invoices extends Export { - public $ids; - - public function __construct($ids = null) - { - $this->ids = $ids; - } - public function collection() { $model = Model::usingSearchString(request('search')); @@ -30,30 +18,7 @@ class Invoices implements FromCollection, ShouldAutoSize, WithHeadings, WithMapp return $model->get(); } - public function map($model): array - { - return [ - $model->invoice_number, - $model->order_number, - $model->status, - Date::parse($model->invoiced_at)->format('Y-m-d'), - Date::parse($model->due_at)->format('Y-m-d'), - $model->amount, - $model->currency_code, - $model->currency_rate, - $model->category_id, - $model->contact_id, - $model->contact_name, - $model->contact_email, - $model->contact_tax_number, - $model->contact_phone, - $model->contact_address, - $model->notes, - $model->footer, - ]; - } - - public function headings(): array + public function fields(): array { return [ 'invoice_number', @@ -75,9 +40,4 @@ class Invoices implements FromCollection, ShouldAutoSize, WithHeadings, WithMapp 'footer', ]; } - - public function title(): string - { - return 'invoices'; - } }