Siopas Inventory PETI for ISTW Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
2.8 KiB

<?php
namespace App\Exports;
use App\Models\Peti;
use Illuminate\Support\Carbon;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;
class StokOpNameExport implements FromCollection, WithHeadings
{
protected $stokOpnames;
protected $todayStokOpnames;
protected $yesterdayStokOpnames;
protected $gudangStokOpnames;
public function __construct($stokOpnames, $todayStokOpnames, $yesterdayStokOpnames, $gudangStokOpnames)
{
$this->stokOpnames = $stokOpnames;
$this->todayStokOpnames = $todayStokOpnames;
$this->yesterdayStokOpnames = $yesterdayStokOpnames;
$this->gudangStokOpnames = $gudangStokOpnames;
}
public function collection()
{
$data = collect();
$nomor = 1;
foreach ($this->stokOpnames as $data_StokOpname) {
$yesterdayStokOpname = $this->yesterdayStokOpnames
// ->where('status', 'AKTIF')
->where('customer_id', $data_StokOpname->customer_id)
->where('tipe_peti_id', $data_StokOpname->tipe_peti_id)
->first();
$todayStokOpname = $this->todayStokOpnames
->where('customer_id', $data_StokOpname->customer_id)
->where('tipe_peti_id', $data_StokOpname->tipe_peti_id)
->first();
$gudangData = $this->gudangStokOpnames
->where('customer_id', $data_StokOpname->customer_id)
->where('tipe_peti_id', $data_StokOpname->tipe_peti_id)
->keyBy('warehouse_id');
$data->push([
'No' => $nomor++,
'Customer' => $data_StokOpname->customer->name,
'Kode' => $data_StokOpname->customer->code_customer . ' 0 ' . $data_StokOpname->tipe_peti->type,
'Ukuran Peti' => $data_StokOpname->tipe_peti->size_peti,
'Bagging Stok' => $yesterdayStokOpname ? $yesterdayStokOpname->total_petis : '-',
'Add' => $todayStokOpname ? $todayStokOpname->total_petis : '0',
'Total' => $data_StokOpname->total_petis ?? '0',
'Jakarta' => $gudangData->get(1)->total_petis ?? '0',
'Bekasi' => $gudangData->get(2)->total_petis ?? '0',
'Semarang' => $gudangData->get(3)->total_petis ?? '0',
'Surabaya' => $gudangData->get(4)->total_petis ?? '0',
'Total Stok' => $data_StokOpname->total_petis ?? '0',
]);
}
return $data;
}
public function headings(): array
{
return [
'No',
'Customer',
'Kode',
'Ukuran Peti',
'Bagging Stok',
'Add',
'Total',
'Jakarta',
'Bekasi',
'Semarang',
'Surabaya',
'Total Stok',
];
}
}