Merge pull request 'Added item code missing logic on new invoice' (#232) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s

Reviewed-on: #232
This commit was merged in pull request #232.
This commit is contained in:
2026-01-22 06:20:30 +00:00

View File

@@ -17,9 +17,9 @@ use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Livewire\Attributes\On;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use Str; use Str;
use Livewire\Attributes\On;
class CreateInvoiceValidation extends CreateRecord class CreateInvoiceValidation extends CreateRecord
{ {
@@ -53,6 +53,7 @@ class CreateInvoiceValidation extends CreateRecord
public bool $showCapacitorInput = false; public bool $showCapacitorInput = false;
public $excel_file; public $excel_file;
public $mInvoiceNo; public $mInvoiceNo;
public function getFormActions(): array public function getFormActions(): array
@@ -121,8 +122,7 @@ class CreateInvoiceValidation extends CreateRecord
// ..GET SERIAL INVOICE API // ..GET SERIAL INVOICE API
if(strlen($invoiceNumber) > 15) if (strlen($invoiceNumber) > 15) {
{
$payloadJson = base64_decode(strtr($parts[1], '-_', '+/')); $payloadJson = base64_decode(strtr($parts[1], '-_', '+/'));
@@ -132,41 +132,44 @@ class CreateInvoiceValidation extends CreateRecord
->danger() ->danger()
->seconds(1) ->seconds(1)
->send(); ->send();
return; return;
} }
$payload = json_decode($payloadJson, true); $payload = json_decode($payloadJson, true);
if (! isset($payload['data'])) {
if (!isset($payload['data'])) {
Notification::make() Notification::make()
->title('Invalid payload for scanned qr code.') ->title('Invalid payload for scanned qr code.')
->info() ->info()
->seconds(1) ->seconds(1)
->send(); ->send();
return; return;
} }
$documentData = $payload['data']; $documentData = $payload['data'];
if($documentData == '' || $documentData == ''){ if ($documentData == '' || $documentData == '') {
Notification::make() Notification::make()
->title('Invalid payload for scanned qr code.') ->title('Invalid payload for scanned qr code.')
->info() ->info()
->seconds(1) ->seconds(1)
->send(); ->send();
return; return;
} }
// Extract DocNo // Extract DocNo
preg_match('/"DocNo"\s*:\s*"([^"]+)"/', $documentData, $matches); preg_match('/"DocNo"\s*:\s*"([^"]+)"/', $documentData, $matches);
if (!isset($matches[1])) { if (! isset($matches[1])) {
Notification::make() Notification::make()
->title('Invoice number not found.') ->title('Invoice number not found.')
->info() ->info()
->seconds(1) ->seconds(1)
->send(); ->send();
return; return;
} }
@@ -175,7 +178,7 @@ class CreateInvoiceValidation extends CreateRecord
} }
} }
//dd($invoiceNumber); // dd($invoiceNumber);
// .. // ..
@@ -1427,6 +1430,7 @@ class CreateInvoiceValidation extends CreateRecord
return; return;
} }
$missingCodes = [];
foreach ($rows as $index => $row) { foreach ($rows as $index => $row) {
if ($index == 0) { if ($index == 0) {
continue; continue;
@@ -1438,8 +1442,8 @@ class CreateInvoiceValidation extends CreateRecord
if (Str::length($materialCode) < 6) { if (Str::length($materialCode) < 6) {
continue; continue;
} else { } else {
$sticker = StickerMaster::where('plant_id', $plantId)->whereHas('item', function ($query) use ($materialCode) { $sticker = StickerMaster::where('plant_id', $plantId)->whereHas('item', function ($query) use ($plantId, $materialCode) {
$query->where('plant_id', $this->plantId)->where('code', $materialCode); // Check if item.code matches Excel's materialCode $query->where('plant_id', $plantId)->where('code', $materialCode); // $this->plantId >> Check if item.code matches Excel's materialCode
}); });
if ($sticker->exists()) { if ($sticker->exists()) {
if ($sticker->first()->material_type && ! empty($sticker->first()->material_type)) { if ($sticker->first()->material_type && ! empty($sticker->first()->material_type)) {
@@ -1450,6 +1454,8 @@ class CreateInvoiceValidation extends CreateRecord
break; break;
} }
} else { } else {
$missingCodes[] = $materialCode;
continue; continue;
} }
} }
@@ -1458,7 +1464,26 @@ class CreateInvoiceValidation extends CreateRecord
} }
} }
if ($invoiceType == 'M') { $uniqueCodes = array_unique($missingCodes);
if (! empty($uniqueCodes)) {
$missingCount = count($uniqueCodes);
$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(', ', $uniqueCodes);
Notification::make()
->title('Unknown: Item Codes')
->body($message)
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
// if ($disk->exists($filePath)) {
// $disk->delete($filePath);
// }
return;
} elseif ($invoiceType == 'M') {
$invalidMatCodes = []; $invalidMatCodes = [];
$materialCodes = []; $materialCodes = [];
$missingQuantities = []; $missingQuantities = [];
@@ -3195,7 +3220,7 @@ class CreateInvoiceValidation extends CreateRecord
if (! empty($emails)) { if (! empty($emails)) {
Mail::to($emails)->send( Mail::to($emails)->send(
new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode,$mUserName,'NotFoundInvoice') new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, $mUserName, 'NotFoundInvoice')
); );
} else { } else {
\Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial."); \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");