Files
2026-04-27 10:31:17 +07:00

211 lines
4.7 KiB
PHP

<?php
class Numbering extends MY_Controller
{
var $db_antrione;
public function index()
{
echo "SERVICE API";
}
public function __construct()
{
parent::__construct();
$this->db_antrione = $this->load->database("antrione", true);
}
public function loadx()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
$prm = $this->sys_input;
$sql = "select COUNT(*) as total
from numbering
where
numberingIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_antrione->query($sql,$sql_param)->row()->total;
$sql = "select *
from numbering
join service ON numberingServiceID = ServiceID
where
numberingIsActive = 'Y'";
$sql_param = array($search);
$query = $this->db_antrione->query($sql,$sql_param);
//echo $this->db_antrione->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("numbering 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;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$serviceid = $prm['serviceid'];
$prefix = $prm['prefix'];
$prefixdate = $prm['prefixdate'];
$digit = $prm['digit'];
$sufix = $prm['sufix'];
$counter = $prm['counter'];
$reset = $prm['reset'];
$sql = "insert into numbering(
numberingServiceID,
numberingPrefix,
numberingPrefixDate,
numberingDigit,
numberingSufix,
numberingCounter,
numberingReset
)
values( ?,?,?,?,?,?,?)";
$query = $this->db_antrione->query($sql,
array(
$serviceid,
$prefix,
$prefixdate,
$digit,
$sufix,
$counter,
$reset
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("numbering insert");
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 update()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$serviceid = $prm['serviceid'];
$prefix = $prm['prefix'];
$prefixdate = $prm['prefixdate'];
$digit = $prm['digit'];
$sufix = $prm['sufix'];
$counter = $prm['counter'];
$reset = $prm['reset'];
$sql = "update numbering set
numberingServiceID = ?,
numberingPrefix = ?,
numberingPrefixDate = ?,
numberingDigit = ?,
numberingSufix = ?,
numberingCounter = ?,
numberingReset = ?
where numberingID = ?
";
$query = $this->db_antrione->query($sql,
array(
$serviceid,
$prefix,
$prefixdate,
$digit,
$sufix,
$counter,
$reset,
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("numbering update");
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 deletex()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "update numbering set
numberingIsActive = 'N'
where numberingID = ?
";
$query = $this->db_antrione->query($sql,
array(
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("numbering delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}