db_regional = $this->load->database("regional", true); $this->load->helper(array('form', 'url')); } function lookupmou() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $search = $prm['search']; $number_offset = 0; $number_limit = 10; if ($prm["current_page"] > 0) { $number_offset = ($prm["current_page"] - 1) * $number_limit; } $sql_select = "select M_MouID as id, M_MouM_CompanyID as companyid, 0 as countprice, M_MouName as name, M_MouStartDate, M_MouEndDate, DATE_FORMAT(M_MouStartDate,'%d%m%Y') as startdate, DATE_FORMAT(M_MouEndDate,'%d%m%Y') as enddate, CONCAT(DATE_FORMAT(M_MouStartDate,'%d-%m-%Y'), ' s/d ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as periode, M_MouIsBill as isbill, M_MouRefNumber as refnumber, M_MouNumber as number, CONCAT(M_MouNumber, ' [',M_MouBase, ']') as numberx, CONCAT(M_MouName, ' [',M_OmzetTypeName, ']') as namex, M_MouIsDefault as isdefault, M_MouIsUsingFavourite as isfavorit, M_MouJpaIsNetto as isjpanetto, M_MouIsMcu as ismcu, M_MouIsOnline as isonline, M_MouIsApproved as isapproved, M_MouIsAgingOnHold as isaging, M_MouEmailIsDefault as isemail, M_MouMinDP as mindp, IFNULL(M_MouIsAgingOnHoldNote,'') as agingnote, M_MouAgingDay as agingday, M_MouNote as xnote, IFNULL(M_MouEmail,'') as mouemail, IF(M_MouIsBill = 'Y','Pakai Billing','Tidak Pakai Billing') as bill, M_MouBase as baseid, M_MouBase as basename, M_MouM_OmzetTypeID, M_OmzetTypeID, M_OmzetTypeName, M_MouM_MouTypeID, M_MouTypeID, M_MouTypeName, M_AgingTypeID, M_AgingTypeName, M_MouIsVerified as isverified, M_MouAllowVerify as isallowverified, IF(v.M_UserFullName IS NULL,'',DATE_FORMAT(M_MouVerifyDate,'%d-%m-%Y %h:%i:%s')) as verifydate, M_MouVerifyUserID, IFNULL(v.M_UserFullName,'') as verifyuser, IF(v.M_UserFullName IS NULL, '', CONCAT(DATE_FORMAT(M_MouVerifyDate,'%d-%m-%Y %h:%i:%s'),'\r',v.M_UserFullName)) as verify, M_MouIsReleased as isreleased, IF(r.M_UserFullName IS NULL,'',DATE_FORMAT(M_MouReleaseDate,'%d-%m-%Y %h:%i:%s')) as releasedate, M_MouReleaseUserID, IFNULL(r.M_UserFullName,'') as releaseuser, IF(r.M_UserFullName IS NULL, '', CONCAT(DATE_FORMAT(M_MouReleaseDate,'%d-%m-%Y %h:%i:%s'),'\r',r.M_UserFullName)) as released, M_MouIsConfirm as isconfirm, 'xxx' as action, CASE WHEN M_MouStatus = 'N' THEN 'Baru' WHEN M_MouStatus = 'V' THEN 'Verified' WHEN M_MouStatus = 'UV' THEN 'Unverified' WHEN M_MouStatus = 'R' THEN 'Released' WHEN M_MouStatus = 'C' THEN 'Baru (Konfirmasi)' ELSE 'Unreleased' END as aksi, 'xxx' as statuss, M_MouJpa1Name, M_MouJpa1Percent, M_MouJpa2Name, M_MouJpa2Percent, M_MouJpa3Name, M_MouJpa3Percent, M_MouJpa4Name, M_MouJpa4Percent, M_MouStatus as status, M_MouPicBillName as picname, M_MouPicBillHandphone as pichp, M_MouFinanceName as fincname, M_MouFinanceHandphone as finchp, IFNULL(M_MouPicBillEmail,'') as mouemailpic, IFNULL(M_MouFinanceEmail,'') as mouemailfinc, M_MouM_BillTypeID, M_BillTypeID, M_BillTypeName, M_MouM_BranchBillID, M_BranchID, M_BranchName, 'N' as isnasional, M_MouEresultPersonal as iserpersonal, M_MouEresultCompany as isercompany, IFNULL(M_MouAddonIsVoucher,'N') as isvoucher, IFNULL(M_MouAddonIsAcuanHarga,'N') as isacuanharga, M_MouAddonNat_StaffID, Nat_StaffID M_StaffID, Nat_StaffName M_StaffName, M_MouAddonAddressResult, M_MouAddonAddressBill, M_MouAddonNoteResult, M_MouAddonNoteBill, M_MouAddonNoteResult xnoteresult, M_MouAddonNoteBill xnotebill, M_MouJpa1Amount, M_MouJpa2Amount, M_MouJpa3Amount, M_MouJpa4Amount from m_mou LEFT JOIN m_omzettype ON M_MouM_OmzetTypeID = M_OmzetTypeID LEFT JOIN m_billtype ON M_MouM_BillTypeID = M_BillTypeID LEFT JOIN m_branch ON M_MouM_BranchBillID = M_BranchID LEFT JOIN m_moutype ON M_MouM_MouTypeID = M_MouTypeID LEFT JOIN m_agingtype ON M_MouM_AgingTypeID = M_AgingTypeID LEFT join m_user v ON M_MouVerifyUserID = v.M_UserID LEFT join m_user r ON M_MouReleaseUserID = r.M_UserID LEFT JOIN m_mouaddon ON M_MouAddonM_MouID = M_MouID AND M_MouAddonIsActive = 'Y' LEFT JOIN nat_staff ON Nat_StaffID = M_MouAddonNat_StaffID where M_MouM_CompanyID = {$id} AND M_MouIsActive = 'Y' AND M_MouStatus <> 'N' AND M_MouIsOnline = 'N' AND (M_MouName LIKE CONCAT('%','{$search}','%') OR M_MouNumber LIKE CONCAT('%','{$search}','%') ) GROUP BY M_MouID ORDER BY M_MouID DESC"; // echo $sql; $sql_filter = "SELECT COUNT(*) as total FROM ($sql_select) as x"; $qry_filter = $this->db_regional->query($sql_filter); $tot_count = 0; $tot_page = 0; if ($qry_filter) { $tot_count = $qry_filter->result_array()[0]["total"]; $tot_page = ceil($tot_count / $number_limit); } else { $this->sys_error_db("mou count error", $this->db_regional); exit; } $sql = $sql_select . " LIMIT $number_limit OFFSET $number_offset"; $query = $this->db_regional->query($sql); // echo $this->db_regional->last_query(); // exit; $rows = $query->result_array(); if ($rows) { foreach ($rows as $k => $v) { $x = $this->db_regional->query("select concat( '[', group_concat( json_object('id', G_MouStatusLogID, 'status', CASE WHEN G_MouStatusLogStatus = 'N' THEN 'Baru' WHEN G_MouStatusLogStatus = 'V' THEN 'Verified' WHEN G_MouStatusLogStatus = 'UV' THEN 'Unverified' WHEN G_MouStatusLogStatus = 'R' THEN 'Released' WHEN G_MouStatusLogStatus = 'C' THEN 'Baru (Konfirmasi)' ELSE 'Unreleased' END, 'waktu', DATE_FORMAT(G_MouStatusLogCreated,'%d-%m-%Y %H:%i'), 'user' , M_UserUsername) separator ',' ), ']' ) as n from g_moustatuslog LEFT JOIN m_user ON G_MouStatusLogUserID = M_UserID LEFT JOIN nat_staff ON M_UserM_StaffID = Nat_StaffID WHERE G_MouStatusLogM_MouID = '{$v['id']}' AND G_MouStatusLogIsActive = 'Y'")->row(); $rows[$k]['statuss'] = json_decode($x->n); $cp = $this->db_regional->query("SELECT IFNULL(COUNT(T_PriceID),0) as n FROM t_price WHERE T_PriceM_MouID = '{$v['id']}' AND T_PriceIsActive = 'Y' GROUP BY T_PriceM_MouID")->row(); $rows[$k]['countprice'] = isset($cp->n) && !empty($cp->n) ? $cp->n : 0; $isnasional = $this->db_regional->query("SELECT IF(NasCom_M_MouID IS NULL,'N','Y') as isnasional FROM nas_com_m_mou WHERE NasCom_M_MouNewID = '{$v['id']}'")->row(); //echo $this->db_regional->last_query(); $rows[$k]['isnasional'] = $isnasional->isnasional; if ($rows[$k]['isnasional'] == null) { $rows[$k]['isnasional'] = 'N'; } } } $result = array("total_page" => $tot_page, "total" => count($rows), "records" => $rows); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function lookupreleasebyid() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select tx_mou_release.*, TxMouReleaseID as id, TxMouReleaseM_StaffName as staff_release, DATE_FORMAT(TxMouReleaseCreated,'%d-%m-%Y %T') as date_release, M_BranchName, CASE WHEN TxMouReleaseStatus = 'RN' THEN 'Release New' WHEN TxMouReleaseStatus = 'UN' THEN 'Unrelease New' ELSE '' END as status_release from tx_mou_release JOIN m_branch ON TxMouReleaseM_BranchCode = M_BranchCode where TxMouReleaseM_MouID = {$id} ORDER BY TxMouReleaseCreated DESC"; // echo $sql; $query = $this->db_regional->query($sql, $sql_param); $rows = $query->result_array(); if ($rows) { foreach ($rows as $k => $v) { } } $result = array("total" => count($rows), "records" => $rows); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function lookup() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = $prm['search']; $group = $prm['group']; $all = $prm['all']; $limit = ''; if ($all == 'N') { $limit = ' LIMIT 10'; } $sql = "select COUNT(*) as total from m_company where M_CompanyIsActive = 'Y'"; $sql_param = array($search); $total = $this->db_regional->query($sql, $sql_param)->row()->total; $sql = "select M_CompanyID as id, M_CompanyName as name, M_CompanyAddress as address, M_CompanyPhone as phone, M_CompanyEmail as email,M_CompanyFax as fax, M_CompanyPICBillName as pic, CONCAT(M_CompanyName,' ' ,'[ ', ifnull(M_CompanyTypeGroupName,'-') ,' ]') as description , M_CompanyTypeID, M_CompanyM_CompanyTypeID as companytypeid, M_CompanyTypeName as companytypename, IFNULL(M_CompanyTypeGroupID,0) M_CompanyTypeGroupID, M_CompanyTypeM_CompanyTypeGroupID as companygrouptypeid, M_CompanyTypeGroupName as companygrouptypename, M_CompanyIsLabFrom as islabfrom, M_CompanyIsLabTo as islabto, M_CompanyIsDefault as isdefault,'xxx' as companymou, M_CompanyBusinessID,M_CompanyBusinessName,Nat_CompanyLevelID,Nat_CompanyLevelName,CONCAT(Nat_CompanyLevelName,' [',M_CompanyName,']') as Nat_CompanyLevelNames ,M_ProvinceID,M_ProvinceName,Nat_StaffID as M_StaffID,Nat_StaffName as M_StaffName,M_CompanyNumber,M_CompanyIDParent, Nat_HierarchyID,Nat_HierarchyName,M_CompanyFax, M_CityID, M_CityName, M_DistrictID, M_DistrictName, M_KelurahanID, M_KelurahanName, M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorNames, IF(M_MouID IS NULL , 'N', M_MouIsVerified) as isverified, M_CompanyNatCode from m_company LEFT JOIN m_mou ON M_MouM_CompanyID = M_CompanyID AND M_MouIsActive = 'Y' AND M_MouIsVerified = 'Y' LEFT JOIN m_companytype ON M_CompanyM_CompanyTypeID = M_CompanyTypeID LEFT JOIN m_companytypegroup ON M_CompanyTypeGroupID = M_CompanyTypeM_CompanyTypeGroupID LEFT JOIN m_kelurahan ON M_CompanyM_KelurahanID = M_KelurahanID LEFT JOIN m_district ON M_CompanyM_DistrictID = M_DistrictID LEFT JOIN m_city ON M_CompanyM_CityID = M_CityID LEFT JOIN m_province ON M_CompanyM_ProvinceID = M_ProvinceID LEFT JOIN m_companybusiness ON M_CompanyM_CompanyBusinessID = M_CompanyBusinessID LEFT JOIN nat_staff ON M_CompanyM_StaffID = Nat_StaffID LEFT JOIN nat_companylevel ON M_CompanyNat_CompanyLevelID = Nat_CompanyLevelID LEFT JOIN nat_hierarchy ON M_CompanyNat_HierarchyID = Nat_HierarchyID LEFT JOIN m_doctor ON M_CompanyM_DoctorID = M_DoctorID where ( M_CompanyName LIKE CONCAT('%','{$search}','%')) AND ($group = 0 OR($group > 0 AND M_CompanyTypeGroupID = $group)) AND M_CompanyIsActive = 'Y' GROUP BY M_CompanyID $limit"; $sql_param = array($search); $query = $this->db_regional->query($sql); //echo $this->db_regional->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_company select"); exit; } $result = array("total" => $total, "total_filter" => count($rows), "records" => $rows); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewcompany() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name = $prm['name']; $idparent = $prm['idparent']; $companytype = $prm['companytype']; $companybusiness = $prm['companybusiness']; $hierarkiid = $prm['hierarkiid']; $companylevelid = $prm['companylevelid']; $staffid = $prm['staffid']; $province = $prm['province']; $city = $prm['city']; $district = $prm['district']; $kelurahan = $prm['kelurahan']; $address = $prm['address']; $email = $prm['email']; $phone = $prm['phone']; $fax = $prm['fax']; $isdefault = $prm['isdefault']; $natcode = $prm['natcode']; if ($natcode != '') { $query = "SELECT COUNT(*) as exist FROM m_company WHERE M_CompanyIsActive = 'Y' AND M_CompanyNatCode = '{$natcode}'"; $exist_name = $this->db_regional->query($query)->row()->exist; } else { $exist_name = 0; } if ($exist_name == 0) { $sql = "insert into m_company( M_CompanyName, M_CompanyIDParent, M_CompanyNatCode, M_CompanyM_CompanyTypeID, M_CompanyM_CompanyBusinessID, M_CompanyNat_HierarchyID, M_CompanyNat_CompanyLevelID, M_CompanyM_StaffID, M_CompanyM_ProvinceID, M_CompanyM_CityID, M_CompanyM_DistrictID, M_CompanyM_KelurahanID, M_CompanyAddress, M_CompanyEmail, M_CompanyPhone, M_CompanyFax, M_CompanyIsDefault, M_CompanyCreated, M_CompanyLastUpdated ) values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now())"; // echo $sql; $query = $this->db_regional->query( $sql, array( $name, $idparent, $natcode, $companytype, $companybusiness, $hierarkiid, $companylevelid, $staffid, $province, $city, $district, $kelurahan, $address, $email, $phone, $fax, $isdefault ) ); if (!$query) { echo $this->db_regional->last_query(); $this->sys_error_db("m_company insert"); exit; } $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); $last_id = $this->db_regional->insert_id(); if ($isdefault == 'Y') { $querydefault = "UPDATE m_company SET M_CompanyIsDefault = 'N' WHERE M_CompanyIsDefault = 'Y' AND M_CompanyID <> '{$last_id}' AND M_CompanyIsActive = 'Y' "; $rows = $this->db_regional->query($querydefault); } } else { $errors = array(); if ($exist_name != 0) { array_push($errors, array('field' => 'name', 'msg' => 'Nomor kode nasional sudah ada yang pakai dong')); } $result = array("total" => -1, "errors" => $errors, "records" => 0); $this->sys_ok($result); } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function editcompany() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_company = $prm['id']; $name = $prm['name']; $idparent = $prm['idparent']; $companytype = $prm['companytype']; $companybusiness = $prm['companybusiness']; $hierarkiid = $prm['hierarkiid']; $companylevelid = $prm['companylevelid']; $staffid = $prm['staffid']; $province = $prm['province']; $city = $prm['city']; $district = $prm['district']; $kelurahan = $prm['kelurahan']; $address = $prm['address']; $email = $prm['email']; $phone = $prm['phone']; $fax = $prm['fax']; $isdefault = $prm['isdefault']; $natcode = $prm['natcode']; if ($natcode != '') { $query = "SELECT COUNT(*) as exist FROM m_company WHERE M_CompanyIsActive = 'Y' AND M_CompanyNatCode = '{$natcode}' AND M_CompanyID <> {$id_company}"; $exist_name = $this->db_regional->query($query)->row()->exist; } else { $exist_name = 0; } if ($exist_name == 0) { $sqlcompany = "update m_company SET M_CompanyName = ?, M_CompanyIDParent = ?, M_CompanyNatCode = ?, M_CompanyM_CompanyTypeID = ?, M_CompanyM_CompanyBusinessID = ?, M_CompanyNat_HierarchyID = ?, M_CompanyNat_CompanyLevelID = ?, M_CompanyM_StaffID = ?, M_CompanyM_ProvinceID = ?, M_CompanyM_CityID = ?, M_CompanyM_DistrictID = ?, M_CompanyM_KelurahanID = ?, M_CompanyAddress = ?, M_CompanyEmail = ?, M_CompanyPhone = ?, M_CompanyFax = ?, M_CompanyIsDefault = ?, M_CompanyLastUpdated = now() where M_CompanyID = ? "; $querycompany = $this->db_regional->query( $sqlcompany, array( $name, $idparent, $natcode, $companytype, $companybusiness, $hierarkiid, $companylevelid, $staffid, $province, $city, $district, $kelurahan, $address, $email, $phone, $fax, $isdefault, $id_company ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("m_company update"); exit; } $result = array("total" => 1, "records" => array("xid" => $id_company)); $this->sys_ok($result); if ($isdefault == 'Y') { $querydefault = "UPDATE m_company SET M_CompanyIsDefault = 'N' WHERE M_CompanyIsDefault = 'Y' AND M_CompanyIsActive = 'Y' AND M_CompanyID <> '{$id_company}' "; $rows = $this->db_regional->query($querydefault); } } else { $errors = array(); if ($exist_name != 0) { array_push($errors, array('field' => 'name', 'msg' => 'Nomor kode nasional sudah ada yang pakai dong')); } $result = array("total" => -1, "errors" => $errors, "records" => 0); $this->sys_ok($result); } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function checkacuanharga() { $prm = $this->sys_input; $query = "SELECT COUNT(*) x_count, CONCAT(M_CompanyName,' | ', M_MouName) note FROM m_mouaddon JOIN m_mou ON M_MouID = M_MouAddonM_MouID AND M_MouIsActive = 'Y' JOIN m_company ON M_CompanyID = M_MouM_CompanyID WHERE M_MouAddonIsActive = 'Y' AND M_MouAddonIsAcuanHarga = 'Y'"; //echo $query; $rows = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); exit; } public function editcompanyafterrelease() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_company = $prm['id']; $name = $prm['name']; $idparent = $prm['idparent']; $companytype = $prm['companytype']; $companybusiness = $prm['companybusiness']; $hierarkiid = $prm['hierarkiid']; $companylevelid = $prm['companylevelid']; $staffid = $prm['staffid']; $province = $prm['province']; $city = $prm['city']; $district = $prm['district']; $kelurahan = $prm['kelurahan']; $address = $prm['address']; $email = $prm['email']; $phone = $prm['phone']; $fax = $prm['fax']; $isdefault = $prm['isdefault']; $natcode = $prm['natcode']; $userid = $this->sys_user["M_UserID"]; if ($natcode != '') { $query = "SELECT COUNT(*) as exist FROM m_company WHERE M_CompanyIsActive = 'Y' AND M_CompanyNatCode = '{$natcode}' AND M_CompanyID <> {$id_company}"; $exist_name = $this->db_regional->query($query)->row()->exist; } else { $exist_name = 0; } if ($exist_name == 0) { $sqlcompany = "update m_company SET M_CompanyM_CompanyTypeID = ?, M_CompanyM_ProvinceID = ?, M_CompanyM_CityID = ?, M_CompanyM_DistrictID = ?, M_CompanyM_KelurahanID = ?, M_CompanyAddress = ?, M_CompanyM_StaffID = ?, M_CompanyNatCode = ?, M_CompanyLastUpdated = now() where M_CompanyID = ? "; $querycompany = $this->db_regional->query( $sqlcompany, array( $companytype, $province, $city, $district, $kelurahan, $address, $staffid, $natcode, $id_company ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("m_company update"); exit; } $result = $this->upload_editcompanyafterrelease($id_company); if ($result[0]) { $result = array("total" => 1, "records" => array("xid" => 0), "lastid" => $id_company); $this->sys_ok($result); } else { $this->sys_error($result); } } else { $errors = array(); if ($exist_name != 0) { array_push($errors, array('field' => 'name', 'msg' => 'Nomor kode nasional sudah ada yang pakai dong')); } $result = array("total" => -1, "errors" => $errors, "records" => 0); $this->sys_ok($result); } /* if($isdefault == 'Y'){ $querydefault ="UPDATE m_company SET M_CompanyIsDefault = 'N' WHERE M_CompanyIsDefault = 'Y' AND M_CompanyIsActive = 'Y' AND M_CompanyID <> '{$id_company}' "; $rows = $this->db_regional->query($querydefault); } */ } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function upload_editcompanyafterrelease($companyid) { //upload company $sql = "select M_CompanyID,M_CompanyM_CompanyTypeID,M_CompanyM_ProvinceID, M_CompanyM_CityID,M_CompanyM_DistrictID,M_CompanyM_KelurahanID,M_CompanyAddress,M_CompanyLastUpdated,M_CompanyM_StaffID from m_company where M_CompanyID = ?"; $qry = $this->db_regional->query($sql, array($companyid)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Company : " . $this->db_regional->last_query()); } $company = $rows[0]; $param = array( "company" => $company ); $param_md5 = md5(json_encode($param)); $j_param = json_encode(array("param" => $param, "md5" => $param_md5)); $sql = "select * from m_branch JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID AND S_RegionalIsDefault = 'Y' where M_BranchIsActive = 'Y'"; $qry = $this->db_regional->query($sql); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Branch"); } $flag_error = false; $err_msg = array(); foreach ($rows as $r) { $branchCode = $r["M_BranchCode"]; $ipAddress = $r["M_BranchIPAddress"]; try { $txMouID = $this->db_regional->insert_id(); $url = "http://$ipAddress/one-api/tools/company/editcompanyafterrelease"; $post_rst = $this->post($url, $j_param); $j_rst = json_decode($post_rst, true); } catch (Exception $e) { $err_msg[] = $e->getMessage(); $flag_error = true; } } if ($flag_error) { return array(false, join(",", $err_msg)); } return array(true, "OK"); } public function addnewcompanytype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name_companytype = $prm['name']; $userid = $this->sys_user["M_UserID"]; $sql = "insert into m_companytype( M_CompanyTypeName, M_CompanyTypeUserID, M_CompanyTypeCreated, M_CompanyTypeLastUpdated ) values(?,?,now(),now())"; $query = $this->db_regional->query( $sql, array( $name_companytype, $userid ) ); //echo $query; if (!$query) { $this->sys_error_db("m_companytype insert"); exit; } $rows = []; $query = " SELECT *, COUNT(M_CompanyID) as used FROM (SELECT m_companytype.*,M_CompanyID FROM m_companytype LEFT JOIN m_company ON M_CompanyTypeID = M_CompanyM_CompanyTypeID AND M_CompanyIsActive = 'Y' WHERE M_CompanyTypeIsActive = 'Y') a GROUP BY M_CompanyTypeID "; //echo $query; $rows['companytypes'] = $this->db_regional->query($query)->result_array(); $result = array("total" => 1, "records" => $rows); $this->sys_ok($result); $last_id = $this->db_regional->insert_id(); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function editcompanytype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_company = $prm['id']; $name_company = $prm['name']; $userid = $this->sys_user["M_UserID"]; $sqlcompany = "update m_companytype SET M_CompanyTypeName = ?, M_CompanyTypeUserID = ?, M_CompanyTypeLastUpdated = now() where M_CompanyTypeID = ? "; $querycompany = $this->db_regional->query( $sqlcompany, array( $name_company, $userid, $id_company ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("m_companytype update"); exit; } $rows = []; $query = " SELECT *, COUNT(M_CompanyID) as used FROM (SELECT m_companytype.*,M_CompanyID FROM m_companytype LEFT JOIN m_company ON M_CompanyTypeID = M_CompanyM_CompanyTypeID AND M_CompanyIsActive = 'Y' WHERE M_CompanyTypeIsActive = 'Y') a GROUP BY M_CompanyTypeID"; //echo $query; $rows['companytypes'] = $this->db_regional->query($query)->result_array(); $result = array("total" => 1, "records" => $rows); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletecompanytype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_company = $prm['id']; $userid = $this->sys_user["M_UserID"]; $sqlcompany = "update m_companytype SET M_CompanyTypeIsActive = 'N', M_CompanyTypeUserID = ?, M_CompanyTypeLastUpdated = now() where M_CompanyTypeID = ? "; $querycompany = $this->db_regional->query( $sqlcompany, array( $userid, $id_company ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("m_companytype update"); exit; } $rows = []; $query = " SELECT * FROM m_companytype WHERE M_CompanyTypeIsActive = 'Y' "; //echo $query; $rows['companytypes'] = $this->db_regional->query($query)->result_array(); $result = array("total" => 1, "records" => $rows); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewcompanybusiness() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name_companytype = $prm['name']; $userid = $this->sys_user["M_UserID"]; $sql = "insert into m_companybusiness( M_CompanyBusinessName, M_CompanyBusinessUserID, M_CompanyBusinessCreated, M_CompanyBusinessLastUpdated ) values(?,?,now(),now())"; $query = $this->db_regional->query( $sql, array( $name_companytype, $userid ) ); //echo $query; if (!$query) { $this->sys_error_db("m_companybusiness insert"); exit; } $rows = []; $query = " SELECT *, COUNT(M_CompanyID) as used FROM (SELECT m_companybusiness.*,M_CompanyID FROM m_companybusiness LEFT JOIN m_company ON M_CompanyBusinessID = M_CompanyM_CompanyBusinessID AND M_CompanyIsActive = 'Y' WHERE M_CompanyBusinessIsActive = 'Y') a GROUP BY M_CompanyBusinessID "; //echo $query; $rows['companybusinesss'] = $this->db_regional->query($query)->result_array(); $result = array("total" => 1, "records" => $rows); $this->sys_ok($result); $last_id = $this->db_regional->insert_id(); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function editcompanybusiness() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_company = $prm['id']; $name_company = $prm['name']; $userid = $this->sys_user["M_UserID"]; $sqlcompany = "update m_companybusiness SET M_CompanyBusinessName = ?, M_CompanyBusinessUserID = ?, M_CompanyBusinessLastUpdated = now() where M_CompanyBusinessID = ? "; $querycompany = $this->db_regional->query( $sqlcompany, array( $name_company, $userid, $id_company ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("m_companybusiness update"); exit; } $rows = []; $query = " SELECT *, COUNT(M_CompanyID) as used FROM (SELECT m_companybusiness.*,M_CompanyID FROM m_companybusiness LEFT JOIN m_company ON M_CompanyBusinessID = M_CompanyM_CompanyBusinessID AND M_CompanyIsActive = 'Y' WHERE M_CompanyBusinessIsActive = 'Y') a GROUP BY M_CompanyBusinessID"; //echo $query; $rows['companybusinesss'] = $this->db_regional->query($query)->result_array(); $result = array("total" => 1, "records" => $rows); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletecompanybusiness() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_company = $prm['id']; $userid = $this->sys_user["M_UserID"]; $sqlcompany = "update m_companybusiness SET M_CompanyBusinessIsActive = 'N', M_CompanyBusinessUserID = ?, M_CompanyBusinessLastUpdated = now() where M_CompanyBusinessID = ? "; $querycompany = $this->db_regional->query( $sqlcompany, array( $userid, $id_company ) ); // echo $query; if (!$querycompany) { $this->sys_error_db("m_companybusiness update"); exit; } $rows = []; $query = " SELECT * FROM m_companybusiness WHERE M_CompanyBusinessIsActive = 'Y' "; //echo $query; $rows['companybusinesss'] = $this->db_regional->query($query)->result_array(); $result = array("total" => 1, "records" => $rows); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function addnewmou() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; //# ambil parameter input $prm = $this->sys_input; $companyid = $prm['companyid']; $name = $prm['name']; $startdate = date('Y-m-d', strtotime($prm['startdate'])); $enddate = date('Y-m-d', strtotime($prm['enddate'])); $isbill = $prm['isbill']; $isdefault = $prm['isdefault']; $isaging = $prm['isaging']; $isemail = $prm['isemail']; $isfavorit = $prm['isfavorit']; $isjpanetto = $prm['isjpanetto']; $ismcu = $prm['ismcu']; $isonline = $prm['isonline']; $refnumber = $prm['refnumber']; $mindp = $prm['mindp']; $agingnote = $prm['agingnote']; $xnote = $prm['xnote']; $mouemail = $prm['mouemail']; $base = $prm['base']; $omzettype = $prm['omzettype']; $billtype = $prm['billtype']; $branch = $prm['branch']; $moutype = $prm['moutype']; $agingtype = $prm['agingtype']; $jpa1Name = $prm['jpa1Name']; $jpa2Name = $prm['jpa2Name']; $jpa3Name = $prm['jpa3Name']; $jpa4Name = $prm['jpa4Name']; $jpa1Percent = $prm['jpa1Percent']; $jpa2Percent = $prm['jpa2Percent']; $jpa3Percent = $prm['jpa3Percent']; $jpa4Percent = $prm['jpa4Percent']; $jpa1amount = $prm['jpa1amount']; $jpa2amount = $prm['jpa2amount']; $jpa3amount = $prm['jpa3amount']; $jpa4amount = $prm['jpa4amount']; $picname = $prm['picname']; $pichp = $prm['pichp']; $fincname = $prm['fincname']; $finchp = $prm['finchp']; $mouemailpic = $prm['mouemailpic']; $mouemailfinc = $prm['mouemailfinc']; $iserpersonal = $prm['iserpersonal']; $isercompany = $prm['isercompany']; $isvoucher = $prm['isvoucher']; $isacuanharga = $prm['isacuanharga']; $xnotebill = $prm['xnotebill']; $xnoteresult = $prm['xnoteresult']; $addressbill = $prm['addressbill']; $addressresult = $prm['addressresult']; $staff = $prm['staff']; if ($prm['xid'] == "0" || $prm['xid'] == 0) { $query = "SELECT COUNT(*) as exist FROM m_mou WHERE M_MouIsActive = 'Y' AND M_MouName = '{$name}' AND M_MouM_CompanyID = '{$companyid}'"; $exist_name = $this->db_regional->query($query)->row()->exist; if ($exist_name == 0) { $sql = "insert into m_mou( M_MouM_CompanyID, M_MouName, M_MouStartDate, M_MouEndDate, M_MouIsBill, M_MouIsDefault, M_MouIsAgingOnHold, M_MouEmailIsDefault, M_MouIsUsingFavourite, M_MouJpaIsNetto, M_MouRefNumber, M_MouMinDP, M_MouAgingDay, M_MouNote, M_MouEmail, M_MouBase, M_MouM_OmzetTypeID, M_MouM_MouTypeID, M_MouM_AgingTypeID, M_MouUserID, M_MouJpa1Name, M_MouJpa1Percent, M_MouJpa2Name, M_MouJpa2Percent, M_MouJpa3Name, M_MouJpa3Percent, M_MouJpa4Name, M_MouJpa4Percent, M_MouJpa1Amount, M_MouJpa2Amount, M_MouJpa3Amount, M_MouJpa4Amount, M_MouIsConfirm, M_MouStatus, M_MouIsMcu, M_MouPicBillName, M_MouPicBillHandphone, M_MouFinanceName, M_MouFinanceHandphone, M_MouPicBillEmail, M_MouFinanceEmail, M_MouM_BillTypeID, M_MouM_BranchBillID, M_MouEresultPersonal, M_MouEresultCompany, M_MouCreated, M_MouLastUpdated ) values( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,now(),now())"; $query = $this->db_regional->query( $sql, array( $companyid, $name, $startdate, $enddate, $isbill, $isdefault, $isaging, $isemail, $isfavorit, $isjpanetto, $refnumber, $mindp, $agingnote, $xnote, $mouemail, $base, $omzettype, $moutype, $agingtype, $userid, $jpa1Name, $jpa1Percent, $jpa2Name, $jpa2Percent, $jpa3Name, $jpa3Percent, $jpa4Name, $jpa4Percent, $jpa1amount, $jpa2amount, $jpa3amount, $jpa4amount, 'Y', 'C', $ismcu, $picname, $pichp, $fincname, $finchp, $mouemailpic, $mouemailfinc, $billtype, $branch, $iserpersonal, $isercompany, ) ); //echo $query; if (!$query) { $this->sys_error_db("m_mou insert"); exit; } $last_id = $this->db_regional->insert_id(); $result = array("total" => 1, "records" => array("xid" => 0), "lastid" => $last_id); $this->sys_ok($result); $querystatus = "INSERT g_moustatuslog (G_MouStatusLogDate, G_MouStatusLogM_MouID, G_MouStatusLogStatus, G_MouStatusLogUserID, G_MouStatusLogCreated, G_MouStatusLogLastUpdated) VALUES( date(now()), '{$last_id}', 'C', '{$userid}', now(), now()) "; $rows = $this->db_regional->query($querystatus); $sqladdon = "INSERT INTO m_mouaddon ( M_MouAddonM_MouID, M_MouAddonIsVoucher, M_MouAddonIsAcuanHarga, M_MouAddonNat_StaffID, M_MouAddonAddressResult, M_MouAddonAddressBill, M_MouAddonNoteResult, M_MouAddonNoteBill, M_MouAddonUserID) VALUES('{$last_id}', '{$isvoucher}', '{$isacuanharga}', '{$staff}', '{$addressresult}', '{$addressbill}', '{$xnoteresult}', '{$xnotebill}', '{$userid}') on duplicate key update M_MouAddonIsVoucher = '{$isvoucher}', M_MouAddonIsAcuanHarga = '{$isacuanharga}', M_MouAddonNat_StaffID = '{$staff}', M_MouAddonAddressResult = '{$addressresult}', M_MouAddonAddressBill = '{$addressbill}', M_MouAddonNoteResult = '{$xnoteresult}', M_MouAddonNoteBill = '{$xnotebill}', M_MouAddonUserID = {$userid}"; $this->db_regional->query($sqladdon); if ($isdefault == 'Y') { $querydefault = "UPDATE m_mou SET M_MouIsDefault = 'N' WHERE M_MouIsDefault = 'Y' AND M_MouM_CompanyID = '{$companyid}' AND M_MouID <> '{$last_id}' "; $rows = $this->db_regional->query($querydefault); } if ($isacuanharga == 'Y') { $queryacuanharga = "UPDATE m_mouaddon SET M_MouAddonIsAcuanHarga = 'N' WHERE M_MouAddonIsAcuanHarga = 'Y' AND M_MouAddonM_MouID <> '{$last_id}' "; $rows = $this->db_regional->query($queryacuanharga); } } else { $errors = array(); if ($exist_name != 0) { array_push($errors, array('field' => 'name', 'msg' => 'Nama sudah ada yang pakai dong')); } $result = array("total" => -1, "errors" => $errors, "records" => 0); $this->sys_ok($result); } } else { $query = "SELECT COUNT(*) as exist FROM m_mou WHERE M_MouIsActive = 'Y' AND M_MouName = '{$name}' AND M_MouID <> {$prm['xid']} AND M_MouM_CompanyID = '{$companyid}'"; $exist_name = $this->db_regional->query($query)->row()->exist; //echo $query; if ($exist_name == 0) { $lastid = $prm['xid']; $sql = "UPDATE m_mou SET M_MouName = '{$name}', M_MouRefNumber = '{$refnumber}', M_MouStartDate = '{$startdate}', M_MouEndDate = '{$enddate}', M_MouIsBill = '{$isbill}', M_MouIsDefault = '{$isdefault}', M_MouIsAgingOnHold = '{$isaging}',M_MouEmailIsDefault = '{$isemail}',M_MouIsUsingFavourite = '{$isfavorit}',M_MouJpaIsNetto = '{$isjpanetto}',M_MouMinDP = '{$mindp}',M_MouAgingDay = '{$agingnote}', M_MouNote = '{$xnote}', M_MouEmail = '{$mouemail}',M_MouBase = '{$base}',M_MouM_OmzetTypeID = '{$omzettype}',M_MouM_MouTypeID = '{$moutype}', M_MouM_AgingTypeID = '{$agingtype}', M_MouJpa1Name = '{$jpa1Name}', M_MouJpa1Percent = '{$jpa1Percent}', M_MouJpa2Name = '{$jpa2Name}', M_MouJpa2Percent = '{$jpa2Percent}', M_MouJpa3Name = '{$jpa3Name}', M_MouJpa3Percent = '{$jpa3Percent}', M_MouJpa4Name = '{$jpa4Name}', M_MouJpa4Percent = '{$jpa4Percent}', M_MouJpa1Amount = '{$jpa1amount}', M_MouJpa2Amount = '{$jpa2amount}', M_MouJpa3Amount = '{$jpa3amount}', M_MouJpa4Amount = '{$jpa4amount}', M_MouIsMcu = '{$ismcu}', M_MouPicBillName = '{$picname}', M_MouPicBillHandphone = '{$pichp}', M_MouFinanceName = '{$fincname}', M_MouFinanceHandphone = '{$finchp}', M_MouPicBillEmail = '{$mouemailpic}', M_MouFinanceEmail = '{$mouemailfinc}', M_MouM_BillTypeID = '{$billtype}', M_MouM_BranchBillID = '{$branch}', M_MouEresultPersonal = '{$iserpersonal}', M_MouEresultCompany = '{$isercompany}' WHERE M_MouID = '{$prm['xid']}'"; //echo $sql; $query = $this->db_regional->query($sql); $sqladdon = "INSERT INTO m_mouaddon ( M_MouAddonM_MouID, M_MouAddonIsVoucher, M_MouAddonIsAcuanHarga, M_MouAddonNat_StaffID, M_MouAddonAddressResult, M_MouAddonAddressBill, M_MouAddonNoteResult, M_MouAddonNoteBill, M_MouAddonUserID) VALUES('{$prm['xid']}', '{$isvoucher}', '{$isacuanharga}', '{$staff}', '{$addressresult}', '{$addressbill}', '{$xnoteresult}', '{$xnotebill}', '{$userid}') on duplicate key update M_MouAddonIsVoucher = '{$isvoucher}', M_MouAddonIsAcuanHarga = '{$isacuanharga}', M_MouAddonNat_StaffID = '{$staff}', M_MouAddonAddressResult = '{$addressresult}', M_MouAddonAddressBill = '{$addressbill}', M_MouAddonNoteResult = '{$xnoteresult}', M_MouAddonNoteBill = '{$xnotebill}', M_MouAddonUserID = {$userid}"; $this->db_regional->query($sqladdon); $result = array("total" => 1, "records" => array("xid" => 0), "lastid" => $lastid); $this->sys_ok($result); if ($isdefault == 'Y') { $querydefault = "UPDATE m_mou SET M_MouIsDefault = 'N' WHERE M_MouIsDefault = 'Y' AND M_MouM_CompanyID = '{$companyid}' AND M_MouID <> '{$prm['xid']}' "; $rows = $this->db_regional->query($querydefault); } if ($isacuanharga == 'Y') { $queryacuanharga = "UPDATE m_mouaddon SET M_MouAddonIsAcuanHarga = 'N' WHERE M_MouAddonIsAcuanHarga = 'Y' AND M_MouAddonM_MouID <> '{$prm['xid']}' "; $rows = $this->db_regional->query($queryacuanharga); } } else { $errors = array(); if ($exist_name != 0) { array_push($errors, array('field' => 'name', 'msg' => 'Nama sudah ada yang pakai dong')); } $result = array("total" => -1, "errors" => $errors, "records" => 0); $this->sys_ok($result); } } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function saveafterrelease() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; //# ambil parameter input $prm = $this->sys_input; $isbill = $prm['isbill']; $isdefault = $prm['isdefault']; $isemail = $prm['isemail']; $ismcu = $prm['ismcu']; $isonline = $prm['isonline']; $mouemail = $prm['mouemail']; $mindp = $prm['mindp']; $note = $prm['note']; $agingday = $prm['agingnote']; $isaging = $prm['isaging']; $picname = $prm['picname']; $pichp = $prm['pichp']; $mouemailpic = $prm['mouemailpic']; $finchp = $prm['finchp']; $fincname = $prm['fincname']; $mouemailfinc = $prm['mouemailfinc']; $billtype = $prm['billtype']; $branch = $prm['branch']; $iserpersonal = $prm['iserpersonal']; $isercompany = $prm['isercompany']; $isvoucher = $prm['isvoucher']; $isacuanharga = $prm['isacuanharga']; $xnotebill = $prm['notebill']; $xnoteresult = $prm['noteresult']; $addressbill = $prm['addressbill']; $addressresult = $prm['addressresult']; $staff = $prm['staff']; $lastid = $prm['xid']; $sql = "UPDATE m_mou SET M_MouIsBill = '{$isbill}', M_MouMinDP = '{$mindp}', M_MouIsDefault = '{$isdefault}', M_MouEmailIsDefault = '{$isemail}', M_MouEmail = '{$mouemail}', M_MouIsMcu = '{$ismcu}', M_MouNote = '{$note}', M_MouAgingDay = '{$agingday}', M_MouIsAgingOnHold = '{$isaging}', M_MouPicBillName = '{$picname}', M_MouPicBillHandphone = '{$pichp}', M_MouFinanceName = '{$fincname}', M_MouFinanceHandphone = '{$finchp}', M_MouPicBillEmail = '{$mouemailpic}', M_MouFinanceEmail = '{$mouemailfinc}', M_MouM_BillTypeID = '{$billtype}', M_MouM_BranchBillID = '{$branch}', M_MouEresultPersonal = '{$iserpersonal}', M_MouEresultCompany = '{$isercompany}' WHERE M_MouID = '{$prm['xid']}'"; //echo $sql; $query = $this->db_regional->query($sql); $sqladdon = "INSERT INTO m_mouaddon ( M_MouAddonM_MouID, M_MouAddonIsVoucher, M_MouAddonIsAcuanHarga, M_MouAddonNat_StaffID, M_MouAddonAddressResult, M_MouAddonAddressBill, M_MouAddonNoteResult, M_MouAddonNoteBill, M_MouAddonUserID) VALUES('{$prm['xid']}', '{$isvoucher}', '{$isacuanharga}', '{$staff}', '{$addressresult}', '{$addressbill}', '{$xnoteresult}', '{$xnotebill}', '{$userid}') on duplicate key update M_MouAddonIsVoucher = '{$isvoucher}', M_MouAddonIsAcuanHarga = '{$isacuanharga}', M_MouAddonNat_StaffID = '{$staff}', M_MouAddonAddressResult = '{$addressresult}', M_MouAddonAddressBill = '{$addressbill}', M_MouAddonNoteResult = '{$xnoteresult}', M_MouAddonNoteBill = '{$xnotebill}', M_MouAddonUserID = {$userid}"; $this->db_regional->query($sqladdon); if ($isdefault == 'Y') { $querydefault = "UPDATE m_mou SET M_MouIsDefault = 'N' WHERE M_MouIsDefault = 'Y' AND M_MouM_CompanyID = '{$companyid}' AND M_MouID <> '{$prm['xid']}' "; $rows = $this->db_regional->query($querydefault); } if ($isacuanharga == 'Y') { $queryacuanharga = "UPDATE m_mouaddon SET M_MouAddonIsAcuanHarga = 'N' WHERE M_MouAddonIsAcuanHarga = 'Y' AND M_MouAddonM_MouID <> '{$prm['xid']}' "; $rows = $this->db_regional->query($queryacuanharga); } $queryrelease = "SELECT M_MouIsReleased as released FROM m_mou WHERE M_MouID = {$lastid}"; // echo $queryrelease; $release = $this->db_regional->query($queryrelease)->row()->released; if ($release == 'Y') { $result = $this->upload_editflag($lastid); if ($result[0]) { $result = array("total" => 1, "records" => array("xid" => 0), "lastid" => $lastid); $this->sys_ok($result); } else { $this->sys_error($result); } } else { $result = array("total" => 1, "records" => array("xid" => 0), "lastid" => $lastid); $this->sys_ok($result); } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function upload_editflag($mouID) { //upload aggrement , ss_price_mou $sql = "select M_MouID,M_MouIsDefault,M_MouIsBill,M_MouMinDP,M_MouEmail,M_MouEmailIsDefault,M_MouIsMcu,M_MouNote, M_MouIsAgingOnHold, M_MouAgingDay, M_MouPicBillName, M_MouPicBillHandphone, M_MouPicBillEmail, M_MouFinanceName, M_MouFinanceHandphone, M_MouFinanceEmail, M_MouM_BillTypeID, M_MouEresultCompany, M_MouEresultPersonal, M_MouM_BranchBillID from m_mou where M_MouID = ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No MOU : " . $this->db_regional->last_query()); } $mou = $rows[0]; $sql = "select * from m_mouaddon where M_MouAddonM_MouID = ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (! $qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { $addon = ''; } $addon = $rows[0]; $param = array( "mou" => $mou, "addon" => $addon ); $param_md5 = md5(json_encode($param)); $j_param = json_encode(array("param" => $param, "md5" => $param_md5)); $sql = "select * from m_branch JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID AND S_RegionalIsDefault = 'Y' where M_BranchIsActive = 'Y'"; $qry = $this->db_regional->query($sql); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Branch"); } $sql = "insert into tx_mou(TxMouM_BranchIPAddress, TxMouM_BranchCode,TxMouM_MouID, TxMouJson,TxMouM_UserID,TxMouT_TestID ) values(?,?,?,?,?,'-3')"; $sql_del = "delete from tx_mou where TxMouM_MouID=? and TxMouM_BranchCode=?"; $flag_error = false; $err_msg = array(); $userID = $this->sys_user["M_UserID"]; foreach ($rows as $r) { $branchCode = $r["M_BranchCode"]; $ipAddress = $r["M_BranchIPAddress"]; $qry = $this->db_regional->query($sql_del, array($mouID, $branchCode)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $qry = $this->db_regional->query($sql, array($ipAddress, $branchCode, $mouID, $j_param, $userID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } try { $txMouID = $this->db_regional->insert_id(); $url = "http://$ipAddress/one-api/tools/price/extendmouv2/editflag"; $post_rst = $this->post($url, $j_param); $j_rst = json_decode($post_rst, true); if ($j_rst["status"] != "OK") { $err_msg[] = $post_rst; $flag_error = true; $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID)); //return array(false, "Upload Failed"); } else { $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID)); } } catch (Exception $e) { $err_msg[] = $e->getMessage(); $flag_error = true; } } if ($flag_error) { return array(false, join(",", $err_msg)); } return array(true, "OK"); } public function deletemou() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update m_mou SET M_MouIsActive = 'N', M_MouLastUpdated = now() WHERE M_MouID = ? "; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_mou delete"); exit; } $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function confirmmou() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $id = $prm['id']; $sql = "update m_mou SET M_MouIsConfirm = 'Y', M_MouConfirmDate = now(), M_MouStatus = 'C', M_MouConfirmUserID = '{$userid}', M_MouLastUpdated = now() WHERE M_MouID = ? "; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_mou update"); exit; } $querystatus = "INSERT g_moustatuslog (G_MouStatusLogDate, G_MouStatusLogM_MouID, G_MouStatusLogStatus, G_MouStatusLogUserID, G_MouStatusLogCreated, G_MouStatusLogLastUpdated) VALUES( date(now()), '{$id}', 'C', '{$userid}', now(), now()) "; $rows = $this->db_regional->query($querystatus); $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function verifymou_addhoc() { try { //# cek token valid //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $id = $prm['id']; $sql = "update m_mou SET M_MouIsVerified = 'Y', M_MouVerifyDate = now(), M_MouStatus = 'V', M_MouVerifyUserID = '{$userid}', M_MouLastUpdated = now() WHERE M_MouID = ?"; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_mou update"); exit; } $querystatus = "INSERT g_moustatuslog (G_MouStatusLogDate, G_MouStatusLogM_MouID, G_MouStatusLogStatus, G_MouStatusLogUserID, G_MouStatusLogCreated, G_MouStatusLogLastUpdated) VALUES( date(now()), '{$id}', 'V', '{$userid}', now(), now()) "; $rows = $this->db_regional->query($querystatus); $querydeletessprice = "DELETE FROM ss_price_mou WHERE Ss_PriceMouID IN ( -- pemeriksaan SELECT Ss_PriceMouID FROM ss_price_mou WHERE T_PriceM_MouID = $id AND is_packet = 'N' AND T_TestID IN ( SELECT T_PriceT_TestID FROM t_price WHERE T_PriceT_TestID NOT IN ( select T_PriceT_TestID from t_price where T_PriceIsActive = 'Y' AND T_PriceM_MouID = $id) AND T_PriceIsActive = 'N' AND T_PriceM_MouID = $id GROUP BY T_PriceT_TestID) -- paket UNION SELECT Ss_PriceMouID FROM ss_price_mou WHERE T_PriceM_MouID = $id AND is_packet = 'Y' AND T_TestID IN ( SELECT T_PacketID FROM t_packet WHERE T_PacketIsActive = 'N' AND T_PacketM_MouID = $id ) ) "; $deletessprice = $this->db_regional->query($querydeletessprice); //snapshot to ss_price_mou $this->load->library("SsPriceMou_v4"); $result = $this->sspricemou_v4->create($id); if (!$result[0]) { $this->sys_error($result); exit; } $result = $this->upload_mou($id); // sipe: add snapshot to ss_price_mou_px try { $this->load->library("SsPriceMouPx"); $this->sspricemoupx->create($id); } catch (Exception $exc2) { $message = $exc->getMessage(); $this->sys_error($message); } if ($result[0]) { $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } else { $this->sys_error("Upload MOU : " . $result); } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function verifymou() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $id = $prm['id']; $sql = "update m_mou SET M_MouIsVerified = 'Y', M_MouVerifyDate = now(), M_MouStatus = 'V', M_MouVerifyUserID = '{$userid}', M_MouLastUpdated = now() WHERE M_MouID = ?"; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_mou update"); exit; } $querystatus = "INSERT g_moustatuslog (G_MouStatusLogDate, G_MouStatusLogM_MouID, G_MouStatusLogStatus, G_MouStatusLogUserID, G_MouStatusLogCreated, G_MouStatusLogLastUpdated) VALUES( date(now()), '{$id}', 'V', '{$userid}', now(), now()) "; $rows = $this->db_regional->query($querystatus); $querydeletessprice = "DELETE FROM ss_price_mou WHERE Ss_PriceMouID IN ( -- pemeriksaan SELECT Ss_PriceMouID FROM ss_price_mou WHERE T_PriceM_MouID = $id AND is_packet = 'N' AND T_TestID IN ( SELECT T_PriceT_TestID FROM t_price WHERE T_PriceT_TestID NOT IN ( select T_PriceT_TestID from t_price where T_PriceIsActive = 'Y' AND T_PriceM_MouID = $id) AND T_PriceIsActive = 'N' AND T_PriceM_MouID = $id GROUP BY T_PriceT_TestID) -- paket UNION SELECT Ss_PriceMouID FROM ss_price_mou WHERE T_PriceM_MouID = $id AND is_packet = 'Y' AND T_TestID IN ( SELECT T_PacketID FROM t_packet WHERE T_PacketIsActive = 'N' AND T_PacketM_MouID = $id ) ) "; $deletessprice = $this->db_regional->query($querydeletessprice); //snapshot to ss_price_mou $this->load->library("SsPriceMou_v4"); $result = $this->sspricemou_v4->create($id); if (!$result[0]) { $this->sys_error($result); exit; } $result = $this->upload_mou($id); // sipe: add snapshot to ss_price_mou_px try { $this->load->library("SsPriceMouPx"); $this->sspricemoupx->create($id); } catch (Exception $exc2) { $message = $exc->getMessage(); $this->sys_error($message); } if ($result[0]) { $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } else { $this->sys_error("Upload MOU : " . $result); } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function upload_mou($mouID) { //upload aggrement , ss_price_mou $sql = "select * from m_mou where M_MouID = ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No MOU : " . $this->db_regional->last_query()); } $mou = $rows[0]; $sql = "select * from m_company where M_CompanyID = ?"; $qry = $this->db_regional->query($sql, array($mou["M_MouM_CompanyID"])); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Company"); } $company = $rows[0]; $sql = "select * from g_moustatuslog where G_MouStatusLogM_MouID = ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Log"); } $logs = $rows; $mou["M_MouUserID"] = 3; // set to 3 foreach ($logs as $idx => $l) { $logs[$idx]["G_MouStatusLogUserID"] = 3; } $sql = "select * from ss_price_mou where Ss_PriceMouM_MouID= ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Ss Price Mou"); } $sql = "select * from t_price where T_PriceM_MouID= ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $t_rows = $qry->result_array(); $sql = "select * from t_packet where T_PacketM_MouID = ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $pkt_rows = $qry->result_array(); $sql = "select t_packetdetail.* from t_packet join t_packetdetail on T_PacketDetailT_PacketID = T_PacketID where T_PacketM_MouID = ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $pd_rows = $qry->result_array(); $sql = "select * from m_mouaddon where M_MouAddonM_MouID = ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (! $qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows_addon = $qry->result_array(); if (count($rows_addon) == 0) { $addon = ''; } $addon = $rows_addon[0]; $param = array( "mou" => $mou, "company" => $company, "logs" => $logs, "price_mou" => $rows, "t_price" => $t_rows, "packet" => $pkt_rows, "packet_detail" => $pd_rows, "addon" => $addon ); $param_md5 = md5(json_encode($param)); $j_param = json_encode(array("param" => $param, "md5" => $param_md5)); $sql = "select * from m_branch JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID AND S_RegionalIsDefault = 'Y' where M_BranchIsActive = 'Y'"; $qry = $this->db_regional->query($sql); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Ss Price Mou"); } $sql = "insert into tx_mou(TxMouM_BranchIPAddress, TxMouM_BranchCode,TxMouM_MouID, TxMouJson,TxMouM_UserID ) values(?,?,?,?,?)"; $sql_del = "delete from tx_mou where TxMouM_MouID=? and TxMouM_BranchCode=?"; $flag_error = false; $err_msg = array(); $userID = $this->sys_user["M_UserID"]; foreach ($rows as $r) { $branchCode = $r["M_BranchCode"]; $ipAddress = $r["M_BranchIPAddress"]; $qry = $this->db_regional->query($sql_del, array($mouID, $branchCode)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $qry = $this->db_regional->query($sql, array($ipAddress, $branchCode, $mouID, $j_param, $userID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } try { $txMouID = $this->db_regional->insert_id(); $z_param = gzdeflate($j_param, 9); $url = "http://$ipAddress/one-api/tools/price/r_mou_gz_v2/verify"; $post_rst = $this->post($url, $z_param); $j_rst = json_decode($post_rst, true); if ($j_rst["status"] != "OK") { $err_msg[] = $post_rst; $flag_error = true; $this->db_regional->query("update tx_mou set TxMouRetry = 1 where TxMouID = ? ", array($txMouID)); } else { $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = 1 where TxMouID = ? ", array($txMouID)); } } catch (Exception $e) { $err_msg[] = $e->getMessage(); $flag_error = true; } } if ($flag_error) { return array(false, join(",", $err_msg)); } return array(true, "OK"); } function postold($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_TIMEOUT, 100); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data) ) ); $result = curl_exec($ch); return $result; } 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_TIMEOUT, 100); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data) ) ); $result = curl_exec($ch); if (curl_errno($ch)) { return json_encode(array( "status" => "ERR", "message" => curl_error($ch) )); } curl_close($ch); return $result; } public function unverifymou() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $id = $prm['id']; $sql = "update m_mou SET M_MouIsVerified = 'N', M_MouStatus = 'UV', M_MouVerifyDate = now(), M_MouVerifyUserID = '{$userid}', M_MouLastUpdated = now() WHERE M_MouID = ? "; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_mou update"); exit; } $querystatus = "INSERT g_moustatuslog (G_MouStatusLogDate, G_MouStatusLogM_MouID, G_MouStatusLogStatus, G_MouStatusLogUserID, G_MouStatusLogCreated, G_MouStatusLogLastUpdated) VALUES( date(now()), '{$id}', 'UV', '{$userid}', now(), now()) "; $rows = $this->db_regional->query($querystatus); $result = $this->upload_unverifymou($id); if ($result[0]) { $result = array("total" => 1, "records" => array("xid" => 0), "lastid" => $id); $this->sys_ok($result); } else { $this->sys_error($result); } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function upload_unverifymou($mouID) { //upload aggrement , ss_price_mou $sql = "select M_MouID,M_MouIsVerified,M_MouVerifyDate,M_MouVerifyUserID,M_MouIsReleased,M_MouStatus from m_mou where M_MouID = ?"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No MOU : " . $this->db_regional->last_query()); } $mou = $rows[0]; $sql = "select * from g_moustatuslog where G_MouStatusLogM_MouID = ? AND G_MouStatusLogStatus = 'UV' ORDER BY G_MouStatusLogID DESC LIMIT 1"; $qry = $this->db_regional->query($sql, array($mouID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Log"); } $logs = $rows; $mou["M_MouUserID"] = 3; // set to 3 foreach ($logs as $idx => $l) { $logs[$idx]["G_MouStatusLogUserID"] = 3; } $param = array( "mou" => $mou, "logs" => $logs ); $param_md5 = md5(json_encode($param)); $j_param = json_encode(array("param" => $param, "md5" => $param_md5)); $sql = "select * from m_branch JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID AND S_RegionalIsDefault = 'Y' where M_BranchIsActive = 'Y'"; $qry = $this->db_regional->query($sql); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $rows = $qry->result_array(); if (count($rows) == 0) { return array(false, "No Ss Price Mou"); } $sql = "insert into tx_mou(TxMouM_BranchIPAddress, TxMouM_BranchCode,TxMouM_MouID, TxMouJson,TxMouM_UserID,TxMouT_TestID ) values(?,?,?,?,?,'-4')"; $flag_error = false; $err_msg = array(); $userID = $this->sys_user["M_UserID"]; foreach ($rows as $r) { $branchCode = $r["M_BranchCode"]; $ipAddress = $r["M_BranchIPAddress"]; $qry = $this->db_regional->query(array($mouID, $branchCode)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } $qry = $this->db_regional->query($sql, array($ipAddress, $branchCode, $mouID, $j_param, $userID)); if (!$qry) { return array(false, print_r($this->db_regional->error(), true)); } try { $txMouID = $this->db_regional->insert_id(); $url = "http://$ipAddress/one-api/tools/price/r_mou/unverify"; $post_rst = $this->post($url, $j_param); $j_rst = json_decode($post_rst, true); if ($j_rst["status"] != "OK") { $err_msg[] = $post_rst; $flag_error = true; $this->db_regional->query("update tx_mou set TxMouRetry = 1 where TxMouID = ? ", array($txMouID)); } else { $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = 1 where TxMouID = ? ", array($txMouID)); } } catch (Exception $e) { $err_msg[] = $e->getMessage(); $flag_error = true; } } if ($flag_error) { return array(false, join(",", $err_msg)); } return array(true, "OK"); } public function releasemou() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $id = $prm['id']; $sql = "update m_mou SET M_MouIsReleased = 'Y', M_MouStatus = 'R', M_MouReleaseDate = now(), M_MouReleaseUserID = '{$userid}', M_MouIsApproved = 'Y', M_MouLastUpdated = now() WHERE M_MouID = ? "; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_mou update"); exit; } $querystatus = "INSERT g_moustatuslog (G_MouStatusLogDate, G_MouStatusLogM_MouID, G_MouStatusLogStatus, G_MouStatusLogUserID, G_MouStatusLogCreated, G_MouStatusLogLastUpdated) VALUES( date(now()), '{$id}', 'R', '{$userid}', now(), now()) "; $rows = $this->db_regional->query($querystatus); $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function unreleasemou() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $id = $prm['id']; $sql = "update m_mou SET M_MouIsReleased = 'N', M_MouStatus = 'UR', M_MouReleaseDate = now(), M_MouReleaseUserID = '{$userid}', M_MouIsApproved = 'N', M_MouLastUpdated = now() WHERE M_MouID = ? "; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_mou update"); exit; } $querystatus = "INSERT g_moustatuslog (G_MouStatusLogDate, G_MouStatusLogM_MouID, G_MouStatusLogStatus, G_MouStatusLogUserID, G_MouStatusLogCreated, G_MouStatusLogLastUpdated) VALUES( date(now()), '{$id}', 'UR', '{$userid}', now(), now()) "; $rows = $this->db_regional->query($querystatus); $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletecompany() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update m_company SET M_CompanyIsActive = 'N', M_CompanyLastUpdated = now() WHERE M_CompanyID = ? "; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_company delete"); exit; } $sql = "UPDATE m_mou SET M_MouIsActive = 'N', M_MouLastUpdated = now() WHERE M_MouM_CompanyID = ? "; $query = $this->db_regional->query( $sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("m_mou delete"); exit; } $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectcompanygrouptype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT * FROM m_companytypegroup WHERE M_CompanyTypeGroupIsActive = 'Y' "; //echo $query; $rows['companygrouptypes'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectcompanygrouptypefilter() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = "SELECT 0 M_CompanyTypeGroupID, 'Semua Grup' M_CompanyTypeGroupName UNION SELECT M_CompanyTypeGroupID, M_CompanyTypeGroupName FROM m_companytypegroup WHERE M_CompanyTypeGroupIsActive = 'Y'"; //echo $query; $rows['companygrouptypes'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectcompanytype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $id = $prm['id']; $rows = []; $query = " SELECT *, COUNT(M_CompanyID) as used FROM (SELECT m_companytype.*,M_CompanyID FROM m_companytype LEFT JOIN m_company ON M_CompanyTypeID = M_CompanyM_CompanyTypeID AND M_CompanyIsActive = 'Y' WHERE M_CompanyTypeIsActive = 'Y' AND M_CompanyTypeM_CompanyTypeGroupID = $id) a GROUP BY M_CompanyTypeID "; //echo $query; $rows['companytypes'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectcompanybusiness() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT *, COUNT(M_CompanyID) as used FROM (SELECT m_companybusiness.*,M_CompanyID FROM m_companybusiness LEFT JOIN m_company ON M_CompanyBusinessID = M_CompanyM_CompanyBusinessID AND M_CompanyIsActive = 'Y' WHERE M_CompanyBusinessIsActive = 'Y') a GROUP BY M_CompanyBusinessID "; //echo $query; $rows['companybusinesss'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectcompanylevel() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $rows = []; $query = " SELECT *,CONCAT(Nat_CompanyLevelName,' [',M_CompanyName,']') as Nat_CompanyLevelName, COUNT(M_CompanyID) as used FROM (SELECT nat_companylevel.*,M_CompanyID,M_CompanyName FROM nat_companylevel LEFT JOIN m_company ON Nat_CompanyLevelNat_CompanyID = M_CompanyID AND M_CompanyIsActive = 'Y' WHERE Nat_CompanyLevelIsActive = 'Y') a GROUP BY Nat_CompanyLevelID "; //echo $query; $rows['companylevels'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selecthierarchy() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT *, COUNT(M_CompanyID) as used FROM (SELECT nat_hierarchy.*,M_CompanyID FROM nat_hierarchy LEFT JOIN m_company ON Nat_HierarchyID = M_CompanyNat_HierarchyID AND M_CompanyIsActive = 'Y' WHERE Nat_HierarchyIsActive = 'Y') a GROUP BY Nat_HierarchyID "; //echo $query; $rows['hierarchys'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectdoctor() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT * FROM m_doctor WHERE M_DoctorIsActive = 'Y' "; //echo $query; $rows['doctors'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function searchdoctor() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count = 0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_doctor WHERE M_DoctorName like ? AND M_DoctorIsActive = 'Y'"; $query = $this->db_regional->query($sql, $q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_doctor count", $this->db_regional); exit; } $sql = " SELECT * FROM(SELECT *, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorNames FROM m_doctor WHERE M_DoctorIsActive = 'Y') a WHERE M_DoctorNames like ? AND M_DoctorIsActive = 'Y' ORDER BY M_DoctorName DESC "; $query = $this->db_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_doctor rows", $this->db_regional); exit; } } function searchcompanylevel() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count = 0; $name = $prm['name']; $hirarkiid = intval($prm['id']) - 1; // QUERY TOTAL $sql = "SELECT count(*) as total FROM nat_companylevel WHERE Nat_CompanyLevelName like '%{$name}%' AND Nat_CompanyLevelNat_HierarchyID = '{$hirarkiid}' AND Nat_CompanyLevelIsActive = 'Y'"; $query = $this->db_regional->query($sql); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("nat_companylevel count", $this->db_regional); exit; } $sql = " SELECT * FROM(SELECT *, CONCAT(Nat_CompanyLevelName, ' [',M_CompanyName,']') as Nat_CompanyLevelNames FROM nat_companylevel LEFT JOIN m_company ON Nat_CompanyLevelNat_CompanyID = M_CompanyID WHERE Nat_CompanyLevelIsActive = 'Y') a WHERE Nat_CompanyLevelName like '%{$name}%' AND Nat_CompanyLevelNat_HierarchyID = '{$hirarkiid}' AND Nat_CompanyLevelIsActive = 'Y' ORDER BY Nat_CompanyLevelName DESC "; $query = $this->db_regional->query($sql); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("nat_companylevel rows", $this->db_regional); exit; } } function searchcity() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count = 0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y'"; $query = $this->db_regional->query($sql, $q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_city count", $this->db_regional); exit; } $sql = " SELECT * FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y' ORDER BY M_CityName DESC "; $query = $this->db_regional->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_regional->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_city rows", $this->db_regional); exit; } } function getstaff() { $prm = $this->sys_input; $query = "SELECT 0 as M_StaffID, 'Pilih Marketing' as M_StaffName UNION SELECT Nat_StaffID as M_StaffID, Nat_StaffName as M_StaffName FROM nat_staff JOIN m_position ON Nat_StaffM_PositionID = M_PositionID AND M_PositionIsMarketing = 'Y' WHERE Nat_StaffIsActive = 'Y'"; //echo $query; $rows = $this->db_regional->query($query, array($prm['id']))->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); exit; } function getprovince() { $prm = $this->sys_input; $query = " SELECT * FROM m_province WHERE M_ProvinceIsActive = 'Y'"; //echo $query; $rows = $this->db_regional->query($query, array($prm['id']))->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); exit; } function getcity() { $prm = $this->sys_input; $query = " SELECT * FROM m_city WHERE M_CityIsActive = 'Y' AND M_CityM_ProvinceID = ? "; //echo $query; $rows = $this->db_regional->query($query, array($prm['id']))->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); exit; } function getdistrict() { $prm = $this->sys_input; $query = " SELECT * FROM m_district WHERE M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ? "; //echo $query; $rows = $this->db_regional->query($query, array($prm['id']))->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); exit; } function getkelurahan() { $prm = $this->sys_input; $query = " SELECT * FROM m_kelurahan WHERE M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ? "; //echo $query; $rows = $this->db_regional->query($query, array($prm['id']))->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); exit; } function selectbase() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT 'SPK' as baseid, 'SPK' as basename UNION SELECT 'MOU' as baseid, 'MOU' as basename "; //echo $query; $rows['bases'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectomzettype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT * FROM m_omzettype WHERE M_OmzetTypeIsActive = 'Y' "; //echo $query; $rows['omzettypes'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectbilltype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT * FROM m_billtype WHERE M_BillTypeIsActive = 'Y' "; //echo $query; $rows['billtypes'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectbranch() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT * FROM m_branch JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID WHERE M_BranchIsActive = 'Y' "; //echo $query; $rows['branchs'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectmoutype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT * FROM m_moutype WHERE M_MouTypeIsActive = 'Y' "; //echo $query; $rows['moutypes'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function selectagingtype() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query = " SELECT * FROM m_agingtype WHERE M_AgingIsActive = 'Y' "; //echo $query; $rows['agingtypes'] = $this->db_regional->query($query)->result_array(); $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function generateRandomString($length = 5) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } function uploadattachment() { try { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $data = []; $error = []; $prm = $this->sys_input; $mouid = $this->input->post('mouid'); $xnumber = $this->input->post('number'); $path = '/home/regional/project/regional/one-media/one-files/'; $config['upload_path'] = $path; $config['allowed_types'] = 'pdf'; $config['max_size'] = 1000; // Maksimal 1000 KB $count = count($_FILES['files']['name']); $this->load->library('upload', $config); // print_r($_FILES['files']['name']); // exit; $file_uploaded = 1; if ($file_uploaded > 1) { $error[] = "Jumlah file yang diupload maksimal 1"; } else { for ($i = 0; $i < $count; $i++) { if (!empty($_FILES['files']['name'][$i])) { // Validasi ukuran file secara manual if ($_FILES['files']['size'][$i] > 1000 * 1024) { // 3000 KB dalam byte $error[] = "File " . $_FILES['files']['name'][$i] . " melebihi ukuran maksimal 1MB."; //print_r($error); continue; // Skip file yang terlalu besar } // echo $_FILES['files']['name'][$i]; // exit; $_FILES['file']['name'] = $_FILES['files']['name'][$i]; $_FILES['file']['type'] = $_FILES['files']['type'][$i]; $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i]; $_FILES['file']['error'] = $_FILES['files']['error'][$i]; $_FILES['file']['size'] = $_FILES['files']['size'][$i]; $namex = $xnumber . '_' . $this->generateRandomString(3); $config['file_name'] = $namex; $this->upload->initialize($config); // print_r($this->upload->do_upload('file')); // exit; if ($this->upload->do_upload('file')) { $sql_count = "SELECT File_AttachmentID FROM file_attachment WHERE File_AttachmentIsActive = 'Y' AND File_AttachmentM_MouID = ?"; $qry_count = $this->db_regional->query($sql_count, array($mouid)); if (!$qry_count) { $this->sys_error_db("select count file attachment error", $this->db_regional); exit; } $row = $qry_count->result_array(); // print_r($row); // echo $this->db_regional->last_query(); // exit; if (count($row['total']) > 0) { $uploadData = $this->upload->data(); $filename = $uploadData['file_name']; //echo $filename; // Proses SQL atau penyimpanan data lainnya $sql = "INSERT INTO file_attachment ( File_AttachmentM_MouID, File_AttachmentFileName, File_AttachmentCreated, File_AttachmentCreatedUserID ) VALUES(?,?,NOW(),?)"; $query = $this->db_regional->query($sql, array($mouid, $filename, $userid)); if (!$query) { $this->sys_error_db("insert file error", $this->db_regional); exit; } } else { $sql_update = "UPDATE file_attachment SET File_AttachmentIsActive = 'N', File_AttachmentDeleted = NOW(), File_AttachmentDeletedUserID = ? WHERE File_AttachmentM_MouID = ?"; $query_update = $this->db_regional->query($sql_update, array($userid, $mouid)); if (!$query_update) { $this->sys_error_db("update file error", $this->db_regional); exit; } $uploadData = $this->upload->data(); $filename = $uploadData['file_name']; //echo $filename; $sql = "INSERT INTO file_attachment ( File_AttachmentM_MouID, File_AttachmentFileName, File_AttachmentCreated, File_AttachmentCreatedUserID ) VALUES(?,?,NOW(),?)"; $query = $this->db_regional->query($sql, array($mouid, $filename, $userid)); if (!$query) { $this->sys_error_db("insert file after delete error", $this->db_regional); exit; } } } else { $error[] = $this->upload->display_errors(); } } } } $result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }