diff --git a/app/Console/Commands/SendInvoiceTransitReport.php b/app/Console/Commands/SendInvoiceTransitReport.php index c036c4b..3457036 100644 --- a/app/Console/Commands/SendInvoiceTransitReport.php +++ b/app/Console/Commands/SendInvoiceTransitReport.php @@ -48,12 +48,12 @@ class SendInvoiceTransitReport extends Command if ($plants->isEmpty()) { $this->error('No valid plant(s) found.'); + return; } - if (strtolower($scheduleType) == 'daily') - { - $results = DB::table('invoice_in_transits as it') + if (strtolower($scheduleType) == 'daily') { + $results = DB::table('invoice_in_transits as it') ->join('invoice_masters as im', function ($join) { $join->on('im.receiving_plant_name', '=', 'it.receiving_plant_name')->on('im.transport_name', '=', 'it.transport_name'); }) @@ -84,17 +84,18 @@ class SendInvoiceTransitReport extends Command ') ) - ->when($plantId != 0, fn($q) => $q->where('it.plant_id', $plantId)) + ->when($plantId != 0, fn ($q) => $q->where('it.plant_id', $plantId)) ->whereNotNull('it.lr_bl_aw_date') ->whereRaw(' (CURRENT_DATE - CAST(it.lr_bl_aw_date AS DATE)) - CAST(im.transit_days AS INTEGER) > 0 ') + ->distinct('it.invoice_number') ->get(); - if ($results->isEmpty()) { $this->info('No invoice transit records found for today.'); + return; } @@ -103,24 +104,25 @@ class SendInvoiceTransitReport extends Command foreach ($mailRules as $rule) { $ruleInvoices = $results->where('invoice_master_id', $rule->invoice_master_id); - //$ruleInvoices = $results->filter(fn($item) => $item->invoice_master_id == (int)$rule->invoice_master_id); - + // $ruleInvoices = $results->filter(fn($item) => $item->invoice_master_id == (int)$rule->invoice_master_id); if ($ruleInvoices->isEmpty()) { $this->info("Skipping rule {$rule->id} — no invoice transit data."); - continue; // ❌ DO NOT SEND MAIL + + continue; } $invoiceMaster = InvoiceMaster::find($rule->invoice_master_id); $mailSubject = $invoiceMaster ? "Despatch Invoice In Transit ({$invoiceMaster->receiving_plant_name} - {$invoiceMaster->transport_name})" - : "Despatch Invoice In Transit"; + : 'Despatch Invoice In Transit'; if ($ruleInvoices->isEmpty()) { $tableData = []; $this->info("No despatch invoices in transit found for rule {$rule->id}."); } else { + $tableData = $ruleInvoices->values()->map(function ($item, $index) use ($plantCodes) { return [ 'no' => $index + 1, @@ -132,9 +134,10 @@ class SendInvoiceTransitReport extends Command 'lr_bl_aw_date' => $item->lr_bl_aw_date, 'lr_bl_aw_number' => $item->lr_bl_aw_number, 'transit_days' => $item->transit_days, - 'status' => $item->delayed_days . ' Days', + 'status' => $item->delayed_days.' Days', ]; })->toArray(); + } $mail = new InvoiceTransitMail($scheduleType, $tableData, $mailSubject); @@ -155,13 +158,14 @@ class SendInvoiceTransitReport extends Command if (empty($toEmails)) { $this->warn("Skipping rule {$rule->id} — no To emails."); + continue; } \Mail::to($toEmails)->cc($ccEmails)->send($mail); $this->info( - "Mail sent → Rule {$rule->id} | Invoice Master ID: {$rule->invoice_master_id} | To: " . implode(', ', $toEmails) + "Mail sent → Rule {$rule->id} | Invoice Master ID: {$rule->invoice_master_id} | To: ".implode(', ', $toEmails) ); } } diff --git a/app/Exports/MotorFreeRunExport.php b/app/Exports/MotorFreeRunExport.php new file mode 100644 index 0000000..f72d553 --- /dev/null +++ b/app/Exports/MotorFreeRunExport.php @@ -0,0 +1,231 @@ + $this->records, +// // ]); +// // } + +// public function collection() +// { +// return $this->records; +// } + +// public function headings(): array +// { +// // Top two rows (Company info + Motor KW/HP) +// return [ +// ['C.R.I. Pumps Private Limited', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Unit: MOTOR FREE RUN TEST REGISTER'], +// ['Motor KW/HP : - / -', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Phase : -'], +// // Column headers +// [ +// 'Date', 'Motor SNo', 'Item Code', 'Motor Type', +// 'Voltage', 'Current', 'Power', 'IR.Hot', 'IR.Cool', 'Frequency', 'Speed', 'Leakage Current', // AFTER FREE RUN +// 'Voltage', 'Current', 'Power', // LOCKED ROTOR TEST +// 'No Load Pickup Voltage', 'Room Temp.', 'High Voltage Test', 'Result', 'Remark' +// ] +// ]; +// } + +// public function registerEvents(): array +// { +// return [ +// AfterSheet::class => function (AfterSheet $event) { +// $sheet = $event->sheet->getDelegate(); + +// // Merge top rows for company info +// $sheet->mergeCells('A1:S1'); // Company Name +// $sheet->mergeCells('T1:T1'); // Unit/Register info +// $sheet->mergeCells('A2:S2'); // Motor KW/HP row +// $sheet->mergeCells('T2:T2'); // Phase + +// // Merge headers for grouped columns (AFTER FREE RUN & LOCKED ROTOR TEST) +// $sheet->mergeCells('E3:L3'); // AFTER FREE RUN +// $sheet->mergeCells('M3:O3'); // LOCKED ROTOR TEST + +// // Optional: style headers +// $sheet->getStyle('A1:T3')->getFont()->setBold(true); +// $sheet->getStyle('A1:T3')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); +// $sheet->getStyle('A1:T3')->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); + +// // Set column widths (optional for better visibility) +// $columns = range('A', 'T'); +// foreach ($columns as $col) { +// $sheet->getColumnDimension($col)->setAutoSize(true); +// } +// }, +// ]; +// } + + +// } + +// class MotorFreeRunExport implements FromCollection, WithMapping, WithStartRow +// { +// protected Collection $records; + +// public function __construct(Collection $records) +// { +// $this->records = $records; +// } + +// public function collection() +// { +// return $this->records; +// } + +// public function startRow(): int +// { +// return 3; // insert data starting from row 3 +// } + +// public function map($record): array +// { +// return [ +// $record['Date'] ?? '', +// $record['Output'] ?? '', +// $record['Motor SNo'] ?? '', +// $record['Item Code'] ?? '', +// $record['Motor Type'] ?? '', +// $record['kw'] ?? '', +// $record['hp'] ?? '', +// $record['phase'] ?? '', +// $record['isi_model'] ?? '', +// $record['Voltage_Before'] ?? '', +// $record['Current_Before'] ?? '', +// $record['Power_Before'] ?? '', +// $record['Resistance_RY'] ?? '', +// $record['Resistance_YB'] ?? '', +// $record['Resistance_BR'] ?? '', +// $record['Insulation_Resistance'] ?? '', +// $record['Frequency_Before'] ?? '', +// $record['Speed_Before'] ?? '', +// $record['Voltage_After'] ?? '', +// $record['Current_After'] ?? '', +// $record['Power_After'] ?? '', +// $record['IR_Hot'] ?? '', +// $record['IR_Cool'] ?? '', +// $record['Leakage_Current'] ?? '', +// $record['Frequency_After'] ?? '', +// $record['Speed_After'] ?? '', +// $record['Voltage_Locked'] ?? '', +// $record['Current_Locked'] ?? '', +// $record['Power_Locked'] ?? '', +// $record['No_Load_Pickup_Voltage'] ?? '', +// $record['Room_Temp'] ?? '', +// $record['High_Voltage_Test'] ?? '', +// $record['Batch_Number'] ?? '', +// $record['Batch_Count'] ?? '', +// $record['Result'] ?? '', +// $record['Remark'] ?? '', +// $record['Tested_By'] ?? '', +// ]; +// } +// } + + +class MotorFreeRunExport implements WithCustomStartCell, WithMapping, WithStartRow, WithChunkReading +{ + protected $records; + protected $templatePath; + + public function __construct($records) + { + $this->records = $records; + // dd($this->records); + } + + public function collection() + { + return $this->records; + } + + public function startRow(): int + { + return 7; // Start inserting data from row 7 + } + + public function startCell(): string + { + return 'A7'; // Start inserting data from row 7 column A + } + + public function map($record): array + { + return [ + $record['Date'] ?? '', + $record['Output'] ?? '', + $record['Motor SNo'] ?? '', + $record['Item Code'] ?? '', + $record['Motor Type'] ?? '', + $record['kw'] ?? '', + $record['hp'] ?? '', + $record['phase'] ?? '', + $record['isi_model'] ?? '', + $record['Voltage_Before'] ?? '', + $record['Current_Before'] ?? '', + $record['Power_Before'] ?? '', + $record['Resistance_RY'] ?? '', + $record['Resistance_YB'] ?? '', + $record['Resistance_BR'] ?? '', + $record['Insulation_Resistance'] ?? '', + $record['Frequency_Before'] ?? '', + $record['Speed_Before'] ?? '', + $record['Voltage_After'] ?? '', + $record['Current_After'] ?? '', + $record['Power_After'] ?? '', + $record['IR_Hot'] ?? '', + $record['IR_Cool'] ?? '', + $record['Leakage_Current'] ?? '', + $record['Frequency_After'] ?? '', + $record['Speed_After'] ?? '', + $record['Voltage_Locked'] ?? '', + $record['Current_Locked'] ?? '', + $record['Power_Locked'] ?? '', + $record['No_Load_Pickup_Voltage'] ?? '', + $record['Room_Temp'] ?? '', + $record['High_Voltage_Test'] ?? '', + $record['Batch_Number'] ?? '', + $record['Batch_Count'] ?? '', + $record['Result'] ?? '', + $record['Remark'] ?? '', + $record['Tested_By'] ?? '', + ]; + } + + public function chunkSize(): int + { + return 1000; // load 1000 records at a time + } +} diff --git a/app/Exports/TestingPanelReadingExport.php b/app/Exports/TestingPanelReadingExport.php new file mode 100644 index 0000000..1905771 --- /dev/null +++ b/app/Exports/TestingPanelReadingExport.php @@ -0,0 +1,159 @@ +ids = $ids; +// } +// public function query() +// { +// return TestingPanelReading::query() +// ->whereIn('id', $this->ids) +// ->select('id', 'plant_id', 'line_id', 'motor_testing_master_id', 'machine_id', 'output', 'serial_number', 'winded_serial_number', 'before_fr_volt', 'before_fr_cur', 'before_fr_pow', 'before_fr_res_ry', 'before_fr_res_yb', 'before_fr_res_br', 'before_fr_ir', 'before_fr_ir_r', 'before_fr_ir_y', 'before_fr_ir_b', 'before_fr_freq', 'before_fr_speed', 'after_fr_vol', 'after_fr_cur', 'after_fr_pow', 'after_fr_ir_hot','after_fr_ir_hot_r', 'after_fr_ir_hot_y', 'after_fr_ir_hot_b', 'after_fr_ir_cool', 'after_fr_ir_cool_r', 'after_fr_ir_cool_y', 'after_fr_ir_cool_b', 'after_fr_freq', 'after_fr_speed', 'after_fr_leak_cur', 'locked_rt_volt', 'locked_rt_cur', 'locked_rt_pow', 'no_load_pickup_volt', 'room_temperature', 'hv_test', 'batch_number', 'batch_count', 'result', 'remark', 'rework_count', 'update_count', 'output_flag', 'tested_by', 'updated_by', 'created_at', 'updated_at', 'scanned_at', 'created_at'); +// } + +// public function chunkSize(): int +// { +// return 1000; // process 1000 rows at a time +// } + +// public function headings(): array +// { +// return ['NO', 'PLANT', 'LINE', 'MOTORTESTINGMASTER', 'MACHINE', 'OUTPUT', 'SERIAL NUMBER', 'WINDED SERIAL NUMBER', 'BEFORE FR VOLT', 'BEFORE FR CUR', 'BEFORE FR POW', 'BEFORE FR RES RY', 'BEFORE FR RES YB', 'BEFORE FR RES BR', 'BEFORE FR IR', 'BEFORE FR IR R', 'BEFORE FR IR Y', 'BEFORE FR IR B', 'BEFORE FR FREQ', 'BEFORE FR SPEED', 'AFTER FR VOL', 'AFTER FR CUR', 'AFTER FR POW', 'AFTER FR IR HOT', 'AFTER FR IR HOT R', 'AFTER FR IR HOT Y', 'AFTER FR IR HOT B', 'AFTER FR IR COOL', 'AFTER FR IR COOL R', 'AFTER FR IR COOL Y', 'AFTER FR IR COOL B', 'AFTER FR FREQ', 'AFTER FR SPEED', 'AFTER FR LEAK CUR', 'LOCKED RT VOLT', 'LOCKED RT CUR', 'LOCKED RT POW', 'NO LOAD PICKUP VOLT', 'ROOM TEMPERATURE', 'HV TEST', 'BATCH NUMBER', 'BATCH COUNT', 'RESULT', 'REMARK', 'REWORK COUNT', 'UPDATE COUNT', 'OUTPUT FLAG', 'TETSED BY', 'UPDATED BY', 'CREATED AT', 'UPDATED AT', 'SCANNED AT', 'CREATED AT']; +// } + +// public function map($record): array +// { +// $this->counter++; +// return [ +// $this->counter, // No. +// $record->plant_id, +// $record->line_id, +// $record->motor_testing_master_id, +// $record->machine_id, +// $record->output, +// $record->serial_number, +// $record->winded_serial_number, +// $record->before_fr_volt, +// $record->before_fr_cur, +// $record->before_fr_pow, +// $record->before_fr_res_ry, +// $record->before_fr_res_yb, +// $record->before_fr_res_br, +// $record->before_fr_ir, +// $record->before_fr_ir_r, +// $record->before_fr_ir_y, +// $record->before_fr_ir_b, +// $record->before_fr_freq, +// $record->before_fr_speed, +// $record->after_fr_vol, +// $record->after_fr_cur, +// $record->after_fr_pow, +// $record->after_fr_ir_hot, +// $record->after_fr_ir_hot_r, +// $record->after_fr_ir_hot_y, +// $record->after_fr_ir_hot_b, +// $record->after_fr_ir_cool, +// $record->after_fr_ir_cool_r, +// $record->after_fr_ir_cool_y, +// $record->after_fr_ir_cool_b, +// $record->after_fr_freq, +// $record->after_fr_speed, +// $record->after_fr_leak_cur, +// $record->locked_rt_volt, +// $record->locked_rt_cur, +// $record->locked_rt_pow, +// $record->no_load_pickup_volt, +// $record->room_temperature, +// $record->hv_test, +// $record->batch_number, +// $record->batch_count, +// $record->result, +// $record->remark, +// $record->rework_count, +// $record->update_count, +// $record->output_flag, +// $record->tested_by, +// $record->updated_by, +// // $record->created_at, +// $record->updated_at, +// $record->scanned_at, +// $record->created_at, +// ]; +// } +// } + +class TestingPanelReadingExport implements FromCollection, WithHeadings +{ + protected $records; + protected $isAllStarDelta; + + public function __construct($records, $isAllStarDelta) + { + $this->records = $records; + $this->isAllStarDelta = $isAllStarDelta; + } + + public function collection() + { + return collect($this->records)->map(function ($record) { + if (!$this->isAllStarDelta) { + return [ + 'Date' => date('Y-m-d', strtotime($record['created_at'] ?? '')), + 'Output' => $record['output'] ?? '', + 'Motor SNo' => $record['serial_number'] ?? '', + 'Item Code' => $record->motorTestingMaster->item->code ?? '', + 'Motor Type' => $record->motorTestingMaster->item->description ?? '', + 'IR_Hot' => $record['after_fr_ir_hot'] ?? '', + 'IR_Cool' => $record['after_fr_ir_cool'] ?? '', + 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '', + ]; + } else { + return [ + 'Date' => date('Y-m-d', strtotime($record['created_at'] ?? '')), + 'Output' => $record['output'] ?? '', + 'Motor SNo' => $record['serial_number'] ?? '', + 'Item Code' => $record->motorTestingMaster->item->code ?? '', + 'Motor Type' => $record->motorTestingMaster->item->description ?? '', + 'IR_Hot_R' => $record['after_fr_ir_hot_r'] ?? '', + 'IR_Hot_Y' => $record['after_fr_ir_hot_y'] ?? '', + 'IR_Hot_B' => $record['after_fr_ir_hot_b'] ?? '', + 'IR_Cool_R' => $record['after_fr_ir_cool_r'] ?? '', + 'IR_Cool_Y' => $record['after_fr_ir_cool_y'] ?? '', + 'IR_Cool_B' => $record['after_fr_ir_cool_b'] ?? '', + 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '', + ]; + } + }); + } + + public function headings(): array + { + return array_keys($this->collection()->first() ?? []); + } +} diff --git a/app/Filament/Pages/InvoicePendingReason.php b/app/Filament/Pages/InvoicePendingReason.php index 9213f0e..36df31c 100644 --- a/app/Filament/Pages/InvoicePendingReason.php +++ b/app/Filament/Pages/InvoicePendingReason.php @@ -357,18 +357,6 @@ class InvoicePendingReason extends Page ]); return; } - // else if(!empty($import->remarkEmpty)) { - - // Notification::make() - // ->title('Import failed') - // ->body("Remark can't be empty") - // ->danger() - // ->send(); - // $this->filtersForm->fill([ - // 'file' => null, - // ]); - // return; - // } else if (! empty($import->duplicateExcelDocs)) { $duplicates = collect($import->duplicateExcelDocs) diff --git a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php index f0cd68b..e2c8887 100644 --- a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php +++ b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php @@ -2899,7 +2899,7 @@ class CreateInvoiceValidation extends CreateRecord if ($dupRecord) { Notification::make() ->title('Duplicate: Material QR') - ->body("Scanned 'Material QR' already completed the scanning process.") + ->body("Scanned Material QR : '{$serialNumber}' already completed the scanning process..!") ->danger() ->seconds(2) ->send(); @@ -2998,19 +2998,19 @@ class CreateInvoiceValidation extends CreateRecord } } else { if (str_contains($serialNumber, '|')) { + Notification::make() + ->title('Duplicate: Material QR') + ->body("Scanned Material QR : '{$serialNumber}' already completed the scanning process..!") + ->danger() + ->seconds(2) + ->send(); + $itemCode = null; $this->currentItemCode = ''; $batchNumber = null; $serNo = null; $serialNumber = null; - Notification::make() - ->title('Duplicate: Material QR') - ->body("Scanned 'Material QR' already completed the scanning process.") - ->danger() - ->seconds(2) - ->send(); - $this->dispatch('playWarnSound'); $this->form->fill([ @@ -3359,7 +3359,7 @@ class CreateInvoiceValidation extends CreateRecord } elseif ($hadMotorQr == $hasMotorQr) { Notification::make() ->title('Duplicate: Motor QR') - ->body("Scanned 'Motor' serial number already completed the scanning process.") + ->body("Scanned Motor Serial Number : '{$serialNumber}' already completed the scanning process.") ->danger() ->seconds(3) ->send(); @@ -3476,7 +3476,7 @@ class CreateInvoiceValidation extends CreateRecord } elseif ($hadPumpQr == $hasPumpQr) { Notification::make() ->title('Duplicate: Pump QR') - ->body("Scanned 'Pump' serial number already completed the scanning process.") + ->body("Scanned Pump Serial Number : '{$serialNumber}' already completed the scanning process.") ->danger() ->seconds(3) ->send(); @@ -3595,7 +3595,7 @@ class CreateInvoiceValidation extends CreateRecord } elseif ($hadCapacitorQr == '1' && $hasCapacitorQr) { Notification::make() ->title('Duplicate: Capacitor QR') - ->body("Scanned 'Capacitor' serial number already completed the scanning process.") + ->body("Scanned Capacitor Serial Number : '{$serialNumber}' already completed the scanning process.") ->danger() ->seconds(3) ->send(); @@ -3657,7 +3657,7 @@ class CreateInvoiceValidation extends CreateRecord } elseif ($hadPumpSetQr == $hasPumpSetQr) { Notification::make() ->title('Duplicate: Pump Set QR') - ->body("Scanned 'Pump Set' serial number already completed the scanning process.") + ->body("Scanned Pump Set Serial Number : '{$serialNumber}' already completed the scanning process.") ->danger() ->seconds(3) ->send();