116 lines
3.7 KiB
PHP
116 lines
3.7 KiB
PHP
<?php
|
|
class Auto_on_hold 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 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 m_mou on M_MouID = F_BillIssueM_MouID
|
|
and F_BillIssueIsAllMou = 'N'
|
|
and M_MouIsActive = 'Y'
|
|
and F_BillIssueIsActive = 'Y'
|
|
and F_BillIssueIsLunas = 'N'
|
|
and F_BillIssueIsReceive = 'Y'
|
|
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 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 m_mou on M_MouID = F_BillIssueM_MouID
|
|
and M_MouIsActive = 'Y'
|
|
and F_BillIssueIsActive = 'Y'
|
|
and F_BillIssueIsReceive = 'Y'
|
|
and F_BillIssueIsLunas = 'N'
|
|
and F_BillIssueIsAllMou = 'N'
|
|
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 Agreement : Error DB transaction." .
|
|
$this->db->error()["message"]
|
|
);
|
|
} else {
|
|
$this->db->trans_commit();
|
|
$this->log("End Auto On Hold Agreement : OK");
|
|
}
|
|
}
|
|
}
|