@php
use Illuminate\Support\Facades\DB;
$MasterItems = DB::table('tstktmatstockcardproduct')
->where('xistkqtyleft','>','0')
->join('tmstmproduct','tstktmatstockcardproduct.xvpdtcode','=','tmstmproduct.xvpdtcode');
if(isset($WhereType) && isset($ValueWhere) && isset($operator)){
$MasterItems->where($WhereType,$operator,$ValueWhere);
}
$MasterItems = $MasterItems
->groupBy('xvpdtcode','xvpszname')
->select('tstktmatstockcardproduct.*','tmstmproduct.xvpdtname',DB::raw('SUM(xistkqtyleft) as SumQty'))
->orderBy('tstktmatstockcardproduct.xvpdtcode','desc')
->get()->toArray();
foreach ($MasterItems as $item){
$item->size = DB::table('tmstmproductsize')
->where('xvpdtcode','=',$item->xvpdtcode)
->get()->toArray();
}
@endphp