255 lines
9.6 KiB
PHP
255 lines
9.6 KiB
PHP
<?php
|
|
class Blooddestroy extends MY_Controller
|
|
{
|
|
var $db;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
function index()
|
|
{
|
|
echo "API PEMUSNAHAN DARAH";
|
|
// $cek = $this->db->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = "%%";
|
|
if(isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != ""){
|
|
$search = "%" . $prm["search"] . "%";
|
|
}else{
|
|
$search = "%%";
|
|
}
|
|
}
|
|
$start_date = date("Y-m-d");
|
|
if (isset($prm['start_date'])) {
|
|
$start_date = $prm["start_date"];
|
|
}
|
|
$end_date = date("Y-m-d");
|
|
if (isset($prm['end_date'])) {
|
|
$end_date = $prm["end_date"];
|
|
}
|
|
|
|
$sortBy = $prm["sortBy"];
|
|
$sortStatus = $prm["sortStatus"];
|
|
if($sortBy){
|
|
$q_sort = "ORDER BY ".$sortBy." ".$sortStatus;
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
if($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_filter = "SELECT count(*) as total
|
|
FROM one_bb.td_orderdestroy
|
|
JOIN one_bb.td_order ON Td_OrderDestroyTd_OrderID = Td_OrderID
|
|
AND Td_OrderIsActive = 'Y'
|
|
JOIN one_bb.td_donor ON Td_OrderTd_DonorID = Td_DonorID
|
|
AND Td_DonorIsActive = 'Y'
|
|
JOIN one_bb.td_orderbag ON Td_OrderBagID = Td_OrderDestroyTd_OrderBagID
|
|
AND Td_OrderBagIsActive = 'Y'
|
|
JOIN one_bb.td_bloodtype ON Td_DonorTd_BloodTypeID = Td_BloodTypeID
|
|
AND Td_BloodTypeIsActive = 'Y'
|
|
JOIN one_bb.td_orderaftap ON Td_OrderID = Td_OrderAftapTd_OrderID
|
|
AND Td_OrderAftapIsActive = 'Y'
|
|
LEFT JOIN one_bb.td_bloodcategory ON Td_OrderAftapTd_BloodCategoryID = Td_BloodCategoryID
|
|
AND Td_BloodCategoryIsActive = 'Y'
|
|
LEFT JOIN one_bb.m_almari ON Td_OrderDestroyM_AlmariID = M_AlmariID
|
|
AND M_AlmariIsActive = 'Y'
|
|
JOIN one_bb.td_orderimltd ON Td_OrderID = Td_OrderImltdTd_OrderID
|
|
AND Td_OrderImltdIsActive = 'Y'
|
|
WHERE Td_OrderDestroyIsActive = 'Y' AND
|
|
(DATE(Td_OrderDate) BETWEEN ? AND ?) AND (Td_OrderBagNumber LIKE ?)";
|
|
$qry_filter = $this->db->query($sql_filter, array($start_date, $end_date, $search));
|
|
// $last_qry = $this->db->last_query();
|
|
// print_r($last_qry);
|
|
$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("pemusnahan darah count", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql_data = "SELECT Td_OrderDestroyID as id,
|
|
Td_OrderDestroyTd_OrderID as order_id,
|
|
DATE_FORMAT(Td_OrderDate, '%d-%m-%Y') as donor_created,
|
|
Td_OrderBagNumber as no_bag,
|
|
Td_DonorName as donor_name,
|
|
Td_BloodTypeCode as blood_type,
|
|
Td_OrderDestroyVolume as volume,
|
|
Td_BloodCategoryCode as blood_category,
|
|
Td_OrderDestroyM_AlmariID as almariId,
|
|
M_AlmariName as almari_name,
|
|
DATE_FORMAT(Td_OrderDestroyDestroyDate, '%d-%m-%Y') as destroy_date,
|
|
Td_OrderDestroyNote as note,
|
|
Td_OrderDestroyIsDestroy as is_destroy,
|
|
Td_OrderAftapCheckBag as check_bag,
|
|
Td_OrderImltdResult as imltd_result,
|
|
Td_OrderImltdNatResult as nat_result
|
|
FROM one_bb.td_orderdestroy
|
|
JOIN one_bb.td_order ON Td_OrderDestroyTd_OrderID = Td_OrderID
|
|
AND Td_OrderIsActive = 'Y'
|
|
JOIN one_bb.td_donor ON Td_OrderTd_DonorID = Td_DonorID
|
|
AND Td_DonorIsActive = 'Y'
|
|
JOIN one_bb.td_orderbag ON Td_OrderBagID = Td_OrderDestroyTd_OrderBagID
|
|
AND Td_OrderBagIsActive = 'Y'
|
|
JOIN one_bb.td_bloodtype ON Td_DonorTd_BloodTypeID = Td_BloodTypeID
|
|
AND Td_BloodTypeIsActive = 'Y'
|
|
JOIN one_bb.td_orderaftap ON Td_OrderID = Td_OrderAftapTd_OrderID
|
|
AND Td_OrderAftapIsActive = 'Y'
|
|
LEFT JOIN one_bb.td_bloodcategory ON Td_OrderAftapTd_BloodCategoryID = Td_BloodCategoryID
|
|
AND Td_BloodCategoryIsActive = 'Y'
|
|
LEFT JOIN one_bb.m_almari ON Td_OrderDestroyM_AlmariID = M_AlmariID
|
|
AND M_AlmariIsActive = 'Y'
|
|
JOIN one_bb.td_orderimltd ON Td_OrderID = Td_OrderImltdTd_OrderID
|
|
AND Td_OrderImltdIsActive = 'Y'
|
|
WHERE Td_OrderDestroyIsActive = 'Y' AND
|
|
(DATE(Td_OrderDate) BETWEEN ? AND ?) AND (Td_OrderBagNumber LIKE ?)
|
|
$q_sort LIMIT ? OFFSET ?";
|
|
$qry_data = $this->db->query($sql_data, array($start_date, $end_date, $search, $number_limit, $number_offset));
|
|
// $last_qry = $this->db->last_query();
|
|
// print_r($last_qry);
|
|
if ($qry_data) {
|
|
$rows = $qry_data->result_array();
|
|
} else {
|
|
$this->sys_error_db("pemusnahan darah select", $this->db);
|
|
exit;
|
|
}
|
|
|
|
foreach($rows as $idx => $r) {
|
|
$check_bag = $r['check_bag'];
|
|
$json_checkbag = json_decode($check_bag);
|
|
$str_check_bag = implode(', ',$json_checkbag);
|
|
$rows[$idx]['check_bag'] = $str_check_bag;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_page,
|
|
"total_filter" => count($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_almari()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT M_AlmariID as almariId,
|
|
M_AlmariCode as almaricode,
|
|
M_AlmariName as almariname
|
|
FROM one_bb.m_almari
|
|
WHERE M_AlmariIsActive = 'Y'";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
// echo $last_qry;
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function destroy()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$almariId = "";
|
|
if (isset($prm['almariId'])) {
|
|
if (is_numeric($prm["almariId"])) {
|
|
$almariId = trim($prm["almariId"]);
|
|
}
|
|
}
|
|
$note = "";
|
|
if (isset($prm['note'])){
|
|
$note = trim($prm["note"]);
|
|
}
|
|
$destroyId = "";
|
|
if (isset($prm['destroyId'])) {
|
|
if (is_numeric($prm["destroyId"])) {
|
|
$destroyId = trim($prm["destroyId"]);
|
|
}
|
|
}
|
|
|
|
$sql = "UPDATE one_bb.td_orderdestroy SET
|
|
Td_OrderDestroyM_AlmariID = ?,
|
|
Td_OrderDestroyNote = ?,
|
|
Td_OrderDestroyIsDestroy = 'Y',
|
|
Td_OrderDestroyDestroyDate = NOW(),
|
|
Td_OrderDestroyDestroyUserID = ?,
|
|
Td_OrderDestroyUserID = ?,
|
|
Td_OrderDestroyLastUpdated = NOW()
|
|
WHERE Td_OrderDestroyID = ?";
|
|
$qry = $this->db->query($sql, array($almariId, $note, $userid, $userid, $destroyId));
|
|
$last_qry= $this->db->last_query();
|
|
// print_r($last_qry);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"affected_rows" => $this->db->affected_rows()
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|
|
?>
|