1 Commits

Author SHA1 Message Date
dc1f03ff35 Update dependency tpetry/laravel-postgresql-enhanced to v3
Some checks failed
renovate/artifacts Artifact file update failure
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / review (pull_request) Successful in 29s
Laravel Pint / pint (pull_request) Failing after 1m48s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Laravel Larastan / larastan (pull_request) Failing after 2m12s
2025-12-14 00:00:58 +00:00
7 changed files with 128 additions and 377 deletions

View File

@@ -13,49 +13,30 @@ class CharacteristicValueExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('line.name')
->label('LINE NAME'),
ExportColumn::make('item.code')
->label('ITEM CODE'),
ExportColumn::make('machine.name')
->label('WORK CENTER'),
ExportColumn::make('process_order')
->label('PROCESS ORDER'),
ExportColumn::make('coil_number')
->label('COIL NUMBER'),
ExportColumn::make('status')
->label('STATUS'),
ExportColumn::make('created_at')
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
ExportColumn::make('updated_by')
->label('UPDATED BY'),
ExportColumn::make('deleted_at')
->enabledByDefault(false)
->label('DELETED AT'),
ExportColumn::make('id')
->label('ID'),
ExportColumn::make('plant.name'),
ExportColumn::make('line.name'),
ExportColumn::make('item.id'),
ExportColumn::make('machine.name'),
ExportColumn::make('process_order'),
ExportColumn::make('coil_number'),
ExportColumn::make('status'),
ExportColumn::make('created_at'),
ExportColumn::make('updated_at'),
ExportColumn::make('created_by'),
ExportColumn::make('updated_by'),
ExportColumn::make('deleted_at'),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your characteristic value export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
$body = 'Your characteristic value export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
}
return $body;

View File

