2020-01-20 19:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-08-14 14:23:01 +00:00
|
|
|
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;
|
2026-03-09 19:45:01 +00:00
|
|
|
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 [];
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 10:00:59 +00:00
|
|
|
$row['invoice_number'] = (string) $row['invoice_number'];
|
|
|
|
|
|
2020-01-20 19:58:49 +00:00
|
|
|
$row = parent::map($row);
|
|
|
|
|
|
2026-03-09 19:45:01 +00:00
|
|
|
$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);
|
2026-03-09 19:45:01 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
}
|