diff --git a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php index fb0fd71..1dd5cdf 100644 --- a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php +++ b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php @@ -211,16 +211,20 @@ class CreateInvoiceValidation extends CreateRecord } else { $totQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); $scanSQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count(); + $totMQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('quantity')->where('plant_id', $plantId)->count(); // ->where('quantity', '!=', '') $scanMQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); if ($totMQuan > 0) { + $totMatQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('invoice_quantity') ?? 0; // ->where('quantity', '!=', '') + $scanMatQuan = number_format($totMatQuan - (InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('quantity') ?? 0), 3, '.', ''); + $this->form->fill([ 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, - 'scanned_quantity' => $scanMQuan, + 'total_quantity' => $totMatQuan, + 'scanned_quantity' => $scanMatQuan, ]); if ($totQuan == $scanMQuan) { @@ -829,12 +833,16 @@ class CreateInvoiceValidation extends CreateRecord // Update total quantity in the form $totalQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); $scannedQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); + + $totMatQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('invoice_quantity') ?? 0; + $scanMatQuan = number_format($totMatQuan - (InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('quantity') ?? 0), 3, '.', ''); + $this->form->fill([ 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totalQuantity, - 'scanned_quantity' => $scannedQuantity, + 'total_quantity' => $totMatQuan, + 'scanned_quantity' => $scanMatQuan, ]); if ($totalQuantity == $scannedQuantity) { @@ -861,12 +869,16 @@ class CreateInvoiceValidation extends CreateRecord $totalQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); $scannedQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); + + $totMatQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('invoice_quantity') ?? 0; + $scanMatQuan = number_format($totMatQuan - (InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('quantity') ?? 0), 3, '.', ''); + $this->form->fill([ 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totalQuantity, - 'scanned_quantity' => $scannedQuantity, + 'total_quantity' => $totMatQuan, + 'scanned_quantity' => $scanMatQuan, ]); // if ($disk->exists($filePath)) { @@ -1918,12 +1930,16 @@ class CreateInvoiceValidation extends CreateRecord // Update total quantity in the form $totalQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); $scannedQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); + + $totMatQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('invoice_quantity') ?? 0; + $scanMatQuan = number_format($totMatQuan - (InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('quantity') ?? 0), 3, '.', ''); + $this->form->fill([ 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totalQuantity, - 'scanned_quantity' => $scannedQuantity, + 'total_quantity' => $totMatQuan, + 'scanned_quantity' => $scanMatQuan, ]); if ($totalQuantity == $scannedQuantity) { @@ -1951,12 +1967,16 @@ class CreateInvoiceValidation extends CreateRecord $totalQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); $scannedQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); + + $totMatQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('invoice_quantity') ?? 0; + $scanMatQuan = number_format($totMatQuan - (InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('quantity') ?? 0), 3, '.', ''); + $this->form->fill([ 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totalQuantity, - 'scanned_quantity' => $scannedQuantity, + 'total_quantity' => $totMatQuan, + 'scanned_quantity' => $scanMatQuan, ]); // if ($disk->exists($filePath)) { @@ -2448,6 +2468,9 @@ class CreateInvoiceValidation extends CreateRecord return; } else { if ($totMQuan > 0) { + $totMatQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('invoice_quantity') ?? 0; + $scanMatQuan = number_format($totMatQuan - (InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('quantity') ?? 0), 3, '.', ''); + if ($totQuan == $scanMQuan) { Notification::make() ->title('Completed: Material Invoice') @@ -2484,9 +2507,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); // $hasRecords = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->first()->stickerMasterRelation->material_type ?? null; $this->dispatch('refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId); @@ -2524,9 +2547,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2543,9 +2566,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2586,9 +2609,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2620,9 +2643,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2655,9 +2678,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2698,9 +2721,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2731,9 +2754,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2763,9 +2786,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2805,9 +2828,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2838,9 +2861,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -2914,7 +2937,6 @@ class CreateInvoiceValidation extends CreateRecord $duplicateSerial = []; $weightExceeded = []; - $processedItems = []; $invalidMaterialItems = []; $wireItems1 = WireMasterPacking::join('items', 'items.id', '=', 'wire_master_packings.item_id') @@ -2933,8 +2955,6 @@ class CreateInvoiceValidation extends CreateRecord $palletWeight = $wireItem->pallet_weight; $itemCode = $wireItem->item_code; - $processedItems[] = $itemCode; - $duplicate = InvoiceValidation::where('plant_id', $this->plantId) ->where('invoice_number', $this->invoiceNumber) ->where('serial_number', $processOrder) @@ -3120,16 +3140,18 @@ class CreateInvoiceValidation extends CreateRecord $this->dispatch('refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId); $totQuan = InvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->count(); - $scanMQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); + $totMatQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('invoice_quantity') ?? 0; + $scanMatQuan = number_format($totMatQuan - (InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('quantity') ?? 0), 3, '.', ''); + $this->form->fill([ 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3168,9 +3190,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3206,9 +3228,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3243,9 +3265,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3266,9 +3288,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3301,9 +3323,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3329,9 +3351,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3351,9 +3373,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3373,9 +3395,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3439,9 +3461,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3467,9 +3489,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scanMQuan, + 'scanned_quantity' => $scanMatQuan, ]); return; @@ -3492,9 +3514,11 @@ class CreateInvoiceValidation extends CreateRecord // ->send(); $totQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); - $scannedMQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); + $totMatQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('invoice_quantity') ?? 0; + $scanMatQuan = number_format($totMatQuan - (InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNull('serial_number')->where('plant_id', $plantId)->latest()->value('quantity') ?? 0), 3, '.', ''); + if ($totQuan == $scannedMQuantity) { Notification::make() ->title('Completed: Material Invoice') @@ -3530,9 +3554,9 @@ class CreateInvoiceValidation extends CreateRecord 'plant_id' => $plantId, 'invoice_number' => $invoiceNumber, 'serial_number' => null, - 'total_quantity' => $totQuan, + 'total_quantity' => $totMatQuan, 'update_invoice' => false, - 'scanned_quantity' => $scannedMQuantity, + 'scanned_quantity' => $scanMatQuan, ]); $this->dispatch('refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId); }