diff --git a/app/Console/Commands/SendInvoiceDataReport.php b/app/Console/Commands/SendInvoiceDataReport.php index 2deec81..b3dfee4 100644 --- a/app/Console/Commands/SendInvoiceDataReport.php +++ b/app/Console/Commands/SendInvoiceDataReport.php @@ -33,43 +33,15 @@ class SendInvoiceDataReport extends Command public function handle() { $scheduleType = $this->argument('schedule_type'); - $plantId = (int) $this->argument('plant'); // cast to int for safety + $plantId = (int) $this->argument('plant'); - // // Fetch mail rules based on schedule type - // $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceDataReport') - // ->where('rule_name', 'InvoiceDataMail') - // ->where('schedule_type', $scheduleType) - // ->where('plant', $plantId) - // ->get(); - - // $emails = $mailRules->pluck('email')->unique()->toArray(); - - // $ccEmails = $mailRules->pluck('cc_emails')->filter()->unique()->toArray(); - - // $this->info('Found emails: ' . implode(', ', $ccEmails)); - $mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceDataReport') ->where('rule_name', 'InvoiceDataMail') ->where('schedule_type', $scheduleType) ->where('plant', $plantId) ->get(); - // $toEmails = $mailRules->pluck('email') - // ->flatMap(function ($emails) { - // return array_map('trim', explode(',', $emails)); - // }) - // ->filter() - // ->toArray(); - - // $ccEmails = $mailRules->pluck('cc_emails') - // ->filter() // remove null or empty - // ->flatMap(function ($emails) { - // return array_map('trim', explode(',', $emails)); - // }) - // ->filter() - // ->toArray(); - $plants = $plantId == 0 ? Plant::all() : Plant::where('id', $plantId)->get(); @@ -108,8 +80,6 @@ class SendInvoiceDataReport extends Command //.. - $no = 1; - foreach ($plants as $plant) { $tableData = []; @@ -140,18 +110,11 @@ class SendInvoiceDataReport extends Command continue; } - // $lastInvoiceDate = $invoices->max('document_date'); - // $extendedEndDate = \Carbon\Carbon::parse($lastInvoiceDate) - // ->addDay() // +1 day - // ->setTime(10, 0, 0); // 10:00 AM - - // Filter invoices directly — exclude ones with '-' in document_number $invoices = $invoices->filter(function ($inv) { return !empty($inv->document_number) && !str_contains($inv->document_number, '-'); }); - // For empty distribution, only take those starting with '7' if (trim($selectedDistribution) == '' || $selectedDistribution == null) { $invoices = $invoices->filter(function ($inv) { return str_starts_with($inv->document_number, '7'); @@ -168,8 +131,6 @@ class SendInvoiceDataReport extends Command ->toArray(); $wentOutInvoices = \App\Models\InvoiceOutValidation::where('plant_id', $plant->id) - //->whereIn('qr_code', $invoices->pluck('document_number')) - //->whereIn('qr_code', $invoices->pluck('document_number')->toArray()) ->whereIn('qr_code', $invoiceNumbers) ->whereBetween('scanned_at', [$startDate, $endDate]) ->distinct('qr_code')