Initial import
This commit is contained in:
523
one-api/application/controllers/v1/masterdata/Bahan.php
Normal file
523
one-api/application/controllers/v1/masterdata/Bahan.php
Normal file
@@ -0,0 +1,523 @@
|
||||
<?php
|
||||
|
||||
class Bahan extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
public function index()
|
||||
{
|
||||
echo "BAHAN API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
|
||||
function lookupsampletype(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$sql = "select Nat_SampleTypeID as id,
|
||||
Nat_SampleTypeNat_BahanID as bahanid,
|
||||
Nat_SampleTypeCode as code,
|
||||
Nat_SampleTypeName as name,
|
||||
Nat_SampleTypeSuffix as suffix,
|
||||
'xxx' as action
|
||||
from nat_sampletype
|
||||
where
|
||||
Nat_SampleTypeNat_BahanID = {$id} AND Nat_SampleTypeIsActive = 'Y'";
|
||||
//echo $sql;
|
||||
$rows = $this->db_regional->query($sql)->result();
|
||||
|
||||
$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'];
|
||||
$all = $prm['all'];
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$sql = "select COUNT(*) as total
|
||||
from nat_bahan
|
||||
where
|
||||
Nat_BahanIsActive = 'Y'";
|
||||
$sql_param = array($search);
|
||||
$total = $this->db_regional->query($sql,$sql_param)->row()->total;
|
||||
|
||||
|
||||
$sql = "select Nat_BahanID as id, Nat_BahanCode as code, Nat_BahanName as name, CONCAT('[ ',Nat_BahanCode,' ]',' ', Nat_BahanName) as description , 'xxx' as bahansampletype
|
||||
from nat_bahan
|
||||
where
|
||||
( Nat_BahanCode LIKE CONCAT('%','{$search}','%') OR
|
||||
Nat_BahanName LIKE CONCAT('%','{$search}','%')
|
||||
)AND
|
||||
Nat_BahanIsActive = 'Y' $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("nat_bahan 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 addnewbahan()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$code_bahan = $prm['code'];
|
||||
$name_bahan = $prm['name'];
|
||||
$query = "SELECT COUNT(*) as exist FROM nat_bahan WHERE Nat_BahanIsActive = 'Y' AND Nat_BahanCode = '{$code_bahan}'";
|
||||
$exist_code = $this->db_regional->query($query)->row()->exist;
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM nat_bahan WHERE Nat_BahanIsActive = 'Y' AND Nat_BahanName = '{$name_bahan}'";
|
||||
$exist_name = $this->db_regional->query($query)->row()->exist;
|
||||
//echo $exist_name;
|
||||
if($exist_code == 0 && $exist_name == 0){
|
||||
$sql = "insert into nat_bahan(
|
||||
Nat_BahanCode,
|
||||
Nat_BahanName,
|
||||
Nat_BahanCreated,
|
||||
Nat_BahanLastUpdated
|
||||
)
|
||||
values( ?, ?, now(), now())";
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$code_bahan,
|
||||
$name_bahan
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("nat_bahan insert");
|
||||
exit;
|
||||
}
|
||||
$sql = "insert into t_bahan(
|
||||
T_BahanCode,
|
||||
T_BahanName,
|
||||
T_BahanCreated,
|
||||
T_BahanLastUpdated
|
||||
)
|
||||
values( ?, ?, now(), now())";
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$code_bahan,
|
||||
$name_bahan
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_bahan insert");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$errors = array();
|
||||
if($exist_code != 0){
|
||||
array_push($errors,array('field'=>'code','msg'=>'Kode sudah ada yang pakai dong'));
|
||||
}
|
||||
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 editbahan()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id_bahan = $prm['id'];
|
||||
$code_bahan = $prm['code'];
|
||||
$name_bahan = $prm['name'];
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM nat_bahan WHERE Nat_BahanIsActive = 'Y' AND Nat_BahanCode = '{$code_bahan}' AND Nat_BahanID <> {$id_bahan}";
|
||||
$exist_code = $this->db_regional->query($query)->row()->exist;
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM nat_bahan WHERE Nat_BahanIsActive = 'Y' AND Nat_BahanName = '{$name_bahan}' AND Nat_BahanID <> {$id_bahan}";
|
||||
$exist_name = $this->db_regional->query($query)->row()->exist;
|
||||
|
||||
if($exist_code == 0 && $exist_name == 0){
|
||||
$sql = "update nat_bahan SET
|
||||
Nat_BahanCode = ?,
|
||||
Nat_BahanName = ?,
|
||||
Nat_BahanLastUpdated = now()
|
||||
where
|
||||
Nat_BahanID = ?
|
||||
";
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$code_bahan,
|
||||
$name_bahan,
|
||||
$id_bahan
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("nat_bahan update");
|
||||
exit;
|
||||
}
|
||||
$sql = "update t_bahan SET
|
||||
T_BahanCode = ?,
|
||||
T_BahanName = ?,
|
||||
T_BahanLastUpdated = now()
|
||||
where
|
||||
T_BahanID = ?
|
||||
";
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$code_bahan,
|
||||
$name_bahan,
|
||||
$id_bahan
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_bahan update");
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => $id_bahan));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$errors = array();
|
||||
if($exist_code != 0){
|
||||
array_push($errors,array('field'=>'code','msg'=>'Kode sudah ada yang pakai dong'));
|
||||
}
|
||||
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 addnewsampletype()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$bahanid = $prm['bahanid'];
|
||||
$code = $prm['code'];
|
||||
$name = $prm['name'];
|
||||
$suffix = $prm['suffix'];
|
||||
//$agingonhold = $prm['agingonhold'];
|
||||
//$agingonholdtime = $prm['agingonholdtime'];
|
||||
// $sampleimgid = $prm['sampleimgid'];
|
||||
|
||||
|
||||
if($prm['xid'] == "0" || $prm['xid'] == 0){
|
||||
$query = "SELECT COUNT(*) as exist FROM nat_sampletype WHERE Nat_SampleTypeIsActive = 'Y' AND Nat_SampleTypeCode = '{$code}'";
|
||||
$exist_code = $this->db_regional->query($query)->row()->exist;
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM nat_sampletype WHERE Nat_SampleTypeIsActive = 'Y' AND Nat_SampleTypeName = '{$name}'";
|
||||
$exist_name = $this->db_regional->query($query)->row()->exist;
|
||||
if($exist_code == 0 && $exist_name == 0){
|
||||
$sql = "insert into nat_sampletype(
|
||||
Nat_SampleTypeNat_BahanID,
|
||||
Nat_SampleTypeCode,
|
||||
Nat_SampleTypeName,
|
||||
Nat_SampleTypeSuffix,
|
||||
Nat_SampleTypeCreated,
|
||||
Nat_SampleTypeLastUpdated
|
||||
)
|
||||
values( ?,?,?,?,now(),now())";
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$bahanid,
|
||||
$code,
|
||||
$name,
|
||||
$suffix
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("nat_sampletype insert");
|
||||
exit;
|
||||
}
|
||||
$sql = "insert into t_sampletype(
|
||||
T_SampleTypeT_BahanID,
|
||||
T_SampleTypeCode,
|
||||
T_SampleTypeName,
|
||||
T_SampleTypeSuffix,
|
||||
T_SampleTypeCreated,
|
||||
T_SampleTypeLastUpdated
|
||||
)
|
||||
values( ?,?,?,?,now(),now())";
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$bahanid,
|
||||
$code,
|
||||
$name,
|
||||
$suffix
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_sampletype insert");
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$errors = array();
|
||||
if($exist_code != 0){
|
||||
array_push($errors,array('field'=>'code','msg'=>'Kode sudah ada yang pakai dong'));
|
||||
}
|
||||
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 nat_sampletype WHERE Nat_SampleTypeIsActive = 'Y' AND Nat_SampleTypeCode = '{$code}' AND Nat_SampleTypeID <> {$prm['xid']}";
|
||||
$exist_code = $this->db_regional->query($query)->row()->exist;
|
||||
//echo $query;
|
||||
$query = "SELECT COUNT(*) as exist FROM nat_sampletype WHERE Nat_SampleTypeIsActive = 'Y' AND Nat_SampleTypeName = '{$name}' AND Nat_SampleTypeID <> {$prm['xid']}";
|
||||
$exist_name = $this->db_regional->query($query)->row()->exist;
|
||||
//echo $query;
|
||||
if($exist_code == 0 && $exist_name == 0){
|
||||
$sql = "UPDATE nat_sampletype SET Nat_SampleTypeCode = '{$code}', Nat_SampleTypeName = '{$name}', Nat_SampleTypeSuffix = '{$suffix}' WHERE Nat_SampleTypeID = '{$prm['xid']}'";
|
||||
//echo $sql;
|
||||
$query = $this->db_regional->query($sql);
|
||||
|
||||
$sqllocal = "UPDATE t_sampletype SET T_SampleTypeCode = '{$code}', T_SampleTypeName = '{$name}', T_SampleTypeSuffix = '{$suffix}' WHERE T_SampleTypeID = '{$prm['xid']}'";
|
||||
//echo $sql;
|
||||
$querylocal = $this->db_regional->query($sqllocal);
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$errors = array();
|
||||
if($exist_code != 0){
|
||||
array_push($errors,array('field'=>'code','msg'=>'Kode sudah ada yang pakai dong'));
|
||||
}
|
||||
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 deletesampletype()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "update nat_sampletype SET
|
||||
Nat_SampleTypeIsActive = 'N',
|
||||
Nat_SampleTypeLastUpdated = now()
|
||||
WHERE
|
||||
Nat_SampleTypeID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("nat_sampletype delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "update t_sampletype SET
|
||||
T_SampleTypeIsActive = 'N',
|
||||
T_SampleTypeLastUpdated = now()
|
||||
WHERE
|
||||
T_SampleTypeID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_sampletype 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 deletebahan()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "update nat_bahan SET
|
||||
Nat_BahanIsActive = 'N',
|
||||
Nat_BahanLastUpdated = now()
|
||||
WHERE
|
||||
Nat_BahanID = ?
|
||||
|
||||
";
|
||||
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("nat_bahan delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE nat_sampletype SET
|
||||
Nat_SampleTypeIsActive = 'N',
|
||||
Nat_SampleTypeLastUpdated = now()
|
||||
WHERE
|
||||
Nat_SampleTypeNat_BahanID = ?
|
||||
";
|
||||
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("nat_sampletype delete");
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE t_sampletype SET
|
||||
T_SampleTypeIsActive = 'N',
|
||||
T_SampleTypeLastUpdated = now()
|
||||
WHERE
|
||||
T_SampleTypeNat_BahanID = ?
|
||||
";
|
||||
|
||||
$query = $this->db_regional->query($sql,
|
||||
array(
|
||||
$prm['id']
|
||||
)
|
||||
);
|
||||
// echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_sampletype delete");
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user