382 lines
11 KiB
PHP
Executable File
382 lines
11 KiB
PHP
Executable File
<?php
|
|
|
|
class Item extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "ITEM API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function lookupitem()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$all = $prm['all'];
|
|
$limit = '';
|
|
if($all == 'N'){
|
|
$limit = ' LIMIT 10';
|
|
}
|
|
$sql = "select COUNT(*) as total
|
|
from m_itemadditional
|
|
where
|
|
M_ItemAdditionalIsActive = 'Y'";
|
|
$total = $this->db_onedev->query($sql)->row()->total;
|
|
|
|
|
|
$sql = "select M_ItemAdditionalID as id, M_ItemAdditionalCode as code, M_ItemAdditionalName as name,M_ItemAdditionalMandatory as flagmandatory, IF(M_ItemAdditionalMandatory = 'N',CONCAT('[ ',M_ItemAdditionalCode,' ] ',M_ItemAdditionalName),CONCAT('[ ',M_ItemAdditionalCode,' ] ',M_ItemAdditionalName,'*')) as namex,M_ItemAdditionalPrice as price,'xxx' as itemtests
|
|
from m_itemadditional
|
|
where
|
|
( M_ItemAdditionalCode LIKE CONCAT('%',?,'%') OR M_ItemAdditionalName LIKE CONCAT('%',?,'%')) AND
|
|
M_ItemAdditionalIsActive = 'Y' $limit";
|
|
$sql_param = array($search,$search);
|
|
$query = $this->db_onedev->query($sql,$sql_param);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
} else {
|
|
$this->sys_error_db("m_itemadditional 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 save()
|
|
{
|
|
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;
|
|
$code = $prm['code'];
|
|
$name = $prm['name'];
|
|
$price = $prm['price'];
|
|
$flagmandatory = $prm['flagmandatory'];
|
|
if($prm['act'] == 'new'){
|
|
$query = "SELECT COUNT(*) as exist FROM m_itemadditional WHERE M_ItemAdditionalIsActive = 'Y' AND M_ItemAdditionalCode = '{$code}'";
|
|
$exist_code = $this->db_onedev->query($query)->row()->exist;
|
|
$query = "SELECT COUNT(*) as exist FROM m_itemadditional WHERE M_ItemAdditionalIsActive = 'Y' AND M_ItemAdditionalName = '{$name}'";
|
|
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
|
|
|
if($exist_code == 0 && $exist_name == 0){
|
|
$sql = "insert into m_itemadditional(
|
|
M_ItemAdditionalCode,
|
|
M_ItemAdditionalName,
|
|
M_ItemAdditionalMandatory,
|
|
M_ItemAdditionalPrice,
|
|
M_ItemAdditionalUserID,
|
|
M_ItemAdditionalCreatedDate,
|
|
M_ItemAdditionalLastUpdated
|
|
)
|
|
values( ?,?,?,?,?,now(),now())";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$code,
|
|
$name,
|
|
$flagmandatory,
|
|
$price,
|
|
$userid
|
|
)
|
|
);
|
|
//echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_itemadditional insert");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
}else{
|
|
$errors = array();
|
|
if($exist_code > 0){
|
|
array_push($errors,"errorcode");
|
|
}
|
|
if($exist_name > 0){
|
|
array_push($errors,"errorname");
|
|
}
|
|
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
|
$this->sys_ok($result);
|
|
}
|
|
}else{
|
|
$query = "SELECT COUNT(*) as exist FROM m_itemadditional WHERE M_ItemAdditionalIsActive = 'Y' AND M_ItemAdditionalCode = '{$code}' AND M_ItemAdditionalID <> {$prm['id']}";
|
|
$exist_code = $this->db_onedev->query($query)->row()->exist;
|
|
$query = "SELECT COUNT(*) as exist FROM m_itemadditional WHERE M_ItemAdditionalIsActive = 'Y' AND M_ItemAdditionalName = '{$name}' AND M_ItemAdditionalID <> {$prm['id']}";
|
|
$exist_name = $this->db_onedev->query($query)->row()->exist;
|
|
|
|
if($exist_code == 0 && $exist_name == 0){
|
|
$sql = "UPDATE m_itemadditional SET
|
|
M_ItemAdditionalCode = ?,
|
|
M_ItemAdditionalName = ?,
|
|
M_ItemAdditionalMandatory = ?,
|
|
M_ItemAdditionalPrice = ?,
|
|
M_ItemAdditionalLastUpdated = now()
|
|
WHERE
|
|
M_ItemAdditionalID = ?";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$code,
|
|
$name,
|
|
$flagmandatory,
|
|
$price,
|
|
$prm['id']
|
|
)
|
|
);
|
|
//echo $query;
|
|
if (!$query) {
|
|
//echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("m_itemadditional update");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => $prm['id']));
|
|
$this->sys_ok($result);
|
|
}else{
|
|
$errors = array();
|
|
if($exist_code > 0){
|
|
array_push($errors,"errorcode");
|
|
}
|
|
if($exist_name > 0){
|
|
array_push($errors,"errorname");
|
|
}
|
|
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
|
$this->sys_ok($result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
public function deleteitem()
|
|
{
|
|
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;
|
|
|
|
$sql = "update m_itemadditional SET
|
|
M_ItemAdditionalIsActive = 'N',
|
|
M_ItemAdditionalUserID = ?,
|
|
M_ItemAdditionalLastUpdated = now()
|
|
WHERE
|
|
M_ItemAdditionalID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$userid,
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
//echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("m_item delete");
|
|
exit;
|
|
}
|
|
|
|
$sql = "update m_itemadditionaltest SET
|
|
M_ItemAdditionalTestIsActive = 'N',
|
|
M_ItemAdditionalTestLastUpdated = now()
|
|
WHERE
|
|
M_ItemAdditionalTestM_ItemAdditionalID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
//echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("m_itemadditionaltest 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 lookupitemtests(){
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$sql = "select M_ItemAdditionalTestID as id, T_TestName as testname, M_ItemAdditionalTestT_TestID as testid
|
|
from m_itemadditionaltest
|
|
JOIN t_test ON M_ItemAdditionalTestT_TestID = T_TestID AND T_TestIsActive = 'Y'
|
|
where
|
|
M_ItemAdditionalTestM_ItemAdditionalID = {$id} AND M_ItemAdditionalTestIsActive = 'Y'";
|
|
$sql_param = array($orderid);
|
|
$query = $this->db_onedev->query($sql,$sql_param);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("m_itemadditionaltest select by itemadditional");
|
|
exit;
|
|
}
|
|
$result = array ("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function lookuptests()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$search = $prm["search"];
|
|
$sql_param = array($search,$search);
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM t_test
|
|
WHERE
|
|
(T_TestCode like CONCAT('%','{$search}','%') OR T_TestName like CONCAT('%','{$search}','%')) AND
|
|
T_TestIsActive = 'Y'
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
|
|
$tot_count = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
} else {
|
|
echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("t_test count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT T_TestID as testid,
|
|
T_TestCode as testcode,
|
|
T_TestName as testname
|
|
FROM t_test
|
|
WHERE
|
|
(T_TestCode like CONCAT('%','{$search}','%') OR T_TestName like CONCAT('%','{$search}','%')) AND
|
|
T_TestIsActive = 'Y'
|
|
ORDER BY T_TestName ASC
|
|
limit 0,20";
|
|
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
//echo $this->db_onedev->last_query();
|
|
$rows = $query->result_array();
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function saveitemtest(){
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
$id = $prm['itemid'];
|
|
$itemtests = $prm['itemtests'];
|
|
$deleteditemtests = $prm['deleteditemtest'];
|
|
|
|
foreach($itemtests as $k=>$v){
|
|
if($v['id'] == 0){
|
|
$sql = "INSERT INTO m_itemadditionaltest (
|
|
M_ItemAdditionalTestT_TestID,
|
|
M_ItemAdditionalTestM_ItemAdditionalID,
|
|
M_ItemAdditionalTestUserID
|
|
)
|
|
VALUES(?,?,?)";
|
|
$sql_param = array($v['testid'],$id,$userid);
|
|
$query = $this->db_onedev->query($sql,$sql_param);
|
|
}
|
|
}
|
|
|
|
if($deleteditemtests){
|
|
foreach($deleteditemtests as $k=>$v){
|
|
$sql = "UPDATE m_itemadditionaltest SET
|
|
M_ItemAdditionalTestIsActive = 'N',
|
|
M_ItemAdditionalTestUserID = ?
|
|
WHERE
|
|
M_ItemAdditionalTestID = ?
|
|
";
|
|
$sql_param = array($userid,$v['id']);
|
|
$query = $this->db_onedev->query($sql,$sql_param);
|
|
}
|
|
}
|
|
|
|
|
|
$result = array ("total" => 1, "records" => array());
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|