Added Item code exist validation against plant on create invoice and scan qr
This commit is contained in:
@@ -277,6 +277,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
|
|
||||||
$uniqueCodes = array_unique($materialCodes);
|
$uniqueCodes = array_unique($materialCodes);
|
||||||
|
|
||||||
|
//itemNotFound
|
||||||
$matchedItems = StickerMaster::with('item')
|
$matchedItems = StickerMaster::with('item')
|
||||||
->whereHas('item', function ($query) use ($uniqueCodes) {
|
->whereHas('item', function ($query) use ($uniqueCodes) {
|
||||||
$query->whereIn('code', $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);
|
$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()
|
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)
|
->body($message)
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
@@ -737,6 +767,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
|
|
||||||
$uniqueCodes = array_unique($materialCodes);
|
$uniqueCodes = array_unique($materialCodes);
|
||||||
|
|
||||||
|
//itemNotFound
|
||||||
$matchedItems = StickerMaster::with('item')
|
$matchedItems = StickerMaster::with('item')
|
||||||
->whereHas('item', function ($query) use ($uniqueCodes) {
|
->whereHas('item', function ($query) use ($uniqueCodes) {
|
||||||
$query->whereIn('code', $uniqueCodes);
|
$query->whereIn('code', $uniqueCodes);
|
||||||
@@ -751,10 +782,10 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
{
|
{
|
||||||
$missingCount = count($missingCodes);
|
$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()
|
Notification::make()
|
||||||
->title('Unknown Item Codes')
|
->title('Unknown: Item Codes')
|
||||||
->body($message)
|
->body($message)
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
@@ -765,6 +796,36 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
return;
|
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
|
$invalidCodes = $matchedItems
|
||||||
->filter(fn ($sticker) => !empty($sticker->material_type)) //filter invalid
|
->filter(fn ($sticker) => !empty($sticker->material_type)) //filter invalid
|
||||||
->pluck('item.code')
|
->pluck('item.code')
|
||||||
@@ -1217,6 +1278,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
|
|
||||||
$uniqueCodes = array_unique($materialCodes);
|
$uniqueCodes = array_unique($materialCodes);
|
||||||
|
|
||||||
|
//itemNotFound
|
||||||
$matchedItems = StickerMaster::with('item')
|
$matchedItems = StickerMaster::with('item')
|
||||||
->whereHas('item', function ($query) use ($uniqueCodes) {
|
->whereHas('item', function ($query) use ($uniqueCodes) {
|
||||||
$query->whereIn('code', $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);
|
$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()
|
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)
|
->body($message)
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
@@ -1250,7 +1341,6 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
->pluck('item.code')
|
->pluck('item.code')
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
|
|
||||||
if (!empty($invalidCodes))
|
if (!empty($invalidCodes))
|
||||||
{
|
{
|
||||||
$missingCount = count($invalidCodes);
|
$missingCount = count($invalidCodes);
|
||||||
@@ -1551,6 +1641,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
|
|
||||||
$uniqueCodes = array_unique($materialCodes);
|
$uniqueCodes = array_unique($materialCodes);
|
||||||
|
|
||||||
|
//itemNotFound
|
||||||
$matchedItems = StickerMaster::with('item')
|
$matchedItems = StickerMaster::with('item')
|
||||||
->whereHas('item', function ($query) use ($uniqueCodes) {
|
->whereHas('item', function ($query) use ($uniqueCodes) {
|
||||||
$query->whereIn('code', $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);
|
$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()
|
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)
|
->body($message)
|
||||||
->danger()
|
->danger()
|
||||||
->send();
|
->send();
|
||||||
@@ -1594,7 +1714,6 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
->pluck('item.code')
|
->pluck('item.code')
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
|
|
||||||
if (!empty($invalidCodes))
|
if (!empty($invalidCodes))
|
||||||
{
|
{
|
||||||
$missingCount = count($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)->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);
|
$query->where('code', $this->currentItemCode);
|
||||||
});
|
});
|
||||||
if ($record->count() <= 0)
|
if ($record->count() <= 0)
|
||||||
@@ -2016,6 +2135,27 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
return;
|
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();
|
$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)
|
if (empty($record->material_type) || !$record->material_type)
|
||||||
|
|||||||
Reference in New Issue
Block a user