Merge pull request 'ranjith-dev' (#643) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #643
This commit was merged in pull request #643.
This commit is contained in:
2026-05-25 11:31:23 +00:00
3 changed files with 139 additions and 73 deletions

View File

@@ -32,9 +32,7 @@ class SendInvoiceReport extends Command
{
$schedule = $this->argument('schedule_type');
// $scheduleType = $this->argument('scheduleType');
$plantIdArg = (int) $this->argument('plant'); // can be 0 for all plants
// $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
$plantIdArg = (int) $this->argument('plant');
$mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
@@ -50,6 +48,8 @@ class SendInvoiceReport extends Command
? InvoiceValidation::select('plant_id')->distinct()->pluck('plant_id')->toArray()
: [$plantIdArg];
$isPlantRun = $plantIdArg != 0;
$no = 1;
if (strtolower($schedule) == 'daily') {
$startDate = now()->subDay()->setTime(8, 0, 0);
@@ -178,61 +178,97 @@ class SendInvoiceReport extends Command
$no++;
}
$mail = new test($serialTableData, $materialTableData, $bundleTableData, $schedule);
$contentVars = $mail->content()->with;
// $mail = new test($serialTableData, $materialTableData, $bundleTableData, $schedule);
// $contentVars = $mail->content()->with;
$this->info($contentVars['greeting'] ?? 'Invoice Report');
// Send to SerialInvoiceMail recipients
// if ($mailRules->has('SerialInvoiceMail')) {
// foreach ($mailRules->get('SerialInvoiceMail') as $rule) {
// $filteredSerialData = [];
// $toEmails = collect(explode(',', $rule->email))
// ->map(fn ($e) => trim($e))
// ->filter()
// ->unique()
// ->values()
// ->toArray();
// $ccEmails = collect(explode(',', $rule->cc_emails ?? ''))
// ->map(fn ($e) => trim($e))
// ->filter()
// ->unique()
// ->values()
// ->toArray();
// if (empty($toEmails)) {
// $this->warn("Skipping rule ID {$rule->id} — no valid To emails found.");
// continue;
// }
// if ($rule->plant == 0) {
// $filteredSerialData = $serialTableData;
// } else {
// $filteredSerialData = collect($serialTableData)
// ->where('plant_id', $rule->plant)
// ->values()
// ->toArray();
// }
// if (empty($filteredSerialData)) {
// $this->warn("Skipping empty mail for rule {$rule->id}");
// continue;
// }
// // \Mail::to($toEmails)
// // ->cc($ccEmails)
// // ->send(new test(
// // $filteredSerialData,
// // [],
// // [],
// // $schedule
// // ));
// $mail = new test(
// $filteredSerialData,
// [],
// [],
// $schedule
// );
// \Mail::to($toEmails)
// ->cc($ccEmails)
// ->send($mail);
// // \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, [], [], $schedule));
// $this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
// }
// }
if ($mailRules->has('SerialInvoiceMail')) {
// $emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
// foreach ($emails as $email) {
// Mail::to($email)->send(new test($serialTableData, [], [], $schedule));
// }
foreach ($mailRules->get('SerialInvoiceMail') as $rule) {
$toEmails = collect(explode(',', $rule->email))
->map(fn ($e) => trim($e))
->filter()
->unique()
->values()
->toArray();
$ccEmails = collect(explode(',', $rule->cc_emails ?? ''))
->map(fn ($e) => trim($e))
->filter()
->unique()
->values()
->toArray();
if (empty($toEmails)) {
$this->warn("Skipping rule ID {$rule->id} — no valid To emails found.");
if ($isPlantRun && $rule->plant != $plantIdArg && $rule->plant != 0) {
continue;
}
if ($rule->plant == 0) {
$filteredSerialData = $serialTableData;
$data = collect($serialTableData)
->when($rule->plant != 0, fn ($q) => $q->where('plant_id', $rule->plant))
->values()
->toArray();
} else {
$filteredSerialData = collect($serialTableData)
->where('plant_id', $rule->plant)
->values()
->toArray();
}
if (empty($data)) continue;
\Mail::to($toEmails)
->cc($ccEmails)
->send(new test(
$filteredSerialData,
[],
[],
$schedule
));
// \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, [], [], $schedule));
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
\Mail::to($rule->email)
->cc($rule->cc_emails ?? [])
->send(new test($data, [], [], $schedule));
}
}
@@ -300,12 +336,21 @@ class SendInvoiceReport extends Command
// Send to InvoiceMail recipients (all three tables)
if ($mailRules->has('InvoiceMail')) {
//$emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
// foreach ($emails as $email) {
// Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
// $this->info("✅ Sent InvoiceMail to: {$email}");
// }
foreach ($mailRules->get('InvoiceMail') as $rule) {
$invoiceRules = $mailRules->get('InvoiceMail');
$hasGlobalRule = $invoiceRules->contains('plant', 0);
// foreach ($mailRules->get('InvoiceMail') as $rule) {
foreach ($invoiceRules as $rule) {
if ($hasGlobalRule && $rule->plant != 0) {
$this->info("Skipping rule ID {$rule->id} (plant={$rule->plant}) — covered by global plant=0 rule.");
continue;
}
$filteredSerialData = [];
$filteredMaterialData = [];
$filteredBundleData = [];
$toEmails = collect(explode(',', $rule->email))
->map(fn ($e) => trim($e))
@@ -327,7 +372,6 @@ class SendInvoiceReport extends Command
continue;
}
// FILTER DATA
if ($rule->plant == 0) {
$filteredSerialData = $serialTableData;
@@ -362,18 +406,35 @@ class SendInvoiceReport extends Command
continue;
}
// \Mail::to($toEmails)
// ->cc($ccEmails)
// ->send(new test(
// $filteredSerialData,
// $filteredMaterialData,
// $filteredBundleData,
// $schedule
// ));
$mail = new test(
$filteredSerialData,
$filteredMaterialData,
$filteredBundleData,
$schedule
);
\Mail::to($toEmails)
->cc($ccEmails)
->send(new test(
$filteredSerialData,
$filteredMaterialData,
$filteredBundleData,
$schedule
));
->send($mail);
// \Mail::raw('Test mail', function ($message) use ($toEmails, $ccEmails) {
// $message->to($toEmails)
// ->cc($ccEmails)
// ->subject('Test');
// });
// \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
// $this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
}
}

View File

@@ -273,8 +273,8 @@ class StickerMasterImporter extends Importer
if (Str::length($this->data['bundle_quantity']) > 0 && (! is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
}
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { // ($this->data['material_type'] != null) &&
$warnMsg[] = 'Material type must be 1 or 2 or 3 or empty';
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3' && $this->data['material_type'] != '4') { // ($this->data['material_type'] != null) &&
$warnMsg[] = 'Material type must be 1 or 2 or 3 or 4 or empty';
}
if (empty($warnMsg)) {

View File

@@ -296,9 +296,10 @@ class StickerMasterResource extends Resource
Forms\Components\Select::make('material_type')
->label('Material Type')
->options([
'1' => 'Individual',
'2' => 'Bundle',
'3' => 'Quantity',
1 => 'Individual',
2 => 'Bundle',
3 => 'Quantity',
4 => 'Bundle Individual',
])
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -307,7 +308,7 @@ class StickerMasterResource extends Resource
$set('load_rate', 0);
}
if ($state !== '2') {
if ($state != '2' && $state != '4') {
$set('bundle_quantity', null);
} else {
$set('bundle_quantity', 2);
@@ -319,12 +320,12 @@ class StickerMasterResource extends Resource
Forms\Components\TextInput::make('bundle_quantity')
->label('Bundle Quantity')
->integer()
->readOnly(fn (callable $get) => $get('material_type') !== '2')
->readOnly(fn (callable $get) => $get('material_type') != 2 && $get('material_type') != 4)
->nullable()
->minValue(2)
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
if ($get('material_type') !== '2') {
if ($get('material_type') != 2 && $get('material_type') != 4) {
$set('bundle_quantity', null);
} elseif ($get('bundle_quantity') < 2) {
$set('bundle_quantity', 2);
@@ -655,10 +656,6 @@ class StickerMasterResource extends Resource
->label('Load Rate')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('bundle_quantity')
->label('Bundle Quantity')
->default('-')
->alignCenter(),
Tables\Columns\TextColumn::make('material_type')
->label('Material Type')
->default('-')
@@ -672,9 +669,14 @@ class StickerMasterResource extends Resource
1 => 'Individual',
2 => 'Bundle',
3 => 'Quantity',
4 => 'Bundle Individual',
default => '-',
};
}),
Tables\Columns\TextColumn::make('bundle_quantity')
->label('Bundle Quantity')
->default('-')
->alignCenter(),
Tables\Columns\TextColumn::make('created_by')
->label('Created By')
->alignCenter()
@@ -754,12 +756,13 @@ class StickerMasterResource extends Resource
->searchable()
->reactive(),
Select::make('material_type')
->label('Select Material Type')
->label('Search by Material Type')
->nullable()
->options([
1 => 'Individual',
2 => 'Bundle',
3 => 'Quantity',
4 => 'Bundle Individual',
])
->searchable()
->reactive(),
@@ -870,6 +873,8 @@ class StickerMasterResource extends Resource
$indicators[] = 'Material Type: Bundle';
} elseif ($data['material_type'] == 3) {
$indicators[] = 'Material Type: Quantity';
} elseif ($data['material_type'] == 4) {
$indicators[] = 'Material Type: Bundle Individual';
}
// $indicators[] = 'Material Type: '.$data['material_type'];
}