651 lines
23 KiB
PHP
651 lines
23 KiB
PHP
<?php
|
|
|
|
class Payment extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
public function index()
|
|
{
|
|
echo "Doctor API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
$this->IP_SOCKET_IO = "localhost";
|
|
}
|
|
|
|
public function get_order()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$rst = ["order_header" => [], "order_detail" => [], "order_delivery" => []];
|
|
|
|
$sql = "
|
|
select T_OrderHeaderID as order_id,
|
|
T_OrderHeaderLabNumber as order_no,
|
|
T_OrderHeaderDate as order_date,
|
|
T_OrderHeaderSubTotal as order_subtotal,
|
|
T_OrderHeaderRounding as order_rounding,
|
|
T_OrderHeaderTotal as order_total,
|
|
concat(if(M_TitleID is null, '', concat(M_TitleName, ' ')), M_PatientName) as patient_name,
|
|
M_PatientNoReg as patient_mr,
|
|
M_MouName as order_mou,
|
|
M_CompanyName as order_company,
|
|
fn_global_doctor_name(da.M_DoctorID) doctor_sender,
|
|
fn_global_doctor_name(db.M_DoctorID) doctor_pj,
|
|
fn_global_doctor_address(aa.M_DoctorAddressID, 1) doctor_sender_address,
|
|
M_MouIsBill M_CompanyIsBill, M_MouMinDP M_CompanyMinDP,
|
|
M_MouIsAgingOnHold M_CompanyIsAgingOnHold, M_MouIsAgingOnHoldNote M_CompanyIsAgingOnHoldNote
|
|
from t_orderheader
|
|
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
|
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID
|
|
join m_mou on T_OrderHeaderM_MouID = M_MouID
|
|
join m_doctor da on T_OrderHeaderSenderM_DoctorID = da.M_DoctorID
|
|
join m_doctoraddress aa on T_OrderHeaderSenderM_DoctorAddressID = aa.M_DoctorAddressID
|
|
join m_doctor db on T_OrderHeaderSenderM_DoctorID = db.M_DoctorID
|
|
left join m_title on m_patientm_titleid = m_titleid
|
|
where T_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, array($prm['id']));
|
|
if ($query) {
|
|
$rows = (array) $query->row();
|
|
$rst['order_header'] = $rows;
|
|
// $result = array("status" => "OK" , "data" => $rst);
|
|
// $this->sys_ok($result);
|
|
// exit;
|
|
} else {
|
|
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$sql = "CALL sp_fo_payment_get_delivery('{$prm['id']}')";
|
|
$query = $this->db_smartone->query($sql);
|
|
$this->clean_mysqli_connection($this->db_smartone->conn_id);
|
|
|
|
if ($query) {
|
|
$rows = $query->row();
|
|
$rst['order_delivery'] = json_decode($rows->delivery);
|
|
// $result = array("status" => "OK" , "data" => $rst);
|
|
// $this->sys_ok($result);
|
|
// exit;
|
|
} else {
|
|
$this->sys_error_db("m_doctoraddress delivery ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
// { n:1, d_id:1, t_id:1, t_name:'SGOT', t_price:80000, t_disctotal:7000, t_total:73000 },
|
|
// { n:2, d_id:2, t_id:2, t_name:'SGPT', t_price:75000, t_disctotal:8000, t_total:67000 }
|
|
// T_OrderDetailPrice double [0]
|
|
// T_OrderDetailPriceForDisc double [0]
|
|
// T_OrderDetailDisc double [0]
|
|
// T_OrderDetailDiscAmount double [0]
|
|
// T_OrderDetailTotal
|
|
|
|
$sql = "
|
|
select T_OrderDetailID as d_id,
|
|
T_OrderDetailT_TestID as t_id,
|
|
IFNULL(T_OrderDetailT_TestName, T_PacketName) as t_name,
|
|
T_OrderDetailPrice as t_price,
|
|
T_OrderDetailDiscTotal as t_disctotal,
|
|
T_OrderDetailTotal as t_total
|
|
from t_orderdetail
|
|
join t_orderdetailaddon on T_OrderDetailAddOnT_OrderDetailID = T_OrderDetailID
|
|
left join t_test on t_orderdetailt_testid = t_testid
|
|
left join t_packet on t_orderdetailaddonispacket = 'Y' and t_orderdetailaddont_packetid = t_packetid
|
|
where T_OrderDetailT_OrderHeaderID = ?
|
|
and T_ORderDetailIsActive = 'Y'
|
|
and ((T_ORderDetailAddOnIsPacket = 'N' AND T_TestIsPrintNota = 'Y' AND T_OrderDetailT_TestIsPanelChildren = 'N')
|
|
OR (T_OrderDetailT_TestIsPanelChildren = 'Y' AND T_OrderDetailT_TestIsPanelChildrenPrintNota = 'Y')
|
|
OR (T_ORderDetailAddOnIsPacket = 'Y' AND T_PacketIsNOta = 'Y'))";
|
|
|
|
$query = $this->db_smartone->query($sql, array($prm['id']));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$rst['order_detail'] = $rows;
|
|
|
|
$result = array("status" => "OK", "data" => $rst);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} else {
|
|
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 100;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '') {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select count(*) total
|
|
from
|
|
m_paymenttype
|
|
where M_PaymentTypeIsActive = 'Y'
|
|
and M_PaymentTypeName like ?";
|
|
$query = $this->db_smartone->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("m_paymenttype count", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select M_PaymentTypeID payment_type_id, M_PaymentTypeName payment_type_name, M_PaymentTypeCode payment_type_code,
|
|
0 payment_amount, '' payment_note, 'Nomor Kartu' payment_note_label, 'N' payment_enable,
|
|
0 payment_change, 0 payment_actual, 0 payment_card_id, 0 payment_edc_id, 0 payment_account_id
|
|
from m_paymenttype
|
|
where M_PaymentTypeIsActive = 'Y'
|
|
and M_PaymentTypeName like ?";
|
|
$query = $this->db_smartone->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
foreach ($rows as $k => $v) {
|
|
|
|
if ($v['payment_type_code'] == 'CASH')
|
|
$v['payment_note_label'] = 'Kembali';
|
|
if ($v['payment_type_code'] == 'VOUCHER')
|
|
$v['payment_note_label'] = 'Nomor Voucher';
|
|
|
|
$rows[$k] = $v;
|
|
}
|
|
|
|
$result = $rows;
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_paymenttype rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function save()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$payment_json = json_encode($prm['payments']);
|
|
$company_id = $prm['company_id'];
|
|
$mou_id =$prm['mou_id'];
|
|
|
|
$sql = "CALL sp_fo_payment('{$prm['order_id']}', '{$payment_json}', '{$this->sys_user['M_UserID']}');";
|
|
$query = $this->db_smartone->query($sql);
|
|
|
|
if ($query) {
|
|
$rst = $query->row();
|
|
$rst->data = json_decode($rst->data);
|
|
$paymentId = $rst->data->payment_id;
|
|
|
|
foreach($prm['payments'] as $k => $v){
|
|
if($v['payment_enable'] == 'Y' && $v['payment_type_code'] == 'VOUCHER'){
|
|
$this->insert_voucher_payment($prm['order_id'], $paymentId, $company_id, $mou_id, $xuserid);
|
|
}
|
|
}
|
|
|
|
// get discount member
|
|
$sqldisc = "SELECT
|
|
T_OrderMemberDiscountID,
|
|
T_OrderMemberDiscountT_OrderHeaderID,
|
|
T_OrderMemberDiscountBruto,
|
|
T_OrderMemberDiscountNetto,
|
|
T_OrderMemberDiscountPercent
|
|
FROM t_ordermemberdiscount
|
|
WHERE T_OrderMemberDiscountT_OrderHeaderID = ?";
|
|
$discdata = $this->db_onedev->query($sqldisc, array($prm['order_id']));
|
|
if (!$discdata) {
|
|
$this->sys_error_db("t_ordermemberdiscount get");
|
|
exit;
|
|
}
|
|
$discount = $discdata->result_array();
|
|
|
|
if (count($discount) > 0) {
|
|
$sqldisc = "INSERT INTO f_memberdiscount(
|
|
F_MemberDiscountF_PaymentID,
|
|
T_OrderMemberDiscountID,
|
|
T_OrderMemberDiscountT_OrderHeaderID,
|
|
T_OrderMemberDiscountBruto,
|
|
T_OrderMemberDiscountNetto,
|
|
T_OrderMemberDiscountPercent,
|
|
T_OrderMemberDiscountCreated,
|
|
T_OrderMemberDiscountCreatedUserID
|
|
) VALUES (?,?,?,?,?,?,NOW(),?)";
|
|
$disc = $this->db_onedev->query($sqldisc, array(
|
|
$paymentId,
|
|
$discount[0]['T_OrderMemberDiscountID'],
|
|
$discount[0]['T_OrderMemberDiscountT_OrderHeaderID'],
|
|
$discount[0]['T_OrderMemberDiscountBruto'],
|
|
$discount[0]['T_OrderMemberDiscountNetto'],
|
|
$discount[0]['T_OrderMemberDiscountPercent'],
|
|
$this->sys_user['M_UserID']
|
|
));
|
|
|
|
if (!$disc) {
|
|
$this->sys_error_db("f_memberdiscount insert");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
echo json_encode($rst);
|
|
} else {
|
|
$this->sys_error_db("save payment", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function endshowtime()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$sql = "UPDATE t_orderheaderaddon SET
|
|
T_OrderHeaderAddonFoTimeStart = ?,
|
|
T_OrderHeaderAddonFoTimeEnd = NOW()
|
|
WHERE
|
|
T_OrderHeaderAddOnT_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, array($prm['time_start'], $prm['order_id']));
|
|
//echo $sql;
|
|
if ($query) {
|
|
$sql = "UPDATE antrione.queue_status SET queueStatusDone = NOW() WHERE queueStatusQueueID = ?";
|
|
$this->db_smartone->query($sql, array($prm['queue_id']));
|
|
$sql = "SELECT * FROM antrione.queue WHERE queueID = ? LIMIT 1";
|
|
$data_queue = $this->db_smartone->query($sql, array($prm['queue_id']))->row_array();
|
|
$sql = "INSERT INTO antrione.queuelog(
|
|
queueLogDate,
|
|
queueLogStatusID,
|
|
queueLogCounterID
|
|
)
|
|
VALUES(
|
|
NOW(),
|
|
4,
|
|
?
|
|
)";
|
|
$this->db_smartone->query($sql, array($data_queue['queueCounterID']));
|
|
//echo $sql;
|
|
$last_logid = $this->db_smartone->insert_id();
|
|
//echo $last_logid ;
|
|
$sql = "UPDATE antrione.queue SET queueQueueLogID = ? ,queueStatusID = 4 WHERE queueID = ?";
|
|
$this->db_smartone->query($sql, array($last_logid, $prm['queue_id']));
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
$sql_get_sID = "SELECT queueServiceID as serviceID, queueCounterID as counterID FROM antrione.queue WHERE queueID = ?";
|
|
$qry_get_sID = $this->db_smartone->query($sql_get_sID, [$prm['queue_id']]);
|
|
|
|
//$last_qry = $this->db_smartone->last_query();
|
|
|
|
$data = $qry_get_sID->row_array();
|
|
$serviceID = $data['serviceID'];
|
|
$counterID = $data['counterID'];
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/done.fo.$serviceID.$counterID");
|
|
exit;
|
|
} else {
|
|
$this->sys_error_db("save payment error", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_bank()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
if (isset($prm['card'])) {
|
|
$sql = "SELECT Nat_BankID, Nat_BankName
|
|
FROM nat_bank WHERE Nat_BankIsCard = 'Y' ORDER BY Nat_BankName ASC";
|
|
$query = $this->db_smartone->query($sql);
|
|
} else if (isset($prm['edc'])) {
|
|
$sql = "SELECT Nat_BankID, Nat_BankName
|
|
FROM nat_bank WHERE Nat_BankIsEDC = 'Y' ORDER BY Nat_BankName ASC";
|
|
$query = $this->db_smartone->query($sql);
|
|
} else {
|
|
$sql = "SELECT Nat_BankID, Nat_BankName
|
|
FROM nat_bank ORDER BY Nat_BankName ASC";
|
|
$query = $this->db_smartone->query($sql);
|
|
}
|
|
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$this->sys_ok(["records" => $rows, "total" => sizeof($rows), "q" => $this->db_smartone->last_query()]);
|
|
} else {
|
|
$this->sys_error_db("NAT BANK", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function getLocations()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$station_location = [];
|
|
$locations = [];
|
|
$sql = "SELECT T_OrderDetailT_OrderHeaderID as order_id, T_SampleStationID as station_id, T_SampleStationName as station_name,
|
|
fn_get_location(T_SampleStationID,T_OrderDetailT_OrderHeaderID) as location_id, '' locations
|
|
FROM (
|
|
SELECT distinct T_OrderDetailT_OrderHeaderID,T_SampleStationID, T_SampleStationName
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_SampleTypeID = T_TestT_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID
|
|
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
|
|
|
|
) x";
|
|
$query = $this->db_smartone->query($sql, array($prm['order_id']));
|
|
if ($query) {
|
|
$datas = $query->result_array();
|
|
foreach ($datas as $key => $value) {
|
|
$sql = "SELECT M_LocationID as location_id, M_LocationName as location_name FROM m_location WHERE M_LocationT_SampleStationID = ? AND M_LocationIsActive = 'Y' ";
|
|
$query = $this->db_smartone->query($sql, array($value['station_id']));
|
|
if ($query) {
|
|
$datas[$key]['locations'] = $query->result_array();
|
|
} else {
|
|
$datas[$key]['locations'] = [];
|
|
}
|
|
}
|
|
$this->sys_ok(["datas" => $datas]);
|
|
} else {
|
|
echo $this->db_smartone->last_query();
|
|
$this->sys_error_db("gagal ambil data", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function save_control()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
if ($prm['data'] && count($prm['data']) > 0) {
|
|
foreach ($prm['data'] as $key => $value) {
|
|
$sql = "INSERT INTO t_order_location (
|
|
T_OrderLocationT_OrderHeaderID,
|
|
T_OrderLocationM_LocationID,
|
|
T_OrderLocationT_SampleStationID,
|
|
T_OrderLocationCreated,
|
|
T_OrderLocationLastUpdated,
|
|
T_OrderLocationUserID
|
|
)
|
|
VALUES (?,?,?,NOW(),NOW(),?)
|
|
ON DUPLICATE KEY
|
|
UPDATE T_OrderLocationT_OrderHeaderID = ?,
|
|
T_OrderLocationM_LocationID = ?,
|
|
T_OrderLocationT_SampleStationID = ?,
|
|
T_OrderLocationLastUpdated = NOW(),
|
|
T_OrderLocationUserID = ?";
|
|
$query = $this->db_smartone->query($sql, array($value['order_id'], $value['location_id'], $value['station_id'], $userid, $value['order_id'], $value['location_id'], $value['station_id'], $userid));
|
|
}
|
|
$this->sys_ok(["datas" => '']);
|
|
} else {
|
|
$this->sys_error_db("data not valid", $this->db_smartone);
|
|
exit;
|
|
}
|
|
//echo $sql;
|
|
|
|
|
|
}
|
|
|
|
function lookup_point()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT
|
|
MemberInfoNasionalNIK,
|
|
MemberInfoNasionalPoint
|
|
FROM one_pointreward.member_infonational
|
|
WHERE
|
|
MemberInfoNasionalNIK = ?";
|
|
$query = $this->db_smartone->query($sql, array($prm['nik']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$data = array(
|
|
"nik" => $rows[0]['MemberInfoNasionalNIK'] ?? 0,
|
|
"amount" => $rows[0]['MemberInfoNasionalPoint'] ?? 0
|
|
);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $data
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
|
|
} else {
|
|
$this->sys_error_db("lookup point", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function lookup_discounted()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT
|
|
IFNULL(T_OrderMemberDiscountBruto, 0) as T_OrderMemberDiscountBruto,
|
|
IFNULL(T_OrderMemberDiscountNetto, 0) as T_OrderMemberDiscountNetto,
|
|
IFNULL(T_OrderMemberDiscountPercent, 'X') as T_OrderMemberDiscountPercent
|
|
FROM t_ordermemberdiscount
|
|
WHERE T_OrderMemberDiscountT_OrderHeaderID = ?";
|
|
|
|
$query = $this->db_smartone->query($sql, array($prm['order_id']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$data = array(
|
|
"T_OrderMemberDiscountBruto" => $rows[0]['T_OrderMemberDiscountBruto'] ?? 0,
|
|
"T_OrderMemberDiscountNetto" => $rows[0]['T_OrderMemberDiscountNetto'] ?? 0,
|
|
"T_OrderMemberDiscountPercent" => $rows[0]['T_OrderMemberDiscountPercent'] ?? "X",
|
|
);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $data
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
|
|
} else {
|
|
$this->sys_error_db("lookup point", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function update_point()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$nik = $prm['nik'];
|
|
$amount_left = $prm['amount_left'];
|
|
|
|
$sql = "UPDATE one_pointreward.member_infonational
|
|
SET MemberInfoNasionalPoint = ?
|
|
WHERE MemberInfoNasionalNIK = ?";
|
|
$query = $this->db_smartone->query($sql, array($amount_left, $nik));
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("update point", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$this->lookup_point();
|
|
}
|
|
|
|
function lookup_detail_payment()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT
|
|
F_PaymentID,
|
|
F_PaymentNumber,
|
|
F_PaymentTotal,
|
|
F_PaymentNote,
|
|
F_PaymentDetailM_PaymentTypeID,
|
|
F_PaymentDetailNote,
|
|
F_PaymentDetailAmount,
|
|
F_PaymentDetailActual,
|
|
F_PaymentDetailChange
|
|
FROM f_payment
|
|
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
|
|
WHERE F_PaymentT_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, array($prm['orderheaderid']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$this->sys_ok($rows);
|
|
} else {
|
|
$this->sys_error_db("update point", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
function lookup_company()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$qp = [
|
|
'keyword' => '%'
|
|
];
|
|
|
|
$prm = $this->sys_input;
|
|
$keyword = $prm['keyword'];
|
|
|
|
if ($keyword != '') {
|
|
$qp['keyword'] = "%{$keyword}%";
|
|
}
|
|
|
|
$sql = "SELECT
|
|
M_CompanyID, M_CompanyName,
|
|
IFNULL( concat('[', group_concat( json_object('M_MouID', M_MouID, 'M_MouName', CONCAT(M_MouName,' (',M_MouNumber,')'), 'M_MouStartDate', M_MouStartDate, 'M_MouEndDate', M_MouEndDate, 'M_MouNote', M_MouNote, 'M_MouIsBill', M_MouIsBill, 'M_MouEmail', M_MouEmail, 'M_MouIsDefault', M_MouIsDefault, 'M_MouEmailIsDefault', M_MouEmailIsDefault, 'delivery_email_code', `fn_fo_delivery_code`('MOU', 'EMAIL', '0')) ), ']'), '[]') as mou
|
|
from m_company
|
|
join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
|
|
and M_MouIsApproved = 'Y'
|
|
-- and M_MouStartDate <= date(now()) and M_MouEndDate >= date(now())
|
|
AND M_MouIsReleased = 'Y'
|
|
join m_mouaddon on M_MouAddonM_MouID = M_MouID and M_MouAddonIsVoucher = 'Y' and M_MouAddonIsActive = 'Y'
|
|
where M_CompanyIsActive = 'Y' and M_CompanyName LIKE ?
|
|
group by m_companyid
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql, array($qp['keyword']));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
foreach ($rows as $key => $value) {
|
|
$rows[$key]['mou'] = json_decode($value['mou']);
|
|
}
|
|
|
|
$result = array(
|
|
"total" => sizeof($rows),
|
|
"records" => $rows,
|
|
"total_display" => sizeof($rows)
|
|
);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("lookup_company", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function insert_voucher_payment($orderheaderID, $paymentID, $companyID, $mouID, $userID)
|
|
{
|
|
|
|
$sql = "INSERT INTO f_payment_voucher(
|
|
F_Payment_VoucherT_OrderHeaderID,
|
|
F_Payment_VoucherF_PaymentID,
|
|
F_Payment_VoucherM_CompanyID,
|
|
F_Payment_VoucherM_MouID,
|
|
F_Payment_VoucherCreated,
|
|
F_Payment_VoucherUserID
|
|
) VALUES (?, ?, ?, ?, NOW(), ?)
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($orderheaderID, $paymentID, $companyID, $mouID, $userID));
|
|
if (!$query) {
|
|
$this->sys_error_db("error insert f payment voucher");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/*function endshowtime()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$sql = "UPDATE t_orderheaderaddon SET
|
|
T_OrderHeaderAddonFoTimeStart = ?,
|
|
T_OrderHeaderAddonFoTimeEnd = NOW()
|
|
WHERE
|
|
T_OrderHeaderAddOnT_OrderHeaderID = ?";
|
|
|
|
$query = $this->db_smartone->query($sql,array($prm['time_start'],$prm['order_id']));
|
|
if ($query)
|
|
{
|
|
$this->sys_ok(["records"=>array(), "q"=>'']);
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error_db("NAT BANK",$this->db_smartone);
|
|
exit;
|
|
}
|
|
}*/
|
|
}
|