2 Commits

Author SHA1 Message Date
f633285a57 Merge pull request 'Changed logic for to mail and cc mail for production report' (#148) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Reviewed-on: #148
2026-01-03 09:12:44 +00:00
dhanabalan
6acdfc30fa Changed logic for to mail and cc mail for production report
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 9s
Gemini PR Review / review (pull_request) Failing after 1m2s
Laravel Larastan / larastan (pull_request) Failing after 3m9s
Laravel Pint / pint (pull_request) Successful in 2m34s
2026-01-03 14:42:33 +05:30

View File

@@ -2,15 +2,13 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Models\InvoiceValidation;
use App\Models\Plant;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use App\Mail\ProductionMail; use App\Mail\ProductionMail;
use App\Models\Line; use App\Models\Line;
use App\Models\Plant;
use App\Models\ProductionPlan; use App\Models\ProductionPlan;
use App\Models\ProductionQuantity; use App\Models\ProductionQuantity;
use DB; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
class SendProductionReport extends Command class SendProductionReport extends Command
{ {
@@ -19,7 +17,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} {plant}'; protected $signature = 'send:production-report {schedule_type} {plant}';
/** /**
@@ -32,11 +30,10 @@ class SendProductionReport extends Command
/** /**
* Execute the console command. * Execute the console command.
*/ */
public function handle() public function handle()
{ {
ini_set('max_execution_time', 0); // disable limit // ini_set('max_execution_time', 0); // disable limit
set_time_limit(0); // set_time_limit(0);
$scheduleType = $this->argument('schedule_type'); $scheduleType = $this->argument('schedule_type');
$plantId = (int) $this->argument('plant'); // cast to int for safety $plantId = (int) $this->argument('plant'); // cast to int for safety
@@ -55,33 +52,30 @@ class SendProductionReport extends Command
: Plant::where('id', $plantId)->get(); : Plant::where('id', $plantId)->get();
if ($plants->isEmpty()) { if ($plants->isEmpty()) {
$this->error("No valid plant(s) found."); $this->error('No valid plant(s) found.');
return; return;
} }
// $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);
if (strtolower($scheduleType) == 'daily') if (strtolower($scheduleType) == '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);
} }
$PlanstartDate = now()->setTime(8, 0, 0); $PlanstartDate = now()->subDay()->setTime(8, 0, 0);
$planendDate = now()->copy()->addDay()->setTime(7, 59, 0); $planendDate = now()->setTime(7, 59, 0);
$tableData = []; $tableData = [];
$no = 1; $no = 1;
//. // .
foreach ($plants as $plant) foreach ($plants as $plant) {
{
$lines = Line::where('plant_id', $plant->id)->get(); $lines = Line::where('plant_id', $plant->id)->get();
foreach ($lines as $line) { foreach ($lines as $line) {
@@ -90,6 +84,7 @@ class SendProductionReport extends Command
->whereBetween('created_at', [$PlanstartDate, $planendDate]) ->whereBetween('created_at', [$PlanstartDate, $planendDate])
->sum('plan_quantity'); ->sum('plan_quantity');
/** @phpstan-ignore property.notFound */
if (strtolower($line->type) == 'fg line') { if (strtolower($line->type) == 'fg line') {
$productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id) $productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
->where('line_id', $line->id) ->where('line_id', $line->id)
@@ -113,9 +108,7 @@ class SendProductionReport extends Command
} }
} }
// $this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $fgTableData);
//$this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $fgTableData);
// $this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $tableData); // $this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $tableData);
@@ -128,7 +121,7 @@ class SendProductionReport extends Command
// } // }
// $this->info("Production report sent to " . count($emails) . " recipient(s)."); // $this->info("Production report sent to " . count($emails) . " recipient(s).");
// Preview in console // Preview in console
$mail = new ProductionMail($scheduleType, $tableData); $mail = new ProductionMail($scheduleType, $tableData);
$contentVars = $mail->content()->with; $contentVars = $mail->content()->with;
@@ -140,13 +133,39 @@ class SendProductionReport extends Command
$this->info($contentVars['wishes'] ?? ''); $this->info($contentVars['wishes'] ?? '');
// Send mails // Send mails
if (!empty($emails)) { // if (! empty($emails)) {
foreach ($emails as $email) { // foreach ($emails as $email) {
Mail::to($email)->send(new ProductionMail($scheduleType, $tableData)); // Mail::to($email)->send(new ProductionMail($scheduleType, $tableData));
// }
// $this->info('Production report sent to '.count($emails).' recipient(s).');
// } else {
// $this->warn('No recipients found for ProductionMailAlert.');
// }
foreach ($mailRules 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;
} }
$this->info("Production report sent to " . count($emails) . " recipient(s).");
} else { \Mail::to($toEmails)->cc($ccEmails)->send($mail);
$this->warn('No recipients found for ProductionMailAlert.');
$this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : ''));
} }
} }
} }