Item import re-factoring for multiple tax feature
This commit is contained in:
		| @@ -2,29 +2,17 @@ | ||||
|  | ||||
| namespace App\Imports\Common; | ||||
|  | ||||
| use App\Abstracts\Import; | ||||
| use App\Http\Requests\Common\Item as Request; | ||||
| use App\Models\Common\Item as Model; | ||||
| use App\Imports\Common\Sheets\Items as Base; | ||||
| use App\Imports\Common\Sheets\ItemTaxes; | ||||
| use Maatwebsite\Excel\Concerns\WithMultipleSheets; | ||||
|  | ||||
| class Items extends Import | ||||
| class Items implements WithMultipleSheets | ||||
| { | ||||
|     public function model(array $row) | ||||
|     public function sheets(): array | ||||
|     { | ||||
|         return new Model($row); | ||||
|     } | ||||
|  | ||||
|     public function map($row): array | ||||
|     { | ||||
|         $row = parent::map($row); | ||||
|  | ||||
|         $row['category_id'] = $this->getCategoryId($row, 'item'); | ||||
|         $row['tax_id'] = $this->getTaxId($row); | ||||
|  | ||||
|         return $row; | ||||
|     } | ||||
|  | ||||
|     public function rules(): array | ||||
|     { | ||||
|         return (new Request())->rules(); | ||||
|         return [ | ||||
|             'items' => new Base(), | ||||
|             'item_taxes' => new ItemTaxes(), | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										34
									
								
								app/Imports/Common/Sheets/ItemTaxes.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								app/Imports/Common/Sheets/ItemTaxes.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Imports\Sales\Sheets; | ||||
|  | ||||
| use App\Abstracts\Import; | ||||
| use App\Http\Requests\Common\ItemTax as Request; | ||||
| use App\Models\Common\Item; | ||||
| use App\Models\Sale\ItemTax as Model; | ||||
|  | ||||
| class InvoiceItemTaxes extends Import | ||||
| { | ||||
|     public function model(array $row) | ||||
|     { | ||||
|         return new Model($row); | ||||
|     } | ||||
|  | ||||
|     public function map($row): array | ||||
|     { | ||||
|         $row = parent::map($row); | ||||
|  | ||||
|         $row['tax_id'] = $this->getTaxId($row); | ||||
|  | ||||
|         if (empty($row['name']) && !empty($row['item_name'])) { | ||||
|             $row['name'] = $row['item_name']; | ||||
|         } | ||||
|  | ||||
|         return $row; | ||||
|     } | ||||
|  | ||||
|     public function rules(): array | ||||
|     { | ||||
|         return (new Request())->rules(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										29
									
								
								app/Imports/Common/Sheets/Items.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/Imports/Common/Sheets/Items.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Imports\Common\Sheets; | ||||
|  | ||||
| use App\Abstracts\Import; | ||||
| use App\Http\Requests\Common\Item as Request; | ||||
| use App\Models\Common\Item as Model; | ||||
|  | ||||
| class Items extends Import | ||||
| { | ||||
|     public function model(array $row) | ||||
|     { | ||||
|         return new Model($row); | ||||
|     } | ||||
|  | ||||
|     public function map($row): array | ||||
|     { | ||||
|         $row = parent::map($row); | ||||
|  | ||||
|         $row['category_id'] = $this->getCategoryId($row, 'item'); | ||||
|  | ||||
|         return $row; | ||||
|     } | ||||
|  | ||||
|     public function rules(): array | ||||
|     { | ||||
|         return (new Request())->rules(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user