items import/export

This commit is contained in:
denisdulici
2020-01-20 23:18:47 +03:00
parent 6923a3d6e4
commit b119deca9f
4 changed files with 43 additions and 8 deletions

View File

@ -3,18 +3,45 @@
namespace App\Imports\Common;
use App\Abstracts\Import;
use App\Models\Common\Item as Model;
use App\Http\Requests\Common\Item as Request;
use App\Jobs\Common\CreateItem;
use App\Models\Common\Item as Model;
use App\Models\Setting\Category;
use App\Models\Setting\Tax;
class Items extends Import
{
public function model(array $row)
{
return new Model($row);
//$request = (new Request())->merge($row);
}
//return dispatch_now(new CreateItem($request));
public function map($row): array
{
$row = parent::map($row);
if (empty($row['category_id']) && !empty($row['category_name'])) {
$row['category_id'] = Category::firstOrCreate([
'name' => $row['category_name'],
], [
'company_id' => session('company_id'),
'type' => 'income',
'color' => '#' . dechex(rand(0x000000, 0xFFFFFF)),
'enabled' => 1,
])->id;
}
if (empty($row['tax_id']) && !empty($row['tax_rate'])) {
$row['tax_id'] = Tax::firstOrCreate([
'rate' => $row['tax_rate'],
], [
'company_id' => session('company_id'),
'type' => 'normal',
'name' => $row['tax_rate'],
'enabled' => 1,
])->id;
}
return $row;
}
public function rules(): array