Akaunting/app/Imports/Sales/Invoices/Sheets/InvoiceTransactions.php

59 lines
1.4 KiB
PHP
Raw Normal View History

2020-01-20 19:58:49 +00:00
<?php
namespace App\Imports\Sales\Invoices\Sheets;
2020-01-20 19:58:49 +00:00
use App\Abstracts\Import;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Banking\Transaction as Model;
use App\Models\Setting\Category;
2020-01-20 19:58:49 +00:00
class InvoiceTransactions extends Import
{
2023-03-07 12:18:14 +00:00
public $request_class = Request::class;
2024-02-22 14:02:57 +00:00
public $model = Model::class;
public $columns = [
'type',
'number',
];
2020-01-20 19:58:49 +00:00
public function model(array $row)
{
2024-02-22 14:02:57 +00:00
if (self::hasRow($row)) {
return;
}
2020-01-20 19:58:49 +00:00
return new Model($row);
}
2024-02-22 14:02:57 +00:00
2020-01-20 19:58:49 +00:00
public function map($row): array
{
2020-02-25 11:56:48 +00:00
if ($this->isEmpty($row, 'invoice_number')) {
return [];
}
$row['invoice_number'] = (string) $row['invoice_number'];
2020-01-20 19:58:49 +00:00
$row = parent::map($row);
$row['type'] = Model::INCOME_TYPE;
2023-03-07 12:18:14 +00:00
$row['currency_code'] = $this->getCurrencyCode($row);
2020-01-21 06:10:12 +00:00
$row['account_id'] = $this->getAccountId($row);
$row['category_id'] = $this->getCategoryId($row, Category::INCOME_TYPE);
2020-01-21 06:10:12 +00:00
$row['contact_id'] = $this->getContactId($row, 'customer');
$row['document_id'] = $this->getDocumentId($row);
2022-06-01 07:15:55 +00:00
$row['number'] = $row['transaction_number'];
2020-01-20 19:58:49 +00:00
return $row;
}
2023-03-07 12:18:14 +00:00
public function prepareRules(array $rules): array
2020-01-20 19:58:49 +00:00
{
$rules['invoice_number'] = 'required|string';
return $rules;
}
}