2020-12-24 01:28:38 +03:00
|
|
|
<?php
|
|
|
|
|
2020-12-25 19:25:38 +03:00
|
|
|
namespace App\Imports\Purchases\Sheets;
|
2020-12-24 01:28:38 +03:00
|
|
|
|
|
|
|
use App\Abstracts\Import;
|
|
|
|
use App\Http\Requests\Document\DocumentItemTax as Request;
|
|
|
|
use App\Models\Common\Item;
|
|
|
|
use App\Models\Document\Document;
|
|
|
|
use App\Models\Document\DocumentItem;
|
|
|
|
use App\Models\Document\DocumentItemTax as Model;
|
|
|
|
|
2020-12-25 19:25:38 +03:00
|
|
|
class BillItemTaxes extends Import
|
2020-12-24 01:28:38 +03:00
|
|
|
{
|
2023-03-07 15:18:14 +03:00
|
|
|
public $request_class = Request::class;
|
|
|
|
|
2020-12-24 01:28:38 +03:00
|
|
|
public function model(array $row)
|
|
|
|
{
|
|
|
|
return new Model($row);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function map($row): array
|
|
|
|
{
|
2020-12-25 19:25:38 +03:00
|
|
|
if ($this->isEmpty($row, 'bill_number')) {
|
2020-12-24 01:28:38 +03:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2023-02-20 13:00:59 +03:00
|
|
|
$row['bill_number'] = (string) $row['bill_number'];
|
|
|
|
|
2020-12-24 01:28:38 +03:00
|
|
|
$row = parent::map($row);
|
|
|
|
|
2020-12-25 19:25:38 +03:00
|
|
|
$row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first();
|
2020-12-24 01:28:38 +03:00
|
|
|
|
2021-01-28 15:37:54 +03:00
|
|
|
if (empty($row['document_item_id']) && !empty($row['item_name'])) {
|
2020-12-24 01:28:38 +03:00
|
|
|
$item_id = Item::name($row['item_name'])->pluck('id')->first();
|
2021-01-28 15:37:54 +03:00
|
|
|
$row['document_item_id'] = DocumentItem::bill()->where('item_id', $item_id)->pluck('id')->first();
|
2020-12-24 01:28:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$row['tax_id'] = $this->getTaxId($row);
|
|
|
|
|
|
|
|
if (empty($row['name']) && !empty($row['item_name'])) {
|
|
|
|
$row['name'] = $row['item_name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$row['amount'] = (double) $row['amount'];
|
|
|
|
|
2020-12-25 19:25:38 +03:00
|
|
|
$row['type'] = Document::BILL_TYPE;
|
2020-12-24 01:28:38 +03:00
|
|
|
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2023-03-07 15:18:14 +03:00
|
|
|
public function prepareRules(array $rules): array
|
2020-12-24 01:28:38 +03:00
|
|
|
{
|
2020-12-25 19:25:38 +03:00
|
|
|
$rules['bill_number'] = 'required|string';
|
2020-12-24 01:28:38 +03:00
|
|
|
|
2020-12-25 19:25:38 +03:00
|
|
|
unset($rules['bill_id']);
|
2020-12-24 01:28:38 +03:00
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|