@@ -3,16 +3,9 @@
namespace App\Filament\Imports;
use App\Models\CharacteristicValue;
use App\Models\Item;
use App\Models\Line;
use App\Models\Machine;
use App\Models\Plant;
use App\Models\ProcessOrder;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Str;
class CharacteristicValueImporter extends Importer
{
@@ -23,52 +16,25 @@ class CharacteristicValueImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->relationship()
->rules(['required']),
ImportColumn::make('line')
->requiredMapping()
->exampleHeader('Line Name')
->example('4 inch pump line')
->label('Line Name')
->relationship(resolveUsing: 'name')
->relationship()
->rules(['required']),
ImportColumn::make('item')
->requiredMapping()
->exampleHeader('Item Code')
->example('123456')
->label('Item Code')
->relationship(resolveUsing: 'code')
->relationship()
->rules(['required']),
ImportColumn::make('machine')
->requiredMapping()
->exampleHeader('Work Center')
->example('RMGS09745')
->label('Work Center')
->relationship(resolveUsing: 'work_center')
->relationship()
->rules(['required']),
ImportColumn::make('process_order')
->requiredMapping()
->exampleHeader('Process Order')
->example('23455256352')
->label('Process Order'),
ImportColumn::make('coil_number')
->requiredMapping()
->exampleHeader('Coil Number')
->example('0')
->label('Coil Number'),
ImportColumn::make('status')
->requiredMapping()
->exampleHeader('Status')
->example('Ok')
->label('Status'),
ImportColumn::make('created_by')
->requiredMapping()
->exampleHeader('Created By')
->example('RAW01234')
->label('Created By'),
ImportColumn::make('process_order'),
ImportColumn::make('coil_number'),
ImportColumn::make('status'),
ImportColumn::make('created_by'),
ImportColumn::make('updated_by'),
];
}
@@ -79,180 +45,15 @@ class CharacteristicValueImporter extends Importer
// 'email' => $this->data['email'],
// ]);
$warnMsg = [];
$plantId = null;
$itemId = null;
$LineId = null;
$machineId = null;
$itemAgainstPlant = null;
$plantCode = $this->data['plant'];
$processOrder = trim($this->data['process_order'] ?? '');
$iCode = trim($this->data['item']);
$workCenter = trim($this->data['machine']);
$lineName = trim($this->data['line']);
$status = trim($this->data['status']);
$createdBy = trim($this->data['created_by']);
$coilNo = trim($this->data['coil_number']);
if ($plantCode == null || $plantCode == '') {
$warnMsg[] = 'Plant code cannot be empty';
} elseif ($iCode == null || $iCode == '') {
$warnMsg[] = 'Process Order cannot be empty';
} elseif ($workCenter == null || $workCenter == '') {
$warnMsg[] = 'Work center cannot be empty';
} elseif ($lineName == null || $lineName == '') {
$warnMsg[] = 'Line cannot be empty';
}
if (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCode)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$plantId = $plant->id;
}
}
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
$warnMsg[] = 'Invalid item code found';
} else {
$itemCode = Item::where('code', $iCode)->first();
if (! $itemCode) {
$warnMsg[] = 'Item code not found';
} else {
if ($plantId) {
$itemAgainstPlant = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
if (! $itemAgainstPlant) {
$warnMsg[] = 'Item code not found for the given plant';
} else {
$itemId = $itemAgainstPlant->id;
}
}
}
}
$lineExists = Line::where('name', $lineName)->first();
if (! $lineExists) {
$warnMsg[] = 'Line name not found';
} else {
if ($plantId) {
$lineAgainstPlant = Line::where('name', $lineName)->where('plant_id', $plantId)->first();
if (! $lineAgainstPlant) {
$warnMsg[] = 'Line name not found for the given plant';
} else {
$LineId = $lineAgainstPlant->id;
}
}
}
$workCenterExist = Machine::where('work_center', $workCenter)->first();
if (! $workCenterExist) {
$warnMsg[] = 'Work Center not found';
}
// $workCenterAgainstPlant = Machine::where('work_center', $workCenter)
// ->where('plant_id', $plantId)
// ->first();
// if (!$workCenterAgainstPlant) {
// $warnMsg[] = 'Work center not found for the given plant';
// } else {
// $MachineId = $workCenterAgainstPlant->id;
// }
if ($plantId != null && $LineId != null) {
$machineAgaPlantLine = Machine::where('plant_id', $plantId)
->where('line_id', $LineId)
->where('work_center', $workCenter)
->first();
if (! $machineAgaPlantLine) {
$warnMsg[] = 'Work center not found for the given plant and line';
} else {
$machineId = $machineAgaPlantLine->id;
}
}
if ($processOrder == null || $processOrder == '') {
$warnMsg[] = 'Process Order cannot be empty';
}
if ($coilNo == null || $coilNo == '') {
$warnMsg[] = 'Coil No cannot be empty';
} elseif (! is_numeric($coilNo)) {
$warnMsg[] = 'Coil number should contain only numeric values!';
}
if ($status == null || $status == '' || ! $status) {
$warnMsg[] = 'Status cannot be empty';
} elseif (! in_array($status, ['Ok', 'NotOk'], true)) {
$warnMsg[] = "Status must be either 'Ok' or 'NotOk'!";
}
if ($createdBy == null || $createdBy == '' || ! $createdBy) {
$warnMsg[] = 'Created By cannot be empty';
}
// $existing = CharacteristicValue::where('plant_id', $plantId)
// ->where('process_order', $processOrder)
// ->where('coil_number', $coilNo)
// ->first();
// if ($existing) {
// $warnMsg[] = "Process order '{$processOrder}' with coil number '{$coilNo}' already exist for the plant code '{$plantCode}'!";
// }
if ($plantId && $processOrder) {
$existing = CharacteristicValue::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('coil_number', $coilNo)
->first();
if ($existing) {
$warnMsg[] = "Coil number '{$coilNo}' already exists for Plant '{$plantCode}' and Process Order '{$processOrder}'.";
}
}
if ($plant && $itemCode && $processOrder != '') {
$existingOrder = ProcessOrder::where('plant_id', $plant->id)
->where('process_order', $processOrder)
->first();
if ($existingOrder && $existingOrder->item_id !== ($itemCode->id ?? null)) {
$warnMsg[] = 'Same Process Order already exists for this Plant with a different Item Code';
}
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return CharacteristicValue::create([
'plant_id' => $plantId,
'item_id' => $itemId,
'line_id' => $LineId,
'machine_id' => $machineId,
'process_order' => trim($this->data['process_order']),
'coil_number' => trim($this->data['coil_number']),
'status' => trim($this->data['status']),
'created_by' => trim($this->data['created_by']),
]);
// return null;
// return new CharacteristicValue;
return new CharacteristicValue();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your characteristic value import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
$body = 'Your characteristic value import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
}
return $body;

View File

