changed logic in invoice report
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 17s
Laravel Pint / pint (pull_request) Successful in 2m24s
Laravel Larastan / larastan (pull_request) Failing after 3m35s

This commit is contained in:
dhanabalan
2026-01-20 18:42:19 +05:30
parent 58191aada6
commit d04e118bf6

View File

@@ -70,7 +70,7 @@ class SendInvoiceReport extends Command
$scannedSerialCount = InvoiceValidation::select('invoice_number')
->where('plant_id', $plantId)
->whereNull('quantity')
->whereBetween('updated_at', [$startDate, $endDate])
->whereBetween('created_at', [$startDate, $endDate])
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)")
->count();
@@ -86,7 +86,7 @@ class SendInvoiceReport extends Command
$query->whereNull('quantity')
->orWhere('quantity', 0);
})
->whereBetween('updated_at', [$startDate, $endDate])
->whereBetween('created_at', [$startDate, $endDate])
->count();
$serialTableData[] = [
@@ -108,7 +108,7 @@ class SendInvoiceReport extends Command
$scannedMatCount = InvoiceValidation::select('invoice_number')
->where('plant_id', $plantId)
->where('quantity', 1)
->whereBetween('updated_at', [$startDate, $endDate])
->whereBetween('created_at', [$startDate, $endDate])
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
->count();
@@ -122,7 +122,7 @@ class SendInvoiceReport extends Command
->where('quantity', 1)
->whereNotNull('serial_number')
->where('serial_number', '!=', '')
->whereBetween('updated_at', [$startDate, $endDate])
->whereBetween('created_at', [$startDate, $endDate])
->count();
$materialTableData[] = [
@@ -144,7 +144,7 @@ class SendInvoiceReport extends Command
$scannedBundleCount = InvoiceValidation::select('invoice_number')
->where('plant_id', $plantId)
->where('quantity', '>', 1)
->whereBetween('updated_at', [$startDate, $endDate])
->whereBetween('created_at', [$startDate, $endDate])
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
->count();
@@ -158,7 +158,7 @@ class SendInvoiceReport extends Command
->where('quantity', '>', 1)
->whereNotNull('serial_number')
->where('serial_number', '!=', '')
->whereBetween('updated_at', [$startDate, $endDate])
->whereBetween('created_at', [$startDate, $endDate])
->count();
$bundleTableData[] = [
@@ -180,25 +180,104 @@ class SendInvoiceReport extends Command
// Send to SerialInvoiceMail recipients
if ($mailRules->has('SerialInvoiceMail')) {
$emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
foreach ($emails as $email) {
Mail::to($email)->send(new test($serialTableData, [], [], $schedule));
// $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.");
continue;
}
\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) : ''));
}
}
// Send to MaterialInvoiceMail recipients (material + bundle table)
if ($mailRules->has('MaterialInvoiceMail')) {
$emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
foreach ($emails as $email) {
Mail::to($email)->send(new test([], $materialTableData, $bundleTableData, $schedule));
// $emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
// foreach ($emails as $email) {
// Mail::to($email)->send(new test([], $materialTableData, $bundleTableData, $schedule));
// }
foreach ($mailRules->get('MaterialInvoiceMail') 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.");
continue;
}
\Mail::to($toEmails)->cc($ccEmails)->send(new test([], $materialTableData, $bundleTableData, $schedule));
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
}
}
// 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));
//$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) {
$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;
}
\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) : ''));
}
}
@@ -213,5 +292,6 @@ class SendInvoiceReport extends Command
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice', 'TotalInvoice Quantity', 'ScannedInvoice Quantity'], $bundleTableData);
$this->info($contentVars['wishes'] ?? '');
}
}