Files
BE_CPONE/application/controllers/keu/Auto_on_hold_multi.php
2026-04-27 10:26:26 +07:00

118 lines
3.9 KiB
PHP

<?php
class Auto_on_hold_multi extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function log($msg)
{
$sdate = date("Y-m-d H:i:s");
echo "$sdate $msg\n";
}
function index()
{
$this->log("Starting Auto On Hold Multi Agreement. [without extend]");
$cur_date = date("Y-m-d");
$this->db->trans_begin();
$sql = "
select
distinct
M_MouID, M_MouName , M_CompanyName, M_MouNumber,
date_format(M_MouEndDate,'%d-%m-%Y') M_MouEndDate
from f_bill_issue
join f_bill on F_BillIssueF_BillID = F_BillID
and F_BillIsActive = 'Y'
join f_bill_mou on F_BillIssueF_BillID = F_BillMouF_BillID
join m_mou on M_MouID = F_BillMouM_MouID
and F_BillIssueIsAllMou = 'Y'
and M_MouIsActive = 'Y'
and F_BillIssueIsActive = 'Y'
and F_BillIssueIsReceive = 'Y'
and F_BillIssueIsLunas = 'N'
and (F_BillDueDate + interval 7 day )< ?
and F_BillIssueExtendDueDate is null
join m_company on M_MouM_CompanyID = M_CompanyID
";
$qry = $this->db->query($sql, [$cur_date]);
if (!$qry) {
$message =
$this->db->error()["message"] . "|" . $this->db->last_query();
$this->log($message);
$this->db->trans_rollback();
exit();
}
$rows = $qry->result_array();
$sql = "update m_mou set M_MouIsActive = 'H' where M_MouID = ?";
foreach ($rows as $r) {
$qry = $this->db->query($sql, [$r["M_MouID"]]);
$message = "Hold Mou [{$r["M_MouID"]}] {$r["M_MouNumber"]} | {$r["M_MouName"]} from {$r["M_CompanyName"]} yg berlaku s/d {$r["M_MouEndDate"]}";
if (!$qry) {
$message .=
"\n" .
str_repeat(" ", 20) .
" => Err : " .
$this->db->error()["message"];
} else {
$message .= "\n" . str_repeat(" ", 20) . " => OK";
}
$this->log($message);
}
$this->log("Starting Auto On Hold Multi Agreement. [with extend]");
$cur_date = date("Y-m-d");
$sql = "
select
distinct
M_MouID, M_MouName , M_CompanyName, M_MouNumber,
date_format(M_MouEndDate,'%d-%m-%Y') M_MouEndDate
from f_bill_issue
join f_bill on F_BillIssueF_BillID = F_BillID
and F_BillIsActive = 'Y'
join f_bill_mou on F_BillIssueF_BillID = F_BillMouF_BillID
join m_mou on M_MouID = F_BillMouM_MouID
and M_MouIsActive = 'Y'
and F_BillIssueIsActive = 'Y'
and F_BillIssueIsReceive = 'Y'
and F_BillIssueIsLunas = 'N'
and F_BillIssueIsAllMou = 'Y'
and F_BillIssueExtendDueDate is not null
and F_BillIssueExtendDueDate < ?
join m_company on M_MouM_CompanyID = M_CompanyID
";
$qry = $this->db->query($sql, [$cur_date]);
if (!$qry) {
$message =
$this->db->error()["message"] . "|" . $this->db->last_query();
$this->log($message);
$this->db->trans_rollback();
exit();
}
$rows = $qry->result_array();
$sql = "update m_mou set M_MouIsActive = 'H' where M_MouID = ?";
foreach ($rows as $r) {
$qry = $this->db->query($sql, [$r["M_MouID"]]);
$message = "Hold Mou [{$r["M_MouID"]}] {$r["M_MouNumber"]} | {$r["M_MouName"]} from {$r["M_CompanyName"]} yg berlaku s/d {$r["M_MouEndDate"]}";
if (!$qry) {
$message .=
"\n" .
str_repeat(" ", 20) .
" => Err : " .
$this->db->error()["message"];
} else {
$message .= "\n" . str_repeat(" ", 20) . " => OK";
}
$this->log($message);
}
if ($this->db->trans_status === false) {
$this->db->trans_rollback();
$this->log(
"End Auto On Hold Multi Agreement : Error DB transaction." .
$this->db->error()["message"]
);
} else {
$this->db->trans_commit();
$this->log("End Auto On Hold Multi Agreement : OK");
}
}
}