1
0
forked from poc/pds

Added Item code exist validation against plant on create invoice and scan qr

This commit is contained in:
dhanabalan
2025-04-25 13:01:17 +05:30
parent b3c034a602
commit 716d2e48d7

View File

@@ -277,6 +277,7 @@ class CreateInvoiceValidation extends CreateRecord
$uniqueCodes = array_unique($materialCodes);
//itemNotFound
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes) {
$query->whereIn('code', $uniqueCodes);
@@ -294,7 +295,36 @@ class CreateInvoiceValidation extends CreateRecord
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown Item Codes')
->title('Unknown: Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($filePath)) {
$disk->delete($filePath);
}
return;
}
//plantNotFound
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes, $plantId) {
$query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId);
})
->get();
$matchedCodes = $matchedItems->pluck('item.code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes))
{
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database for choosed plant." : 'The following item codes are not found in database for choosed plant:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown: Item Codes')
->body($message)
->danger()
->send();
@@ -737,6 +767,7 @@ class CreateInvoiceValidation extends CreateRecord
$uniqueCodes = array_unique($materialCodes);
//itemNotFound
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes) {
$query->whereIn('code', $uniqueCodes);
@@ -751,10 +782,10 @@ class CreateInvoiceValidation extends CreateRecord
{
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes); //->where('plant_id', $plantId)
Notification::make()
->title('Unknown Item Codes')
->title('Unknown: Item Codes')
->body($message)
->danger()
->send();
@@ -765,6 +796,36 @@ class CreateInvoiceValidation extends CreateRecord
return;
}
//plantNotFound
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes, $plantId) {
$query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId);
})
->get();
$matchedCodes = $matchedItems->pluck('item.code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes))
{
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database for choosed plant." : 'The following item codes are not found in database for choosed plant:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown: Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($filePath)) {
$disk->delete($filePath);
}
return;
}
$invalidCodes = $matchedItems
->filter(fn ($sticker) => !empty($sticker->material_type)) //filter invalid
->pluck('item.code')
@@ -1217,6 +1278,7 @@ class CreateInvoiceValidation extends CreateRecord
$uniqueCodes = array_unique($materialCodes);
//itemNotFound
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes) {
$query->whereIn('code', $uniqueCodes);
@@ -1234,7 +1296,36 @@ class CreateInvoiceValidation extends CreateRecord
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown Item Codes')
->title('Unknown: Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($filePath)) {
$disk->delete($filePath);
}
return;
}
//plantNotFound
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes, $plantId) {
$query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId);
})
->get();
$matchedCodes = $matchedItems->pluck('item.code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes))
{
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database for choosed plant." : 'The following item codes are not found in database for choosed plant:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown: Item Codes')
->body($message)
->danger()
->send();
@@ -1250,7 +1341,6 @@ class CreateInvoiceValidation extends CreateRecord
->pluck('item.code')
->toArray();
if (!empty($invalidCodes))
{
$missingCount = count($invalidCodes);
@@ -1551,6 +1641,7 @@ class CreateInvoiceValidation extends CreateRecord
$uniqueCodes = array_unique($materialCodes);
//itemNotFound
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes) {
$query->whereIn('code', $uniqueCodes);
@@ -1578,7 +1669,36 @@ class CreateInvoiceValidation extends CreateRecord
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown Item Codes')
->title('Unknown: Item Codes')
->body($message)
->danger()
->send();
if ($disk->exists($filePath)) {
$disk->delete($filePath);
}
return;
}
//plantNotFound
$matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes, $plantId) {
$query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId);
})
->get();
$matchedCodes = $matchedItems->pluck('item.code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes))
{
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database for choosed plant." : 'The following item codes are not found in database for choosed plant:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown: Item Codes')
->body($message)
->danger()
->send();
@@ -1594,7 +1714,6 @@ class CreateInvoiceValidation extends CreateRecord
->pluck('item.code')
->toArray();
if (!empty($invalidCodes))
{
$missingCount = count($invalidCodes);
@@ -1995,7 +2114,7 @@ class CreateInvoiceValidation extends CreateRecord
}
// $record = StickerMaster::where('plant_id', $plantId)->with('item')->where('item.code', $itemCode);
$record = StickerMaster::where('plant_id', $plantId)->whereHas('item', function ($query) {
$record = StickerMaster::whereHas('item', function ($query) {
$query->where('code', $this->currentItemCode);
});
if ($record->count() <= 0)
@@ -2016,6 +2135,27 @@ class CreateInvoiceValidation extends CreateRecord
return;
}
$record = StickerMaster::where('plant_id', $plantId)->whereHas('item', function ($query) {
$query->where('code', $this->currentItemCode);
});
if ($record->count() <= 0)
{
Notification::make()
->title('Unknown: Item Code')
->body("Item code '$itemCode' not found in database for choosed plant.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'scanned_quantity'=> $scanMQuan,
]);
return;
}
$record = StickerMaster::where('plant_id', $plantId)->where('item_id', Item::where('plant_id', $plantId)->where('code', $itemCode)->first()->id)->first();
if (empty($record->material_type) || !$record->material_type)