1
0
forked from poc/pds

Hide update_invoice button on scanning and Added operate_id on update and Added material_type 3 func.

This commit is contained in:
dhanabalan
2025-04-28 00:43:30 +05:30
parent be9457c4e2
commit 550792372a

View File

@@ -43,6 +43,8 @@ class CreateInvoiceValidation extends CreateRecord
public $plantId;
public $hasQuanTyp = false;
public $invoiceNumber;
public bool $hasSearched = false;
@@ -137,6 +139,7 @@ class CreateInvoiceValidation extends CreateRecord
Notification::make()
->title("Start the scanning process!")
->info()
->seconds(1)
->send();
// $hasRecords = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->first()->stickerMasterRelation->material_type ?? null;
// $this->dispatch( (!empty($hasRecords) && $hasRecords) ? 'refreshMaterialInvoiceData' : 'refreshInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId); //$this->invoiceNumber
@@ -174,6 +177,7 @@ class CreateInvoiceValidation extends CreateRecord
$materialCodes = [];
$missingQuantities = [];
$invalidMatQuan = [];
$hasQuanTypIds = [];
$validRowsFound = false;
foreach ($rows as $index => $row)
@@ -234,7 +238,7 @@ class CreateInvoiceValidation extends CreateRecord
if (!empty($uniqueInvalidCodes)) {
Notification::make()
->title('Invalid Item Codes')
->title('Invalid: Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger()
->send();
@@ -348,10 +352,10 @@ class CreateInvoiceValidation extends CreateRecord
$message = $missingCount > 10 ? "'$missingCount' Serial Invoice item codes found." : "'Serial Invoice' item codes found:<br>" . implode(', ', $invalidCodes);
Notification::make()
->title('Invalid Item Codes')
->body($message)
->danger()
->send();
->title('Invalid: Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($filePath)) {
$disk->delete($filePath);
@@ -362,6 +366,7 @@ class CreateInvoiceValidation extends CreateRecord
$nonNumericQtyCodes = [];
$zeroQtyCodes = [];
$notDivisibleCodes = [];
$hasQuanTyp = false;
foreach ($matchedItems as $sticker)
{
@@ -380,6 +385,9 @@ class CreateInvoiceValidation extends CreateRecord
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if (empty($excelCode) || empty($excelMatQty)) {
continue;
}
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty; // Sum up the quantities
@@ -394,6 +402,11 @@ class CreateInvoiceValidation extends CreateRecord
$notDivisibleCodes[] = $code;
}
}
else if ($materialType == 3)
{
$hasQuanTyp = true;
$hasQuanTypIds[] = $sticker->id;
}
}
$showValidationNotification = function(array $codes, string $message) {
@@ -428,7 +441,7 @@ class CreateInvoiceValidation extends CreateRecord
$inserted = 0;
foreach ($matchedItems as $sticker)
{
if ($newQuan === -1)
if ($newQuan === -1 && !$hasQuanTyp)
{
InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->where(function($query) {
$query->whereNull('serial_number')->orWhere('serial_number', '');
@@ -436,7 +449,15 @@ class CreateInvoiceValidation extends CreateRecord
->delete();
$newQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count();
continue;
}
else if ($newQuan === -1 && $hasQuanTyp)
{
InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->where(function($query) {
$query->whereNull('serial_number')->orWhere('serial_number', '');
})->whereNotIn('sticker_master_id', $hasQuanTypIds)
->delete();
$newQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count();
}
$code = $sticker->item->code;
@@ -454,6 +475,10 @@ class CreateInvoiceValidation extends CreateRecord
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if (empty($excelCode) || empty($excelMatQty)) {
continue;
}
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty; // Sum up the quantities
}
@@ -491,6 +516,10 @@ class CreateInvoiceValidation extends CreateRecord
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if (empty($excelCode) || empty($excelMatQty)) {
continue;
}
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty; // Sum up the quantities
}
@@ -518,6 +547,115 @@ class CreateInvoiceValidation extends CreateRecord
}
}
}
else if ($materialType == 3)
{
$totalExcelQty = 0;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if (empty($excelCode) || empty($excelMatQty)) {
continue;
}
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty;
}
}
$existEmpRecQty = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->where(function($query) {
$query->whereNull('serial_number')->orWhere('serial_number', '');
})->where('sticker_master_id', $sticker->id)->first();
$existEmpQty = $existEmpRecQty ? $existEmpRecQty->quantity : 0;
$existComQty = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->where(function($query) {
$query->whereNotNull('serial_number')->where('serial_number', '!=', '');
})
->where('sticker_master_id', $sticker->id)
->sum(column: 'quantity');
$existComQty = $existComQty ? $existComQty : 0;
// 8 = 3 + 5 // 8 = 5 + 3 // 8 = 0 + 8 // 8 = 8 + 0
// 8 = 3 + 5 // 8 = 5 + 3 // 8 = 0 + 8 // 8 = 8 + 0
// 0 = 0 + 0
$existQty = $existEmpQty + $existComQty;
// 8 <= 11 // 8 <= 8 // 8 <= 11 // 8 <= 9
// 8 <= 7 // 8 <= 7 // 8 <= 7 // 8 <= 7
// 0 <= 5
if ($existQty <= $totalExcelQty)
{
// 6 = 11 - 5 // 5 = 8 - 3 // 3 = 11 - 8 // 9 = 9 - 0
// 5 = 5 - 0
$newInsQty = $totalExcelQty - $existComQty;
// 3 > 0 // 5 > 0 // 0 > 0 // 8 > 0
// 0 > 0
if($existEmpQty > 0) // update
{
// 3 = 6 // 5 = 5 // 0 = 3 // 8 = 9
// 0 = 5
if($existEmpQty == $newInsQty) { continue; }
// $existEmpRecQty->delete();
$existEmpRecQty->update([
'quantity' => $newInsQty,
'operator_id'=> $operatorName,
'updated_at' => now(),
]);
$newQuan--;
$inserted++;
}
else if ($newInsQty > 0) // if ($sticker) // create
{
InvoiceValidation::create([
'sticker_master_id' => $sticker->id,
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'quantity' => $newInsQty,
'operator_id'=> $operatorName,
]);
$inserted++;
}
}
// 8 > 7 // 8 > 7 // 8 > 7 // 8 > 7
else
{
// 2 = 7 - 5 // 4 = 7 - 3 // -1 = 7 - 8 // 7 = 7 - 0
$newInsQty = $totalExcelQty - $existComQty;
// 3 > 0 // 5 > 0 // 0 > 0 // 8 > 0
if($existEmpQty > 0) // update
{
// 3 = 2 // 5 = 4 // 0 = -1 // 8 = 7
if($existEmpQty == $newInsQty) { continue; }
// $existEmpRecQty->delete();
$existEmpRecQty->update([
'quantity' => $newInsQty,
'operator_id'=> $operatorName,
'updated_at' => now(),
]);
$newQuan--;
$inserted++;
}
else if ($newInsQty > 0) // create
{
InvoiceValidation::create([
'sticker_master_id' => $sticker->id,
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'quantity' => $newInsQty,
'operator_id'=> $operatorName,
]);
$inserted++;
}
}
}
}
if ($inserted > 0 || $oldQuan !== $newQuan)
@@ -754,7 +892,7 @@ class CreateInvoiceValidation extends CreateRecord
if (!empty($uniqueInvalidCodes)) {
Notification::make()
->title('Invalid Item Codes')
->title('Invalid: Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger()
->send();
@@ -825,7 +963,6 @@ class CreateInvoiceValidation extends CreateRecord
return;
}
$invalidCodes = $matchedItems
->filter(fn ($sticker) => !empty($sticker->material_type)) //filter invalid
->pluck('item.code')
@@ -838,7 +975,30 @@ class CreateInvoiceValidation extends CreateRecord
$message = $missingCount > 10 ? "'$missingCount' Material Invoice item codes found." : "'Material Invoice' item codes found:<br>" . implode(', ', $invalidCodes);
Notification::make()
->title('Invalid Item Codes')
->title('Invalid: Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($filePath)) {
$disk->delete($filePath);
}
return;
}
$missPackCodes = $matchedItems
->filter(fn ($sticker) => empty($sticker->tube_sticker_motor) && empty($sticker->tube_sticker_pump) && empty($sticker->tube_sticker_pumpset) && empty($sticker->panel_box_code)) //filter invalid
->pluck('item.code')
->toArray();
if (!empty($missPackCodes))
{
$missingCount = count($missPackCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes doesn't have valid package type to proceed!" : "The following 'Item Code' doesn't have valid package type:<br>" . implode(', ', $missPackCodes);
Notification::make()
->title('Invalid: Item Codes')
->body($message)
->danger()
->send();
@@ -1235,7 +1395,7 @@ class CreateInvoiceValidation extends CreateRecord
if (!empty($uniqueInvalidCodes)) {
Notification::make()
->title('Invalid Item Codes')
->title('Invalid: Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger()
->send();
@@ -1348,7 +1508,7 @@ class CreateInvoiceValidation extends CreateRecord
$message = $missingCount > 10 ? "'$missingCount' Serial Invoice item codes found." : "'Serial Invoice' item codes found:<br>" . implode(', ', $invalidCodes);
Notification::make()
->title('Invalid Item Codes')
->title('Invalid: Item Codes')
->body($message)
->danger()
->send();
@@ -1380,6 +1540,9 @@ class CreateInvoiceValidation extends CreateRecord
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if (empty($excelCode) || empty($excelMatQty)) {
continue;
}
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty; // Sum up the quantities
@@ -1440,6 +1603,10 @@ class CreateInvoiceValidation extends CreateRecord
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if (empty($excelCode) || empty($excelMatQty)) {
continue;
}
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty; // Sum up the quantities
}
@@ -1471,6 +1638,10 @@ class CreateInvoiceValidation extends CreateRecord
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if (empty($excelCode) || empty($excelMatQty)) {
continue;
}
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty; // Sum up the quantities
}
@@ -1490,6 +1661,37 @@ class CreateInvoiceValidation extends CreateRecord
}
}
}
else if ($materialType == 3)
{
$totalExcelQty = 0;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
$excelCode = trim($row[0]);
$excelMatQty = trim($row[1]);
if (empty($excelCode) || empty($excelMatQty)) {
continue;
}
if ($excelCode === $code && is_numeric($excelMatQty)) {
$totalExcelQty += $excelMatQty; // Sum up the quantities
}
}
if ($sticker) {
InvoiceValidation::create([
'sticker_master_id' => $sticker->id,
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'quantity' => $totalExcelQty,
'operator_id'=> $operatorName,
]);
$inserted++;
}
}
}
if ($inserted > 0)
@@ -1628,7 +1830,7 @@ class CreateInvoiceValidation extends CreateRecord
if (!empty($uniqueInvalidCodes)) {
Notification::make()
->title('Invalid Item Codes')
->title('Invalid: Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger()
->send();
@@ -1721,7 +1923,30 @@ class CreateInvoiceValidation extends CreateRecord
$message = $missingCount > 10 ? "'$missingCount' Material Invoice item codes found." : "'Material Invoice' item codes found:<br>" . implode(', ', $invalidCodes);
Notification::make()
->title('Invalid Item Codes')
->title('Invalid: Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($filePath)) {
$disk->delete($filePath);
}
return;
}
$missPackCodes = $matchedItems
->filter(fn ($sticker) => empty($sticker->tube_sticker_motor) && empty($sticker->tube_sticker_pump) && empty($sticker->tube_sticker_pumpset) && empty($sticker->panel_box_code))
->pluck('item.code')
->toArray();
if (!empty($missPackCodes))
{
$missingCount = count($missPackCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes doesn't have valid package type to proceed!" : "The following 'Item Code' doesn't have valid package type:<br>" . implode(', ', $missPackCodes);
Notification::make()
->title('Invalid: Item Codes')
->body($message)
->danger()
->send();
@@ -1932,6 +2157,9 @@ class CreateInvoiceValidation extends CreateRecord
public function processSerialNumber($serNo)
{
$user = Filament::auth()->user();
$operatorName = $user->name;
$serialNumber = null;
$plantId = $this->form->getState()['plant_id'];
$this->plantId = $plantId;
@@ -1956,6 +2184,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => 0, //$totQuan
'update_invoice' => false,
'scanned_quantity'=> 0, //($totMQuan > 0) ? $scanMQuan : $scanSQuan
]);
$this->dispatch('refreshEmptyInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId);
@@ -1978,6 +2207,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
@@ -2000,29 +2230,93 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
//$hasRecords = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->first()->stickerMasterRelation->material_type ?? null;
$this->dispatch( 'refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId);
}
$pattern1 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>.+)$/i';
$pattern2 = '/^(?<item_code>[^|]+)\|(?<batch_id>[^|]+)-(?<batch_count>.+)$/i';
$pattern1 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>[^|]+)\/(?<batch_quantity>.+)$/i';
$pattern2 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>.+)$/i';
$pattern3 = '/^(?<item_code>[^|]+)\|(?<batch_id>[^|]+)-(?<batch_count>.+)$/i';
$itemCode = '';
$batchNumber = '';
$curScanQty = '';
if (preg_match($pattern1, $serNo, $matches)) {
$itemCode = $matches['item_code'];
$this->currentItemCode = $itemCode;
$batchNumber = $matches['batch_number'];
$serialNumber = $matches['batch_id'] . '-' . $matches['batch_count'];
$curScanQty = $matches['batch_quantity'];
if(empty($matches['batch_id']) || !$matches['batch_id'])
{
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')
->send();
$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 proceed!<br>Sample formats are:<br>123456|12345|12345678|1/1 (or)<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
->send();
$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')
->send();
$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($pattern2, $serNo, $matches)) {
$itemCode = $matches['item_code'];
$this->currentItemCode = $itemCode;
$batchNumber = $matches['batch_number'];
$serialNumber = $matches['batch_id'] . '-' . $matches['batch_count'];
if(empty($matches['batch_id']) || !$matches['batch_id'])
{
Notification::make()
->danger()
->title('Invalid Material QR Format')
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
->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')
->send();
$this->form->fill([
@@ -2030,6 +2324,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
@@ -2039,7 +2334,7 @@ class CreateInvoiceValidation extends CreateRecord
Notification::make()
->danger()
->title('Invalid Material QR Format')
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
->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')
->send();
$this->form->fill([
@@ -2047,11 +2342,12 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
}
} elseif (preg_match($pattern2, $serNo, $matches)) {
} elseif (preg_match($pattern3, $serNo, $matches)) {
$itemCode = $matches['item_code'];
$this->currentItemCode = $itemCode;
$batchNumber = null; // batch_number not present in this pattern
@@ -2062,7 +2358,7 @@ class CreateInvoiceValidation extends CreateRecord
Notification::make()
->danger()
->title('Invalid Material QR Format')
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
->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')
->send();
$this->form->fill([
@@ -2070,6 +2366,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
@@ -2079,7 +2376,7 @@ class CreateInvoiceValidation extends CreateRecord
Notification::make()
->danger()
->title('Invalid Material QR Format')
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
->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')
->send();
$this->form->fill([
@@ -2087,12 +2384,14 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
}
} else {
$itemCode = null;
$this->currentItemCode = '';
$batchNumber = null;
$serNo = null;
$serialNumber = null;
@@ -2100,7 +2399,7 @@ class CreateInvoiceValidation extends CreateRecord
Notification::make()
->danger()
->title('Invalid Material QR Format')
->body('Scan valid Material QR code proceed!<br>Sample formats are:<br>123456|12345|12345678|1 (or)<br>123456|12345678-1')
->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')
->send();
$this->form->fill([
@@ -2108,6 +2407,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
@@ -2130,6 +2430,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
@@ -2151,6 +2452,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
@@ -2171,11 +2473,14 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
}
$hasQuanTyp = ($record->material_type == 3) ? true : false;
$record = InvoiceValidation::where('invoice_number', $invoiceNumber)
->where('plant_id', $plantId)
->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode) {
@@ -2194,16 +2499,16 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
}
//->where('serial_number', '!=', '')
$record = InvoiceValidation::where('invoice_number', $invoiceNumber)
->where('serial_number', null)
->where('plant_id', $plantId)
->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode) {
// ->whereNotNull('serial_number')->where('serial_number', '!=', '')
$record = InvoiceValidation::where('invoice_number', $invoiceNumber)->where(function($query) {
$query->whereNull('serial_number')->orWhere('serial_number', '');
})->where('plant_id', $plantId)->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode) {
$query->where('plant_id', $this->plantId)->where('code', $itemCode);
})
->first();
@@ -2219,6 +2524,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
@@ -2238,17 +2544,83 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
}
$record->serial_number = $serialNumber;
if($batchNumber && !empty($batchNumber))
if($hasQuanTyp)
{
$record->batch_number = $batchNumber;
$createdDt = $record->created_at;
$stickMasterId = $record->sticker_master_id;
$curExistQty = $record->quantity;
// $curScanQty = 2;
if($curExistQty > $curScanQty) // 5 > 2
{
$record->quantity = $curExistQty - $curScanQty; // 5 - 2
$record->operator_id = $operatorName;
// $record->updated_at = now();
$record->save();
InvoiceValidation::create([
'sticker_master_id' => $stickMasterId,
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'serial_number' => $serialNumber,
'batch_number' => $batchNumber,
'quantity' => $curScanQty,
'created_at' => $createdDt,
'operator_id'=> $operatorName,
]);
}
else if($curExistQty == $curScanQty) // 2 = 2
{
// $record->delete();
$record->serial_number = $serialNumber;
$record->batch_number = $batchNumber;
$record->operator_id = $operatorName;
// $record->updated_at = now();
$record->save();
// InvoiceValidation::create([
// 'sticker_master_id' => $stickMasterId,
// 'plant_id' => $plantId,
// 'invoice_number' => $invoiceNumber,
// 'quantity' => $curScanQty,
// 'created_at' => $createdDt,
// 'operator_id'=> $operatorName,
// ]);
}
else
{
Notification::make()
->title('Item Code Limit Exceeds')
->body("Scanned item code '$itemCode' has '$curScanQty' quantity.<br>But, '$curExistQty' quantity only available for the invoice '$invoiceNumber'.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanMQuan,
]);
return;
}
}
else
{
$record->serial_number = $serialNumber;
// if($batchNumber && !empty($batchNumber)) {}
$record->batch_number = $batchNumber;
// $record->updated_at = now();
$record->operator_id = $operatorName;
$record->save();
}
$record->save();
Notification::make()
->title('Success: Material QR')
@@ -2256,6 +2628,8 @@ class CreateInvoiceValidation extends CreateRecord
->success()
->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();
if($totQuan === $scannedMQuantity)
@@ -2271,6 +2645,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scannedMQuantity,
]);
@@ -2292,6 +2667,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scannedMQuantity,
]);
$this->dispatch( 'refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId);
@@ -2313,6 +2689,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
@@ -2335,6 +2712,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
//$hasRecords = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->first()->stickerMasterRelation->material_type ?? null;
@@ -2353,6 +2731,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2376,7 +2755,7 @@ class CreateInvoiceValidation extends CreateRecord
if (!$record) {
Notification::make()
->title('Serial Number Not Found')
->body("Serial '$serialNumber' not found in database.")
->body("Serial '$serialNumber' not found in database for choosed plant.")
->danger()
->send();
@@ -2385,6 +2764,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2405,6 +2785,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2429,6 +2810,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2444,6 +2826,25 @@ class CreateInvoiceValidation extends CreateRecord
$hadPumpSetQr = $record->scanned_status_set ?? null;
$hadCapacitorQr = $record->capacitor_scanned_status ?? null;
if (!$hasMotorQr && !$hasPumpQr && !$hasPumpSetQr && !$hasCapacitorQr)
{
Notification::make()
->title('Invalid: Item Code')
->body("Scanned 'Item Code' doesn't have valid package type to proceed!")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
}
if ($isMarkM) {
if (!$hasMotorQr)
{
@@ -2458,6 +2859,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2475,6 +2877,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2503,6 +2906,7 @@ class CreateInvoiceValidation extends CreateRecord
{
$record->scanned_status = 'Scanned';
}
$record->operator_id = $operatorName;
$record->save();
Notification::make()
@@ -2517,6 +2921,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scannedQuantity,
]);
@@ -2560,6 +2965,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2577,6 +2983,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2605,6 +3012,7 @@ class CreateInvoiceValidation extends CreateRecord
{
$record->scanned_status = 'Scanned';
}
$record->operator_id = $operatorName;
$record->save();
Notification::make()
@@ -2619,6 +3027,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scannedQuantity,
]);
@@ -2664,6 +3073,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2681,6 +3091,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2696,6 +3107,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scannedQuantity,
]);
$this->dispatch( 'refreshInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId);
@@ -2717,6 +3129,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2734,6 +3147,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scanSQuan,
]);
return;
@@ -2762,6 +3176,7 @@ class CreateInvoiceValidation extends CreateRecord
{
$record->scanned_status = 'Scanned';
}
$record->operator_id = $operatorName;
$record->save();
Notification::make()
@@ -2776,6 +3191,7 @@ class CreateInvoiceValidation extends CreateRecord
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity'=> $scannedQuantity,
]);