diff --git a/app/Imports/Common/Items.php b/app/Imports/Common/Items.php index f3e78b060..dbec14d0d 100644 --- a/app/Imports/Common/Items.php +++ b/app/Imports/Common/Items.php @@ -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(), + ]; } } diff --git a/app/Imports/Common/Sheets/ItemTaxes.php b/app/Imports/Common/Sheets/ItemTaxes.php new file mode 100644 index 000000000..3f77a71f4 --- /dev/null +++ b/app/Imports/Common/Sheets/ItemTaxes.php @@ -0,0 +1,34 @@ +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(); + } +} diff --git a/app/Imports/Common/Sheets/Items.php b/app/Imports/Common/Sheets/Items.php new file mode 100644 index 000000000..53fa519df --- /dev/null +++ b/app/Imports/Common/Sheets/Items.php @@ -0,0 +1,29 @@ +getCategoryId($row, 'item'); + + return $row; + } + + public function rules(): array + { + return (new Request())->rules(); + } +}