702 lines
31 KiB
PHP
702 lines
31 KiB
PHP
<?php
|
|
|
|
class Order extends MY_Controller
|
|
{
|
|
var $db_regional;
|
|
var $load;
|
|
var $db;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_regional = $this->load->database("regional", true);
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$userID = $this->sys_user['M_UserID'];
|
|
|
|
$sql_cek_token = "SELECT M_UserActiveToken
|
|
from one_mitra.m_user
|
|
WHERE M_UserID = ?
|
|
AND M_UserActiveToken IS NOT NULL";
|
|
|
|
$qry_token = $this->db->query($sql_cek_token, [$userID]);
|
|
if (!$qry_token) {
|
|
$this->sys_error('Invalid token');
|
|
exit;
|
|
}
|
|
|
|
$rows_token = $qry_token->result_array();
|
|
if (count($rows_token) == 0) {
|
|
$this->sys_error('Invalid token');
|
|
exit;
|
|
}
|
|
}
|
|
function getorder()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userID = $this->sys_user['M_UserID'];
|
|
$regionalID = $this->sys_user["M_UserS_RegionalID"];
|
|
// print_r($prm);
|
|
|
|
|
|
$keyword = '%%';
|
|
if (isset($prm['keyword'])) {
|
|
$keyword = '%' . $prm['keyword'] . '%';
|
|
}
|
|
|
|
$page = $prm['page'];
|
|
$rowPerPage = $prm['rpp'];
|
|
$companyID = $prm['company_id'];
|
|
$startDate = $prm['start_date'];
|
|
$endDate = $prm['end_date'];
|
|
|
|
|
|
$start_offset = 0;
|
|
if (isset($prm['page'])) {
|
|
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
|
|
$start_offset = ($page - 1) * intval($rowPerPage);
|
|
}
|
|
}
|
|
$sql_total = "SELECT
|
|
COUNT(T_OrderID) AS total
|
|
FROM one_mitra.t_order
|
|
JOIN one_mitra.m_patient
|
|
ON T_OrderM_PatientID = M_PatientID
|
|
AND M_PatientIsActive = 'Y'
|
|
WHERE T_OrderIsActive = 'Y'
|
|
AND T_OrderDate >= ? AND T_OrderDate <= ?
|
|
AND (T_OrderNumber LIKE ? OR M_PatientName LIKE ?)
|
|
AND T_OrderM_CompanyID = ?
|
|
AND T_OrderS_RegionalID = ?";
|
|
$query_total = $this->db->query($sql_total, [$startDate, $endDate, $keyword, $keyword, $companyID, $regionalID]);
|
|
if (!$query_total) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$totals = $query_total->result_array()[0]['total'];
|
|
// print_r($totals);
|
|
|
|
$sql = "SELECT
|
|
T_OrderID AS order_id,
|
|
T_OrderNumber AS order_number,
|
|
T_OrderM_PatientID AS patient_id,
|
|
M_PatientName AS patient_name,
|
|
DATE_FORMAT(T_OrderDate, '%Y-%m-%d') AS date,
|
|
GROUP_CONCAT(DISTINCT T_OrderDetailTestName SEPARATOR '|') AS tests,
|
|
GROUP_CONCAT(DISTINCT T_OrderDetailPacketName SEPARATOR '|' ) AS packetName,
|
|
IFNULL(T_OrderDetailDeliveryID, 'N') AS status,
|
|
T_OrderM_MouID AS mouID,
|
|
T_OrderIsQRCode AS is_qr,
|
|
T_OrderStatus AS status_pemeriksaan,
|
|
T_OrderStatusQR AS status_qr,
|
|
M_PatientPrefix AS prefix,
|
|
M_PatientSuffix AS suffix,
|
|
M_PatientDOB AS dob,
|
|
M_PatientNIK AS NIK,
|
|
M_PatientNIP AS NIP,
|
|
M_PatientTitleID AS title,
|
|
M_PatientM_SexID AS sexID,
|
|
M_PatientHP AS hp,
|
|
M_PatientJabatan AS jabatan,
|
|
M_PatientKedudukan AS kedudukan,
|
|
M_PatientLocation AS lokasi,
|
|
M_PatientJob AS pekerjaan,
|
|
M_PatientNoRM AS noRM,
|
|
M_PatientAddress AS address,
|
|
T_OrderNote AS note,
|
|
T_OrderDiagnosis AS diagnosis,
|
|
GROUP_CONCAT(DISTINCT T_OrderDetailTestID) AS testsID,
|
|
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailID,'|',T_OrderDetailTestID, '|', T_OrderDetailTestDate)) AS testDetail,
|
|
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailBahanID ,'|',T_OrderDetailBahanNat_BahanID, '|', T_OrderDetailBahanName,'|',T_OrderDetailBahanQty)) AS bahan,
|
|
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailSampleID,'|',T_OrderDetailSampleNat_SampleTypeID, '|',T_OrderDetailSampleName,'|', T_OrderDetailSampleQty)) AS sample,
|
|
GROUP_CONCAT(DISTINCT T_OrderDetailPacketT_PacketID) AS packet,
|
|
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailPacketID, '|', T_OrderDetailPacketT_PacketID )) AS packetDetail
|
|
FROM one_mitra.t_order
|
|
LEFT JOIN one_mitra.t_orderdetail
|
|
ON T_OrderID = T_OrderDetailOrderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
JOIN one_mitra.m_patient
|
|
ON T_OrderM_PatientID = M_PatientID
|
|
AND M_PatientIsActive = 'Y'
|
|
LEFT JOIN one_mitra.t_orderdetaildelivery
|
|
ON T_OrderID = T_OrderDetailDeliveryT_OrderID
|
|
AND T_OrderDetailDeliveryIsActive = 'Y'
|
|
LEFT JOIN one_mitra.t_orderdetailsample
|
|
ON T_OrderID = T_OrderDetailSampleT_OrderID
|
|
AND T_OrderDetailSampleIsActive = 'Y'
|
|
LEFT JOIN one_mitra.t_orderdetailbahan
|
|
ON T_OrderID = T_OrderDetailBahanT_OrderID
|
|
AND T_OrderDetailBahanIsActive = 'Y'
|
|
LEFT JOIN one_mitra.t_orderdetailpacket
|
|
ON T_OrderID = T_OrderDetailPacketOrderID
|
|
AND T_OrderDetailPacketIsActive = 'Y'
|
|
WHERE T_OrderIsActive = 'Y'
|
|
AND T_OrderDate >= ? AND T_OrderDate <= ?
|
|
AND (T_OrderNumber LIKE ? OR M_PatientName LIKE ?)
|
|
AND T_OrderM_CompanyID = ?
|
|
AND T_OrderS_RegionalID = ?
|
|
GROUP BY T_OrderID
|
|
LIMIT ? OFFSET ?";
|
|
$query = $this->db->query($sql, [$startDate, $endDate, $keyword, $keyword, $companyID, $regionalID, intval($rowPerPage), intval($start_offset)]);
|
|
if (!$query) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$search = $query->result_array();
|
|
// print_r($search);
|
|
// packetName
|
|
for ($i = 0; $i < count($search); $i++) {
|
|
$tes = explode('|', $search[$i]['tests']);
|
|
$bahan = explode(',', $search[$i]['bahan']);
|
|
$paket = explode(',', $search[$i]['packet']);
|
|
$paketName = explode('|', $search[$i]['packetName']);
|
|
$sample = explode(',', $search[$i]['sample']);
|
|
$testsID = explode(',', $search[$i]['testsID']);
|
|
$testdetail = explode(',', $search[$i]['testDetail']);
|
|
$packetDetail = explode(',', $search[$i]['packetDetail']);
|
|
$search[$i]['tests'] = array_merge($tes, $paketName);
|
|
$search[$i]['bahan'] = $bahan;
|
|
$search[$i]['sample'] = $sample;
|
|
$search[$i]['testsID'] = $testsID;
|
|
$search[$i]['testDetail'] = $testdetail;
|
|
$search[$i]['packet'] = $paket;
|
|
$search[$i]['packetDetail'] = $packetDetail;
|
|
|
|
$sql = "SELECT
|
|
M_UserMouID as userMouID,
|
|
M_UserMouM_MouID as userMouMouID,
|
|
M_UserMouAliasName as userMouName,
|
|
M_UserMouIsDefault as userMouIsDefault
|
|
FROM one_mitra.m_user_mou
|
|
WHERE M_UserMouM_UserID = ? AND M_UserMouM_MouID = ?";
|
|
$qry = $this->db_regional->query($sql, [$userID, $search[$i]['mouID']]);
|
|
if (!$qry) {
|
|
$this->sys_error('Error get mou');
|
|
exit;
|
|
}
|
|
$mou = $qry->result_array();
|
|
if (count($mou) > 0) {
|
|
$search[$i]['mou'] = $mou[0];
|
|
} else {
|
|
$search[$i]['mou'] = array(
|
|
"userMouID" => "0",
|
|
"userMouMouID" => '0',
|
|
"userMouName" => '',
|
|
"userMouIsDefault" => ''
|
|
);
|
|
}
|
|
// $tes = array_merge($tes, $paketName);
|
|
}
|
|
$result = [
|
|
"data" => $search,
|
|
"total" => $totals,
|
|
"total_page" => ceil($totals / $rowPerPage)
|
|
];
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function editOrder()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$companyID = $this->sys_user["M_UserM_CompanyID"];
|
|
$mouID = $this->sys_user["M_UserM_MouID"];
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$patient = $prm['patient_data'];
|
|
$tests = $prm['tests'];
|
|
$specimens = $prm['specimens'];
|
|
$bahan = $prm['bahan'];
|
|
$orderID = $prm['orderID'];
|
|
$patientID = $prm['patient_id'];
|
|
$paket = $prm['paket'];
|
|
$mouID = $prm['userMouID'];
|
|
// $this->db->trans_begin();
|
|
// $this->db->trans_rollback();
|
|
// $this->db->trans_commit();
|
|
// print_r($this->sys_user);
|
|
// exit;
|
|
$this->db->trans_begin();
|
|
$sql_old = "SELECT DISTINCT
|
|
T_OrderID AS id,
|
|
T_OrderNote AS note,
|
|
T_OrderDiagnosis AS diagnosis,
|
|
T_OrderTotal AS total,
|
|
T_OrderDetailID AS detailID,
|
|
T_OrderDetailTestID AS testID,
|
|
T_OrderDetailTotal AS detailTotal,
|
|
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailID, '|',T_OrderDetailTestID , '|',T_OrderDetailTotal )SEPARATOR '^') AS detail,
|
|
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailBahanID , '|',T_OrderDetailBahanNat_BahanID , '|',T_OrderDetailBahanQty ) SEPARATOR '^') AS bahan,
|
|
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailSampleID , '|',T_OrderDetailSampleNat_SampleTypeID, '|',T_OrderDetailSampleQty)SEPARATOR '^') AS sample,
|
|
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDetailPacketID, '|', T_OrderDetailPacketT_PacketID )) AS packet
|
|
FROM
|
|
one_mitra.t_order
|
|
JOIN one_mitra.t_orderdetail
|
|
ON T_OrderID = T_OrderDetailOrderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
LEFT JOIN one_mitra.t_orderdetailsample
|
|
ON T_OrderID = T_OrderDetailSampleT_OrderID
|
|
AND T_OrderDetailSampleIsActive = 'Y'
|
|
LEFT JOIN one_mitra.t_orderdetailbahan
|
|
ON T_OrderID = T_OrderDetailBahanT_OrderID
|
|
AND T_OrderDetailBahanIsActive = 'Y'
|
|
LEFT JOIN one_mitra.t_orderdetailpacket
|
|
ON T_OrderID = T_OrderDetailPacketOrderID
|
|
AND T_OrderDetailPacketIsActive = 'Y'
|
|
WHERE T_OrderID = ?
|
|
AND T_OrderIsActive = 'Y'";
|
|
$query_old = $this->db->query($sql_old, [$orderID]);
|
|
if (!$query_old) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$rst_old = $query_old->result_array()[0];
|
|
//order detail old
|
|
$detail_old = explode('^', $rst_old['detail']);
|
|
$arr_detail = array();
|
|
$arr_detailID = array();
|
|
for ($i = 0; $i < count($detail_old); $i++) {
|
|
$splitted = explode('|', $detail_old[$i]);
|
|
$arr_detail[] = [
|
|
"id" => $splitted[0],
|
|
"testID" => $splitted[1],
|
|
];
|
|
$arr_detailID[] = $splitted[1];
|
|
}
|
|
$rst_old['detail'] = $arr_detail;
|
|
//sample detail old
|
|
$sample_old = explode('^', $rst_old['sample']);
|
|
$arr_sample = array();
|
|
for ($i = 0; $i < count($sample_old); $i++) {
|
|
$splitted = explode('|', $sample_old[$i]);
|
|
$arr_sample[] = [
|
|
"id" => $splitted[0],
|
|
"sampleID" => $splitted[1],
|
|
"qty" => $splitted[2],
|
|
];
|
|
}
|
|
$rst_old['sample'] = $arr_sample;
|
|
//bahan detail old
|
|
$bahan_old = explode('^', $rst_old['bahan']);
|
|
$arr_bahan = array();
|
|
for ($i = 0; $i < count($bahan_old); $i++) {
|
|
$splitted = explode('|', $bahan_old[$i]);
|
|
$arr_bahan[] = [
|
|
"id" => $splitted[0],
|
|
"bahanID" => $splitted[1],
|
|
"qty" => $splitted[2],
|
|
];
|
|
}
|
|
$rst_old['bahan'] = $arr_bahan;
|
|
//paket detail old
|
|
$paket_old = explode(',', $rst_old['packet']);
|
|
$arr_paket = array();
|
|
for ($i = 0; $i < count($paket_old); $i++) {
|
|
$splitted = explode('|', $paket_old[$i]);
|
|
$arr_paket[] = [
|
|
"id" => $splitted[0],
|
|
"paket_id" => $splitted[1],
|
|
];
|
|
}
|
|
$rst_old['packet'] = $arr_paket;
|
|
|
|
|
|
$this->db->set("T_OrderNote", $patient['note'])
|
|
->set("T_OrderDiagnosis", $patient['diagnosis'])
|
|
->set("T_OrderTotal", intval($prm['total']))
|
|
->set("T_OrderUserID", $userid)
|
|
->set("T_OrderM_MouID", $mouID)
|
|
->where("T_OrderID", $orderID)->update('one_mitra.t_order');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("m_patient rows", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$arr_new_test = array();
|
|
for ($i = 0; $i < count($tests); $i++) {
|
|
$arr_new_test[] = $tests[$i]['id'];
|
|
}
|
|
$arr_sampleIdnew = array();
|
|
for ($i = 0; $i < count($specimens); $i++) {
|
|
$arr_sampleIdnew[] = $specimens[$i]['id'];
|
|
}
|
|
$arr_bahanIdnew = array();
|
|
for ($i = 0; $i < count($bahan); $i++) {
|
|
$arr_bahanIdnew[] = $bahan[$i]['id'];
|
|
}
|
|
$arr_paketIdnew = array();
|
|
for ($i = 0; $i < count($paket); $i++) {
|
|
$arr_paketIdnew[] = $paket[$i]['id'];
|
|
}
|
|
// $this->db->trans_commit();
|
|
|
|
// $this->sys_ok($rst_old);
|
|
// $this->sys_ok(["new test" => $arr_new_test, "old_test" => $arr_detail]);
|
|
// return;
|
|
|
|
//deleted test
|
|
for ($i = 0; $i < count($arr_detail); $i++) {
|
|
//deleted
|
|
if (!in_array($arr_detail[$i]['testID'], $arr_new_test)) {
|
|
$this->db->set("T_OrderDetailIsActive", 'N')
|
|
->where("T_OrderDetailID", $arr_detail[$i]['id'])->update('one_mitra.t_orderdetail');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
//New test
|
|
for ($i = 0; $i < count($tests); $i++) {
|
|
//new
|
|
if ($tests[$i]['detailID'] == 'new') {
|
|
$coba = strtotime($tests[$i]['date']);
|
|
$dt = date('Y-m-d H:i:s', $coba);
|
|
|
|
$order = [
|
|
"T_OrderDetailOrderID" => $orderID,
|
|
"T_OrderDetailTestID" => $tests[$i]['id'],
|
|
"T_OrderDetailTestName" => $tests[$i]['name'],
|
|
"T_OrderDetailTotal" => $tests[$i]['price'],
|
|
"T_OrderDetailTestDate" => $dt,
|
|
"T_OrderDetailUserID" => $userid,
|
|
|
|
];
|
|
|
|
$this->db->insert('one_mitra.t_orderdetail', $order);
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
} else {
|
|
$coba = strtotime($tests[$i]['date']);
|
|
$dt = date('Y-m-d H:i:s', $coba);
|
|
$this->db->set("T_OrderDetailTestDate", $dt)
|
|
->set("T_OrderDetailUserID", $userid)
|
|
->where("T_OrderDetailID", $tests[$i]['detailID'])
|
|
->update('one_mitra.t_orderdetail');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR UPDATE ORDER DETAIL", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
// if (!in_array($tests[$i]['id'], $arr_detailID)) {
|
|
// $coba = strtotime($tests[$i]['date']);
|
|
// $dt = date('Y-m-d H:i:s', $coba);
|
|
|
|
// $order = [
|
|
// "T_OrderDetailOrderID" => $orderID,
|
|
// "T_OrderDetailTestID" => $tests[$i]['id'],
|
|
// "T_OrderDetailTestName" => $tests[$i]['name'],
|
|
// "T_OrderDetailTotal" => $tests[$i]['price'],
|
|
// "T_OrderDetailTestDate" => $dt,
|
|
// "T_OrderDetailUserID" => $userid,
|
|
|
|
// ];
|
|
|
|
// $this->db->insert('one_mitra.t_orderdetail', $order);
|
|
// $err = $this->db->error();
|
|
// if (
|
|
// $err['message'] != ""
|
|
// ) {
|
|
// $this->sys_error_db("ERROR INSERT ORDER DETAIL", $this->db);
|
|
// $this->db->trans_rollback();
|
|
// exit;
|
|
// }
|
|
// }
|
|
}
|
|
|
|
// $this->sys_ok($rst_old);
|
|
// $this->sys_ok(["new sample" => $arr_sampleIdnew, "old_sample" => $arr_sample]);
|
|
// return;
|
|
//deleted sample
|
|
for ($i = 0; $i < count($arr_sample); $i++) {
|
|
if (!in_array($arr_sample[$i]['sampleID'], $arr_sampleIdnew)) {
|
|
$this->db->set("T_OrderDetailSampleIsActive", 'N')
|
|
->where("T_OrderDetailSampleID", $arr_sample[$i]['id'])->update('one_mitra.t_orderdetailsample');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR DELETE ORDER DETAIL SAMPLE", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
//new & updated sample
|
|
for ($i = 0; $i < count($specimens); $i++) {
|
|
if ($specimens[$i]['detailID'] == "new") {
|
|
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
|
$order = [
|
|
"T_OrderDetailSampleT_OrderID" => $orderID,
|
|
"T_OrderDetailSampleNat_SampleTypeID" => $specimens[$i]['id'],
|
|
"T_OrderDetailSampleName" => $specimens[$i]['name'],
|
|
"T_OrderDetailSampleQty" => $specimens[$i]['amount'],
|
|
"T_OrderDetailSampleUserID" => $userid,
|
|
|
|
];
|
|
|
|
$this->db->insert('one_mitra.t_orderdetailsample', $order);
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR INSERT ORDER DETAIL SAMPLE", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
} else {
|
|
if ($specimens[$i]['amount'] != 0 && $specimens[$i]['amount'] != "0" && $specimens[$i]['amount'] != "") {
|
|
$this->db->set("T_OrderDetailSampleQty", $specimens[$i]['amount'])
|
|
->set("T_OrderDetailSampleUserID", $userid)
|
|
->where("T_OrderDetailSampleID", $specimens[$i]['detailID'])
|
|
->update('one_mitra.t_orderdetailsample');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR UPDATE ORDER DETAIL SAMPLE", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
} else {
|
|
if (!in_array($arr_sample[$i]['sampleID'], $arr_sampleIdnew)) {
|
|
$this->db->set("T_OrderDetailSampleIsActive", 'N')
|
|
->where("T_OrderDetailSampleID", $specimens[$i]['detailID'])
|
|
->update('one_mitra.t_orderdetailsample');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR DELETE ORDER DETAIL SAMPLE", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//deleted bahan
|
|
for ($i = 0; $i < count($arr_bahan); $i++) {
|
|
if (!in_array($arr_bahan[$i]['bahanID'], $arr_bahanIdnew)) {
|
|
$this->db->set("T_OrderDetailBahanIsActive", 'N')
|
|
->where("T_OrderDetailBahanID", $arr_bahan[$i]['id'])->update('one_mitra.t_orderdetailbahan');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR DELETE ORDER DETAIL BAHAN", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
//new and update bahan
|
|
for ($i = 0; $i < count($bahan); $i++) {
|
|
if ($bahan[$i]['detailID'] == "new") {
|
|
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
|
|
|
$order = [
|
|
"T_OrderDetailBahanT_OrderID" => $orderID,
|
|
"T_OrderDetailBahanNat_BahanID" => $bahan[$i]['id'],
|
|
"T_OrderDetailBahanName" => $bahan[$i]['name'],
|
|
"T_OrderDetailBahanQty" => $bahan[$i]['amount'],
|
|
"T_OrderDetailBahanUserID" => $userid,
|
|
|
|
];
|
|
|
|
$this->db->insert('one_mitra.t_orderdetailbahan', $order);
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR INSERT ORDER DETAIL BAHAN", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
} else {
|
|
if ($bahan[$i]['amount'] != 0 && $bahan[$i]['amount'] != "0" && $bahan[$i]['amount'] != "") {
|
|
$this->db->set("T_OrderDetailBahanQty", $bahan[$i]['amount'])
|
|
->set("T_OrderDetailBahanUserID", $userid)
|
|
->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])
|
|
->update('one_mitra.t_orderdetailbahan');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR UPDATE ORDER DETAIL BAHAN", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
} else {
|
|
$this->db->set("T_OrderDetailBahanIsActive", 'N')
|
|
->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])->update('one_mitra.t_orderdetailbahan');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR DELETE ORDER DETAIL BAHAN", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//deleted paket
|
|
for ($i = 0; $i < count($arr_paket); $i++) {
|
|
if (!in_array($arr_paket[$i]['paket_id'], $arr_paketIdnew)) {
|
|
$this->db->set("T_OrderDetailPacketIsActive", 'N')
|
|
->where("T_OrderDetailPacketID", $arr_paket[$i]['id'])->update('one_mitra.t_orderdetailpacket');
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR DELETE PACKET DETAIL ", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
//new and paket
|
|
for ($i = 0; $i < count($paket); $i++) {
|
|
if ($paket[$i]['detail_id'] == "new") {
|
|
$order = [
|
|
"T_OrderDetailPacketOrderID" => $orderID,
|
|
"T_OrderDetailPacketT_PacketID" => $paket[$i]['id'],
|
|
"T_OrderDetailPacketName" => $paket[$i]['name'],
|
|
"T_OrderDetailPacketUserID" => $userid,
|
|
"T_OrderDetailPacketPrice" => $paket[$i]['price'],
|
|
"T_OrderDetailPacketT_PacketType" => $paket[$i]["type"],
|
|
|
|
];
|
|
|
|
$this->db->insert('one_mitra.t_orderdetailpacket', $order);
|
|
$err = $this->db->error();
|
|
if (
|
|
$err['message'] != ""
|
|
) {
|
|
$this->sys_error_db("ERROR INSERT ORDER DETAIL PAKET", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
// else {
|
|
|
|
// $this->db->set("T_OrderDetailBahanQty", $bahan[$i]['amount'])
|
|
// ->set("T_OrderDetailBahanUserID", $userid)
|
|
// ->where("T_OrderDetailBahanID", $bahan[$i]['detailID'])
|
|
// ->update('one_mitra.t_orderdetailbahan');
|
|
// $err = $this->db->error();
|
|
// if (
|
|
// $err['message'] != ""
|
|
// ) {
|
|
// $this->sys_error_db("ERROR UPDATE ORDER DETAIL BAHAN", $this->db);
|
|
// $this->db->trans_rollback();
|
|
// exit;
|
|
// }
|
|
// }
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
|
|
$this->sys_ok("OK");
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function cancel()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$sql = "SELECT T_OrderDetailDeliveryID AS CEK
|
|
FROM one_mitra.t_orderdetaildelivery
|
|
WHERE T_OrderDetailDeliveryT_OrderID = ?
|
|
AND T_OrderDetailDeliveryIsActive = 'Y'
|
|
";
|
|
$query = $this->db->query($sql, [$prm['id']]);
|
|
if (!$query) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$cek = $query->result_array();
|
|
if (count($cek) == 0) {
|
|
# code...
|
|
$this->db->trans_begin();
|
|
$sql = "UPDATE one_mitra.t_order SET T_OrderIsActive = 'N'
|
|
WHERE T_OrderID = ?;
|
|
";
|
|
$query = $this->db->query($sql, [$prm['id']]);
|
|
if (!$query) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
$sql = "UPDATE one_mitra.t_orderdetail SET T_OrderDetailIsActive = 'N'
|
|
WHERE T_OrderDetailOrderID = ?;
|
|
";
|
|
$query = $this->db->query($sql, [$prm['id']]);
|
|
if (!$query) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$this->sys_ok("ok");
|
|
} else {
|
|
$this->sys_ok("Sudah di buat surat jalan");
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|