Item multiple tax added
This commit is contained in:
		@@ -4,6 +4,7 @@ namespace App\Jobs\Common;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Job;
 | 
			
		||||
use App\Models\Common\Item;
 | 
			
		||||
use App\Jobs\Common\CreateItemTaxes;
 | 
			
		||||
 | 
			
		||||
class CreateItem extends Job
 | 
			
		||||
{
 | 
			
		||||
@@ -37,6 +38,8 @@ class CreateItem extends Job
 | 
			
		||||
 | 
			
		||||
                $this->item->attachMedia($media, 'picture');
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $this->dispatch(new CreateItemTaxes($this->item, $this->request));
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        return $this->item;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										54
									
								
								app/Jobs/Common/CreateItemTaxes.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								app/Jobs/Common/CreateItemTaxes.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Jobs\Common;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Job;
 | 
			
		||||
use App\Models\Common\ItemTax;
 | 
			
		||||
 | 
			
		||||
class CreateItemTaxes extends Job
 | 
			
		||||
{
 | 
			
		||||
    protected $item;
 | 
			
		||||
 | 
			
		||||
    protected $request;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new job instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $item
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($item, $request)
 | 
			
		||||
    {
 | 
			
		||||
        $this->item = $item;
 | 
			
		||||
        $this->request = $request;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Execute the job.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Item
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        \DB::transaction(function () {
 | 
			
		||||
            // This controller for BC < 2.1
 | 
			
		||||
            if (!empty($this->request['tax_id'])) {
 | 
			
		||||
                ItemTax::create([
 | 
			
		||||
                    'company_id' => $this->item->company_id,
 | 
			
		||||
                    'item_id' => $this->item->id,
 | 
			
		||||
                    'tax_id' => $this->request['tax_id']
 | 
			
		||||
                ]);
 | 
			
		||||
            } else {
 | 
			
		||||
                foreach ($this->request['tax_ids'] as $tax_id) {
 | 
			
		||||
                    ItemTax::create([
 | 
			
		||||
                        'company_id' => $this->item->company_id,
 | 
			
		||||
                        'item_id' => $this->item->id,
 | 
			
		||||
                        'tax_id' => $tax_id
 | 
			
		||||
                    ]);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        return $this->item->taxes;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -28,6 +28,10 @@ class DeleteItem extends Job
 | 
			
		||||
        $this->authorize();
 | 
			
		||||
 | 
			
		||||
        \DB::transaction(function () {
 | 
			
		||||
            $this->deleteRelationships($this->item, [
 | 
			
		||||
                'taxes'
 | 
			
		||||
            ]);
 | 
			
		||||
 | 
			
		||||
            $this->item->delete();
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ namespace App\Jobs\Common;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Job;
 | 
			
		||||
use App\Models\Common\Item;
 | 
			
		||||
use App\Jobs\Common\CreateItemTaxes;
 | 
			
		||||
 | 
			
		||||
class UpdateItem extends Job
 | 
			
		||||
{
 | 
			
		||||
@@ -39,6 +40,10 @@ class UpdateItem extends Job
 | 
			
		||||
 | 
			
		||||
                $this->item->attachMedia($media, 'picture');
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $this->deleteRelationships($this->item, ['taxes']);
 | 
			
		||||
 | 
			
		||||
            $this->dispatch(new CreateItemTaxes($this->item, $this->request));
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        return $this->item;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user