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
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:
@@ -70,7 +70,7 @@ class SendInvoiceReport extends Command
|
|||||||
$scannedSerialCount = InvoiceValidation::select('invoice_number')
|
$scannedSerialCount = InvoiceValidation::select('invoice_number')
|
||||||
->where('plant_id', $plantId)
|
->where('plant_id', $plantId)
|
||||||
->whereNull('quantity')
|
->whereNull('quantity')
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
->groupBy('invoice_number')
|
->groupBy('invoice_number')
|
||||||
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)")
|
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)")
|
||||||
->count();
|
->count();
|
||||||
@@ -86,7 +86,7 @@ class SendInvoiceReport extends Command
|
|||||||
$query->whereNull('quantity')
|
$query->whereNull('quantity')
|
||||||
->orWhere('quantity', 0);
|
->orWhere('quantity', 0);
|
||||||
})
|
})
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$serialTableData[] = [
|
$serialTableData[] = [
|
||||||
@@ -108,7 +108,7 @@ class SendInvoiceReport extends Command
|
|||||||
$scannedMatCount = InvoiceValidation::select('invoice_number')
|
$scannedMatCount = InvoiceValidation::select('invoice_number')
|
||||||
->where('plant_id', $plantId)
|
->where('plant_id', $plantId)
|
||||||
->where('quantity', 1)
|
->where('quantity', 1)
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
->groupBy('invoice_number')
|
->groupBy('invoice_number')
|
||||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
|
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
|
||||||
->count();
|
->count();
|
||||||
@@ -122,7 +122,7 @@ class SendInvoiceReport extends Command
|
|||||||
->where('quantity', 1)
|
->where('quantity', 1)
|
||||||
->whereNotNull('serial_number')
|
->whereNotNull('serial_number')
|
||||||
->where('serial_number', '!=', '')
|
->where('serial_number', '!=', '')
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$materialTableData[] = [
|
$materialTableData[] = [
|
||||||
@@ -144,7 +144,7 @@ class SendInvoiceReport extends Command
|
|||||||
$scannedBundleCount = InvoiceValidation::select('invoice_number')
|
$scannedBundleCount = InvoiceValidation::select('invoice_number')
|
||||||
->where('plant_id', $plantId)
|
->where('plant_id', $plantId)
|
||||||
->where('quantity', '>', 1)
|
->where('quantity', '>', 1)
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
->groupBy('invoice_number')
|
->groupBy('invoice_number')
|
||||||
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
|
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)")
|
||||||
->count();
|
->count();
|
||||||
@@ -158,7 +158,7 @@ class SendInvoiceReport extends Command
|
|||||||
->where('quantity', '>', 1)
|
->where('quantity', '>', 1)
|
||||||
->whereNotNull('serial_number')
|
->whereNotNull('serial_number')
|
||||||
->where('serial_number', '!=', '')
|
->where('serial_number', '!=', '')
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$bundleTableData[] = [
|
$bundleTableData[] = [
|
||||||
@@ -180,25 +180,104 @@ class SendInvoiceReport extends Command
|
|||||||
|
|
||||||
// Send to SerialInvoiceMail recipients
|
// Send to SerialInvoiceMail recipients
|
||||||
if ($mailRules->has('SerialInvoiceMail')) {
|
if ($mailRules->has('SerialInvoiceMail')) {
|
||||||
$emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
// $emails = $mailRules['SerialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||||
foreach ($emails as $email) {
|
// foreach ($emails as $email) {
|
||||||
Mail::to($email)->send(new test($serialTableData, [], [], $schedule));
|
// 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)
|
// Send to MaterialInvoiceMail recipients (material + bundle table)
|
||||||
if ($mailRules->has('MaterialInvoiceMail')) {
|
if ($mailRules->has('MaterialInvoiceMail')) {
|
||||||
$emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
// $emails = $mailRules['MaterialInvoiceMail']->pluck('email')->unique()->toArray();
|
||||||
foreach ($emails as $email) {
|
// foreach ($emails as $email) {
|
||||||
Mail::to($email)->send(new test([], $materialTableData, $bundleTableData, $schedule));
|
// 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)
|
// Send to InvoiceMail recipients (all three tables)
|
||||||
if ($mailRules->has('InvoiceMail')) {
|
if ($mailRules->has('InvoiceMail')) {
|
||||||
$emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
//$emails = $mailRules['InvoiceMail']->pluck('email')->unique()->toArray();
|
||||||
foreach ($emails as $email) {
|
// foreach ($emails as $email) {
|
||||||
Mail::to($email)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule));
|
// 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->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice', 'TotalInvoice Quantity', 'ScannedInvoice Quantity'], $bundleTableData);
|
||||||
|
|
||||||
$this->info($contentVars['wishes'] ?? '');
|
$this->info($contentVars['wishes'] ?? '');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user