changed logici n production mail report
This commit is contained in:
@@ -8,7 +8,9 @@ use Illuminate\Console\Command;
|
|||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use App\Mail\ProductionMail;
|
use App\Mail\ProductionMail;
|
||||||
use App\Models\Line;
|
use App\Models\Line;
|
||||||
|
use App\Models\ProductionPlan;
|
||||||
use App\Models\ProductionQuantity;
|
use App\Models\ProductionQuantity;
|
||||||
|
use DB;
|
||||||
|
|
||||||
class SendProductionReport extends Command
|
class SendProductionReport extends Command
|
||||||
{
|
{
|
||||||
@@ -18,7 +20,7 @@ class SendProductionReport extends Command
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
//protected $signature = 'send:production-report';
|
//protected $signature = 'send:production-report';
|
||||||
protected $signature = 'send:production-report {schedule_type}';
|
protected $signature = 'send:production-report {schedule_type} {plant}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@@ -30,147 +32,45 @@ class SendProductionReport extends Command
|
|||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*/
|
*/
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
|
|
||||||
$scheduleType = $this->argument('schedule_type');
|
|
||||||
|
|
||||||
$mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
|
||||||
->where('rule_name', 'ProductionMail')
|
|
||||||
->where('schedule_type', $scheduleType)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
$emails = $mailRules->pluck('email')->unique()->toArray();
|
|
||||||
|
|
||||||
$lines = Line::all();
|
|
||||||
$lineMeta = []; // Store line name, type, and plant_id
|
|
||||||
foreach ($lines as $line) {
|
|
||||||
$lineMeta[$line->id] = [
|
|
||||||
'name' => $line->name,
|
|
||||||
'type' => $line->type,
|
|
||||||
'plant_id' => $line->plant_id,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$startDate = now()->setTime(8, 0, 0);
|
|
||||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
|
||||||
|
|
||||||
$plants = Plant::all()->keyBy('id');
|
|
||||||
|
|
||||||
$uniqueLineIds = ProductionQuantity::select('line_id')->distinct()->pluck('line_id');
|
|
||||||
|
|
||||||
// Preload production quantities grouped by line_id
|
|
||||||
$allProduction = ProductionQuantity::select('line_id', \DB::raw('COUNT(*) as total_quantity'))
|
|
||||||
->whereBetween('created_at', [$startDate, $endDate])
|
|
||||||
->groupBy('line_id')
|
|
||||||
->pluck('total_quantity', 'line_id')
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
$tableData = [];
|
|
||||||
$no = 1;
|
|
||||||
|
|
||||||
foreach ($plants as $plantId => $plant) {
|
|
||||||
foreach ($uniqueLineIds as $lineId) {
|
|
||||||
if (!isset($lineMeta[$lineId]) || $lineMeta[$lineId]['plant_id'] != $plantId) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$lineInfo = $lineMeta[$lineId];
|
|
||||||
$lineName = $lineInfo['name'];
|
|
||||||
|
|
||||||
$targetQuantity = \App\Models\ProductionPlan::where('plant_id', $plantId)
|
|
||||||
->where('line_id', $lineId)
|
|
||||||
->whereBetween('created_at', [$startDate, $endDate])
|
|
||||||
->sum('plan_quantity');
|
|
||||||
|
|
||||||
$productionQuantity = $allProduction[$lineId] ?? 0;
|
|
||||||
|
|
||||||
$tableData[] = [
|
|
||||||
'no' => $no++,
|
|
||||||
'plant' => $plant->name,
|
|
||||||
'line' => $lineName,
|
|
||||||
'targetQuantity' => $targetQuantity,
|
|
||||||
'productionQuantity' => $productionQuantity,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//$this->info(json_encode($tableData));
|
|
||||||
if (!empty($emails))
|
|
||||||
{
|
|
||||||
// Mail::to($emails)->send(new test($tableData));
|
|
||||||
//$this->info('production report email sent successfully to: ' . implode(', ', $emails));
|
|
||||||
foreach ($emails as $email)
|
|
||||||
{
|
|
||||||
Mail::to($email)->send(new ProductionMail($tableData));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->info('No recipients found for InvoiceMailAlert.');
|
|
||||||
}
|
|
||||||
//$this->info(implode(', ', $emails));
|
|
||||||
}
|
|
||||||
|
|
||||||
// public function handle()
|
// public function handle()
|
||||||
// {
|
// {
|
||||||
// $now = now();
|
|
||||||
|
// $scheduleType = $this->argument('schedule_type');
|
||||||
|
// //$plant = $this->argument('plant');
|
||||||
|
// $plant = (int) $this->argument('plant');
|
||||||
|
|
||||||
// $mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
// $mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
||||||
// ->where('rule_name', 'ProductionMail')
|
// ->where('rule_name', 'ProductionMail')
|
||||||
|
// ->where('plant', $plant)
|
||||||
|
// ->where('schedule_type', $scheduleType)
|
||||||
// ->get();
|
// ->get();
|
||||||
|
|
||||||
// // Filter emails based on current time and schedule_type
|
// $emails = $mailRules->pluck('email')->unique()->toArray();
|
||||||
// $filteredEmails = $mailRules->filter(function ($rule) use ($now) {
|
|
||||||
// return match ($rule->schedule_type) {
|
|
||||||
// 'Live' => true,
|
|
||||||
// 'Hourly' => $now->minute === 0,
|
|
||||||
// 'Daily' => $now->format('H:i') === '07:59',
|
|
||||||
// default => false,
|
|
||||||
// };
|
|
||||||
// })->pluck('email')->unique()->toArray();
|
|
||||||
|
|
||||||
// $lines = Line::all();
|
// $plants = Plant::all()->keyBy('id');
|
||||||
// $lineMeta = [];
|
// $lines = Line::all()->groupBy('plant_id'); // Group lines by plant for easy lookup
|
||||||
// foreach ($lines as $line) {
|
|
||||||
// $lineMeta[$line->id] = [
|
|
||||||
// 'name' => $line->name,
|
|
||||||
// 'type' => $line->type,
|
|
||||||
// 'plant_id' => $line->plant_id,
|
|
||||||
// ];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $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);
|
||||||
|
|
||||||
// $plants = Plant::all()->keyBy('id');
|
|
||||||
|
|
||||||
// $uniqueLineIds = ProductionQuantity::select('line_id')->distinct()->pluck('line_id');
|
|
||||||
|
|
||||||
// $allProduction = ProductionQuantity::select('line_id', \DB::raw('COUNT(*) as total_quantity'))
|
|
||||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
|
||||||
// ->groupBy('line_id')
|
|
||||||
// ->pluck('total_quantity', 'line_id')
|
|
||||||
// ->toArray();
|
|
||||||
|
|
||||||
// $tableData = [];
|
// $tableData = [];
|
||||||
// $no = 1;
|
// $no = 1;
|
||||||
|
|
||||||
// foreach ($plants as $plantId => $plant) {
|
// foreach ($plants as $plantId => $plant) {
|
||||||
// foreach ($uniqueLineIds as $lineId) {
|
// $plantLines = $lines->get($plantId, collect());
|
||||||
// if (!isset($lineMeta[$lineId]) || $lineMeta[$lineId]['plant_id'] != $plantId) {
|
// foreach ($plantLines as $line) {
|
||||||
// continue;
|
// $lineId = $line->id;
|
||||||
// }
|
// $lineName = $line->name;
|
||||||
|
|
||||||
// $lineInfo = $lineMeta[$lineId];
|
// $targetQuantity = ProductionPlan::where('plant_id', $plant)
|
||||||
// $lineName = $lineInfo['name'];
|
|
||||||
|
|
||||||
// $targetQuantity = \App\Models\ProductionPlan::where('plant_id', $plantId)
|
|
||||||
// ->where('line_id', $lineId)
|
// ->where('line_id', $lineId)
|
||||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||||
// ->sum('plan_quantity');
|
// ->sum('plan_quantity');
|
||||||
|
|
||||||
// $productionQuantity = $allProduction[$lineId] ?? 0;
|
// $productionQuantity = ProductionQuantity::where('plant_id', $plant)
|
||||||
|
// ->where('line_id', $lineId)
|
||||||
|
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||||
|
// ->count();
|
||||||
|
|
||||||
// $tableData[] = [
|
// $tableData[] = [
|
||||||
// 'no' => $no++,
|
// 'no' => $no++,
|
||||||
@@ -182,14 +82,86 @@ class SendProductionReport extends Command
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (!empty($filteredEmails)) {
|
// $this->table(
|
||||||
// $this->info('Production report sent to: ' . implode(', ', $filteredEmails));
|
// ['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'],
|
||||||
// foreach ($filteredEmails as $email) {
|
// $tableData
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (!empty($emails))
|
||||||
|
// {
|
||||||
|
// foreach ($emails as $email)
|
||||||
|
// {
|
||||||
// Mail::to($email)->send(new ProductionMail($tableData));
|
// Mail::to($email)->send(new ProductionMail($tableData));
|
||||||
// }
|
// }
|
||||||
// } else {
|
// }
|
||||||
// $this->info('No matching recipients for this minute.');
|
// else
|
||||||
|
// {
|
||||||
|
// $this->info('No recipients found for ProductionMailAlert.');
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$scheduleType = $this->argument('schedule_type');
|
||||||
|
$plantId = (int) $this->argument('plant'); // Only one plant
|
||||||
|
|
||||||
|
$mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
|
||||||
|
->where('rule_name', 'ProductionMail')
|
||||||
|
->where('plant', $plantId)
|
||||||
|
->where('schedule_type', $scheduleType)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$emails = $mailRules->pluck('email')->unique()->toArray();
|
||||||
|
|
||||||
|
$plant = Plant::find($plantId);
|
||||||
|
|
||||||
|
if (!$plant) {
|
||||||
|
$this->error("Invalid plant ID: $plantId");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines = Line::where('plant_id', $plantId)->get();
|
||||||
|
|
||||||
|
$startDate = now()->setTime(8, 0, 0);
|
||||||
|
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||||
|
|
||||||
|
$tableData = [];
|
||||||
|
$no = 1;
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$lineId = $line->id;
|
||||||
|
$lineName = $line->name;
|
||||||
|
|
||||||
|
$targetQuantity = ProductionPlan::where('plant_id', $plantId)
|
||||||
|
->where('line_id', $lineId)
|
||||||
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
|
->sum('plan_quantity');
|
||||||
|
|
||||||
|
$productionQuantity = ProductionQuantity::where('plant_id', $plantId)
|
||||||
|
->where('line_id', $lineId)
|
||||||
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$tableData[] = [
|
||||||
|
'no' => $no++,
|
||||||
|
'plant' => $plant->name,
|
||||||
|
'line' => $lineName,
|
||||||
|
'targetQuantity' => $targetQuantity,
|
||||||
|
'productionQuantity' => $productionQuantity,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// $this->table(
|
||||||
|
// ['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'],
|
||||||
|
// $tableData
|
||||||
|
// );
|
||||||
|
|
||||||
|
if (!empty($emails)) {
|
||||||
|
foreach ($emails as $email) {
|
||||||
|
Mail::to($email)->send(new ProductionMail($tableData));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->info('No recipients found for ProductionMailAlert.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ namespace App\Filament\Resources;
|
|||||||
use App\Filament\Resources\AlertMailRuleResource\Pages;
|
use App\Filament\Resources\AlertMailRuleResource\Pages;
|
||||||
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
|
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
|
||||||
use App\Models\AlertMailRule;
|
use App\Models\AlertMailRule;
|
||||||
|
use App\Models\Plant;
|
||||||
|
use Dotenv\Exception\ValidationException;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Components\Checkbox;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
@@ -14,6 +17,7 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
|
use Illuminate\Validation\ValidationException as ValidationValidationException;
|
||||||
|
|
||||||
class AlertMailRuleResource extends Resource
|
class AlertMailRuleResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -29,6 +33,13 @@ class AlertMailRuleResource extends Resource
|
|||||||
->schema([
|
->schema([
|
||||||
Section::make('')
|
Section::make('')
|
||||||
->schema([
|
->schema([
|
||||||
|
Forms\Components\Select::make('plant')
|
||||||
|
->label('Plant')
|
||||||
|
->reactive()
|
||||||
|
->options(fn () => Plant::pluck('name', 'id')->toArray())
|
||||||
|
->required(fn ($get) => ! $get('is_active'))
|
||||||
|
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
|
||||||
|
// ->options(fn () => Plant::pluck('id', 'name')->toArray()),
|
||||||
Forms\Components\Select::make('module')
|
Forms\Components\Select::make('module')
|
||||||
->label('Module')
|
->label('Module')
|
||||||
->required()
|
->required()
|
||||||
@@ -56,15 +67,29 @@ class AlertMailRuleResource extends Resource
|
|||||||
'Hourly' => 'Hourly',
|
'Hourly' => 'Hourly',
|
||||||
'Daily' => 'Daily',
|
'Daily' => 'Daily',
|
||||||
]),
|
]),
|
||||||
|
Checkbox::make('is_active')
|
||||||
|
->label('All Plants Reports')
|
||||||
|
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
|
||||||
|
->reactive(),
|
||||||
Forms\Components\Hidden::make('created_by')
|
Forms\Components\Hidden::make('created_by')
|
||||||
->default(fn () => Filament::auth()->user()?->name),
|
->default(fn () => Filament::auth()->user()?->name),
|
||||||
Forms\Components\Hidden::make('updated_by')
|
Forms\Components\Hidden::make('updated_by')
|
||||||
->default(fn () => Filament::auth()->user()?->name),
|
->default(fn () => Filament::auth()->user()?->name),
|
||||||
])
|
])
|
||||||
->columns(4),
|
->columns(5),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optionally, also override for update/editing
|
||||||
|
// public static function mutateFormDataBeforeSave(array $data): array
|
||||||
|
// {
|
||||||
|
// dd('test');
|
||||||
|
// if ($data['is_active']) {
|
||||||
|
// $data['plant'] = 'All Plants';
|
||||||
|
// }
|
||||||
|
// return $data;
|
||||||
|
// }
|
||||||
|
|
||||||
public static function table(Table $table): Table
|
public static function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
@@ -73,6 +98,16 @@ class AlertMailRuleResource extends Resource
|
|||||||
->label('ID')
|
->label('ID')
|
||||||
->numeric()
|
->numeric()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('plant')
|
||||||
|
->label('Plant')
|
||||||
|
->sortable()
|
||||||
|
->formatStateUsing(function ($state) {
|
||||||
|
static $plants;
|
||||||
|
if (! $plants) {
|
||||||
|
$plants = Plant::pluck('name', 'id')->toArray();
|
||||||
|
}
|
||||||
|
return $plants[$state] ?? 'All Plants';
|
||||||
|
}),
|
||||||
Tables\Columns\TextColumn::make('module')
|
Tables\Columns\TextColumn::make('module')
|
||||||
->label('Module')
|
->label('Module')
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|||||||
@@ -9,4 +9,14 @@ use Filament\Resources\Pages\CreateRecord;
|
|||||||
class CreateAlertMailRule extends CreateRecord
|
class CreateAlertMailRule extends CreateRecord
|
||||||
{
|
{
|
||||||
protected static string $resource = AlertMailRuleResource::class;
|
protected static string $resource = AlertMailRuleResource::class;
|
||||||
|
|
||||||
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($data['is_active']) {
|
||||||
|
$data['plant'] = '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,130 +12,29 @@ Artisan::command('inspire', function () {
|
|||||||
// Schedule::command('send:invoice-report');
|
// Schedule::command('send:invoice-report');
|
||||||
// Schedule::command('send:production-report');
|
// Schedule::command('send:production-report');
|
||||||
|
|
||||||
// $rules = [
|
|
||||||
// [
|
|
||||||
// 'module' => 'InvoiceValidation',
|
|
||||||
// 'rule_name' => 'InvoiceMail',
|
|
||||||
// 'argument' => 'InvoiceMail',
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'module' => 'InvoiceValidation',
|
|
||||||
// 'rule_name' => 'SerialInvoiceMail',
|
|
||||||
// 'argument' => 'SerialInvoiceMail',
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'module' => 'InvoiceValidation',
|
|
||||||
// 'rule_name' => 'MaterialInvoiceMail',
|
|
||||||
// 'argument' => 'MaterialInvoiceMail',
|
|
||||||
// ],
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// foreach ($rules as $rule) {
|
|
||||||
// $scheduleType = AlertMailRule::where('module', $rule['module'])
|
|
||||||
// ->where('rule_name', $rule['rule_name'])
|
|
||||||
// ->value('schedule_type');
|
|
||||||
|
|
||||||
// switch ($scheduleType) {
|
|
||||||
// case 'Live':
|
|
||||||
// Schedule::command("send:invoice-report {$rule['argument']}")->everyMinute();
|
|
||||||
// break;
|
|
||||||
// case 'Hourly':
|
|
||||||
// Schedule::command("send:invoice-report {$rule['argument']}")->hourly();
|
|
||||||
// break;
|
|
||||||
// case 'Daily':
|
|
||||||
// Schedule::command("send:invoice-report {$rule['argument']}")->dailyAt('07:59');
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// Schedule::command("send:invoice-report {$rule['argument']}")->hourly();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Production Report Scheduling
|
|
||||||
// $productionScheduleType = AlertMailRule::where('module', 'ProductionQuantities')
|
|
||||||
// ->where('rule_name', 'ProductionMail')
|
|
||||||
// ->value('schedule_type');
|
|
||||||
|
|
||||||
// // $this->info($productionScheduleType);
|
|
||||||
// // \Log::info('Production Schedule Type: ' . $productionScheduleType);
|
|
||||||
|
|
||||||
// switch ($productionScheduleType) {
|
|
||||||
// case 'Live':
|
|
||||||
// Schedule::command('send:production-report')->everyMinute();
|
|
||||||
// break;
|
|
||||||
// case 'Hourly':
|
|
||||||
// Schedule::command('send:production-report')->hourly();
|
|
||||||
// break;
|
|
||||||
// case 'Daily':
|
|
||||||
// Schedule::command('send:production-report')->dailyAt('07:59');
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// Schedule::command('send:production-report')->hourly();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// app()->booted(function () {
|
// app()->booted(function () {
|
||||||
// $schedule = app(Schedule::class);
|
// $schedule = app(Schedule::class);
|
||||||
|
|
||||||
// // Dynamic rules for invoice reports
|
// $productionRules = AlertMailRule::where('module', 'ProductionQuantities')
|
||||||
// $rules = [
|
|
||||||
// [
|
|
||||||
// 'module' => 'InvoiceValidation',
|
|
||||||
// 'rule_name' => 'InvoiceMail',
|
|
||||||
// 'argument' => 'InvoiceMail',
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'module' => 'InvoiceValidation',
|
|
||||||
// 'rule_name' => 'SerialInvoiceMail',
|
|
||||||
// 'argument' => 'SerialInvoiceMail',
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'module' => 'InvoiceValidation',
|
|
||||||
// 'rule_name' => 'MaterialInvoiceMail',
|
|
||||||
// 'argument' => 'MaterialInvoiceMail',
|
|
||||||
// ],
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// foreach ($rules as $rule) {
|
|
||||||
// $scheduleType = AlertMailRule::where('module', $rule['module'])
|
|
||||||
// ->where('rule_name', $rule['rule_name'])
|
|
||||||
// ->value('schedule_type');
|
|
||||||
|
|
||||||
// switch ($scheduleType) {
|
|
||||||
// case 'Live':
|
|
||||||
// $schedule->command("send:invoice-report {$rule['argument']}")->everyMinute();
|
|
||||||
// break;
|
|
||||||
// case 'Hourly':
|
|
||||||
// $schedule->command("send:invoice-report {$rule['argument']}")->hourly();
|
|
||||||
// break;
|
|
||||||
// case 'Daily':
|
|
||||||
// $schedule->command("send:invoice-report {$rule['argument']}")->dailyAt('07:59');
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// $schedule->command("send:invoice-report {$rule['argument']}")->hourly();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Production Report Scheduling
|
|
||||||
// $productionScheduleType = AlertMailRule::where('module', 'ProductionQuantities')
|
|
||||||
// ->where('rule_name', 'ProductionMail')
|
// ->where('rule_name', 'ProductionMail')
|
||||||
// ->value('schedule_type');
|
// ->get();
|
||||||
|
|
||||||
// switch ($productionScheduleType) {
|
// $types = $productionRules->pluck('schedule_type')->unique();
|
||||||
|
|
||||||
|
// foreach ($types as $type) {
|
||||||
|
// $command = $schedule->command("send:production-report", [$type]);
|
||||||
|
// switch ($type) {
|
||||||
// case 'Live':
|
// case 'Live':
|
||||||
// $schedule->command('send:production-report')->everyMinute();
|
// $command->everyMinute();
|
||||||
// break;
|
// break;
|
||||||
// case 'Hourly':
|
// case 'Hourly':
|
||||||
// $schedule->command('send:production-report')->hourly();
|
// $command->hourly();
|
||||||
// break;
|
// break;
|
||||||
// case 'Daily':
|
// case 'Daily':
|
||||||
// $schedule->command('send:production-report')->dailyAt('07:59');
|
// $command->dailyAt('07:59');
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// $schedule->command('send:production-report')->hourly();
|
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
app()->booted(function () {
|
app()->booted(function () {
|
||||||
@@ -145,10 +44,13 @@ app()->booted(function () {
|
|||||||
->where('rule_name', 'ProductionMail')
|
->where('rule_name', 'ProductionMail')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$types = $productionRules->pluck('schedule_type')->unique();
|
// Loop each mail rule individually (plant + schedule_type)
|
||||||
|
foreach ($productionRules as $rule) {
|
||||||
|
$type = $rule->schedule_type;
|
||||||
|
$plantId = $rule->plant;
|
||||||
|
|
||||||
|
$command = $schedule->command('send:production-report', [$type, $plantId]);
|
||||||
|
|
||||||
foreach ($types as $type) {
|
|
||||||
$command = $schedule->command("send:production-report", [$type]);
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'Live':
|
case 'Live':
|
||||||
$command->everyMinute();
|
$command->everyMinute();
|
||||||
@@ -163,3 +65,4 @@ app()->booted(function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user