akaunting/app/Exports/Sales/Revenues.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2019-11-16 07:21:14 +00:00
<?php
2019-12-31 12:49:09 +00:00
namespace App\Exports\Sales;
2019-11-16 07:21:14 +00:00
2020-01-19 23:05:40 +00:00
use App\Abstracts\Export;
2019-11-16 07:21:14 +00:00
use App\Models\Banking\Transaction as Model;
2021-02-15 19:58:58 +00:00
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
2019-11-16 07:21:14 +00:00
2021-02-15 19:58:58 +00:00
class Revenues extends Export implements WithColumnFormatting
2019-11-16 07:21:14 +00:00
{
public function collection()
{
2021-06-27 08:40:46 +00:00
return Model::with('account', 'category', 'contact', 'invoice')->income()->collectForExport($this->ids, ['paid_at' => 'desc']);
2019-11-16 07:21:14 +00:00
}
2020-01-20 20:50:19 +00:00
public function map($model): array
{
$model->account_name = $model->account->name;
2020-12-23 22:28:38 +00:00
$model->invoice_number = $model->invoice->document_number ?? 0;
2020-01-20 20:50:19 +00:00
$model->contact_email = $model->contact->email;
$model->category_name = $model->category->name;
return parent::map($model);
}
2020-01-19 23:05:40 +00:00
public function fields(): array
2019-11-16 07:21:14 +00:00
{
return [
'paid_at',
'amount',
'currency_code',
'currency_rate',
2020-01-20 20:50:19 +00:00
'account_name',
'invoice_number',
'contact_email',
'category_name',
2020-01-19 21:21:37 +00:00
'description',
2019-11-16 07:21:14 +00:00
'payment_method',
2020-01-19 21:21:37 +00:00
'reference',
2019-11-16 07:21:14 +00:00
'reconciled',
];
}
2021-02-15 19:58:58 +00:00
public function columnFormats(): array
{
return [
'A' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
2020-01-19 21:21:37 +00:00
}