Add sendTime control for preregister email
This commit is contained in:
@@ -292,6 +292,67 @@ class SendEmailPreregister extends MY_Controller
|
||||
{
|
||||
try {
|
||||
$data_send_patients = [];
|
||||
$sendTime = '20:00:00';
|
||||
|
||||
$sql_notif_config = "SELECT
|
||||
Email_ConfigNofificationTemplate,
|
||||
Email_ConfigNofificationSender,
|
||||
Email_ConfigNofificationSendTime
|
||||
FROM email_config_nofification
|
||||
WHERE Email_ConfigNofificationIsActive = 'Y'
|
||||
ORDER BY Email_ConfigNofificationID DESC
|
||||
LIMIT 1";
|
||||
$que_notif_config = $this->db->query($sql_notif_config);
|
||||
if (!$que_notif_config || $que_notif_config->num_rows() == 0) {
|
||||
throw new Exception('[Error] failed get notif email template config');
|
||||
}
|
||||
$notifConfig = $que_notif_config->row_array();
|
||||
$templateBody = $notifConfig['Email_ConfigNofificationTemplate'];
|
||||
if (!empty($notifConfig['Email_ConfigNofificationSendTime'])) {
|
||||
$sendTime = $notifConfig['Email_ConfigNofificationSendTime'];
|
||||
}
|
||||
|
||||
$nowTime = date('H:i:s');
|
||||
if ($nowTime < $sendTime) {
|
||||
$this->sys_ok([
|
||||
"message" => "skip queue, current time before send time",
|
||||
"current_time" => $nowTime,
|
||||
"send_time" => $sendTime,
|
||||
"total_email_queued" => 0
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$targetDate = date('Y-m-d', strtotime('+1 day'));
|
||||
$sql_mcu_sync = "SELECT Mgm_McuID
|
||||
FROM mgm_mcu
|
||||
WHERE Mgm_McuIsActive = 'Y'";
|
||||
$que_mcu_sync = $this->db->query($sql_mcu_sync);
|
||||
if (!$que_mcu_sync) {
|
||||
throw new Exception('[Error] failed get mcu list for dashboard sync');
|
||||
}
|
||||
$mcuRows = $que_mcu_sync->result_array();
|
||||
foreach ($mcuRows as $mcuRow) {
|
||||
$mcuIDSync = isset($mcuRow['Mgm_McuID']) ? intval($mcuRow['Mgm_McuID']) : 0;
|
||||
if ($mcuIDSync <= 0) {
|
||||
continue;
|
||||
}
|
||||
$que_sync = $this->db->query(
|
||||
"CALL cpone.sp_refresh_mcu_participant_daily_by_mcu_date(?, ?)",
|
||||
[$mcuIDSync, $targetDate]
|
||||
);
|
||||
if (!$que_sync) {
|
||||
throw new Exception('[Error] failed sync dashboard participant daily');
|
||||
}
|
||||
if (isset($this->db->conn_id) && $this->db->conn_id instanceof mysqli) {
|
||||
while ($this->db->conn_id->more_results() && $this->db->conn_id->next_result()) {
|
||||
$dummyResult = $this->db->conn_id->store_result();
|
||||
if ($dummyResult instanceof mysqli_result) {
|
||||
$dummyResult->free();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql_patients = "SELECT
|
||||
pp.Mcu_PreregisterPatientsID AS preregister_id,
|
||||
@@ -325,20 +386,6 @@ class SendEmailPreregister extends MY_Controller
|
||||
}
|
||||
$data_send_patients = $que_patients->result_array();
|
||||
|
||||
$sql_notif_config = "SELECT
|
||||
Email_ConfigNofificationTemplate,
|
||||
Email_ConfigNofificationSender
|
||||
FROM email_config_nofification
|
||||
WHERE Email_ConfigNofificationIsActive = 'Y'
|
||||
ORDER BY Email_ConfigNofificationID DESC
|
||||
LIMIT 1";
|
||||
$que_notif_config = $this->db->query($sql_notif_config);
|
||||
if (!$que_notif_config || $que_notif_config->num_rows() == 0) {
|
||||
throw new Exception('[Error] failed get notif email template config');
|
||||
}
|
||||
$notifConfig = $que_notif_config->row_array();
|
||||
$templateBody = $notifConfig['Email_ConfigNofificationTemplate'];
|
||||
|
||||
$this->db->trans_begin();
|
||||
foreach ($data_send_patients as $patient) {
|
||||
$sql_config_email = "SELECT * FROM m_emailconfig WHERE M_EmailConfigType = 'R'";
|
||||
|
||||
Reference in New Issue
Block a user