Seperate Document Import/Export files into Invoice/Bill
This commit is contained in:
50
app/Imports/Purchases/Sheets/BillItems.php
Normal file
50
app/Imports/Purchases/Sheets/BillItems.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Document\DocumentItem as Request;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
|
||||
class BillItems extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
if ($this->isEmpty($row, 'bill_number')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first();
|
||||
|
||||
if (empty($row['item_id']) && !empty($row['item_name'])) {
|
||||
$row['item_id'] = $this->getItemIdFromName($row);
|
||||
|
||||
$row['name'] = $row['item_name'];
|
||||
}
|
||||
|
||||
$row['tax'] = (double) $row['tax'];
|
||||
$row['tax_id'] = 0;
|
||||
$row['type'] = Document::BILL_TYPE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user