akaunting/app/Imports/Banking/Transactions.php

54 lines
1.2 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\Imports\Banking;
2020-01-20 01:26:35 +03:00
use App\Abstracts\Import;
2019-11-16 10:21:14 +03:00
use App\Http\Requests\Banking\Transaction as Request;
2020-01-21 09:10:12 +03:00
use App\Models\Banking\Transaction as Model;
2023-07-24 14:37:03 +03:00
use App\Traits\Transactions as TraitsTransactions;
2019-11-16 10:21:14 +03:00
2020-01-20 01:26:35 +03:00
class Transactions extends Import
2019-11-16 10:21:14 +03:00
{
2023-07-24 14:37:03 +03:00
use TraitsTransactions;
2023-08-16 18:18:17 +03:00
public $model = Model::class;
2023-03-07 15:18:14 +03:00
public $request_class = Request::class;
2023-08-16 18:18:17 +03:00
public $columns = [
'number',
];
2019-11-16 10:21:14 +03:00
public function model(array $row)
{
2023-08-16 18:18:17 +03:00
if (self::hasRow($row)) {
return;
}
2019-11-16 10:21:14 +03:00
return new Model($row);
}
2020-01-21 09:10:12 +03:00
public function map($row): array
{
$row = parent::map($row);
2023-07-24 14:37:03 +03:00
$real_type = $this->getRealTypeTransaction($row['type']);
2023-02-08 01:37:55 +03:00
$row['currency_code'] = $this->getCurrencyCode($row);
2020-01-21 09:10:12 +03:00
$row['account_id'] = $this->getAccountId($row);
2023-07-24 14:37:03 +03:00
$row['category_id'] = $this->getCategoryId($row, $real_type);
$row['contact_id'] = $this->getContactId($row, $real_type);
2020-01-21 09:10:12 +03:00
$row['document_id'] = $this->getDocumentId($row);
2023-08-16 18:18:17 +03:00
$row['parent_id'] = $this->getParentId($row) ?? 0;
2020-01-21 09:10:12 +03:00
return $row;
}
2023-08-16 18:18:17 +03:00
public function prepareRules($rules): array
{
$rules['number'] = 'required|string';
return $rules;
}
2020-01-20 01:26:35 +03:00
}