@@ -1155,27 +1155,12 @@ class StickerReprint extends Page implements HasForms
// Only search when all parent IDs are selected
$parts = explode('|', $formQRData);
$itemCode = trim($parts[0]);
$serialNumberRaw = isset($parts[1]) ? trim($parts[1]) : null;
// // Remove slash and everything after it
// if ($serialNumberRaw != null) {
// $serialNumber = preg_replace('/\/.*/', '', $serialNumberRaw);
// $serialNumber = trim($serialNumber);
// } else {
// $serialNumber = null;
// }
// Remove slash and everything after it
if ($serialNumberRaw != null) {
if (strpos($serialNumberRaw, '/') !== false) {
$serialNumber = strstr($serialNumberRaw, '/', true); // gets text before slash
} else {
$serialNumber = $serialNumberRaw; // keep original
}
$serialNumber = preg_replace('/\/.*/', '', $serialNumberRaw);
$serialNumber = trim($serialNumber);
} else {
$serialNumber = null;
}
@@ -1398,33 +1383,6 @@ class StickerReprint extends Page implements HasForms
$itemCode = trim($parts[0]);
$this->sNoId = isset($parts[1]) ? trim($parts[1]) : null;
$originalQR = $this->qrData;
if (strpos($originalQR, '/') != false)
{
// Allowed endings
$allowed = ['/m', '/M', '/p', '/P'];
$foundValidEnding = false;
foreach ($allowed as $end) {
if (str_ends_with($originalQR, $end)) {
$foundValidEnding = true;
break;
}
}
if (!$foundValidEnding) {
Notification::make()
->title('Invalid QR Code')
->body("Invalid QR format: '$originalQR'")
->danger()
->send();
return;
}
}
if ($this->sNoId != null) {
$this->sNoId = preg_replace('/\/.*/', '', $serialNumberRaw);
$this->sNoId = trim($this->sNoId);
@@ -1432,7 +1390,7 @@ class StickerReprint extends Page implements HasForms
$this->sNoId = null;
}
//$this->qrData = preg_replace('/\/.*/', '', $this->qrData);
$this->qrData = preg_replace('/\/.*/', '', $this->qrData);
ProductionQuantity::create([
'plant_id'=> $this->pId,
@@ -1448,6 +1406,7 @@ class StickerReprint extends Page implements HasForms
// after success insertion
$this->form->fill([
'plant_id'=> $this->pId,
'block_name'=> $this->bId,
'shift_id'=> $this->sId,
@@ -1470,7 +1429,7 @@ class StickerReprint extends Page implements HasForms
->duration(1000)
->send();
$url = route('download-qr1-pdf', ['palletNo' => urlencode($originalQR)]);
$url = route('download-qr1-pdf', ['palletNo' => $this->qrData]);
$this->js(<<<JS
window.dispatchEvent(new CustomEvent('open-pdf', {
detail: {

View File

@@ -53,7 +53,6 @@ class CreateInvoiceValidation extends CreateRecord
public bool $showCapacitorInput = false;
public $excel_file;
public $mInvoiceNo;
public function getFormActions(): array
{
@@ -104,8 +103,6 @@ class CreateInvoiceValidation extends CreateRecord
{
$invoiceNumber = trim($invoiceNumber);
$parts = explode('.', $invoiceNumber);
$this->showCapacitorInput = false;
$user = Filament::auth()->user();
@@ -121,62 +118,6 @@ class CreateInvoiceValidation extends CreateRecord
// ..GET SERIAL INVOICE API
if(strlen($invoiceNumber) > 15)
{
$payloadJson = base64_decode(strtr($parts[1], '-_', '+/'));
if (empty($payloadJson)) {
Notification::make()
->title('Invalid payload for scanned qr code.')
->danger()
->seconds(1)
->send();
return;
}
$payload = json_decode($payloadJson, true);
if (!isset($payload['data'])) {
Notification::make()
->title('Invalid payload for scanned qr code.')
->info()
->seconds(1)
->send();
return;
}
$documentData = $payload['data'];
if($documentData == '' || $documentData == ''){
Notification::make()
->title('Invalid payload for scanned qr code.')
->info()
->seconds(1)
->send();
return;
}
// Extract DocNo
preg_match('/"DocNo"\s*:\s*"([^"]+)"/', $documentData, $matches);
if (!isset($matches[1])) {
Notification::make()
->title('Invoice number not found.')
->info()
->seconds(1)
->send();
return;
}
if (isset($matches[1])) {
$invoiceNumber = $matches[1];
}
}
//dd($invoiceNumber);
// ..
$updateStatus = $this->form->getState()['update_invoice'] ?? null;
@@ -2801,6 +2742,19 @@ class CreateInvoiceValidation extends CreateRecord
->send();
$this->dispatch('playWarnSound');
// $mailData = $this->getMail();
// $mPlantName = $mailData['plant_name'];
// $emails = $mailData['emails'];
// $mInvoiceType = 'Material';
// if (! empty($emails)) {
// Mail::to($emails)->send(
// new InvalidSerialMail($mSerNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, 'ItemNotValidMaterialType')
// );
// } else {
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
// }
$this->form->fill([
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
@@ -2830,6 +2784,19 @@ class CreateInvoiceValidation extends CreateRecord
->send();
$this->dispatch('playWarnSound');
// $mailData = $this->getMail();
// $mPlantName = $mailData['plant_name'];
// $emails = $mailData['emails'];
// $mInvoiceType = 'Material';
// if (! empty($emails)) {
// Mail::to($emails)->send(
// new InvalidSerialMail($mSerNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, 'ItemNotInvoice')
// );
// } else {
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
// }
$this->form->fill([
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
@@ -2858,6 +2825,19 @@ class CreateInvoiceValidation extends CreateRecord
->send();
$this->dispatch('playWarnSound');
// $mailData = $this->getMail();
// $mPlantName = $mailData['plant_name'];
// $emails = $mailData['emails'];
// $mInvoiceType = 'Material';
// if (! empty($emails)) {
// Mail::to($emails)->send(
// new InvalidSerialMail($mSerNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, 'Item')
// );
// } else {
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
// }
$this->form->fill([
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
@@ -3401,6 +3381,19 @@ class CreateInvoiceValidation extends CreateRecord
->send();
$this->dispatch('playNotificationSound');
// $mInvoiceType = 'Serial';
// $mailData = $this->getMail();
// $mPlantName = $mailData['plant_name'];
// $emails = $mailData['emails'];
// if (! empty($emails)) {
// Mail::to($emails)->send(
// new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, 'CompletedSerialInvoice')
// );
// } else {
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
// }
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$disk = Storage::disk('local');
@@ -3518,6 +3511,20 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playNotificationSound');
// $mInvoiceType = 'Serial';
// $mailData = $this->getMail();
// $mPlantName = $mailData['plant_name'];
// $emails = $mailData['emails'];
// if (! empty($emails)) {
// // Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType));
// Mail::to($emails)->send(
// new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, 'CSerialInvoice')
// );
// } else {
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
// }
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$disk = Storage::disk('local');
@@ -3577,6 +3584,22 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playWarnSound');
// $mInvoiceType = 'Serial';
// $mailData = $this->getMail();
// $mPlantName = $mailData['plant_name'];
// $emails = $mailData['emails'];
// $mUserName = Filament::auth()->user()->name;
// if (! empty($emails)) {
// // Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType));
// Mail::to($emails)->send(
// new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, $mUserName, 'DuplicateCapacitorQR')
// );
// } else {
// \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");
// }
$this->form->fill([
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,

View File

@@ -22,8 +22,6 @@ class ProductionStickerReprintController extends Controller
public function downloadQrPdf($palletNo)
{
$palletNo = urldecode($palletNo);
$parts = explode('|', $palletNo);
$itemCode = trim($parts[0]);
$serialNumberRaw = isset($parts[1]) ? trim($parts[1]) : null;
@@ -52,30 +50,14 @@ class ProductionStickerReprintController extends Controller
$productionOrder = $production->production_order ?? '';
if(!preg_match('/\//', $palletNo)){
if ($item->category == 'Submersible Motor')
{
$copies = 1;
}
elseif ($item->category == 'Submersible Pump')
{
$copies = 2;
}
}
else
if ($item->category == 'Submersible Motor')
{
if ($item->category == 'Submersible Motor')
{
$copies = 1;
}
elseif ($item->category == 'Submersible Pump')
{
$copies = 1;
}
$copies = 1;
}
elseif ($item->category == 'Submersible Pump')
{
$copies = 2;
}
$palletNo = preg_replace('/\/.*/', '', $palletNo);
// 5. Generate QR Code (base64)
$qrCode = new QrCode($palletNo);
$output = new Output\Png();

View File

@@ -29,7 +29,7 @@
"smalot/pdfparser": "^2.12",
"tecnickcom/tcpdf": "^6.10",
"thiagoalessio/tesseract_ocr": "^2.13",
"tpetry/laravel-postgresql-enhanced": "^2.3"
"tpetry/laravel-postgresql-enhanced": "^3.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.15",

View File

@@ -9,9 +9,14 @@ Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
Artisan::command('auto:scheduler', function () {
$this->call('custom:scheduler');
})->everyMinute()->withoutOverlapping();
})->everyMinute();
// Schedule::command('send:invoice-report');
// Schedule::command('send:production-report');
// app()->booted(function () {
// $schedule = app(Schedule::class);