74 lines
1.7 KiB
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\Purchases;
2019-11-16 10:21:14 +03:00
use App\Models\Banking\Transaction as Model;
2020-01-20 00:21:37 +03:00
use Jenssegers\Date\Date;
2019-11-16 10:21:14 +03:00
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
{
public $ids;
public function __construct($ids = null)
{
$this->ids = $ids;
}
public function collection()
{
$model = Model::type('expense')->usingSearchString(request('search'));
if (!empty($this->ids)) {
$model->whereIn('id', (array) $this->ids);
}
return $model->get();
}
public function map($model): array
{
return [
2020-01-20 00:21:37 +03:00
Date::parse($model->paid_at)->format('Y-m-d'),
2019-11-16 10:21:14 +03:00
$model->amount,
$model->currency_code,
$model->currency_rate,
2020-01-20 00:21:37 +03:00
$model->account_id,
2019-11-16 10:21:14 +03:00
$model->document_id,
$model->contact_id,
2020-01-20 00:21:37 +03:00
$model->category_id,
$model->description,
2019-11-16 10:21:14 +03:00
$model->payment_method,
2020-01-20 00:21:37 +03:00
$model->reference,
2019-11-16 10:21:14 +03:00
$model->reconciled,
];
}
public function headings(): array
{
return [
'paid_at',
'amount',
'currency_code',
'currency_rate',
2020-01-20 00:21:37 +03:00
'account_id',
2019-11-16 10:21:14 +03:00
'document_id',
'contact_id',
2020-01-20 00:21:37 +03:00
'category_id',
'description',
2019-11-16 10:21:14 +03:00
'payment_method',
2020-01-20 00:21:37 +03:00
'reference',
2019-11-16 10:21:14 +03:00
'reconciled',
];
}
public function title(): string
{
return 'payments';
}
2020-01-20 00:21:37 +03:00
}