Rapport-Laravel/app/Console/Commands/SendNeblogisticEmail.php

119 lines
4.6 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use App\Mail\NeblogisticAbm;
use App\Mail\Neblogistic;
class SendNeblogisticEmail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
//protected $signature = 'neblogistic:send-email {id : The ID of the neblogistic record}';
protected $signature = 'neblogistic:send-email';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send neblogistic ABM email for a specific record by ID';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$records = DB::table('neblogistic')
->where('email_sent', 0)
->where('status', 'Requested')
//->whereRaw('CAST(no_of_nebulizer AS UNSIGNED) <= 5')
->whereNotNull('submission_id')
->where('id', '>', 202910)
->orderBy('created_at', 'asc')
->limit(5)
->get();
// $records = DB::table('neblogistic')
// ->whereIn('emp_id', ['169626', '163474', '149440'])
// ->where('updated_at', '>', '2025-09-17')
// ->where('status', 'Requested')
// ->get();
foreach ($records as $record) {
//print_r($record);exit;
$this->sendEmail($record);
}
}
protected function sendEmail($record) {
$post = [
'emp_id' => $record->emp_id,
'user_id' => $record->user_id,
'hierarchy_id' => $record->hierarchy_id,
'employee_name' => $record->emp_name,
'employee_phone' => $record->emp_phone,
'employee_email' => $record->emp_email,
'abm_name' => $record->abm_name,
'abm_email' => $record->abm_email,
'rbm_name' => $record->rbm_name,
'msl_code' => $record->msl_code,
'form_submit_type' => $record->form_submit_type,
'dr_name' => $record->doctor_name,
'doctor_name' => $record->doctor_name,
'doctor_mobile_number' => $record->doctor_phone,
'speciality' => $record->doctor_speciality,
'for_what_purpose_nebulisers_will_be_used_by_dr' => $record->nebulizer_purpose,
'type_of_nebuliser' => $record->type_of_nebulizer,
'no_of_nebulizer' => $record->no_of_nebulizer,
'value_of_the_parcel' => $record->value_of_parcel,
'address_type' => $record->address_type,
'building_name' => $record->address_building,
'address_line_1' => $record->address_line_1,
'address_line_2' => $record->address_line_2,
'state' => $record->address_state,
'city' => $record->address_city,
'pin_code' => $record->address_pin_code,
'clinic_hospital_home_name' => $record->clinic_hospital_name,
'status' => $record->status,
'team' => $record->team,
'depot_id' => $record->depot_id,
'depot_name' => $record->depot_name,
'old_employee_code' => $record->old_employee_code,
'remarks' => $record->remarks,
'paramedic_alternate_contact_number' => $record->paramedic_alternate_contact_number,
'request_letter' => $record->request_letter ?? '',
'created_at' => $record->created_at,
'updated_at' => $record->updated_at,
'id' => $record->id,
'submission_id' => $record->submission_id,
'form_id' => '1750914801-153443b9-94d0-4dcb-b3f3-4fa11588a0a9',
'partition' => 'rapport-team3'
];
$this->info("Doctor: ". print_r($record, true));
try {
Mail::to($record->abm_email)->cc('ravigulhane1983@gmail.com')->send(new NeblogisticAbm($post));
DB::table('neblogistic')->where('id', $record->id)->update(['email_sent' => 1]);
Mail::to($record->emp_email)->cc('ravigulhane1983@gmail.com')->send(new Neblogistic($post));
$this->info("Email sent successfully to {$record->abm_email} for record ID {$record->id}");
$this->info("Doctor: {$record->doctor_name}");
$this->info("Status: {$record->status}");
} catch (\Exception $e) {
DB::table('neblogistic')->where('id', $record->id)->update(['email_sent' => 2]);
$this->error("Failed to send email for record ID {$record->id}: " . $e->getMessage());
}
}
}