Added material type 4 (Bundle Individual) on resource
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -32,12 +32,12 @@ class SendInvoiceReport extends Command
|
|||||||
{
|
{
|
||||||
$schedule = $this->argument('schedule_type');
|
$schedule = $this->argument('schedule_type');
|
||||||
// $scheduleType = $this->argument('scheduleType');
|
// $scheduleType = $this->argument('scheduleType');
|
||||||
$plantIdArg = (int) $this->argument('plant'); // can be 0 for all plants
|
$plantIdArg = (int) $this->argument('plant');
|
||||||
|
|
||||||
// $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
|
||||||
|
|
||||||
$mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
$mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
||||||
|
|
||||||
|
$this->info(print_r($mailRules->toArray(), true));
|
||||||
|
|
||||||
// $startDate = now()->setTime(8, 0, 0);
|
// $startDate = now()->setTime(8, 0, 0);
|
||||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||||
|
|
||||||
@@ -50,6 +50,8 @@ class SendInvoiceReport extends Command
|
|||||||
? InvoiceValidation::select('plant_id')->distinct()->pluck('plant_id')->toArray()
|
? InvoiceValidation::select('plant_id')->distinct()->pluck('plant_id')->toArray()
|
||||||
: [$plantIdArg];
|
: [$plantIdArg];
|
||||||
|
|
||||||
|
$isPlantRun = $plantIdArg != 0;
|
||||||
|
|
||||||
$no = 1;
|
$no = 1;
|
||||||
if (strtolower($schedule) == 'daily') {
|
if (strtolower($schedule) == 'daily') {
|
||||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||||
@@ -178,61 +180,97 @@ class SendInvoiceReport extends Command
|
|||||||
$no++;
|
$no++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mail = new test($serialTableData, $materialTableData, $bundleTableData, $schedule);
|
// $mail = new test($serialTableData, $materialTableData, $bundleTableData, $schedule);
|
||||||
$contentVars = $mail->content()->with;
|
// $contentVars = $mail->content()->with;
|
||||||
|
|
||||||
$this->info($contentVars['greeting'] ?? 'Invoice Report');
|
$this->info($contentVars['greeting'] ?? 'Invoice Report');
|
||||||
|
|
||||||
// Send to SerialInvoiceMail recipients
|
// 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')) {
|
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) {
|
foreach ($mailRules->get('SerialInvoiceMail') as $rule) {
|
||||||
|
|
||||||
$toEmails = collect(explode(',', $rule->email))
|
if ($isPlantRun && $rule->plant != $plantIdArg && $rule->plant != 0) {
|
||||||
->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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rule->plant == 0) {
|
$data = collect($serialTableData)
|
||||||
$filteredSerialData = $serialTableData;
|
->when($rule->plant != 0, fn ($q) => $q->where('plant_id', $rule->plant))
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
} else {
|
if (empty($data)) continue;
|
||||||
$filteredSerialData = collect($serialTableData)
|
|
||||||
->where('plant_id', $rule->plant)
|
|
||||||
->values()
|
|
||||||
->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
\Mail::to($toEmails)
|
\Mail::to($rule->email)
|
||||||
->cc($ccEmails)
|
->cc($rule->cc_emails ?? [])
|
||||||
->send(new test(
|
->send(new test($data, [], [], $schedule));
|
||||||
$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) : ''));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,12 +338,21 @@ class SendInvoiceReport extends Command
|
|||||||
|
|
||||||
// Send to InvoiceMail recipients (all three tables)
|
// Send to InvoiceMail recipients (all three tables)
|
||||||
if ($mailRules->has('InvoiceMail')) {
|
if ($mailRules->has('InvoiceMail')) {
|
||||||
//$emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
|
||||||
// foreach ($emails as $email) {
|
$invoiceRules = $mailRules->get('InvoiceMail');
|
||||||
// Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
|
$hasGlobalRule = $invoiceRules->contains('plant', 0);
|
||||||
// $this->info("✅ Sent InvoiceMail to: {$email}");
|
|
||||||
// }
|
// foreach ($mailRules->get('InvoiceMail') as $rule) {
|
||||||
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))
|
$toEmails = collect(explode(',', $rule->email))
|
||||||
->map(fn ($e) => trim($e))
|
->map(fn ($e) => trim($e))
|
||||||
@@ -327,7 +374,6 @@ class SendInvoiceReport extends Command
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILTER DATA
|
|
||||||
if ($rule->plant == 0) {
|
if ($rule->plant == 0) {
|
||||||
|
|
||||||
$filteredSerialData = $serialTableData;
|
$filteredSerialData = $serialTableData;
|
||||||
@@ -362,18 +408,35 @@ class SendInvoiceReport extends Command
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// \Mail::to($toEmails)
|
||||||
|
// ->cc($ccEmails)
|
||||||
|
// ->send(new test(
|
||||||
|
// $filteredSerialData,
|
||||||
|
// $filteredMaterialData,
|
||||||
|
// $filteredBundleData,
|
||||||
|
// $schedule
|
||||||
|
// ));
|
||||||
|
|
||||||
|
$mail = new test(
|
||||||
|
$filteredSerialData,
|
||||||
|
$filteredMaterialData,
|
||||||
|
$filteredBundleData,
|
||||||
|
$schedule
|
||||||
|
);
|
||||||
|
|
||||||
\Mail::to($toEmails)
|
\Mail::to($toEmails)
|
||||||
->cc($ccEmails)
|
->cc($ccEmails)
|
||||||
->send(new test(
|
->send($mail);
|
||||||
$filteredSerialData,
|
|
||||||
$filteredMaterialData,
|
// \Mail::raw('Test mail', function ($message) use ($toEmails, $ccEmails) {
|
||||||
$filteredBundleData,
|
// $message->to($toEmails)
|
||||||
$schedule
|
// ->cc($ccEmails)
|
||||||
));
|
// ->subject('Test');
|
||||||
|
// });
|
||||||
|
|
||||||
// \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
|
// \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) : ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -296,9 +296,10 @@ class StickerMasterResource extends Resource
|
|||||||
Forms\Components\Select::make('material_type')
|
Forms\Components\Select::make('material_type')
|
||||||
->label('Material Type')
|
->label('Material Type')
|
||||||
->options([
|
->options([
|
||||||
'1' => 'Individual',
|
1 => 'Individual',
|
||||||
'2' => 'Bundle',
|
2 => 'Bundle',
|
||||||
'3' => 'Quantity',
|
3 => 'Quantity',
|
||||||
|
4 => 'Bundle Individual',
|
||||||
])
|
])
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
@@ -307,7 +308,7 @@ class StickerMasterResource extends Resource
|
|||||||
$set('load_rate', 0);
|
$set('load_rate', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($state !== '2') {
|
if ($state != '2' && $state != '4') {
|
||||||
$set('bundle_quantity', null);
|
$set('bundle_quantity', null);
|
||||||
} else {
|
} else {
|
||||||
$set('bundle_quantity', 2);
|
$set('bundle_quantity', 2);
|
||||||
@@ -319,12 +320,12 @@ class StickerMasterResource extends Resource
|
|||||||
Forms\Components\TextInput::make('bundle_quantity')
|
Forms\Components\TextInput::make('bundle_quantity')
|
||||||
->label('Bundle Quantity')
|
->label('Bundle Quantity')
|
||||||
->integer()
|
->integer()
|
||||||
->readOnly(fn (callable $get) => $get('material_type') !== '2')
|
->readOnly(fn (callable $get) => $get('material_type') != 2 && $get('material_type') != 4)
|
||||||
->nullable()
|
->nullable()
|
||||||
->minValue(2)
|
->minValue(2)
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->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);
|
$set('bundle_quantity', null);
|
||||||
} elseif ($get('bundle_quantity') < 2) {
|
} elseif ($get('bundle_quantity') < 2) {
|
||||||
$set('bundle_quantity', 2);
|
$set('bundle_quantity', 2);
|
||||||
@@ -655,10 +656,6 @@ class StickerMasterResource extends Resource
|
|||||||
->label('Load Rate')
|
->label('Load Rate')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('bundle_quantity')
|
|
||||||
->label('Bundle Quantity')
|
|
||||||
->default('-')
|
|
||||||
->alignCenter(),
|
|
||||||
Tables\Columns\TextColumn::make('material_type')
|
Tables\Columns\TextColumn::make('material_type')
|
||||||
->label('Material Type')
|
->label('Material Type')
|
||||||
->default('-')
|
->default('-')
|
||||||
@@ -672,9 +669,14 @@ class StickerMasterResource extends Resource
|
|||||||
1 => 'Individual',
|
1 => 'Individual',
|
||||||
2 => 'Bundle',
|
2 => 'Bundle',
|
||||||
3 => 'Quantity',
|
3 => 'Quantity',
|
||||||
|
4 => 'Bundle Individual',
|
||||||
default => '-',
|
default => '-',
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
Tables\Columns\TextColumn::make('bundle_quantity')
|
||||||
|
->label('Bundle Quantity')
|
||||||
|
->default('-')
|
||||||
|
->alignCenter(),
|
||||||
Tables\Columns\TextColumn::make('created_by')
|
Tables\Columns\TextColumn::make('created_by')
|
||||||
->label('Created By')
|
->label('Created By')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
@@ -754,12 +756,13 @@ class StickerMasterResource extends Resource
|
|||||||
->searchable()
|
->searchable()
|
||||||
->reactive(),
|
->reactive(),
|
||||||
Select::make('material_type')
|
Select::make('material_type')
|
||||||
->label('Select Material Type')
|
->label('Search by Material Type')
|
||||||
->nullable()
|
->nullable()
|
||||||
->options([
|
->options([
|
||||||
1 => 'Individual',
|
1 => 'Individual',
|
||||||
2 => 'Bundle',
|
2 => 'Bundle',
|
||||||
3 => 'Quantity',
|
3 => 'Quantity',
|
||||||
|
4 => 'Bundle Individual',
|
||||||
])
|
])
|
||||||
->searchable()
|
->searchable()
|
||||||
->reactive(),
|
->reactive(),
|
||||||
@@ -870,6 +873,8 @@ class StickerMasterResource extends Resource
|
|||||||
$indicators[] = 'Material Type: Bundle';
|
$indicators[] = 'Material Type: Bundle';
|
||||||
} elseif ($data['material_type'] == 3) {
|
} elseif ($data['material_type'] == 3) {
|
||||||
$indicators[] = 'Material Type: Quantity';
|
$indicators[] = 'Material Type: Quantity';
|
||||||
|
} elseif ($data['material_type'] == 4) {
|
||||||
|
$indicators[] = 'Material Type: Bundle Individual';
|
||||||
}
|
}
|
||||||
// $indicators[] = 'Material Type: '.$data['material_type'];
|
// $indicators[] = 'Material Type: '.$data['material_type'];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user