Akaunting/app/Exports/Purchases/Sheets/BillTransactions.php

60 lines
1.5 KiB
PHP
Raw Normal View History

2019-11-16 07:21:14 +00:00
<?php
namespace App\Exports\Purchases\Sheets;
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;
2020-11-13 00:07:30 +00:00
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
2019-11-16 07:21:14 +00:00
class BillTransactions 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', 'document')->expense()->isDocument()->collectForExport($this->ids, ['paid_at' => 'desc'], 'document_id');
2019-11-16 07:21:14 +00:00
}
2020-01-21 06:55:12 +00:00
public function map($model): array
{
2020-12-23 22:28:38 +00:00
$document = $model->document;
2020-02-21 18:37:48 +00:00
2020-12-23 22:28:38 +00:00
if (empty($document)) {
2020-02-21 18:37:48 +00:00
return [];
}
$model->bill_number = $document->document_number;
2020-01-21 06:55:12 +00:00
$model->account_name = $model->account->name;
$model->category_name = $model->category->name;
$model->contact_email = $model->contact->email;
2022-06-01 07:15:55 +00:00
$model->transaction_number = $model->number;
2020-01-21 06:55:12 +00:00
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 [
'bill_number',
2022-06-01 07:15:55 +00:00
'transaction_number',
2019-11-16 07:21:14 +00:00
'paid_at',
'amount',
'currency_code',
'currency_rate',
2020-01-21 06:55:12 +00:00
'account_name',
'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',
];
}
2020-11-13 00:07:30 +00:00
public function columnFormats(): array
{
return [
'B' => NumberFormat::FORMAT_DATE_YYYYMMDD,
];
}
2020-01-19 21:21:37 +00:00
}