ranjith-dev #268
@@ -15,6 +15,9 @@ use Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Livewire\Livewire;
|
||||
use Str;
|
||||
use Livewire\Attributes\On;
|
||||
use App\Services\SmbService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateSerialValidation extends CreateRecord
|
||||
{
|
||||
@@ -61,10 +64,13 @@ class CreateSerialValidation extends CreateRecord
|
||||
return $this->getResource()::getUrl('create');
|
||||
}
|
||||
|
||||
|
||||
public function processInvoice($invoiceNumber)
|
||||
{
|
||||
$invoiceNumber = trim($invoiceNumber);
|
||||
|
||||
$fileName = $invoiceNumber . '.txt';
|
||||
|
||||
$this->showCapacitorInput = false;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
@@ -88,6 +94,187 @@ class CreateSerialValidation extends CreateRecord
|
||||
|
||||
//..GET SERIAL INVOICE API
|
||||
|
||||
$content = SmbService::readTextFile($fileName);
|
||||
|
||||
if ($content == '') {
|
||||
Notification::make()
|
||||
->title('File Not Found')
|
||||
->body("Unable to locate file: {$fileName}")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$lines = preg_split("/\r\n|\n|\r/", trim($content));
|
||||
|
||||
$insertData = [];
|
||||
$missingItemCodes = [];
|
||||
$InvalidLenSno = [];
|
||||
$InvalidSno = [];
|
||||
$InvalidLenItem = [];
|
||||
$InvalidItem = [];
|
||||
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
$line = trim($line);
|
||||
if ($line == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$parts = array_map('trim', explode(',', $line));
|
||||
|
||||
if (count($parts) != 2) {
|
||||
Notification::make()
|
||||
->title("Invalid data found inside the file.")
|
||||
->danger()
|
||||
->seconds(1)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
[$itemCode, $serialNumber] = $parts;
|
||||
|
||||
$sticker = StickerMaster::where('plant_id', $plantId)
|
||||
->whereHas('item', function ($query) use ($itemCode, $plantId) {
|
||||
$query->where('plant_id', $plantId)
|
||||
->where('code', $itemCode);
|
||||
})
|
||||
->first();
|
||||
|
||||
if (Str::length($itemCode) < 6)
|
||||
{
|
||||
$InvalidLenItem [] = $itemCode;
|
||||
continue;
|
||||
}
|
||||
else if(!is_numeric($itemCode)){
|
||||
$InvalidItem [] = $itemCode;
|
||||
continue;
|
||||
}
|
||||
if (Str::length($serialNumber) < 9)
|
||||
{
|
||||
$InvalidLenSno [] = $serialNumber;
|
||||
continue;
|
||||
}
|
||||
else if(!ctype_alnum($serialNumber)){
|
||||
$InvalidSno [] = $serialNumber;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$sticker) {
|
||||
$missingItemCodes[] = $itemCode;
|
||||
continue;
|
||||
}
|
||||
|
||||
$insertData[] = [
|
||||
'plant_id' => $plantId,
|
||||
'sticker_master_id' => $sticker->id,
|
||||
'invoice_number' => $invoiceNumber,
|
||||
'serial_number' => $serialNumber,
|
||||
'created_at' => now(),
|
||||
'operator_id' => $operatorName,
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($InvalidLenItem))
|
||||
{
|
||||
$count = count($InvalidLenItem);
|
||||
|
||||
if ($count <= 10) {
|
||||
$body = 'Item Code should contain minimum 6 digits: ' . implode(', ', $InvalidLenItem);
|
||||
} else {
|
||||
$body = "{$count} item codes contain minimum 6 digits.";
|
||||
}
|
||||
Notification::make()
|
||||
->title("Invalid Item Code.")
|
||||
->body("$body")
|
||||
->danger()
|
||||
->seconds(1)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (!empty($InvalidItem))
|
||||
{
|
||||
$count = count($InvalidItem);
|
||||
|
||||
if ($count <= 10) {
|
||||
$body = 'Item code must be in numeric values: ' . implode(', ', $InvalidSno);
|
||||
} else {
|
||||
$body = "{$count} item codes must be in numeric values.";
|
||||
}
|
||||
Notification::make()
|
||||
->title("Invalid Item Code.")
|
||||
->body("$body")
|
||||
->danger()
|
||||
->seconds(1)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (!empty($InvalidLenSno))
|
||||
{
|
||||
$count = count($InvalidLenSno);
|
||||
|
||||
if ($count <= 10) {
|
||||
$body = 'Serial number should be minimum 9 digits: ' . implode(', ', $InvalidLenSno);
|
||||
} else {
|
||||
$body = "{$count} serial number should be minimum 9 digits.";
|
||||
}
|
||||
Notification::make()
|
||||
->title("Invalid Serial Number.")
|
||||
->body("$body")
|
||||
->danger()
|
||||
->seconds(1)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (!empty($InvalidSno))
|
||||
{
|
||||
$count = count($InvalidSno);
|
||||
|
||||
if ($count <= 10) {
|
||||
$body = 'Serial number should be conatin alpha numeric values: ' . implode(', ', $InvalidSno);
|
||||
} else {
|
||||
$body = "{$count} serial number should be conatin alpha numeric values.";
|
||||
}
|
||||
Notification::make()
|
||||
->title("Invalid Serial Number.")
|
||||
->body("$body")
|
||||
->danger()
|
||||
->seconds(1)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (!empty($missingItemCodes))
|
||||
{
|
||||
$count = count($missingItemCodes);
|
||||
|
||||
if ($count <= 10) {
|
||||
$body = 'Item codes not found in sticker master: ' . implode(', ', $missingItemCodes);
|
||||
} else {
|
||||
$body = "{$count} item codes not found in sticker master table.";
|
||||
}
|
||||
Notification::make()
|
||||
->title("Unknown Item Code.")
|
||||
->body("$body")
|
||||
->danger()
|
||||
->seconds(1)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($insertData)) {
|
||||
SerialValidation::insert($insertData);
|
||||
}
|
||||
else{
|
||||
Notification::make()
|
||||
->title("Insert Failed.")
|
||||
->body("Data insertion failed")
|
||||
->danger()
|
||||
->seconds(1)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
//..
|
||||
|
||||
@@ -2311,8 +2498,9 @@ class CreateSerialValidation extends CreateRecord
|
||||
}
|
||||
}
|
||||
|
||||
public function processSerialNumber($serNo)
|
||||
public function processSer($serNo)
|
||||
{
|
||||
|
||||
$serNo = trim($serNo);
|
||||
$user = Filament::auth()->user();
|
||||
$operatorName = $user->name;
|
||||
@@ -2795,24 +2983,28 @@ class CreateSerialValidation extends CreateRecord
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dispatch('openCapacitorModal', itemCode: $itemCode, serialNumber: $serialNumber, plantId: $plantId);
|
||||
// $this->dispatch('openCapacitorModal', itemCode: $itemCode, serialNumber: $serialNumber, plantId: $plantId);
|
||||
//$this->dispatch('focusCapacitor', invoiceNumber: $invoiceNumber, plantId: $plantId);
|
||||
|
||||
$scannedQuantity = SerialValidation::where('invoice_number', $invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count();
|
||||
$this->dispatch('focusCapacitor', itemCode: $itemCode);
|
||||
|
||||
$totQuan = SerialValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count();
|
||||
$scanSQuan = SerialValidation::where('invoice_number', $invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count();
|
||||
$totMQuan = SerialValidation::where('invoice_number', $invoiceNumber)->whereNotNull('quantity')->where('plant_id', $plantId)->count(); //->where('quantity', '!=', '')
|
||||
$scanMQuan = SerialValidation::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'=> $scannedQuantity,
|
||||
]);
|
||||
$this->dispatch( 'refreshInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId);
|
||||
//$scannedQuantity = SerialValidation::where('invoice_number', $invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count();
|
||||
|
||||
// $totQuan = SerialValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count();
|
||||
// $scanSQuan = SerialValidation::where('invoice_number', $invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count();
|
||||
// $totMQuan = SerialValidation::where('invoice_number', $invoiceNumber)->whereNotNull('quantity')->where('plant_id', $plantId)->count(); //->where('quantity', '!=', '')
|
||||
// $scanMQuan = SerialValidation::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' => $serNo,
|
||||
// 'total_quantity' => $totQuan,
|
||||
// 'update_invoice' => false,
|
||||
// 'scanned_quantity'=> $scanSQuan,
|
||||
// ]);
|
||||
// $this->dispatch( 'refreshInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId);
|
||||
return;
|
||||
}
|
||||
else if ($isMarkPs)
|
||||
@@ -2958,6 +3150,173 @@ class CreateSerialValidation extends CreateRecord
|
||||
}
|
||||
}
|
||||
|
||||
#[On('process-scan')]
|
||||
public function processSerial($serial)
|
||||
{
|
||||
$this->processSer($serial);
|
||||
}
|
||||
|
||||
public function processCapacitor($serial, $itemCode)
|
||||
{
|
||||
$user = Filament::auth()->user();
|
||||
$operatorName = $user->name;
|
||||
|
||||
$this->currentItemCode = $itemCode;
|
||||
|
||||
if (!$serial) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preg_match('/^[^\/]+\/[^\/]+\/.+$/', $serial)) {
|
||||
Notification::make()
|
||||
->title('Invalid Panel Box QR Format:')
|
||||
->body('Scan the valid panel box QR code to proceed!')
|
||||
->danger()
|
||||
// ->duration(3000)
|
||||
->seconds(2)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$parts = explode('/', $serial);
|
||||
|
||||
$supplier = $parts[0];
|
||||
$itemCode = $parts[1];
|
||||
$serialNumber = implode('/', array_slice($parts, 2)); // Keep rest of the string
|
||||
|
||||
$existsInStickerMaster = StickerMaster::where('panel_box_code', $itemCode)->where('plant_id', $this->plantId)->whereHas('item', function ($query) {
|
||||
$query->where('code', $this->currentItemCode);
|
||||
})
|
||||
->exists();
|
||||
|
||||
if (!$existsInStickerMaster) {
|
||||
Notification::make()
|
||||
->title('Unknown: Panel Box Code')
|
||||
->body("Unknown panel box code: $itemCode found for item code: $this->currentItemCode")
|
||||
->danger()
|
||||
// ->duration(4000)
|
||||
->seconds(2)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->invoiceData as &$row) {
|
||||
if (
|
||||
($row['code'] ?? '') === $this->currentItemCode &&
|
||||
($row['serial_number'] ?? '') === $this->currentSerialNumber
|
||||
) {
|
||||
$row['panel_box_supplier'] = $supplier;
|
||||
$row['panel_box_item_code'] = $itemCode;
|
||||
$row['panel_box_serial_number'] = $serialNumber;
|
||||
$row['capacitor_scanned_status'] = 1;
|
||||
// $row['scanned_status_set'] = true;
|
||||
|
||||
$matchingValidation = SerialValidation::with('stickerMaster.item')
|
||||
->where('serial_number', $this->currentSerialNumber)
|
||||
->where('plant_id', $this->plantId)
|
||||
->get()
|
||||
->first(function ($validation) {
|
||||
return $validation->stickerMaster?->item?->code === $this->currentItemCode;
|
||||
});
|
||||
|
||||
if ($matchingValidation) {
|
||||
$hasMotorQr = $matchingValidation->stickerMasterRelation->tube_sticker_motor ?? null;
|
||||
$hasPumpQr = $matchingValidation->stickerMasterRelation->tube_sticker_pump ?? null;
|
||||
$hasPumpSetQr = $matchingValidation->stickerMasterRelation->tube_sticker_pumpset ?? null;
|
||||
// $hasCapacitorQr = $matchingValidation->stickerMasterRelation->panel_box_code ?? null;
|
||||
|
||||
$hadMotorQr = $matchingValidation->motor_scanned_status ?? null;
|
||||
$hadPumpQr = $matchingValidation->pump_scanned_status ?? null;
|
||||
$hadPumpSetQr = $matchingValidation->scanned_status_set ?? null;
|
||||
// $hadCapacitorQr = $matchingValidation->capacitor_scanned_status ?? null;
|
||||
|
||||
$packCnt = 1;
|
||||
$scanCnt = 1;
|
||||
// if($hadMotorQr === $hasMotorQr && $hadPumpQr === $hasPumpQr && $hadPumpSetQr === $hasPumpSetQr)
|
||||
if($hasMotorQr || $hasPumpQr || $hasPumpSetQr)
|
||||
{
|
||||
$packCnt = $hasMotorQr ? $packCnt + 1 : $packCnt;
|
||||
$packCnt = $hasPumpQr ? $packCnt + 1 : $packCnt;
|
||||
$packCnt = $hasPumpSetQr ? $packCnt + 1 : $packCnt;
|
||||
|
||||
$scanCnt = $hadMotorQr ? $scanCnt + 1: $scanCnt;
|
||||
$scanCnt = $hadPumpQr ? $scanCnt + 1: $scanCnt;
|
||||
$scanCnt = $hadPumpSetQr ? $scanCnt + 1: $scanCnt;
|
||||
|
||||
if($packCnt === $scanCnt)
|
||||
{
|
||||
$matchingValidation->update([
|
||||
'panel_box_supplier' => $supplier,
|
||||
'panel_box_item_code' => $itemCode,
|
||||
'panel_box_serial_number' => $serialNumber,
|
||||
'capacitor_scanned_status' => 1,
|
||||
'scanned_status' => 'Scanned',
|
||||
'operator_id'=> $operatorName,
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$matchingValidation->update([
|
||||
'panel_box_supplier' => $supplier,
|
||||
'panel_box_item_code' => $itemCode,
|
||||
'panel_box_serial_number' => $serialNumber,
|
||||
'capacitor_scanned_status' => 1,
|
||||
'operator_id'=> $operatorName,
|
||||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$matchingValidation->update([
|
||||
'panel_box_supplier' => $supplier,
|
||||
'panel_box_item_code' => $itemCode,
|
||||
'panel_box_serial_number' => $serialNumber,
|
||||
'capacitor_scanned_status' => 1,
|
||||
'scanned_status' => 'Scanned',
|
||||
'operator_id'=> $operatorName,
|
||||
]);
|
||||
}
|
||||
|
||||
// Notification::make()
|
||||
// ->title('Success: Capacitor QR')
|
||||
// // ->title("Panel box code scanned: $itemCode")
|
||||
// ->body("'Capacitor' QR scanned status updated, Scan next QR.")
|
||||
// ->success() // commented
|
||||
// ->seconds(2)
|
||||
// ->send();
|
||||
|
||||
$totalQuantity = SerialValidation::where('invoice_number', $matchingValidation->invoice_number)->where('plant_id', $this->plantId)->count();
|
||||
$scannedQuantity = SerialValidation::where('invoice_number', $matchingValidation->invoice_number)->where('plant_id', $this->plantId)->where('scanned_status', 'Scanned')->count();
|
||||
// $this->form->fill([
|
||||
// 'plant_id' => $matchingValidation->plant_id,
|
||||
// 'invoice_number' => $matchingValidation->invoice_number,
|
||||
// 'serial_number' => null,
|
||||
// 'total_quantity' => $totalQuantity,
|
||||
// 'scanned_quantity'=> $scannedQuantity,
|
||||
// ]);
|
||||
|
||||
if($totalQuantity === $scannedQuantity)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Completed: Serial Invoice')
|
||||
->body("Serial invoice '$matchingValidation->invoice_number' completed the scanning process.<br>Scan the next 'Serial Invoice' to proceed!")
|
||||
->success()
|
||||
->seconds(2)
|
||||
->send();
|
||||
$this->loadCompletedData($matchingValidation->invoice_number, $matchingValidation->plant_id, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->loadData($matchingValidation->invoice_number, $matchingValidation->plant_id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->showCapacitorInput = false;
|
||||
$this->dispatch('focus-serial-number');
|
||||
}
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Scan Serial Validation';
|
||||
|
||||
Reference in New Issue
Block a user