Files
BE_IBL/application/controllers/tools/price/Extendmou.php
2026-04-15 15:23:57 +07:00

86 lines
2.7 KiB
PHP

<?php
class Extendmou extends MY_Controller
{
function __construct() {
parent::__construct();
//$this->db = $this->load->database('regional', true);
$this->db = $this->load->database('onedev', true);
}
function is_exists($table, $field, $value) {
$this->db->where($field,$value);
$qry = $this->db->get($table);
if (! $qry) {
echo json_encode(array("status" => "ERR", "message" => "Cek exists $table $field $value". print_r($this->db->error(),true) ));
exit;
}
if (! empty($qry->result_array())) {
return true;
}
return false;
}
function verify() {
$md5 = $this->sys_input["md5"];
$param = $this->sys_input["param"];
$j_param = json_encode($param);
$l_md5 = md5($j_param);
if ($md5 != $l_md5 ) {
echo json_encode(array("status" => "ERR", "message" => "MD5 $md5 <> $l_md5"));
exit;
}
$mou = $param["mou"];
if ( $this->is_exists("m_mou","M_MouID", $mou["M_MouID"]) ) {
$this->db->where("M_MouID", $mou["M_MouID"]);
$qry = $this->db->update("m_mou",$mou);
} else {
$qry = $this->db->insert("m_mou",$mou);
}
if (! $qry ) {
echo json_encode(array("status" => "ERR", "message" => "Update MOU : " . print_r($this->db->error(),true) ));
exit;
}
echo json_encode( array("status" => "OK" , "message" => "" , "mouID" => $mou["M_MouID"]));
}
function editflag() {
$md5 = $this->sys_input["md5"];
$param = $this->sys_input["param"];
$j_param = json_encode($param);
$l_md5 = md5($j_param);
if ($md5 != $l_md5 ) {
echo json_encode(array("status" => "ERR", "message" => "MD5 $md5 <> $l_md5"));
exit;
}
$mou = $param["mou"];
if ( $this->is_exists("m_mou","M_MouID", $mou["M_MouID"]) ) {
$this->db->where("M_MouID", $mou["M_MouID"]);
$qry = $this->db->update("m_mou",$mou);
} else {
$qry = $this->db->insert("m_mou",$mou);
}
if ($mou["M_MouIsDefault"] == 'Y') {
$idmou = $mou["M_MouID"];
$query = "SELECT M_MouM_CompanyID as companyid FROM m_mou WHERE M_MouID = {$idmou}";
$companyid = $this->db->query($query)->row()->companyid;
$sql = "update m_mou SET
M_MouIsDefault = 'N'
WHERE M_MouIsDefault = 'Y' AND M_MouM_CompanyID = '{$companyid}' AND
M_MouID <> ?";
$query = $this->db->query($sql,$mou["M_MouID"]);
}
if (! $qry ) {
echo json_encode(array("status" => "ERR", "message" => "Update MOU : " . print_r($this->db->error(),true) ));
exit;
}
echo json_encode( array("status" => "OK" , "message" => "" , "mouID" => $mou["M_MouID"]));
}
}