Added wire master packing qr logic and material qr (with and without kg) logic
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
This commit is contained in:
@@ -10,6 +10,8 @@ use App\Models\InvoiceValidation;
|
|||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\StickerMaster;
|
use App\Models\StickerMaster;
|
||||||
|
use App\Models\WireMasterPacking;
|
||||||
|
use DB;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Pages\Concerns\ExposesTableToWidgets;
|
use Filament\Pages\Concerns\ExposesTableToWidgets;
|
||||||
@@ -174,17 +176,15 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($matches[1])) {
|
if (isset($matches[1])) {
|
||||||
$invoiceNumber = $matches[1];
|
$invoiceNumber = strtoupper($matches[1]);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$invoiceNumber = strtoupper($invoiceNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dd($invoiceNumber);
|
|
||||||
|
|
||||||
// ..
|
|
||||||
|
|
||||||
$updateStatus = $this->form->getState()['update_invoice'] ?? null;
|
$updateStatus = $this->form->getState()['update_invoice'] ?? null;
|
||||||
|
|
||||||
$this->invoiceNumber = trim($this->form->getState()['invoice_number']) ?? $invoiceNumber;
|
$this->invoiceNumber = strtoupper(trim($this->form->getState()['invoice_number'])) ?? $invoiceNumber;
|
||||||
|
|
||||||
$invoiceType = null;
|
$invoiceType = null;
|
||||||
// $this->invoiceNumber = $this->invoiceNumber ?? $invoiceNumber;
|
// $this->invoiceNumber = $this->invoiceNumber ?? $invoiceNumber;
|
||||||
@@ -2317,7 +2317,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
protected function refreshInvoiceTable()
|
protected function refreshInvoiceTable()
|
||||||
{
|
{
|
||||||
$this->plantId = $this->form->getState()['plant_id'] ?? '';
|
$this->plantId = $this->form->getState()['plant_id'] ?? '';
|
||||||
$this->invoiceNumber = $this->form->getState()['invoice_number'] ?? '';
|
$this->invoiceNumber = strtoupper(trim($this->form->getState()['invoice_number'])) ?? '';
|
||||||
|
|
||||||
if (! empty($this->invoiceNumber)) {
|
if (! empty($this->invoiceNumber)) {
|
||||||
$hasInvoice = InvoiceValidation::where('invoice_number', $this->invoiceNumber)->where('plant_id', $this->plantId)->first();
|
$hasInvoice = InvoiceValidation::where('invoice_number', $this->invoiceNumber)->where('plant_id', $this->plantId)->first();
|
||||||
@@ -2378,7 +2378,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$serialNumber = null;
|
$serialNumber = null;
|
||||||
$plantId = $this->form->getState()['plant_id'];
|
$plantId = $this->form->getState()['plant_id'];
|
||||||
$this->plantId = $plantId;
|
$this->plantId = $plantId;
|
||||||
$invoiceNumber = $this->form->getState()['invoice_number'];
|
$invoiceNumber = strtoupper(trim($this->form->getState()['invoice_number']));
|
||||||
$this->invoiceNumber = $invoiceNumber;
|
$this->invoiceNumber = $invoiceNumber;
|
||||||
|
|
||||||
$plant = Plant::find($plantId);
|
$plant = Plant::find($plantId);
|
||||||
@@ -2455,14 +2455,65 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$this->dispatch('refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId);
|
$this->dispatch('refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$pattern0 = '/^(?<item_code>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>[^|]+)\|(?<batch_quantity>[0-9]+(?:\.[0-9]+)?)kg$/i';
|
||||||
$pattern1 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>[^|]+)\/(?<batch_quantity>.+)$/i';
|
$pattern1 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>[^|]+)\/(?<batch_quantity>.+)$/i';
|
||||||
$pattern2 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>.+)$/i';
|
$pattern2 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>.+)$/i';
|
||||||
$pattern3 = '/^(?<item_code>[^|]+)\|(?<batch_id>[^|]+)-(?<batch_count>.+)$/i';
|
$pattern3 = '/^(?<item_code>[^|]+)\|(?<batch_id>[^|]+)-(?<batch_count>.+)$/i';
|
||||||
|
$pattern4 = '/^MP-(?<code>.+)$/i';
|
||||||
$itemCode = '';
|
$itemCode = '';
|
||||||
$batchNumber = '';
|
$batchNumber = '';
|
||||||
$curScanQty = '';
|
$curScanQty = '';
|
||||||
|
$wirePallet = '';
|
||||||
|
$curMaterialQty = '';
|
||||||
|
$curMaterialSer = '';
|
||||||
|
|
||||||
if (preg_match($pattern1, $serNo, $matches)) {
|
if (preg_match($pattern0, $serNo, $matches)) {
|
||||||
|
$itemCode = $matches['item_code'];
|
||||||
|
$this->currentItemCode = $itemCode;
|
||||||
|
$curScanQty = $matches['batch_quantity'];
|
||||||
|
$serialNumber = $matches['batch_id'].'-'.$matches['batch_count'];
|
||||||
|
$serNo = null;
|
||||||
|
|
||||||
|
if (empty($matches['batch_id']) || ! $matches['batch_id']) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Invalid Material QR Format')
|
||||||
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
|
->seconds(2)
|
||||||
|
->send();
|
||||||
|
$this->dispatch('playWarnSound');
|
||||||
|
|
||||||
|
$this->form->fill([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'invoice_number' => $invoiceNumber,
|
||||||
|
'serial_number' => null,
|
||||||
|
'total_quantity' => $totQuan,
|
||||||
|
'update_invoice' => false,
|
||||||
|
'scanned_quantity' => $scanMQuan,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($matches['batch_count']) || ! $matches['batch_count']) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Invalid Material QR Format')
|
||||||
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
|
->seconds(2)
|
||||||
|
->send();
|
||||||
|
$this->dispatch('playWarnSound');
|
||||||
|
|
||||||
|
$this->form->fill([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'invoice_number' => $invoiceNumber,
|
||||||
|
'serial_number' => null,
|
||||||
|
'total_quantity' => $totQuan,
|
||||||
|
'update_invoice' => false,
|
||||||
|
'scanned_quantity' => $scanMQuan,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} elseif (preg_match($pattern1, $serNo, $matches)) {
|
||||||
$itemCode = $matches['item_code'];
|
$itemCode = $matches['item_code'];
|
||||||
$this->currentItemCode = $itemCode;
|
$this->currentItemCode = $itemCode;
|
||||||
$batchNumber = $matches['batch_number'];
|
$batchNumber = $matches['batch_number'];
|
||||||
@@ -2470,11 +2521,45 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$curScanQty = $matches['batch_quantity'];
|
$curScanQty = $matches['batch_quantity'];
|
||||||
$serNo = null;
|
$serNo = null;
|
||||||
|
|
||||||
if (empty($matches['batch_id']) || ! $matches['batch_id']) {
|
if (empty($matches['batch_number']) || ! $matches['batch_number']) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title('Invalid Material QR Format')
|
->title('Invalid Material QR Format')
|
||||||
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
|
->seconds(2)
|
||||||
|
->send();
|
||||||
|
$this->dispatch('playWarnSound');
|
||||||
|
|
||||||
|
// .Mail
|
||||||
|
|
||||||
|
// $mailData = $this->getMail();
|
||||||
|
// $mPlantName = $mailData['plant_name'];
|
||||||
|
// $emails = $mailData['emails'];
|
||||||
|
// $mInvoiceType = 'Material';
|
||||||
|
|
||||||
|
// if (! empty($emails)) {
|
||||||
|
// Mail::to($emails)->send(
|
||||||
|
// new InvalidSerialMail($mSerNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, 'InvalidMaterialFormat')
|
||||||
|
// );
|
||||||
|
// } else {
|
||||||
|
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
|
||||||
|
// }
|
||||||
|
|
||||||
|
$this->form->fill([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'invoice_number' => $invoiceNumber,
|
||||||
|
'serial_number' => null,
|
||||||
|
'total_quantity' => $totQuan,
|
||||||
|
'update_invoice' => false,
|
||||||
|
'scanned_quantity' => $scanMQuan,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($matches['batch_id']) || ! $matches['batch_id']) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Invalid Material QR Format')
|
||||||
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
->seconds(2)
|
->seconds(2)
|
||||||
->send();
|
->send();
|
||||||
$this->dispatch('playWarnSound');
|
$this->dispatch('playWarnSound');
|
||||||
@@ -2508,42 +2593,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title('Invalid Material QR Format')
|
->title('Invalid Material QR Format')
|
||||||
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
->seconds(2)
|
|
||||||
->send();
|
|
||||||
$this->dispatch('playWarnSound');
|
|
||||||
|
|
||||||
// .Mail
|
|
||||||
|
|
||||||
// $mailData = $this->getMail();
|
|
||||||
// $mPlantName = $mailData['plant_name'];
|
|
||||||
// $emails = $mailData['emails'];
|
|
||||||
// $mInvoiceType = 'Material';
|
|
||||||
|
|
||||||
// if (! empty($emails)) {
|
|
||||||
// // Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType));
|
|
||||||
// Mail::to($emails)->send(
|
|
||||||
// new InvalidSerialMail($mSerNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, 'InvalidMaterialFormat')
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
|
|
||||||
// }
|
|
||||||
|
|
||||||
$this->form->fill([
|
|
||||||
'plant_id' => $plantId,
|
|
||||||
'invoice_number' => $invoiceNumber,
|
|
||||||
'serial_number' => null,
|
|
||||||
'total_quantity' => $totQuan,
|
|
||||||
'update_invoice' => false,
|
|
||||||
'scanned_quantity' => $scanMQuan,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return;
|
|
||||||
} elseif (! is_numeric($curScanQty)) {
|
|
||||||
Notification::make()
|
|
||||||
->danger()
|
|
||||||
->title('Invalid Material QR Format')
|
|
||||||
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
|
||||||
->seconds(2)
|
->seconds(2)
|
||||||
->send();
|
->send();
|
||||||
$this->dispatch('playWarnSound');
|
$this->dispatch('playWarnSound');
|
||||||
@@ -2580,13 +2630,48 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$this->currentItemCode = $itemCode;
|
$this->currentItemCode = $itemCode;
|
||||||
$batchNumber = $matches['batch_number'];
|
$batchNumber = $matches['batch_number'];
|
||||||
$serialNumber = $matches['batch_id'].'-'.$matches['batch_count'];
|
$serialNumber = $matches['batch_id'].'-'.$matches['batch_count'];
|
||||||
|
$curMaterialSer = $matches['batch_number'].'-'.$matches['batch_id'];
|
||||||
|
$curMaterialQty = $matches['batch_count'];
|
||||||
$serNo = null;
|
$serNo = null;
|
||||||
|
|
||||||
if (empty($matches['batch_id']) || ! $matches['batch_id']) {
|
if (empty($matches['batch_number']) || ! $matches['batch_number']) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title('Invalid Material QR Format')
|
->title('Invalid Material QR Format')
|
||||||
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
|
->seconds(2)
|
||||||
|
->send();
|
||||||
|
$this->dispatch('playWarnSound');
|
||||||
|
// .Mail
|
||||||
|
|
||||||
|
// $mailData = $this->getMail();
|
||||||
|
// $mPlantName = $mailData['plant_name'];
|
||||||
|
// $emails = $mailData['emails'];
|
||||||
|
// $mInvoiceType = 'Material';
|
||||||
|
|
||||||
|
// if (! empty($emails)) {
|
||||||
|
// Mail::to($emails)->send(
|
||||||
|
// new InvalidSerialMail($mSerNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, 'InvalidMaterialFormat')
|
||||||
|
// );
|
||||||
|
// } else {
|
||||||
|
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
|
||||||
|
// }
|
||||||
|
|
||||||
|
$this->form->fill([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'invoice_number' => $invoiceNumber,
|
||||||
|
'serial_number' => null,
|
||||||
|
'total_quantity' => $totQuan,
|
||||||
|
'update_invoice' => false,
|
||||||
|
'scanned_quantity' => $scanMQuan,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($matches['batch_id']) || ! $matches['batch_id']) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Invalid Material QR Format')
|
||||||
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
->seconds(2)
|
->seconds(2)
|
||||||
->send();
|
->send();
|
||||||
$this->dispatch('playWarnSound');
|
$this->dispatch('playWarnSound');
|
||||||
@@ -2619,7 +2704,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title('Invalid Material QR Format')
|
->title('Invalid Material QR Format')
|
||||||
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
->seconds(2)
|
->seconds(2)
|
||||||
->send();
|
->send();
|
||||||
$this->dispatch('playWarnSound');
|
$this->dispatch('playWarnSound');
|
||||||
@@ -2659,7 +2744,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title('Invalid Material QR Format')
|
->title('Invalid Material QR Format')
|
||||||
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
->seconds(2)
|
->seconds(2)
|
||||||
->send();
|
->send();
|
||||||
$this->dispatch('playWarnSound');
|
$this->dispatch('playWarnSound');
|
||||||
@@ -2693,7 +2778,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title('Invalid Material QR Format')
|
->title('Invalid Material QR Format')
|
||||||
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
->seconds(2)
|
->seconds(2)
|
||||||
->send();
|
->send();
|
||||||
$this->dispatch('playWarnSound');
|
$this->dispatch('playWarnSound');
|
||||||
@@ -2723,6 +2808,294 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} elseif (preg_match($pattern4, $serNo, $matches)) {
|
||||||
|
$wirePallet = 'MP-'.$matches['code'];
|
||||||
|
$wirePattern = '/^MP-(?<code>\d+)$/i';
|
||||||
|
|
||||||
|
if (! preg_match($wirePattern, $serNo, $matches)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Invalid Master Packing QR Format')
|
||||||
|
->body("Scan valid Master Packing QR code proceed!<br>Sample format : 'MP-2601001'")
|
||||||
|
->danger()
|
||||||
|
->seconds(1)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$wireMaster = WireMasterPacking::where('plant_id', $plantId)->where('wire_packing_number', $wirePallet)->first();
|
||||||
|
|
||||||
|
if (! $wireMaster) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Master Pallet Not Found')
|
||||||
|
->body("No record found for this Master Packing QR $wirePallet")
|
||||||
|
->danger()
|
||||||
|
->seconds(2)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$wireItemCodes = WireMasterPacking::join('items', 'items.id', '=', 'wire_master_packings.item_id')
|
||||||
|
->where('wire_master_packings.plant_id', $plantId)
|
||||||
|
->where('wire_master_packings.wire_packing_number', $wirePallet)
|
||||||
|
->pluck('items.code')
|
||||||
|
->unique()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$invoiceItemCodes = InvoiceValidation::join(
|
||||||
|
'sticker_masters',
|
||||||
|
'sticker_masters.id',
|
||||||
|
'=',
|
||||||
|
'invoice_validations.sticker_master_id'
|
||||||
|
)
|
||||||
|
->join(
|
||||||
|
'items',
|
||||||
|
'items.id',
|
||||||
|
'=',
|
||||||
|
'sticker_masters.item_id'
|
||||||
|
)
|
||||||
|
->where('invoice_validations.plant_id', $plantId)
|
||||||
|
->where('invoice_validations.invoice_number', $this->invoiceNumber)
|
||||||
|
->pluck('items.code')
|
||||||
|
->unique()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$missedCodes = array_diff($wireItemCodes, $invoiceItemCodes);
|
||||||
|
|
||||||
|
if (! empty($missedCodes)) {
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title('Items Missing in Invoice')
|
||||||
|
->body('Item codes are missing in invoice: '.implode(', ', $missedCodes))
|
||||||
|
->danger()
|
||||||
|
->seconds(3)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$duplicateSerial = [];
|
||||||
|
$weightExceeded = [];
|
||||||
|
$processedItems = [];
|
||||||
|
$invalidMaterialItems = [];
|
||||||
|
|
||||||
|
$wireItems1 = WireMasterPacking::join('items', 'items.id', '=', 'wire_master_packings.item_id')
|
||||||
|
->where('wire_master_packings.plant_id', $plantId)
|
||||||
|
->where('wire_master_packings.wire_packing_number', $wirePallet)
|
||||||
|
->select(
|
||||||
|
'items.code as item_code',
|
||||||
|
'wire_master_packings.process_order',
|
||||||
|
DB::raw('SUM(wire_master_packings.weight::numeric) as pallet_weight')
|
||||||
|
)
|
||||||
|
->groupBy('items.code', 'wire_master_packings.process_order')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach ($wireItems1 as $wireItem) {
|
||||||
|
$processOrder = $wireItem->process_order;
|
||||||
|
$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)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($duplicate) {
|
||||||
|
$duplicateSerial[] = $processOrder;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$materialType = StickerMaster::where('item_id', function ($q) use ($itemCode) {
|
||||||
|
$q->select('id')->from('items')->where('code', $itemCode);
|
||||||
|
})->value('material_type');
|
||||||
|
|
||||||
|
if ($materialType != 3) {
|
||||||
|
if (! in_array($itemCode, $invalidMaterialItems)) {
|
||||||
|
$invalidMaterialItems[] = $itemCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$scannedQty = InvoiceValidation::join('sticker_masters', 'sticker_masters.id', '=', 'invoice_validations.sticker_master_id')
|
||||||
|
->join('items', 'items.id', '=', 'sticker_masters.item_id')
|
||||||
|
->where('invoice_validations.plant_id', $plantId)
|
||||||
|
->where('invoice_validations.invoice_number', $this->invoiceNumber)
|
||||||
|
->where('items.code', $itemCode)
|
||||||
|
->sum(DB::raw('invoice_validations.quantity::numeric'));
|
||||||
|
|
||||||
|
if ($palletWeight > $scannedQty) {
|
||||||
|
$weightExceeded[] = $itemCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($invalidMaterialItems)) {
|
||||||
|
$uniqueInvalidItems = array_unique($invalidMaterialItems);
|
||||||
|
Notification::make()
|
||||||
|
->title('Invalid Material Type')
|
||||||
|
->body(implode(', ', $uniqueInvalidItems)."<br>Invalid material type found for the invoice '$invoiceNumber'.")
|
||||||
|
->danger()
|
||||||
|
->seconds(4)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (! empty($weightExceeded)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Item Code Limit')
|
||||||
|
->body(implode(', ', $weightExceeded)."<br>Master pallet weight exceeds the remaining quantity in invoice '$invoiceNumber'.")
|
||||||
|
->danger()
|
||||||
|
->seconds(4)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (! empty($duplicateSerial)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Duplicate Serial Number')
|
||||||
|
->body(implode(', ', $duplicateSerial)."<br>Duplicate Serial numbers found for the invoice '$invoiceNumber'.")
|
||||||
|
->danger()
|
||||||
|
->seconds(4)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemExceeded = [];
|
||||||
|
|
||||||
|
$invoiceRows = InvoiceValidation::where('plant_id', $plantId)
|
||||||
|
->where('invoice_number', $invoiceNumber)
|
||||||
|
->whereNull('serial_number')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$palletItems = WireMasterPacking::where('wire_master_packings.plant_id', $plantId)
|
||||||
|
->where('wire_master_packings.wire_packing_number', $wirePallet)
|
||||||
|
->join('items', 'items.id', '=', 'wire_master_packings.item_id')
|
||||||
|
->select(
|
||||||
|
'items.code as item_code',
|
||||||
|
DB::raw('SUM(wire_master_packings.weight::numeric) as pallet_weight')
|
||||||
|
)
|
||||||
|
->groupBy('items.code')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach ($invoiceRows as $row) {
|
||||||
|
$itemCode = $row->stickerMaster->item->code ?? null;
|
||||||
|
|
||||||
|
if (! $itemCode) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pallet = $palletItems->firstWhere('item_code', $itemCode);
|
||||||
|
$palletWeight = $pallet->pallet_weight ?? 0;
|
||||||
|
|
||||||
|
$remainingQty = $row->quantity;
|
||||||
|
|
||||||
|
if ($palletWeight > $remainingQty) {
|
||||||
|
$itemExceeded[] = $itemCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = implode(', ', $itemExceeded);
|
||||||
|
|
||||||
|
if (! empty($itemExceeded)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Item Code Limit')
|
||||||
|
->body("Pallet weight exceeds remaining quantity for invoice number '$invoiceNumber'for below item codes <br>$items")
|
||||||
|
->danger()
|
||||||
|
->seconds(5)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$wireItems = WireMasterPacking::join('items', 'items.id', '=', 'wire_master_packings.item_id')
|
||||||
|
->where('wire_master_packings.wire_packing_number', $wirePallet)
|
||||||
|
->select(
|
||||||
|
'items.code as item_code',
|
||||||
|
'wire_master_packings.process_order',
|
||||||
|
'wire_master_packings.weight as pallet_weight'
|
||||||
|
// DB::raw('(wire_master_packings.weight::numeric) as pallet_weight')
|
||||||
|
)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach ($wireItems as $wireItem) {
|
||||||
|
|
||||||
|
$itemCode = $wireItem->item_code;
|
||||||
|
$palletWeight = $wireItem->pallet_weight;
|
||||||
|
$processOrder = $wireItem->process_order;
|
||||||
|
|
||||||
|
if (! $processOrder || $palletWeight <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$records = InvoiceValidation::join('sticker_masters', 'sticker_masters.id', '=', 'invoice_validations.sticker_master_id')
|
||||||
|
->join('items', 'items.id', '=', 'sticker_masters.item_id')
|
||||||
|
->where('invoice_validations.invoice_number', $invoiceNumber)
|
||||||
|
->where('invoice_validations.plant_id', $plantId)
|
||||||
|
->where('items.code', $itemCode)
|
||||||
|
->whereNull('invoice_validations.serial_number')
|
||||||
|
->where('invoice_validations.quantity', '>', 0)
|
||||||
|
->orderBy('invoice_validations.created_at')
|
||||||
|
->select('invoice_validations.*')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
if ($records->isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($records as $record) {
|
||||||
|
|
||||||
|
if ($palletWeight <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$usedQty = min($record->quantity, $palletWeight);
|
||||||
|
|
||||||
|
$record->quantity -= $usedQty;
|
||||||
|
|
||||||
|
if ($usedQty == $record->quantity + $usedQty) {
|
||||||
|
$record->serial_number = $processOrder;
|
||||||
|
$record->quantity = $palletWeight;
|
||||||
|
$record->save();
|
||||||
|
} else {
|
||||||
|
$record->save();
|
||||||
|
|
||||||
|
InvoiceValidation::create([
|
||||||
|
'sticker_master_id' => $record->sticker_master_id,
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'invoice_number' => $invoiceNumber,
|
||||||
|
'serial_number' => $processOrder,
|
||||||
|
'quantity' => $usedQty,
|
||||||
|
'operator_id' => $operatorName,
|
||||||
|
'created_by' => $operatorName,
|
||||||
|
'updated_by' => $operatorName,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$palletWeight -= $usedQty;
|
||||||
|
|
||||||
|
// if ($record->quantity <= 0) {
|
||||||
|
// $records->forget($key);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$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();
|
||||||
|
|
||||||
|
$this->form->fill([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'invoice_number' => $invoiceNumber,
|
||||||
|
'serial_number' => null,
|
||||||
|
'total_quantity' => $totQuan,
|
||||||
|
'update_invoice' => false,
|
||||||
|
'scanned_quantity' => $scanMQuan,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
$itemCode = null;
|
$itemCode = null;
|
||||||
$this->currentItemCode = '';
|
$this->currentItemCode = '';
|
||||||
@@ -2733,7 +3106,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title('Invalid Material QR Format')
|
->title('Invalid Material QR Format')
|
||||||
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
->body('Scan valid Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
|
||||||
->seconds(1)
|
->seconds(1)
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
@@ -2866,6 +3239,12 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
|
|
||||||
$hasQuanTyp = ($record->material_type == 3) ? true : false;
|
$hasQuanTyp = ($record->material_type == 3) ? true : false;
|
||||||
|
|
||||||
|
if ($hasQuanTyp && $curMaterialSer && $curMaterialQty) {
|
||||||
|
$batchNumber = null;
|
||||||
|
$serialNumber = $curMaterialSer;
|
||||||
|
$curScanQty = $curMaterialQty;
|
||||||
|
}
|
||||||
|
|
||||||
$record = InvoiceValidation::where('invoice_number', $invoiceNumber)
|
$record = InvoiceValidation::where('invoice_number', $invoiceNumber)
|
||||||
->where('plant_id', $plantId)
|
->where('plant_id', $plantId)
|
||||||
->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode) {
|
->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode) {
|
||||||
@@ -2948,7 +3327,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
->title('Invalid Quantity Material QR Format')
|
->title('Invalid Quantity Material QR Format')
|
||||||
->body('Scan valid Quantity Material QR code proceed!<br>Ex:123456|12345|12345678|1/1')
|
->body('Scan valid Quantity Material QR code to proceed!<br>Sample formats are:<br>123456|123456789|001|5kg (or)<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1')
|
||||||
->seconds(2)
|
->seconds(2)
|
||||||
->send();
|
->send();
|
||||||
$this->dispatch('playWarnSound');
|
$this->dispatch('playWarnSound');
|
||||||
@@ -2994,8 +3373,8 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$record->serial_number = $serialNumber;
|
$record->serial_number = $serialNumber;
|
||||||
$record->batch_number = $batchNumber;
|
$record->batch_number = $batchNumber;
|
||||||
$record->operator_id = $operatorName;
|
$record->operator_id = $operatorName;
|
||||||
// $record->updated_by = $operatorName;
|
$record->updated_by = $operatorName;
|
||||||
// $record->updated_at = now();
|
$record->updated_at = now();
|
||||||
$record->save();
|
$record->save();
|
||||||
|
|
||||||
// InvoiceValidation::create([
|
// InvoiceValidation::create([
|
||||||
@@ -3231,7 +3610,6 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
$record = InvoiceValidation::where('serial_number', $serialNumber)->where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->first();
|
$record = InvoiceValidation::where('serial_number', $serialNumber)->where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->first();
|
||||||
// $invoiceNumber = $this->form->getState()['invoice_number'];
|
|
||||||
|
|
||||||
if (! $record) {
|
if (! $record) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
|
|||||||
Reference in New Issue
Block a user