Added printSpare in pallet print controller
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\CustomerPoMaster;
|
||||
use App\Models\Plant;
|
||||
use App\Models\SaleOrderMaster;
|
||||
use App\Models\SparePacking;
|
||||
use App\Models\WireMasterPacking;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -279,9 +281,6 @@ class PalletPrintController extends Controller
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
@@ -310,4 +309,101 @@ class PalletPrintController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function printSpare(Request $request, $pallet, $plant)
|
||||
{
|
||||
|
||||
$customerPoMasterId = SparePacking::where('plant_id', $plant)
|
||||
->where('spare_packing_number', $pallet)
|
||||
->value('sale_order_master_id');
|
||||
|
||||
$masterIds = SparePacking::where('plant_id', $plant)
|
||||
->where('spare_packing_number', $pallet)
|
||||
->pluck('sale_order_master_id');
|
||||
|
||||
$customerPo = SaleOrderMaster::whereIn('id', $masterIds)
|
||||
->value('sale_order_number');
|
||||
|
||||
$customerPoMasterIds = SaleOrderMaster::where('sale_order_number', $customerPo)
|
||||
->pluck('id');
|
||||
|
||||
$items = SparePacking::with('item')
|
||||
->where('plant_id', $plant)
|
||||
->where('spare_packing_number', $pallet)
|
||||
->get()
|
||||
->map(function ($row) {
|
||||
return (object) [
|
||||
'code' => $row->item->code,
|
||||
'description' => $row->item->description,
|
||||
'box_count' => 1, // each row = one box
|
||||
'weight' => $row->quantity,
|
||||
];
|
||||
});
|
||||
|
||||
$customer = SaleOrderMaster::find($customerPoMasterId);
|
||||
|
||||
$customerCode = $customer->sale_order_number ?? '';
|
||||
$customerName = $customer->supplier_name ?? '';
|
||||
|
||||
$totalBoxes = SparePacking::where('plant_id', $plant)
|
||||
->whereIn('sale_order_master_id', $customerPoMasterIds)
|
||||
->select('spare_packing_number')
|
||||
->groupBy('spare_packing_number')
|
||||
->havingRaw(
|
||||
'COUNT(*) = COUNT(CASE WHEN spare_packing_status = ? THEN 1 END)',
|
||||
['Completed']
|
||||
)
|
||||
->count();
|
||||
|
||||
$completedPallets = SparePacking::where('plant_id', $plant)
|
||||
->whereIn('sale_order_master_id', $customerPoMasterIds)
|
||||
->select('spare_packing_number')
|
||||
->groupBy('spare_packing_number')
|
||||
->havingRaw(
|
||||
'COUNT(*) = COUNT(CASE WHEN spare_packing_status = ? THEN 1 END)',
|
||||
['Completed']
|
||||
)
|
||||
->orderBy('spare_packing_number')
|
||||
->pluck('spare_packing_number')
|
||||
->values();
|
||||
|
||||
$index = $completedPallets->search($pallet);
|
||||
|
||||
$currentPalletNo = ($index !== false) ? $index + 1 : 0;
|
||||
|
||||
$boxLabel = $currentPalletNo.'/'.$totalBoxes;
|
||||
|
||||
$grossWeight = $items->sum('weight');
|
||||
$widthPt = 85 * 2.83465; // 85mm → points
|
||||
$heightPt = 100 * 2.83465; // 100mm → points
|
||||
|
||||
$plantName = Plant::where('id', $plant)->value('name');
|
||||
|
||||
$plantAddress = Plant::where('id', $plant)->value('address');
|
||||
|
||||
$scannedAt = SparePacking::where('plant_id', $plant)
|
||||
->where('spare_packing_number', $pallet)
|
||||
->value('scanned_at');
|
||||
|
||||
$pdf = Pdf::loadView('pdf.spare-pallet', [
|
||||
'product' => 'Spare Packing List',
|
||||
'plantName' => $plantName,
|
||||
'plantAddress' => $plantAddress,
|
||||
// 'monthYear' => now()->format('M-y'),
|
||||
'monthYear' => $scannedAt
|
||||
? \Carbon\Carbon::parse($scannedAt)->format('M-y')
|
||||
: '',
|
||||
'branch' => '',
|
||||
'customerCode' => $customerCode,
|
||||
'customerName' => $customerName,
|
||||
'masterBox' => $boxLabel,
|
||||
'items' => $items,
|
||||
'grossWeight' => $grossWeight + 3.050,
|
||||
'netWeight' => $grossWeight,
|
||||
'pallet' => $pallet,
|
||||
])->setPaper([0, 0, $widthPt, $heightPt], 'portrait');
|
||||
|
||||
return $pdf->stream("Pallet-{$pallet}.pdf");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user