akaunting/app/Jobs/Common/CreateItemTaxes.php

55 lines
1.1 KiB
PHP
Raw Normal View History

2020-12-08 13:30:06 +03:00
<?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.
*
2020-12-14 16:04:54 +03:00
* @return mixed
2020-12-08 13:30:06 +03:00
*/
public function handle()
{
2020-12-14 16:04:54 +03:00
// BC for 2.0 version
if (!empty($this->request['tax_id'])) {
$this->request['tax_ids'][] = $this->request['tax_id'];
}
if (empty($this->request['tax_ids'])) {
return false;
}
2020-12-08 13:30:06 +03:00
\DB::transaction(function () {
2020-12-14 16:04:54 +03:00
foreach ($this->request['tax_ids'] as $tax_id) {
2020-12-08 13:30:06 +03:00
ItemTax::create([
'company_id' => $this->item->company_id,
'item_id' => $this->item->id,
2020-12-14 16:04:54 +03:00
'tax_id' => $tax_id,
2020-12-08 13:30:06 +03:00
]);
}
});
return $this->item->taxes;
}
}