akaunting/app/Exports/Sales/Sheets/InvoiceTotals.php

45 lines
863 B
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
2019-12-31 15:49:09 +03:00
namespace App\Exports\Sales\Sheets;
2019-11-16 10:21:14 +03:00
2020-01-20 02:05:40 +03:00
use App\Abstracts\Export;
2019-12-31 15:49:09 +03:00
use App\Models\Sale\InvoiceTotal as Model;
2019-11-16 10:21:14 +03:00
2020-01-20 02:05:40 +03:00
class InvoiceTotals extends Export
2019-11-16 10:21:14 +03:00
{
public function collection()
{
2020-01-20 22:58:49 +03:00
$model = Model::with(['invoice'])->usingSearchString(request('search'));
2019-11-16 10:21:14 +03:00
2020-01-20 02:05:40 +03:00
if (!empty($this->ids)) {
$model->whereIn('invoice_id', (array) $this->ids);
2019-11-16 10:21:14 +03:00
}
return $model->get();
}
2020-01-20 22:58:49 +03:00
public function map($model): array
{
2020-02-21 21:37:48 +03:00
$invoice = $model->invoice;
if (empty($invoice)) {
return [];
}
$model->invoice_number = $invoice->invoice_number;
2020-01-20 22:58:49 +03:00
return parent::map($model);
}
2020-01-20 02:05:40 +03:00
public function fields(): array
2019-11-16 10:21:14 +03:00
{
return [
2020-01-20 22:58:49 +03:00
'invoice_number',
2019-11-16 10:21:14 +03:00
'code',
'name',
'amount',
'sort_order',
];
}
2020-01-20 00:21:37 +03:00
}