Item export re-factoring for multiple tax feature
This commit is contained in:
parent
669c05eaaa
commit
40c1202c6d
@ -2,40 +2,24 @@
|
||||
|
||||
namespace App\Exports\Common;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Common\Item as Model;
|
||||
use App\Exports\Common\Sheets\Items as Base;
|
||||
use App\Exports\Common\Sheets\ItemTaxes;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
|
||||
class Items extends Export
|
||||
class Items implements WithMultipleSheets
|
||||
{
|
||||
public function collection()
|
||||
public $ids;
|
||||
|
||||
public function __construct($ids = null)
|
||||
{
|
||||
$model = Model::with('category', 'tax')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
$this->ids = $ids;
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->category_name = $model->category->name;
|
||||
$model->tax_rate = $model->tax->rate;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
'name',
|
||||
'description',
|
||||
'sale_price',
|
||||
'purchase_price',
|
||||
'category_name',
|
||||
'tax_rate',
|
||||
'enabled',
|
||||
'items' => new Base($this->ids),
|
||||
'item_taxes' => new ItemTaxes($this->ids),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
42
app/Exports/Common/Sheets/ItemTaxes.php
Normal file
42
app/Exports/Common/Sheets/ItemTaxes.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Common\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Common\ItemTax as Model;
|
||||
|
||||
class ItemTaxes extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('item', 'tax')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('item_id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$item = $model->item;
|
||||
|
||||
if (empty($item)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$model->item_name = $model->item->name;
|
||||
$model->tax_rate = $model->tax->rate;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'item_name',
|
||||
'tax_rate',
|
||||
];
|
||||
}
|
||||
}
|
40
app/Exports/Common/Sheets/Items.php
Normal file
40
app/Exports/Common/Sheets/Items.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\Common\Sheets;
|
||||
|
||||
use App\Abstracts\Export;
|
||||
use App\Models\Common\Item as Model;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
|
||||
class Invoices extends Export implements WithColumnFormatting
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with('category')->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
}
|
||||
|
||||
return $model->cursor();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->category_name = $model->category->name;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'name',
|
||||
'description',
|
||||
'sale_price',
|
||||
'purchase_price',
|
||||
'category_name',
|
||||
'enabled',
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user