Initial import
This commit is contained in:
373
application/controllers/keu/Ais.php
Normal file
373
application/controllers/keu/Ais.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
class Ais extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Resultentry API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$this->load->helper(array('form', 'url'));
|
||||
}
|
||||
|
||||
function get_branchs(){
|
||||
$sql = "SELECT M_BranchCode as branch_code, M_BranchName as branch_name FROM m_branch WHERE M_BranchIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
$rows = $query->result_array();
|
||||
$this->sys_ok($rows);
|
||||
exit;
|
||||
}
|
||||
|
||||
function get_corporates(){
|
||||
$prm = $this->sys_input;
|
||||
|
||||
if(isset($prm['search'])){
|
||||
$search = $prm['search'];
|
||||
}else{
|
||||
$search = '';
|
||||
}
|
||||
if($prm['current_page']){
|
||||
$current_page = intval($prm['current_page']);
|
||||
}else{
|
||||
$current_page = 1;
|
||||
}
|
||||
if($prm['limit']){
|
||||
$limit = intval($prm['limit']);
|
||||
}else{
|
||||
$limit = 100;
|
||||
}
|
||||
|
||||
$offset = ($current_page - 1) * $limit;
|
||||
|
||||
$total = 0;
|
||||
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM corporate
|
||||
WHERE CorporateIsActive = 'Y' AND
|
||||
(
|
||||
CorporateName LIKE CONCAT('%',?,'%') OR
|
||||
CorporateCode LIKE CONCAT('%',?,'%')
|
||||
)";
|
||||
$query = $this->db_onedev->query($sql, array(
|
||||
$search,
|
||||
$search));
|
||||
if(!$query){
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$c_rows = $query->result_array();
|
||||
$total = $c_rows[0]['total'];
|
||||
|
||||
|
||||
$sql = "SELECT
|
||||
CorporateID as corporate_id,
|
||||
CorporateCode as corporate_code,
|
||||
CorporateName as corporate_name
|
||||
FROM corporate
|
||||
WHERE CorporateIsActive = 'Y' AND
|
||||
(
|
||||
CorporateName LIKE CONCAT('%',?,'%') OR
|
||||
CorporateCode LIKE CONCAT('%',?,'%')
|
||||
)
|
||||
|
||||
ORDER BY CorporateName ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
$query = $this->db_onedev->query($sql, array(
|
||||
$search,
|
||||
$search,
|
||||
$limit,
|
||||
$offset));
|
||||
if(!$query){
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => $total,
|
||||
"current_page" => $current_page,
|
||||
"limit" => $limit,
|
||||
"offset" => $offset,
|
||||
"total_page" => ceil($total / $limit),
|
||||
"data" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function get_mcus(){
|
||||
$prm = $this->sys_input;
|
||||
$start_date = $prm['start_date'];
|
||||
$end_date = $prm['end_date'];
|
||||
$branch_code = isset($prm['branch_code']) ? $prm['branch_code'] : null;
|
||||
$corporate_code = isset($prm['corporate_code']) ? $prm['corporate_code'] : null;
|
||||
$limit = intval($prm['limit']);
|
||||
$current_page = intval($prm['current_page']);
|
||||
$offset = ($current_page - 1) * $limit;
|
||||
|
||||
if(isset($prm['search'])){
|
||||
$search = $prm['search'];
|
||||
}else{
|
||||
$search = '';
|
||||
}
|
||||
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM mgm_mcu
|
||||
JOIN m_branch ON Mgm_McuM_BranchID = M_BranchID
|
||||
JOIN corporate ON Mgm_McuCorporateID = CorporateID
|
||||
WHERE Mgm_McuIsActive = 'Y' AND
|
||||
(
|
||||
Mgm_McuNumber LIKE CONCAT('%',?,'%') OR
|
||||
Mgm_McuLabel LIKE CONCAT('%',?,'%')
|
||||
) AND
|
||||
(M_BranchCode = ? OR ? IS NULL) AND
|
||||
(CorporateCode = ? OR ? IS NULL) AND
|
||||
date(Mgm_McuStartDate) between ? and ? AND
|
||||
date(Mgm_McuEndDate) between ? and ?";
|
||||
$query = $this->db_onedev->query($sql, array(
|
||||
$search,
|
||||
$search,
|
||||
$branch_code,
|
||||
$branch_code,
|
||||
$corporate_code,
|
||||
$corporate_code,
|
||||
$start_date,
|
||||
$end_date,
|
||||
$start_date,
|
||||
$end_date));
|
||||
if(!$query){
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$c_rows = $query->result_array();
|
||||
$total = $c_rows[0]['total'];
|
||||
|
||||
$sql = "SELECT
|
||||
Mgm_McuID as mcu_id,
|
||||
Mgm_McuNumber as mcu_number,
|
||||
Mgm_McuLabel as mcu_label,
|
||||
M_BranchCode as branch_code,
|
||||
M_BranchName as branch_name,
|
||||
CorporateCode as corporate_code,
|
||||
CorporateName as corporate_name
|
||||
FROM mgm_mcu
|
||||
JOIN m_branch ON Mgm_McuM_BranchID = M_BranchID
|
||||
JOIN corporate ON Mgm_McuCorporateID = CorporateID
|
||||
WHERE Mgm_McuIsActive = 'Y' AND
|
||||
(
|
||||
Mgm_McuNumber LIKE CONCAT('%',?,'%') OR
|
||||
Mgm_McuLabel LIKE CONCAT('%',?,'%')
|
||||
) AND
|
||||
(M_BranchCode = ? OR ? IS NULL) AND
|
||||
(CorporateCode = ? OR ? IS NULL) AND
|
||||
( `Mgm_McuStartDate` >= ? AND `Mgm_McuEndDate` <= ?)
|
||||
ORDER BY Mgm_McuNumber ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
$query = $this->db_onedev->query($sql, array(
|
||||
$search,
|
||||
$search,
|
||||
$branch_code,
|
||||
$branch_code,
|
||||
$corporate_code,
|
||||
$corporate_code,
|
||||
$start_date,
|
||||
$end_date,
|
||||
$limit,
|
||||
$offset));
|
||||
|
||||
if(!$query){
|
||||
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"total" => $total,
|
||||
"current_page" => $current_page,
|
||||
"limit" => $limit,
|
||||
"offset" => $offset,
|
||||
"total_page" => ceil($total / $limit),
|
||||
"data" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function get_data(){
|
||||
$prm = $this->sys_input;
|
||||
|
||||
if(isset($prm['start_date'])){
|
||||
$start_date = $prm['start_date'];
|
||||
}else{
|
||||
$start_date = null;
|
||||
}
|
||||
|
||||
if(isset($prm['end_date'])){
|
||||
$end_date = $prm['end_date'];
|
||||
}else{
|
||||
$end_date = null;
|
||||
}
|
||||
|
||||
if(isset($prm['branch_code'])){
|
||||
$branch_code = $prm['branch_code'];
|
||||
}else{
|
||||
$branch_code = null;
|
||||
}
|
||||
|
||||
if(isset($prm['mcu_number'])){
|
||||
$mcu_number = $prm['mcu_number'];
|
||||
}
|
||||
else{
|
||||
$mcu_number = null;
|
||||
}
|
||||
|
||||
if(isset($prm['corporate_code'])){
|
||||
$corporate_code = $prm['corporate_code'];
|
||||
}else{
|
||||
$corporate_code = null;
|
||||
}
|
||||
|
||||
if(isset($prm['limit'])){
|
||||
$limit = intval($prm['limit']);
|
||||
}else{
|
||||
$limit = 500;
|
||||
}
|
||||
|
||||
if(isset($prm['current_page'])){
|
||||
$current_page = intval($prm['current_page']);
|
||||
}else{
|
||||
$current_page = 1;
|
||||
}
|
||||
|
||||
|
||||
$offset = ($current_page - 1) * $limit;
|
||||
|
||||
|
||||
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM (
|
||||
SELECT T_OrderHeaderID
|
||||
FROM t_orderheader
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
||||
JOIN m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
||||
JOIN corporate on T_OrderHeaderCorporateID = CorporateID
|
||||
JOIN m_branch on T_OrderHeaderM_BranchID = M_BranchID
|
||||
JOIN mgm_mcu on T_OrderHeaderMgm_McuID = Mgm_McuID
|
||||
|
||||
WHERE T_OrderHeaderIsActive = 'Y'
|
||||
AND date(T_OrderHeaderDate) between ? and ?
|
||||
AND (M_BranchCode = ? OR ? IS NULL)
|
||||
AND (Mgm_McuNumber = ? OR ? IS NULL)
|
||||
AND (CorporateCode = ? OR ? IS NULL)
|
||||
group by T_OrderHeaderID
|
||||
) as t
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array(
|
||||
$start_date,
|
||||
$end_date,
|
||||
$branch_code,
|
||||
$branch_code,
|
||||
$mcu_number,
|
||||
$mcu_number,
|
||||
$corporate_code,
|
||||
$corporate_code));
|
||||
if(!$query){
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
$total = $rows[0]['total'];
|
||||
$result = array();
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderID as order_id,
|
||||
T_OrderHeaderDate as order_date,
|
||||
T_OrderHeaderLabNumber as order_lab_number,
|
||||
concat(IF(M_TitleName IS NULL, '',CONCAT(M_TitleName,'. ')), M_PatientName) as patient_name,
|
||||
T_OrderHeaderTotal as order_total,
|
||||
CorporateID as corporate_id,
|
||||
CorporateCode as corporate_code,
|
||||
CorporateName as corporate_name,
|
||||
Mgm_McuID as mcu_id,
|
||||
Mgm_McuLabel as mcu_label,
|
||||
Mgm_McuNumber as mcu_number,
|
||||
M_BranchCode as branch_code,
|
||||
M_BranchName as branch_name,
|
||||
T_OrderHeaderTotal as order_total,
|
||||
IFNULL(F_PaymentTotal, 0) as payment_total,
|
||||
IFNULL(F_PaymentNumber, '-') as payment_number,
|
||||
IF(T_OrderHeaderTotal - IFNULL(F_PaymentTotal, 0) > 0, 'Belum Bayar', 'Lunas') as payment_status,
|
||||
'' as details
|
||||
FROM t_orderheader
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
||||
JOIN m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
||||
JOIN corporate on T_OrderHeaderCorporateID = CorporateID
|
||||
JOIN m_branch on T_OrderHeaderM_BranchID = M_BranchID
|
||||
JOIN mgm_mcu on T_OrderHeaderMgm_McuID = Mgm_McuID
|
||||
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
WHERE T_OrderHeaderIsActive = 'Y'
|
||||
AND date(T_OrderHeaderDate) between ? and ?
|
||||
AND (M_BranchCode = ? OR ? IS NULL)
|
||||
AND (Mgm_McuNumber = ? OR ? IS NULL)
|
||||
AND (CorporateCode = ? OR ? IS NULL)
|
||||
group by T_OrderHeaderID
|
||||
limit ? offset ?";
|
||||
$query = $this->db_onedev->query($sql, array(
|
||||
$start_date,
|
||||
$end_date,
|
||||
$branch_code,
|
||||
$branch_code,
|
||||
$mcu_number,
|
||||
$mcu_number,
|
||||
$corporate_code,
|
||||
$corporate_code,
|
||||
$limit, $offset));
|
||||
//echo $this->db_onedev->last_query();
|
||||
if(!$query){
|
||||
$message = $this->db_onedev->error();
|
||||
//$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
|
||||
if(count($rows) > 0){
|
||||
foreach($rows as $key => $row){
|
||||
$sql = "SELECT
|
||||
T_TestName as test_name,
|
||||
T_TestCode as test_code_cpone,
|
||||
IFNULL(Nat_TestMapCode,'') as test_code_lis,
|
||||
T_OrderDetailPrice as test_price,
|
||||
T_OrderDetailDisc as test_disc,
|
||||
T_OrderDetailDiscAmount as test_disc_amount,
|
||||
T_OrderDetailDiscTotal as test_disc_total,
|
||||
T_OrderDetailTotal as test_total
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsPrice = 'Y'
|
||||
LEFT JOIN nat_testmap ON Nat_TestMapNat_TestID = T_TestNat_TestID
|
||||
WHERE T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql, array($row['order_id']));
|
||||
$rows_detail = $query->result_array();
|
||||
$rows[$key]['details'] = $rows_detail;
|
||||
}
|
||||
}
|
||||
$result = array(
|
||||
"total" => $total,
|
||||
"current_page" => $current_page,
|
||||
"limit" => $limit,
|
||||
"offset" => $offset,
|
||||
"total_page" => ceil($total / $limit),
|
||||
"data" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
1902
application/controllers/keu/Auto_count.php
Normal file
1902
application/controllers/keu/Auto_count.php
Normal file
File diff suppressed because it is too large
Load Diff
1680
application/controllers/keu/Auto_count2024.php
Normal file
1680
application/controllers/keu/Auto_count2024.php
Normal file
File diff suppressed because it is too large
Load Diff
1900
application/controllers/keu/Auto_count2532024.php
Normal file
1900
application/controllers/keu/Auto_count2532024.php
Normal file
File diff suppressed because it is too large
Load Diff
1520
application/controllers/keu/Auto_countV2.php
Normal file
1520
application/controllers/keu/Auto_countV2.php
Normal file
File diff suppressed because it is too large
Load Diff
1550
application/controllers/keu/Auto_count_bkp.php
Normal file
1550
application/controllers/keu/Auto_count_bkp.php
Normal file
File diff suppressed because it is too large
Load Diff
115
application/controllers/keu/Auto_on_hold.php
Normal file
115
application/controllers/keu/Auto_on_hold.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?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");
|
||||
}
|
||||
}
|
||||
}
|
||||
117
application/controllers/keu/Auto_on_hold_multi.php
Normal file
117
application/controllers/keu/Auto_on_hold_multi.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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");
|
||||
}
|
||||
}
|
||||
}
|
||||
371
application/controllers/keu/Auto_on_hold_titip.php
Normal file
371
application/controllers/keu/Auto_on_hold_titip.php
Normal file
@@ -0,0 +1,371 @@
|
||||
<?php
|
||||
class Auto_on_hold_titip extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function R_status($branch_code, $cur_date = "")
|
||||
{
|
||||
if ($cur_date == "") {
|
||||
$cur_date = date("Y-m-d");
|
||||
}
|
||||
list($regionalID, $titipBranchCode) = $this->get_branch();
|
||||
//glondongan
|
||||
$sql = "select
|
||||
distinct
|
||||
? pusatBranchCode,
|
||||
F_BillIssuePusatID,
|
||||
f_bill_titip_detail.M_MouID M_MouID, F_BillIssuePusatDueDate as HoldDate,
|
||||
f_bill_titip.M_BranchID, f_bill_titip.M_BranchCode,
|
||||
f_bill_titip.F_BillID,
|
||||
F_BillIssuePusatDueDate, F_BillIssuePusatRefNumber
|
||||
from f_bill_issue_pusat
|
||||
join f_bill_issue_pusat_detail on F_BillIssuePusatID = F_BillIssuePusatDetailF_BillIssuePusatID
|
||||
and F_BillIssuePusatIsActive = 'Y'
|
||||
and F_BillIssuePusatDetailIsActive = 'Y'
|
||||
and F_BillIssuePusatIsLunas = 'N'
|
||||
and F_BillIssuePusatIsReceive = 'Y'
|
||||
and (F_BillIssuePusatDueDate + interval 7 day ) < ?
|
||||
join f_bill_titip on F_BillIssuePusatDetailF_BillID = F_BillID
|
||||
and f_bill_titip.M_BranchID = F_BillIssuePusatDetailM_BranchID
|
||||
and f_bill_titip.M_BranchCode = ?
|
||||
join f_bill_titip_detail on F_BillID = F_BillDetailF_BillID
|
||||
and f_bill_titip_detail.M_BranchID = f_bill_titip.M_BranchID";
|
||||
// per cabang
|
||||
// $sql = "select
|
||||
// distinct
|
||||
// ? pusatBranchCode,
|
||||
// F_BillIssuePusatID,
|
||||
// f_bill_titip_detail.M_MouID M_MouID, F_BillIssuePusatDueDate as HoldDate,
|
||||
// f_bill_titip.M_BranchID, f_bill_titip.M_BranchCode,
|
||||
// f_bill_titip.F_BillID,
|
||||
// F_BillIssuePusatDueDate
|
||||
// from f_bill_issue_pusat
|
||||
// join f_bill_issue_pusat_detail on F_BillIssuePusatID = F_BillIssuePusatDetailF_BillIssuePusatID
|
||||
// and F_BillIssuePusatIsActive = 'Y'
|
||||
// and F_BillIssuePusatDetailIsActive = 'Y'
|
||||
// and F_BillIssuePusatIsReceive = 'Y'
|
||||
// and (F_BillIssuePusatDueDate + interval 7 day ) < ?
|
||||
// join f_bill_titip on F_BillIssuePusatDetailF_BillID = F_BillID
|
||||
// and f_bill_titip.M_BranchID = F_BillIssuePusatDetailM_BranchID
|
||||
// and f_bill_titip.F_BillIsLunas = 'N'
|
||||
// and f_bill_titip.M_BranchCode = ?
|
||||
// join f_bill_titip_detail on F_BillID = F_BillDetailF_BillID
|
||||
// and f_bill_titip_detail.M_BranchID = f_bill_titip.M_BranchID";
|
||||
$qry = $this->db->query($sql, [
|
||||
$titipBranchCode,
|
||||
$cur_date,
|
||||
$branch_code,
|
||||
]);
|
||||
if (!$qry) {
|
||||
$message =
|
||||
$this->db->error()["message"] . "|" . $this->db->last_query();
|
||||
echo json_encode(["status" => "ERR", "message" => $message]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
echo json_encode(["status" => "OK", "data" => $rows]);
|
||||
}
|
||||
|
||||
function log($msg)
|
||||
{
|
||||
$sdate = date("Y-m-d H:i:s");
|
||||
echo "$sdate $msg\n";
|
||||
}
|
||||
function get_branch()
|
||||
{
|
||||
$sql =
|
||||
"select M_BranchS_RegionalID,M_BranchCode from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return [false, $this->db->error()["message"]];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return ["ERR", "No Default Branch"];
|
||||
}
|
||||
return [$rows[0]["M_BranchS_RegionalID"], $rows[0]["M_BranchCode"]];
|
||||
}
|
||||
function url_branches($regionalID, $branchCode)
|
||||
{
|
||||
$sql = "select M_BranchCode,M_BranchIpAddress,M_BranchName
|
||||
from m_branch where M_BranchS_RegionalID = ? and M_BranchIsActive = 'Y' ";
|
||||
$qry = $this->db->query($sql, [$regionalID]);
|
||||
|
||||
if (!$qry) {
|
||||
return [false, $this->db->error()["message"]];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$url = [];
|
||||
foreach ($rows as $r) {
|
||||
$url[] = [
|
||||
"url" =>
|
||||
"http://" .
|
||||
$r["M_BranchIpAddress"] .
|
||||
"/one-api/keu/auto_on_hold_titip/r_status/" .
|
||||
$branchCode,
|
||||
"name" => $r["M_BranchName"],
|
||||
];
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
function check_table() {
|
||||
$sql = "select count(MouHoldStatusRefNumber) from mou_hold_status";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$sql = "alter table mou_hold_status add MouHoldStatusRefNumber varchar(50)";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->log("Error Alter mou_hold_status");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
function index()
|
||||
{
|
||||
$this->check_table();
|
||||
$this->log("Starting Auto On Hold Titip Agreement. [without extend]");
|
||||
list($regionalID, $branchCode) = $this->get_branch();
|
||||
if (!$regionalID) {
|
||||
$this->log("Error No Default Branch");
|
||||
exit();
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$urls = $this->url_branches($regionalID, $branchCode);
|
||||
$mou_ids = "-1";
|
||||
|
||||
$url_update = [];
|
||||
foreach ($urls as $u) {
|
||||
$url = $u["url"];
|
||||
$name = $u["name"];
|
||||
$this->log("Check Auto On Hold from $name : $url");
|
||||
$resp = $this->get($url);
|
||||
if ($resp["status"] == "ERR") {
|
||||
$this->log("\t Error : " . $resp["message"]);
|
||||
continue;
|
||||
}
|
||||
if (count($resp["data"]) > 0) {
|
||||
$x_url = str_ireplace("r_status", "r_hold", $url);
|
||||
$url_update[$x_url] = $resp["data"];
|
||||
}
|
||||
foreach ($resp["data"] as $d) {
|
||||
$mou_ids .= "," . $d["M_MouID"];
|
||||
}
|
||||
}
|
||||
if ($mou_ids == "-1") {
|
||||
$this->log("No Auto On Hold Titipan");
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$sql = "select M_MouID,M_MouName,M_MouNumber from m_mou
|
||||
where M_MouID in ($mou_ids) and M_MouIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->log("Error : " . $this->db->error()["message"]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->log("No Active Mou from [ $mou_ids]");
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$mou_ids = "-1";
|
||||
$mou_number = "";
|
||||
foreach ($rows as $r) {
|
||||
$mou_ids .= "," . $r["M_MouID"];
|
||||
if ($mou_number != "") {
|
||||
$mou_number .= ", ";
|
||||
}
|
||||
$mou_number .= $r["M_MouNumber"];
|
||||
}
|
||||
$this->db->query(
|
||||
"update m_mou set M_MouIsActive = 'H' where M_MouID in ($mou_ids)"
|
||||
);
|
||||
if (!$qry) {
|
||||
$this->log("Error : " . $this->db->error()["message"]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
/*
|
||||
drop table if exists mou_hold_status;
|
||||
create table mou_hold_status(
|
||||
MouHoldStatusID int not null auto_increment primary key,
|
||||
MouHoldStatusM_MouID int ,
|
||||
MouHoldStatusTargetUrl varchar(300),
|
||||
MouHoldStatusHoldDate datetime,
|
||||
MouHoldStatusSendDate datetime,
|
||||
MouHoldStatusIsSent varchar(1) default 'N',
|
||||
key(MouHoldStatusM_MouID),
|
||||
key(MouHoldStatusIsSent)
|
||||
);
|
||||
*/
|
||||
$sql = "insert into mou_hold_status(
|
||||
MouHoldStatusTargetUrl,
|
||||
MouHoldStatusM_MouID,
|
||||
MouHoldStatusF_BillID,
|
||||
MouHoldStatusPusatBranchCode,
|
||||
MouHoldStatusDueDate,
|
||||
MouHoldStatusRefNumber,
|
||||
MouHoldStatusHoldDate
|
||||
)
|
||||
values(?,?,?, ?,?,?, now())
|
||||
";
|
||||
foreach ($url_update as $url => $v) {
|
||||
foreach ($v as $d) {
|
||||
$mouID = $d["M_MouID"];
|
||||
$fBillID = $d["F_BillID"];
|
||||
$pusatBranchCode = $d["pusatBranchCode"];
|
||||
$dueDate = $d["F_BillIssuePusatDueDate"];
|
||||
$refNumber = $d["F_BillIssuePusatRefNumber"];
|
||||
$qry = $this->db->query($sql, [
|
||||
$url,
|
||||
$mouID,
|
||||
$fBillID,
|
||||
$pusatBranchCode,
|
||||
$dueDate,
|
||||
$refNumber
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->log("Error : " . $this->db->error()["message"]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->log("Done : " . $mou_number . " already hold.");
|
||||
$this->db->trans_commit();
|
||||
// upload_hold_status
|
||||
$this->upload_hold_status();
|
||||
}
|
||||
function upload_hold_status()
|
||||
{
|
||||
$this->log("Starting Update On Hold Titip Status");
|
||||
$this->db->trans_begin();
|
||||
//Update Mou hold titip
|
||||
$sql = "select MouHoldStatusTargetUrl,
|
||||
group_concat(MouHoldStatusID) ids,
|
||||
group_concat(MouHoldStatusM_MouID) mou,
|
||||
group_concat(MouHoldStatusHoldDate) date
|
||||
from mou_hold_status
|
||||
where MouHoldStatusIsSent = 'N'
|
||||
group by MouHoldStatusTargetUrl";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->log("Error : " . $this->db->error()["message"]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->log(" No Pending Upload Mou Hold Titip Status.");
|
||||
exit();
|
||||
}
|
||||
foreach ($rows as $r) {
|
||||
$param = ["mou" => $r["mou"], "date" => $r["date"]];
|
||||
$jparam = json_encode($param);
|
||||
$url = $r["MouHoldStatusTargetUrl"];
|
||||
$resp = $this->post($url, $jparam);
|
||||
$jresp = json_decode($resp, true);
|
||||
if (isset($jresp["status"]) && $jresp["status"] == "OK") {
|
||||
$ids = $r["ids"];
|
||||
$qry = $this->db->query("update mou_hold_status
|
||||
set MouHoldStatusIsSent = 'Y' ,
|
||||
MouHoldStatusSendDate = now()
|
||||
where MouHoldStatusID in ($ids)");
|
||||
if (!$qry) {
|
||||
$this->log("Error : " . $this->db->error()["message"]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$this->db->trans_begin();
|
||||
} else {
|
||||
$this->log("Error : Mou Hold Titip Status. $resp");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
$this->log("Starting Update On Hold Titip Status [DONE]");
|
||||
}
|
||||
function R_hold($branchCode)
|
||||
{
|
||||
/*
|
||||
drop table if exists mou_hold_titip;
|
||||
create table mou_hold_titip (
|
||||
MouHoldTitipID int auto_increment primary key,
|
||||
MouHoldTitipM_BranchCode varchar(2),
|
||||
MouHoldTitipDate datetime,
|
||||
MouHoldTitipM_MouID int,
|
||||
key(MouHOldTitipM_BranchCode),
|
||||
key(MouHOldTitipDate),
|
||||
key(MouHoldTitipM_MouID)
|
||||
);
|
||||
*/
|
||||
$param = $this->sys_input;
|
||||
$mou = $param["mou"];
|
||||
$date = $param["date"];
|
||||
$mouids = explode(",", $mou);
|
||||
$dates = explode(",", $date);
|
||||
$sql = "insert into mou_hold_titip(MouHoldTitipM_BranchCode,
|
||||
MouHoldTitipM_MouID, MouHoldTitipDate)
|
||||
values(?,?,?)";
|
||||
foreach ($mouids as $idx => $mouID) {
|
||||
$date = $dates[$idx];
|
||||
$qry = $this->db->query($sql, [$branchCode, $mouID, $date]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => $this->db->error()["message"],
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
echo json_encode([
|
||||
"status" => "OK",
|
||||
"message" => "",
|
||||
]);
|
||||
}
|
||||
public function post($url, $data)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/text",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
|
||||
if (curl_error($ch) != "") {
|
||||
return "ERROR Updating Hold : " . curl_error($ch) . "\n";
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
function get($url, $timeout = 60, $c_timeout = 5)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
return ["status" => "ERR", "message" => $err_msg];
|
||||
}
|
||||
$jresult = json_decode($result, true);
|
||||
if (json_last_error() != 0) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "Invalid JSON : " . $result,
|
||||
];
|
||||
}
|
||||
return $jresult;
|
||||
}
|
||||
}
|
||||
604
application/controllers/keu/Email_on_hold.php
Normal file
604
application/controllers/keu/Email_on_hold.php
Normal file
@@ -0,0 +1,604 @@
|
||||
<?php
|
||||
|
||||
class Email_on_hold extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->response = [
|
||||
"status" => "ERR",
|
||||
"message" => "",
|
||||
];
|
||||
}
|
||||
public function reply()
|
||||
{
|
||||
echo json_encode($this->response);
|
||||
exit();
|
||||
}
|
||||
public function get_config()
|
||||
{
|
||||
$sql = "select *
|
||||
from conf_on_hold
|
||||
where ConfOnHoldIsActive = 'Y'
|
||||
limit 0,1";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get Config On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->response["message"] =
|
||||
"Error Get Config On Hold Email | Configuration On Hold not found!";
|
||||
$this->reply();
|
||||
}
|
||||
$config = $rows[0];
|
||||
$sql = "select M_CityName
|
||||
from m_branch
|
||||
join m_city on M_BranchM_CityID = M_CityID
|
||||
where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get City Branch | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->response["message"] = "Error Get City Branch not found!";
|
||||
$this->reply();
|
||||
}
|
||||
$config["M_CityName"] = $rows[0]["M_CityName"];
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function compose_email($reminder, $config, $r)
|
||||
{
|
||||
$tpl = $config["ConfOnHoldTemplateHtml"];
|
||||
if ($reminder == 2) {
|
||||
$tpl = $config["ConfOnHoldTemplateHtml02"];
|
||||
}
|
||||
if ($reminder == 3) {
|
||||
$tpl = $config["ConfOnHoldTemplateHtml03"];
|
||||
}
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_NAME}}",
|
||||
$config["ConfOnHoldSenderName"],
|
||||
$tpl
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_TITLE}}",
|
||||
$config["ConfOnHoldSenderTitle"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_TITLE_EN}}",
|
||||
$config["ConfOnHoldSenderTitleEng"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_CITY}}",
|
||||
$config["M_CityName"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_DATE}}",
|
||||
date("d M Y"),
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_NUMBER}}",
|
||||
$r["F_BillIssueRefNumber"] . "/RE/01",
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{PIC_NAME}}",
|
||||
$r["F_BillIssuePIC"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_NAME}}",
|
||||
$r["M_CompanyName"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_ADDRESS}}",
|
||||
$r["M_CompanyAddress"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_CITY}}",
|
||||
$r["M_CityName"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$periode =
|
||||
$this->xdate($r["StartOrderDate"]) .
|
||||
" - " .
|
||||
$this->xdate($r["EndOrderDate"]);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_PERIODE}}",
|
||||
$periode,
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_DUEDATE}}",
|
||||
$this->xdate($r["DueDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
$inv_amount =
|
||||
"<b>Rp " .
|
||||
number_format(intVal($r["TotalAmount"]), 0, ".", ",") .
|
||||
",-<b>";
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_AMOUNT}}",
|
||||
$inv_amount,
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_NUMBER}}",
|
||||
$r["F_BillIssueRefNumber"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_ID}}",
|
||||
$r["Terbilang_id"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_EN}}",
|
||||
$r["Terbilang_en"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_EN}}",
|
||||
$r["Terbilang_en"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_ATTACHMENT}}",
|
||||
$r["F_BillIssueImg"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_REMINDERDATE}}",
|
||||
$this->xdate($r["ReminderDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_FINALDATE}}",
|
||||
$this->xdate($r["OnHoldDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_ATTACHMENT_SEND}}",
|
||||
$r["F_BillIssueImgSend"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_RECEIVEDATE}}",
|
||||
$this->xdate($r["F_BillIssueReceiveDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
return $emailMessage;
|
||||
}
|
||||
//TODO:
|
||||
public function first_reminder()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
$sql = "select
|
||||
F_BillIssueID,
|
||||
F_BillNo,
|
||||
F_BillIssueNumber,
|
||||
F_BillIssueRefNumber,
|
||||
F_BillIssueDate,
|
||||
F_BillIssueReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
sum(F_BillDetailTotal) TotalAmount,
|
||||
F_BillDueDate DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePIC,
|
||||
F_BillIssueImg,
|
||||
F_BillIssuePICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today ,
|
||||
fn_IntegerToWords(sum(F_BillDetailTotal)) Terbilang_en,
|
||||
f_terbilang(sum(F_BillDetailTotal)) Terbilang_id,
|
||||
F_BillDueDate + interval 7 day as OnHoldDate,
|
||||
F_BillDueDate - interval 7 day as ReminderDate
|
||||
from
|
||||
f_bill_issue
|
||||
join f_bill on F_BillIssueF_BillID = F_BillID
|
||||
and F_BillIsActive = 'Y'
|
||||
and F_BillIssueIsAllMou = 'N'
|
||||
join f_bill_detail on F_BillIssueF_BillID = F_BillDetailF_BillID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join t_orderheader on F_BillDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
join m_company on M_CompanyID = F_BillIssueM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join m_mou on F_BillIssueM_MouID = M_MouID and M_MouM_BillTypeID <> 1
|
||||
left join keu_reminder
|
||||
on F_BillIssueID = KeuReminderF_BillIssueID
|
||||
and KeuReminderType = '01'
|
||||
where
|
||||
F_BillIssueIsActive = 'Y'
|
||||
and F_BillIssueIsLunas = 'N'
|
||||
and F_BillIssueIsReceive = 'Y'
|
||||
and ( F_BillDueDate - interval 7 DAY) = date(now())
|
||||
and F_BillIssueExtendDueDate is null
|
||||
group by F_BillIssueID
|
||||
";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
if ($r["today"] == "Y" && $r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($r["F_BillIssuePICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(1, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssueImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssueImg"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssueID"],
|
||||
$r["F_BillIssuePICEmail"]
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
public function xdate($str)
|
||||
{
|
||||
return date("d M Y", strtotime($str));
|
||||
}
|
||||
//TODO:
|
||||
public function second_reminder()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
$sql = "select
|
||||
F_BillIssueID,
|
||||
F_BillNo,
|
||||
F_BillIssueNumber,
|
||||
F_BillIssueRefNumber,
|
||||
F_BillIssueDate,
|
||||
F_BillIssueReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
sum(F_BillDetailTotal) TotalAmount,
|
||||
F_BillDueDate DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePIC,
|
||||
F_BillIssueImg,
|
||||
F_BillIssuePICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today,
|
||||
fn_IntegerToWords(sum(F_BillDetailTotal)) Terbilang_en,
|
||||
f_terbilang(sum(F_BillDetailTotal)) Terbilang_id,
|
||||
F_BillDueDate + interval 7 day as OnHoldDate,
|
||||
F_BillDueDate - interval 7 day as ReminderDate
|
||||
from
|
||||
f_bill_issue
|
||||
join f_bill on F_BillIssueF_BillID = F_BillID
|
||||
and F_BillIsActive = 'Y'
|
||||
and F_BillIssueIsAllMou = 'N'
|
||||
join f_bill_detail on F_BillIssueF_BillID = F_BillDetailF_BillID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join t_orderheader on F_BillDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
join m_company on M_CompanyID = F_BillIssueM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join m_mou on F_BillIssueM_MouID = M_MouID and M_MouM_BillTypeID <> 1
|
||||
left join keu_reminder
|
||||
on F_BillIssueID = KeuReminderF_BillIssueID
|
||||
and KeuReminderType = '02'
|
||||
where
|
||||
F_BillIssueIsActive = 'Y'
|
||||
and F_BillIssueIsLunas = 'N'
|
||||
and F_BillIssueIsReceive = 'Y'
|
||||
and F_BillDueDate = date(now())
|
||||
and F_BillIssueExtendDueDate is null
|
||||
group by F_BillIssueID
|
||||
";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
if ($r["today"] == "Y" && $r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($r["F_BillIssuePICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(2, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssueImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssueImg"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssueID"],
|
||||
$r["F_BillIssuePICEmail"],
|
||||
"02"
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
//TODO:
|
||||
public function tagihan_awal()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
$sql = "select
|
||||
F_BillIssueID,
|
||||
F_BillNo,
|
||||
F_BillIssueNumber,
|
||||
F_BillIssueRefNumber,
|
||||
F_BillIssueDate,
|
||||
F_BillIssueReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
sum(F_BillDetailTotal) TotalAmount,
|
||||
F_BillDueDate DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePIC,
|
||||
F_BillIssueImg,
|
||||
F_BillIssuePICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today,
|
||||
fn_IntegerToWords(sum(F_BillDetailTotal)) Terbilang_en,
|
||||
f_terbilang(sum(F_BillDetailTotal)) Terbilang_id,
|
||||
F_BillDueDate + interval 7 day as OnHoldDate,
|
||||
F_BillDueDate - interval 7 day as ReminderDate,
|
||||
F_BillIssueImgSend,
|
||||
F_BillIssueReceiveDate
|
||||
from
|
||||
f_bill_issue
|
||||
join f_bill on F_BillIssueF_BillID = F_BillID
|
||||
and F_BillIsActive = 'Y'
|
||||
and F_BillIssueIsAllMou = 'N'
|
||||
join f_bill_detail on F_BillIssueF_BillID = F_BillDetailF_BillID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join t_orderheader on F_BillDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
join m_company on M_CompanyID = F_BillIssueM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join m_mou on F_BillIssueM_MouID = M_MouID and M_MouM_BillTypeID <> 1
|
||||
left join keu_reminder
|
||||
on F_BillIssueID = KeuReminderF_BillIssueID
|
||||
and KeuReminderType = '03'
|
||||
where
|
||||
F_BillIssueIsActive = 'Y'
|
||||
and F_BillIssueIsNotif = 'Y'
|
||||
group by F_BillIssueID
|
||||
";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["F_BillIssuePICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(3, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssueImgSend"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssueImgSend"];
|
||||
}
|
||||
if ($r["F_BillIssueImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssueImg"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssueID"],
|
||||
$r["F_BillIssuePICEmail"],
|
||||
"03"
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function log()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$sql = "update keu_reminder
|
||||
set KeuReminderStatus =? ,
|
||||
KeuReminderNote = ? ,
|
||||
KeuReminderSendDate = now()
|
||||
where KeuReminderID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$prm["status"],
|
||||
$prm["note"],
|
||||
$prm["id"],
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Log Keu Reminder | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["query"] = $this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function log_awal()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$sql = "update f_bill_issue
|
||||
set F_BillIssueIsNotif= ?
|
||||
where F_BillIssueID = ? ";
|
||||
$qry = $this->db->query($sql, [$prm["status"], $prm["id"]]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Log Keu Reminder | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["query"] = $this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function create_log($billIssueID, $email, $type = "01")
|
||||
{
|
||||
$sql = "select KeuReminderID
|
||||
from keu_reminder
|
||||
where KeuReminderF_BillIssueID=? and KeuReminderStatus = 'N'
|
||||
and KeuReminderType=?";
|
||||
$qry = $this->db->query($sql, [$billIssueID, $type]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Check Log Keu Reminder $type | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$total = 0;
|
||||
if (count($rows) > 0) {
|
||||
return $rows[0]["KeuReminderID"];
|
||||
}
|
||||
$sql = "insert into keu_reminder (KeuReminderF_BillIssueID, KeuReminderEmail,
|
||||
KeuReminderStatus, KeuReminderNote,KeuReminderType)
|
||||
values (?,?,'N','New Request',?)";
|
||||
$qry = $this->db->query($sql, [$billIssueID, $email, $type]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Create Log Keu Reminder | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
}
|
||||
607
application/controllers/keu/Email_on_hold_multi.php
Normal file
607
application/controllers/keu/Email_on_hold_multi.php
Normal file
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
|
||||
class Email_on_hold_multi extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->response = [
|
||||
"status" => "ERR",
|
||||
"message" => "",
|
||||
];
|
||||
}
|
||||
public function reply()
|
||||
{
|
||||
echo json_encode($this->response);
|
||||
exit();
|
||||
}
|
||||
public function get_config()
|
||||
{
|
||||
$sql = "select *
|
||||
from conf_on_hold
|
||||
where ConfOnHoldIsActive = 'Y'
|
||||
limit 0,1";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get Config On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->response["message"] =
|
||||
"Error Get Config On Hold Email | Configuration On Hold not found!";
|
||||
$this->reply();
|
||||
}
|
||||
$config = $rows[0];
|
||||
$sql = "select M_CityName
|
||||
from m_branch
|
||||
join m_city on M_BranchM_CityID = M_CityID
|
||||
where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get City Branch | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->response["message"] = "Error Get City Branch not found!";
|
||||
$this->reply();
|
||||
}
|
||||
$config["M_CityName"] = $rows[0]["M_CityName"];
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function compose_email($reminder, $config, $r)
|
||||
{
|
||||
$tpl = $config["ConfOnHoldTemplateHtml"];
|
||||
if ($reminder == 2) {
|
||||
$tpl = $config["ConfOnHoldTemplateHtml02"];
|
||||
}
|
||||
if ($reminder == 3) {
|
||||
$tpl = $config["ConfOnHoldTemplateHtml03"];
|
||||
}
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_NAME}}",
|
||||
$config["ConfOnHoldSenderName"],
|
||||
$tpl
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_TITLE}}",
|
||||
$config["ConfOnHoldSenderTitle"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_TITLE_EN}}",
|
||||
$config["ConfOnHoldSenderTitleEng"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_CITY}}",
|
||||
$config["M_CityName"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_DATE}}",
|
||||
date("d M Y"),
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_NUMBER}}",
|
||||
$r["F_BillIssueRefNumber"] . "/RE/01",
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{PIC_NAME}}",
|
||||
$r["F_BillIssuePIC"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_NAME}}",
|
||||
$r["M_CompanyName"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_ADDRESS}}",
|
||||
$r["M_CompanyAddress"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_CITY}}",
|
||||
$r["M_CityName"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$periode =
|
||||
$this->xdate($r["StartOrderDate"]) .
|
||||
" - " .
|
||||
$this->xdate($r["EndOrderDate"]);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_PERIODE}}",
|
||||
$periode,
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_DUEDATE}}",
|
||||
$this->xdate($r["DueDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
$inv_amount =
|
||||
"<b>Rp " .
|
||||
number_format(intVal($r["TotalAmount"]), 0, ".", ",") .
|
||||
",-<b>";
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_AMOUNT}}",
|
||||
$inv_amount,
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_NUMBER}}",
|
||||
$r["F_BillIssueRefNumber"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_ID}}",
|
||||
$r["Terbilang_id"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_EN}}",
|
||||
$r["Terbilang_en"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_EN}}",
|
||||
$r["Terbilang_en"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_ATTACHMENT}}",
|
||||
$r["F_BillIssueImg"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_REMINDERDATE}}",
|
||||
$this->xdate($r["ReminderDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_FINALDATE}}",
|
||||
$this->xdate($r["OnHoldDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_ATTACHMENT_SEND}}",
|
||||
$r["F_BillIssueImgSend"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_RECEIVEDATE}}",
|
||||
$this->xdate($r["F_BillIssueReceiveDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
return $emailMessage;
|
||||
}
|
||||
//TODO:
|
||||
public function first_reminder()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
$sql = "select
|
||||
F_BillIssueID,
|
||||
F_BillNo,
|
||||
F_BillIssueNumber,
|
||||
F_BillIssueRefNumber,
|
||||
F_BillIssueDate,
|
||||
F_BillIssueReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
(F_BillTotal) TotalAmount,
|
||||
F_BillDueDate DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePIC,
|
||||
F_BillIssueImg,
|
||||
F_BillIssuePICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today ,
|
||||
fn_IntegerToWords((F_BillTotal)) Terbilang_en,
|
||||
f_terbilang((F_BillTotal)) Terbilang_id,
|
||||
F_BillDueDate + interval 7 day as OnHoldDate,
|
||||
F_BillDueDate - interval 7 day as ReminderDate
|
||||
from
|
||||
f_bill_issue
|
||||
join f_bill on F_BillIssueF_BillID = F_BillID
|
||||
and F_BillIsActive = 'Y'
|
||||
and F_BillIssueIsAllMou = 'Y'
|
||||
join f_bill_detail on F_BillIssueF_BillID = F_BillDetailF_BillID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join t_orderheader on F_BillDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
join m_company on M_CompanyID = F_BillIssueM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join m_mou on F_BillIssueM_MouID = M_MouID and M_MouM_BillTypeID <> 1
|
||||
left join keu_reminder
|
||||
on F_BillIssueID = KeuReminderF_BillIssueID
|
||||
and KeuReminderType = '01'
|
||||
where
|
||||
F_BillIssueIsActive = 'Y'
|
||||
and F_BillIssueIsLunas = 'N'
|
||||
and F_BillIssueIsReceive = 'Y'
|
||||
and F_BillDueDate - interval 7 DAY = date(now())
|
||||
and F_BillIssueExtendDueDate is null
|
||||
group by F_BillIssueID
|
||||
";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
if ($r["today"] == "Y" && $r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($r["F_BillIssuePICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(1, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssueImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssueImg"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssueID"],
|
||||
$r["F_BillIssuePICEmail"]
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
public function xdate($str)
|
||||
{
|
||||
return date("d M Y", strtotime($str));
|
||||
}
|
||||
//TODO:
|
||||
public function second_reminder()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
$sql = "select
|
||||
F_BillIssueID,
|
||||
F_BillNo,
|
||||
F_BillIssueNumber,
|
||||
F_BillIssueRefNumber,
|
||||
F_BillIssueDate,
|
||||
F_BillIssueReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
(F_BillTotal) TotalAmount,
|
||||
date(F_BillIssueReceiveDate + interval F_BillIssueAgingDay day) DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePIC,
|
||||
F_BillIssueImg,
|
||||
F_BillIssuePICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today,
|
||||
fn_IntegerToWords((F_BillTotal)) Terbilang_en,
|
||||
f_terbilang((F_BillTotal)) Terbilang_id,
|
||||
F_BillDueDate + interval 7 day as OnHoldDate,
|
||||
F_BillDueDate - interval 7 day as ReminderDate
|
||||
from
|
||||
f_bill_issue
|
||||
join f_bill on F_BillIssueF_BillID = F_BillID
|
||||
and F_BillIsActive = 'Y'
|
||||
and F_BillIssueIsAllMou = 'Y'
|
||||
join f_bill_detail on F_BillIssueF_BillID = F_BillDetailF_BillID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join t_orderheader on F_BillDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
join m_company on M_CompanyID = F_BillIssueM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join f_bill_mou on F_BillID = F_BillMouF_BillID
|
||||
and F_BillMouIsActive = 'Y'
|
||||
join m_mou on F_BillMouM_MouID = M_MouID
|
||||
and M_MouM_BillTypeID <> 1
|
||||
left join keu_reminder
|
||||
on F_BillIssueID = KeuReminderF_BillIssueID
|
||||
and KeuReminderType = '02'
|
||||
where
|
||||
F_BillIssueIsActive = 'Y'
|
||||
and F_BillIssueIsLunas = 'N'
|
||||
and F_BillIssueIsReceive = 'Y'
|
||||
and F_BillDueDate = date(now())
|
||||
and F_BillIssueExtendDueDate is null
|
||||
group by F_BillIssueID
|
||||
";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
if ($r["today"] == "Y" && $r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($r["F_BillIssuePICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(2, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssueImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssueImg"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssueID"],
|
||||
$r["F_BillIssuePICEmail"],
|
||||
"02"
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
//TODO:
|
||||
public function tagihan_awal()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
$sql = "select
|
||||
F_BillIssueID,
|
||||
F_BillNo,
|
||||
F_BillIssueNumber,
|
||||
F_BillIssueRefNumber,
|
||||
F_BillIssueDate,
|
||||
F_BillIssueReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
(F_BillTotal) TotalAmount,
|
||||
F_BillDueDate DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePIC,
|
||||
F_BillIssueImg,
|
||||
F_BillIssuePICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today,
|
||||
fn_IntegerToWords((F_BillTotal)) Terbilang_en,
|
||||
f_terbilang((F_BillTotal)) Terbilang_id,
|
||||
F_BillIssueReceiveDate + interval (F_BillIssueAgingDay + 7 ) day as OnHoldDate,
|
||||
F_BillIssueReceiveDate + interval (F_BillIssueAgingDay - 7 ) day as ReminderDate,
|
||||
F_BillIssueImgSend,
|
||||
F_BillIssueReceiveDate
|
||||
from
|
||||
f_bill_issue
|
||||
join f_bill on F_BillIssueF_BillID = F_BillID
|
||||
and F_BillIsActive = 'Y'
|
||||
and F_BillIssueIsAllMou = 'Y'
|
||||
join f_bill_detail on F_BillIssueF_BillID = F_BillDetailF_BillID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join t_orderheader on F_BillDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
join m_company on M_CompanyID = F_BillIssueM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join m_mou on F_BillIssueM_MouID = M_MouID and M_MouM_BillTypeID <> 1
|
||||
left join keu_reminder
|
||||
on F_BillIssueID = KeuReminderF_BillIssueID
|
||||
and KeuReminderType = '03'
|
||||
where
|
||||
F_BillIssueIsActive = 'Y'
|
||||
and F_BillIssueIsNotif = 'Y'
|
||||
group by F_BillIssueID
|
||||
";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["F_BillIssuePICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(3, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssueImgSend"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssueImgSend"];
|
||||
}
|
||||
if ($r["F_BillIssueImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssueImg"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssueID"],
|
||||
$r["F_BillIssuePICEmail"],
|
||||
"03"
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssueID" => $r["F_BillIssueID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function log()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$sql = "update keu_reminder
|
||||
set KeuReminderStatus =? ,
|
||||
KeuReminderNote = ? ,
|
||||
KeuReminderSendDate = now()
|
||||
where KeuReminderID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$prm["status"],
|
||||
$prm["note"],
|
||||
$prm["id"],
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Log Keu Reminder | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["query"] = $this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function log_awal()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$sql = "update f_bill_issue
|
||||
set F_BillIssueIsNotif= ?
|
||||
where F_BillIssueID = ? ";
|
||||
$qry = $this->db->query($sql, [$prm["status"], $prm["id"]]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Log Keu Reminder | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["query"] = $this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function create_log($billIssueID, $email, $type = "01")
|
||||
{
|
||||
$sql = "select KeuReminderID
|
||||
from keu_reminder
|
||||
where KeuReminderF_BillIssueID=? and KeuReminderStatus = 'N'
|
||||
and KeuReminderType=?";
|
||||
$qry = $this->db->query($sql, [$billIssueID, $type]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Check Log Keu Reminder $type | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$total = 0;
|
||||
if (count($rows) > 0) {
|
||||
return $rows[0]["KeuReminderID"];
|
||||
}
|
||||
$sql = "insert into keu_reminder (KeuReminderF_BillIssueID, KeuReminderEmail,
|
||||
KeuReminderStatus, KeuReminderNote,KeuReminderType)
|
||||
values (?,?,'N','New Request',?)";
|
||||
$qry = $this->db->query($sql, [$billIssueID, $email, $type]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Create Log Keu Reminder | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
}
|
||||
610
application/controllers/keu/Email_on_hold_titipan.php
Normal file
610
application/controllers/keu/Email_on_hold_titipan.php
Normal file
@@ -0,0 +1,610 @@
|
||||
<?php
|
||||
class Email_on_hold_titipan extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->response = [
|
||||
"status" => "ERR",
|
||||
"message" => "",
|
||||
];
|
||||
}
|
||||
public function reply()
|
||||
{
|
||||
echo json_encode($this->response);
|
||||
exit();
|
||||
}
|
||||
public function get_config()
|
||||
{
|
||||
$sql = "select *
|
||||
from conf_on_hold
|
||||
where ConfOnHoldIsActive = 'Y'
|
||||
limit 0,1";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get Config On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->response["message"] =
|
||||
"Error Get Config On Hold Email | Configuration On Hold not found!";
|
||||
$this->reply();
|
||||
}
|
||||
$config = $rows[0];
|
||||
$sql = "select M_CityName
|
||||
from m_branch
|
||||
join m_city on M_BranchM_CityID = M_CityID
|
||||
where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get City Branch | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
$this->response["message"] = "Error Get City Branch not found!";
|
||||
$this->reply();
|
||||
}
|
||||
$config["M_CityName"] = $rows[0]["M_CityName"];
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function compose_email($reminder, $config, $r)
|
||||
{
|
||||
$tpl = $config["ConfOnHoldTemplateHtml"];
|
||||
if ($reminder == 2) {
|
||||
$tpl = $config["ConfOnHoldTemplateHtml02"];
|
||||
}
|
||||
if ($reminder == 3) {
|
||||
$tpl = $config["ConfOnHoldTemplateHtml03"];
|
||||
}
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_NAME}}",
|
||||
$config["ConfOnHoldSenderName"],
|
||||
$tpl
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_TITLE}}",
|
||||
$config["ConfOnHoldSenderTitle"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{SENDER_TITLE_EN}}",
|
||||
$config["ConfOnHoldSenderTitleEng"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_CITY}}",
|
||||
$config["M_CityName"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_DATE}}",
|
||||
date("d M Y"),
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_NUMBER}}",
|
||||
$r["F_BillIssuePusatRefNumber"] . "/RE/01",
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{PIC_NAME}}",
|
||||
$r["F_BillIssuePusatPIC"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_NAME}}",
|
||||
$r["M_CompanyName"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_ADDRESS}}",
|
||||
$r["M_CompanyAddress"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{COMPANY_CITY}}",
|
||||
$r["M_CityName"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$periode =
|
||||
$this->xdate($r["StartOrderDate"]) .
|
||||
" - " .
|
||||
$this->xdate($r["EndOrderDate"]);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_PERIODE}}",
|
||||
$periode,
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_DUEDATE}}",
|
||||
$this->xdate($r["DueDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
$inv_amount =
|
||||
"<b>Rp " .
|
||||
number_format(intVal($r["TotalAmount"]), 0, ".", ",") .
|
||||
",-<b>";
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_AMOUNT}}",
|
||||
$inv_amount,
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_NUMBER}}",
|
||||
$r["F_BillIssuePusatRefNumber"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_ID}}",
|
||||
$r["Terbilang_id"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_EN}}",
|
||||
$r["Terbilang_en"],
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_ALPHABET_EN}}",
|
||||
$r["Terbilang_en"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_ATTACHMENT}}",
|
||||
$r["F_BillIssuePusatImg"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_REMINDERDATE}}",
|
||||
$this->xdate($r["ReminderDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_FINALDATE}}",
|
||||
$this->xdate($r["OnHoldDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{LETTER_ATTACHMENT_SEND}}",
|
||||
$r["F_BillIssuePusatImgSend"],
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
$emailMessage = str_replace(
|
||||
"{{INVOICE_RECEIVEDATE}}",
|
||||
$this->xdate($r["F_BillIssuePusatReceiveDate"]),
|
||||
$emailMessage
|
||||
);
|
||||
|
||||
return $emailMessage;
|
||||
}
|
||||
|
||||
public function tagihan_awal()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
$sql = "select
|
||||
F_BillIssuePusatID,
|
||||
F_BillNo,
|
||||
F_BillIssuePusatNumber,
|
||||
F_BillIssuePusatRefNumber,
|
||||
F_BillIssuePusatDate,
|
||||
F_BillIssuePusatReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
sum(F_BillDetailTotal) TotalAmount,
|
||||
F_BillIssuePusatDueDate DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePusatPIC,
|
||||
F_BillIssuePusatImg,
|
||||
F_BillIssuePusatImgSend,
|
||||
F_BillIssuePusatPICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today ,
|
||||
fn_IntegerToWords(sum(F_BillDetailTotal)) Terbilang_en,
|
||||
f_terbilang(sum(F_BillDetailTotal)) Terbilang_id,
|
||||
F_BillIssuePusatDueDate + interval 7 day as OnHoldDate,
|
||||
F_BillIssuePusatDueDate - interval 7 day as ReminderDate
|
||||
from
|
||||
f_bill_issue_pusat
|
||||
join f_bill_issue_pusat_detail on F_BillIssuePusatID = F_BillIssuePusatDetailF_BillIssuePusatID
|
||||
and F_BillIssuePusatDetailIsActive = 'Y'
|
||||
and F_BillIssuePusatIsActive = 'Y'
|
||||
join f_bill_titip on F_BillIssuePusatDetailF_BillID = F_BillID
|
||||
and f_bill_titip.M_BranchID = F_BillIssuePusatDetailM_BranchID
|
||||
and F_BillIsActive = 'Y'
|
||||
join f_bill_titip_detail on F_BillID=F_BillDetailF_BillID
|
||||
and f_bill_titip.M_BranchID = f_bill_titip_detail.M_BranchID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join m_company on M_CompanyID = f_bill_titip.F_BillM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join m_mou on f_bill_titip.F_BillM_MouID = m_mou.M_MouID
|
||||
left join keu_reminder_pusat
|
||||
on F_BillIssuePusatID = KeuReminderF_BillIssuePusatID
|
||||
and KeuReminderType = '03'
|
||||
where
|
||||
F_BillIssuePusatIsActive = 'Y'
|
||||
and F_BillIssuePusatIsNotif = 'Y'
|
||||
group by F_BillIssuePusatID";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["F_BillIssuePusatPICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssueID" => $r["F_BillIssuePusatID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(3, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssuePusatImgSend"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssuePusatImgSend"];
|
||||
}
|
||||
if ($r["F_BillIssuePusatImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssuePusatImg"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssuePusatID"],
|
||||
$r["F_BillIssuePusatPICEmail"],
|
||||
"03"
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssueID" => $r["F_BillIssuePusatID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePusatPICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
//TODO:
|
||||
public function first_reminder()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
$sql = "select
|
||||
F_BillIssuePusatID,
|
||||
F_BillNo,
|
||||
F_BillIssuePusatNumber,
|
||||
F_BillIssuePusatRefNumber,
|
||||
F_BillIssuePusatDate,
|
||||
F_BillIssuePusatReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
sum(F_BillDetailTotal) TotalAmount,
|
||||
F_BillIssuePusatDueDate DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePusatPIC,
|
||||
F_BillIssuePusatImg,
|
||||
F_BillIssuePusatPICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today ,
|
||||
fn_IntegerToWords(sum(F_BillDetailTotal)) Terbilang_en,
|
||||
f_terbilang(sum(F_BillDetailTotal)) Terbilang_id,
|
||||
F_BillIssuePusatDueDate + interval 7 day as OnHoldDate,
|
||||
F_BillIssuePusatDueDate - interval 7 day as ReminderDate
|
||||
from
|
||||
f_bill_issue_pusat
|
||||
join f_bill_issue_pusat_detail on F_BillIssuePusatID = F_BillIssuePusatDetailF_BillIssuePusatID
|
||||
and F_BillIssuePusatDetailIsActive = 'Y'
|
||||
and F_BillIssuePusatIsActive = 'Y'
|
||||
join f_bill_titip on F_BillIssuePusatDetailF_BillID = F_BillID
|
||||
and f_bill_titip.M_BranchID = F_BillIssuePusatDetailM_BranchID
|
||||
and F_BillIsActive = 'Y'
|
||||
join f_bill_titip_detail on F_BillID=F_BillDetailF_BillID
|
||||
and f_bill_titip.M_BranchID = f_bill_titip_detail.M_BranchID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join m_company on M_CompanyID = f_bill_titip.F_BillM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join m_mou on f_bill_titip.F_BillM_MouID = m_mou.M_MouID
|
||||
left join keu_reminder_pusat
|
||||
on F_BillIssuePusatID = KeuReminderF_BillIssuePusatID
|
||||
and KeuReminderType = '01'
|
||||
where
|
||||
F_BillIssuePusatIsActive = 'Y'
|
||||
and F_BillIssuePusatIsLunas = 'N'
|
||||
and F_BillIssuePusatIsReceive = 'Y'
|
||||
and F_BillIssuePusatDueDate - interval 7 DAY = date(now())
|
||||
and F_BillIssuePusatExtendDueDate is null
|
||||
group by F_BillIssuePusatID
|
||||
";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
if ($r["today"] == "Y" && $r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($r["F_BillIssuePusatPICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssuePusatID" => $r["F_BillIssuePusatID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(1, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssuePusatImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssuePusatImg"];
|
||||
}
|
||||
if ($r["F_BillIssuePusatImgSend"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssuePusatImgSend"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssuePusatID"],
|
||||
$r["F_BillIssuePusatPICEmail"]
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssuePusatID" => $r["F_BillIssuePusatID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePusatPICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
public function xdate($str)
|
||||
{
|
||||
return date("d M Y", strtotime($str));
|
||||
}
|
||||
//TODO:
|
||||
public function second_reminder()
|
||||
{
|
||||
$config = $this->get_config();
|
||||
|
||||
$sql = "select
|
||||
F_BillIssuePusatID,
|
||||
F_BillNo,
|
||||
F_BillIssuePusatNumber,
|
||||
F_BillIssuePusatRefNumber,
|
||||
F_BillIssuePusatDate,
|
||||
F_BillIssuePusatReceiveDate,
|
||||
min(date(T_OrderHeaderDate)) StartOrderDate,
|
||||
max(date(T_OrderHeaderDate)) EndOrderDate,
|
||||
sum(F_BillDetailTotal) TotalAmount,
|
||||
F_BillIssuePusatDueDate DueDate,
|
||||
M_CompanyName,
|
||||
M_CompanyAddress,
|
||||
M_CityName,
|
||||
F_BillIssuePusatPIC,
|
||||
F_BillIssuePusatImg,
|
||||
F_BillIssuePusatPICEmail,
|
||||
ifnull(KeuReminderStatus , 'N') KeuReminderStatus,
|
||||
if( date(KeuReminderCreated) = date(now()) , 'Y' , 'N') today ,
|
||||
fn_IntegerToWords(sum(F_BillDetailTotal)) Terbilang_en,
|
||||
f_terbilang(sum(F_BillDetailTotal)) Terbilang_id,
|
||||
F_BillIssuePusatDueDate + interval 7 day as OnHoldDate,
|
||||
F_BillIssuePusatDueDate - interval 7 day as ReminderDate
|
||||
from
|
||||
f_bill_issue_pusat
|
||||
join f_bill_issue_pusat_detail on F_BillIssuePusatID = F_BillIssuePusatDetailF_BillIssuePusatID
|
||||
and F_BillIssuePusatDetailIsActive = 'Y'
|
||||
and F_BillIssuePusatIsActive = 'Y'
|
||||
join f_bill_titip on F_BillIssuePusatDetailF_BillID = F_BillID
|
||||
and f_bill_titip.M_BranchID = F_BillIssuePusatDetailM_BranchID
|
||||
and F_BillIsActive = 'Y'
|
||||
join f_bill_titip_detail on F_BillID=F_BillDetailF_BillID
|
||||
and f_bill_titip.M_BranchID = f_bill_titip_detail.M_BranchID
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
join m_company on M_CompanyID = f_bill_titip.F_BillM_CompanyID
|
||||
join m_city on M_CompanyM_CityID = M_CityID
|
||||
join m_mou on f_bill_titip.F_BillM_MouID = m_mou.M_MouID
|
||||
left join keu_reminder_pusat
|
||||
on F_BillIssuePusatID = KeuReminderF_BillIssuePusatID
|
||||
and KeuReminderType = '02'
|
||||
where
|
||||
F_BillIssuePusatIsActive = 'Y'
|
||||
and F_BillIssuePusatIsLunas = 'N'
|
||||
and F_BillIssuePusatIsReceive = 'Y'
|
||||
and F_BillIssuePusatDueDate = date(now())
|
||||
and F_BillIssuePusatExtendDueDate is null
|
||||
group by F_BillIssuePusatID
|
||||
";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Get On Hold Email | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [];
|
||||
foreach ($rows as $r) {
|
||||
if ($r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
if ($r["today"] == "Y" && $r["KeuReminderStatus"] != "N") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($r["F_BillIssuePusatPICEmail"] == "") {
|
||||
$result[] = [
|
||||
"F_BillIssuePusatID" => $r["F_BillIssuePusatID"],
|
||||
"F_BillNo" => $r["F_BillNo"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"ErrorMessage" => "Invalid M_MouFinanceEmail",
|
||||
"KeuReminderID" => 0,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$emailMessage = $this->compose_email(2, $config, $r);
|
||||
$img = [];
|
||||
if ($r["F_BillIssuePusatImg"] != "") {
|
||||
$img[] =
|
||||
"http://localhost/one-media/one-photo/" .
|
||||
$r["F_BillIssuePusatImg"];
|
||||
}
|
||||
$keuReminderID = $this->create_log(
|
||||
$r["F_BillIssuePusatID"],
|
||||
$r["F_BillIssuePusatPICEmail"],
|
||||
"02"
|
||||
);
|
||||
$result[] = [
|
||||
"ErrorMessage" => "",
|
||||
"KeuReminderID" => $keuReminderID,
|
||||
"F_BillIssuePusatID" => $r["F_BillIssuePusatID"],
|
||||
"F_BillNo" => $r["F_BillNo"] . "/RE/01",
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"email" => $r["F_BillIssuePusatPICEmail"],
|
||||
"message" => $emailMessage,
|
||||
"attachment" => $img,
|
||||
];
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["data"] = $result;
|
||||
$this->response["config"] = $config;
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function log()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$sql = "update keu_reminder_pusat
|
||||
set KeuReminderStatus =? ,
|
||||
KeuReminderNote = ? ,
|
||||
KeuReminderSendDate = now()
|
||||
where KeuReminderID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$prm["status"],
|
||||
$prm["note"],
|
||||
$prm["id"],
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Log Keu Reminder | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["query"] = $this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function log_awal()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$sql = "update f_bill_issue_pusat
|
||||
set F_BillIssuePusatIsNotif= ?
|
||||
where F_BillIssuePusatID = ? ";
|
||||
$qry = $this->db->query($sql, [$prm["status"], $prm["id"]]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Log Keu Reminder Awal | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$this->response["status"] = "OK";
|
||||
$this->response["query"] = $this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
|
||||
public function create_log($billIssueID, $email, $type = "01")
|
||||
{
|
||||
$sql = "select KeuReminderID
|
||||
from keu_reminder_pusat
|
||||
where KeuReminderF_BillIssuePusatID=? and KeuReminderStatus = 'N'
|
||||
and KeuReminderType=?";
|
||||
$qry = $this->db->query($sql, [$billIssueID, $type]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Check Log Keu Reminder $type | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$total = 0;
|
||||
if (count($rows) > 0) {
|
||||
return $rows[0]["KeuReminderID"];
|
||||
}
|
||||
$sql = "insert into keu_reminder_pusat(KeuReminderF_BillIssuePusatID, KeuReminderEmail,
|
||||
KeuReminderStatus, KeuReminderNote,KeuReminderType)
|
||||
values (?,?,'N','New Request',?)";
|
||||
$qry = $this->db->query($sql, [$billIssueID, $email, $type]);
|
||||
if (!$qry) {
|
||||
$this->response["message"] =
|
||||
"Error Create Log Keu Reminder | " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query();
|
||||
$this->reply();
|
||||
}
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
}
|
||||
161
application/controllers/keu/Tagihan_terpusat.php
Normal file
161
application/controllers/keu/Tagihan_terpusat.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
class Tagihan_terpusat extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function log($msg)
|
||||
{
|
||||
$sdate = date("Y-m-d H:i:s");
|
||||
echo "$sdate $msg\n";
|
||||
}
|
||||
function info_mou($mouID, $json = "Y")
|
||||
{
|
||||
$json = strtoupper($json);
|
||||
if ($json != "Y") {
|
||||
$this->print_table_style();
|
||||
}
|
||||
$sql = "select M_MouID,M_MouName,M_MouNumber,
|
||||
M_BillTypeName , M_BranchName TitipKeBranch
|
||||
from m_mou
|
||||
join m_billtype
|
||||
on M_MouID = ?
|
||||
and M_MouM_BillTypeID = M_BillTypeID
|
||||
and M_BillTypeID = 2
|
||||
join m_branch
|
||||
on M_MouM_BranchBillID = M_BranchID";
|
||||
$qry = $this->db->query($sql, [$mouID]);
|
||||
if (!$qry) {
|
||||
if ($json != "Y") {
|
||||
$arr = [];
|
||||
$arr[] = ["Query" => $this->db->last_query()];
|
||||
$arr[] = ["Query" => $this->db->error()["message"]];
|
||||
$this->print_table($arr, array_keys($arr[0]));
|
||||
} else {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error get MOU : " . $this->db->error()["message"],
|
||||
]);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
$mou = $qry->result_array();
|
||||
if ($json == "Y") {
|
||||
echo json_encode([
|
||||
"status" => "OK",
|
||||
"mou" => $mou,
|
||||
]);
|
||||
} else {
|
||||
$this->print_table($mou, array_keys($mou[0]));
|
||||
}
|
||||
|
||||
$sql = "select
|
||||
T_OrderHeaderID, Last_StatusPaymentIsLunas
|
||||
from t_orderheader
|
||||
join last_statuspayment
|
||||
on T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderM_MouID = ?
|
||||
and T_OrderHeaderID = Last_StatusPaymentT_OrderHeaderID";
|
||||
$qry = $this->db->query($sql, [$mouID]);
|
||||
if (!$qry) {
|
||||
if ($json != "Y") {
|
||||
$arr = [];
|
||||
$arr[] = ["Query" => $this->db->last_query()];
|
||||
$arr[] = ["Query" => $this->db->error()["message"]];
|
||||
$this->print_table($arr, array_keys($arr[0]));
|
||||
} else {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error get Last Status Payment : " . $this->db->error()["message"],
|
||||
]);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$arr_lunas = [];
|
||||
foreach($rows as $r) {
|
||||
$id = $r["T_OrderHeaderID"];
|
||||
$arr_lunas[$id] = $r["Last_StatusPaymentIsLunas"];
|
||||
}
|
||||
$sql = "select
|
||||
T_OrderHeaderID,T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber,T_OrderHeaderLabNumberExt,
|
||||
fn_get_patient_atribute(T_OrderHeaderM_PatientID) j_patient,
|
||||
fn_get_doctor_fullname(T_OrderHeaderSenderM_DoctorID) doctorName ,
|
||||
T_OrderHeaderTotal,
|
||||
T_OrderHeaderSubTotal,
|
||||
M_CompanyID, M_CompanyNumber, M_CompanyName
|
||||
from t_orderheader
|
||||
join m_company on
|
||||
T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderM_MouID = ?
|
||||
and T_OrderHeaderM_CompanyID=M_CompanyID";
|
||||
$qry = $this->db->query($sql, [$mouID]);
|
||||
if (!$qry) {
|
||||
if ($json != "Y") {
|
||||
$arr = [];
|
||||
$arr[] = ["Query" => $this->db->last_query()];
|
||||
$arr[] = ["Query" => $this->db->error()["message"]];
|
||||
$this->print_table($arr, array_keys($arr[0]));
|
||||
} else {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error get MOU : " . $this->db->error()["message"],
|
||||
]);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$orders = [];
|
||||
foreach ($rows as $r) {
|
||||
$jp = json_decode($r["j_patient"],true);
|
||||
unset($r["j_patient"]);
|
||||
$r["Patient"] = $jp["patient_fullname"];
|
||||
if (isset($arr_lunas[$r["T_OrderHeaderID"]])) {
|
||||
$r["IsLunas"] = $arr_lunas[$r["T_OrderHeaderID"]];
|
||||
} else {
|
||||
$r["IsLunas"] = "N";
|
||||
}
|
||||
$orders[] = $r;
|
||||
}
|
||||
$this->print_table($orders, array_keys($orders[0]));
|
||||
}
|
||||
|
||||
public function print_table_style()
|
||||
{
|
||||
echo "
|
||||
<style>
|
||||
th, td {
|
||||
padding: 15px;
|
||||
text-align: left;
|
||||
}
|
||||
tr:nth-child(even) {background-color: #f2f2f2;}
|
||||
table {
|
||||
border: solid 1px ;
|
||||
min-width:600px;
|
||||
}
|
||||
</style>
|
||||
";
|
||||
}
|
||||
public function print_table($rows, $keys)
|
||||
{
|
||||
echo "<table>";
|
||||
echo "<tr>";
|
||||
foreach ($keys as $k) {
|
||||
echo "<td>$k</td>";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
foreach ($rows as $r) {
|
||||
echo "<tr>";
|
||||
foreach ($keys as $k) {
|
||||
echo "<td>" . $r[$k] . "</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
}
|
||||
308
application/controllers/keu/Titip_extend.php
Normal file
308
application/controllers/keu/Titip_extend.php
Normal file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
class Titip_extend extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->PAYMENT_TYPE_ID = 20;
|
||||
$this->USER_ID = 1500;
|
||||
}
|
||||
function get_branch_ip($branchID)
|
||||
{
|
||||
$sql =
|
||||
"select * from m_branch where M_BranchID = ? and M_BranchIsActive ='Y'";
|
||||
$resp = $this->get_one_row($sql, [$branchID]);
|
||||
if ($resp[0]) {
|
||||
return $resp[1]["M_BranchIPAddress"];
|
||||
} else {
|
||||
$this->log("\tError Get Ip Address : " . $resp[1]);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function r_extend($debug=0) {
|
||||
$sql = "select
|
||||
m.M_MouID, m.M_MouNumber, m.M_MouName
|
||||
from
|
||||
f_bill_issue_pusat_extend
|
||||
join f_bill_issue_pusat_extend_mou on F_BillIssuePusatExtendMouF_BillIssuePusatExtendID = F_BillIssuePusatExtendID
|
||||
and F_BillIssuePusatExtendIsActive = 'Y'
|
||||
and F_BillIssuePusatExtendLastUpdate + interval 3 day > now()
|
||||
and F_BillIssuePusatExtendMouIsActive = 'Y'
|
||||
join f_bill_issue_pusat_detail ON F_BillIssuePusatDetailF_BillIssuePusatID = F_BillIssuePusatExtendF_BillIssuePusatID
|
||||
join f_bill_titip_detail b ON b.F_BillDetailF_BillID = F_BillIssuePusatDetailF_BillID
|
||||
AND b.M_BranchID = F_BillIssuePusatDetailM_BranchID
|
||||
join m_mou m ON m.M_MouID = b.M_MouID
|
||||
GROUP BY m.M_MouID
|
||||
";
|
||||
$resp = $this->get_rows($sql);
|
||||
if ($debug == 1) {
|
||||
echo $this->db->last_query();
|
||||
print_r($resp);
|
||||
}
|
||||
if(!$resp[0]) {
|
||||
$this->reply_gz(["status" => "ERR", "message" => $resp[1]], $debug == 1) ;
|
||||
exit();
|
||||
}
|
||||
$this->reply_gz(["status"=>"OK","data"=>$resp[1]], $debug == 1);
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$this->log("Starting Extend Titipan.");
|
||||
list($regionalID, $branchCode, $branchID) = $this->get_branch();
|
||||
if (!$regionalID) {
|
||||
$this->log("Error No Default Branch");
|
||||
exit();
|
||||
}
|
||||
$urls = $this->url_branches($regionalID);
|
||||
foreach ($urls as $u) {
|
||||
$url = $u["url"];
|
||||
$name = $u["name"];
|
||||
$this->log("Check Extend from $name : $url");
|
||||
$resp = $this->get($url);
|
||||
if ($resp["status"] == "ERR") {
|
||||
$this->log("\t Error : " . $resp["message"]);
|
||||
continue;
|
||||
}
|
||||
foreach ($resp["data"] as $d) {
|
||||
$this->log(
|
||||
"\t Titip Extend : " .
|
||||
$d["M_MouNumber"] . " " . $d["M_MouName"] .
|
||||
" | M_MouID : " . $d["M_MouID"]
|
||||
);
|
||||
$sql = "select M_MouIsActive from m_mou where M_MouID = ?";
|
||||
$resp = $this->get_one_row($sql,[$d["M_MouID"]]);
|
||||
if (!$resp[0]) {
|
||||
$this->log("\t Error : " . $resp[1]);
|
||||
continue;
|
||||
}
|
||||
if ($resp[1]["M_IsActive"] == "N") {
|
||||
$this->log("\t Mou sudah di hapus.");
|
||||
}
|
||||
if ($resp[1]["M_IsActive"] == "H") {
|
||||
$this->log("\t Mou sudah di extend.");
|
||||
continue;
|
||||
}
|
||||
$sql ="update m_mou set M_MouIsActive = 'Y' where M_MouID = ?";
|
||||
$qry = $this->db->query($sql,[$d["M_MouID"]]);
|
||||
if (!$qry) {
|
||||
$this->log("\t Error update m_mou : " . $this->db->error()["message"]. "|" . $this->db->last_query());
|
||||
continue;
|
||||
} else {
|
||||
$this->log("\t Sukses extend Mou " . $d["M_MouNumber"] . " " . $d["M_MouName"]);
|
||||
}
|
||||
}
|
||||
$this->log( "\tDone.");
|
||||
}
|
||||
}
|
||||
function log($msg)
|
||||
{
|
||||
$sdate = date("Y-m-d H:i:s");
|
||||
echo "$sdate $msg\n";
|
||||
}
|
||||
function insert_or_update($table, $dt, $keys, $keyID)
|
||||
{
|
||||
$s_where = "";
|
||||
$param = [];
|
||||
foreach ($keys as $k) {
|
||||
if ($s_where != "") {
|
||||
$s_where .= " and ";
|
||||
}
|
||||
$s_where .= " $k = ?";
|
||||
$param[] = $dt[$k];
|
||||
}
|
||||
$sql = "select $keyID
|
||||
from $table
|
||||
where $s_where ";
|
||||
$qry = $this->db->query($sql, $param);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$status = "Insert";
|
||||
if (count($rows) > 0) {
|
||||
$lastInsertID = $rows[0][$keyID];
|
||||
foreach ($keys as $k) {
|
||||
$this->db->where($k, $dt[$k]);
|
||||
}
|
||||
$qry = $this->db->update($table, $dt);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"ERR Update : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$status = "Update";
|
||||
} else {
|
||||
$qry = $this->db->insert($table, $dt);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"ERR Insert : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$lastInsertID = $this->db->insert_id();
|
||||
}
|
||||
return [
|
||||
"status" => "OK",
|
||||
"message" => $status,
|
||||
"insertID" => $lastInsertID,
|
||||
];
|
||||
}
|
||||
function reply_gz($param, $debug = false)
|
||||
{
|
||||
if ($debug) {
|
||||
echo json_encode($param);
|
||||
} else {
|
||||
echo gzcompress(json_encode($param), 9);
|
||||
}
|
||||
}
|
||||
function get_param()
|
||||
{
|
||||
$zdata = file_get_contents("php://input");
|
||||
$data = gzuncompress($zdata);
|
||||
$param = json_decode($data, true);
|
||||
if (json_last_error() != JSON_ERROR_NONE) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Json Error : " . json_last_error_msg(),
|
||||
"raw" => $data,
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
return $param;
|
||||
}
|
||||
function get_branch()
|
||||
{
|
||||
$sql = "select M_BranchS_RegionalID,M_BranchCode,M_BranchID
|
||||
from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return [false, $this->db->error()["message"]];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return ["ERR", "No Default Branch"];
|
||||
}
|
||||
return [
|
||||
$rows[0]["M_BranchS_RegionalID"],
|
||||
$rows[0]["M_BranchCode"],
|
||||
$rows[0]["M_BranchID"],
|
||||
];
|
||||
}
|
||||
function url_branches($regionalID)
|
||||
{
|
||||
$sql = "select M_BranchCode,M_BranchIpAddress,M_BranchName
|
||||
from m_branch where M_BranchS_RegionalID = ? and M_BranchIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$regionalID]);
|
||||
|
||||
if (!$qry) {
|
||||
return [false, $this->db->error()["message"]];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$url = [];
|
||||
foreach ($rows as $r) {
|
||||
$url[] = [
|
||||
"url" =>
|
||||
"http://" .
|
||||
$r["M_BranchIpAddress"] .
|
||||
"/one-api/keu/titip_extend/r_extend" ,
|
||||
"name" => $r["M_BranchName"],
|
||||
];
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function post($url, $data)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
$zdata = gzcompress($data, 9);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $zdata);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/octet",
|
||||
"Content-Length: " . strlen($zdata),
|
||||
]);
|
||||
$zresult = curl_exec($ch);
|
||||
if (curl_error($ch) != "") {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Http Error : " . curl_error($ch),
|
||||
]);
|
||||
curl_close($ch);
|
||||
exit();
|
||||
}
|
||||
curl_close($ch);
|
||||
$result = gzuncompress($zresult);
|
||||
$jresult = json_decode($result, true);
|
||||
if (json_last_error() != 0) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "Invalid JSON : " . $result,
|
||||
];
|
||||
}
|
||||
return $jresult;
|
||||
}
|
||||
function get($url, $timeout = 60, $c_timeout = 5)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$zresult = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
return ["status" => "ERR", "message" => $err_msg];
|
||||
}
|
||||
$result = gzuncompress($zresult);
|
||||
$jresult = json_decode($result, true);
|
||||
if (json_last_error() != 0) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "Invalid JSON : " . $result,
|
||||
];
|
||||
}
|
||||
return $jresult;
|
||||
}
|
||||
function get_rows($sql, $prm = false)
|
||||
{
|
||||
if ($prm) {
|
||||
$qry = $this->db->query($sql, $prm);
|
||||
} else {
|
||||
$qry = $this->db->query($sql);
|
||||
}
|
||||
if (!$qry) {
|
||||
$msg = "Error Query : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
|
||||
return [false, $msg];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return [true, $rows];
|
||||
}
|
||||
function get_one_row($sql, $prm)
|
||||
{
|
||||
list($status, $msg) = $this->get_rows($sql, $prm);
|
||||
if ($status !== true) {
|
||||
return [$status, $msg];
|
||||
}
|
||||
if (count($msg) == 0) {
|
||||
return [false, "Record not found. | " . $msg];
|
||||
}
|
||||
return [true, $msg[0]];
|
||||
}
|
||||
}
|
||||
968
application/controllers/keu/Titip_pelunasan.php
Normal file
968
application/controllers/keu/Titip_pelunasan.php
Normal file
@@ -0,0 +1,968 @@
|
||||
<?php
|
||||
class Titip_pelunasan extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->PAYMENT_TYPE_ID = 20;
|
||||
$this->USER_ID = 1500;
|
||||
}
|
||||
public function r_fix_rk()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
$param = $this->get_param();
|
||||
$param["Payment_RkIsActive"] = "Y";
|
||||
$param["Payment_RkM_UserID"] = $this->USER_ID;
|
||||
$resp = $this->insert_or_update(
|
||||
"payment_rk",
|
||||
$param,
|
||||
[
|
||||
"Payment_RkM_BranchID",
|
||||
"Payment_RkM_BranchCode",
|
||||
"Payment_RkF_BillPaymentPusatID",
|
||||
"Payment_RkF_PaymentNumber",
|
||||
"Payment_RkIsActive",
|
||||
],
|
||||
"Payment_RkID"
|
||||
);
|
||||
if ($resp["status"] == "ERR") {
|
||||
$this->reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => $resp["message"],
|
||||
]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->reply_gz([
|
||||
"status" => "OK",
|
||||
"message" => print_r($resp, true),
|
||||
]);
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
public function fix_payment($billPusatID)
|
||||
{
|
||||
$sql = "select distinct
|
||||
F_BillTitipLunasDetailT_OrderHeaderID,
|
||||
F_PaymentDetailID, F_PaymentDetailAmount, F_BillTitipLunasDetailAmount
|
||||
from f_bill_titip_lunas
|
||||
join f_bill on F_BillTitipLunasF_BillID = F_BillID
|
||||
and F_BillTitipLunasIsActive='Y'
|
||||
and F_BillIsActive = 'Y'
|
||||
and F_BillTitipLunasF_BillPaymentPusatID = ?
|
||||
join f_bill_titip_lunas_detail on F_BillTitipLunasDetailF_BillTitipLunasID = F_BillTitipLunasID
|
||||
and F_BillTitipLunasDetailIsActive = 'Y'
|
||||
join f_payment on F_PaymentT_OrderHeaderID = F_BillTitipLunasDetailT_OrderHeaderID
|
||||
and F_PaymentIsActive = 'Y'
|
||||
join f_paymentdetail on F_PaymentID = F_PaymentDetailF_PaymentID
|
||||
and F_PaymentDetailIsActive = 'Y' ";
|
||||
$qry = $this->db->query($sql, [$billPusatID]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError Get Payment from RK : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query()
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$sql = "update f_paymentdetail set F_PaymentDetailAmount=?
|
||||
where F_PaymentDetailID = ?";
|
||||
foreach ($rows as $r) {
|
||||
if (
|
||||
$r["F_PaymentDetailAmount"] !=
|
||||
$r["F_BillTitipLunasDetailAmount"]
|
||||
) {
|
||||
$fPaymentDetailID = $r["F_PaymentDetailID"];
|
||||
$fBillTitipLunasDetailAmount =
|
||||
$r["F_BillTitipLunasDetailAmount"];
|
||||
$this->db->query($sql, [
|
||||
$fBillTitipLunasDetailAmount,
|
||||
$fPaymentDetailID,
|
||||
]);
|
||||
//echo $this->db->last_query() . "<br/>";
|
||||
}
|
||||
}
|
||||
}
|
||||
public function fix_rk($billPusatID)
|
||||
{
|
||||
$this->fix_payment($billPusatID);
|
||||
$this->log("Starting Fix RK Bill Pusat ID $billPusatID.");
|
||||
$this->db->trans_begin();
|
||||
list($regionalID, $branchCode, $branchID) = $this->get_branch();
|
||||
$sql = "select F_BillTitipLunasM_BranchID Payment_RkM_BranchID,
|
||||
F_BillTitipLunasM_BranchCode Payment_RkM_BranchCode,
|
||||
F_PaymentID Payment_RkF_PaymentID, F_PaymentNumber Payment_RkF_PaymentNumber,
|
||||
F_PaymentTotal Payment_RkAmount, F_PaymentDate Payment_RkF_PaymentDate,
|
||||
F_PaymentM_UserID Payment_RkM_UserID, F_BillTitipLunasF_BillPaymentPusatID Payment_RkF_BillPaymentPusatID
|
||||
from f_bill_titip_lunas
|
||||
join f_bill_titip_lunas_detail on F_BillTitipLunasID = F_BillTitipLunasDetailF_BillTitipLunasID
|
||||
and F_BillTitipLunasF_BillPaymentPusatID = ?
|
||||
join f_payment on f_paymentT_OrderHeaderID = F_BillTitipLunasDetailT_OrderHeaderID";
|
||||
$qry = $this->db->query($sql, [$billPusatID]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError Insert f_bill_payment : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query()
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$r_resp = [];
|
||||
foreach ($rows as $r) {
|
||||
$resp = $this->insert_or_update(
|
||||
"payment_rk",
|
||||
$r,
|
||||
["Payment_RkM_BranchID", "Payment_RkF_PaymentNumber"],
|
||||
"Payment_RkID"
|
||||
);
|
||||
$param = [
|
||||
"Payment_RkF_PaymentID" => $r["Payment_RkF_PaymentID"],
|
||||
"Payment_RkF_PaymentNumber" => $r["Payment_RkF_PaymentNumber"],
|
||||
"Payment_RkF_PaymentDate" => $r["Payment_RkF_PaymentDate"],
|
||||
"Payment_RkM_BranchID" => $branchID,
|
||||
"Payment_RkM_BranchCode" => $branchCode,
|
||||
"Payment_RkF_BillPaymentPusatID" => $billPusatID,
|
||||
"Payment_RkAmount" => $r["Payment_RkAmount"],
|
||||
];
|
||||
$originIpAddress = $this->get_branch_ip($r["Payment_RkM_BranchID"]);
|
||||
if ($originIpAddress == "") {
|
||||
$this->log(
|
||||
"\tError get Ip Address : " .
|
||||
$r["F_BillTitipLunasM_BranchCode"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rk_url = "http://$originIpAddress/one-api/keu/titip_pelunasan/r_fix_rk";
|
||||
$jparam = json_encode($param);
|
||||
$resp = $this->post($rk_url, $jparam);
|
||||
if ($resp["status"] != "OK") {
|
||||
$this->log("\tError Post RK to $rk_url : " . $resp["message"]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$r_resp[] = $resp;
|
||||
}
|
||||
$this->log("Done Fix RK Bill Pusat ID $billPusatID.");
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
|
||||
public function real()
|
||||
{
|
||||
$this->log("Starting Pelunasan Real.");
|
||||
$this->db->trans_begin();
|
||||
list($regionalID, $branchCode, $branchID) = $this->get_branch();
|
||||
//isConfirm R => sudah real payment
|
||||
$sql = "select
|
||||
distinct
|
||||
F_BillTitipLunasID,
|
||||
F_BillTitipLunasF_BillID, F_BillTitipLunasDate, F_BillTitipLunasF_BillID,
|
||||
F_BillTitipLunasF_BillPaymentPusatID,
|
||||
F_BillTitipLunasNumber,F_BillNo, F_BillTitipLunasAmount,
|
||||
F_BillTitipLunasM_PaymentTypeID, F_BillTitipLunasEDCNat_BankID, F_BillTitipLunasCardNat_BankID,
|
||||
if(F_BillPaymentPusatM_BankAccountID > 0, F_BillPaymentPusatM_BankAccountID, F_BillTitipLunasM_BankAccountID) F_BillTitipLunasM_BankAccountID ,
|
||||
F_BillTitipLunasVoucherNumber,
|
||||
F_BillTitipLunasM_BranchID, F_BillTitipLunasM_BranchCode
|
||||
from f_bill_titip_lunas
|
||||
join f_bill on F_BillTitipLunasF_BillID = F_BillID
|
||||
and F_BillTitipLunasIsConfirm = 'N'
|
||||
and F_BillTitipLunasIsActive='Y'
|
||||
and F_BillIsActive = 'Y'
|
||||
join f_bill_titip_lunas_detail on F_BillTitipLunasDetailF_BillTitipLunasID = F_BillTitipLunasID
|
||||
and F_BillTitipLunasDetailIsActive = 'Y'
|
||||
left join f_bill_payment_pusat on F_BillTitipLunasF_BillPaymentPusatID = F_BillPaymentPusatID
|
||||
and F_BillPaymentPusatIsActive = 'Y' ";
|
||||
$resp = $this->get_rows($sql);
|
||||
if (!$resp[0]) {
|
||||
$this->log("\tError : " . $resp[1]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rows = $resp[1];
|
||||
$arr_titip_number = [];
|
||||
$arr_payment_number = [];
|
||||
|
||||
$sql_detail = "select
|
||||
F_BillTitipLunasDetailF_BillDetailID,
|
||||
F_BillTitipLunasDetailT_OrderHeaderID,
|
||||
F_BillTitipLunasM_BranchID, F_BillTitipLunasM_BranchCode,
|
||||
F_BillTitipLunasDetailAmount
|
||||
from f_bill_titip_lunas
|
||||
join f_bill on F_BillTitipLunasF_BillID = F_BillID
|
||||
and F_BillTitipLunasIsConfirm = 'N'
|
||||
and F_BillTitipLunasIsActive='Y'
|
||||
and F_BillIsActive = 'Y'
|
||||
and F_BillTitipLunasID = ?
|
||||
join f_bill_titip_lunas_detail on F_BillTitipLunasDetailF_BillTitipLunasID = F_BillTitipLunasID
|
||||
and F_BillTitipLunasDetailIsActive = 'Y'";
|
||||
|
||||
foreach ($rows as $r) {
|
||||
$fBillTitipLunasID = $r["F_BillTitipLunasID"];
|
||||
$fBillID = $r["F_BillTitipLunasF_BillID"];
|
||||
$fBilltTitipLunasAmount = $r["F_BillTitipLunasAmount"];
|
||||
$fBillNumber = $r["F_BillTitipLunasNumber"];
|
||||
$fBillAmount = $r["F_BillTitipLunasAmount"];
|
||||
$fBillTitipLunasM_BranchID = $r["F_BillTitipLunasM_BranchID"];
|
||||
$fBillPaymentPusatID = $r["F_BillTitipLunasF_BillPaymentPusatID"];
|
||||
|
||||
if ($fBillTitipLunasM_BranchID == $branchID) {
|
||||
$isLocalPayment = true;
|
||||
} else {
|
||||
$isLocalPayment = false;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO f_bill_payment(F_BillPaymentF_BillID, F_BillPaymentDate, F_BillPaymentAmount,
|
||||
F_BillPaymentM_PaymentTypeID, F_BillPaymentEDCNat_BankID,
|
||||
F_BillPaymentCardNat_BankID, F_BillPaymentM_BankAccountID, F_BillPaymentVoucherNumber,
|
||||
F_BillPaymentCreated, F_BillPaymentUserID)
|
||||
VALUES (?, CURDATE(), ?, ?, ?, ?, ?, ?, NOW(), ? )";
|
||||
|
||||
if ($isLocalPayment) {
|
||||
$qry = $this->db->query($sql, [
|
||||
$fBillID,
|
||||
$fBilltTitipLunasAmount,
|
||||
$r["F_BillTitipLunasM_PaymentTypeID"],
|
||||
$r["F_BillTitipLunasEDCNat_BankID"],
|
||||
$r["F_BillTitipLunasCardNat_BankID"],
|
||||
$r["F_BillTitipLunasM_BankAccountID"],
|
||||
$r["F_BillTitipLunasVoucherNumber"],
|
||||
$this->USER_ID,
|
||||
]);
|
||||
} else {
|
||||
$qry = $this->db->query($sql, [
|
||||
$fBillID,
|
||||
$fBilltTitipLunasAmount,
|
||||
$this->PAYMENT_TYPE_ID,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
$this->USER_ID,
|
||||
]);
|
||||
}
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError Insert f_bill_payment : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query()
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$fBillPaymentID = $this->db->insert_id();
|
||||
$qry = $this->db->query($sql_detail, [$fBillTitipLunasID]);
|
||||
|
||||
// update f_bill
|
||||
$sql = "UPDATE f_bill SET
|
||||
F_BillUnpaid = F_BillUnpaid - ?, F_BillIsLunas = IF(F_BillUnpaid = 0,'Y','N')
|
||||
WHERE F_BillID = ?";
|
||||
$qry = $this->db->query($sql, [$fBillAmount, $fBillID]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError Update f_bill : " . $this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
|
||||
//get detail
|
||||
$qry = $this->db->query($sql_detail, [$fBillTitipLunasID]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError get f_bill_titip_lunas_detail : " .
|
||||
$this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rows_detail = $qry->result_array();
|
||||
foreach ($rows_detail as $rd) {
|
||||
$orderHeaderID = $rd["F_BillTitipLunasDetailT_OrderHeaderID"];
|
||||
$fBillDetailID = $rd["F_BillTitipLunasDetailF_BillDetailID"];
|
||||
$fBillDetailAmount = $rd["F_BillTitipLunasDetailAmount"];
|
||||
//3 INSERT f_bill_payment_detail
|
||||
$sql = "INSERT INTO f_bill_payment_detail( F_BillPaymentDetailF_BillPaymentID,
|
||||
F_BillPaymentDetailF_BillID, F_BillPaymentDetailF_BillDetailID, F_BillPaymentDetailAmount,
|
||||
F_BillPaymentDetailUserID, F_BillPaymentDetailCreated, F_BillPaymentDetailLastUpdated)
|
||||
VALUES( ?, ?, ?, ?, ?, now(), now())";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$fBillPaymentID,
|
||||
$fBillID,
|
||||
$fBillDetailID,
|
||||
$fBillDetailAmount,
|
||||
$this->USER_ID,
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError insert f_bill_payment_detail : " .
|
||||
$this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$fBillPaymentDetailID = $this->db->insert_id();
|
||||
//4 update f_bill_detail
|
||||
$sql = "UPDATE f_bill_detail SET
|
||||
F_BillDetailUnpaid = F_BillDetailUnpaid - ?
|
||||
WHERE F_BillDetailID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$fBillDetailAmount,
|
||||
$fBillDetailID,
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError update f_bill_detail : " .
|
||||
$this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
|
||||
//5 INSERT f_payment
|
||||
$sql = "INSERT INTO f_payment (F_PaymentT_OrderHeaderID, F_PaymentDate,
|
||||
F_PaymentTotal, F_PaymentCreated, F_PaymentLastUpdated, F_PaymentM_UserID)
|
||||
VALUES( ?, now(), ?, now(), now(), ?)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$orderHeaderID,
|
||||
$fBillDetailAmount,
|
||||
$this->USER_ID,
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError insert f_payment : " .
|
||||
$this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$fPaymentID = $this->db->insert_id();
|
||||
|
||||
//6 INSERT f_paymentdetail
|
||||
$sql = "INSERT INTO f_paymentdetail
|
||||
(F_PaymentDetailF_PaymentID, F_PaymentDetailM_PaymentTypeID, F_PaymentDetailAmount,
|
||||
F_PaymentDetailActual, F_PaymentDetailChange, F_PaymentDetailEDCNat_BankID, F_PaymentDetailCardNat_BankID,
|
||||
F_PaymentDetailM_BankAccountID, F_PaymentDetailCreated, F_PaymentDetailLastUpdated, F_PaymentDetailUserID)
|
||||
VALUES( ?, ?, ?, ?, 0, ?, ?, ?, now(), now(), ?)";
|
||||
if ($isLocalPayment) {
|
||||
$qry = $this->db->query($sql, [
|
||||
$fPaymentID,
|
||||
$r["F_BillTitipLunasM_PaymentTypeID"],
|
||||
$fBillDetailAmount,
|
||||
$fBillDetailAmount,
|
||||
$r["F_BillTitipLunasEDCNat_BankID"],
|
||||
$r["F_BillTitipLunasCardNat_BankID"],
|
||||
$r["F_BillTitipLunasM_BankAccountID"],
|
||||
$this->USER_ID,
|
||||
]);
|
||||
} else {
|
||||
$qry = $this->db->query($sql, [
|
||||
$fPaymentID,
|
||||
$this->PAYMENT_TYPE_ID,
|
||||
$fBillDetailAmount,
|
||||
$fBillDetailAmount,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$this->USER_ID,
|
||||
]);
|
||||
}
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError insert f_paymentdetail: " .
|
||||
$this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
//7. update f_bill_payment_detail
|
||||
$sql = "UPDATE f_bill_payment_detail SET
|
||||
F_BillPaymentDetailF_PaymentID = ?
|
||||
WHERE F_BillPaymentDetailID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$fPaymentID,
|
||||
$fBillPaymentDetailID,
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError update f_bill_payment_detal : " .
|
||||
$this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
|
||||
$sql = "select F_PaymentID,F_PaymentNumber,F_PaymentDate, F_PaymentTotal
|
||||
from f_payment
|
||||
where F_PaymentID = ?";
|
||||
$resp = $this->get_one_row($sql, [$fPaymentID]);
|
||||
if (!$resp[0]) {
|
||||
$this->log("\tError get f_payment : " . $resp[1]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rpayment = $resp[1];
|
||||
if (!$isLocalPayment) {
|
||||
//Create`RK Payment
|
||||
// - Piutang
|
||||
// + Hutang
|
||||
$sql = "insert into payment_rk(Payment_RkF_PaymentID,Payment_RkF_PaymentNumber, Payment_RkF_PaymentDate,
|
||||
Payment_RkM_BranchID, Payment_RkM_BranchCode, Payment_RkAmount, Payment_RkM_UserID, Payment_RkF_BillPaymentPusatID )
|
||||
value (?,?,?, ?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$rpayment["F_PaymentID"],
|
||||
$rpayment["F_PaymentNumber"],
|
||||
$rpayment["F_PaymentDate"],
|
||||
$r["F_BillTitipLunasM_BranchID"],
|
||||
$r["F_BillTitipLunasM_BranchCode"],
|
||||
-1 * $rpayment["F_PaymentTotal"],
|
||||
$this->USER_ID,
|
||||
$fBillPaymentPusatID,
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError insert payment_rk local : " .
|
||||
$this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
// create post rk to cabang asal
|
||||
$param = [
|
||||
"Payment_RkF_PaymentID" => $rpayment["F_PaymentID"],
|
||||
"Payment_RkF_PaymentNumber" =>
|
||||
$rpayment["F_PaymentNumber"],
|
||||
"Payment_RkF_PaymentDate" => $rpayment["F_PaymentDate"],
|
||||
"Payment_RkM_BranchID" => $branchID,
|
||||
"Payment_RkM_BranchCode" => $branchCode,
|
||||
"Payment_RkF_BillPaymentPusatID" => $fBillPaymentPusatID,
|
||||
"Payment_RkAmount" => $rpayment["F_PaymentTotal"],
|
||||
];
|
||||
$originIpAddress = $this->get_branch_ip(
|
||||
$r["F_BillTitipLunasM_BranchID"]
|
||||
);
|
||||
if ($originIpAddress == "") {
|
||||
$this->log(
|
||||
"\tError get Ip Address : " .
|
||||
$r["F_BillTitipLunasM_BranchCode"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$rk_url = "http://$originIpAddress/one-api/keu/titip_pelunasan/r_rk";
|
||||
$jparam = json_encode($param);
|
||||
$resp = $this->post($rk_url, $jparam);
|
||||
if ($resp["status"] != "OK") {
|
||||
$this->log(
|
||||
"\tError Post RK to $rk_url : " . $resp["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
}
|
||||
$sql =
|
||||
"update f_bill_titip_lunas set F_BillTitipLunasIsConfirm='R' where F_BillTitipLunasID=?";
|
||||
$qry = $this->db->query($sql, [$fBillTitipLunasID]);
|
||||
if (!$qry) {
|
||||
$this->log(
|
||||
"\tError update f_bill_titip_lunas Confirm: " .
|
||||
$this->db->error()["message"]
|
||||
);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
$arr_titip_number[] = $fBillNumber;
|
||||
$arr_payment_number[] = $rpayment["F_PaymentNumber"];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->log(
|
||||
"\tSukses Payment No : " . implode(", ", $arr_payment_number)
|
||||
);
|
||||
$this->log("End Pelunasan Real.");
|
||||
}
|
||||
function r_rk()
|
||||
{
|
||||
$this->db->trans_begin();
|
||||
$param = $this->get_param();
|
||||
$param["Payment_RkIsActive"] = "Y";
|
||||
$param["Payment_RkM_UserID"] = $this->USER_ID;
|
||||
$resp = $this->insert_or_update(
|
||||
"payment_rk",
|
||||
$param,
|
||||
[
|
||||
"Payment_RkM_BranchID",
|
||||
"Payment_RkM_BranchCode",
|
||||
"Payment_RkF_BillPaymentPusatID",
|
||||
"Payment_RkF_PaymentNumber",
|
||||
"Payment_RkIsActive",
|
||||
],
|
||||
"Payment_RkID"
|
||||
);
|
||||
if ($resp["status"] == "ERR") {
|
||||
$this->reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => $resp["message"],
|
||||
]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->reply_gz([
|
||||
"status" => "OK",
|
||||
"message" => print_r($resp, true),
|
||||
]);
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
function r_rk_old()
|
||||
{
|
||||
$param = $this->get_param();
|
||||
$sql = "insert into payment_rk(Payment_RkF_PaymentID,Payment_RkF_PaymentNumber, Payment_RkF_PaymentDate,
|
||||
Payment_RkM_BranchID, Payment_RkM_BranchCode, Payment_RkAmount , Payment_RkM_UserID, Payment_RkF_BillPaymentPusatID)
|
||||
value (?,?,?, ?,?,?, ?,?)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$param["Payment_RkF_PaymentID"],
|
||||
$param["Payment_RkF_PaymentNumber"],
|
||||
$param["Payment_RkF_PaymentDate"],
|
||||
$param["Payment_RkM_BranchID"],
|
||||
$param["Payment_RkM_BranchCode"],
|
||||
$param["Payment_RkAmount"],
|
||||
$this->USER_ID,
|
||||
$param["Payment_RkF_BillPaymentPusatID"],
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => "Error : " . $this->db->error()["message"],
|
||||
]);
|
||||
} else {
|
||||
$this->reply_gz(["status" => "OK", "message" => ""]);
|
||||
}
|
||||
}
|
||||
function get_branch_ip($branchID)
|
||||
{
|
||||
$sql =
|
||||
"select * from m_branch where M_BranchID = ? and M_BranchIsActive ='Y'";
|
||||
$resp = $this->get_one_row($sql, [$branchID]);
|
||||
if ($resp[0]) {
|
||||
return $resp[1]["M_BranchIPAddress"];
|
||||
} else {
|
||||
$this->log("\tError Get Ip Address : " . $resp[1]);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$this->log("Starting Pelunasan Titipan.");
|
||||
list($regionalID, $branchCode, $branchID) = $this->get_branch();
|
||||
if (!$regionalID) {
|
||||
$this->log("Error No Default Branch");
|
||||
exit();
|
||||
}
|
||||
$urls = $this->url_branches($regionalID, $branchCode);
|
||||
foreach ($urls as $u) {
|
||||
$url = $u["url"];
|
||||
$name = $u["name"];
|
||||
$this->log("Check Pelunasan from $name : $url");
|
||||
$resp = $this->get($url);
|
||||
if ($resp["status"] == "ERR") {
|
||||
$this->log("\t Error : " . $resp["message"]);
|
||||
continue;
|
||||
}
|
||||
$billCounter = 0;
|
||||
$billCounterDetail = 0;
|
||||
foreach ($resp["data"] as $d) {
|
||||
$this->log(
|
||||
"\t Titip Pelunasan : " .
|
||||
$d["F_BillPaymentPusatNumber"] .
|
||||
" | Bill ID : " .
|
||||
$d["F_BillDetailF_BillID"]
|
||||
);
|
||||
$data = [
|
||||
"F_BillTitipLunasDate" => $d["F_BillPaymentPusatDate"],
|
||||
"F_BillTitipLunasF_BillID" => $d["F_BillDetailF_BillID"],
|
||||
"F_BillTitipLunasF_BillPaymentPusatID" =>
|
||||
$d["F_BillPaymentPusatID"],
|
||||
"F_BillTitipLunasM_PaymentTypeID" =>
|
||||
$d["F_BillPaymentPusatM_PaymentTypeID"],
|
||||
"F_BillTitipLunasAmount" => $d["F_BillTitipLunasAmount"],
|
||||
"F_BillTitipLunasIsActive" =>
|
||||
$d["F_BillPaymentPusatIsActive"],
|
||||
"F_BillTitipLunasStaffName" => "Admin",
|
||||
"F_BillTitipLunasUserID" => 3,
|
||||
"F_BillTitipLunasNumber" => $d["F_BillPaymentPusatNumber"],
|
||||
"F_BillTitipLunasM_BranchID" => $d["M_BranchID"],
|
||||
"F_BillTitipLunasM_BranchCode" => $d["M_BranchCode"],
|
||||
];
|
||||
$resp = $this->insert_or_update(
|
||||
"f_bill_titip_lunas",
|
||||
$data,
|
||||
["F_BillTitipLunasNumber", "F_BillTitipLunasF_BillID"],
|
||||
"F_BillTitipLUnasID"
|
||||
);
|
||||
if ($resp["status"] == "ERR") {
|
||||
$this->log("Error : " . $resp["message"]);
|
||||
continue;
|
||||
}
|
||||
$billCounter++;
|
||||
$insertID = $resp["insertID"];
|
||||
foreach ($d["details"] as $det) {
|
||||
$data = [
|
||||
"F_BillTitipLunasDetailF_BillTitipLunasID" => $insertID,
|
||||
"F_BillTitipLunasDetailT_OrderHeaderID" =>
|
||||
$det["F_BillDetailT_OrderHeaderID"],
|
||||
"F_BillTitipLunasDetailFullPatientName" =>
|
||||
$det["FullPatientName"],
|
||||
"F_BillTitipLunasDetailF_BillDetailID" =>
|
||||
$det["F_BillDetailID"],
|
||||
"F_BillTitipLunasDetailT_OrderHeaderLabNumber" =>
|
||||
$det["T_OrderHeaderLabNumber"],
|
||||
"F_BillTitipLunasDetailT_OrderHeaderLabNumberExt" =>
|
||||
$det["T_OrderHeaderLabNumberExt"],
|
||||
"F_BillTitipLunasDetailAmount" =>
|
||||
$det["Log_PaymentTitipDetailAmount"],
|
||||
"F_BillTitipLunasDetailUserID" => 3,
|
||||
];
|
||||
$resp = $this->insert_or_update(
|
||||
"f_bill_titip_lunas_detail",
|
||||
$data,
|
||||
[
|
||||
"F_BillTitipLunasDetailT_OrderHeaderID",
|
||||
"F_BillTitipLunasDetailF_BillTitipLunasID",
|
||||
],
|
||||
"F_BillTitipLunasDetailID"
|
||||
);
|
||||
if ($resp["status"] == "ERR") {
|
||||
$this->log("Error : " . $resp["message"]);
|
||||
break;
|
||||
}
|
||||
$billCounterDetail++;
|
||||
}
|
||||
}
|
||||
$this->log(
|
||||
"\tDone. Bill : $billCounter | Detail : $billCounterDetail\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
function log($msg)
|
||||
{
|
||||
$sdate = date("Y-m-d H:i:s");
|
||||
echo "$sdate $msg\n";
|
||||
}
|
||||
function insert_or_update($table, $dt, $keys, $keyID)
|
||||
{
|
||||
$s_where = "";
|
||||
$param = [];
|
||||
foreach ($keys as $k) {
|
||||
if ($s_where != "") {
|
||||
$s_where .= " and ";
|
||||
}
|
||||
$s_where .= " $k = ?";
|
||||
$param[] = $dt[$k];
|
||||
}
|
||||
$sql = "select $keyID
|
||||
from $table
|
||||
where $s_where ";
|
||||
$qry = $this->db->query($sql, $param);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$status = "Insert";
|
||||
if (count($rows) > 0) {
|
||||
$lastInsertID = $rows[0][$keyID];
|
||||
foreach ($keys as $k) {
|
||||
$this->db->where($k, $dt[$k]);
|
||||
}
|
||||
$qry = $this->db->update($table, $dt);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"ERR Update : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$status = "Update";
|
||||
} else {
|
||||
$qry = $this->db->insert($table, $dt);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"ERR Insert : " .
|
||||
$this->db->error()["message"] .
|
||||
"|" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$lastInsertID = $this->db->insert_id();
|
||||
}
|
||||
return [
|
||||
"status" => "OK",
|
||||
"message" => $status,
|
||||
"insertID" => $lastInsertID,
|
||||
];
|
||||
}
|
||||
function r_lunas($inp_branchCode, $debug = 0)
|
||||
{
|
||||
$flag_debug = false;
|
||||
if ($debug != 0) {
|
||||
$flag_debug = true;
|
||||
}
|
||||
list($regionalID, $branchCode, $branchID) = $this->get_branch();
|
||||
// pelunasan 3 hari ke belakang
|
||||
$sql = "select distinct
|
||||
F_BillPaymentPusatID, F_BillDetailF_BillID,
|
||||
F_BillPaymentPusatDate, F_BillPaymentPusatNumber, F_BillPaymentPusatNote,
|
||||
F_BillPaymentPusatAmount, F_BillPaymentPusatIsActive, F_BillPaymentPusatM_PaymentTypeID ,
|
||||
F_BillIssuePusatID, $branchID M_BranchID, '$branchCode' M_BranchCode
|
||||
from f_bill_payment_pusat
|
||||
join f_bill_issue_pusat on F_BillPaymentPusatF_BillIssuePusatID = F_BillIssuePusatID
|
||||
and F_BillIssuePusatIsActive = 'Y'
|
||||
and F_BillPaymentPusatIsActive = 'Y'
|
||||
and F_BillPaymentPusatLastUpdated + interval 3 day > now()
|
||||
join f_bill_issue_pusat_detail on F_BillIssuePusatDetailF_BillIssuePusatID = F_BillIssuePusatID
|
||||
and F_BillIssuePusatDetailIsActive = 'Y'
|
||||
join f_bill_titip_detail on F_BillDetailF_BillID = F_BillIssuePusatDetailF_BillID
|
||||
and f_bill_titip_detail.M_BranchID = F_BillIssuePusatDetailM_BranchID
|
||||
and f_bill_titip_detail.M_BranchCode = ?
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
";
|
||||
$resp = $this->get_rows($sql, [$inp_branchCode]);
|
||||
if (!$resp[0]) {
|
||||
$this->reply_gz(
|
||||
["status" => "ERR", "message" => $resp[1]],
|
||||
$flag_debug
|
||||
);
|
||||
exit();
|
||||
}
|
||||
$rows = $resp[1];
|
||||
$pusat_ids = "-1";
|
||||
foreach ($rows as $idx => $r) {
|
||||
$pusat_ids .= "," . $r["F_BillIssuePusatID"];
|
||||
unset($rows[$idx]["F_BillIssuePusatID"]);
|
||||
}
|
||||
$bill_issue = $rows;
|
||||
$sql = "select distinct
|
||||
F_BillPaymentPusatDetailF_BillPaymentPusatID,
|
||||
F_BillDetailT_OrderHeaderID, T_OrderHeaderDate,FullPatientName,
|
||||
T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
|
||||
Log_PaymentTitipDetailAmount,
|
||||
F_BillPaymentPusatDetailAmount,
|
||||
F_BillDetailTotal, F_BillDetailUnpaid,
|
||||
F_BillDetailIsLunas,
|
||||
F_BillDetailID, F_BillDetailF_BillID
|
||||
from
|
||||
f_bill_issue_pusat_detail
|
||||
join f_bill_payment_pusat_detail on F_BillPaymentPusatDetailF_BillIssuePusatDetailID = F_BillIssuePusatDetailID
|
||||
and F_BillIssuePusatDetailF_BillIssuePusatID in ($pusat_ids)
|
||||
and F_BillPaymentPusatDetailIsActive = 'Y'
|
||||
and F_BillIssuePusatDetailIsActive = 'Y'
|
||||
join log_payment_titip_detail on Log_PaymentTitipDetailF_BillPaymentPusatDetailID = F_BillPaymentPusatDetailID
|
||||
and Log_PaymentTitipDetailIsActive = 'Y'
|
||||
join f_bill_titip_detail on F_BillDetailID = Log_PaymentTitipDetailF_BillDetailID
|
||||
and M_BranchCode = ?
|
||||
and F_BillIssuePusatDetailM_BranchID = Log_PaymentTitipDetailM_BranchID
|
||||
and F_BillDetailUnpaid < F_BillDetailTotal
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
";
|
||||
$resp = $this->get_rows($sql, [$inp_branchCode]);
|
||||
if (!$resp[0]) {
|
||||
$this->reply_gz(
|
||||
["status" => "ERR", "message" => $resp[1]],
|
||||
$flag_debug
|
||||
);
|
||||
exit();
|
||||
}
|
||||
$rows = $resp[1];
|
||||
foreach ($bill_issue as $idx => $bill) {
|
||||
$billPusatID = $bill["F_BillPaymentPusatID"];
|
||||
$billID = $bill["F_BillDetailF_BillID"];
|
||||
$details = array_filter($rows, function ($r) use (
|
||||
$billPusatID,
|
||||
$billID
|
||||
) {
|
||||
if (
|
||||
$r["F_BillPaymentPusatDetailF_BillPaymentPusatID"] ==
|
||||
$billPusatID &&
|
||||
$r["F_BillDetailF_BillID"] == $billID
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$total_per_cabang = 0;
|
||||
foreach ($details as $xd) {
|
||||
$total_per_cabang += $xd["Log_PaymentTitipDetailAmount"];
|
||||
}
|
||||
$bill_issue[$idx]["details"] = $details;
|
||||
$bill_issue[$idx]["F_BillTitipLunasAmount"] = $total_per_cabang;
|
||||
if (count($details) == 0) {
|
||||
unset($bill_issue[$idx]);
|
||||
}
|
||||
}
|
||||
$this->reply_gz(["status" => "OK", "data" => $bill_issue], $flag_debug);
|
||||
}
|
||||
|
||||
function reply_gz($param, $debug = false)
|
||||
{
|
||||
if ($debug) {
|
||||
echo json_encode($param);
|
||||
} else {
|
||||
echo gzcompress(json_encode($param), 9);
|
||||
}
|
||||
}
|
||||
function get_param()
|
||||
{
|
||||
$zdata = file_get_contents("php://input");
|
||||
$data = gzuncompress($zdata);
|
||||
$param = json_decode($data, true);
|
||||
if (json_last_error() != JSON_ERROR_NONE) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Json Error : " . json_last_error_msg(),
|
||||
"raw" => $data,
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
return $param;
|
||||
}
|
||||
function get_branch()
|
||||
{
|
||||
$sql = "select M_BranchS_RegionalID,M_BranchCode,M_BranchID
|
||||
from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return [false, $this->db->error()["message"]];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return ["ERR", "No Default Branch"];
|
||||
}
|
||||
return [
|
||||
$rows[0]["M_BranchS_RegionalID"],
|
||||
$rows[0]["M_BranchCode"],
|
||||
$rows[0]["M_BranchID"],
|
||||
];
|
||||
}
|
||||
function url_branches($regionalID, $branchCode)
|
||||
{
|
||||
$sql = "select M_BranchCode,M_BranchIpAddress,M_BranchName
|
||||
from m_branch where M_BranchS_RegionalID = ? and M_BranchIsActive = 'Y' ";
|
||||
$qry = $this->db->query($sql, [$regionalID]);
|
||||
|
||||
if (!$qry) {
|
||||
return [false, $this->db->error()["message"]];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$url = [];
|
||||
foreach ($rows as $r) {
|
||||
$url[] = [
|
||||
"url" =>
|
||||
"http://" .
|
||||
$r["M_BranchIpAddress"] .
|
||||
"/one-api/keu/titip_pelunasan/r_lunas/" .
|
||||
$branchCode,
|
||||
"name" => $r["M_BranchName"],
|
||||
];
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function post($url, $data)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
$zdata = gzcompress($data, 9);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $zdata);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/octet",
|
||||
"Content-Length: " . strlen($zdata),
|
||||
]);
|
||||
$zresult = curl_exec($ch);
|
||||
if (curl_error($ch) != "") {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Http Error : " . curl_error($ch),
|
||||
]);
|
||||
curl_close($ch);
|
||||
exit();
|
||||
}
|
||||
curl_close($ch);
|
||||
$result = gzuncompress($zresult);
|
||||
$jresult = json_decode($result, true);
|
||||
if (json_last_error() != 0) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "Invalid JSON : " . $result,
|
||||
];
|
||||
}
|
||||
return $jresult;
|
||||
}
|
||||
function get($url, $timeout = 60, $c_timeout = 5)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$zresult = curl_exec($ch);
|
||||
$err_msg = curl_error($ch);
|
||||
if ($err_msg != "") {
|
||||
return ["status" => "ERR", "message" => $err_msg];
|
||||
}
|
||||
$result = gzuncompress($zresult);
|
||||
$jresult = json_decode($result, true);
|
||||
if (json_last_error() != 0) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => "Invalid JSON : " . $result,
|
||||
];
|
||||
}
|
||||
return $jresult;
|
||||
}
|
||||
function get_rows($sql, $prm = false)
|
||||
{
|
||||
if ($prm) {
|
||||
$qry = $this->db->query($sql, $prm);
|
||||
} else {
|
||||
$qry = $this->db->query($sql);
|
||||
}
|
||||
if (!$qry) {
|
||||
$msg = "Error Query : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
|
||||
return [false, $msg];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
return [true, $rows];
|
||||
}
|
||||
function get_one_row($sql, $prm)
|
||||
{
|
||||
list($status, $msg) = $this->get_rows($sql, $prm);
|
||||
if ($status !== true) {
|
||||
return [$status, $msg];
|
||||
}
|
||||
if (count($msg) == 0) {
|
||||
return [false, "Record not found. | " . $msg];
|
||||
}
|
||||
return [true, $msg[0]];
|
||||
}
|
||||
}
|
||||
289
application/controllers/keu/Titip_tagihan.php
Normal file
289
application/controllers/keu/Titip_tagihan.php
Normal file
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
class Titip_tagihan extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Titip Tagihan";
|
||||
}
|
||||
function now()
|
||||
{
|
||||
return Date("Y-m-d H:i:s");
|
||||
}
|
||||
function get_branch()
|
||||
{
|
||||
$sql = "select M_BranchID,M_BranchCode
|
||||
from m_branch where M_BranchIsActive = 'Y'
|
||||
and M_BranchIsDefault='Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Get Default Branch | " . $this->db->error()["message"],
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "No Default Branch ",
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
return [$rows[0]["M_BranchID"], $rows[0]["M_BranchCode"]];
|
||||
}
|
||||
function upload($id, $userID = 3)
|
||||
{
|
||||
list($branchID, $branchCode) = $this->get_branch();
|
||||
$sql = "select f_bill.*, F_BillConfirmIssueIsSend, F_BillConfirmIssueSendDate,
|
||||
M_BranchIPAddress,
|
||||
? M_BranchID, ? M_BranchCode
|
||||
from
|
||||
f_bill_confirm_issue
|
||||
join f_bill on F_BillConfirmIssueID = ?
|
||||
and F_BillConfirmIssueIsActive = 'Y'
|
||||
and F_BillConfirmIssueF_BillID = F_BillID
|
||||
join m_branch on F_BillConfirmIssueM_BranchID = M_BranchID";
|
||||
|
||||
$qry = $this->db->query($sql, [$branchID, $branchCode, $id]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Get f_bill | " . $this->db->error()["message"],
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo json_encode(["status" => "ERR", "message" => "No F_Bill "]);
|
||||
echo $this->db->last_query();
|
||||
exit();
|
||||
}
|
||||
$f_bill = $rows[0];
|
||||
$targetIP = $f_bill["M_BranchIPAddress"];
|
||||
if ($f_bill["F_BillConfirmIssueIsSend"] == "Y") {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "F_Bill sudah di kirim.",
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
|
||||
unset($f_bill["F_BillConfirmIssueIsSend"]);
|
||||
unset($f_bill["F_BillConfirmIssueSendDate"]);
|
||||
unset($f_bill["M_BranchIPAddress"]);
|
||||
|
||||
$sql = "select ? M_BranchID, ? M_BranchCode,
|
||||
T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt, fn_get_patient_atribute(T_OrderHeaderM_PatientID) xpat,
|
||||
M_MouID, M_MouName, M_MouNumber,
|
||||
f_bill_detail.*
|
||||
from f_bill_detail
|
||||
join t_orderheader on F_BillDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
and F_BillDetailIsActive = 'Y'
|
||||
and F_BillDetailF_BillID = ?
|
||||
join m_mou on T_OrderHeaderM_MouID = M_MouID ";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$branchID,
|
||||
$branchCode,
|
||||
$f_bill["F_BillID"],
|
||||
]);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Get f_bill_detail | " . $this->db->error()["message"],
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "No f_bill_detail ",
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$f_bill_detail = [];
|
||||
foreach ($rows as $r) {
|
||||
$xpat = $r["xpat"];
|
||||
unset($r["xpat"]);
|
||||
$jpat = json_decode($xpat, true);
|
||||
$r["FullPatientName"] = $jpat["patient_fullname"];
|
||||
$f_bill_detail[] = $r;
|
||||
}
|
||||
$target_url = "http://$targetIP/one-api/keu/titip_tagihan/r_upload";
|
||||
$param = json_encode([
|
||||
"f_bill" => $f_bill,
|
||||
"f_bill_detail" => $f_bill_detail,
|
||||
]);
|
||||
|
||||
$zparam = gzcompress($param, 9);
|
||||
|
||||
$result = $this->post($target_url, $zparam);
|
||||
$j_result = json_decode($result, true);
|
||||
if ($j_result["status"] == "OK") {
|
||||
$sql = "update f_bill_confirm_issue set F_BillConfirmIssueIsSend='Y',
|
||||
F_BillConfirmIssueSendDate = now(),
|
||||
F_BillConfirmIssueConfirmDate = now(),
|
||||
F_BillConfirmIssueIsConfirm = 'S',
|
||||
F_BillConfirmIssueConfirmUserID = ?,
|
||||
F_BillConfirmIssueUserID = ?
|
||||
where F_BillConfirmIssueID =?";
|
||||
$qry = $this->db->query($sql, [$userID, $userID, $id]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error update f_bill_confirm_issue | " .
|
||||
$this->db->error()["message"],
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
echo $result;
|
||||
}
|
||||
function get_param()
|
||||
{
|
||||
$zdata = file_get_contents("php://input");
|
||||
$data = gzuncompress($zdata);
|
||||
$param = json_decode($data, true);
|
||||
if (json_last_error() != JSON_ERROR_NONE) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Json Error : " . json_last_error_msg(),
|
||||
"raw" => $data,
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
return $param;
|
||||
}
|
||||
|
||||
function r_upload()
|
||||
{
|
||||
$param = $this->get_param();
|
||||
$M_BranchID = $param["f_bill"]["M_BranchID"];
|
||||
$M_BranchCode = $param["f_bill"]["M_BranchCode"];
|
||||
$fBillID = $param["f_bill"]["F_BillID"];
|
||||
$sql = "select F_BillID
|
||||
from f_bill_titip
|
||||
where M_BranchID = ? and F_BillID = ? and F_BillIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$M_BranchID, $fBillID]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error check f_bill_titip for $M_BranchCode|$fBillID " .
|
||||
$this->db->error()["message"],
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "f_bill_titip already exists. $M_BranchCode|$fBillID",
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$sql = "select F_BillDetailID
|
||||
from f_bill_titip_detail
|
||||
where M_BranchID = ? and F_BillDetailF_BillID = ? and F_BillDetailIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$M_BranchID, $fBillID]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error check f_bill_titip_detail for $M_BranchCode|$fBillID " .
|
||||
$this->db->error()["message"],
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "f_bill_titip_detail already exists. $M_BranchCode|$fBillID",
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$qry = $this->db->insert("f_bill_titip", $param["f_bill"]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error insert f_bill_titip " .
|
||||
$this->db->error()["message"],
|
||||
]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
foreach ($param["f_bill_detail"] as $r) {
|
||||
$qry = $this->db->insert("f_bill_titip_detail", $r);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
"Error insert f_bill_titip_detail " .
|
||||
$this->db->error()["message"],
|
||||
]);
|
||||
$this->db->trans_rollback();
|
||||
exit();
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
echo json_encode([
|
||||
"status" => "OK",
|
||||
"message" => "F_Bill Success",
|
||||
]);
|
||||
}
|
||||
|
||||
public function post($url, $data)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/text",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_error($ch) != "") {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Http Error : " . curl_error($ch),
|
||||
]);
|
||||
curl_close($ch);
|
||||
exit();
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
titip tagihan utk kirim api :
|
||||
http://localhost/one-api/keu/titip_tagihan/upload/[F_BillConfirmIssueID]/[UserID]
|
||||
|
||||
hasilnya json
|
||||
{
|
||||
"message" : "F_Bill Success",
|
||||
"status" : "OK"
|
||||
}
|
||||
|
||||
Jika status OK maka data akan di titipkan ke table f_bill_titip dan f_bill_titip_detail
|
||||
Jika status ERR message akan berisi informasi tentang kegagalan transfer
|
||||
*/
|
||||
38
application/controllers/keu/ais.http
Normal file
38
application/controllers/keu/ais.http
Normal file
@@ -0,0 +1,38 @@
|
||||
### Variabel Global
|
||||
@baseUrl = https://devcpone.aplikasi.web.id/one-api/keu/ais/
|
||||
@adminApiKey = 7a9b8c7d6e5f4g3h2i1j0k9l8m7n6o5p4q3r2s1t0u9v8w7x6y5z4a3b2c1d0
|
||||
|
||||
### 0. GET Data Branch
|
||||
GET {{baseUrl}}/get_branchs
|
||||
Authorization: Bearer {{adminApiKey}}
|
||||
Accept: application/json
|
||||
|
||||
### 0. GET Data Corporate
|
||||
GET {{baseUrl}}/get_corporates?search=C24070004&limit=10¤t_page=1
|
||||
Authorization: Bearer {{adminApiKey}}
|
||||
Accept: application/json
|
||||
|
||||
### 0. GET Data MCU
|
||||
GET {{baseUrl}}/get_mcus?start_date=2024-07-01&end_date=2025-07-10&limit=10¤t_page=1&search=MGM240700015
|
||||
Authorization: Bearer {{adminApiKey}}
|
||||
Accept: application/json
|
||||
|
||||
### 1. GET Data AIS dengan Filter Default
|
||||
GET {{baseUrl}}/get_data?start_date=2025-01-01&end_date=2025-01-31&limit=10¤t_page=1
|
||||
Authorization: Bearer {{adminApiKey}}
|
||||
Accept: application/json
|
||||
|
||||
### 2. GET Data AIS dengan Filter Corporate Code
|
||||
GET {{baseUrl}}/get_data?start_date=2025-01-01&end_date=2025-01-31&limit=10¤t_page=1&corporate_code=C24070004
|
||||
Authorization: Bearer {{adminApiKey}}
|
||||
Accept: application/json
|
||||
|
||||
### 3. GET Data AIS dengan Filter Branch Code
|
||||
GET {{baseUrl}}/get_data?start_date=2025-01-01&end_date=2025-01-31&limit=10¤t_page=1&branch_code=00001691
|
||||
Authorization: Bearer {{adminApiKey}}
|
||||
Accept: application/json
|
||||
|
||||
### 4. GET Data AIS dengan Filter MCU Number
|
||||
GET {{baseUrl}}/get_data?start_date=2025-01-01&end_date=2025-01-31&limit=10¤t_page=1&mcu_number=MGM250100001
|
||||
Authorization: Bearer {{adminApiKey}}
|
||||
Accept: application/json
|
||||
Reference in New Issue
Block a user