correction of alert mail rule logic for invoice data report
This commit is contained in:
@@ -5,7 +5,8 @@ namespace App\Console\Commands;
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use App\Models\AlertMailRule;
|
use App\Models\AlertMailRule;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class Scheduler extends Command
|
class Scheduler extends Command
|
||||||
{
|
{
|
||||||
@@ -76,6 +77,7 @@ class Scheduler extends Command
|
|||||||
|
|
||||||
// --- Invoice Validation Rules ---
|
// --- Invoice Validation Rules ---
|
||||||
$invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
|
$invoiceRules = AlertMailRule::where('module', 'InvoiceValidation')
|
||||||
|
->where('rule_name', 'InvoiceMail')
|
||||||
->select('plant', 'schedule_type')
|
->select('plant', 'schedule_type')
|
||||||
->distinct()
|
->distinct()
|
||||||
->get();
|
->get();
|
||||||
@@ -90,6 +92,7 @@ class Scheduler extends Command
|
|||||||
'plant' => $rule->plant,
|
'plant' => $rule->plant,
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Hourly':
|
case 'Hourly':
|
||||||
if (now()->minute == 0) {
|
if (now()->minute == 0) {
|
||||||
\Artisan::call('send:invoice-report', [
|
\Artisan::call('send:invoice-report', [
|
||||||
@@ -108,9 +111,46 @@ class Scheduler extends Command
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// foreach ($invoiceRules as $rule) {
|
||||||
|
|
||||||
|
// switch ($rule->schedule_type) {
|
||||||
|
// case 'Live':
|
||||||
|
// try {
|
||||||
|
// Artisan::call('send:invoice-report', [
|
||||||
|
// 'schedule_type' => $rule->schedule_type,
|
||||||
|
// 'plant' => $rule->plant,
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// Log::info('Invoice report sent | Plant: '.$rule->plant);
|
||||||
|
// } catch (\Throwable $e) {
|
||||||
|
// Log::error("Invoice Live Failed ({$rule->plant}): ".$e->getMessage());
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case 'Hourly':
|
||||||
|
// if (now()->minute == 0) {
|
||||||
|
// Artisan::call('send:invoice-report', [
|
||||||
|
// 'schedule_type' => $rule->schedule_type,
|
||||||
|
// 'plant' => $rule->plant,
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case 'Daily':
|
||||||
|
// if (now()->format('H:i') == '07:59') {
|
||||||
|
// Artisan::call('send:invoice-report', [
|
||||||
|
// 'schedule_type' => $rule->schedule_type,
|
||||||
|
// 'plant' => $rule->plant,
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
// --- Invoice Data Report Rules ---
|
// --- Invoice Data Report Rules ---
|
||||||
$invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport')
|
$invoiceDataRules = AlertMailRule::where('module', 'InvoiceDataReport')
|
||||||
|
->where('rule_name', 'InvoiceDataMail')
|
||||||
->select('plant', 'schedule_type')
|
->select('plant', 'schedule_type')
|
||||||
->distinct()
|
->distinct()
|
||||||
->get();
|
->get();
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Mail\test;
|
||||||
use App\Models\InvoiceValidation;
|
use App\Models\InvoiceValidation;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use App\Mail\test;
|
|
||||||
|
|
||||||
class SendInvoiceReport extends Command
|
class SendInvoiceReport extends Command
|
||||||
{
|
{
|
||||||
@@ -15,9 +15,8 @@ class SendInvoiceReport extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
// protected $signature = 'app:send-invoice-report';
|
// protected $signature = 'app:send-invoice-report';
|
||||||
protected $signature = 'send:invoice-report{schedule_type} {plant}';
|
protected $signature = 'send:invoice-report {schedule_type} {plant}';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@@ -29,12 +28,10 @@ class SendInvoiceReport extends Command
|
|||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$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'); // can be 0 for all plants
|
||||||
|
|
||||||
$mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
$mailRules = \App\Models\AlertMailRule::where('module', 'InvoiceValidation')->get()->groupBy('rule_name');
|
||||||
@@ -52,18 +49,14 @@ class SendInvoiceReport extends Command
|
|||||||
: [$plantIdArg];
|
: [$plantIdArg];
|
||||||
|
|
||||||
$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);
|
||||||
$endDate = now()->setTime(8, 0, 0);
|
$endDate = now()->setTime(8, 0, 0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$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);
|
||||||
}
|
}
|
||||||
foreach ($plantIds as $plantId)
|
foreach ($plantIds as $plantId) {
|
||||||
{
|
|
||||||
$plant = Plant::find($plantId);
|
$plant = Plant::find($plantId);
|
||||||
$plantName = $plant ? $plant->name : $plantId;
|
$plantName = $plant ? $plant->name : $plantId;
|
||||||
|
|
||||||
@@ -89,7 +82,7 @@ class SendInvoiceReport extends Command
|
|||||||
|
|
||||||
$scannedInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
$scannedInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||||
->where('scanned_status', 'Scanned')
|
->where('scanned_status', 'Scanned')
|
||||||
->where(function($query) {
|
->where(function ($query) {
|
||||||
$query->whereNull('quantity')
|
$query->whereNull('quantity')
|
||||||
->orWhere('quantity', 0);
|
->orWhere('quantity', 0);
|
||||||
})
|
})
|
||||||
@@ -128,7 +121,7 @@ class SendInvoiceReport extends Command
|
|||||||
$scannedMatInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
$scannedMatInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||||
->where('quantity', 1)
|
->where('quantity', 1)
|
||||||
->whereNotNull('serial_number')
|
->whereNotNull('serial_number')
|
||||||
->where('serial_number','!=', '')
|
->where('serial_number', '!=', '')
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('updated_at', [$startDate, $endDate])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
@@ -164,7 +157,7 @@ class SendInvoiceReport extends Command
|
|||||||
$scannedBundleInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
$scannedBundleInvoiceQuan = InvoiceValidation::where('plant_id', $plantId)
|
||||||
->where('quantity', '>', 1)
|
->where('quantity', '>', 1)
|
||||||
->whereNotNull('serial_number')
|
->whereNotNull('serial_number')
|
||||||
->where('serial_number','!=', '')
|
->where('serial_number', '!=', '')
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('updated_at', [$startDate, $endDate])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
@@ -193,7 +186,6 @@ class SendInvoiceReport extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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();
|
||||||
@@ -212,16 +204,14 @@ class SendInvoiceReport extends Command
|
|||||||
|
|
||||||
// Show preview in console
|
// Show preview in console
|
||||||
$this->info('--- Serial Invoice Table ---');
|
$this->info('--- Serial Invoice Table ---');
|
||||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice','TotalInvoice Quantity', 'ScannedInvoice Quantity'], $serialTableData);
|
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice', 'TotalInvoice Quantity', 'ScannedInvoice Quantity'], $serialTableData);
|
||||||
|
|
||||||
$this->info('--- Material Invoice Table ---');
|
$this->info('--- Material Invoice Table ---');
|
||||||
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice','TotalInvoice Quantity', 'ScannedInvoice Quantity'], $materialTableData);
|
$this->table(['#', 'Plant', 'Total Invoice', 'Scanned Invoice', 'TotalInvoice Quantity', 'ScannedInvoice Quantity'], $materialTableData);
|
||||||
|
|
||||||
$this->info('--- Bundle Invoice Table ---');
|
$this->info('--- Bundle Invoice Table ---');
|
||||||
$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