69 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\Exports\Sales\Invoices\Sheets;
2019-11-16 10:21:14 +03:00
2020-01-20 02:05:40 +03:00
use App\Abstracts\Export;
2020-12-24 01:28:38 +03:00
use App\Models\Document\Document as Model;
2021-01-27 23:13:56 +03:00
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
2020-11-13 03:07:30 +03:00
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
2019-11-16 10:21:14 +03:00
2021-01-27 23:13:56 +03:00
class Invoices extends Export implements WithColumnFormatting
2019-11-16 10:21:14 +03:00
{
public function collection()
{
return Model::with('category')->invoice()->collectForExport($this->ids, ['document_number' => 'desc']);
2019-11-16 10:21:14 +03:00
}
2020-01-20 22:58:49 +03:00
public function map($model): array
{
$country = null;
if ($model->contact_country && array_key_exists($model->contact_country, trans('countries'))) {
$country = trans('countries.' . $model->contact_country);
}
2020-01-20 22:58:49 +03:00
$model->category_name = $model->category->name;
$model->invoice_number = $model->document_number;
$model->invoiced_at = $model->issued_at;
$model->contact_country = $country;
$model->parent_number = Model::invoiceRecurring()->find($model->parent_id)?->document_number;
2020-12-24 01:28:38 +03:00
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 [
'invoice_number',
2019-11-16 10:21:14 +03:00
'order_number',
2020-01-11 16:57:32 +03:00
'status',
'invoiced_at',
2019-11-16 10:21:14 +03:00
'due_at',
'amount',
'currency_code',
'currency_rate',
2020-01-20 22:58:49 +03:00
'category_name',
2019-11-16 10:21:14 +03:00
'contact_name',
'contact_email',
'contact_tax_number',
'contact_phone',
2019-11-16 10:21:14 +03:00
'contact_address',
2021-11-08 02:40:40 +03:00
'contact_country',
'contact_state',
'contact_zip_code',
'contact_city',
2019-11-16 10:21:14 +03:00
'notes',
'footer',
'parent_number',
2019-11-16 10:21:14 +03:00
];
}
2020-11-13 03:07:30 +03:00
public function columnFormats(): array
{
return [
'D' => NumberFormat::FORMAT_DATE_YYYYMMDD,
'E' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
}