Flatten mockup repo

This commit is contained in:
sas.fajri
2026-04-27 10:31:17 +07:00
parent bf9b9097ee
commit 8ba3d33c6d
3307 changed files with 2795939 additions and 1 deletions

Submodule application/controllers/mockup deleted from 9ca114c1e7

View File

@@ -0,0 +1,181 @@
<?php
class Main extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Report Main API";
}
public function __construct()
{
parent::__construct();
$this->db_one= $this->load->database("onedev", true);
}
function detail(){
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select *
from
r_reportdetail
left join r_reportparam on R_ReportDetailR_ReportParamID = R_ReportParamID
left join r_inputtype on R_ReportParamR_InputTypeID = R_InputTypeID
and R_ReportDetailIsActive = 'Y'
where R_ReportDetailR_ReportID = ?
order by R_ReportDetailID, R_ReportDetailPriority desc";
// echo $sql;
$qry = $this->db_one->query($sql, array($id) );
$last_q = $this->db_one->last_query();
if ($qry) {
$rows = $qry->result_array();
foreach($rows as $idx => $r) {
$rows[$idx]["model"] = "";
$rows[$idx]["tmp_date"] = false;
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} else {
$message = "Err Report Query";
$this->sys_error($message,$this->db_one);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function list(){
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$q_search = "";
$q_param = array();
if ($search !== "") {
$q_search = " where ( R_ReportCode like ? or R_ReportName like ? ) ";
$q_param[] = "%$search%";
$q_param[] = "%$search%";
}
$sql = "select
R_ReportGroupID, R_ReportGroupName, R_ReportGroupColor,
R_ReportID, R_ReportCode, R_ReportName, R_ReportUrl
from r_report
join r_reportgroup on R_ReportGroupID = R_ReportR_ReportGroupID
and R_ReportIsActive = 'Y'
$q_search ORDER BY R_ReportGroupName ASC, R_ReportCode ASC";
//echo $sql;
if ($q_search == "" ) {
$qry = $this->db_one->query($sql);
} else {
$qry = $this->db_one->query($sql,$q_param);
}
$last_q = $this->db_one->last_query();
if ($qry) {
$rows = $qry->result_array();
$reports = array();
$prev_group = 0;
$idx = -1;
foreach($rows as $r) {
if ($prev_group != $r["R_ReportGroupID"] ) {
$idx++;
$reports[] = array("id"=>$r["R_ReportGroupID"], "name" => $r["R_ReportGroupName"],
"color" => $r["R_ReportGroupColor"],
"reports" => array());
}
$prev_group = $r["R_ReportGroupID"];
$reports[$idx]["reports"][] = $r;
}
$result = array ("total" => count($reports), "records" => $reports);
$this->sys_ok($result);
} else {
$message = "Err Report Query";
$this->sys_error($message,$this->db_one);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function lookupparam()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
from r_reportparam
LEFT JOIN r_inputtype ON R_ReportParamR_InputTypeID = R_InputTypeID AND R_InputTypeIsActive = 'Y'
where
(R_ReportParamName LIKE CONCAT('%','{$search}','%') OR
IFNULL(R_InputTypeName,'') LIKE CONCAT('%','{$search}','%') OR
IFNULL(R_ReportParamLabel,'') LIKE CONCAT('%','{$search}','%')) AND
R_ReportParamIsActive = 'Y'";
$sql_param = array($search);
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("r_reportparam count", $this->db_onedev);
exit;
}
$sql = "select R_ReportParamID as id,
R_InputTypeName,
r_reportparam.*
from r_reportparam
LEFT JOIN r_inputtype ON R_ReportParamR_InputTypeID = R_InputTypeID AND R_InputTypeIsActive = 'Y'
where
(R_ReportParamName LIKE CONCAT('%','{$search}','%') OR
IFNULL(R_InputTypeName,'') LIKE CONCAT('%','{$search}','%') OR
IFNULL(R_ReportParamLabel,'') LIKE CONCAT('%','{$search}','%')) AND
R_ReportParamIsActive = 'Y'
GROUP BY R_ReportParamID
ORDER BY R_ReportParamName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("r_reportparam select");
exit;
}
$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);
}
}
}

View File

@@ -0,0 +1,627 @@
<?php
class Gateway extends MY_Controller
{
var $db_onedev;
var $load;
var $hostname;
private $translationAPIUrl = 'https://devone.aplikasi.web.id/one-api/ai-lab-translate/ai_lab/sendToAi';
public function index()
{
// ini di devcpone
echo "API BE untuk Gateway AI Lab";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database('onedev', TRUE);
$this->hostname = "devcpone.aplikasi.web.id";
}
public function translateLabArr($T_OrderHeaderID)
{
$sql = "SELECT
T_OrderDetailID as orderDetailID,
T_OrderDetailT_TestID as T_TestID,
T_OrderDetailResult as result,
T_OrderDetailT_OrderHeaderID as T_OrderHeaderID
FROM t_orderdetail
WHERE T_OrderDetailT_OrderHeaderID = ?
AND T_OrderDetailIsActive = 'Y'
AND T_OrderDetailValidation = 'Y'
AND T_OrderDetailResult IS NOT NULL
";
$query = $this->db_onedev->query($sql, array(
$T_OrderHeaderID
));
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$array = $query->result_array();
$notTranslated = [];
$translated = [];
$allData = [];
/* Looping didalam array untuk mengambil order result */
$inputs = [];
foreach ($array as $key => $item) {
/* Kalau pakai isNumeric nanti "0 - 1" tidak terfilter */
if (!preg_match('/[a-zA-Z]/', $item['result'])) {
$notTranslated[] = [
'orderDetailID' => $item['orderDetailID'],
'original' => $item['result'],
'translated' => $item['result'],
'confidence' => 1
];
continue;
}
$translated[] = [
'orderDetailID' => $item['orderDetailID'],
'original' => $item['result'],
'translated' => '',
'confidence' => 0
];
$inputs[] = $item['result'];
}
/* Jika panjang input lebih dari 0 maka lakukan curl */
if (count($inputs) > 0) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://devone.aplikasi.web.id/one-api/ai-lab-translate/ai_lab/sendToAi',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(['data' => $inputs]),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
curl_close($curl);
$result = json_decode($response, true);
$outputs = $result['data']['output'];
foreach ($outputs as $key => $output) {
$translated[$key]['translated'] = $output['translated'];
$translated[$key]['confidence'] = $output['confidence'];
}
}
$sqlInsert = "INSERT INTO t_orderdetaillang_ai (
T_OrderDetailLangAiT_OrderHeaderID,
T_OrderDetailLangAiT_OrderDetailID,
T_OrderDetailLangAiNat_LangID,
T_OrderDetailLangAiResult,
T_OrderDetailLangAiConfidence
) VALUES (?,?,?,?,?)
ON DUPLICATE KEY UPDATE
T_OrderDetailLangAiResult = VALUES(T_OrderDetailLangAiResult),
T_OrderDetailLangAiConfidence = VALUES(T_OrderDetailLangAiConfidence),
T_OrderDetailLangAiLastUpdated = NOW()";
$this->db_onedev->trans_start(true); // (true) jika debugging
foreach (array_merge($translated, $notTranslated) as $entry) {
$query = $this->db_onedev->query($sqlInsert, [
$T_OrderHeaderID,
$entry['orderDetailID'],
2,
$entry['translated'],
$entry['confidence']
]);
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
}
$this->db_onedev->trans_complete();
$this->sys_ok("OK");
}
public function translateLabStr($T_OrderHeaderID)
{
$sql = "SELECT
T_OrderDetailID as orderDetailID,
T_OrderDetailT_TestID as T_TestID,
T_OrderDetailResult as result,
T_OrderDetailT_OrderHeaderID as T_OrderHeaderID
FROM t_orderdetail
WHERE T_OrderDetailT_OrderHeaderID = ?
AND T_OrderDetailIsActive = 'Y'
AND T_OrderDetailValidation = 'Y'
AND T_OrderDetailResult IS NOT NULL ";
$query = $this->db_onedev->query($sql, array(
$T_OrderHeaderID
));
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$array = $query->result_array();
$notTranslated = [];
$translated = [];
$inputs = [];
foreach ($array as $key => $item) {
/* Kalau pakai isNumeric nanti "0 - 1" tidak terfilter */
if (!preg_match('/[a-zA-Z]/', $item['result'])) {
$notTranslated[] = [
'orderDetailID' => $item['orderDetailID'],
'original' => $item['result'],
'translated' => $item['result'],
'confidence' => 1
];
continue;
}
$translated[] = [
'orderDetailID' => $item['orderDetailID'],
'original' => $item['result'],
'translated' => '',
'confidence' => 0
];
$inputs[] = $item['result'];
}
// Ambil input yang berbeda saja
$distinctInputs = array_values(array_unique($inputs));
$distinctInputMap = array_flip($distinctInputs); // Map untuk mengembalikan hasil ke translated
$sql = "SELECT Translate_WordTo FROM translate_word
WHERE Translate_WordNat_LangID = 2
AND Translate_WordIsActive = 'Y'
AND Translate_WordFrom = ?";
$hasilLookup = [];
$lookupMap = [];
// Lookup ke tabel translate_word, jika sudah ada ambil dari sana
foreach ($distinctInputs as $key => $item) {
$query = $this->db_onedev->query($sql, $item);
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$result = $query->row_array();
if ($result) {
$hasilLookup[] = [
'original' => $item,
'translated' => $result['Translate_WordTo'],
];
$lookupMap[] = $item;
unset($distinctInputs[$key]);
unset($distinctInputMap[$item]);
}
}
// var_dump($distinctInputs, $distinctInputMap, $hasilLookup);
$lookupMap = array_flip($lookupMap);
// Memasukkan hasil lookup ke translated berdasar lookupMap
foreach ($translated as &$entry) {
$original = $entry['original'];
if (isset($lookupMap[$original])) {
$entry['translated'] = $hasilLookup[$lookupMap[$original]]['translated'];
$entry['confidence'] = 1;
}
}
// die(var_dump($hasilLookup, $distinctInputs, $distinctInputMap, $translated));
$distictInputsStr = implode(" + ", $distinctInputs);
if (count($distinctInputs) > 0) {
$result = $this->calldevone($distictInputsStr);
$outputAi = $result['data']['output'];
$outputAi = trim($result['data']['output'], '"'); // remove double quote because apis handling
$outputAiArray = explode(" + ", $outputAi); // separete by +
$outputAiArray = array_map('trim', $outputAiArray); //remove space
$outputAiConfidence = $result['data']['confidence'];
$distinctInputMap = array_flip($distinctInputs);
foreach ($translated as &$entry) {
$original = $entry['original'];
if (isset($distinctInputMap[$original])) {
$entry['translated'] = $outputAiArray[$distinctInputMap[$original]];
$entry['confidence'] = $outputAiConfidence;
}
}
}
// die(var_dump($outputAi, $translated));
$sqlInsert = "INSERT INTO t_orderdetaillang_ai (
T_OrderDetailLangAiT_OrderHeaderID,
T_OrderDetailLangAiT_OrderDetailID,
T_OrderDetailLangAiNat_LangID,
T_OrderDetailLangAiResult,
T_OrderDetailLangAiConfidence
) VALUES (?,?,?,?,?)
ON DUPLICATE KEY UPDATE
T_OrderDetailLangAiResult = VALUES(T_OrderDetailLangAiResult),
T_OrderDetailLangAiConfidence = VALUES(T_OrderDetailLangAiConfidence),
T_OrderDetailLangAiLastUpdated = NOW()";
// $this->db_onedev->trans_start(true);
$this->db_onedev->trans_start();
foreach (array_merge($translated, $notTranslated) as $entry) {
$query = $this->db_onedev->query($sqlInsert, [
$T_OrderHeaderID,
$entry['orderDetailID'],
2,
$entry['translated'],
$entry['confidence']
]);
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
}
$this->db_onedev->trans_complete();
$this->sys_ok([
'translated' => $translated,
'notTranslated' => $notTranslated
]);
return true;
}
public function byorderheaderid()
{
$startDate = $this->sys_input['headerStartDate'];
$endDate = $this->sys_input['headerEndDate'];
$sql = "SELECT
T_OrderDetailT_OrderHeaderID as ID,
T_OrderHeaderDate
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
WHERE T_OrderDetailIsActive = 'Y'
AND T_OrderDetailValidation = 'Y'
AND T_OrderHeaderIsActive = 'Y'
AND T_OrderDetailResult IS NOT NULL
AND (DATE_FORMAT(T_OrderHeaderDate, '%Y-%m-%d') BETWEEN ? AND ?)
group by T_OrderDetailT_OrderHeaderID
";
$query = $this->db_onedev->query($sql, [$startDate, $endDate]);
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$result = $query->result_array();
foreach ($result as $key => $item) {
$this->translateLabStr($item['ID']);
}
$this->sys_ok("Berhasil inject translate ke t_orderdetaillang_ai");
}
public function calldevone($distictInputsStr)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://devone.aplikasi.web.id/one-api/ai-lab-translate/ai_lab/sendToAi',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($distictInputsStr), // JSON-encode the string with "data" key
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json', // Set content type to JSON
),
));
$response = curl_exec($curl);
curl_close($curl);
$result = json_decode($response, true);
return $result;
}
/*
*TRIAL*
*/
public function processOrderHeaders($startDate, $endDate, $usingAi = false)
{
try {
if (!isset($startDate) || !isset($endDate)) {
throw new Exception('Start date and end date are required');
}
$orderHeaders = $this->getOrderHeaders($startDate, $endDate);
$successOrderHeaders = [];
$failedOrderHeaders = [];
foreach ($orderHeaders as $header) {
try {
$this->db_onedev->trans_start();
// $this->db_onedev->trans_start(true);
$result = $this->translateLabResults($header['ID'], $usingAi);
if ($result['status'] === 'success') {
$this->db_onedev->trans_complete();
$successOrderHeaders[] = [
'orderHeaderId' => $header['ID'],
'date' => $header['T_OrderHeaderDate'],
'translationResults' => $result['data']
];
} else {
throw new Exception($result['message']);
}
} catch (Exception $e) {
$this->db_onedev->trans_rollback();
$failedOrderHeaders[] = [
'orderHeaderId' => $header['ID'],
'date' => $header['T_OrderHeaderDate'],
'error' => $e->getMessage()
];
}
}
$resp = [
'successOrderHeaders' => $successOrderHeaders,
'failedOrderHeaders' => $failedOrderHeaders,
'totalProcessed' => count($orderHeaders),
'totalSuccess' => count($successOrderHeaders),
'totalFailed' => count($failedOrderHeaders)
];
$this->sys_ok($resp);
} catch (Exception $e) {
$this->sys_error($e->getMessage());
}
}
private function getOrderHeaders($startDate, $endDate)
{
$sql = "SELECT
T_OrderDetailT_OrderHeaderID as ID,
T_OrderHeaderDate
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
WHERE T_OrderDetailIsActive = 'Y'
AND T_OrderDetailValidation = 'Y'
AND T_OrderHeaderIsActive = 'Y'
AND T_OrderDetailResult IS NOT NULL
AND (DATE_FORMAT(T_OrderHeaderDate, '%Y-%m-%d') BETWEEN ? AND ?)
group by T_OrderDetailT_OrderHeaderID";
$query = $this->db_onedev->query($sql, [$startDate, $endDate]);
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
throw new Exception(json_encode($message));
return;
}
return $query->result_array();
}
// translation process
private function translateLabResults($orderHeaderId, $usingAI)
{
try {
$results = $this->getLabResults($orderHeaderId);
if (empty($results)) {
throw new Exception('No lab results found');
}
list($translated, $notTranslated) = $this->processTranslations($results, $usingAI);
// ? Kalau tidak ditranslate apa tetap insert?
$this->saveTranslations($orderHeaderId, array_merge($translated, $notTranslated));
return [
'status' => 'success',
'data' => [
'translated' => $translated,
'notTranslated' => $notTranslated
]
];
} catch (Exception $e) {
return [
'status' => 'error',
'message' => $e->getMessage()
];
}
}
// get order detail from orderHeader
private function getLabResults($orderHeaderId)
{
return $this->db_onedev
->select('T_OrderDetailID as orderDetailID, T_OrderDetailT_TestID as T_TestID,
T_OrderDetailResult as result, T_OrderDetailT_OrderHeaderID as T_OrderHeaderID')
->from('t_orderdetail')
->where('T_OrderDetailT_OrderHeaderID', $orderHeaderId)
->where('T_OrderDetailIsActive', 'Y')
->where('T_OrderDetailValidation', 'Y')
->where('T_OrderDetailResult IS NOT NULL')
->get()
->result_array();
}
private function processTranslations($results, $usingAI)
{
$translated = [];
$notTranslated = [];
$distinctInputs = [];
foreach ($results as $result) {
// Skip yang hanya berisi angka
if (!preg_match('/[a-zA-Z]/', $result['result'])) {
$notTranslated[] = $this->createTranslationEntry($result, $result['result'], 1);
continue;
}
$distinctInputs[$result['result']] = true;
$translated[] = $this->createTranslationEntry($result, '', 0);
}
$distinctInputs = array_keys($distinctInputs);
// Get existing translations
$existingTranslations = $this->getExistingTranslations($distinctInputs);
if (!empty($existingTranslations)) {
$translated = $this->applyExistingTranslations($translated, $existingTranslations);
$distinctInputs = array_diff($distinctInputs, array_keys($existingTranslations));
}
if ($usingAI) {
// Get new translations from API
if (!empty($distinctInputs)) {
$translated = $this->applyNewTranslations($translated, $distinctInputs);
}
}
return [$translated, $notTranslated];
}
private function createTranslationEntry($result, $translatedText, $confidence)
{
return [
'orderDetailID' => $result['orderDetailID'],
'original' => $result['result'],
'translated' => $translatedText,
'confidence' => $confidence
];
}
private function getExistingTranslations($inputs)
{
$sql = "SELECT Translate_WordTo FROM translate_word
WHERE Translate_WordNat_LangID = 2
AND Translate_WordIsActive = 'Y'
AND Translate_WordFrom = ?";
$translations = [];
foreach ($inputs as $input) {
$query = $this->db_onedev->query($sql, $input);
$result = $query->row_array();
if ($result) {
$translations[$input] = $result['Translate_WordTo'];
}
}
return $translations;
}
private function applyExistingTranslations($translated, $translations)
{
foreach ($translated as &$entry) {
if (isset($translations[$entry['original']])) {
$entry['translated'] = $translations[$entry['original']];
$entry['confidence'] = 1;
}
}
return $translated;
}
private function applyNewTranslations($translated, $distinctInputs)
{
if (empty($distinctInputs)) {
return $translated;
}
$inputString = implode(' + ', $distinctInputs);
$apiResult = $this->callTranslationAPI($inputString);
if ($apiResult['status'] === 'success') {
$translations = array_combine($distinctInputs, $apiResult['translations']);
foreach ($translated as &$entry) {
if (isset($translations[$entry['original']]) && empty($entry['translated'])) {
$entry['translated'] = $translations[$entry['original']];
$entry['confidence'] = $apiResult['confidence'];
}
}
}
return $translated;
}
private function callTranslationAPI($inputString)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $this->translationAPIUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($inputString),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($curl);
$error = curl_error($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($error || $httpCode !== 200) {
return [
'status' => 'error',
'message' => "API request failed: $error"
];
}
$result = json_decode($response, true);
if (!isset($result['data']['output'])) {
return [
'status' => 'error',
'message' => 'Invalid API response'
];
}
return [
'status' => 'success',
'translations' => explode(' + ', trim($result['data']['output'], '"')),
'confidence' => $result['data']['confidence'] ?? 0.5
];
}
private function saveTranslations($orderHeaderId, $translations)
{
foreach ($translations as $translation) {
$data = [
'T_OrderDetailLangAiT_OrderHeaderID' => $orderHeaderId,
'T_OrderDetailLangAiT_OrderDetailID' => $translation['orderDetailID'],
'T_OrderDetailLangAiNat_LangID' => 2,
'T_OrderDetailLangAiResult' => $translation['translated'],
'T_OrderDetailLangAiConfidence' => $translation['confidence']
];
$this->db_onedev->replace('t_orderdetaillang_ai', $data);
if ($this->db_onedev->error()['code'] !== 0) {
throw new Exception('Failed to save translation: ' . $this->db_onedev->error()['message']);
}
}
}
}

View File

@@ -0,0 +1,239 @@
<?php
class Antrianonlinemonitoring extends MY_Controller
{
var $db;
var $load;
public function index()
{
echo "Antrian Online Monitoring";
}
public function __construct()
{
parent::__construct();
// $this->db = $this->load->database("antrian_online", true);
}
public function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$page = $prm['page'];
$rowPerPage = 10;
$keyword = '%%';
$startDate = $prm['start_date'];
$subService = $prm['subService'];
$status = $prm['status'];
if (!isset($prm['subService'])) {
$subService = 0;
}
$endDate = $prm['end_date'];
if (isset($prm['keyword'])) {
$keyword = '%' . $prm['keyword'] . '%';
}
$start_offset = 0;
if (isset($prm['page'])) {
if (is_numeric((int)$prm['page']) && $prm['page'] > 0) {
$start_offset = ($page - 1) * intval($rowPerPage);
}
}
$filter_subservice = "";
if ($subService != 0) {
$filter_subservice = "AND queueSubServiceID = {$subService}";
}
$filter_status = "";
if ($status == 'X') {
$filter_status = "WHERE IFNULL(Queue_FollowUpID, 'X') = 'X'";
} else if ($status == "Y") {
$filter_status = "WHERE IFNULL(Queue_FollowUpID, 'X') != 'X'";
}
$page = $prm['page'];
$sql_total = "SELECT
COUNT(queueID) AS total
FROM antrian_online.queue
JOIN antrian_online.m_patient
ON queueM_PatientID = M_PatientID
AND queueIsActive = 'Y'
AND M_PatientIsActive = 'Y'
AND queueDate BETWEEN ? AND ?
$filter_subservice
AND (M_PatientName LIKE ? OR M_PatientNoreg LIKE ?)
JOIN subservice
ON queueSubServiceID = subServiceID
AND subServiceIsActive = 'Y'
LEFT JOIN antrian_online.queue_followup
ON queueID = Queue_FollowUpQueueID
AND Queue_FollowUpIsActive = 'Y'
$filter_status
ORDER BY queueDate DESC
";
$qry_total = $this->db->query($sql_total, [
$startDate,
$endDate,
$keyword,
$keyword
]);
$totals = $qry_total->result_array()[0]['total'];
if (!$qry_total) {
$error = array(
"message" => $this->db->error()["message"],
);
$this->sys_error_db($error);
exit;
}
$sql = "SELECT
queueID,
queueM_PatientID,
queueSubServiceID,
subServiceName,
DATE_FORMAT(queueDate, '%d-%m-%Y') AS queueDate,
TIME_FORMAT(queueTimeStart, '%H:%i') AS queueTimeStart,
CONCAT(M_TitleName , ' ',M_PatientName) AS M_PatientName,
M_PatientNoreg,
Queue_FollowUpID,
Queue_FollowUpMessage,
Queue_FollowUpUserID,
M_PatientHp,
M_PatientEmail,
DATE_FORMAT(Queue_FollowUpDate, '%d-%m-%Y %H:%i') AS Queue_FollowUpDate,
M_UserUsername,
IFNULL(Queue_FollowUpID, 'X') AS status
FROM antrian_online.queue
JOIN antrian_online.m_patient
ON queueM_PatientID = M_PatientID
AND queueIsActive = 'Y'
AND M_PatientIsActive = 'Y'
AND queueDate BETWEEN ? AND ?
$filter_subservice
AND (M_PatientName LIKE ? OR M_PatientNoreg LIKE ?)
JOIN subservice
ON queueSubServiceID = subServiceID
AND subServiceIsActive = 'Y'
LEFT JOIN antrian_online.queue_followup
ON queueID = Queue_FollowUpQueueID
AND Queue_FollowUpIsActive = 'Y'
JOIN m_title
ON M_PatientM_TitleID = M_TitleID
AND M_TitleIsActive = 'Y'
LEFT JOIN m_user
ON Queue_FollowUpUserID = M_UserID
AND M_UserIsActive = 'Y'
$filter_status
ORDER BY queueDate DESC
LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, [
$startDate,
$endDate,
$keyword,
$keyword,
intval($rowPerPage),
intval($start_offset),
]);
$last_qry = $this->db->last_query();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$result = [
"data" => $qry->result_array(),
"total" => $totals,
"total_page" => ceil($totals / $rowPerPage),
"last_qry" => $last_qry
];
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function getsubservice()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT
subServiceID AS id,
subServiceName AS name
FROM subservice
WHERE subServiceIsActive = 'Y'";
$qry = $this->db->query($sql, []);
$last_qry = $this->db->last_query();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$data = $qry->result_array();
array_unshift($data, ["id" => "0", "name" => "All"]);
$this->sys_ok($data);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function followup()
{
try {
$prm = $this->sys_input;
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$queueID = $prm['queue_id'];
$msg = $prm['msg'];
$userID = $this->sys_user['M_UserID'];
if (!(isset($prm['queue_id']) && (strlen(trim($queueID)) > 0))) {
$this->sys_error("queue id mandatory");
exit;
}
if (!(isset($prm['msg']) && (strlen(trim($msg)) > 0))) {
$this->sys_error("note mandatory");
exit;
}
$sql = "INSERT INTO antrian_online.queue_followup(
Queue_FollowUpQueueID,
Queue_FollowUpMessage,
Queue_FollowUpUserID,
Queue_FollowUpDate
)VALUES(?,?,?,NOW())";
$qry = $this->db->query($sql, [$queueID, $msg, $userID]);
$last_qry = $this->db->last_query();
if (!$qry) {
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$this->sys_ok("Berhasil");
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,196 @@
<?php
class Counter 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 counter
where
counterIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_antrione->query($sql,$sql_param)->row()->total;
$sql = "select *
from counter
where
counterIsActive = '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("counter 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;
$code = $prm['code'];
$ip = $prm['ip'];
$query = "SELECT COUNT(*) as exist FROM counter WHERE counterIsActive = 'Y' AND counterCode = '{$code}'";
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "insert into counter(
counterCode,
counterIP
)
values( ?,?)";
$query = $this->db_antrione->query($sql,
array(
$code,
$ip
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("counter insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 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'];
$code = $prm['code'];
$ip = $prm['ip'];
$query = "SELECT COUNT(*) as exist FROM counter WHERE counterIsActive = 'Y' AND counterCode = '{$code}' AND counterID <> {$id}";
//echo $query;
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "update counter set
counterCode = ?,
counterIP = ?
where counterID = ?
";
$query = $this->db_antrione->query($sql,
array(
$code,
$ip,
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("counter update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 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 counter set
counterIsActive = 'N'
where counterID = ?
";
$query = $this->db_antrione->query($sql,
array(
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("counter delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,210 @@
<?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);
}
}
}

View File

@@ -0,0 +1,201 @@
<?php
class Service 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 service
where
serviceIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_antrione->query($sql,$sql_param)->row()->total;
$sql = "select *
from service
where
serviceIsActive = '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("m_schedule select");
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows,
"ownIP" => $_SERVER["REMOTE_ADDR"] );
$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;
$code = $prm['code'];
$name = $prm['name'];
$priority = $prm['priority'];
$query = "SELECT COUNT(*) as exist FROM service WHERE serviceIsActive = 'Y' AND serviceCode = '{$code}'";
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "insert into service(
serviceCode,
serviceName,
servicePriority
)
values( ?,?,?)";
$query = $this->db_antrione->query($sql,
array(
$code,
$name,
$priority
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 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'];
$code = $prm['code'];
$name = $prm['name'];
$priority = $prm['priority'];
$query = "SELECT COUNT(*) as exist FROM service WHERE serviceIsActive = 'Y' AND serviceCode = '{$code}' AND serviceID <> {$id}";
//echo $query;
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "update service set
serviceCode = ?,
serviceName = ?,
servicePriority = ?
where serviceID = ?
";
$query = $this->db_antrione->query($sql,
array(
$code,
$name,
$priority,
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 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 service set
serviceIsActive = 'N'
where serviceID = ?
";
$query = $this->db_antrione->query($sql,
array(
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,963 @@
<?php
class Groupresult extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Group Result API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->load->helper(array('form', 'url'));
}
function getphotos($orderid,$sampletypeid){
$rows = [];
//print_r($_SERVER);
$urlbase = 'http://'.$_SERVER['SERVER_NAME']."/one-media/one-image-nonlab/";
$sql = "SELECT So_ImageUploadID as id,
So_ImageUploadOldName as oldname,
CONCAT('{$urlbase}',So_ImageUploadNewName) as newname
FROM so_imageupload
WHERE
So_ImageUploadT_OrderHeaderID = {$orderid} AND So_ImageUploadT_SampleTypeID = {$sampletypeid} AND So_ImageUploadIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
function getdoctors($sampletypeid){
$rows = [];
$sql = "SELECT M_DoctorID as id,
CONCAT(M_DoctorPrefix,' ',M_DoctorName,' ',M_DoctorSufix) as name
FROM m_doctorso
JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID
JOIN t_test ON T_TestT_SampleTypeID = {$sampletypeid} AND M_DoctorSONat_SubGroupID = T_TestNat_SubgroupID
WHERE
M_DoctorSOIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
function getsetdoctoraddress($doctorid){
$rows = [];
$sql = "SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
FROM m_doctoraddress
WHERE
M_DoctorAddressM_DoctorID = {$doctorid} AND M_DoctorAddressIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
public function search_old()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = isset($prm["name"])?$prm["name"]:'';
$nolab = $prm["nolab"];
$stationid = $prm["stationid"];
$statusid = $prm["statusid"];
$where_status = '';
$limit = '';
//echo $statusid;
if($statusid == 'C'){
$limit = 'LIMIT 50';
}
//echo $limit = 'LIMIT 5';
$sql_where = "WHERE T_OrderHeaderIsActive = 'Y' {$where_status}";
$filter_search = '';
if ($nolab != "") {
$filter_search = " AND (T_OrderHeaderLabNumber LIKE CONCAT('%','{$nolab}','%') OR T_OrderHeaderLabNumberExt LIKE CONCAT('%','{$nolab}','%') OR M_PatientName LIKE CONCAT('%','{$nolab}','%'))";
}
$sql = "SELECT T_OrderHeaderID,T_SamplingSoID as T_BarcodeLabID,T_SampleTypeName as T_BarcodeLabBarcode,T_SampleTypeName,T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
IFNULL(M_PatientPhoto,'') as M_PatientPhotoThumb,T_TestID,
M_SexName, M_TitleName,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
M_CompanyName,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
T_OrderHeaderM_PatientAge as umur,
T_SampleStationID, T_SampleTypeID,
T_OrderDetailT_TestName as testname,
{$stationid} as stationid,
T_SamplingSoID,
T_SamplingSoFlagSend as status,
fn_result_so_status_by_sample(T_SamplingSoID) as status_result,
T_OrderHeaderIsCito as iscito,
IF(ISNULL(T_SamplingSoRequirementID),'X',T_SamplingSoRequirementStatus) as requirement_status,
'' as requirements,
'' as barcodes,
IF(ISNULL(readdoctor.M_DoctorName),'-',CONCAT(readdoctor.M_DoctorPrefix,readdoctor.M_DoctorPrefix2,' ',readdoctor.M_DoctorName,' ',readdoctor.M_DoctorSufix,readdoctor.M_DoctorSufix2,readdoctor.M_DoctorSufix3)) as doctor_fullname,
CONCAT(sender.M_DoctorPrefix,sender.M_DoctorPrefix2,' ',sender.M_DoctorName,' ',sender.M_DoctorSufix,sender.M_DoctorSufix2,sender.M_DoctorSufix3) as doctor_sender,
T_SamplingSoFlagDoctorInOffice as flagdoctorinoffice,
T_SamplingSoM_DoctorID,
T_OrderDetailID
FROM t_orderheader
JOIN m_doctor sender ON T_OrderHeaderSenderM_DoctorID = sender.M_DoctorID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid} AND T_SampleStationIsNonLab = 'RADIODIAGNOSTIC'
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID AND
T_SamplingSoFlag = 'V' AND
(('{$statusid}' = 'R' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID = 0 ) OR ('{$statusid}' = 'C' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID <> 0 )) AND
T_SamplingSoIsActive = 'Y'
LEFT JOIN m_doctor readdoctor ON T_SamplingSoM_DoctorID = readdoctor.M_DoctorID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoRequirementT_SamplingSoID = T_SamplingSoID AND
T_SamplingSoRequirementNat_PositionID = 9 AND
T_SamplingSoRequirementIsActive = 'Y'
$sql_where $filter_search
GROUP BY T_SamplingSoID
ORDER BY iscito ASC,T_SamplingSoReceiveAdmDate ASC, T_SamplingSoReceiveAdmTime ASC,T_OrderHeaderID ASC
$limit
";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$zxprm = array();
$zxprm['status'] = $v['status'];
$zxprm['orderid'] = $v['T_OrderHeaderID'];
$zxprm['sampletypeid'] = $v['T_SampleTypeID'];
$zxprm['samplingso_id'] = $v['T_SamplingSoID'];
$rows[$k]['requirements'] = $this->getrequirements($zxprm);
$rows[$k]['barcodes'] = $this->getbarcodes($v['T_OrderHeaderID']);
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = isset($prm["name"])?$prm["name"]:'';
$nolab = $prm["nolab"];
$sdate = $prm["sdate"];
$edate = $prm["edate"];
$companyid = $prm["companyid"];
$gresultid = $prm["gresultid"];
$where_status = '';
$limit = '';
//echo $statusid;
if($statusid == 'C'){
$limit = 'LIMIT 50';
}
//echo $limit = 'LIMIT 5';
$sql_where = "WHERE T_OrderHeaderIsActive = 'Y' {$where_status}";
$filter_search = '';
if ($nolab != "") {
$filter_search = " AND (T_OrderHeaderLabNumber LIKE CONCAT('%','{$nolab}','%') OR T_OrderHeaderLabNumberExt LIKE CONCAT('%','{$nolab}','%') OR M_PatientName LIKE CONCAT('%','{$nolab}','%'))";
}
$filter_company = '';
if ($companyid != 0) {
$filter_company = " AND T_OrderHeaderM_CompanyID = $companyid";
}
$sql = "SELECT T_OrderHeaderID,T_SamplingSoID as T_BarcodeLabID,T_SampleTypeName as T_BarcodeLabBarcode,T_SampleTypeName,T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as M_PatientPhotoThumb,T_TestID,
'' as M_SexName, '' as M_TitleName,
JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.patient_fullname')) as patient_fullname,
M_CompanyName,
M_CompanyName as companyname,
JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.M_PatientDOB')) as patient_dob,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
T_OrderHeaderM_PatientAge as umur,
T_SampleStationID, T_SampleTypeID,
T_TestName as testname,
T_SamplingSoT_SampleStationID as stationid,
T_SamplingSoID,
T_SamplingSoFlagSend as status,
fn_result_so_status_by_sample(T_SamplingSoID) as status_result,
T_OrderHeaderIsCito as iscito,
IF(ISNULL(T_SamplingSoRequirementID),'X',T_SamplingSoRequirementStatus) as requirement_status,
'' as requirements,
'' as barcodes,
IF(ISNULL(readdoctor.M_DoctorName),'-',CONCAT(readdoctor.M_DoctorPrefix,readdoctor.M_DoctorPrefix2,' ',readdoctor.M_DoctorName,' ',readdoctor.M_DoctorSufix,readdoctor.M_DoctorSufix2,readdoctor.M_DoctorSufix3)) as doctor_fullname,
CONCAT(sender.M_DoctorPrefix,sender.M_DoctorPrefix2,' ',sender.M_DoctorName,' ',sender.M_DoctorSufix,sender.M_DoctorSufix2,sender.M_DoctorSufix3) as doctor_sender,
T_SamplingSoFlagDoctorInOffice as flagdoctorinoffice,
T_SamplingSoM_DoctorID,
T_OrderDetailID,
IFNULL(Print_BarcodeSoLogID,0) as status_print
FROM t_orderheader
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoFlag = 'V' AND
(( T_SamplingSoFlagSend = 'R' AND T_SamplingSoIsActive = 'Y' AND T_SamplingSoM_DoctorID = 0) OR
(T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID <> 0 ))
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_TestID = T_OrderDetailT_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_doctor sender ON T_OrderHeaderSenderM_DoctorID = sender.M_DoctorID
JOIN t_samplestation ON T_SampleStationID = T_SamplingSoT_SampleStationID
LEFT JOIN m_doctor readdoctor ON T_SamplingSoM_DoctorID = readdoctor.M_DoctorID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoRequirementT_SamplingSoID = T_SamplingSoID AND
T_SamplingSoRequirementNat_PositionID = 9 AND
T_SamplingSoRequirementIsActive = 'Y'
LEFT JOIN print_barcode_so_log ON Print_BarcodeSoLogT_OrderHeaderID = T_OrderHeaderID AND
Print_BarcodeSoLogT_TestID = T_TestID
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive = 'Y' AND Group_ResultFlagNonLab = 'Y'
WHERE
T_OrderHeaderDate BETWEEN CONCAT('{$sdate}', ' 00:00:00') AND CONCAT('{$edate}', ' 23:59:59') AND
Group_ResultID = $gresultid AND
T_OrderHeaderIsActive = 'Y'
$filter_search $filter_company
GROUP BY T_OrderDetailID
ORDER BY iscito ASC,T_SamplingSoReceiveAdmDate ASC, T_SamplingSoReceiveAdmTime ASC,T_OrderHeaderID ASC
$limit
";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$zxprm = array();
$zxprm['status'] = $v['status'];
$zxprm['orderid'] = $v['T_OrderHeaderID'];
$zxprm['sampletypeid'] = $v['T_SampleTypeID'];
$zxprm['samplingso_id'] = $v['T_SamplingSoID'];
$rows[$k]['requirements'] = $this->getrequirements($zxprm);
$rows[$k]['barcodes'] = $this->getbarcodes($v['T_OrderHeaderID']);
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function searchbackup()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = isset($prm["name"])?$prm["name"]:'';
$nolab = $prm["nolab"];
$stationid = $prm["stationid"];
$statusid = $prm["statusid"];
$where_status = '';
$limit = '';
//echo $statusid;
if($statusid == 'C'){
$limit = 'LIMIT 50';
}
//echo $limit = 'LIMIT 5';
$sql_where = "WHERE T_OrderHeaderIsActive = 'Y' {$where_status}";
$filter_search = '';
if ($nolab != "") {
$filter_search = " AND (T_OrderHeaderLabNumber LIKE CONCAT('%','{$nolab}','%') OR T_OrderHeaderLabNumberExt LIKE CONCAT('%','{$nolab}','%') OR M_PatientName LIKE CONCAT('%','{$nolab}','%'))";
}
$sql = "SELECT T_OrderHeaderID,T_SamplingSoID as T_BarcodeLabID,T_SampleTypeName as T_BarcodeLabBarcode,T_SampleTypeName,T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
IFNULL(M_PatientPhoto,'') as M_PatientPhotoThumb,T_TestID,
'' as M_SexName, M_TitleName,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
M_CompanyName,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
T_OrderHeaderM_PatientAge as umur,
T_SampleStationID, T_SampleTypeID,
T_TestName as testname,
T_SamplingSoT_SampleStationID as stationid,
T_SamplingSoID,
T_SamplingSoFlagSend as status,
fn_result_so_status_by_sample(T_SamplingSoID) as status_result,
T_OrderHeaderIsCito as iscito,
IF(ISNULL(T_SamplingSoRequirementID),'X',T_SamplingSoRequirementStatus) as requirement_status,
'' as requirements,
'' as barcodes,
IF(ISNULL(readdoctor.M_DoctorName),'-',CONCAT(readdoctor.M_DoctorPrefix,readdoctor.M_DoctorPrefix2,' ',readdoctor.M_DoctorName,' ',readdoctor.M_DoctorSufix,readdoctor.M_DoctorSufix2,readdoctor.M_DoctorSufix3)) as doctor_fullname,
CONCAT(sender.M_DoctorPrefix,sender.M_DoctorPrefix2,' ',sender.M_DoctorName,' ',sender.M_DoctorSufix,sender.M_DoctorSufix2,sender.M_DoctorSufix3) as doctor_sender,
T_SamplingSoFlagDoctorInOffice as flagdoctorinoffice,
T_SamplingSoM_DoctorID,
T_OrderDetailID,
IFNULL(Print_BarcodeSoLogID,0) as status_print
FROM t_samplingso
JOIN t_test ON T_SamplingSoT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_orderheader ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN t_orderdetail ON T_SamplingSoT_TestID = T_OrderDetailT_TestID AND T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN m_doctor sender ON T_OrderHeaderSenderM_DoctorID = sender.M_DoctorID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_samplestation ON T_SampleStationID = T_SamplingSoT_SampleStationID
LEFT JOIN m_doctor readdoctor ON T_SamplingSoM_DoctorID = readdoctor.M_DoctorID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoRequirementT_SamplingSoID = T_SamplingSoID AND
T_SamplingSoRequirementNat_PositionID = 9 AND
T_SamplingSoRequirementIsActive = 'Y'
LEFT JOIN print_barcode_so_log ON Print_BarcodeSoLogT_OrderHeaderID = T_OrderHeaderID AND
Print_BarcodeSoLogT_TestID = T_TestID
WHERE
T_OrderHeaderIsActive = 'Y' AND T_SamplingSoT_SampleStationID = {$stationid} AND T_SamplingSoFlag = 'V' AND
(( T_SamplingSoFlagSend = 'R' AND T_SamplingSoIsActive = 'Y' AND T_SamplingSoM_DoctorID = 0 AND '{$statusid}' = 'R' ) OR
('{$statusid}' = 'C' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID <> 0 ))
$filter_search
GROUP BY T_OrderDetailID
ORDER BY iscito ASC,T_SamplingSoReceiveAdmDate ASC, T_SamplingSoReceiveAdmTime ASC,T_OrderHeaderID ASC
$limit
";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$zxprm = array();
$zxprm['status'] = $v['status'];
$zxprm['orderid'] = $v['T_OrderHeaderID'];
$zxprm['sampletypeid'] = $v['T_SampleTypeID'];
$zxprm['samplingso_id'] = $v['T_SamplingSoID'];
$rows[$k]['requirements'] = $this->getrequirements($zxprm);
$rows[$k]['barcodes'] = $this->getbarcodes($v['T_OrderHeaderID']);
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function getbarcodes($orderid){
$sql = " SELECT T_TestName,
T_OrderHeaderLabNumber,
M_PatientNoReg,
M_PatientName,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
T_OrderHeaderM_PatientAge as umur,
fn_get_patient_first_address(M_PatientID) as alamat,
IF(ISNULL(M_DoctorName),'-',CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_fullname,
M_CompanyName
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND
( DocumentationGroupName <> 'lab' AND DocumentationGroupName <> 'other' )
WHERE
T_OrderHeaderID = {$orderid} AND T_OrderDetailIsActive = 'Y'
GROUP BY T_TestID";
//echo $sql;
$rst = $this->db_onedev->query($sql)->result_array();
return $rst;
}
function getrequirements($prm){
$query =" SELECT Nat_RequirementID as id,
Nat_RequirementName as name, '{$prm['status']}' as status,
if(ISNULL(T_SamplingSoRequirementID),'N', if(json_contains(T_SamplingSoRequirementRequirements,Nat_RequirementID),'Y','N') ) as chex,
Nat_RequirementPositionNat_PositionID as positionid
FROM nat_requirement
JOIN nat_testrequirement ON Nat_TestRequirementNat_RequirementID = Nat_RequirementID
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID AND Nat_RequirementPositionNat_PositionID = 9 AND
Nat_RequirementPositionIsActive = 'Y'
JOIN t_test ON T_TestNat_TestID = Nat_TestRequirementNat_TestID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = {$prm['orderid']} AND
T_SamplingSoRequirementT_SamplingSoID = {$prm['samplingso_id']} AND T_SamplingSoRequirementNat_PositionID = Nat_RequirementPositionNat_PositionID
WHERE
Nat_TestRequirementIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
return $rows;
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query =" SELECT T_SampleStationID as id, T_SampleStationName as name
FROM t_samplestation
WHERE
T_SampleStationIsActive = 'Y' AND T_SampleStationIsNonLab = 'RADIODIAGNOSTIC'
";
//echo $query;
$rows['stations'] = $this->db_onedev->query($query)->result_array();
$rows['statuses'] = array(array('id'=>'R','name'=>'Sudah Terima'),array('id'=>'C','name'=>'Selesai'));
$query =" SELECT Group_ResultID as id, Group_ResultName as name
FROM group_result
WHERE
Group_ResultIsActive = 'Y' AND Group_ResultFlagNonLab = 'Y'
";
//echo $query;
$rows['gresults'] = $this->db_onedev->query($query)->result_array();
$rows['doctors'] = array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function saveprintlog(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$rows = [];
$sql ="INSERT INTO print_barcode_so_log (
Print_BarcodeSoLogT_TestID,
Print_BarcodeSoLogT_OrderHeaderID,
Print_BarcodeSoLogUserID
)
VALUES(
{$prm['T_TestID']},
{$prm['T_OrderHeaderID']},
{$userid}
)";
//echo $query;
$this->db_onedev->query($sql);
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdoctorbystation(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows= [];
$sql = "
SELECT M_DoctorID as id, M_DoctorName, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name, '' as address
FROM m_doctor
JOIN m_doctorso ON M_DoctorSOM_DoctorID = M_DoctorID AND M_DoctorSOIsActive = 'Y'
JOIN t_test ON T_TestNat_SubgroupID = M_DoctorSONat_SubGroupID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
WHERE
M_DoctorIsActive = 'Y'
GROUP BY M_DoctorID
ORDER BY M_DoctorName DESC
";
// echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v){
$rows[$k]['address'] = $this->db_onedev->query("SELECT * FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['id']} AND M_DoctorAddressIsActive = 'Y'")->result_array();
}
$rows['doctors'] = $rows;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function search_patient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$stationid = $prm["stationid"];
$statusid = $prm["statusid"];
$sql_where = "WHERE T_OrderHeaderLabNumber = '{$search}' AND T_OrderHeaderIsActive = 'Y'";
$rows = [];
$query = "SELECT T_OrderHeaderID,T_BarcodeLabID,T_BarcodeLabBarcode,T_SampleTypeName,T_OrderHeaderLabNumber,
IFNULL(M_PatientPhoto,'') as M_PatientPhotoThumb,
M_SexName, M_TitleName,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
M_CompanyName,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
T_SampleStationID, T_SampleTypeID,
{$stationid} as stationid,
T_SamplingSoID,
T_SamplingSoFlagSend as status,
fn_global_check_is_cito(T_OrderHeaderID) as iscito,
IF(ISNULL(T_SamplingSoRequirementID),'X',T_SamplingSoRequirementStatus) as requirement_status,
'' as requirements,
IF(ISNULL(M_DoctorName),'-',CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,'...')) as doctor_fullname,
T_SamplingSoFlagDoctorInOffice as flagdoctorinoffice,
T_SamplingSoM_DoctorID
FROM t_orderheader
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid} AND T_SampleStationIsNonLab = 'RADIODIAGNOSTIC'
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoT_SampleTypeID = T_SampleTypeID AND
T_SamplingSoT_BarcodeLabID = T_BarcodeLabID AND T_SamplingSoFlag = 'V' AND
(('{$statusid}' = 'R' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID = 0 ) OR ('{$statusid}' = 'C' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID <> 0 )) AND
T_SamplingSoIsActive = 'Y'
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoRequirementT_SampletypeID = T_SampletypeID AND
T_SamplingSoRequirementNat_PositionID = 9 AND
T_SamplingSoRequirementIsActive = 'Y'
$sql_where
GROUP BY T_BarcodeLabID
ORDER BY iscito DESC,T_OrderPromiseDateTime ASC, T_OrderHeaderID ASC, T_SamplingSoID ASC
limit 0,20";
$rows = $this->db_onedev->query($query)->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['chex'] = true;
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdoctoraddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
FROM m_doctoraddress
WHERE
M_DoctorAddressM_DoctorID = {$prm['id']} AND M_DoctorAddressIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$samples = $prm['sample'];
if($prm['act'] == 'receive'){
foreach($samples as $k=>$v){
$sql = "UPDATE t_samplingso SET
T_SamplingSoFlagSend = 'R',
T_SamplingSoReceiveAdmDate = CURDATE(),
T_SamplingSoReceiveAdmTime = CURTIME(),
T_SamplingSoReceiveAdmUserID = {$userid},
T_SamplingSoUserID = {$userid}
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
$this->db_onedev->query($sql);
}
}
if($prm['act'] == 'cancel'){
foreach($samples as $k=>$v){
$sql = "UPDATE t_samplingso SET
T_SamplingSoFlagSend = 'N',
T_SamplingSoReceiveAdmDate = NULL,
T_SamplingSoReceiveAdmTime = NULL,
T_SamplingSoReceiveAdmUserID = NULL,
T_SamplingSoFlag = 'Z',
T_SamplingSoSendAdmDate = NULL,
T_SamplingSoSendAdmTime = NULL,
T_SamplingSoSendAdmUserID = NULL,
T_SamplingSoVerifyDate = NULL,
T_SamplingSoVerifyTime = NULL,
T_SamplingSoVerifyUserID = NULL,
T_SamplingSoUserID = {$userid}
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
$this->db_onedev->query($sql);
}
}
if($prm['act'] == 'reject'){
foreach($samples as $k=>$v){
$sql = "UPDATE t_samplingso SET
T_SamplingSoFlagSend = 'D',
T_SamplingSoSendAdmDate = NULL,
T_SamplingSoSendAdmTime = NULL,
T_SamplingSoSendAdmUserID = NULL,
T_SamplingSoVerifyDate = NULL,
T_SamplingSoVerifyTime = NULL,
T_SamplingSoVerifyUserID = NULL,
T_SamplingSoUserID = {$userid}
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
$this->db_onedev->query($sql);
}
}
if($prm['act'] == 'removedoctor'){
foreach($samples as $k => $v){
$query =" UPDATE t_samplingso SET
T_SamplingSoFlagDoctorInOffice = 'N',
T_SamplingSoM_DoctorID = 0,
T_SamplingSoM_DoctorAddressID = 0
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
//echo $query;
$savedoctor = $this->db_onedev->query($query);
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM (
SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name, '' as address
FROM m_doctor
JOIN m_doctorso ON M_DoctorSOM_DoctorID = M_DoctorID AND M_DoctorSOIsActive = 'Y'
JOIN t_test ON T_TestNat_SubgroupID = M_DoctorSONat_SubGroupID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
WHERE
M_DoctorName like ?
AND M_DoctorIsActive = 'Y'
GROUP BY M_DoctorID
)xx";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_DoctorID as id, M_DoctorName, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name, '' as address
FROM m_doctor
JOIN m_doctorso ON M_DoctorSOM_DoctorID = M_DoctorID AND M_DoctorSOIsActive = 'Y'
JOIN t_test ON T_TestNat_SubgroupID = M_DoctorSONat_SubGroupID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
WHERE
CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) like ?
AND M_DoctorIsActive = 'Y'
GROUP BY M_DoctorID
ORDER BY M_DoctorName DESC
";
//echo $sql;
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v){
$rows[$k]['address'] = $this->db_onedev->query("SELECT * FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['id']} AND M_DoctorAddressIsActive = 'Y'")->result_array();
}
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
//echo $sql;
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v){
}
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function saveprintalllog(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sel_order = $prm['selected_order'];
$userid = $this->sys_user["M_UserID"];
$rows = [];
foreach($sel_order as $k => $v){
$sql ="INSERT INTO print_barcode_so_log (
Print_BarcodeSoLogT_TestID,
Print_BarcodeSoLogT_OrderHeaderID,
Print_BarcodeSoLogUserID
)
VALUES(
{$v['T_TestID']},
{$v['T_OrderHeaderID']},
{$userid}
)";
//echo $query;
$this->db_onedev->query($sql);
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savedoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sel_patient = $prm['selected_patient'];
$sel_doctor = $prm['selected_doctor'];
$sel_doctor_address = $prm['selected_doctor_address'];
$flagdoctorinoffice = $prm['flagdoctorinoffice'] == true ? 'Y':'N';
foreach($sel_patient as $k => $v){
$query =" UPDATE t_samplingso SET
T_SamplingSoFlagDoctorInOffice = '{$flagdoctorinoffice}',
T_SamplingSoM_DoctorID = {$sel_doctor['id']},
T_SamplingSoM_DoctorAddressID = {$sel_doctor_address['M_DoctorAddressID']}
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
//echo $query;
$savedoctor = $this->db_onedev->query($query);
$sql = "INSERT INTO sample_so_by_step (
SampleSoByStepT_OrderHeaderID,
SampleSoByStepT_TestID,
SampleSoByStepCode,
SampleSoByStepDateTime,
SampleSoByStepUserID
)
VALUES(
{$v['T_OrderHeaderID']},
{$v['T_TestID']},
'SAMPLING.Handling.Process',
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
$sql = "INSERT INTO sample_so_by_step (
SampleSoByStepT_OrderHeaderID,
SampleSoByStepT_TestID,
SampleSoByStepCode,
SampleSoByStepDateTime,
SampleSoByStepUserID
)
VALUES(
{$v['T_OrderHeaderID']},
{$v['T_TestID']},
'SAMPLING.Handling.To.Process',
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
}
if($savedoctor){
$result = array(
"total" => 1 ,
"records" => array(),
);
$this->sys_ok($result);
exit;
}
else{
$this->sys_error_db("doctor update", $this->db_onedev);
exit;
}
}
function deletephoto(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query =" UPDATE so_imageupload SET So_ImageUploadIsActive = 'N', So_ImageUploadUserID = {$userid} WHERE So_ImageUploadID = {$prm['id']}";
//echo $query;
$actdelete = $this->db_onedev->query($query);
if($actdelete){
$result = array(
"total" => 1 ,
"records" => array(),
);
$this->sys_ok($result);
exit;
}
else{
$this->sys_error_db("so_imageupload delete", $this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,956 @@
<?php
class Labnumber extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Group Result API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->load->helper(array('form', 'url'));
}
function getphotos($orderid,$sampletypeid){
$rows = [];
//print_r($_SERVER);
$urlbase = 'http://'.$_SERVER['SERVER_NAME']."/one-media/one-image-nonlab/";
$sql = "SELECT So_ImageUploadID as id,
So_ImageUploadOldName as oldname,
CONCAT('{$urlbase}',So_ImageUploadNewName) as newname
FROM so_imageupload
WHERE
So_ImageUploadT_OrderHeaderID = {$orderid} AND So_ImageUploadT_SampleTypeID = {$sampletypeid} AND So_ImageUploadIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
function getdoctors($sampletypeid){
$rows = [];
$sql = "SELECT M_DoctorID as id,
CONCAT(M_DoctorPrefix,' ',M_DoctorName,' ',M_DoctorSufix) as name
FROM m_doctorso
JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID
JOIN t_test ON T_TestT_SampleTypeID = {$sampletypeid} AND M_DoctorSONat_SubGroupID = T_TestNat_SubgroupID
WHERE
M_DoctorSOIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
function getsetdoctoraddress($doctorid){
$rows = [];
$sql = "SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
FROM m_doctoraddress
WHERE
M_DoctorAddressM_DoctorID = {$doctorid} AND M_DoctorAddressIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
public function search_old()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = isset($prm["name"])?$prm["name"]:'';
$nolab = $prm["nolab"];
$stationid = $prm["stationid"];
$statusid = $prm["statusid"];
$where_status = '';
$limit = '';
//echo $statusid;
if($statusid == 'C'){
$limit = 'LIMIT 50';
}
//echo $limit = 'LIMIT 5';
$sql_where = "WHERE T_OrderHeaderIsActive = 'Y' {$where_status}";
$filter_search = '';
if ($nolab != "") {
$filter_search = " AND (T_OrderHeaderLabNumber LIKE CONCAT('%','{$nolab}','%') OR T_OrderHeaderLabNumberExt LIKE CONCAT('%','{$nolab}','%') OR M_PatientName LIKE CONCAT('%','{$nolab}','%'))";
}
$sql = "SELECT T_OrderHeaderID,T_SamplingSoID as T_BarcodeLabID,T_SampleTypeName as T_BarcodeLabBarcode,T_SampleTypeName,T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
IFNULL(M_PatientPhoto,'') as M_PatientPhotoThumb,T_TestID,
M_SexName, M_TitleName,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
M_CompanyName,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
T_OrderHeaderM_PatientAge as umur,
T_SampleStationID, T_SampleTypeID,
T_OrderDetailT_TestName as testname,
{$stationid} as stationid,
T_SamplingSoID,
T_SamplingSoFlagSend as status,
fn_result_so_status_by_sample(T_SamplingSoID) as status_result,
T_OrderHeaderIsCito as iscito,
IF(ISNULL(T_SamplingSoRequirementID),'X',T_SamplingSoRequirementStatus) as requirement_status,
'' as requirements,
'' as barcodes,
IF(ISNULL(readdoctor.M_DoctorName),'-',CONCAT(readdoctor.M_DoctorPrefix,readdoctor.M_DoctorPrefix2,' ',readdoctor.M_DoctorName,' ',readdoctor.M_DoctorSufix,readdoctor.M_DoctorSufix2,readdoctor.M_DoctorSufix3)) as doctor_fullname,
CONCAT(sender.M_DoctorPrefix,sender.M_DoctorPrefix2,' ',sender.M_DoctorName,' ',sender.M_DoctorSufix,sender.M_DoctorSufix2,sender.M_DoctorSufix3) as doctor_sender,
T_SamplingSoFlagDoctorInOffice as flagdoctorinoffice,
T_SamplingSoM_DoctorID,
T_OrderDetailID
FROM t_orderheader
JOIN m_doctor sender ON T_OrderHeaderSenderM_DoctorID = sender.M_DoctorID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid} AND T_SampleStationIsNonLab = 'RADIODIAGNOSTIC'
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID AND
T_SamplingSoFlag = 'V' AND
(('{$statusid}' = 'R' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID = 0 ) OR ('{$statusid}' = 'C' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID <> 0 )) AND
T_SamplingSoIsActive = 'Y'
LEFT JOIN m_doctor readdoctor ON T_SamplingSoM_DoctorID = readdoctor.M_DoctorID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoRequirementT_SamplingSoID = T_SamplingSoID AND
T_SamplingSoRequirementNat_PositionID = 9 AND
T_SamplingSoRequirementIsActive = 'Y'
$sql_where $filter_search
GROUP BY T_SamplingSoID
ORDER BY iscito ASC,T_SamplingSoReceiveAdmDate ASC, T_SamplingSoReceiveAdmTime ASC,T_OrderHeaderID ASC
$limit
";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$zxprm = array();
$zxprm['status'] = $v['status'];
$zxprm['orderid'] = $v['T_OrderHeaderID'];
$zxprm['sampletypeid'] = $v['T_SampleTypeID'];
$zxprm['samplingso_id'] = $v['T_SamplingSoID'];
$rows[$k]['requirements'] = $this->getrequirements($zxprm);
$rows[$k]['barcodes'] = $this->getbarcodes($v['T_OrderHeaderID']);
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = isset($prm["name"])?$prm["name"]:'';
$nolab = $prm["nolab"];
$sdate = $prm["sdate"];
$edate = $prm["edate"];
$companyid = $prm["companyid"];
$gresultid = $prm["gresultid"];
$where_status = '';
$limit = '';
//echo $statusid;
if($statusid == 'C'){
$limit = 'LIMIT 50';
}
//echo $limit = 'LIMIT 5';
$sql_where = "WHERE T_OrderHeaderIsActive = 'Y' {$where_status}";
$filter_search = '';
if ($nolab != "") {
$filter_search = " AND (T_OrderHeaderLabNumber LIKE CONCAT('%','{$nolab}','%') OR T_OrderHeaderLabNumberExt LIKE CONCAT('%','{$nolab}','%') OR M_PatientName LIKE CONCAT('%','{$nolab}','%'))";
}
$filter_company = '';
if ($companyid != 0) {
$filter_company = " AND T_OrderHeaderM_CompanyID = $companyid";
}
$sql = "SELECT T_OrderHeaderID,T_SamplingSoID as T_BarcodeLabID,T_SampleTypeName as T_BarcodeLabBarcode,T_SampleTypeName,T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as M_PatientPhotoThumb,T_TestID,
'' as M_SexName, '' as M_TitleName,
JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.patient_fullname')) as patient_fullname,
M_CompanyName,
M_CompanyName as companyname,
JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.M_PatientDOB')) as patient_dob,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
T_OrderHeaderM_PatientAge as umur,
T_SampleStationID, T_SampleTypeID,
GROUP_CONCAT(DISTINCT T_TestName SEPARATOR '\n') as testname,
T_SamplingSoT_SampleStationID as stationid,
T_SamplingSoID,
T_SamplingSoFlagSend as status,
fn_result_so_status_by_sample(T_SamplingSoID) as status_result,
T_OrderHeaderIsCito as iscito,
IF(ISNULL(T_SamplingSoRequirementID),'X',T_SamplingSoRequirementStatus) as requirement_status,
'' as requirements,
'' as barcodes,
IF(ISNULL(readdoctor.M_DoctorName),'-',CONCAT(readdoctor.M_DoctorPrefix,readdoctor.M_DoctorPrefix2,' ',readdoctor.M_DoctorName,' ',readdoctor.M_DoctorSufix,readdoctor.M_DoctorSufix2,readdoctor.M_DoctorSufix3)) as doctor_fullname,
CONCAT(sender.M_DoctorPrefix,sender.M_DoctorPrefix2,' ',sender.M_DoctorName,' ',sender.M_DoctorSufix,sender.M_DoctorSufix2,sender.M_DoctorSufix3) as doctor_sender,
T_SamplingSoFlagDoctorInOffice as flagdoctorinoffice,
T_SamplingSoM_DoctorID,
T_OrderDetailID,
IFNULL(Print_BarcodeSoLogID,0) as status_print
FROM t_orderheader
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoFlag = 'V' AND
(( T_SamplingSoFlagSend = 'R' AND T_SamplingSoIsActive = 'Y' AND T_SamplingSoM_DoctorID = 0) OR
(T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID <> 0 ))
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_TestID = T_OrderDetailT_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_doctor sender ON T_OrderHeaderSenderM_DoctorID = sender.M_DoctorID
JOIN t_samplestation ON T_SampleStationID = T_SamplingSoT_SampleStationID
LEFT JOIN m_doctor readdoctor ON T_SamplingSoM_DoctorID = readdoctor.M_DoctorID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoRequirementT_SamplingSoID = T_SamplingSoID AND
T_SamplingSoRequirementNat_PositionID = 9 AND
T_SamplingSoRequirementIsActive = 'Y'
LEFT JOIN print_barcode_so_log ON Print_BarcodeSoLogT_OrderHeaderID = T_OrderHeaderID AND
Print_BarcodeSoLogT_TestID = T_TestID
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive = 'Y' AND Group_ResultFlagNonLab = 'Y'
WHERE
T_OrderHeaderDate BETWEEN CONCAT('{$sdate}', ' 00:00:00') AND CONCAT('{$edate}', ' 23:59:59') AND
T_OrderHeaderIsActive = 'Y'
$filter_search $filter_company
GROUP BY T_OrderHeaderID
ORDER BY iscito ASC,T_SamplingSoReceiveAdmDate ASC, T_SamplingSoReceiveAdmTime ASC,T_OrderHeaderID ASC
$limit
";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$zxprm = array();
$zxprm['status'] = $v['status'];
$zxprm['orderid'] = $v['T_OrderHeaderID'];
$zxprm['sampletypeid'] = $v['T_SampleTypeID'];
$zxprm['samplingso_id'] = $v['T_SamplingSoID'];
$rows[$k]['requirements'] = $this->getrequirements($zxprm);
$rows[$k]['barcodes'] = $this->getbarcodes($v['T_OrderHeaderID']);
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function searchbackup()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = isset($prm["name"])?$prm["name"]:'';
$nolab = $prm["nolab"];
$stationid = $prm["stationid"];
$statusid = $prm["statusid"];
$where_status = '';
$limit = '';
//echo $statusid;
if($statusid == 'C'){
$limit = 'LIMIT 50';
}
//echo $limit = 'LIMIT 5';
$sql_where = "WHERE T_OrderHeaderIsActive = 'Y' {$where_status}";
$filter_search = '';
if ($nolab != "") {
$filter_search = " AND (T_OrderHeaderLabNumber LIKE CONCAT('%','{$nolab}','%') OR T_OrderHeaderLabNumberExt LIKE CONCAT('%','{$nolab}','%') OR M_PatientName LIKE CONCAT('%','{$nolab}','%'))";
}
$sql = "SELECT T_OrderHeaderID,T_SamplingSoID as T_BarcodeLabID,T_SampleTypeName as T_BarcodeLabBarcode,T_SampleTypeName,T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
IFNULL(M_PatientPhoto,'') as M_PatientPhotoThumb,T_TestID,
'' as M_SexName, M_TitleName,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
M_CompanyName,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
T_OrderHeaderM_PatientAge as umur,
T_SampleStationID, T_SampleTypeID,
T_TestName as testname,
T_SamplingSoT_SampleStationID as stationid,
T_SamplingSoID,
T_SamplingSoFlagSend as status,
fn_result_so_status_by_sample(T_SamplingSoID) as status_result,
T_OrderHeaderIsCito as iscito,
IF(ISNULL(T_SamplingSoRequirementID),'X',T_SamplingSoRequirementStatus) as requirement_status,
'' as requirements,
'' as barcodes,
IF(ISNULL(readdoctor.M_DoctorName),'-',CONCAT(readdoctor.M_DoctorPrefix,readdoctor.M_DoctorPrefix2,' ',readdoctor.M_DoctorName,' ',readdoctor.M_DoctorSufix,readdoctor.M_DoctorSufix2,readdoctor.M_DoctorSufix3)) as doctor_fullname,
CONCAT(sender.M_DoctorPrefix,sender.M_DoctorPrefix2,' ',sender.M_DoctorName,' ',sender.M_DoctorSufix,sender.M_DoctorSufix2,sender.M_DoctorSufix3) as doctor_sender,
T_SamplingSoFlagDoctorInOffice as flagdoctorinoffice,
T_SamplingSoM_DoctorID,
T_OrderDetailID,
IFNULL(Print_BarcodeHeaderSoLogID,0) as status_print
FROM t_samplingso
JOIN t_test ON T_SamplingSoT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_orderheader ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN t_orderdetail ON T_SamplingSoT_TestID = T_OrderDetailT_TestID AND T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN m_doctor sender ON T_OrderHeaderSenderM_DoctorID = sender.M_DoctorID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_samplestation ON T_SampleStationID = T_SamplingSoT_SampleStationID
LEFT JOIN m_doctor readdoctor ON T_SamplingSoM_DoctorID = readdoctor.M_DoctorID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoRequirementT_SamplingSoID = T_SamplingSoID AND
T_SamplingSoRequirementNat_PositionID = 9 AND
T_SamplingSoRequirementIsActive = 'Y'
LEFT JOIN print_barcode_headerso_log ON Print_BarcodeHeaderSoLogT_OrderHeaderID = T_OrderHeaderID
WHERE
T_OrderHeaderIsActive = 'Y' AND T_SamplingSoT_SampleStationID = {$stationid} AND T_SamplingSoFlag = 'V' AND
(( T_SamplingSoFlagSend = 'R' AND T_SamplingSoIsActive = 'Y' AND T_SamplingSoM_DoctorID = 0 AND '{$statusid}' = 'R' ) OR
('{$statusid}' = 'C' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID <> 0 ))
$filter_search
GROUP BY T_OrderDetailID
ORDER BY iscito ASC,T_SamplingSoReceiveAdmDate ASC, T_SamplingSoReceiveAdmTime ASC,T_OrderHeaderID ASC
$limit
";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$zxprm = array();
$zxprm['status'] = $v['status'];
$zxprm['orderid'] = $v['T_OrderHeaderID'];
$zxprm['sampletypeid'] = $v['T_SampleTypeID'];
$zxprm['samplingso_id'] = $v['T_SamplingSoID'];
$rows[$k]['requirements'] = $this->getrequirements($zxprm);
$rows[$k]['barcodes'] = $this->getbarcodes($v['T_OrderHeaderID']);
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function getbarcodes($orderid){
$sql = " SELECT T_TestName,
T_OrderHeaderLabNumber,
M_PatientNoReg,
M_PatientName,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
T_OrderHeaderM_PatientAge as umur,
fn_get_patient_first_address(M_PatientID) as alamat,
IF(ISNULL(M_DoctorName),'-',CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3)) as doctor_fullname,
M_CompanyName
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND
( DocumentationGroupName <> 'lab' AND DocumentationGroupName <> 'other' )
WHERE
T_OrderHeaderID = {$orderid} AND T_OrderDetailIsActive = 'Y'
GROUP BY T_TestID";
//echo $sql;
$rst = $this->db_onedev->query($sql)->result_array();
return $rst;
}
function getrequirements($prm){
$query =" SELECT Nat_RequirementID as id,
Nat_RequirementName as name, '{$prm['status']}' as status,
if(ISNULL(T_SamplingSoRequirementID),'N', if(json_contains(T_SamplingSoRequirementRequirements,Nat_RequirementID),'Y','N') ) as chex,
Nat_RequirementPositionNat_PositionID as positionid
FROM nat_requirement
JOIN nat_testrequirement ON Nat_TestRequirementNat_RequirementID = Nat_RequirementID
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID AND Nat_RequirementPositionNat_PositionID = 9 AND
Nat_RequirementPositionIsActive = 'Y'
JOIN t_test ON T_TestNat_TestID = Nat_TestRequirementNat_TestID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = {$prm['orderid']} AND
T_SamplingSoRequirementT_SamplingSoID = {$prm['samplingso_id']} AND T_SamplingSoRequirementNat_PositionID = Nat_RequirementPositionNat_PositionID
WHERE
Nat_TestRequirementIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
return $rows;
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query =" SELECT T_SampleStationID as id, T_SampleStationName as name
FROM t_samplestation
WHERE
T_SampleStationIsActive = 'Y' AND T_SampleStationIsNonLab = 'RADIODIAGNOSTIC'
";
//echo $query;
$rows['stations'] = $this->db_onedev->query($query)->result_array();
$rows['statuses'] = array(array('id'=>'R','name'=>'Sudah Terima'),array('id'=>'C','name'=>'Selesai'));
$query =" SELECT Group_ResultID as id, Group_ResultName as name
FROM group_result
WHERE
Group_ResultIsActive = 'Y' AND Group_ResultFlagNonLab = 'Y'
";
//echo $query;
$rows['gresults'] = $this->db_onedev->query($query)->result_array();
$rows['doctors'] = array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function saveprintlog(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$rows = [];
$sql ="INSERT INTO print_barcode_headerso_log (
Print_BarcodeHeaderSoLogT_OrderHeaderID,
Print_BarcodeHeaderSoLogUserID
)
VALUES(
{$prm['T_OrderHeaderID']},
{$userid}
)";
//echo $query;
$this->db_onedev->query($sql);
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function saveprintalllog(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sel_order = $prm['selected_order'];
$userid = $this->sys_user["M_UserID"];
$rows = [];
foreach($sel_order as $k => $v){
$sql ="INSERT INTO print_barcode_headerso_log (
Print_BarcodeHeaderSoLogT_OrderHeaderID,
Print_BarcodeHeaderSoLogUserID
)
VALUES(
{$v['T_OrderHeaderID']},
{$userid}
)";
//echo $query;
$this->db_onedev->query($sql);
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdoctorbystation(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows= [];
$sql = "
SELECT M_DoctorID as id, M_DoctorName, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name, '' as address
FROM m_doctor
JOIN m_doctorso ON M_DoctorSOM_DoctorID = M_DoctorID AND M_DoctorSOIsActive = 'Y'
JOIN t_test ON T_TestNat_SubgroupID = M_DoctorSONat_SubGroupID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
WHERE
M_DoctorIsActive = 'Y'
GROUP BY M_DoctorID
ORDER BY M_DoctorName DESC
";
// echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v){
$rows[$k]['address'] = $this->db_onedev->query("SELECT * FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['id']} AND M_DoctorAddressIsActive = 'Y'")->result_array();
}
$rows['doctors'] = $rows;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function search_patient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$stationid = $prm["stationid"];
$statusid = $prm["statusid"];
$sql_where = "WHERE T_OrderHeaderLabNumber = '{$search}' AND T_OrderHeaderIsActive = 'Y'";
$rows = [];
$query = "SELECT T_OrderHeaderID,T_BarcodeLabID,T_BarcodeLabBarcode,T_SampleTypeName,T_OrderHeaderLabNumber,
IFNULL(M_PatientPhoto,'') as M_PatientPhotoThumb,
M_SexName, M_TitleName,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
M_CompanyName,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
T_SampleStationID, T_SampleTypeID,
{$stationid} as stationid,
T_SamplingSoID,
T_SamplingSoFlagSend as status,
fn_global_check_is_cito(T_OrderHeaderID) as iscito,
IF(ISNULL(T_SamplingSoRequirementID),'X',T_SamplingSoRequirementStatus) as requirement_status,
'' as requirements,
IF(ISNULL(M_DoctorName),'-',CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,'...')) as doctor_fullname,
T_SamplingSoFlagDoctorInOffice as flagdoctorinoffice,
T_SamplingSoM_DoctorID
FROM t_orderheader
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid} AND T_SampleStationIsNonLab = 'RADIODIAGNOSTIC'
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND T_SamplingSoT_SampleTypeID = T_SampleTypeID AND
T_SamplingSoT_BarcodeLabID = T_BarcodeLabID AND T_SamplingSoFlag = 'V' AND
(('{$statusid}' = 'R' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID = 0 ) OR ('{$statusid}' = 'C' AND T_SamplingSoFlagSend = 'R' AND T_SamplingSoM_DoctorID <> 0 )) AND
T_SamplingSoIsActive = 'Y'
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = T_OrderHeaderID AND
T_SamplingSoRequirementT_SampletypeID = T_SampletypeID AND
T_SamplingSoRequirementNat_PositionID = 9 AND
T_SamplingSoRequirementIsActive = 'Y'
$sql_where
GROUP BY T_BarcodeLabID
ORDER BY iscito DESC,T_OrderPromiseDateTime ASC, T_OrderHeaderID ASC, T_SamplingSoID ASC
limit 0,20";
$rows = $this->db_onedev->query($query)->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['chex'] = true;
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdoctoraddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
FROM m_doctoraddress
WHERE
M_DoctorAddressM_DoctorID = {$prm['id']} AND M_DoctorAddressIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$samples = $prm['sample'];
if($prm['act'] == 'receive'){
foreach($samples as $k=>$v){
$sql = "UPDATE t_samplingso SET
T_SamplingSoFlagSend = 'R',
T_SamplingSoReceiveAdmDate = CURDATE(),
T_SamplingSoReceiveAdmTime = CURTIME(),
T_SamplingSoReceiveAdmUserID = {$userid},
T_SamplingSoUserID = {$userid}
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
$this->db_onedev->query($sql);
}
}
if($prm['act'] == 'cancel'){
foreach($samples as $k=>$v){
$sql = "UPDATE t_samplingso SET
T_SamplingSoFlagSend = 'N',
T_SamplingSoReceiveAdmDate = NULL,
T_SamplingSoReceiveAdmTime = NULL,
T_SamplingSoReceiveAdmUserID = NULL,
T_SamplingSoFlag = 'Z',
T_SamplingSoSendAdmDate = NULL,
T_SamplingSoSendAdmTime = NULL,
T_SamplingSoSendAdmUserID = NULL,
T_SamplingSoVerifyDate = NULL,
T_SamplingSoVerifyTime = NULL,
T_SamplingSoVerifyUserID = NULL,
T_SamplingSoUserID = {$userid}
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
$this->db_onedev->query($sql);
}
}
if($prm['act'] == 'reject'){
foreach($samples as $k=>$v){
$sql = "UPDATE t_samplingso SET
T_SamplingSoFlagSend = 'D',
T_SamplingSoSendAdmDate = NULL,
T_SamplingSoSendAdmTime = NULL,
T_SamplingSoSendAdmUserID = NULL,
T_SamplingSoVerifyDate = NULL,
T_SamplingSoVerifyTime = NULL,
T_SamplingSoVerifyUserID = NULL,
T_SamplingSoUserID = {$userid}
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
$this->db_onedev->query($sql);
}
}
if($prm['act'] == 'removedoctor'){
foreach($samples as $k => $v){
$query =" UPDATE t_samplingso SET
T_SamplingSoFlagDoctorInOffice = 'N',
T_SamplingSoM_DoctorID = 0,
T_SamplingSoM_DoctorAddressID = 0
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
//echo $query;
$savedoctor = $this->db_onedev->query($query);
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM (
SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name, '' as address
FROM m_doctor
JOIN m_doctorso ON M_DoctorSOM_DoctorID = M_DoctorID AND M_DoctorSOIsActive = 'Y'
JOIN t_test ON T_TestNat_SubgroupID = M_DoctorSONat_SubGroupID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
WHERE
M_DoctorName like ?
AND M_DoctorIsActive = 'Y'
GROUP BY M_DoctorID
)xx";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_DoctorID as id, M_DoctorName, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name, '' as address
FROM m_doctor
JOIN m_doctorso ON M_DoctorSOM_DoctorID = M_DoctorID AND M_DoctorSOIsActive = 'Y'
JOIN t_test ON T_TestNat_SubgroupID = M_DoctorSONat_SubGroupID AND T_TestIsActive = 'Y'
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID AND T_SampleTypeIsActive = 'Y'
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y'
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
WHERE
CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) like ?
AND M_DoctorIsActive = 'Y'
GROUP BY M_DoctorID
ORDER BY M_DoctorName DESC
";
//echo $sql;
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v){
$rows[$k]['address'] = $this->db_onedev->query("SELECT * FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['id']} AND M_DoctorAddressIsActive = 'Y'")->result_array();
}
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
//echo $sql;
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v){
}
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function savedoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sel_patient = $prm['selected_patient'];
$sel_doctor = $prm['selected_doctor'];
$sel_doctor_address = $prm['selected_doctor_address'];
$flagdoctorinoffice = $prm['flagdoctorinoffice'] == true ? 'Y':'N';
foreach($sel_patient as $k => $v){
$query =" UPDATE t_samplingso SET
T_SamplingSoFlagDoctorInOffice = '{$flagdoctorinoffice}',
T_SamplingSoM_DoctorID = {$sel_doctor['id']},
T_SamplingSoM_DoctorAddressID = {$sel_doctor_address['M_DoctorAddressID']}
WHERE
T_SamplingSoID = {$v['T_SamplingSoID']}";
//echo $query;
$savedoctor = $this->db_onedev->query($query);
$sql = "INSERT INTO sample_so_by_step (
SampleSoByStepT_OrderHeaderID,
SampleSoByStepT_TestID,
SampleSoByStepCode,
SampleSoByStepDateTime,
SampleSoByStepUserID
)
VALUES(
{$v['T_OrderHeaderID']},
{$v['T_TestID']},
'SAMPLING.Handling.Process',
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
$sql = "INSERT INTO sample_so_by_step (
SampleSoByStepT_OrderHeaderID,
SampleSoByStepT_TestID,
SampleSoByStepCode,
SampleSoByStepDateTime,
SampleSoByStepUserID
)
VALUES(
{$v['T_OrderHeaderID']},
{$v['T_TestID']},
'SAMPLING.Handling.To.Process',
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
}
if($savedoctor){
$result = array(
"total" => 1 ,
"records" => array(),
);
$this->sys_ok($result);
exit;
}
else{
$this->sys_error_db("doctor update", $this->db_onedev);
exit;
}
}
function deletephoto(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query =" UPDATE so_imageupload SET So_ImageUploadIsActive = 'N', So_ImageUploadUserID = {$userid} WHERE So_ImageUploadID = {$prm['id']}";
//echo $query;
$actdelete = $this->db_onedev->query($query);
if($actdelete){
$result = array(
"total" => 1 ,
"records" => array(),
);
$this->sys_ok($result);
exit;
}
else{
$this->sys_error_db("so_imageupload delete", $this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,716 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
F_BillM_MouID,
M_MouID,
IF(F_BillM_MouID = 0, 'Semua',M_MouName) as M_MouName,
F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$rows[$k]['haveDetail'] = "N";
} else {
$rows[$k]['haveDetail'] = "Y";
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' ";
/*
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
*/
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName
limit 0,50
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT 0 as M_MouID, 'Semua' as M_MouName
UNION
SELECT M_MouID, M_MouName
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouIsBill = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillDueDateDay = '{$prm['day']}',
F_BillDueDate = '{$pdate}',
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}',
F_BillCreated = now()
WHERE F_BillID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
order by F_BillDetailID asc";
} else {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsBill = 'Y'
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_BillDetailID IS NULL AND F_PaymentID IS NULL
order by T_OrderHeaderDate asc, T_OrderHeaderID asc";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,681 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
// echo $norm;
$sql_where = "WHERE F_BillIsActive = 'Y' ";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
//if ($sql_where != "") $sql_where .= " and ";
// Order masih dalam status registrasi
//$sql_where .= " M_PatientIsActive = 'Y' ";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,20";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
WHERE F_BillID = '{$v['F_BillID']}' ")->row();
$rows[$k]['statuss'] = json_decode($x->n);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDate,
F_BillNote,
F_BillTotal,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$pdate}',
'{$prm['note']}',
`fn_get_total_bill`({$prm['mouid']}),
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="INSERT INTO f_bill_detail (
F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated
)
select $last_id,T_OrderHeaderID,$userid,NOW(),NOW()
from t_orderheader
left join f_payment on T_OrderHeaderID = F_PaymentT_OrderHeaderID
and T_OrderHeaderM_MouID = '{$prm['mouid']}'
where T_OrderHeaderIsActive = 'Y' and F_PaymentID is null and T_OrderHeaderID not in (
select F_BillDetailT_OrderHeaderID from f_bill_detail where F_BillDetailIsActive = 'Y'
)
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailIsActive = 'Y' AND F_BillDetailF_BillID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailF_BillID = '{$v['F_BillID']}' AND F_BillDetailIsActive = 'Y'")->row();
$rows[$k]['tesx'] = json_decode($x->n);
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO t_receivereferencepatient (
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID,
T_ReceiveReferencePatientNoRef,
T_ReceiveReferencePatientName,
T_ReceiveReferencePatientDOB,
T_ReceiveReferencePatientM_SexID,
T_ReceiveReferencePatientUserID,
T_ReceiveReferencePatientTotal,
T_ReceiveReferencePatientDPPercent,
T_ReceiveReferencePatientDPAmount,
T_ReceiveReferencePatientCreated
)
VALUES(
'{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
'{$prm['T_ReceiveReferencePatientNoRef']}',
'{$prm['T_ReceiveReferencePatientName']}',
'{$pdob}',
'{$prm['T_ReceiveReferencePatientM_SexID']}',
'{$userid}',
'{$prm['T_ReceiveReferencePatientTotal']}',
'{$prm['T_ReceiveReferencePatientDPPercent']}',
'{$prm['T_ReceiveReferencePatientDPAmount']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$orderpatient_id = $this->db_onedev->insert_id();
foreach($prm['ordertests'] as $k=>$v){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestT_TestDisc,
T_ReceiveReferenceTestT_TestDiscRp,
T_ReceiveReferenceTestT_TestTotal,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,?,?,?, now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$orderpatient_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['T_PriceAmount'],
$v['T_PriceDisc'],
$v['T_PriceDiscRp'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,937 @@
<?php
class BillIssue extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "BRANCH API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupbillissuebyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billissue = $prm['branch'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
from f_bill_issue
JOIN m_company ON M_CompanyID = F_BillIssueM_CompanyID
JOIN m_mou ON M_MouID = F_BillIssueM_MouID
WHERE
(F_BillIssueNumber LIKE CONCAT('%','{$billissue}','%') OR
M_MouName LIKE CONCAT('%','{$billissue}','%')) AND
F_BillIssueIsActive = 'Y'";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("f_bill_issue count", $this->db_onedev);
exit;
}
$sql = "select F_BillIssueID as id,
DATE_FORMAT(F_BillIssueDate,'%d-%m-%Y') as tanggal,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as companyname,
M_CompanyID,
M_CompanyName,
M_MouID,
M_MouName,
f_bill_issue.*
from f_bill_issue
JOIN m_company ON M_CompanyID = F_BillIssueM_CompanyID
JOIN m_mou ON M_MouID = F_BillIssueM_MouID
WHERE
(F_BillIssueNumber LIKE CONCAT('%','{$billissue}','%') OR
M_MouName LIKE CONCAT('%','{$billissue}','%')) AND
F_BillIssueIsActive = 'Y'
GROUP BY F_BillIssueID
ORDER BY F_BillIssueNumber DESC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("f_bill_issue select");
exit;
}
$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);
}
}
public function lookupregionalbyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$regional = $prm['regional'];
$billissue = $prm['billissue'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
FROM(SELECT *
from s_regional
LEFT JOIN f_bill_issue ON S_RegionalID = F_BillIssueS_RegionalID AND F_BillIssueIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(F_BillIssueName,'') LIKE CONCAT('%','{$billissue}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID) a";
$sql_param = array($search);
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("s_regional count", $this->db_onedev);
exit;
}
$sql = "select S_RegionalID as id,
S_RegionalName as name,
S_RegionalName as namex,
s_regional.*
from s_regional
LEFT JOIN f_bill_issue ON S_RegionalID = F_BillIssueS_RegionalID AND F_BillIssueIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(F_BillIssueName,'') LIKE CONCAT('%','{$billissue}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID
ORDER BY S_RegionalName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("s_regional select");
exit;
}
$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);
}
}
public function addnewregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$sql = "insert into s_regional(
S_RegionalName,
S_RegionalCreated,
S_RegionalLastUpdated
)
values( ?, now(), now())";
$query = $this->db_onedev->query($sql,
array(
$name
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("s_regional insert");
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
$last_id = $this->db_onedev->insert_id();
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$name = $prm['name'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update s_regional SET
S_RegionalName = ?,
S_RegionalLastUpdated = now()
where
S_RegionalID = ?
";
$querycompany = $this->db_onedev->query($sqlcompany,
array(
$name,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("s_regional update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewbillissue()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$F_BillIssueM_CompanyID = $prm['akunid'];
$F_BillIssueMerchantCode = $prm['code'];
$F_BillIssueM_PaymentTypeID = $prm['paymenttypeid'];
$userid = $this->sys_user["M_UserID"];
if($prm['xid'] == 0){
$sql = "insert into f_bill_issue(
F_BillIssueM_CompanyID,
F_BillIssueMerchantCode,
F_BillIssueM_PaymentTypeID,
F_BillIssueCreated,
F_BillIssueLastUpdated,
F_BillIssueUserID)
values(?,?,?,now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$F_BillIssueM_CompanyID,
$F_BillIssueMerchantCode,
$F_BillIssueM_PaymentTypeID,
$userid)
);
if (!$query) {
$this->sys_error_db("f_bill_issue insert",$this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$sql = "UPDATE f_bill_issue SET F_BillIssueM_CompanyID = '{$F_BillIssueM_CompanyID}',
F_BillIssueMerchantCode = '{$F_BillIssueMerchantCode}',
F_BillIssueM_PaymentTypeID = '{$F_BillIssueM_PaymentTypeID}',
F_BillIssueUserID = '{$userid}',
F_BillIssueLastUpdated = now()
WHERE F_BillIssueID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sql = "update s_regional SET
S_RegionalIsActive = 'N',
S_RegionalLastUpdated = now()
WHERE
S_RegionalID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("s_regional delete");
exit;
}
$sql = "update f_bill_issue SET
F_BillIssueIsActive = 'N',
F_BillIssueLastUpdated = now()
WHERE
F_BillIssueS_RegionalID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("f_bill_issue 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 deletebillissue()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sql = "update f_bill_issue SET
F_BillIssueIsActive = 'N',
F_BillIssueLastUpdated = now()
WHERE
F_BillIssueID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("f_bill_issue 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 searchakun(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['tes'] != '')
{
$q['search'] = "%{$prm['tes']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
F_BillIssueNumber like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_CompanyID,CONCAT(M_MouName, ' [',F_BillIssueNumber,'] ') as F_BillIssueNumber
FROM m_company
JOIN m_mou ON M_MouID = F_BillIssueM_MouID
WHERE
CONCAT(M_MouName, ' [',F_BillIssueNumber,'] ') like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function selectpaymenttype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_paymenttype
WHERE
M_PaymentTypeIsActive = 'Y'
";
//echo $query;
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchregionalbyname(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("s_regional count",$this->db_onedev);
exit;
}
$sql = "
SELECT S_RegionalID, S_RegionalName
FROM s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'
ORDER BY S_RegionalName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("s_regional rows",$this->db_onedev);
exit;
}
}
function searchpaymenttype(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_paymenttype
WHERE
M_PaymentTypeName like ?
AND M_PaymentTypeIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_subcategory count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_PaymentTypeID, M_PaymentTypeName
FROM m_paymenttype
WHERE
M_PaymentTypeName like ?
AND M_PaymentTypeIsActive = 'Y'
ORDER BY M_PaymentTypeName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_subcategory rows",$this->db_onedev);
exit;
}
}
function searchdistrict(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_SubCategoryID = '{$id}'
AND M_DistrictIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_SubCategoryID = '{$id}'
AND M_DistrictIsActive = 'Y'
ORDER BY M_DistrictName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_onedev);
exit;
}
}
function searchkelurahan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'
ORDER BY M_KelurahanName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_onedev);
exit;
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_CompanyID, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function searchmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y' AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_mou count",$this->db_onedev);
exit;
}
$sql = "SELECT *
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_mou rows",$this->db_onedev);
exit;
}
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_doctor count",$this->db_onedev);
exit;
}
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?
GROUP BY M_DoctorID
ORDER BY M_DoctorName ASC";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_onedev);
exit;
}
}
function selectaddressdoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$rows = [];
$query ="SELECT M_DoctorAddressID,
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
FROM
m_doctoraddress
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
//echo $query;
$rows['addressdoctors'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,975 @@
<?php
class Extend extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}' AND F_BillIssueIsReceive = 'Y'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like concat('%','{$nama}','%') ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like concat('%','{$norm}','%') ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID AND F_BillIssueIsActive = 'Y'
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
f_bill_issue.*,
F_BillM_MouID,
M_MouID,
M_MouName,
F_BillDueDateDay + SUM(IFNULL(b.F_BillIssueExtendDay,0)) as F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,F_BillDueDate),'%d-%m-%Y') as duedate,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,F_BillDueDate),'%Y-%m-%d') as duedatex,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillIssueReceiveDate,'%d-%m-%Y') as F_BillCreated,
DATE_FORMAT(F_BillIssueReceiveDate,'%Y-%m-%d') as billcreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
CONCAT(M_MouName,'|',M_MouNumber) as moudesc,
IFNULL(F_BillIssueExtendID,0) as F_BillIssueExtendID,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,'-'),'%d-%m-%Y') as extenddate,
DATE_ADD(F_BillDueDate, INTERVAL 7 DAY) as exduedate,
DATE_FORMAT(DATE_ADD(F_BillDueDate, INTERVAL 7 DAY),'%d-%m-%Y') as exduedatex,
F_BillIssueIsAllMou,
M_MouID as mouid,
M_MouIsActive
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID AND F_BillIssueIsActive = 'Y'
LEFT JOIN f_bill_issue_extend b ON F_BillIssueExtendF_BillIssueID = F_BillIssueID
$sql_where
AND F_BillIssueIsAllMou = 'N'
GROUP BY F_BillIssueID
UNION
SELECT
F_BillID,
F_BillNo,
f_bill_issue.*,
F_BillM_MouID,
M_MouID,
M_MouName,
F_BillDueDateDay + SUM(IFNULL(b.F_BillIssueExtendDay,0)) as F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,F_BillDueDate),'%d-%m-%Y') as duedate,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,F_BillDueDate),'%Y-%m-%d') as duedatex,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillIssueReceiveDate,'%d-%m-%Y') as F_BillCreated,
DATE_FORMAT(F_BillIssueReceiveDate,'%Y-%m-%d') as billcreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
GROUP_CONCAT(DISTINCT CONCAT(M_MouName,'|',M_MouNumber) SEPARATOR ',') as moudesc,
IFNULL(F_BillIssueExtendID,0) as F_BillIssueExtendID,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,'-'),'%d-%m-%Y') as extenddate,
DATE_ADD(F_BillDueDate, INTERVAL 7 DAY) as exduedate,
DATE_FORMAT(DATE_ADD(F_BillDueDate, INTERVAL 7 DAY),'%d-%m-%Y') as exduedatex,
F_BillIssueIsAllMou,
GROUP_CONCAT(M_MouID SEPARATOR ',') as mouid,
M_MouIsActive
FROM f_bill
left join m_company on F_BillM_CompanyID = M_CompanyID
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID AND F_BillIssueIsActive = 'Y'
join f_bill_mou on F_BillMouF_BillID = F_BillID AND F_BillMouIsActive = 'Y'
LEFT JOIN m_mou ON F_BillMouM_MouID = M_MouID
LEFT JOIN f_bill_issue_extend b ON F_BillIssueExtendF_BillIssueID = F_BillIssueID
$sql_where
AND F_BillIssueIsAllMou = 'Y'
GROUP BY F_BillIssueID
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$mouID = $v['F_BillM_MouID'];
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM t_orderheader
join f_bill on F_BillID = '{$v['F_BillID']}'
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID AND F_BillIssueIsActive = 'Y'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_PaymentID IS NULL")->row();
$rows[$k]['haveDetail'] = "N";
$rows[$k]['startdate'] = $startdate->startdate;
} else {
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
$rows[$k]['haveDetail'] = "Y";
$rows[$k]['startdate'] = $startdate->startdate;
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function history()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$id = $prm["id"];
$sql_where = "WHERE F_BillIssueExtendF_BillIssueID = '{$id}'";
$sql_param = array();
$sql = "SELECT count(*) as total
FROM f_bill_issue_extend
$sql_where";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
f_bill_issue_extend.*,
DATE_FORMAT(F_BillIssueExtendCreated,'%d-%m-%Y %H:%i') as tanggal,
DATE_FORMAT(F_BillIssueExtendDueDate,'%d-%m-%Y') as duedate,
M_StaffName
FROM f_bill_issue_extend
LEFT JOIN m_user ON F_BillIssueExtendUserID = M_UserID
left join m_staff on M_UserM_StaffID = M_StaffID
$sql_where
ORDER BY F_BillIssueExtendID DESC
limit 0, $tot_count ";
// echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query ="SELECT M_MouID,
M_MouName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
M_MouAgingDay,
M_MouPicBillName,
M_MouPicBillHandphone
FROM m_mou
WHERE
M_MouM_CompanyID = ?
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$bquery = "SELECT M_BranchCode as branchcode FROM m_branch WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'";
$branchcode = $this->db_onedev->query($bquery)->row()->branchcode;
$queryissue ="INSERT INTO f_bill_issue (
F_BillIssueNumber,
F_BillIssueF_BillID,
F_BillIssueDate,
F_BillIssuePIC,
F_BillIssuePICHP,
F_BillIssueM_CompanyID,
F_BillIssueM_MouID,
F_BillIssueAgingDay,
F_BillIssueUserID,
F_BillIssueCreated
)
VALUES(
CONCAT('{$branchcode}','/',`fn_numbering`('BI')),
'{$last_id}',
date(now()),
'{$prm['picname']}',
'{$prm['pichp']}',
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rowsissue = $this->db_onedev->query($queryissue);
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue SET
F_BillIssueExtendDay = F_BillIssueExtendDay + '{$prm['day']}',
F_BillIssueExtendNote = '{$prm['note']}',
F_BillIssueExtendDueDate = '{$prm['duedate']}',
F_BillIssueExtendUserID = '{$userid}'
WHERE F_BillIssueID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE m_mou SET
M_MouIsActive = 'Y'
WHERE M_MouID IN ({$prm['mouid']})
";
// echo $query;
$rows = $this->db_onedev->query($query);
$query ="INSERT INTO f_bill_issue_extend(F_BillIssueExtendF_BillIssueID,
F_BillIssueExtendDay,
F_BillIssueExtendNote,
F_BillIssueExtendDueDate,
F_BillIssueExtendUserID,
F_BillIssueExtendCreated)
VALUES('{$prm['id']}',
'{$prm['day']}',
'{$prm['note']}',
'{$prm['duedate']}',
'{$userid}',
now())";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "SELECT *, IF(F_BillDetailID IS NULL ,'N','Y') as isbill,F_BillNo FROM (select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
SUM(IFNULL(F_PaymentTotal,0)) as bayar,
T_OrderHeaderTotal - SUM(IFNULL(F_PaymentTotal,0)) as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID))
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC) a
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillDetailF_BillID = F_BillID AND F_BillIsActive = 'Y'
WHERE total > 1";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_issue SET
F_BillIssueIsActive = 'N',
F_BillIssueUserID = '{$userid}'
WHERE
F_BillIssueF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function notifbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue SET
F_BillIssueIsNotif = 'Y',
F_BillIssueNotifUserID = '{$userid}',
F_BillIssueNotifDate = now()
WHERE
F_BillIssueF_BillID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function sendbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue SET
F_BillIssueIsSend = 'Y',
F_BillIssueNotifUserID = '{$userid}',
F_BillIssueSendDate = now()
WHERE
F_BillIssueF_BillID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,975 @@
<?php
class Extendv2 extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}' AND F_BillIssueIsReceive = 'Y'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like concat('%','{$nama}','%') ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like concat('%','{$norm}','%') ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID AND F_BillIssueIsActive = 'Y'
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
f_bill_issue.*,
F_BillM_MouID,
M_MouID,
M_MouName,
F_BillDueDateDay + SUM(IFNULL(b.F_BillIssueExtendDay,0)) as F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,F_BillDueDate),'%d-%m-%Y') as duedate,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,F_BillDueDate),'%Y-%m-%d') as duedatex,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillIssueReceiveDate,'%d-%m-%Y') as F_BillCreated,
DATE_FORMAT(F_BillIssueReceiveDate,'%Y-%m-%d') as billcreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
CONCAT(M_MouName,'|',M_MouNumber) as moudesc,
IFNULL(F_BillIssueExtendID,0) as F_BillIssueExtendID,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,'-'),'%d-%m-%Y') as extenddate,
DATE_ADD(F_BillDueDate, INTERVAL 7 DAY) as exduedate,
DATE_FORMAT(DATE_ADD(F_BillDueDate, INTERVAL 7 DAY),'%d-%m-%Y') as exduedatex,
F_BillIssueIsAllMou,
M_MouID as mouid,
M_MouIsActive
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID AND F_BillIssueIsActive = 'Y'
LEFT JOIN f_bill_issue_extend b ON F_BillIssueExtendF_BillIssueID = F_BillIssueID
$sql_where
AND F_BillIssueIsAllMou = 'N'
GROUP BY F_BillIssueID
UNION
SELECT
F_BillID,
F_BillNo,
f_bill_issue.*,
F_BillM_MouID,
M_MouID,
M_MouName,
F_BillDueDateDay + SUM(IFNULL(b.F_BillIssueExtendDay,0)) as F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,F_BillDueDate),'%d-%m-%Y') as duedate,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,F_BillDueDate),'%Y-%m-%d') as duedatex,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as F_BillDueDate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillIssueReceiveDate,'%d-%m-%Y') as F_BillCreated,
DATE_FORMAT(F_BillIssueReceiveDate,'%Y-%m-%d') as billcreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
GROUP_CONCAT(DISTINCT CONCAT(M_MouName,'|',M_MouNumber) SEPARATOR ',') as moudesc,
IFNULL(F_BillIssueExtendID,0) as F_BillIssueExtendID,
DATE_FORMAT(IFNULL(f_bill_issue.F_BillIssueExtendDueDate,'-'),'%d-%m-%Y') as extenddate,
DATE_ADD(F_BillDueDate, INTERVAL 7 DAY) as exduedate,
DATE_FORMAT(DATE_ADD(F_BillDueDate, INTERVAL 7 DAY),'%d-%m-%Y') as exduedatex,
F_BillIssueIsAllMou,
GROUP_CONCAT(M_MouID SEPARATOR ',') as mouid,
M_MouIsActive
FROM f_bill
left join m_company on F_BillM_CompanyID = M_CompanyID
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID AND F_BillIssueIsActive = 'Y'
join f_bill_mou on F_BillMouF_BillID = F_BillID AND F_BillMouIsActive = 'Y'
LEFT JOIN m_mou ON F_BillMouM_MouID = M_MouID
LEFT JOIN f_bill_issue_extend b ON F_BillIssueExtendF_BillIssueID = F_BillIssueID
$sql_where
AND F_BillIssueIsAllMou = 'Y'
GROUP BY F_BillIssueID
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$mouID = $v['F_BillM_MouID'];
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM t_orderheader
join f_bill on F_BillID = '{$v['F_BillID']}'
JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID AND F_BillIssueIsActive = 'Y'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_PaymentID IS NULL")->row();
$rows[$k]['haveDetail'] = "N";
$rows[$k]['startdate'] = $startdate->startdate;
} else {
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
$rows[$k]['haveDetail'] = "Y";
$rows[$k]['startdate'] = $startdate->startdate;
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function history()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$id = $prm["id"];
$sql_where = "WHERE F_BillIssueExtendF_BillIssueID = '{$id}'";
$sql_param = array();
$sql = "SELECT count(*) as total
FROM f_bill_issue_extend
$sql_where";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
f_bill_issue_extend.*,
DATE_FORMAT(F_BillIssueExtendCreated,'%d-%m-%Y %H:%i') as tanggal,
DATE_FORMAT(F_BillIssueExtendDueDate,'%d-%m-%Y') as duedate,
M_StaffName
FROM f_bill_issue_extend
LEFT JOIN m_user ON F_BillIssueExtendUserID = M_UserID
left join m_staff on M_UserM_StaffID = M_StaffID
$sql_where
ORDER BY F_BillIssueExtendID DESC
limit 0, $tot_count ";
// echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query ="SELECT M_MouID,
M_MouName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
M_MouAgingDay,
M_MouPicBillName,
M_MouPicBillHandphone
FROM m_mou
WHERE
M_MouM_CompanyID = ?
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$bquery = "SELECT M_BranchCode as branchcode FROM m_branch WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'";
$branchcode = $this->db_onedev->query($bquery)->row()->branchcode;
$queryissue ="INSERT INTO f_bill_issue (
F_BillIssueNumber,
F_BillIssueF_BillID,
F_BillIssueDate,
F_BillIssuePIC,
F_BillIssuePICHP,
F_BillIssueM_CompanyID,
F_BillIssueM_MouID,
F_BillIssueAgingDay,
F_BillIssueUserID,
F_BillIssueCreated
)
VALUES(
CONCAT('{$branchcode}','/',`fn_numbering`('BI')),
'{$last_id}',
date(now()),
'{$prm['picname']}',
'{$prm['pichp']}',
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rowsissue = $this->db_onedev->query($queryissue);
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue SET
F_BillIssueExtendDay = F_BillIssueExtendDay + '{$prm['day']}',
F_BillIssueExtendNote = '{$prm['note']}',
F_BillIssueExtendDueDate = '{$prm['duedate']}',
F_BillIssueExtendUserID = '{$userid}'
WHERE F_BillIssueID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE m_mou SET
M_MouIsActive = 'Y'
WHERE M_MouID IN ({$prm['mouid']})
";
// echo $query;
$rows = $this->db_onedev->query($query);
$query ="INSERT INTO f_bill_issue_extend(F_BillIssueExtendF_BillIssueID,
F_BillIssueExtendDay,
F_BillIssueExtendNote,
F_BillIssueExtendDueDate,
F_BillIssueExtendUserID,
F_BillIssueExtendCreated)
VALUES('{$prm['id']}',
'{$prm['day']}',
'{$prm['note']}',
'{$prm['duedate']}',
'{$userid}',
now())";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "SELECT *, IF(F_BillDetailID IS NULL ,'N','Y') as isbill,F_BillNo FROM (select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
SUM(IFNULL(F_PaymentTotal,0)) as bayar,
T_OrderHeaderTotal - SUM(IFNULL(F_PaymentTotal,0)) as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID))
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC) a
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillDetailF_BillID = F_BillID AND F_BillIsActive = 'Y'
WHERE total > 1";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_issue SET
F_BillIssueIsActive = 'N',
F_BillIssueUserID = '{$userid}'
WHERE
F_BillIssueF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function notifbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue SET
F_BillIssueIsNotif = 'Y',
F_BillIssueNotifUserID = '{$userid}',
F_BillIssueNotifDate = now()
WHERE
F_BillIssueF_BillID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function sendbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue SET
F_BillIssueIsSend = 'Y',
F_BillIssueNotifUserID = '{$userid}',
F_BillIssueSendDate = now()
WHERE
F_BillIssueF_BillID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,980 @@
<?php
class Forceonhold extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "BRANCH API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookuppgbankbyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pgbank = $prm['branch'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
from f_force_onhold
JOIN m_mou ON M_MouID = F_ForceOnHoldM_MouID
WHERE
(M_MouNumber LIKE CONCAT('%','{$pgbank}','%') OR
M_MouName LIKE CONCAT('%','{$pgbank}','%'))";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("f_force_onhold count", $this->db_onedev);
exit;
}
$sql = "select F_ForceOnHoldID as id,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
M_MouID,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
M_MouName,
f_force_onhold.*,
M_StaffID,
M_StaffName,
DATE_FORMAT(F_ForceOnHoldCreated,'%d-%m-%Y') as tanggal,
IF(F_ForceOnHoldIsActive = 'Y','On Hold','Batal') as status
from f_force_onhold
JOIN m_mou ON M_MouID = F_ForceOnHoldM_MouID
JOIN m_company ON M_CompanyID = M_MouM_CompanyID
JOIN m_user ON M_UserID = F_ForceOnHoldUserID
JOIN m_staff ON M_StaffID = M_UserM_StaffID
WHERE
(M_MouNumber LIKE CONCAT('%','{$pgbank}','%') OR
M_MouName LIKE CONCAT('%','{$pgbank}','%'))
GROUP BY F_ForceOnHoldID
ORDER BY F_ForceOnHoldID ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("f_force_onhold select");
exit;
}
$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);
}
}
public function lookupregionalbyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$regional = $prm['regional'];
$pgbank = $prm['pgbank'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
FROM(SELECT *
from s_regional
LEFT JOIN f_force_onhold ON S_RegionalID = F_ForceOnHoldS_RegionalID AND F_ForceOnHoldIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(F_ForceOnHoldName,'') LIKE CONCAT('%','{$pgbank}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID) a";
$sql_param = array($search);
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("s_regional count", $this->db_onedev);
exit;
}
$sql = "select S_RegionalID as id,
S_RegionalName as name,
S_RegionalName as namex,
s_regional.*
from s_regional
LEFT JOIN f_force_onhold ON S_RegionalID = F_ForceOnHoldS_RegionalID AND F_ForceOnHoldIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(F_ForceOnHoldName,'') LIKE CONCAT('%','{$pgbank}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID
ORDER BY S_RegionalName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("s_regional select");
exit;
}
$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);
}
}
public function addnewregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$sql = "insert into s_regional(
S_RegionalName,
S_RegionalCreated,
S_RegionalLastUpdated
)
values( ?, now(), now())";
$query = $this->db_onedev->query($sql,
array(
$name
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("s_regional insert");
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
$last_id = $this->db_onedev->insert_id();
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$name = $prm['name'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update s_regional SET
S_RegionalName = ?,
S_RegionalLastUpdated = now()
where
S_RegionalID = ?
";
$querycompany = $this->db_onedev->query($sqlcompany,
array(
$name,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("s_regional update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewpgbank()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$F_ForceOnHoldM_MouID = $prm['mouid'];
$F_ForceOnHoldNote = $prm['note'];
$userid = $this->sys_user["M_UserID"];
if($prm['xid'] == 0){
$sql = "insert into f_force_onhold(
F_ForceOnHoldM_MouID,
F_ForceOnHoldNote,
F_ForceOnHoldCreated,
F_ForceOnHoldLastUpdated,
F_ForceOnHoldUserID)
values(?,?,now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$F_ForceOnHoldM_MouID,
$F_ForceOnHoldNote,
$userid)
);
if (!$query) {
$this->sys_error_db("f_force_onhold insert",$this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$sql = "UPDATE m_mou SET M_MouIsActive = 'F'
WHERE M_MouID = '{$F_ForceOnHoldM_MouID}'";
// echo $sql;
$query = $this->db_onedev->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$sql = "UPDATE f_force_onhold SET F_ForceOnHoldM_MouID = '{$F_ForceOnHoldM_MouID}',
F_ForceOnHoldNote = '{$F_ForceOnHoldNote}',
F_ForceOnHoldUserID = '{$userid}',
F_ForceOnHoldLastUpdated = now()
WHERE F_ForceOnHoldID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sql = "update s_regional SET
S_RegionalIsActive = 'N',
S_RegionalLastUpdated = now()
WHERE
S_RegionalID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("s_regional delete");
exit;
}
$sql = "update f_force_onhold SET
F_ForceOnHoldIsActive = 'N',
F_ForceOnHoldLastUpdated = now()
WHERE
F_ForceOnHoldS_RegionalID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("f_force_onhold 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 deletepgbank()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$fid = $prm['id'];
$sql = $this->db_onedev->query("SELECT F_ForceOnHoldM_MouID as mouid from
f_force_onhold
WHERE F_ForceOnHoldID = $fid")->row();
$mouid = $sql->mouid;
$userid = $this->sys_user["M_UserID"];
$sql = "update f_force_onhold SET
F_ForceOnHoldIsActive = 'N',
F_ForceOnHoldLastUpdated = now()
WHERE
F_ForceOnHoldID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("f_force_onhold delete");
exit;
}
$sql = "update m_mou SET
M_MouIsActive = 'Y'
WHERE
M_MouID = ? AND M_MouIsActive = 'F'";
$query = $this->db_onedev->query($sql,
array(
$mouid
)
);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['tes'] != '')
{
$q['search'] = "%{$prm['tes']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query ="SELECT M_MouID,
M_MouName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
M_MouAgingDay,
M_MouPicBillName,
M_MouPicBillHandphone,
M_MouPicBillEmail,
M_MouFinanceName,
M_MouFinanceHandphone,
CONCAT(M_MouPicBillEmail,' , ', M_MouFinanceEmail) as M_MouFinanceEmail
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchakun(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['tes'] != '')
{
$q['search'] = "%{$prm['tes']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_mou
WHERE
M_MouNumber like ?
AND M_MouIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_mou count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_MouID,CONCAT(M_MouName, ' [',M_MouNumber,'] ') as M_MouNumber
FROM m_mou
JOIN nat_bank ON Nat_BankID = M_MouNat_BankID
WHERE
CONCAT(M_MouName, ' [',M_MouNumber,'] ') like ?
AND M_MouIsActive = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_mou rows",$this->db_onedev);
exit;
}
}
function selectpaymenttype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_paymenttype
WHERE
M_PaymentTypeIsActive = 'Y'
";
//echo $query;
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchregionalbyname(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("s_regional count",$this->db_onedev);
exit;
}
$sql = "
SELECT S_RegionalID, S_RegionalName
FROM s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'
ORDER BY S_RegionalName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("s_regional rows",$this->db_onedev);
exit;
}
}
function searchpaymenttype(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_paymenttype
WHERE
M_PaymentTypeName like ?
AND M_PaymentTypeIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_subcategory count",$this->db_onedev);
exit;
}
$sql = "
SELECT M_PaymentTypeID, M_PaymentTypeName
FROM m_paymenttype
WHERE
M_PaymentTypeName like ?
AND M_PaymentTypeIsActive = 'Y'
ORDER BY M_PaymentTypeName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_subcategory rows",$this->db_onedev);
exit;
}
}
function searchdistrict(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_SubCategoryID = '{$id}'
AND M_DistrictIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_SubCategoryID = '{$id}'
AND M_DistrictIsActive = 'Y'
ORDER BY M_DistrictName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_onedev);
exit;
}
}
function searchkelurahan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'
ORDER BY M_KelurahanName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_onedev);
exit;
}
}
function searchmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_mou count",$this->db_onedev);
exit;
}
$sql = "SELECT *
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_mou rows",$this->db_onedev);
exit;
}
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_doctor count",$this->db_onedev);
exit;
}
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?
GROUP BY M_DoctorID
ORDER BY M_DoctorName ASC";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_onedev);
exit;
}
}
function selectaddressdoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$rows = [];
$query ="SELECT M_DoctorAddressID,
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
FROM
m_doctoraddress
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
//echo $query;
$rows['addressdoctors'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,752 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
F_BillM_MouID,
M_MouID,
IF(F_BillM_MouID = 0, 'Semua',M_MouName) as M_MouName,
F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
IF(F_BillM_MouID = 0, 'Semua',CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y'))) as M_MouDesc
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$mouID = $v['F_BillM_MouID'];
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM t_orderheader
join f_bill on F_BillID = '{$v['F_BillID']}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_PaymentID IS NULL")->row();
$rows[$k]['haveDetail'] = "N";
$rows[$k]['startdate'] = $startdate->startdate;
} else {
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
$rows[$k]['haveDetail'] = "Y";
$rows[$k]['startdate'] = $startdate->startdate;
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query ="SELECT M_MouID, M_MouName, CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillDueDateDay = '{$prm['day']}',
F_BillDueDate = '{$pdate}',
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}',
F_BillCreated = now()
WHERE F_BillID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "SELECT *, IF(F_BillDetailID IS NULL ,'N','Y') as isbill,F_BillNo FROM (select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
SUM(IFNULL(F_PaymentTotal,0)) as bayar,
T_OrderHeaderTotal - SUM(IFNULL(F_PaymentTotal,0)) as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID))
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC) a
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillDetailF_BillID = F_BillID AND F_BillIsActive = 'Y'
WHERE total > 1";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,198 @@
<?php
class Bill extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Bill API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_BillPaymentF_BillID as note_order_id,
F_BillPaymentID as note_id,
F_BillPaymentDate as note_date,
F_BillPaymentNumber as note_number,
GROUP_CONCAT(DISTINCT M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentDetailIsActive as note_active,
'xxx' as tests,
'N' as show_detail
FROM f_bill_payment
JOIN f_bill_payment_detail ON F_BillPaymentDetailF_BillPaymentID = F_BillPaymentID
JOIN m_paymenttype ON F_BillPaymentM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentUserID = M_UserID
WHERE
F_BillPaymentF_BillID = {$orderid}
GROUP BY F_BillPaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
}
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tagihans($orderid){
$sql = " SELECT F_BillID as tagihan_id,
T_OrderHeaderLabNumber as tagihan_number,
JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.patient_fullname')) as pasien,
F_BillDetailTotal as tagihan_total,
F_BillDetailUnpaid as tagihan_tagihan,
0 as tagihan_bayar,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as tagihan_duedate,
F_BillDetailIsActive as tagihan_active,
'N' as show_detail,
F_BillDetailID,
F_BillDetailT_OrderHeaderID
FROM f_bill
JOIN f_bill_detail ON F_BillDetailF_BillID = F_BillID AND F_BillDetailIsActive = 'Y' AND F_BillDetailUnpaid > 0
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
WHERE
F_BillID = {$orderid}
GROUP BY F_BillDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tests($orderid){
$sql = " SELECT F_BillPaymentF_BillID as note_order_id,
F_BillPaymentID as note_id,
F_BillPaymentDate as note_date,
F_BillPaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentDetailIsActive as note_active,
T_OrderHeaderLabNumber,
F_BillDetailTotal,
F_BillPaymentDetailAmount
FROM f_bill_payment
JOIN f_bill_payment_detail ON F_BillPaymentDetailF_BillPaymentID = F_BillPaymentID
LEFT JOIN f_bill ON F_BillPaymentDetailF_BillID = F_BillID
LEFT JOIN f_bill_detail ON F_BillPaymentDetailF_BillDetailID = F_BillDetailID
LEFT JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_paymenttype ON F_BillPaymentM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentDetailUserID = M_UserID
WHERE
F_BillPaymentID = {$orderid}
GROUP BY F_BillPaymentDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$company = $prm["company"];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "(F_BillIsActive = 'Y'AND F_BillTotal > 0 AND F_BillIsLunas = '{$status}' AND (F_BillNo LIKE '%{$search}%' OR F_BillIssueRefNumber LIKE '%{$search}%' OR F_BillPaymentNumber LIKE '%{$search}%') AND M_CompanyName LIKE '%{$company}%')";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN f_bill_payment ON F_BillID = F_BillPaymentF_BillID AND F_BillPaymentIsActive = 'Y'
LEFT JOIN m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
LEFT JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID
LEFT JOIN f_bill_confirm_issue ON F_BillConfirmIssueF_BillID = F_BillID AND F_BillConfirmIssueIsActive = 'Y'
WHERE
$where
AND F_BillConfirmIssueID IS NULL
";
// echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT f_bill.*, f_bill_payment.*,
M_CompanyName,
M_MouName,
IFNULL(F_BillTotal,0) as totalbill,
IFNULL(F_BillTotal - F_BillUnpaid,0) as paid,
IFNULL(F_BillUnpaid,0) as unpaid,
F_BillIsLunas as flaglunas,
GROUP_CONCAT(F_BillPaymentNumber SEPARATOR ', ') as F_BillPaymentNumber,
SUM(F_BillPaymentAmount) as F_BillPaymentAmount,
DATE_FORMAT(F_BillPaymentDate,'%d-%m-%Y') as F_BillPaymentDate,
IFNULL(F_BillIssueRefNumber,'') as F_BillIssueRefNumber,
'' as notes,
'' as tagihans,
IF(F_BillConfirmIssueID IS NULL,'N','Y') as isbillterpusat
FROM f_bill
LEFT JOIN f_bill_payment ON F_BillID = F_BillPaymentF_BillID AND F_BillPaymentIsActive = 'Y'
LEFT JOIN m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
LEFT JOIN f_bill_issue ON F_BillIssueF_BillID = F_BillID
LEFT JOIN f_bill_confirm_issue ON F_BillConfirmIssueF_BillID = F_BillID AND F_BillConfirmIssueIsActive = 'Y'
WHERE
$where
AND F_BillConfirmIssueID IS NULL
GROUP BY F_BillID
ORDER BY F_BillID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['F_BillID']);
$rows[$k]['tagihans'] = $this->add_tagihans($v['F_BillID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,604 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookup_type()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
'N' as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
'' as selected_card,
'' as selected_edc,
'' as selected_account,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'No. Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
$rows[$k]['selected_card'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_edc'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_account'] = array('id'=>0,'name'=>'');
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function selectpaymenttype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_paymenttype
WHERE
M_PaymentTypeIsActive = 'Y'
";
//echo $query;
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectbank(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC
";
//echo $query;
$rows['banks'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectaccount(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
//echo $query;
$rows['accounts'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_banks()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT Nat_BankID as id, Nat_BankCode as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function lookup_accounts()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_BankAccountID as id, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcard(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
if($prm['search'] != ''){
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
if($prm['search'] != ''){
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function pay()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$payments = $prm['payments'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment
(F_BillPaymentF_BillID,F_BillPaymentDate,F_BillPaymentCreated,F_BillPaymentUserID)
VALUES (?,CURDATE(),NOW(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid, $xuserid
)
);
if (!$query) {
$this->sys_error_db("f_bill_payment insert");
exit;
}
$headerid = $this->db_onedev->insert_id();
//echo $headerid;
foreach($payments as $k => $v){
if($v['chex']){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
if($v['code'] == 'CASH'){
$actual = $v['leftvalue'];
$change = $v['rightvalue'];
if($actual > 0){
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
}
else{
$amount = $actual;
}
$sql = "CALL `sp_bill_payment_add_cash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.")";
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_detail cash insert");
exit;
}
}
else{
if(intval($v['leftvalue']) > 0){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
$selected_card = 0;
$selected_edc = 0;
$selected_account = 0;
if($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER'){
$selected_card = $v['selected_card']['id'];
$selected_edc = $v['selected_edc']['id'];
$selected_account = $v['selected_account']['id'];
}
$sql = "CALL `sp_bill_payment_add_noncash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.",".$selected_card.",".$selected_edc.",".$selected_account.")";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("f_bill_payment_detail non cash insert");
exit;
}
}
}
}
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'Nomor Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('types'=>$rows,'data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function paymanual()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$amount = $prm['amount'];
$paymenttype = $prm['paymenttype'];
if($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5){
$card = 0;
$edc = 0;
$account = 0;
}elseif($prm['paymenttype'] == 4){
$card = 0;
$edc = 0;
$account = $prm['account'];
}else{
$card = $prm['card'];
$edc = $prm['edc'];
$account = 0;
}
$voucher = $prm['voucher'];
$bills = $prm['bills'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment
(F_BillPaymentF_BillID,
F_BillPaymentDate,
F_BillPaymentAmount,
F_BillPaymentM_PaymentTypeID,
F_BillPaymentEDCNat_BankID,
F_BillPaymentCardNat_BankID,
F_BillPaymentM_BankAccountID,
F_BillPaymentVoucherNumber,
F_BillPaymentCreated,
F_BillPaymentUserID)
VALUES (?,
CURDATE(),
?,
?,
?,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$amount,
$paymenttype,
$edc,
$card,
$account,
$voucher,
$xuserid
)
);
$headerid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment insert");
exit;
} else{
$sqlbill = "UPDATE f_bill SET
F_BillUnpaid = F_BillUnpaid - $amount,
F_BillIsLunas = IF(F_BillUnpaid = 0,'Y','N')
WHERE F_BillID = $orderid";
$querybill = $this->db_onedev->query($sqlbill);
}
//echo $headerid;
foreach($bills as $k => $v){
if($v['tagihan_bayar'] > 0){
$F_BillDetailID = $v['F_BillDetailID'];
$tagihan_bayar = $v['tagihan_bayar'];
$F_BillDetailT_OrderHeaderID = $v['F_BillDetailT_OrderHeaderID'];
$sql = "INSERT INTO f_bill_payment_detail(
F_BillPaymentDetailF_BillPaymentID,
F_BillPaymentDetailF_BillID,
F_BillPaymentDetailF_BillDetailID,
F_BillPaymentDetailAmount,
F_BillPaymentDetailUserID,
F_BillPaymentDetailCreated,
F_BillPaymentDetailLastUpdated)
VALUES(
$headerid,
$orderid,
$F_BillDetailID,
$tagihan_bayar,
$xuserid,
now(),
now())";
$query = $this->db_onedev->query($sql);
$billpaymentdetailid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_detail cash insert");
exit;
}else{
$sqlbilldetail = "UPDATE f_bill_detail SET
F_BillDetailUnpaid = F_BillDetailUnpaid - $tagihan_bayar
WHERE F_BillDetailID = $F_BillDetailID";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlpayment = "INSERT INTO f_payment
(F_PaymentT_OrderHeaderID,
F_PaymentDate,
F_PaymentTotal,
F_PaymentCreated,
F_PaymentLastUpdated,
F_PaymentM_UserID)
VALUES(
$F_BillDetailT_OrderHeaderID,
now(),
$tagihan_bayar,
now(),
now(),
$xuserid)";
$querypayment = $this->db_onedev->query($sqlpayment);
$paymentid = $this->db_onedev->insert_id();
$sqlpaymentdetail = "INSERT INTO f_paymentdetail
(F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailEDCNat_BankID,
F_PaymentDetailCardNat_BankID,
F_PaymentDetailM_BankAccountID,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES(
$paymentid,
$paymenttype,
$tagihan_bayar,
$tagihan_bayar,
0,
$edc,
$card,
$account,
now(),
now(),
$xuserid)";
//echo $sqlpaymentdetail;
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_detail SET
F_BillPaymentDetailF_PaymentID = $paymentid
WHERE F_BillPaymentDetailID = $billpaymentdetailid";
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
}
}
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function delete_note()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$prmnota = $prm['nota'];
$catatan = $prm['catatan'];
$sql = "UPDATE f_bill_payment SET F_BillPaymentIsActive = 'N', F_BillPaymentNote = '{$catatan}' WHERE F_BillPaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment delete");
exit;
}
$sql = "UPDATE f_bill_payment_detail SET F_BillPaymentDetailIsActive = 'N' WHERE F_BillPaymentDetailF_BillPaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_detail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => array('prm'=>$prm)
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,188 @@
<?php
class Bill extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Bill API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_BillPaymentF_BillID as note_order_id,
F_BillPaymentID as note_id,
F_BillPaymentDate as note_date,
F_BillPaymentNumber as note_number,
GROUP_CONCAT(DISTINCT M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentDetailIsActive as note_active,
'xxx' as tests,
'N' as show_detail
FROM f_bill_payment
JOIN f_bill_payment_detail ON F_BillPaymentDetailF_BillPaymentID = F_BillPaymentID
JOIN m_paymenttype ON F_BillPaymentM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentUserID = M_UserID
WHERE
F_BillPaymentF_BillID = {$orderid}
GROUP BY F_BillPaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
}
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tagihans($orderid){
$sql = " SELECT F_BillID as tagihan_id,
T_OrderHeaderLabNumber as tagihan_number,
F_BillDetailTotal as tagihan_total,
F_BillDetailUnpaid as tagihan_tagihan,
0 as tagihan_bayar,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as tagihan_duedate,
F_BillDetailIsActive as tagihan_active,
'N' as show_detail,
F_BillDetailID,
F_BillDetailT_OrderHeaderID
FROM f_bill
JOIN f_bill_detail ON F_BillDetailF_BillID = F_BillID AND F_BillDetailIsActive = 'Y' AND F_BillDetailUnpaid > 0
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
WHERE
F_BillID = {$orderid}
GROUP BY F_BillDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tests($orderid){
$sql = " SELECT F_BillPaymentF_BillID as note_order_id,
F_BillPaymentID as note_id,
F_BillPaymentDate as note_date,
F_BillPaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentDetailIsActive as note_active,
T_OrderHeaderLabNumber,
F_BillDetailTotal,
F_BillPaymentDetailAmount
FROM f_bill_payment
JOIN f_bill_payment_detail ON F_BillPaymentDetailF_BillPaymentID = F_BillPaymentID
LEFT JOIN f_bill ON F_BillPaymentDetailF_BillID = F_BillID
LEFT JOIN f_bill_detail ON F_BillPaymentDetailF_BillDetailID = F_BillDetailID
LEFT JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_paymenttype ON F_BillPaymentM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentDetailUserID = M_UserID
WHERE
F_BillPaymentID = {$orderid}
GROUP BY F_BillPaymentDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$company = $prm["company"];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "(F_BillIsActive = 'Y'AND F_BillTotal > 0 AND F_BillIsLunas = '{$status}' AND (F_BillNo LIKE '%{$search}%' OR F_BillPaymentNumber LIKE '%{$search}%') AND M_CompanyName LIKE '%{$company}%')";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN f_bill_payment ON F_BillID = F_BillPaymentF_BillID AND F_BillPaymentIsActive = 'Y'
LEFT JOIN m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
WHERE
$where";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT f_bill.*, f_bill_payment.*,
M_CompanyName,
M_MouName,
IFNULL(F_BillTotal,0) as totalbill,
IFNULL(F_BillTotal - F_BillUnpaid,0) as paid,
IFNULL(F_BillUnpaid,0) as unpaid,
F_BillIsLunas as flaglunas,
GROUP_CONCAT(F_BillPaymentNumber SEPARATOR ', ') as F_BillPaymentNumber,
SUM(F_BillPaymentAmount) as F_BillPaymentAmount,
DATE_FORMAT(F_BillPaymentDate,'%d-%m-%Y') as F_BillPaymentDate,
'' as notes,
'' as tagihans
FROM f_bill
LEFT JOIN f_bill_payment ON F_BillID = F_BillPaymentF_BillID AND F_BillPaymentIsActive = 'Y'
LEFT JOIN m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
WHERE
$where
GROUP BY F_BillID
ORDER BY F_BillID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['F_BillID']);
$rows[$k]['tagihans'] = $this->add_tagihans($v['F_BillID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,604 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookup_type()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
'N' as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
'' as selected_card,
'' as selected_edc,
'' as selected_account,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'No. Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
$rows[$k]['selected_card'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_edc'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_account'] = array('id'=>0,'name'=>'');
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function selectpaymenttype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_paymenttype
WHERE
M_PaymentTypeIsActive = 'Y'
";
//echo $query;
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectbank(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC
";
//echo $query;
$rows['banks'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectaccount(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
//echo $query;
$rows['accounts'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_banks()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT Nat_BankID as id, Nat_BankCode as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function lookup_accounts()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_BankAccountID as id, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcard(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
if($prm['search'] != ''){
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
if($prm['search'] != ''){
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function pay()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$payments = $prm['payments'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment
(F_BillPaymentF_BillID,F_BillPaymentDate,F_BillPaymentCreated,F_BillPaymentUserID)
VALUES (?,CURDATE(),NOW(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid, $xuserid
)
);
if (!$query) {
$this->sys_error_db("f_bill_payment insert");
exit;
}
$headerid = $this->db_onedev->insert_id();
//echo $headerid;
foreach($payments as $k => $v){
if($v['chex']){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
if($v['code'] == 'CASH'){
$actual = $v['leftvalue'];
$change = $v['rightvalue'];
if($actual > 0){
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
}
else{
$amount = $actual;
}
$sql = "CALL `sp_bill_payment_add_cash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.")";
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_detail cash insert");
exit;
}
}
else{
if(intval($v['leftvalue']) > 0){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
$selected_card = 0;
$selected_edc = 0;
$selected_account = 0;
if($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER'){
$selected_card = $v['selected_card']['id'];
$selected_edc = $v['selected_edc']['id'];
$selected_account = $v['selected_account']['id'];
}
$sql = "CALL `sp_bill_payment_add_noncash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.",".$selected_card.",".$selected_edc.",".$selected_account.")";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("f_bill_payment_detail non cash insert");
exit;
}
}
}
}
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'Nomor Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('types'=>$rows,'data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function paymanual()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$amount = $prm['amount'];
$paymenttype = $prm['paymenttype'];
if($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5){
$card = 0;
$edc = 0;
$account = 0;
}elseif($prm['paymenttype'] == 4){
$card = 0;
$edc = 0;
$account = $prm['account'];
}else{
$card = $prm['card'];
$edc = $prm['edc'];
$account = 0;
}
$voucher = $prm['voucher'];
$bills = $prm['bills'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment
(F_BillPaymentF_BillID,
F_BillPaymentDate,
F_BillPaymentAmount,
F_BillPaymentM_PaymentTypeID,
F_BillPaymentEDCNat_BankID,
F_BillPaymentCardNat_BankID,
F_BillPaymentM_BankAccountID,
F_BillPaymentVoucherNumber,
F_BillPaymentCreated,
F_BillPaymentUserID)
VALUES (?,
CURDATE(),
?,
?,
?,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$amount,
$paymenttype,
$edc,
$card,
$account,
$voucher,
$xuserid
)
);
$headerid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment insert");
exit;
} else{
$sqlbill = "UPDATE f_bill SET
F_BillUnpaid = F_BillUnpaid - $amount,
F_BillIsLunas = IF(F_BillUnpaid = 0,'Y','N')
WHERE F_BillID = $orderid";
$querybill = $this->db_onedev->query($sqlbill);
}
//echo $headerid;
foreach($bills as $k => $v){
if($v['tagihan_bayar'] > 0){
$F_BillDetailID = $v['F_BillDetailID'];
$tagihan_bayar = $v['tagihan_bayar'];
$F_BillDetailT_OrderHeaderID = $v['F_BillDetailT_OrderHeaderID'];
$sql = "INSERT INTO f_bill_payment_detail(
F_BillPaymentDetailF_BillPaymentID,
F_BillPaymentDetailF_BillID,
F_BillPaymentDetailF_BillDetailID,
F_BillPaymentDetailAmount,
F_BillPaymentDetailUserID,
F_BillPaymentDetailCreated,
F_BillPaymentDetailLastUpdated)
VALUES(
$headerid,
$orderid,
$F_BillDetailID,
$tagihan_bayar,
$xuserid,
now(),
now())";
$query = $this->db_onedev->query($sql);
$billpaymentdetailid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_detail cash insert");
exit;
}else{
$sqlbilldetail = "UPDATE f_bill_detail SET
F_BillDetailUnpaid = F_BillDetailUnpaid - $tagihan_bayar
WHERE F_BillDetailID = $F_BillDetailID";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlpayment = "INSERT INTO f_payment
(F_PaymentT_OrderHeaderID,
F_PaymentDate,
F_PaymentTotal,
F_PaymentCreated,
F_PaymentLastUpdated,
F_PaymentM_UserID)
VALUES(
$F_BillDetailT_OrderHeaderID,
now(),
$tagihan_bayar,
now(),
now(),
$xuserid)";
$querypayment = $this->db_onedev->query($sqlpayment);
$paymentid = $this->db_onedev->insert_id();
$sqlpaymentdetail = "INSERT INTO f_paymentdetail
(F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailEDCNat_BankID,
F_PaymentDetailCardNat_BankID,
F_PaymentDetailM_BankAccountID,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES(
$paymentid,
$paymenttype,
$tagihan_bayar,
$tagihan_bayar,
0,
$edc,
$card,
$account,
now(),
now(),
$xuserid)";
//echo $sqlpaymentdetail;
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_detail SET
F_BillPaymentDetailF_PaymentID = $paymentid
WHERE F_BillPaymentDetailID = $billpaymentdetailid";
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
}
}
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function delete_note()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$prmnota = $prm['nota'];
$catatan = $prm['catatan'];
$sql = "UPDATE f_bill_payment SET F_BillPaymentIsActive = 'N', F_BillPaymentNote = '{$catatan}' WHERE F_BillPaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment delete");
exit;
}
$sql = "UPDATE f_bill_payment_detail SET F_BillPaymentDetailIsActive = 'N' WHERE F_BillPaymentDetailF_BillPaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_detail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => array('prm'=>$prm)
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,231 @@
<?php
class Bill extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Bill API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_BillPaymentPusatF_BillIssuePusatID as note_order_id,
F_BillPaymentPusatID as note_id,
F_BillPaymentPusatDate as note_date,
F_BillPaymentPusatNumber as note_number,
GROUP_CONCAT(DISTINCT M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentPusatDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentPusatDetailIsActive as note_active,
'xxx' as tests,
'N' as show_detail
FROM f_bill_payment_pusat
JOIN f_bill_payment_pusat_detail ON F_BillPaymentPusatDetailF_BillPaymentPusatID = F_BillPaymentPusatID
JOIN m_paymenttype ON F_BillPaymentPusatM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentPusatUserID = M_UserID
WHERE
F_BillPaymentPusatF_BillIssuePusatID = {$orderid}
GROUP BY F_BillPaymentPusatID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
}
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tagihans($orderid){
$sql = " SELECT F_BillIssuePusatID as tagihan_id,
F_BillNo as tagihan_number,
a.M_BranchName as pasien,
F_BillIssuePusatDetailTotal as tagihan_total,
F_BillIssuePusatDetailUnpaid as tagihan_tagihan,
0 as tagihan_bayar,
DATE_FORMAT(F_BillIssuePusatDueDate,'%d-%m-%Y') as tagihan_duedate,
F_BillIssuePusatDetailIsActive as tagihan_active,
'N' as show_detail,
F_BillIssuePusatDetailID,
F_BillIssuePusatDetailF_BillID,
F_BillIssuePusatDetailM_BranchID,
a.M_BranchID
FROM f_bill_issue_pusat
JOIN f_bill_issue_pusat_detail ON F_BillIssuePusatDetailF_BillIssuePusatID = F_BillIssuePusatID AND F_BillIssuePusatDetailIsActive = 'Y' AND F_BillIssuePusatDetailUnpaid > 0
JOIN f_bill_titip ON F_BillIssuePusatDetailF_BillID = F_BillID
JOIN m_branch a ON a.M_BranchID = F_BillIssuePusatDetailM_BranchID
WHERE
F_BillIssuePusatID = {$orderid}
GROUP BY F_BillIssuePusatDetailID";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_orders($orderid){
$sql = " SELECT CONCAT(a.M_BranchCode,F_BillDetailID) as tagihan_id,
T_OrderHeaderLabNumber as tagihan_number,
FullPatientName as pasien,
F_BillDetailTotal as tagihan_total,
F_BillDetailUnpaid as tagihan_tagihan,
0 as tagihan_bayar,
DATE_FORMAT(F_BillIssuePusatDueDate,'%d-%m-%Y') as tagihan_duedate,
F_BillIssuePusatDetailIsActive as tagihan_active,
'N' as show_detail,
F_BillIssuePusatDetailID,
F_BillIssuePusatDetailF_BillID,
F_BillIssuePusatDetailM_BranchID,
F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
a.M_BranchID,
F_BillDetailID
FROM f_bill_issue_pusat
JOIN f_bill_issue_pusat_detail ON F_BillIssuePusatDetailF_BillIssuePusatID = F_BillIssuePusatID AND F_BillIssuePusatDetailIsActive = 'Y' AND F_BillIssuePusatDetailUnpaid > 0
JOIN f_bill_titip_detail t ON F_BillIssuePusatDetailF_BillID = F_BillDetailF_BillID AND F_BillIssuePusatDetailM_BranchID = t.M_BranchID
JOIN m_branch a ON a.M_BranchID = F_BillIssuePusatDetailM_BranchID
WHERE
F_BillIssuePusatID = {$orderid} AND
F_BillDetailUnpaid > 0";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tests($orderid){
$sql = " SELECT F_BillPaymentPusatF_BillIssuePusatID as note_order_id,
F_BillPaymentPusatID as note_id,
F_BillPaymentPusatDate as note_date,
F_BillPaymentPusatNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentPusatDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentPusatDetailIsActive as note_active,
F_BillNo,
F_BillIssuePusatDetailTotal,
F_BillPaymentPusatDetailAmount
FROM f_bill_payment_pusat
JOIN f_bill_payment_pusat_detail ON F_BillPaymentPusatDetailF_BillPaymentPusatID = F_BillPaymentPusatID
LEFT JOIN f_bill_issue_pusat ON F_BillPaymentPusatDetailF_BillIssuePusatID = F_BillIssuePusatID
LEFT JOIN f_bill_issue_pusat_detail ON F_BillPaymentPusatDetailF_BillIssuePusatDetailID = F_BillIssuePusatDetailID
LEFT JOIN f_bill ON F_BillIssuePusatDetailF_BillID = F_BillID
JOIN m_paymenttype ON F_BillPaymentPusatM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentPusatDetailUserID = M_UserID
WHERE
F_BillPaymentPusatID = {$orderid}
GROUP BY F_BillPaymentPusatDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$company = $prm["company"];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "(F_BillIssuePusatIsActive = 'Y'AND F_BillIssuePusatTotal > 0 AND F_BillIssuePusatIsLunas = '{$status}' AND (F_BillIssuePusatNumber LIKE '%{$search}%' OR F_BillIssuePusatRefNumber LIKE '%{$search}%' OR F_BillPaymentPusatNumber LIKE '%{$search}%') AND M_CompanyName LIKE '%{$company}%')";
$sql = " SELECT count(*) as total
FROM f_bill_issue_pusat
LEFT JOIN f_bill_payment_pusat ON F_BillIssuePusatID = F_BillPaymentPusatF_BillIssuePusatID AND F_BillPaymentPusatIsActive = 'Y'
LEFT JOIN m_company ON F_BillIssuePusatM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillIssuePusatM_MouID = M_MouID
WHERE
$where";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("f_bill_issue_pusat count", $this->db_onedev);
exit;
}
$sql = "SELECT f_bill_issue_pusat.*, f_bill_payment_pusat.*,
M_CompanyName,
M_MouName,
IFNULL(F_BillIssuePusatTotal,0) as totalbill,
IFNULL(F_BillIssuePusatTotal - F_BillIssuePusatUnpaid,0) as paid,
IFNULL(F_BillIssuePusatUnpaid,0) as unpaid,
F_BillIssuePusatIsLunas as flaglunas,
GROUP_CONCAT(F_BillPaymentPusatNumber SEPARATOR ', ') as F_BillPaymentPusatNumber,
SUM(F_BillPaymentPusatAmount) as F_BillPaymentPusatAmount,
DATE_FORMAT(F_BillPaymentPusatDate,'%d-%m-%Y') as F_BillPaymentPusatDate,
IFNULL(F_BillIssuePusatRefNumber,'') as F_BillIssuePusatRefNumber,
'' as notes,
'' as tagihans,
'' as orders
FROM f_bill_issue_pusat
LEFT JOIN f_bill_payment_pusat ON F_BillIssuePusatID = F_BillPaymentPusatF_BillIssuePusatID AND F_BillPaymentPusatIsActive = 'Y'
LEFT JOIN m_company ON F_BillIssuePusatM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillIssuePusatM_MouID = M_MouID
WHERE
$where
GROUP BY F_BillIssuePusatID
ORDER BY F_BillIssuePusatID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['F_BillIssuePusatID']);
$rows[$k]['tagihans'] = $this->add_tagihans($v['F_BillIssuePusatID']);
$rows[$k]['orders'] = $this->add_orders($v['F_BillIssuePusatID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,875 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookup_type()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
'N' as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
'' as selected_card,
'' as selected_edc,
'' as selected_account,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'No. Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
$rows[$k]['selected_card'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_edc'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_account'] = array('id'=>0,'name'=>'');
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function selectpaymenttype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_paymenttype
WHERE
M_PaymentTypeIsActive = 'Y'
";
//echo $query;
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectbank(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC
";
//echo $query;
$rows['banks'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectaccount(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
//echo $query;
$rows['accounts'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_banks()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT Nat_BankID as id, Nat_BankCode as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function lookup_accounts()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_BankAccountID as id, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcard(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
if($prm['search'] != ''){
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
if($prm['search'] != ''){
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function pay()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$payments = $prm['payments'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment_pusat
(F_BillPaymentPusatF_BillIssuePusatID,F_BillPaymentPusatDate,F_BillPaymentPusatCreated,F_BillPaymentPusatUserID)
VALUES (?,CURDATE(),NOW(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid, $xuserid
)
);
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat insert");
exit;
}
$headerid = $this->db_onedev->insert_id();
//echo $headerid;
foreach($payments as $k => $v){
if($v['chex']){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
if($v['code'] == 'CASH'){
$actual = $v['leftvalue'];
$change = $v['rightvalue'];
if($actual > 0){
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
}
else{
$amount = $actual;
}
$sql = "CALL `sp_bill_payment_add_cash_pusat`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.")";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail cash insert");
exit;
}
}
else{
if(intval($v['leftvalue']) > 0){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
$selected_card = 0;
$selected_edc = 0;
$selected_account = 0;
if($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER'){
$selected_card = $v['selected_card']['id'];
$selected_edc = $v['selected_edc']['id'];
$selected_account = $v['selected_account']['id'];
}
$sql = "CALL `sp_bill_payment_add_noncash_pusat`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.",".$selected_card.",".$selected_edc.",".$selected_account.")";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail non cash insert");
exit;
}
}
}
}
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'Nomor Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentPusatID as idx, F_BillPaymentPusatNumber as numberx FROM f_bill_payment_pusat WHERE F_BillPaymentPusatID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('types'=>$rows,'data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function paymanual()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$amount = $prm['amount'];
$paymenttype = $prm['paymenttype'];
if($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5){
$card = 0;
$edc = 0;
$account = 0;
}elseif($prm['paymenttype'] == 4){
$card = 0;
$edc = 0;
$account = $prm['account'];
}else{
$card = $prm['card'];
$edc = $prm['edc'];
$account = 0;
}
$voucher = $prm['voucher'];
$bills = $prm['bills'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment_pusat
(F_BillPaymentPusatF_BillIssuePusatID,
F_BillPaymentPusatDate,
F_BillPaymentPusatAmount,
F_BillPaymentPusatM_PaymentTypeID,
F_BillPaymentPusatEDCNat_BankID,
F_BillPaymentPusatCardNat_BankID,
F_BillPaymentPusatM_BankAccountID,
F_BillPaymentPusatVoucherNumber,
F_BillPaymentPusatCreated,
F_BillPaymentPusatUserID)
VALUES (?,
CURDATE(),
?,
?,
?,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$amount,
$paymenttype,
$edc,
$card,
$account,
$voucher,
$xuserid
)
);
$headerid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat insert");
exit;
} else{
$sqlbill = "UPDATE f_bill_issue_pusat SET
F_BillIssuePusatUnpaid = F_BillIssuePusatUnpaid - $amount,
F_BillIssuePusatIsLunas = IF(F_BillIssuePusatUnpaid = 0,'Y','N')
WHERE F_BillIssuePusatID = $orderid";
$querybill = $this->db_onedev->query($sqlbill);
}
//echo $headerid;
foreach($bills as $k => $v){
if($v['tagihan_bayar'] > 0){
$F_BillIssuePusatDetailID = $v['F_BillIssuePusatDetailID'];
$tagihan_bayar = $v['tagihan_bayar'];
$F_BillIssuePusatDetailF_BillID = $v['F_BillIssuePusatDetailF_BillID'];
$F_BillIssuePusatDetailM_BranchID = $v['F_BillIssuePusatDetailM_BranchID'];
$sql = "INSERT INTO f_bill_payment_pusat_detail(
F_BillPaymentPusatDetailF_BillPaymentPusatID,
F_BillPaymentPusatDetailF_BillIssuePusatID,
F_BillPaymentPusatDetailF_BillIssuePusatDetailID,
F_BillPaymentPusatDetailAmount,
F_BillPaymentPusatDetailUserID,
F_BillPaymentPusatDetailCreated,
F_BillPaymentPusatDetailLastUpdated)
VALUES(
$headerid,
$orderid,
$F_BillIssuePusatDetailID,
$tagihan_bayar,
$xuserid,
now(),
now())";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$billpaymentdetailid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail cash insert");
exit;
}else{
$sqlbilldetail = "UPDATE f_bill_issue_pusat_detail SET
F_BillIssuePusatDetailUnpaid = F_BillIssuePusatDetailUnpaid - $tagihan_bayar
WHERE F_BillIssuePusatDetailID = $F_BillIssuePusatDetailID";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlpayment = "INSERT INTO f_payment_pusat
(F_PaymentPusatF_BillID,
F_PaymentPusatM_BranchID,
F_PaymentPusatDate,
F_PaymentPusatTotal,
F_PaymentPusatCreated,
F_PaymentPusatLastUpdated,
F_PaymentPusatM_UserID)
VALUES(
$F_BillIssuePusatDetailF_BillID,
$F_BillIssuePusatDetailM_BranchID,
now(),
$tagihan_bayar,
now(),
now(),
$xuserid)";
$querypayment = $this->db_onedev->query($sqlpayment);
$paymentid = $this->db_onedev->insert_id();
$sqlpaymentdetail = "INSERT INTO f_payment_pusatdetail
(F_PaymentPusatDetailF_PaymentPusatID,
F_PaymentPusatDetailM_PaymentTypeID,
F_PaymentPusatDetailAmount,
F_PaymentPusatDetailActual,
F_PaymentPusatDetailChange,
F_PaymentPusatDetailEDCNat_BankID,
F_PaymentPusatDetailCardNat_BankID,
F_PaymentPusatDetailM_BankAccountID,
F_PaymentPusatDetailCreated,
F_PaymentPusatDetailLastUpdated,
F_PaymentPusatDetailUserID)
VALUES(
$paymentid,
$paymenttype,
$tagihan_bayar,
$tagihan_bayar,
0,
$edc,
$card,
$account,
now(),
now(),
$xuserid)";
//echo $sqlpaymentdetail;
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_pusat_detail SET
F_BillPaymentPusatDetailF_PaymentPusatID = $paymentid
WHERE F_BillPaymentPusatDetailID = $billpaymentdetailid";
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
}
}
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentPusatID as idx, F_BillPaymentPusatNumber as numberx FROM f_bill_payment_pusat WHERE F_BillPaymentPusatID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function paymanualorder()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$amount = $prm['amount'];
$paymenttype = $prm['paymenttype'];
if($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5){
$card = 0;
$edc = 0;
$account = 0;
}elseif($prm['paymenttype'] == 4){
$card = 0;
$edc = 0;
$account = $prm['account'];
}else{
$card = $prm['card'];
$edc = $prm['edc'];
$account = 0;
}
$voucher = $prm['voucher'];
$bills = $prm['bills'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment_pusat
(F_BillPaymentPusatF_BillIssuePusatID,
F_BillPaymentPusatDate,
F_BillPaymentPusatAmount,
F_BillPaymentPusatM_PaymentTypeID,
F_BillPaymentPusatEDCNat_BankID,
F_BillPaymentPusatCardNat_BankID,
F_BillPaymentPusatM_BankAccountID,
F_BillPaymentPusatVoucherNumber,
F_BillPaymentPusatCreated,
F_BillPaymentPusatUserID)
VALUES (?,
CURDATE(),
?,
?,
?,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$amount,
$paymenttype,
$edc,
$card,
$account,
$voucher,
$xuserid
)
);
$headerid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat insert");
exit;
} else{
$sqlbill = "UPDATE f_bill_issue_pusat SET
F_BillIssuePusatUnpaid = F_BillIssuePusatUnpaid - $amount,
F_BillIssuePusatIsLunas = IF(F_BillIssuePusatUnpaid = 0,'Y','N')
WHERE F_BillIssuePusatID = $orderid";
$querybill = $this->db_onedev->query($sqlbill);
}
//echo $headerid;
foreach($bills as $k => $v){
if($v['tagihan_bayar'] > 0){
$F_BillIssuePusatDetailID = $v['F_BillIssuePusatDetailID'];
$branchid = $v['M_BranchID'];
$billid = $v['F_BillDetailF_BillID'];
$torderid = $v['F_BillDetailT_OrderHeaderID'];
$tagihan_bayar = $v['tagihan_bayar'];
$detailid = $v['F_BillDetailID'];
$F_BillIssuePusatDetailF_BillID = $v['F_BillIssuePusatDetailF_BillID'];
$F_BillIssuePusatDetailM_BranchID = $v['F_BillIssuePusatDetailM_BranchID'];
$sql = "INSERT INTO f_bill_payment_pusat_order(
F_BillPaymentPusatOrderF_BillPaymentPusatID,
F_BillPaymentPusatOrderF_BillIssuePusatDetailID,
F_BillPaymentPusatOrderM_BranchID,
F_BillPaymentPusatOrderF_BillID,
F_BillPaymentPusatOrderT_OrderHeaderID,
F_BillPaymentPusatOrderAmount,
F_BillPaymentPusatOrderUserID,
F_BillPaymentPusatOrderCreated,
F_BillPaymentPusatOrderLastUpdated)
VALUES(
$headerid,
$F_BillIssuePusatDetailID,
$branchid,
$billid,
$torderid,
$tagihan_bayar,
$xuserid,
now(),
now())";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$billpaymentdetailid = $this->db_onedev->insert_id();
$sqlupdate = "UPDATE f_bill_titip_detail
SET F_BillDetailUnpaid = F_BillDetailUnpaid-$tagihan_bayar,
F_BillDetailIsLunas = IF(F_BillDetailUnpaid = 0,'Y','N')
WHERE
M_BranchID = $branchid AND
F_BillDetailF_BillID = $billid AND
F_BillDetailT_OrderHeaderID = $torderid";
$queryupdate = $this->db_onedev->query($sqlupdate);
$sqllog = "INSERT INTO log_payment_titip_detail(
Log_PaymentTitipDetailF_BillPaymentPusatID,
Log_PaymentTitipDetailF_BillDetailID,
Log_PaymentTitipDetailM_BranchID,
Log_PaymentTitipDetailF_BillDetailF_BillID,
Log_PaymentTitipDetailT_OrderHeaderID,
Log_PaymentTitipDetailAmount,
Log_PaymentTitipDetailUserID)
VALUES(
$headerid,
$detailid,
$branchid,
$billid,
$torderid,
$tagihan_bayar,
$xuserid)";
$querylog = $this->db_onedev->query($sqllog);
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail cash insert");
exit;
}
}
}
$sql = "SELECT F_BillPaymentPusatOrderF_BillPaymentPusatID,
F_BillPaymentPusatOrderF_BillIssuePusatDetailID,
F_BillIssuePusatDetailF_BillIssuePusatID,
F_BillPaymentPusatOrderM_BranchID,
F_BillPaymentPusatOrderF_BillID,
F_BillPaymentPusatOrderT_OrderHeaderID,
SUM(F_BillPaymentPusatOrderAmount) as amount
FROM f_bill_payment_pusat_order
JOIN f_bill_issue_pusat_detail ON F_BillIssuePusatDetailID = F_BillPaymentPusatOrderF_BillIssuePusatDetailID
WHERE F_BillPaymentPusatOrderF_BillPaymentPusatID = $headerid
GROUP BY F_BillIssuePusatDetailID
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$F_BillIssuePusatDetailID = $v['F_BillPaymentPusatOrderF_BillIssuePusatDetailID'];
$tagihan_bayar = $v['amount'];
$F_BillIssuePusatDetailF_BillID = $v['F_BillPaymentPusatOrderF_BillID'];
$F_BillIssuePusatDetailM_BranchID = $v['F_BillPaymentPusatOrderM_BranchID'];
$sql = "INSERT INTO f_bill_payment_pusat_detail(
F_BillPaymentPusatDetailF_BillPaymentPusatID,
F_BillPaymentPusatDetailF_BillIssuePusatID,
F_BillPaymentPusatDetailF_BillIssuePusatDetailID,
F_BillPaymentPusatDetailAmount,
F_BillPaymentPusatDetailUserID,
F_BillPaymentPusatDetailCreated,
F_BillPaymentPusatDetailLastUpdated,
F_BillPaymentPusatDetailIsByOrder)
VALUES(
$headerid,
$orderid,
$F_BillIssuePusatDetailID,
$tagihan_bayar,
$xuserid,
now(),
now(),
'Y')";
$query = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$billpaymentdetailid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail cash insert");
exit;
}else{
$sqlbilldetail = "UPDATE f_bill_issue_pusat_detail SET
F_BillIssuePusatDetailUnpaid = F_BillIssuePusatDetailUnpaid - $tagihan_bayar
WHERE F_BillIssuePusatDetailID = $F_BillIssuePusatDetailID";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlbilldetail = "UPDATE log_payment_titip_detail SET
Log_PaymentTitipDetailF_BillPaymentPusatDetailID = $billpaymentdetailid
WHERE Log_PaymentTitipDetailM_BranchID = $F_BillIssuePusatDetailM_BranchID
AND Log_PaymentTitipDetailF_BillDetailF_BillID = $F_BillIssuePusatDetailF_BillID
AND Log_PaymentTitipDetailF_BillPaymentPusatID = $headerid";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlpayment = "INSERT INTO f_payment_pusat
(F_PaymentPusatF_BillID,
F_PaymentPusatM_BranchID,
F_PaymentPusatDate,
F_PaymentPusatTotal,
F_PaymentPusatCreated,
F_PaymentPusatLastUpdated,
F_PaymentPusatM_UserID)
VALUES(
$F_BillIssuePusatDetailF_BillID,
$F_BillIssuePusatDetailM_BranchID,
now(),
$tagihan_bayar,
now(),
now(),
$xuserid)";
$querypayment = $this->db_onedev->query($sqlpayment);
$paymentid = $this->db_onedev->insert_id();
$sqlpaymentdetail = "INSERT INTO f_payment_pusatdetail
(F_PaymentPusatDetailF_PaymentPusatID,
F_PaymentPusatDetailM_PaymentTypeID,
F_PaymentPusatDetailAmount,
F_PaymentPusatDetailActual,
F_PaymentPusatDetailChange,
F_PaymentPusatDetailEDCNat_BankID,
F_PaymentPusatDetailCardNat_BankID,
F_PaymentPusatDetailM_BankAccountID,
F_PaymentPusatDetailCreated,
F_PaymentPusatDetailLastUpdated,
F_PaymentPusatDetailUserID)
VALUES(
$paymentid,
$paymenttype,
$tagihan_bayar,
$tagihan_bayar,
0,
$edc,
$card,
$account,
now(),
now(),
$xuserid)";
//echo $sqlpaymentdetail;
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_pusat_detail SET
F_BillPaymentPusatDetailF_PaymentPusatID = $paymentid
WHERE F_BillPaymentPusatDetailID = $billpaymentdetailid";
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
}
}
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentPusatID as idx, F_BillPaymentPusatNumber as numberx FROM f_bill_payment_pusat WHERE F_BillPaymentPusatID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function delete_note()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$prmnota = $prm['nota'];
$catatan = $prm['catatan'];
$sql = "UPDATE f_bill_payment_pusat SET F_BillPaymentPusatIsActive = 'N', F_BillPaymentPusatNote = '{$catatan}' WHERE F_BillPaymentPusatID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat delete");
exit;
}
$sql = "UPDATE f_bill_payment_pusat_detail SET F_BillPaymentPusatDetailIsActive = 'N' WHERE F_BillPaymentPusatDetailF_BillPaymentPusatID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => array('prm'=>$prm)
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,189 @@
<?php
class Realpayment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function paymanual()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$amount = $prm['amount'];
$paymenttype = $prm['paymenttype'];
if($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5){
$card = 0;
$edc = 0;
$account = 0;
}elseif($prm['paymenttype'] == 4){
$card = 0;
$edc = 0;
$account = $prm['account'];
}else{
$card = $prm['card'];
$edc = $prm['edc'];
$account = 0;
}
$voucher = $prm['voucher'];
$bills = $prm['bills'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment
(F_BillPaymentF_BillID,
F_BillPaymentDate,
F_BillPaymentAmount,
F_BillPaymentM_PaymentTypeID,
F_BillPaymentEDCNat_BankID,
F_BillPaymentCardNat_BankID,
F_BillPaymentM_BankAccountID,
F_BillPaymentVoucherNumber,
F_BillPaymentCreated,
F_BillPaymentUserID)
VALUES (?,
CURDATE(),
?,
?,
?,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$amount,
$paymenttype,
$edc,
$card,
$account,
$voucher,
$xuserid
)
);
$headerid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment insert");
exit;
} else{
$sqlbill = "UPDATE f_bill SET
F_BillUnpaid = F_BillUnpaid - $amount,
F_BillIsLunas = IF(F_BillUnpaid = 0,'Y','N')
WHERE F_BillID = $orderid";
$querybill = $this->db_onedev->query($sqlbill);
}
//echo $headerid;
foreach($bills as $k => $v){
if($v['tagihan_bayar'] > 0){
$F_BillDetailID = $v['F_BillDetailID'];
$tagihan_bayar = $v['tagihan_bayar'];
$F_BillDetailT_OrderHeaderID = $v['F_BillDetailT_OrderHeaderID'];
$sql = "INSERT INTO f_bill_payment_detail(
F_BillPaymentDetailF_BillPaymentID,
F_BillPaymentDetailF_BillID,
F_BillPaymentDetailF_BillDetailID,
F_BillPaymentDetailAmount,
F_BillPaymentDetailUserID,
F_BillPaymentDetailCreated,
F_BillPaymentDetailLastUpdated)
VALUES(
$headerid,
$orderid,
$F_BillDetailID,
$tagihan_bayar,
$xuserid,
now(),
now())";
$query = $this->db_onedev->query($sql);
$billpaymentdetailid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_detail cash insert");
exit;
}else{
$sqlbilldetail = "UPDATE f_bill_detail SET
F_BillDetailUnpaid = F_BillDetailUnpaid - $tagihan_bayar
WHERE F_BillDetailID = $F_BillDetailID";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlpayment = "INSERT INTO f_payment
(F_PaymentT_OrderHeaderID,
F_PaymentDate,
F_PaymentTotal,
F_PaymentCreated,
F_PaymentLastUpdated,
F_PaymentM_UserID)
VALUES(
$F_BillDetailT_OrderHeaderID,
now(),
$tagihan_bayar,
now(),
now(),
$xuserid)";
$querypayment = $this->db_onedev->query($sqlpayment);
$paymentid = $this->db_onedev->insert_id();
$sqlpaymentdetail = "INSERT INTO f_paymentdetail
(F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailEDCNat_BankID,
F_PaymentDetailCardNat_BankID,
F_PaymentDetailM_BankAccountID,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES(
$paymentid,
$paymenttype,
$tagihan_bayar,
$tagihan_bayar,
0,
$edc,
$card,
$account,
now(),
now(),
$xuserid)";
//echo $sqlpaymentdetail;
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_detail SET
F_BillPaymentDetailF_PaymentID = $paymentid
WHERE F_BillPaymentDetailID = $billpaymentdetailid";
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
}
}
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,194 @@
<?php
class Bill extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Bill API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_BillPaymentPusatF_BillIssuePusatID as note_order_id,
F_BillPaymentPusatID as note_id,
F_BillPaymentPusatDate as note_date,
F_BillPaymentPusatNumber as note_number,
GROUP_CONCAT(DISTINCT M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentPusatDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentPusatDetailIsActive as note_active,
'xxx' as tests,
'N' as show_detail
FROM f_bill_payment_pusat
JOIN f_bill_payment_pusat_detail ON F_BillPaymentPusatDetailF_BillPaymentPusatID = F_BillPaymentPusatID
JOIN m_paymenttype ON F_BillPaymentPusatM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentPusatUserID = M_UserID
WHERE
F_BillPaymentPusatF_BillIssuePusatID = {$orderid}
GROUP BY F_BillPaymentPusatID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
}
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tagihans($orderid){
$sql = " SELECT F_BillIssuePusatID as tagihan_id,
F_BillNo as tagihan_number,
a.M_BranchName as pasien,
F_BillIssuePusatDetailTotal as tagihan_total,
F_BillIssuePusatDetailUnpaid as tagihan_tagihan,
0 as tagihan_bayar,
DATE_FORMAT(F_BillIssuePusatDueDate,'%d-%m-%Y') as tagihan_duedate,
F_BillIssuePusatDetailIsActive as tagihan_active,
'N' as show_detail,
F_BillIssuePusatDetailID,
F_BillIssuePusatDetailF_BillID,
F_BillIssuePusatDetailM_BranchID,
a.M_BranchID
FROM f_bill_issue_pusat
JOIN f_bill_issue_pusat_detail ON F_BillIssuePusatDetailF_BillIssuePusatID = F_BillIssuePusatID AND F_BillIssuePusatDetailIsActive = 'Y' AND F_BillIssuePusatDetailUnpaid > 0
JOIN f_bill_titip ON F_BillIssuePusatDetailF_BillID = F_BillID
JOIN m_branch a ON a.M_BranchID = F_BillIssuePusatDetailM_BranchID
WHERE
F_BillIssuePusatID = {$orderid}
GROUP BY F_BillIssuePusatDetailID";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tests($orderid){
$sql = " SELECT F_BillPaymentPusatF_BillIssuePusatID as note_order_id,
F_BillPaymentPusatID as note_id,
F_BillPaymentPusatDate as note_date,
F_BillPaymentPusatNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentPusatDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentPusatDetailIsActive as note_active,
F_BillNo,
F_BillIssuePusatDetailTotal,
F_BillPaymentPusatDetailAmount
FROM f_bill_payment_pusat
JOIN f_bill_payment_pusat_detail ON F_BillPaymentPusatDetailF_BillPaymentPusatID = F_BillPaymentPusatID
LEFT JOIN f_bill_issue_pusat ON F_BillPaymentPusatDetailF_BillIssuePusatID = F_BillIssuePusatID
LEFT JOIN f_bill_issue_pusat_detail ON F_BillPaymentPusatDetailF_BillIssuePusatDetailID = F_BillIssuePusatDetailID
LEFT JOIN f_bill ON F_BillIssuePusatDetailF_BillID = F_BillID
JOIN m_paymenttype ON F_BillPaymentPusatM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentPusatDetailUserID = M_UserID
WHERE
F_BillPaymentPusatID = {$orderid}
GROUP BY F_BillPaymentPusatDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$company = $prm["company"];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "(F_BillIssuePusatIsActive = 'Y'AND F_BillIssuePusatTotal > 0 AND F_BillIssuePusatIsLunas = '{$status}' AND (F_BillIssuePusatNumber LIKE '%{$search}%' OR F_BillIssuePusatRefNumber LIKE '%{$search}%' OR F_BillPaymentPusatNumber LIKE '%{$search}%') AND M_CompanyName LIKE '%{$company}%')";
$sql = " SELECT count(*) as total
FROM f_bill_issue_pusat
LEFT JOIN f_bill_payment_pusat ON F_BillIssuePusatID = F_BillPaymentPusatF_BillIssuePusatID AND F_BillPaymentPusatIsActive = 'Y'
LEFT JOIN m_company ON F_BillIssuePusatM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillIssuePusatM_MouID = M_MouID
WHERE
$where";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("f_bill_issue_pusat count", $this->db_onedev);
exit;
}
$sql = "SELECT f_bill_issue_pusat.*, f_bill_payment_pusat.*,
M_CompanyName,
M_MouName,
IFNULL(F_BillIssuePusatTotal,0) as totalbill,
IFNULL(F_BillIssuePusatTotal - F_BillIssuePusatUnpaid,0) as paid,
IFNULL(F_BillIssuePusatUnpaid,0) as unpaid,
F_BillIssuePusatIsLunas as flaglunas,
GROUP_CONCAT(F_BillPaymentPusatNumber SEPARATOR ', ') as F_BillPaymentPusatNumber,
SUM(F_BillPaymentPusatAmount) as F_BillPaymentPusatAmount,
DATE_FORMAT(F_BillPaymentPusatDate,'%d-%m-%Y') as F_BillPaymentPusatDate,
IFNULL(F_BillIssuePusatRefNumber,'') as F_BillIssuePusatRefNumber,
'' as notes,
'' as tagihans
FROM f_bill_issue_pusat
LEFT JOIN f_bill_payment_pusat ON F_BillIssuePusatID = F_BillPaymentPusatF_BillIssuePusatID AND F_BillPaymentPusatIsActive = 'Y'
LEFT JOIN m_company ON F_BillIssuePusatM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillIssuePusatM_MouID = M_MouID
WHERE
$where
GROUP BY F_BillIssuePusatID
ORDER BY F_BillIssuePusatID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['F_BillIssuePusatID']);
$rows[$k]['tagihans'] = $this->add_tagihans($v['F_BillIssuePusatID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,608 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookup_type()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
'N' as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
'' as selected_card,
'' as selected_edc,
'' as selected_account,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'No. Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
$rows[$k]['selected_card'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_edc'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_account'] = array('id'=>0,'name'=>'');
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function selectpaymenttype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_paymenttype
WHERE
M_PaymentTypeIsActive = 'Y'
";
//echo $query;
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectbank(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC
";
//echo $query;
$rows['banks'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectaccount(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
//echo $query;
$rows['accounts'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_banks()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT Nat_BankID as id, Nat_BankCode as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function lookup_accounts()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_BankAccountID as id, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcard(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
if($prm['search'] != ''){
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
if($prm['search'] != ''){
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function pay()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$payments = $prm['payments'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment_pusat
(F_BillPaymentPusatF_BillIssuePusatID,F_BillPaymentPusatDate,F_BillPaymentPusatCreated,F_BillPaymentPusatUserID)
VALUES (?,CURDATE(),NOW(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid, $xuserid
)
);
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat insert");
exit;
}
$headerid = $this->db_onedev->insert_id();
//echo $headerid;
foreach($payments as $k => $v){
if($v['chex']){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
if($v['code'] == 'CASH'){
$actual = $v['leftvalue'];
$change = $v['rightvalue'];
if($actual > 0){
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
}
else{
$amount = $actual;
}
$sql = "CALL `sp_bill_payment_add_cash_pusat`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.")";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail cash insert");
exit;
}
}
else{
if(intval($v['leftvalue']) > 0){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
$selected_card = 0;
$selected_edc = 0;
$selected_account = 0;
if($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER'){
$selected_card = $v['selected_card']['id'];
$selected_edc = $v['selected_edc']['id'];
$selected_account = $v['selected_account']['id'];
}
$sql = "CALL `sp_bill_payment_add_noncash_pusat`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.",".$selected_card.",".$selected_edc.",".$selected_account.")";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail non cash insert");
exit;
}
}
}
}
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'Nomor Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentPusatID as idx, F_BillPaymentPusatNumber as numberx FROM f_bill_payment_pusat WHERE F_BillPaymentPusatID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('types'=>$rows,'data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function paymanual()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$amount = $prm['amount'];
$paymenttype = $prm['paymenttype'];
if($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5){
$card = 0;
$edc = 0;
$account = 0;
}elseif($prm['paymenttype'] == 4){
$card = 0;
$edc = 0;
$account = $prm['account'];
}else{
$card = $prm['card'];
$edc = $prm['edc'];
$account = 0;
}
$voucher = $prm['voucher'];
$bills = $prm['bills'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment_pusat
(F_BillPaymentPusatF_BillIssuePusatID,
F_BillPaymentPusatDate,
F_BillPaymentPusatAmount,
F_BillPaymentPusatM_PaymentTypeID,
F_BillPaymentPusatEDCNat_BankID,
F_BillPaymentPusatCardNat_BankID,
F_BillPaymentPusatM_BankAccountID,
F_BillPaymentPusatVoucherNumber,
F_BillPaymentPusatCreated,
F_BillPaymentPusatUserID)
VALUES (?,
CURDATE(),
?,
?,
?,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$amount,
$paymenttype,
$edc,
$card,
$account,
$voucher,
$xuserid
)
);
$headerid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat insert");
exit;
} else{
$sqlbill = "UPDATE f_bill_issue_pusat SET
F_BillIssuePusatUnpaid = F_BillIssuePusatUnpaid - $amount,
F_BillIssuePusatIsLunas = IF(F_BillIssuePusatUnpaid = 0,'Y','N')
WHERE F_BillIssuePusatID = $orderid";
$querybill = $this->db_onedev->query($sqlbill);
}
//echo $headerid;
foreach($bills as $k => $v){
if($v['tagihan_bayar'] > 0){
$F_BillIssuePusatDetailID = $v['F_BillIssuePusatDetailID'];
$tagihan_bayar = $v['tagihan_bayar'];
$F_BillIssuePusatDetailF_BillID = $v['F_BillIssuePusatDetailF_BillID'];
$F_BillIssuePusatDetailM_BranchID = $v['F_BillIssuePusatDetailM_BranchID'];
$sql = "INSERT INTO f_bill_payment_pusat_detail(
F_BillPaymentPusatDetailF_BillPaymentPusatID,
F_BillPaymentPusatDetailF_BillIssuePusatID,
F_BillPaymentPusatDetailF_BillIssuePusatDetailID,
F_BillPaymentPusatDetailAmount,
F_BillPaymentPusatDetailUserID,
F_BillPaymentPusatDetailCreated,
F_BillPaymentPusatDetailLastUpdated)
VALUES(
$headerid,
$orderid,
$F_BillIssuePusatDetailID,
$tagihan_bayar,
$xuserid,
now(),
now())";
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$billpaymentdetailid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail cash insert");
exit;
}else{
$sqlbilldetail = "UPDATE f_bill_issue_pusat_detail SET
F_BillIssuePusatDetailUnpaid = F_BillIssuePusatDetailUnpaid - $tagihan_bayar
WHERE F_BillIssuePusatDetailID = $F_BillIssuePusatDetailID";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlpayment = "INSERT INTO f_payment_pusat
(F_PaymentPusatF_BillID,
F_PaymentPusatM_BranchID,
F_PaymentPusatDate,
F_PaymentPusatTotal,
F_PaymentPusatCreated,
F_PaymentPusatLastUpdated,
F_PaymentPusatM_UserID)
VALUES(
$F_BillIssuePusatDetailF_BillID,
$F_BillIssuePusatDetailM_BranchID,
now(),
$tagihan_bayar,
now(),
now(),
$xuserid)";
$querypayment = $this->db_onedev->query($sqlpayment);
$paymentid = $this->db_onedev->insert_id();
$sqlpaymentdetail = "INSERT INTO f_payment_pusatdetail
(F_PaymentPusatDetailF_PaymentPusatID,
F_PaymentPusatDetailM_PaymentTypeID,
F_PaymentPusatDetailAmount,
F_PaymentPusatDetailActual,
F_PaymentPusatDetailChange,
F_PaymentPusatDetailEDCNat_BankID,
F_PaymentPusatDetailCardNat_BankID,
F_PaymentPusatDetailM_BankAccountID,
F_PaymentPusatDetailCreated,
F_PaymentPusatDetailLastUpdated,
F_PaymentPusatDetailUserID)
VALUES(
$paymentid,
$paymenttype,
$tagihan_bayar,
$tagihan_bayar,
0,
$edc,
$card,
$account,
now(),
now(),
$xuserid)";
//echo $sqlpaymentdetail;
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_pusat_detail SET
F_BillPaymentPusatDetailF_PaymentPusatID = $paymentid
WHERE F_BillPaymentPusatDetailID = $billpaymentdetailid";
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
}
}
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentPusatID as idx, F_BillPaymentPusatNumber as numberx FROM f_bill_payment_pusat WHERE F_BillPaymentPusatID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function delete_note()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$prmnota = $prm['nota'];
$catatan = $prm['catatan'];
$sql = "UPDATE f_bill_payment_pusat SET F_BillPaymentPusatIsActive = 'N', F_BillPaymentPusatNote = '{$catatan}' WHERE F_BillPaymentPusatID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat delete");
exit;
}
$sql = "UPDATE f_bill_payment_pusat_detail SET F_BillPaymentPusatDetailIsActive = 'N' WHERE F_BillPaymentPusatDetailF_BillPaymentPusatID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_pusat_detail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => array('prm'=>$prm)
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,189 @@
<?php
class Realpayment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function paymanual()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$amount = $prm['amount'];
$paymenttype = $prm['paymenttype'];
if($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5){
$card = 0;
$edc = 0;
$account = 0;
}elseif($prm['paymenttype'] == 4){
$card = 0;
$edc = 0;
$account = $prm['account'];
}else{
$card = $prm['card'];
$edc = $prm['edc'];
$account = 0;
}
$voucher = $prm['voucher'];
$bills = $prm['bills'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment
(F_BillPaymentF_BillID,
F_BillPaymentDate,
F_BillPaymentAmount,
F_BillPaymentM_PaymentTypeID,
F_BillPaymentEDCNat_BankID,
F_BillPaymentCardNat_BankID,
F_BillPaymentM_BankAccountID,
F_BillPaymentVoucherNumber,
F_BillPaymentCreated,
F_BillPaymentUserID)
VALUES (?,
CURDATE(),
?,
?,
?,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$amount,
$paymenttype,
$edc,
$card,
$account,
$voucher,
$xuserid
)
);
$headerid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment insert");
exit;
} else{
$sqlbill = "UPDATE f_bill SET
F_BillUnpaid = F_BillUnpaid - $amount,
F_BillIsLunas = IF(F_BillUnpaid = 0,'Y','N')
WHERE F_BillID = $orderid";
$querybill = $this->db_onedev->query($sqlbill);
}
//echo $headerid;
foreach($bills as $k => $v){
if($v['tagihan_bayar'] > 0){
$F_BillDetailID = $v['F_BillDetailID'];
$tagihan_bayar = $v['tagihan_bayar'];
$F_BillDetailT_OrderHeaderID = $v['F_BillDetailT_OrderHeaderID'];
$sql = "INSERT INTO f_bill_payment_detail(
F_BillPaymentDetailF_BillPaymentID,
F_BillPaymentDetailF_BillID,
F_BillPaymentDetailF_BillDetailID,
F_BillPaymentDetailAmount,
F_BillPaymentDetailUserID,
F_BillPaymentDetailCreated,
F_BillPaymentDetailLastUpdated)
VALUES(
$headerid,
$orderid,
$F_BillDetailID,
$tagihan_bayar,
$xuserid,
now(),
now())";
$query = $this->db_onedev->query($sql);
$billpaymentdetailid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_detail cash insert");
exit;
}else{
$sqlbilldetail = "UPDATE f_bill_detail SET
F_BillDetailUnpaid = F_BillDetailUnpaid - $tagihan_bayar
WHERE F_BillDetailID = $F_BillDetailID";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlpayment = "INSERT INTO f_payment
(F_PaymentT_OrderHeaderID,
F_PaymentDate,
F_PaymentTotal,
F_PaymentCreated,
F_PaymentLastUpdated,
F_PaymentM_UserID)
VALUES(
$F_BillDetailT_OrderHeaderID,
now(),
$tagihan_bayar,
now(),
now(),
$xuserid)";
$querypayment = $this->db_onedev->query($sqlpayment);
$paymentid = $this->db_onedev->insert_id();
$sqlpaymentdetail = "INSERT INTO f_paymentdetail
(F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailEDCNat_BankID,
F_PaymentDetailCardNat_BankID,
F_PaymentDetailM_BankAccountID,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES(
$paymentid,
$paymenttype,
$tagihan_bayar,
$tagihan_bayar,
0,
$edc,
$card,
$account,
now(),
now(),
$xuserid)";
//echo $sqlpaymentdetail;
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_detail SET
F_BillPaymentDetailF_PaymentID = $paymentid
WHERE F_BillPaymentDetailID = $billpaymentdetailid";
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
}
}
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,162 @@
<?php
class Billsend extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "CONTROL API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookuptransaction(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$all = $prm['all'];
$sdate = $prm['sdate'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
from f_bill_confirm_issue
LEFT JOIN f_bill_detail ON F_BillDetailF_BillID = F_BillConfirmIssueF_BillID AND F_BillDetailIsActive = 'Y'
LEFT JOIN t_orderheader ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID
where
F_BillConfirmIssueIsActive = 'Y' AND F_BillConfirmIssueIsConfirm = 'Y' AND
(F_BillConfirmIssueRefNumber LIKE CONCAT('%','{$search}','%') OR
F_BillNo LIKE CONCAT('%','{$search}','%') OR
M_CompanyName LIKE CONCAT('%','{$search}','%'))";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("f_bill_confirm_issue count", $this->db_onedev);
exit;
}
$sql = "select F_BillConfirmIssueID as id,
F_BillConfirmIssueRefNumber,
F_BillNo,
DATE_FORMAT(F_BillConfirmIssueDate ,n'%d-%m-%Y') as xdate,
F_BillConfirmIssueDate,
M_CompanyName,
M_MouName
from f_bill_confirm_issue
LEFT JOIN f_bill_detail ON F_BillDetailF_BillID = F_BillConfirmIssueF_BillID AND F_BillDetailIsActive = 'Y'
LEFT JOIN t_orderheader ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID
where
F_BillConfirmIssueIsActive = 'Y' AND F_BillConfirmIssueIsConfirm = 'Y' AND
(F_BillConfirmIssueRefNumber LIKE CONCAT('%','{$search}','%') OR
F_BillNo LIKE CONCAT('%','{$search}','%') OR
M_CompanyName LIKE CONCAT('%','{$search}','%'))
GROUP BY F_BillConfirmIssueID
ORDER BY F_BillConfirmIssueDate DESC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("f_bill_confirm_issue select");
exit;
}
$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);
}
}
public function fix()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$nomor = md5($prm['nomor']);
$userid = $this->sys_user["M_UserID"];
$sql = $this->db_onedev->query("SELECT M_BranchIPAddress as branch_ip_address FROM m_branch WHERE M_BranchIsDefault = 'Y'")->row();
$branch_ip_address = $sql->branch_ip_address;
$param = array (
"id" => $id,
"nomor" => $nomor);
$j_param = json_encode($param);
$url = "http://$branch_ip_address/one-api/keu/titip_tagihan/upload/".$id."/".$userid;
$post_rst = $this->post($url);
// echo "to $url \nresponse : $post_rst\n";
$j_rst = json_decode($post_rst,true);
$xstatus = $j_rst["status"];
$xpesan = $j_rst["message"];
$result = array ("total" => 1, "records" => array("xid" => 0),"pesan"=>$post_rst);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function post($url) {
//$data = $data;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//echo "RST : $result ";
return $result;
}
function postold($url,$data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
if (curl_errno($ch)){
return json_encode( array("status" => "ERR",
"message" => curl_error($ch)) );
}
curl_close($ch);
return $result;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,900 @@
<?php
class Extend extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIssuePusatIsActive = 'Y' AND F_BillIssuePusatIsLunas = '{$status}' AND F_BillIssuePusatIsReceive = 'Y'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillIssuePusatRefNumber like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill_issue_pusat
LEFT JOIN m_mou ON F_BillIssuePusatM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
f_bill_issue_pusat.*,
F_BillIssuePusatM_MouID,
M_MouID,
M_MouName,
F_BillIssuePusatAgingDay + SUM(IFNULL(b.F_BillIssuePusatExtendDay,0)) as F_BillIssuePusatAgingDay,
DATE_FORMAT(F_BillIssuePusatDueDate,'%d-%m-%Y') as F_BillIssuePusatDueDate,
DATE_FORMAT(IFNULL(f_bill_issue_pusat.F_BillIssuePusatExtendDueDate,F_BillIssuePusatDueDate),'%d-%m-%Y') as duedate,
DATE_FORMAT(IFNULL(f_bill_issue_pusat.F_BillIssuePusatExtendDueDate,F_BillIssuePusatDueDate),'%Y-%m-%d') as duedatex,
DATE_FORMAT(F_BillIssuePusatDueDate,'%d-%m-%Y') as F_BillIssuePusatDueDate,
DATE_FORMAT(F_BillIssuePusatReceiveDate,'%d-%m-%Y') as F_BillCreated,
DATE_FORMAT(F_BillIssuePusatReceiveDate,'%Y-%m-%d') as billcreated,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
CONCAT(M_MouName,'|',M_MouNumber) as moudesc,
IFNULL(F_BillIssuePusatExtendID,0) as F_BillIssuePusatExtendID,
DATE_FORMAT(IFNULL(f_bill_issue_pusat.F_BillIssuePusatExtendDueDate,'-'),'%d-%m-%Y') as extenddate,
DATE_ADD(F_BillIssuePusatDueDate, INTERVAL 7 DAY) as exduedate,
DATE_FORMAT(DATE_ADD(F_BillIssuePusatDueDate, INTERVAL 7 DAY),'%d-%m-%Y') as exduedatex,
F_BillIssuePusatIsAllMou,
M_MouID as mouid,
M_MouIsActive
FROM f_bill_issue_pusat
LEFT JOIN m_mou ON F_BillIssuePusatM_MouID = M_MouID
left join m_company on F_BillIssuePusatM_CompanyID = M_CompanyID
LEFT JOIN f_bill_issue_pusat_extend b ON F_BillIssuePusatExtendF_BillIssuePusatID = F_BillIssuePusatID
$sql_where
GROUP BY F_BillIssuePusatID
ORDER BY F_BillIssuePusatRefNumber DESC
limit 0,$tot_count ";
$query = $this->db_onedev->query($sql, $sql_param);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_issue_pusat_detail
where F_BillIssuePusatDetailF_BillIssuePusatID = '{$v['F_BillIssuePusatID']}'")->row();
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function history()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$id = $prm["id"];
$sql_where = "WHERE F_BillIssuePusatExtendF_BillIssuePusatID = '{$id}'";
$sql_param = array();
$sql = "SELECT count(*) as total
FROM f_bill_issue_pusat_extend
$sql_where";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
f_bill_issue_pusat_extend.*,
DATE_FORMAT(F_BillIssuePusatExtendCreated,'%d-%m-%Y %H:%i') as tanggal,
DATE_FORMAT(F_BillIssuePusatExtendDueDate,'%d-%m-%Y') as duedate,
M_StaffName
FROM f_bill_issue_pusat_extend
LEFT JOIN m_user ON F_BillIssuePusatExtendUserID = M_UserID
left join m_staff on M_UserM_StaffID = M_StaffID
$sql_where
ORDER BY F_BillIssuePusatExtendID DESC
limit 0, $tot_count ";
// echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query ="SELECT M_MouID,
M_MouName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
M_MouAgingDay,
M_MouPicBillName,
M_MouPicBillHandphone
FROM m_mou
WHERE
M_MouM_CompanyID = ?
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillIssuePusatM_CompanyID,
F_BillIssuePusatM_MouID,
F_BillIssuePusatAgingDay,
F_BillIssuePusatDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$bquery = "SELECT M_BranchCode as branchcode FROM m_branch WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'";
$branchcode = $this->db_onedev->query($bquery)->row()->branchcode;
$queryissue_pusat ="INSERT INTO f_bill_issue_pusat (
F_BillIssuePusatNumber,
F_BillIssuePusatF_BillIssuePusatID,
F_BillIssuePusatDate,
F_BillIssuePusatPIC,
F_BillIssuePusatPICHP,
F_BillIssuePusatM_CompanyID,
F_BillIssuePusatM_MouID,
F_BillIssuePusatAgingDay,
F_BillIssuePusatUserID,
F_BillIssuePusatCreated
)
VALUES(
CONCAT('{$branchcode}','/',`fn_numbering`('BI')),
'{$last_id}',
date(now()),
'{$prm['picname']}',
'{$prm['pichp']}',
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rowsissue_pusat = $this->db_onedev->query($queryissue_pusat);
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue_pusat SET
F_BillIssuePusatExtendDay = F_BillIssuePusatExtendDay + '{$prm['day']}',
F_BillIssuePusatExtendNote = '{$prm['note']}',
F_BillIssuePusatExtendDueDate = '{$prm['duedate']}',
F_BillIssuePusatExtendUserID = '{$userid}'
WHERE F_BillIssuePusatID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$query ="INSERT INTO f_bill_issue_pusat_extend(F_BillIssuePusatExtendF_BillIssuePusatID,
F_BillIssuePusatExtendDay,
F_BillIssuePusatExtendNote,
F_BillIssuePusatExtendDueDate,
F_BillIssuePusatExtendUserID,
F_BillIssuePusatExtendCreated)
VALUES('{$prm['id']}',
'{$prm['day']}',
'{$prm['note']}',
'{$prm['duedate']}',
'{$userid}',
now())";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$sql = "SELECT M_MouID
FROM f_bill_issue_pusat_detail
JOIN f_bill_titip_detail ON M_BranchID = F_BillIssuePusatDetailM_BranchID AND F_BillDetailF_BillID = F_BillIssuePusatDetailF_BillID
WHERE F_BillIssuePusatDetailF_BillIssuePusatID = '{$prm['id']}' GROUP BY M_MouID";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$mouid = $v['M_MouID'];
$query ="INSERT INTO f_bill_issue_pusat_extend_mou(F_BillIssuePusatExtendMouF_BillIssuePusatExtendID,
F_BillIssuePusatExtendMouM_MouID,
F_BillIssuePusatExtendMouUserID)
VALUES($last_id,
$mouid,
'{$userid}')";
$rows = $this->db_onedev->query($query);
}
}
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_issue_pusat_detail(F_BillIssuePusatDetailF_BillIssuePusatID, F_BillIssuePusatDetailT_OrderHeaderID,
F_BillIssuePusatDetailTotal, F_BillIssuePusatDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql = "select count(*) tot from f_bill_issue_pusat_detail where F_BillIssuePusatDetailF_BillIssuePusatID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_issue_pusat_detail
join t_orderheader ON F_BillIssuePusatDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillIssuePusatDetailIsActive = 'Y' and F_BillIssuePusatDetailF_BillIssuePusatID = '{$billID}'
GROUP BY F_BillIssuePusatDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "SELECT *, IF(F_BillIssuePusatDetailID IS NULL ,'N','Y') as isbill,F_BillNo FROM (select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
SUM(IFNULL(F_PaymentTotal,0)) as bayar,
T_OrderHeaderTotal - SUM(IFNULL(F_PaymentTotal,0)) as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillIssuePusatID = '{$billID}'
left join m_company ON F_BillIssuePusatM_CompanyID = M_CompanyID
LEFT JOIN f_bill_issue_pusat_detail ON T_OrderHeaderID = F_BillIssuePusatDetailT_OrderHeaderID AND F_BillIssuePusatDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID))
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC) a
LEFT JOIN f_bill_issue_pusat_detail ON T_OrderHeaderID = F_BillIssuePusatDetailT_OrderHeaderID AND F_BillIssuePusatDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillIssuePusatDetailF_BillIssuePusatID = F_BillIssuePusatID AND F_BillIsActive = 'Y'
WHERE total > 1";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_issue_pusat_detail
(F_BillIssuePusatDetailF_BillIssuePusatID,
F_BillIssuePusatDetailT_OrderHeaderID,
F_BillIssuePusatDetailTotal,
F_BillIssuePusatDetailUnpaid,
F_BillIssuePusatDetailUserID,
F_BillIssuePusatDetailCreated,
F_BillIssuePusatDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillIssuePusatID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_issue_pusat_detail SET
F_BillIssuePusatDetailIsActive = 'N',
F_BillIssuePusatDetailUserID = '{$userid}'
WHERE
F_BillIssuePusatDetailF_BillIssuePusatID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_issue_pusat SET
F_BillIssuePusatIsActive = 'N',
F_BillIssuePusatUserID = '{$userid}'
WHERE
F_BillIssuePusatF_BillIssuePusatID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function notifbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue_pusat SET
F_BillIssuePusatIsNotif = 'Y',
F_BillIssuePusatNotifUserID = '{$userid}',
F_BillIssuePusatNotifDate = now()
WHERE
F_BillIssuePusatF_BillIssuePusatID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function sendbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue_pusat SET
F_BillIssuePusatIsSend = 'Y',
F_BillIssuePusatNotifUserID = '{$userid}',
F_BillIssuePusatSendDate = now()
WHERE
F_BillIssuePusatF_BillIssuePusatID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue_pusat_detail SET
F_BillIssuePusatDetailIsActive = 'N',
F_BillIssuePusatDetailUserID = '{$userid}'
WHERE
F_BillIssuePusatDetailID = '{$prm['F_BillIssuePusatDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,900 @@
<?php
class Extendv2 extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIssuePusatIsActive = 'Y' AND F_BillIssuePusatIsLunas = '{$status}' AND F_BillIssuePusatIsReceive = 'Y'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillIssuePusatRefNumber like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill_issue_pusat
LEFT JOIN m_mou ON F_BillIssuePusatM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
f_bill_issue_pusat.*,
F_BillIssuePusatM_MouID,
M_MouID,
M_MouName,
F_BillIssuePusatAgingDay + SUM(IFNULL(b.F_BillIssuePusatExtendDay,0)) as F_BillIssuePusatAgingDay,
DATE_FORMAT(F_BillIssuePusatDueDate,'%d-%m-%Y') as F_BillIssuePusatDueDate,
DATE_FORMAT(IFNULL(f_bill_issue_pusat.F_BillIssuePusatExtendDueDate,F_BillIssuePusatDueDate),'%d-%m-%Y') as duedate,
DATE_FORMAT(IFNULL(f_bill_issue_pusat.F_BillIssuePusatExtendDueDate,F_BillIssuePusatDueDate),'%Y-%m-%d') as duedatex,
DATE_FORMAT(F_BillIssuePusatDueDate,'%d-%m-%Y') as F_BillIssuePusatDueDate,
DATE_FORMAT(F_BillIssuePusatReceiveDate,'%d-%m-%Y') as F_BillCreated,
DATE_FORMAT(F_BillIssuePusatReceiveDate,'%Y-%m-%d') as billcreated,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
CONCAT(M_MouName,'|',M_MouNumber) as moudesc,
IFNULL(F_BillIssuePusatExtendID,0) as F_BillIssuePusatExtendID,
DATE_FORMAT(IFNULL(f_bill_issue_pusat.F_BillIssuePusatExtendDueDate,'-'),'%d-%m-%Y') as extenddate,
DATE_ADD(F_BillIssuePusatDueDate, INTERVAL 7 DAY) as exduedate,
DATE_FORMAT(DATE_ADD(F_BillIssuePusatDueDate, INTERVAL 7 DAY),'%d-%m-%Y') as exduedatex,
F_BillIssuePusatIsAllMou,
M_MouID as mouid,
M_MouIsActive
FROM f_bill_issue_pusat
LEFT JOIN m_mou ON F_BillIssuePusatM_MouID = M_MouID
left join m_company on F_BillIssuePusatM_CompanyID = M_CompanyID
LEFT JOIN f_bill_issue_pusat_extend b ON F_BillIssuePusatExtendF_BillIssuePusatID = F_BillIssuePusatID
$sql_where
GROUP BY F_BillIssuePusatID
ORDER BY F_BillIssuePusatRefNumber DESC
limit 0,$tot_count ";
$query = $this->db_onedev->query($sql, $sql_param);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_issue_pusat_detail
where F_BillIssuePusatDetailF_BillIssuePusatID = '{$v['F_BillIssuePusatID']}'")->row();
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function history()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$id = $prm["id"];
$sql_where = "WHERE F_BillIssuePusatExtendF_BillIssuePusatID = '{$id}'";
$sql_param = array();
$sql = "SELECT count(*) as total
FROM f_bill_issue_pusat_extend
$sql_where";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
f_bill_issue_pusat_extend.*,
DATE_FORMAT(F_BillIssuePusatExtendCreated,'%d-%m-%Y %H:%i') as tanggal,
DATE_FORMAT(F_BillIssuePusatExtendDueDate,'%d-%m-%Y') as duedate,
M_StaffName
FROM f_bill_issue_pusat_extend
LEFT JOIN m_user ON F_BillIssuePusatExtendUserID = M_UserID
left join m_staff on M_UserM_StaffID = M_StaffID
$sql_where
ORDER BY F_BillIssuePusatExtendID DESC
limit 0, $tot_count ";
// echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query ="SELECT M_MouID,
M_MouName,
CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc,
M_MouAgingDay,
M_MouPicBillName,
M_MouPicBillHandphone
FROM m_mou
WHERE
M_MouM_CompanyID = ?
AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillIssuePusatM_CompanyID,
F_BillIssuePusatM_MouID,
F_BillIssuePusatAgingDay,
F_BillIssuePusatDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$bquery = "SELECT M_BranchCode as branchcode FROM m_branch WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'";
$branchcode = $this->db_onedev->query($bquery)->row()->branchcode;
$queryissue_pusat ="INSERT INTO f_bill_issue_pusat (
F_BillIssuePusatNumber,
F_BillIssuePusatF_BillIssuePusatID,
F_BillIssuePusatDate,
F_BillIssuePusatPIC,
F_BillIssuePusatPICHP,
F_BillIssuePusatM_CompanyID,
F_BillIssuePusatM_MouID,
F_BillIssuePusatAgingDay,
F_BillIssuePusatUserID,
F_BillIssuePusatCreated
)
VALUES(
CONCAT('{$branchcode}','/',`fn_numbering`('BI')),
'{$last_id}',
date(now()),
'{$prm['picname']}',
'{$prm['pichp']}',
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rowsissue_pusat = $this->db_onedev->query($queryissue_pusat);
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue_pusat SET
F_BillIssuePusatExtendDay = F_BillIssuePusatExtendDay + '{$prm['day']}',
F_BillIssuePusatExtendNote = '{$prm['note']}',
F_BillIssuePusatExtendDueDate = '{$prm['duedate']}',
F_BillIssuePusatExtendUserID = '{$userid}'
WHERE F_BillIssuePusatID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$query ="INSERT INTO f_bill_issue_pusat_extend(F_BillIssuePusatExtendF_BillIssuePusatID,
F_BillIssuePusatExtendDay,
F_BillIssuePusatExtendNote,
F_BillIssuePusatExtendDueDate,
F_BillIssuePusatExtendUserID,
F_BillIssuePusatExtendCreated)
VALUES('{$prm['id']}',
'{$prm['day']}',
'{$prm['note']}',
'{$prm['duedate']}',
'{$userid}',
now())";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$sql = "SELECT M_MouID
FROM f_bill_issue_pusat_detail
JOIN f_bill_titip_detail ON M_BranchID = F_BillIssuePusatDetailM_BranchID AND F_BillDetailF_BillID = F_BillIssuePusatDetailF_BillID
WHERE F_BillIssuePusatDetailF_BillIssuePusatID = '{$prm['id']}' GROUP BY M_MouID";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$mouid = $v['M_MouID'];
$query ="INSERT INTO f_bill_issue_pusat_extend_mou(F_BillIssuePusatExtendMouF_BillIssuePusatExtendID,
F_BillIssuePusatExtendMouM_MouID,
F_BillIssuePusatExtendMouUserID)
VALUES($last_id,
$mouid,
'{$userid}')";
$rows = $this->db_onedev->query($query);
}
}
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_issue_pusat_detail(F_BillIssuePusatDetailF_BillIssuePusatID, F_BillIssuePusatDetailT_OrderHeaderID,
F_BillIssuePusatDetailTotal, F_BillIssuePusatDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql = "select count(*) tot from f_bill_issue_pusat_detail where F_BillIssuePusatDetailF_BillIssuePusatID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_issue_pusat_detail
join t_orderheader ON F_BillIssuePusatDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillIssuePusatDetailIsActive = 'Y' and F_BillIssuePusatDetailF_BillIssuePusatID = '{$billID}'
GROUP BY F_BillIssuePusatDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "SELECT *, IF(F_BillIssuePusatDetailID IS NULL ,'N','Y') as isbill,F_BillNo FROM (select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
SUM(IFNULL(F_PaymentTotal,0)) as bayar,
T_OrderHeaderTotal - SUM(IFNULL(F_PaymentTotal,0)) as total,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillIssuePusatID = '{$billID}'
left join m_company ON F_BillIssuePusatM_CompanyID = M_CompanyID
LEFT JOIN f_bill_issue_pusat_detail ON T_OrderHeaderID = F_BillIssuePusatDetailT_OrderHeaderID AND F_BillIssuePusatDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsAgingOnHold = 'Y' AND M_MouAgingDay > 0
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID))
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC) a
LEFT JOIN f_bill_issue_pusat_detail ON T_OrderHeaderID = F_BillIssuePusatDetailT_OrderHeaderID AND F_BillIssuePusatDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillIssuePusatDetailF_BillIssuePusatID = F_BillIssuePusatID AND F_BillIsActive = 'Y'
WHERE total > 1";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_issue_pusat_detail
(F_BillIssuePusatDetailF_BillIssuePusatID,
F_BillIssuePusatDetailT_OrderHeaderID,
F_BillIssuePusatDetailTotal,
F_BillIssuePusatDetailUnpaid,
F_BillIssuePusatDetailUserID,
F_BillIssuePusatDetailCreated,
F_BillIssuePusatDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillIssuePusatID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_issue_pusat_detail SET
F_BillIssuePusatDetailIsActive = 'N',
F_BillIssuePusatDetailUserID = '{$userid}'
WHERE
F_BillIssuePusatDetailF_BillIssuePusatID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_issue_pusat SET
F_BillIssuePusatIsActive = 'N',
F_BillIssuePusatUserID = '{$userid}'
WHERE
F_BillIssuePusatF_BillIssuePusatID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function notifbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue_pusat SET
F_BillIssuePusatIsNotif = 'Y',
F_BillIssuePusatNotifUserID = '{$userid}',
F_BillIssuePusatNotifDate = now()
WHERE
F_BillIssuePusatF_BillIssuePusatID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function sendbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue_pusat SET
F_BillIssuePusatIsSend = 'Y',
F_BillIssuePusatNotifUserID = '{$userid}',
F_BillIssuePusatSendDate = now()
WHERE
F_BillIssuePusatF_BillIssuePusatID = '{$prm['id']}'";
// echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_issue_pusat_detail SET
F_BillIssuePusatDetailIsActive = 'N',
F_BillIssuePusatDetailUserID = '{$userid}'
WHERE
F_BillIssuePusatDetailID = '{$prm['F_BillIssuePusatDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,715 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
F_BillM_MouID,
M_MouID,
IF(F_BillM_MouID = 0, 'Semua',M_MouName) as M_MouName,
F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
M_CompanyName,
IF(F_BillM_MouID = 0, 'Semua',CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y'))) as M_MouDesc
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$rows[$k]['haveDetail'] = "N";
} else {
$rows[$k]['haveDetail'] = "Y";
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT 0 as M_MouID, 'Semua' as M_MouName, 'Semua' as M_MouDesc
UNION
SELECT M_MouID, M_MouName, CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillDueDateDay = '{$prm['day']}',
F_BillDueDate = '{$pdate}',
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}',
F_BillCreated = now()
WHERE F_BillID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
order by F_BillDetailID asc";
} else {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_BillDetailID IS NULL AND F_PaymentID IS NULL
order by T_OrderHeaderDate asc, T_OrderHeaderID asc";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,681 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
// echo $norm;
$sql_where = "WHERE F_BillIsActive = 'Y' ";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
//if ($sql_where != "") $sql_where .= " and ";
// Order masih dalam status registrasi
//$sql_where .= " M_PatientIsActive = 'Y' ";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,20";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
WHERE F_BillID = '{$v['F_BillID']}' ")->row();
$rows[$k]['statuss'] = json_decode($x->n);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDate,
F_BillNote,
F_BillTotal,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$pdate}',
'{$prm['note']}',
`fn_get_total_bill`({$prm['mouid']}),
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="INSERT INTO f_bill_detail (
F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated
)
select $last_id,T_OrderHeaderID,$userid,NOW(),NOW()
from t_orderheader
left join f_payment on T_OrderHeaderID = F_PaymentT_OrderHeaderID
and T_OrderHeaderM_MouID = '{$prm['mouid']}'
where T_OrderHeaderIsActive = 'Y' and F_PaymentID is null and T_OrderHeaderID not in (
select F_BillDetailT_OrderHeaderID from f_bill_detail where F_BillDetailIsActive = 'Y'
)
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailIsActive = 'Y' AND F_BillDetailF_BillID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailF_BillID = '{$v['F_BillID']}' AND F_BillDetailIsActive = 'Y'")->row();
$rows[$k]['tesx'] = json_decode($x->n);
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO t_receivereferencepatient (
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID,
T_ReceiveReferencePatientNoRef,
T_ReceiveReferencePatientName,
T_ReceiveReferencePatientDOB,
T_ReceiveReferencePatientM_SexID,
T_ReceiveReferencePatientUserID,
T_ReceiveReferencePatientTotal,
T_ReceiveReferencePatientDPPercent,
T_ReceiveReferencePatientDPAmount,
T_ReceiveReferencePatientCreated
)
VALUES(
'{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
'{$prm['T_ReceiveReferencePatientNoRef']}',
'{$prm['T_ReceiveReferencePatientName']}',
'{$pdob}',
'{$prm['T_ReceiveReferencePatientM_SexID']}',
'{$userid}',
'{$prm['T_ReceiveReferencePatientTotal']}',
'{$prm['T_ReceiveReferencePatientDPPercent']}',
'{$prm['T_ReceiveReferencePatientDPAmount']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$orderpatient_id = $this->db_onedev->insert_id();
foreach($prm['ordertests'] as $k=>$v){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestT_TestDisc,
T_ReceiveReferenceTestT_TestDiscRp,
T_ReceiveReferenceTestT_TestTotal,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,?,?,?, now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$orderpatient_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['T_PriceAmount'],
$v['T_PriceDisc'],
$v['T_PriceDiscRp'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,749 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
F_BillM_MouID,
M_MouID,
IF(F_BillM_MouID = 0, 'Semua',M_MouName) as M_MouName,
F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
M_CompanyName,
IF(F_BillM_MouID = 0, 'Semua',CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y'))) as M_MouDesc
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$mouID = $v['F_BillM_MouID'];
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM t_orderheader
join f_bill on F_BillID = '{$v['F_BillID']}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_BillDetailID IS NULL AND F_PaymentID IS NULL")->row();
$rows[$k]['haveDetail'] = "N";
$rows[$k]['startdate'] = $startdate->startdate;
} else {
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
$rows[$k]['haveDetail'] = "Y";
$rows[$k]['startdate'] = $startdate->startdate;
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT 0 as M_MouID, 'Semua' as M_MouName, 'Semua' as M_MouDesc
UNION
SELECT M_MouID, M_MouName, CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillDueDateDay = '{$prm['day']}',
F_BillDueDate = '{$pdate}',
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}',
F_BillCreated = now()
WHERE F_BillID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_BillDetailID IS NULL AND F_PaymentID IS NULL
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
ORDER BY T_OrderHeaderID ASC";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,681 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
// echo $norm;
$sql_where = "WHERE F_BillIsActive = 'Y' ";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
//if ($sql_where != "") $sql_where .= " and ";
// Order masih dalam status registrasi
//$sql_where .= " M_PatientIsActive = 'Y' ";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,20";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
WHERE F_BillID = '{$v['F_BillID']}' ")->row();
$rows[$k]['statuss'] = json_decode($x->n);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDate,
F_BillNote,
F_BillTotal,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$pdate}',
'{$prm['note']}',
`fn_get_total_bill`({$prm['mouid']}),
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="INSERT INTO f_bill_detail (
F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated
)
select $last_id,T_OrderHeaderID,$userid,NOW(),NOW()
from t_orderheader
left join f_payment on T_OrderHeaderID = F_PaymentT_OrderHeaderID
and T_OrderHeaderM_MouID = '{$prm['mouid']}'
where T_OrderHeaderIsActive = 'Y' and F_PaymentID is null and T_OrderHeaderID not in (
select F_BillDetailT_OrderHeaderID from f_bill_detail where F_BillDetailIsActive = 'Y'
)
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailIsActive = 'Y' AND F_BillDetailF_BillID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailF_BillID = '{$v['F_BillID']}' AND F_BillDetailIsActive = 'Y'")->row();
$rows[$k]['tesx'] = json_decode($x->n);
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO t_receivereferencepatient (
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID,
T_ReceiveReferencePatientNoRef,
T_ReceiveReferencePatientName,
T_ReceiveReferencePatientDOB,
T_ReceiveReferencePatientM_SexID,
T_ReceiveReferencePatientUserID,
T_ReceiveReferencePatientTotal,
T_ReceiveReferencePatientDPPercent,
T_ReceiveReferencePatientDPAmount,
T_ReceiveReferencePatientCreated
)
VALUES(
'{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
'{$prm['T_ReceiveReferencePatientNoRef']}',
'{$prm['T_ReceiveReferencePatientName']}',
'{$pdob}',
'{$prm['T_ReceiveReferencePatientM_SexID']}',
'{$userid}',
'{$prm['T_ReceiveReferencePatientTotal']}',
'{$prm['T_ReceiveReferencePatientDPPercent']}',
'{$prm['T_ReceiveReferencePatientDPAmount']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$orderpatient_id = $this->db_onedev->insert_id();
foreach($prm['ordertests'] as $k=>$v){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestT_TestDisc,
T_ReceiveReferenceTestT_TestDiscRp,
T_ReceiveReferenceTestT_TestTotal,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,?,?,?, now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$orderpatient_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['T_PriceAmount'],
$v['T_PriceDisc'],
$v['T_PriceDiscRp'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,751 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
F_BillM_MouID,
M_MouID,
IF(F_BillM_MouID = 0, 'Semua',M_MouName) as M_MouName,
F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
M_CompanyName,
IF(F_BillM_MouID = 0, 'Semua',CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y'))) as M_MouDesc
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$mouID = $v['F_BillM_MouID'];
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM t_orderheader
join f_bill on F_BillID = '{$v['F_BillID']}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_BillDetailID IS NULL AND F_PaymentID IS NULL")->row();
$rows[$k]['haveDetail'] = "N";
$rows[$k]['startdate'] = $startdate->startdate;
} else {
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
$rows[$k]['haveDetail'] = "Y";
$rows[$k]['startdate'] = $startdate->startdate;
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT 0 as M_MouID, 'Semua' as M_MouName, 'Semua' as M_MouDesc
UNION
SELECT M_MouID, M_MouName, CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillDueDateDay = '{$prm['day']}',
F_BillDueDate = '{$pdate}',
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}',
F_BillCreated = now()
WHERE F_BillID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "SELECT * FROM (select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
SUM(IFNULL(F_PaymentTotal,0)) as bayar,
T_OrderHeaderTotal - SUM(IFNULL(F_PaymentTotal,0)) as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID))
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC) a
WHERE total > 1";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,681 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
// echo $norm;
$sql_where = "WHERE F_BillIsActive = 'Y' ";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
//if ($sql_where != "") $sql_where .= " and ";
// Order masih dalam status registrasi
//$sql_where .= " M_PatientIsActive = 'Y' ";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,20";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
WHERE F_BillID = '{$v['F_BillID']}' ")->row();
$rows[$k]['statuss'] = json_decode($x->n);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDate,
F_BillNote,
F_BillTotal,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$pdate}',
'{$prm['note']}',
`fn_get_total_bill`({$prm['mouid']}),
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="INSERT INTO f_bill_detail (
F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated
)
select $last_id,T_OrderHeaderID,$userid,NOW(),NOW()
from t_orderheader
left join f_payment on T_OrderHeaderID = F_PaymentT_OrderHeaderID
and T_OrderHeaderM_MouID = '{$prm['mouid']}'
where T_OrderHeaderIsActive = 'Y' and F_PaymentID is null and T_OrderHeaderID not in (
select F_BillDetailT_OrderHeaderID from f_bill_detail where F_BillDetailIsActive = 'Y'
)
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailIsActive = 'Y' AND F_BillDetailF_BillID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailF_BillID = '{$v['F_BillID']}' AND F_BillDetailIsActive = 'Y'")->row();
$rows[$k]['tesx'] = json_decode($x->n);
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO t_receivereferencepatient (
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID,
T_ReceiveReferencePatientNoRef,
T_ReceiveReferencePatientName,
T_ReceiveReferencePatientDOB,
T_ReceiveReferencePatientM_SexID,
T_ReceiveReferencePatientUserID,
T_ReceiveReferencePatientTotal,
T_ReceiveReferencePatientDPPercent,
T_ReceiveReferencePatientDPAmount,
T_ReceiveReferencePatientCreated
)
VALUES(
'{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
'{$prm['T_ReceiveReferencePatientNoRef']}',
'{$prm['T_ReceiveReferencePatientName']}',
'{$pdob}',
'{$prm['T_ReceiveReferencePatientM_SexID']}',
'{$userid}',
'{$prm['T_ReceiveReferencePatientTotal']}',
'{$prm['T_ReceiveReferencePatientDPPercent']}',
'{$prm['T_ReceiveReferencePatientDPAmount']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$orderpatient_id = $this->db_onedev->insert_id();
foreach($prm['ordertests'] as $k=>$v){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestT_TestDisc,
T_ReceiveReferenceTestT_TestDiscRp,
T_ReceiveReferenceTestT_TestTotal,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,?,?,?, now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$orderpatient_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['T_PriceAmount'],
$v['T_PriceDisc'],
$v['T_PriceDiscRp'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,752 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
left join m_company on F_BillM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
// echo $this->db_onedev->last_query();
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
F_BillM_MouID,
M_MouID,
IF(F_BillM_MouID = 0, 'Semua',M_MouName) as M_MouName,
F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName,
IF(F_BillM_MouID = 0, 'Semua',CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y'))) as M_MouDesc
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
//echo $this->db_onedev->last_query();
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$mouID = $v['F_BillM_MouID'];
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM t_orderheader
join f_bill on F_BillID = '{$v['F_BillID']}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_PaymentID IS NULL")->row();
$rows[$k]['haveDetail'] = "N";
$rows[$k]['startdate'] = $startdate->startdate;
} else {
$startdate = $this->db_onedev->query("
select MIN(date(T_OrderHeaderDate)) as startdate
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
$rows[$k]['haveDetail'] = "Y";
$rows[$k]['startdate'] = $startdate->startdate;
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *, CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') as M_CompanyName
FROM m_company
WHERE
CONCAT(M_CompanyName, ' [',M_CompanyNumber,']') like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT 0 as M_MouID, 'Semua' as M_MouName, 'Semua' as M_MouDesc
UNION
SELECT M_MouID, M_MouName, CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillDueDateDay = '{$prm['day']}',
F_BillDueDate = '{$pdate}',
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}',
F_BillCreated = now()
WHERE F_BillID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
F_BillDetailTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
ORDER BY T_OrderHeaderID ASC";
} else {
$sql = "SELECT *, IF(F_BillDetailID IS NULL ,'N','Y') as isbill,F_BillNo FROM (select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
SUM(IFNULL(F_PaymentTotal,0)) as bayar,
T_OrderHeaderTotal - SUM(IFNULL(F_PaymentTotal,0)) as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID))
AND ( T_OrderHeaderDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' )
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID ASC) a
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_bill ON F_BillDetailF_BillID = F_BillID AND F_BillIsActive = 'Y'
WHERE total > 1";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,681 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
// echo $norm;
$sql_where = "WHERE F_BillIsActive = 'Y' ";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
//if ($sql_where != "") $sql_where .= " and ";
// Order masih dalam status registrasi
//$sql_where .= " M_PatientIsActive = 'Y' ";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,20";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
WHERE F_BillID = '{$v['F_BillID']}' ")->row();
$rows[$k]['statuss'] = json_decode($x->n);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDate,
F_BillNote,
F_BillTotal,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$pdate}',
'{$prm['note']}',
`fn_get_total_bill`({$prm['mouid']}),
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="INSERT INTO f_bill_detail (
F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated
)
select $last_id,T_OrderHeaderID,$userid,NOW(),NOW()
from t_orderheader
left join f_payment on T_OrderHeaderID = F_PaymentT_OrderHeaderID
and T_OrderHeaderM_MouID = '{$prm['mouid']}'
where T_OrderHeaderIsActive = 'Y' and F_PaymentID is null and T_OrderHeaderID not in (
select F_BillDetailT_OrderHeaderID from f_bill_detail where F_BillDetailIsActive = 'Y'
)
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailIsActive = 'Y' AND F_BillDetailF_BillID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailF_BillID = '{$v['F_BillID']}' AND F_BillDetailIsActive = 'Y'")->row();
$rows[$k]['tesx'] = json_decode($x->n);
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO t_receivereferencepatient (
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID,
T_ReceiveReferencePatientNoRef,
T_ReceiveReferencePatientName,
T_ReceiveReferencePatientDOB,
T_ReceiveReferencePatientM_SexID,
T_ReceiveReferencePatientUserID,
T_ReceiveReferencePatientTotal,
T_ReceiveReferencePatientDPPercent,
T_ReceiveReferencePatientDPAmount,
T_ReceiveReferencePatientCreated
)
VALUES(
'{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
'{$prm['T_ReceiveReferencePatientNoRef']}',
'{$prm['T_ReceiveReferencePatientName']}',
'{$pdob}',
'{$prm['T_ReceiveReferencePatientM_SexID']}',
'{$userid}',
'{$prm['T_ReceiveReferencePatientTotal']}',
'{$prm['T_ReceiveReferencePatientDPPercent']}',
'{$prm['T_ReceiveReferencePatientDPAmount']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$orderpatient_id = $this->db_onedev->insert_id();
foreach($prm['ordertests'] as $k=>$v){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestT_TestDisc,
T_ReceiveReferenceTestT_TestDiscRp,
T_ReceiveReferenceTestT_TestTotal,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,?,?,?, now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$orderpatient_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['T_PriceAmount'],
$v['T_PriceDisc'],
$v['T_PriceDiscRp'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,212 @@
<?php
class Area extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "AREA API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search_province()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 150;
$tot_count =0;
// QUERY TOTAL
/*$sql = "select count(*) total
from m_province
where M_ProvinceName LIKE ?
and M_ProvinceIsActive = 'Y'";
$query = $this->db_smartone->query($sql, array($src));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_province count",$this->db_smartone);
exit;
}*/
$sql = "select M_ProvinceID, M_ProvinceName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_province
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_provinceid = M_ProvinceID
where M_ProvinceName LIKE ?
and M_ProvinceIsActive = 'Y'
order by M_ProvinceName
";
$query = $this->db_smartone->query($sql, array($src));
if ($query) {
$rows = $query->result_array();
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_province rows",$this->db_smartone);
exit;
}
}
public function search_city()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
/*$sql = "select count(*) total
from m_city
where M_CityName LIKE ?
and M_CityIsActive = 'Y'
and M_CityM_ProvinceID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['province_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_smartone);
exit;
}*/
$sql = "select M_CityID, M_CityName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_city
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_cityid = M_CityID
where M_CityName LIKE ?
and M_CityIsActive = 'Y'
and M_CityM_ProvinceID = ?
order by M_CityName
";
$query = $this->db_smartone->query($sql, array($src, $prm['province_id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_smartone);
exit;
}
}
public function search_district()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
/*$sql = "select count(*) total
from m_district
where M_DistrictName LIKE ?
and M_DistrictIsActive = 'Y'
and M_DistrictM_CityID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['city_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_smartone);
exit;
}*/
$sql = "select M_DistrictID, M_DistrictName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_district
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_districtid = M_DistrictID
where M_DistrictName LIKE ?
and M_DistrictIsActive = 'Y'
and M_DistrictM_CityID = ?
order by M_DistrictName
-- limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src, $prm['city_id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_smartone);
exit;
}
}
public function search_kelurahan()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
/*$sql = "select count(*) total
from m_kelurahan
where M_KelurahanName LIKE ?
and M_KelurahanIsActive = 'Y'
and M_KelurahanM_DistrictID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['district_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_kelurahan count",$this->db_smartone);
exit;
}*/
$sql = "select M_KelurahanID, M_KelurahanName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_kelurahan
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_kelurahanid = M_KelurahanID
where M_KelurahanName LIKE ?
and M_KelurahanIsActive = 'Y'
and M_KelurahanM_DistrictID = ?
order by M_KelurahanName
-- limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src, $prm['district_id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_kelurahan rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
class Conf extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "CONF API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$tot_count = 1;
$sql = "SELECT * FROM conf_clinic";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->row();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("CONF rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,69 @@
<?php
class Diagnose extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Diagnose API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_diagnose
where M_DiagnoseIsActive = 'Y'
and M_DiagnoseName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_diagnose count",$this->db_smartone);
exit;
}
$sql = "select M_DiagnoseID, M_DiagnoseName
from m_diagnose
where M_DiagnoseIsActive = 'Y'
and M_DiagnoseName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['mou'] = json_decode($v['mou']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_diagnose rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,78 @@
<?php
class Doctor extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Doctor API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_doctor
JOIN m_doctorpj ON M_DoctorID = M_DoctorPJM_DoctorID and M_DoctorIsActive = 'Y'
where M_DoctorIsActive = 'Y'
and M_DoctorPJIsClinic = 'Y'
and M_DoctorName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
$sql = "select M_DoctorID, M_DoctorIsDefault, M_DoctorIsPJ,
concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) as M_DoctorName,
IFNULL( concat('[', group_concat(JSON_OBJECT('M_DoctorAddressDescription', M_DoctorAddressDescription, 'M_DoctorAddressID', M_DoctorAddressID) SEPARATOR ','), ']'), '[]') as address
from m_doctor
JOIN m_doctorpj ON M_DoctorID = M_DoctorPJM_DoctorID and M_DoctorIsActive = 'Y'
left join m_doctoraddress on M_DoctorAddressIsActive = 'Y'
and M_DoctorAddressM_DoctorID = M_DoctorID
where M_DoctorPJIsActive = 'Y'
and M_DoctorIsClinic = 'Y'
and concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) like ?
group by M_DoctorID";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['address'] = json_decode($v['address']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Gcs extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "GCS API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_gcs
where M_GcsIsActive = 'Y'
and M_GcsName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_gcs count",$this->db_smartone);
exit;
}
$sql = "select M_GcsID, M_GcsName
from m_gcs
where M_GcsIsActive = 'Y'
and M_GcsName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_gcs rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Order extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "ORDER API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
function save()
{
$prm = $this->sys_input;
$prm['header']['complaint'] = str_replace(PHP_EOL, '<br>', $prm['header']['complaint']);
$header_json = json_encode($prm['header']);
$payment_json = json_encode($prm['payment']);
$uid = $this->sys_user['M_UserID'];
$sql = "CALL sp_clinic_fo_save('{$prm['order_id']}', '{$header_json}', '{$payment_json}', '{$uid}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
// if ($rst->status == "OK")
// {
// // persiapkan curl
// $ch = curl_init();
// // set url
// curl_setopt($ch, CURLOPT_URL, "http://anggrek.aplikasi.web.id:9090/ticket/KLINIK");
// // return the transfer as a string
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// // $output contains the output string
// $output = json_decode(curl_exec($ch));
// // tutup curl
// curl_close($ch);
// // menampilkan hasil curl
// // echo $output;
// if ($output != null)
// if ($output->status == "OK")
// $rst->data->queue = $output->data[0]->number;
// }
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,264 @@
<?php
/*
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'noreg' => '%',
'name' => '%',
'hp' => '%',
'dob' => '%',
'address' => '%'
];
if ($prm['noreg'] != '')
$q['noreg'] = "%{$prm['noreg']}%";
if ($prm['search'] != '')
{
$e = explode('+', $prm['search']);
if (isset($e[0]))
$q['name'] = "%{$e[0]}%";
if (isset($e[1]))
$q['hp'] = "%{$e[1]}%";
if (isset($e[2]))
$q['dob'] = "%{$e[2]}%";
if (isset($e[3]))
$q['address'] = "%{$e[3]}%";
}
// QUERY TOTAL
$sql = "select count(distinct m_patientid) total
from
m_patient join m_title on M_PatientM_TitleID = M_TitleID
join m_patientaddress on M_PatientAddressM_PatientID = M_PatientID and M_PatientAddressIsActive = 'Y'
where M_PatientNoReg like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE ? and M_PatientDOB IS NOT NULL) OR M_PatientDOB IS NULL)
and M_PatientAddressDescription LIKE ?";
$query = $this->db_smartone->query($sql, array($q['noreg'], $q['name'], $q['hp'], $q['dob'], $q['address']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
$sql = "SELECT M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) M_PatientName,
M_PatientName M_PatientRealName, M_TitleID, M_TitleName, M_SexID, M_SexName,
M_PatientHP, M_PatientPOB, M_PatientDOB, M_PatientNote,
concat(M_PatientAddressDescription, '\n\n', m_kelurahanname, ', ', m_districtname,
'\n', m_cityname, ', ', m_provincename) as M_PatientAddress,
M_PatientAddressDescription, M_PatientM_IdTypeID, M_PatientIDNumber,
IFNULL(M_PatientNote, '') M_PatientNote, M_PatientPhoto, IF(M_PatientPhone IS NULL OR M_PatientPhone = '', M_PatientHP, M_PatientPhone) hp,
fn_fo_patient_visit(M_PatientID) info,
M_KelurahanID, M_DistrictID, M_CityID, M_ProvinceID, M_PatientM_ReligionID,
IFNULL(M_ReligionName, '-') M_ReligionName
from
m_patient join m_title on M_PatientM_TitleID = M_TitleID
join m_sex on M_PatientM_SexID = M_SexID
join m_patientaddress on M_PatientAddressM_PatientID = M_PatientID and M_PatientAddressIsActive = 'Y'
left join m_kelurahan on m_patientaddressm_kelurahanid = m_kelurahanid
left join m_district on m_kelurahanm_districtid = m_districtid
left join m_city on m_districtm_cityid = m_cityid
left join m_province on m_citym_provinceid = m_provinceid
left join m_religion on m_patientm_religionid = m_religionid
where M_PatientNoReg like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE ? and M_PatientDOB IS NOT NULL) OR M_PatientDOB IS NULL)
and M_PatientAddressDescription LIKE ?
group by m_patientid
limit 0,{$max_rst}";
$query = $this->db_smartone->query($sql, array($q['noreg'], $q['name'], $q['hp'], $q['dob'], $q['address']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['info'] = json_decode($v['info']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "query" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_smartone);
exit;
}
}
function add_new()
{
$prm = $this->sys_input;
$prm['M_PatientDOB'] = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$ptn = [
'M_PatientName' => $prm['M_PatientName'],
'M_PatientM_TitleID' => $prm['M_PatientM_TitleID'],
'M_PatientSuffix' => $prm['M_PatientSuffix'],
'M_PatientM_SexID' => $prm['M_PatientM_SexID'],
'M_PatientM_ReligionID' => $prm['M_PatientM_ReligionID'],
'M_PatientDOB' => $prm['M_PatientDOB'],
'M_PatientPOB' => $prm['M_PatientPOB'],
'M_PatientHP' => $prm['M_PatientHP'],
'M_PatientPhone' => $prm['M_PatientPhone'],
'M_PatientEmail' => $prm['M_PatientEmail'],
'M_PatientM_IdTypeID' => $prm['M_PatientM_IdTypeID'],
'M_PatientIDNumber' => $prm['M_PatientIDNumber'],
'M_PatientNote' => $prm['M_PatientNote']
];
$this->db_smartone->insert('m_patient', $ptn);
$err = $this->db_smartone->error();
if ( $err['message'] != "" )
{
$this->sys_error_db("m_patient rows", $this->db_smartone);
return;
}
$id = $this->db_smartone->insert_id();
// LOG FO
$ptn = json_encode($ptn);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADD', '{$ptn}', '0')");
// save address
$add = [
'M_PatientAddressM_PatientID' => $id,
'M_PatientAddressDescription' => $prm['M_PatientAddressDescription'],
'M_PatientAddressM_KelurahanID' => $prm['M_PatientAddressM_KelurahanID']
];
$this->db_smartone->insert('m_patientaddress', $add);
// LOG FO
$add = json_encode($add);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADDRESS.ADD', '{$add}', '0')");
// get
$r = $this->db_smartone->where('M_PatientID', $id)
->get('m_patient')
->row();
$rst = array("id" => $id, 'noreg'=>$r->M_PatientNoReg);
$this->sys_ok($rst);
}
function edit()
{
$prm = $this->sys_input;
$prm['M_PatientDOB'] = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$this->db_smartone->set('M_PatientName', $prm['M_PatientName'])
->set('M_PatientM_TitleID', $prm['M_PatientM_TitleID'])
->set('M_PatientSuffix', $prm['M_PatientSuffix'])
->set('M_PatientM_SexID', $prm['M_PatientM_SexID'])
->set('M_PatientM_ReligionID', $prm['M_PatientM_ReligionID'])
->set('M_PatientDOB', $prm['M_PatientDOB'])
->set('M_PatientPOB', $prm['M_PatientPOB'])
->set('M_PatientHP', $prm['M_PatientHP'])
->set('M_PatientPhone', $prm['M_PatientPhone'])
->set('M_PatientEmail', $prm['M_PatientEmail'])
->set('M_PatientM_IdTypeID', $prm['M_PatientM_IdTypeID'])
->set('M_PatientIDNumber', $prm['M_PatientIDNumber'])
->set('M_PatientNote', $prm['M_PatientNote'])
->where('M_PatientID', $prm['id'])
->update('m_patient');
$err = $this->db_smartone->error();
if ( $err['message'] != "" )
{
$this->sys_error_db("m_patient rows", $this->db_smartone);
return;
}
$id = $prm['id'];
// LOG FO
unset($prm['token']);
$ptn = json_encode($prm);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.EDIT', '{$ptn}', '{$this->sys_user['M_UserID']}')");
// save address
// $add = [
// 'M_PatientAddressM_PatientID' => $id,
// 'M_PatientAddressDescription' => $prm['M_PatientAddressDescription'],
// 'M_PatientAddressM_KelurahanID' => $prm['M_PatientAddressM_KelurahanID']
// ];
// $this->db_smartone->insert('m_patientaddress', $add);
// LOG FO
// $add = json_encode($add);
// $this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADDRESS.ADD', '{$add}', '0')");
// get
$r = $this->db_smartone->where('M_PatientID', $id)
->get('m_patient')
->row();
$rst = array("id" => $id, 'noreg'=>$r->M_PatientNoReg);
$this->sys_ok($rst);
}
public function search_idtype()
{
$prm = $this->sys_input;
$sql = "SELECT M_IdTypeID, M_IdTypeName
FROM m_idtype
WHERE M_IdTypeIsActive = 'Y'
ORDER BY M_IdTypeName ASC";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("records" => $rows);
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_idtype rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,217 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Payment API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function get_order() {
$prm = $this->sys_input;
$rst = ["order_header"=>[], "order_detail"=>[]];
$sql = "
select T_OrderHeaderID as order_id,
T_OrderHeaderLabNumber as order_no,
T_OrderHeaderDate as order_date,
T_OrderHeaderSubTotal as order_subtotal,
T_OrderHeaderRounding as order_rounding,
T_OrderHeaderTotal as order_total,
M_PatientName as patient_name,
M_PatientNoReg as patient_mr,
M_MouName as order_mou,
M_CompanyName as order_company
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID
join m_mou on T_OrderHeaderM_MouID = M_MouID
where T_OrderHeaderID = ?";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = (array) $query->row();
$rst['order_header'] = $rows;
// $result = array("status" => "OK" , "data" => $rst);
// $this->sys_ok($result);
// exit;
} else {
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
exit;
}
// { n:1, d_id:1, t_id:1, t_name:'SGOT', t_price:80000, t_disctotal:7000, t_total:73000 },
// { n:2, d_id:2, t_id:2, t_name:'SGPT', t_price:75000, t_disctotal:8000, t_total:67000 }
// T_OrderDetailPrice double [0]
// T_OrderDetailPriceForDisc double [0]
// T_OrderDetailDisc double [0]
// T_OrderDetailDiscAmount double [0]
// T_OrderDetailTotal
$sql = "
select T_OrderDetailID as d_id,
T_OrderDetailT_TestID as t_id,
T_OrderDetailT_TestName as t_name,
T_OrderDetailPrice as t_price,
T_OrderDetailDiscTotal as t_disctotal,
T_OrderDetailTotal as t_total
from t_orderdetail
where T_OrderDetailT_OrderHeaderID = ?
and T_ORderDetailIsActive = 'Y'";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = $query->result_array();
$rst['order_detail'] = $rows;
$result = array("status" => "OK" , "data" => $rst);
$this->sys_ok($result);
exit;
} else {
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
exit;
}
}
public function search()
{
$this->db_smartone = $this->load->database("onedev", true);
$prm = $this->sys_input;
$max_rst = 100;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_paymenttype
where M_PaymentTypeIsActive = 'Y'
and M_PaymentTypeName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_paymenttype count",$this->db_smartone);
exit;
}
$sql = "select M_PaymentTypeID payment_type_id, M_PaymentTypeName payment_type_name, M_PaymentTypeCode payment_type_code,
0 payment_amount, '' payment_note, 'Nomor Kartu' payment_note_label, 'N' payment_enable,
0 payment_change, 0 payment_actual, 0 payment_card_id, 0 payment_edc_id, 0 payment_account_id
from m_paymenttype
where M_PaymentTypeIsActive = 'Y'
and M_PaymentTypeName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v) {
if ($v['payment_type_code'] == 'CASH')
$v['payment_note_label'] = 'Kembali';
if ($v['payment_type_code'] == 'VOUCHER')
$v['payment_note_label'] = 'Nomor Voucher';
$rows[$k] = $v;
}
$result = $rows;
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_paymenttype rows",$this->db_smartone);
exit;
}
}
function save()
{
$prm = $this->sys_input;
$payment_json = json_encode($prm['payments']);
$sql = "CALL sp_fo_payment('{$prm['order_id']}', '{$payment_json}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
echo json_encode($rst);
}
else
{
$this->sys_error_db("save payment", $this->db_smartone);
exit;
}
}
function log_nota()
{
$prm = $this->sys_input;
$dblog = $this->load->database('onelog', true);
$p = $this->db_smartone->where('c_orderheaderid', $prm['order_id'])
->get('c_orderheader')
->row();
$uid = $this->sys_user['M_UserID'];
$q = $dblog->set("Log_ClinicUserID", $uid)
->set("Log_ClinicJson", json_encode(["order_id"=>$prm['order_id'], "patient_id"=>$p->C_OrderHeaderM_PatientID]))
->set("Log_ClinicCode", "CLINIC.PRINT.RECEIPT")
->insert('log_clinic');
if ($q) {
$id = $dblog->insert_id();
$this->sys_ok($id);
}
else {
$this->sys_error_db("LOG Nota",$this->db_smartone);
exit;
}
}
public function search_bank()
{
$prm = $this->sys_input;
// QUERY TOTAL
$sql = "SELECT Nat_BankID, Nat_BankName
FROM nat_bank ORDER BY Nat_BankName ASC";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$this->sys_ok(["records"=>$rows, "total"=>sizeof($rows)]);
}
else
{
$this->sys_error_db("NAT BANK",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
class Photo extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Photo API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
$this->load->library('ImageManipulator');
}
public function upload()
{
$inp = $this->sys_input;
$home_dir = "/home/one/Web/";
$target_dir = $home_dir . "one-media/one-photo/patient/" . date("Y") . "/";
$y = $this->regenerateOldPhoto($home_dir, $inp['id']);
// get patient mr
$p = $this->db_smartone->select("M_PatientNoReg")
->where("M_PatientID", $inp['id'])
->get('m_patient')
->row();
if (!file_exists($target_dir)) {
mkdir($target_dir, 0755, true);
}
$target_path = $target_dir . $p->M_PatientNoReg . ".jpg";
$this->base64_to_jpeg($inp['data'], $target_path);
// CROP Image
$im = new ImageManipulator($target_path);
$w = $im->getWidth();
$h = $im->getHeight();
$mw = ceil(3 * $h / 4);
if ($w <= $mw)
{
$x1 = 0;
$y1 = 0;
$x2 = $w;
$y2 = $h;
}
else
{
$x1 = floor(($w - $mw) / 2);
$y1 = 0;
$x2 = ceil($w - (($w - $mw) / 2));
$y2 = $h;
}
$im->crop($x1, $y1, $x2, $y2); // takes care of out of boundary conditions automatically
$im->save($target_path);
$x = $this->generateThumbnail($target_path, 75, 100);
// Save to DB
$this->db_smartone->set("M_PatientPhoto", "/" . str_replace($home_dir, "", $target_path))
->set("M_PatientPhotoThumb", "/" . str_replace($home_dir, "", $x))
->set('M_PatientPhotoCounter', '`M_PatientPhotoCounter` + 1', false)
->where('M_PatientID', $inp['id'])
->update('m_patient');
// LOGGING
$code = $y ? "PHOTO.PATIENT.EDIT" : "PHOTO.PATIENT.ADD";
$one_log = $this->load->database('onelog', true);
$one_log->set('Log_PhotoCode', $code)
->set('Log_PhotoM_PatientID', $inp['id'])
->set('Log_PhotoUrl', $y ? $y : "/" . str_replace($home_dir, "", $target_path))
->insert('log_photo');
$this->sys_ok(["rename"=>$y, "patient_id"=>$inp['id'], "patient_mr"=>$p->M_PatientNoReg, "photo_url"=>"http://" . $_SERVER['SERVER_NAME'] . "/" . str_replace($home_dir, "", $target_path) . "?d=" . date("YmdHis")]);
}
function base64_to_jpeg($base64_string, $output_file) {
// open the output file for writing
$ifp = fopen( $output_file, 'wb' );
// split the string on commas
// $data[ 0 ] == "data:image/png;base64"
// $data[ 1 ] == <actual base64 string>
$data = explode( ',', $base64_string );
// we could add validation here with ensuring count( $data ) > 1
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
// clean up the file resource
fclose( $ifp );
return $output_file;
}
function generateThumbnail($img, $width, $height, $quality = 90)
{
if (is_file($img)) {
$imagick = new Imagick(realpath($img));
$imagick->setImageFormat('jpeg');
$imagick->setImageCompression(Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality($quality);
$imagick->thumbnailImage($width, $height, false, false);
$filename_no_ext = reset(explode('.', $img));
if (file_put_contents($filename_no_ext . '_thumb' . '.jpg', $imagick) === false) {
throw new Exception("Could not put contents.");
}
return $filename_no_ext . '_thumb' . '.jpg';
}
else {
throw new Exception("No valid image provided with {$img}.");
}
}
function regenerateOldPhoto($home_dir, $id)
{
$r = $this->db_smartone->select('m_patientphoto, m_patientphotocounter', false)
->where('m_patientid', $id)
->get('m_patient')
->row();
if ($r->m_patientphoto != null && $r->m_patientphotocounter > 0) {
$full_path = substr_replace($home_dir ,"", -1) . $r->m_patientphoto;
$path_parts = pathinfo($full_path);
$rename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '-' . $r->m_patientphotocounter . '.' . $path_parts['extension'];
rename($full_path, $rename);
// echo $path_parts['dirname'], "\n";
// echo $path_parts['extension'], "\n";
// echo $path_parts['filename'], "\n";
return "/" . str_replace($home_dir, "", $rename);
}
return false;
}
}

View File

@@ -0,0 +1,409 @@
<?php
//diberi tambahan pembeda IsFromPanel
//utk contoh kasus yg ndak bisa di delete
//sementara profile di ambilkan dari panel juga dengan IsFromPanel = N
class Px extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Px API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function profile() {
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$sql = "select count(distinct T_TestPanelID) total
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_testpanel count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestPanelID
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ?
limit 0,20";
$query = $this->db_smartone->query($sql,$sql_param);
$xrows = $query->result_array();
$a_tpid = "-1";
foreach($xrows as $r) {
$a_tpid .= "," . $r["T_TestPanelID"];
}
$sql = "select distinct T_TestPanelID,T_TestPanelName,
T_TestID,T_TestName, 'N' IsFromPanel, T_TestRequirement,
t_testprice.*
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceM_MouCompanyID = ?
and T_TestPriceIsActive = 'Y'
where
T_TestPanelID in ( $a_tpid ) ";
$query = $this->db_smartone->query($sql,array($mouCompanyID));
$xrows = $query->result_array();
$rows = array();
$prev_tpanel_id = 0;
foreach($xrows as $r) {
$tpanel_id = $r["T_TestPanelID"];
if ($tpanel_id != $prev_tpanel_id) {
$rows[] = array(
"T_TestPanelID" => $r["T_TestPanelID"],
"T_TestPanelName" => $r["T_TestPanelName"],
"test" => array()
);
}
$idx = count($rows) - 1;
$rows[$idx]["test"][] = $r;
$prev_tpanel_id = $tpanel_id;
}
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function panel() {
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$sql = "select count(distinct T_TestPanelID) total
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_testpanel count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestPanelID
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ?
limit 0,20";
$query = $this->db_smartone->query($sql,$sql_param);
$xrows = $query->result_array();
$a_tpid = "-1";
foreach($xrows as $r) {
$a_tpid .= "," . $r["T_TestPanelID"];
}
$sql = "select distinct T_TestPanelID,T_TestPanelName,
T_TestID,T_TestName, 'Y' IsFromPanel,T_TestRequirement,
t_testprice.*
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceM_MouCompanyID = ?
and T_TestPriceIsActive = 'Y'
where
T_TestPanelID in ( $a_tpid )
order by T_TestPanelID";
$query = $this->db_smartone->query($sql,array($mouCompanyID));
$xrows = $query->result_array();
$rows = array();
$prev_tpanel_id = 0;
foreach($xrows as $r) {
$tpanel_id = $r["T_TestPanelID"];
if ($tpanel_id != $prev_tpanel_id) {
$rows[] = array(
"T_TestPanelID" => $r["T_TestPanelID"],
"T_TestPanelName" => $r["T_TestPanelName"],
"test" => array()
);
}
$idx = count($rows) - 1;
$rows[$idx]["test"][] = $r;
$prev_tpanel_id = $tpanel_id;
}
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function search_old()
{
$prm = $this->sys_input;
$search = $prm["search"];
$sql_param = array("%$search%");
$sql = "select count(distinct T_TestID) total
from
t_test
where
T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_company count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestID,T_TestName, 'N' IsFromPanel, T_TestRequirement
from
t_test
where
T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestName like ?
limit 0,20
";
$query = $this->db_smartone->query($sql, $sql_param);
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function search_v2()
{
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$query = $this->db_smartone->query("CALL sp_fo_px_count_v2(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["data"];
} else {
$this->sys_error_db("PX count", $this->db_smartone);
exit;
}
if (isset($prm['order_id']))
$query = $this->db_smartone->query("CALL sp_fo_px_search_byorder_v2(?, ?)", [$prm['order_id'], $mouCompanyID]);
else if ($search == "")
$query = $this->db_smartone->query("CALL sp_fo_px_search_favorite_v2(?, ?)", $sql_param);
else
$query = $this->db_smartone->query("CALL sp_fo_px_search_v2(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
// echo $this->db_smartone->last_query();
// $query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$id_to_remove = [];
// var_dump($rows);
foreach ($rows as $k => $v)
{
$rows[$k]['requirement'] = [];
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$v['T_TestID']}') x")
->row();
if ($x->x != null)
$rows[$k]['requirement'] = json_decode($x->x);
$rows[$k]['nat_test'] = json_decode($v['nat_test']);
$rows[$k]['child_test'] = json_decode($v['child_test']);
// IF PROFILE
if ($v['px_type'] == "PR" || $v['px_type'] == "PXR") {
if ($v['T_TestID'] == null)
{
$id_to_remove[] = $k;
continue;
}
else
{
foreach ($rows[$k]['child_test'] as $l => $w) {
$rows[$k]['child_test'][$l]->requirement = [];
$rows[$k]['child_test'][$l]->nat_test = json_decode($w->nat_test);
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$w->T_TestID}') x")
->row();
if ($x->x != null)
$rows[$k]['child_test'][$l]->requirement = json_decode($x->x);
}
}
}
}
// REMOVE INDEXES
foreach ($id_to_remove as $l => $w)
{ $x = $w - $l; array_splice($rows, $x, 1); }
$result = array("total" => $tot_count, "records" => (array) $rows, "query" => $sqlx, "query2" => $sqly );
$this->sys_ok($result);
exit;
}
}
public function search()
{
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$query = $this->db_smartone->query("CALL sp_fo_px_count(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["data"];
} else {
$this->sys_error_db("PX count", $this->db_smartone);
exit;
}
if (isset($prm['order_id']))
$query = $this->db_smartone->query("CALL sp_fo_px_search_byorder(?, ?)", [$prm['order_id'], $mouCompanyID]);
else if ($search == "")
$query = $this->db_smartone->query("CALL sp_fo_px_search_favorite(?, ?)", $sql_param);
else
$query = $this->db_smartone->query("CALL sp_fo_px_search(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
// echo $this->db_smartone->last_query();
// $query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$id_to_remove = [];
// var_dump($rows);
foreach ($rows as $k => $v)
{
$rows[$k]['requirement'] = [];
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$v['T_TestID']}') x")
->row();
if ($x->x != null)
$rows[$k]['requirement'] = json_decode($x->x);
$rows[$k]['nat_test'] = json_decode($v['nat_test']);
$rows[$k]['child_test'] = json_decode($v['child_test']);
// IF PROFILE
if ($v['px_type'] == "PR" || $v['px_type'] == "PXR") {
if ($v['T_TestID'] == null)
{
$id_to_remove[] = $k;
continue;
}
else
{
foreach ($rows[$k]['child_test'] as $l => $w) {
$rows[$k]['child_test'][$l]->requirement = [];
$rows[$k]['child_test'][$l]->nat_test = json_decode($w->nat_test);
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$w->T_TestID}') x")
->row();
if ($x->x != null)
$rows[$k]['child_test'][$l]->requirement = json_decode($x->x);
}
}
}
}
// REMOVE INDEXES
foreach ($id_to_remove as $l => $w)
{ $x = $w - $l; array_splice($rows, $x, 1); }
$result = array("total" => $tot_count, "records" => (array) $rows, "query" => $sqlx, "query2" => $sqly );
$this->sys_ok($result);
exit;
}
}
function get_price()
{
$prm = $this->sys_input;
$r = [];
$sql_param = array($prm['test_id'], date('Y-m-d'), $prm['cito'], $prm['mou_id']);
$sql = "select fn_price(?, ?, ?, ?) as price";
$query = $this->db_smartone->query($sql, $sql_param);
if ($query) {
$r = $query->result_array()[0];
$r = json_decode($r['price']);
$this->sys_ok($r);
exit;
} else {
$this->sys_error_db("get price", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Religion extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Religion API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_religion
where M_ReligionIsActive = 'Y'
and M_ReligionName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_religion count",$this->db_smartone);
exit;
}
$sql = "select M_ReligionID, M_ReligionName
from m_religion
where M_ReligionIsActive = 'Y'
and M_ReligionName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_religion rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
class Sex extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Sex API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_sex
where M_SexIsActive = 'Y'
and M_SexName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_sex count",$this->db_smartone);
exit;
}
$sql = "select M_SexID, M_SexName, '' as title
from m_sex
left join m_title on m_titlem_sexid = m_sexid and m_titleisactive = 'Y'
where M_SexIsActive = 'Y'
and M_SexName like ?
group by m_sexid
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v){
$sql = "SELECT M_TitleID, M_TitleName
FROM m_title
WHERE
M_TitleM_SexID = {$v['M_SexID']} AND M_TitleIsActive = 'Y'
ORDER BY M_TitleOrder ASC
";
$titles = $this->db_smartone->query($sql)->result_array();
$rows[$k]['title'] = $titles;
}
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_sex rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,72 @@
<?php
class Sex extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Sex API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_sex
where M_SexIsActive = 'Y'
and M_SexName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_sex count",$this->db_smartone);
exit;
}
$sql = "select M_SexID, M_SexName, concat('[', group_concat(json_object('M_TitleID', M_TitleID, 'M_TitleName', M_TitleName) separator ','), ']') as title
from m_sex
left join m_title on m_titlem_sexid = m_sexid and m_titleisactive = 'Y'
where M_SexIsActive = 'Y'
and M_SexName like ?
group by m_sexid
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['title'] = json_decode($v['title']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_sex rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,71 @@
<?php
class Title extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Title API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%',
'sex_id' => 0
];
if ($prm['search'] != '')
$q['search'] = "%{$prm['search']}%";
if ($prm['sex_id'] != '')
$q['sex_id'] = $prm['sex_id'];
// QUERY TOTAL
$sql = "select count(*) total
from
m_title
where M_TitleIsActive = 'Y'
and M_TitleName like ?
and ((M_TitleM_SexID = {$q['sex_id']} and {$q['sex_id']} <> 0) or {$q['sex_id']} = 0)";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_sex count",$this->db_smartone);
exit;
}
$sql = "select M_SexID, M_SexName
from m_sex
where M_SexIsActive = 'Y'
and M_SexName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_sex rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,135 @@
<?php
class Order extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "ORDER API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
function save()
{
$prm = $this->sys_input;
$prm['header']['complaint'] = str_replace(PHP_EOL, '<br>', $prm['header']['complaint']);
$prm['header']['suggestion'] = str_replace(PHP_EOL, '<br>', $prm['header']['suggestion']);
$header_json = json_encode($prm['header']);
$header_json = str_replace("\\", "\\\\", "$header_json");
$lab_json = json_encode($prm['lab']);
$med_json = json_encode($prm['med']);
$server = "http";
$uid = $this->sys_user['M_UserID'];
$sql = "CALL sp_clinic_poly_save('{$prm['order_id']}', '{$header_json}', '{$med_json}', '{$lab_json}', '{$uid}');";
$query = $this->db_smartone->query($sql);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
if ($rst->data->is_lab == "Y" && $rst->status == "OK")
{
// persiapkan curl
$ch = curl_init();
// set url
global $_SERVER;
$current_host = $_SERVER["SERVER_ADDR"];
if ($server == "https")
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "{$server}://{$current_host}:9090/ticket/UMUM");
//file_put_contents("/xtmp/url", "{$server}://{$current_host}:9090/ticket/UMUM" );
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = json_decode(curl_exec($ch));
// tutup curl
curl_close($ch);
// menampilkan hasil curl
// echo $output;
if ($output != null)
if ($output->status == "OK") {
$rst->data->queue = $output->data[0]->number;
$x = json_encode($output->data[0]);
$sql = "CALL sp_clinic_fo_labqueue('{$rst->data->id}', '{$rst->data->queue}', '{$x}');";
$query = $this->db_smartone->query($sql);
}
}
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
function process()
{
$prm = $this->sys_input;
$sql = "CALL sp_clinic_poly_process('{$prm['order_id']}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
function get_one()
{
$prm = $this->sys_input;
$sql = "select *
from c_orderheader
where C_OrderHeaderID = ?";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = $query->row();
$rows->C_OrderHeaderQueueJSON = json_decode($rows->C_OrderHeaderQueueJSON);
$result = $rows;
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient get",$this->db_smartone);
exit;
}
}
function clean_mysqli_connection( $dbc )
{
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
unset($result);
}
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
/*
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'nolab' => '%',
'noreg' => '%',
'name' => '%',
'hp' => '%',
'dob' => '%',
'address' => '%',
'status' => 0
];
if ($prm['noreg'] != '')
$q['noreg'] = "%{$prm['noreg']}%";
if ($prm['nolab'] != '')
$q['nolab'] = "%{$prm['nolab']}%";
if ($prm['status'] != '')
$q['status'] = $prm['status'];
if ($prm['search'] != '')
{
$e = explode('+', $prm['search']);
if (isset($e[0]))
$q['name'] = "%{$e[0]}%";
if (isset($e[1]))
$q['hp'] = "%{$e[1]}%";
if (isset($e[2]))
$q['dob'] = "%{$e[2]}%";
if (isset($e[3]))
$q['address'] = "%{$e[3]}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from c_orderheader
join one.m_patient on c_orderheaderm_patientid = m_patientid
join one.m_title on M_PatientM_TitleID = M_TitleID
where C_OrderHeaderNumber like ?
and M_PatientName LIKE ?
and M_PatientHP LIKE ?
and M_PatientDOB LIKE ?
and C_OrderHeaderIsActive = 'Y'
and ((C_OrderHeaderM_StatusID = ? and ? <> 0) or C_OrderHeaderM_StatusID = 0)";
$query = $this->db_smartone->query($sql, array($q['nolab'], $q['name'], $q['hp'], $q['dob'], $q['status'], $q['status']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
// set locales
$this->db_smartone->query("SET @@lc_time_names = 'id_ID'");
$sql = "select M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) M_PatientName,
M_PatientHP, M_PatientDOB, M_PatientNote, 'X' as M_PatientAddress,
M_PatientNote, C_OrderHeaderID, C_OrderHeaderNumber, M_StatusCode,
C_OrderHeaderM_PatientAge, C_OrderHeaderComplaint, C_OrderHeaderIsLab, C_OrderHeaderIsReceipt,
C_OrderHeaderDate, dayname(C_OrderHeaderDate) `day`
from c_orderheader
join one.m_patient on c_orderheaderm_patientid = m_patientid
join one.m_title on M_PatientM_TitleID = M_TitleID
join m_status on c_orderheaderm_statusid = m_statusid
where C_OrderHeaderNumber like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and M_PatientDOB LIKE ?
and C_OrderHeaderIsActive = 'Y'
and ((C_OrderHeaderM_StatusID = ? and ? <> 0) or C_OrderHeaderM_StatusID = 0)
limit 0,{$max_rst}";
$query = $this->db_smartone->query($sql, array($q['nolab'], $q['name'], $q['hp'], $q['dob'], $q['status'], $q['status']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Status extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "STATUS API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_status
where M_StatusIsActive = 'Y'
and M_StatusName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_status count",$this->db_smartone);
exit;
}
$sql = "select M_StatusID, M_StatusName
from m_status
where M_StatusIsActive = 'Y'
and M_StatusName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// $rows = $rows;
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_status rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
### Auth API
- Functions
- login x
- logout
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Auth extends MY_Controller {
var $db_onedev;
public function index()
{
echo "AUTH API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function isLogin() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
} else {
$prm = $this->sys_input;
$data = array(
"user" => $this->sys_user
);
$this->sys_ok($data);
}
}
function login() {
$prm = $this->sys_input;
try {
//existing password enc
$sm_password = md5($this->one_salt . $prm["password"] .
$this->one_salt);
$query = $this->db_onedev->query("select M_UserID, M_UserUsername,
M_UserGroupDashboard
from m_user
join m_usergroup on m_userm_usergroupid = m_usergroupid
where M_UserUsername=? and M_UserPassword=?
and M_UserIsActive = 'Y'
",array($prm["username"], $sm_password));
echo $query;
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$rows = $query->result_array();
if (count($rows) > 0 ) {
$user = $rows[0];
$user['M_UserGroupDashboard'] = "https://{$_SERVER['SERVER_NAME']}/{$user['M_UserGroupDashboard']}";
$token = JWT::encode($user,$this->SECRET_KEY);
$data = array(
"user" => $user,
"token" => $token
);
$query = $this->db_onedev->query("update m_user SET M_UserIsLoggedIn = 'Y', M_UserLastAccess = now() WHERE M_UserID = ?
",array($user['M_UserID']));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$this->sys_error_db("Invalid UserName / Password");
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function logout() {
$this->sys_error("ok");
}
}
?>

View File

@@ -0,0 +1,134 @@
<?php
class Close extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$startdate = $prm['startdate'] . " 00:00:01";
$enddate = $prm['enddate'] . " 23:59:59";
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = " ( F_PaymentKasirDate BETWEEN '{$startdate}' AND '{$enddate}' ) AND ";
if($search != '')
$where = "( F_PaymentKasirNumber LIKE '%{$search}%') AND ";
$sql = " SELECT count(*) as total
FROM f_payment_kasir
WHERE
$where
( ('{$status}' = 'N' AND (F_PaymentKasirIsReceived = 'N' )) OR ('{$status}' = 'Y' AND F_PaymentKasirIsReceived = 'Y') )";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$sql = "SELECT F_PaymentKasirID ,
F_PaymentKasirNumber ,
date_format(F_PaymentKasirDate,'%d-%m-%Y %T') as F_PaymentKasirDate ,
F_PaymentKasirCreated ,
F_PaymentKasirLastUpdated ,M_StaffName,
if(F_PaymentKasirIsReceived = 'N','Belum Diterima' ,'Sudah diterima') as F_PaymentKasirIsReceived ,
F_PaymentKasirIsActive
FROM f_payment_kasir
JOIN m_user on F_PaymentKasirUserID = M_UserID
join m_staff on M_UserM_StaffID = M_StaffID
WHERE
$where
( ('{$status}' = 'N' AND (F_PaymentKasirIsReceived = 'N' )) OR ('{$status}' = 'Y' AND F_PaymentKasirIsReceived = 'Y') )
ORDER BY F_PaymentKasirID asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['F_PaymentKasirID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function save()
{
//# ambil parameter input
$prm = $this->sys_input;
$puserid = $prm['pUserID'];
$sql = "CALL sp_fo_send_to_cashier({$puserid})";
$query = $this->db_onedev->query($sql);
if ($query) {
$result = array();
$this->sys_ok($result);
}
else {
$this->sys_error_db("payment save rows", $this->db_onedev);
exit;
}
}
public function savetutup()
{
//# ambil parameter input
$prm = $this->sys_input;
$ppaymentkasirid = $prm['pPaymentKasirID'];
$puserid = $prm['pUserID'];
$sql = "CALL sp_fo_received_cashier('{$ppaymentkasirid}','{$puserid}')";
//$sql = "CALL sp_fo_send_to_cashier({$puserid})";
$query = $this->db_onedev->query($sql);
if ($query) {
$result = array();
$this->sys_ok($result);
}
else {
$this->sys_error_db("payment savetutup rows", $this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
F_PaymentID as note_id,
F_PaymentDate as note_date,
F_PaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_PaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_PaymentDetailIsActive as note_active
FROM f_payment
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
WHERE
F_PaymentT_OrderHeaderID = {$orderid}
GROUP BY F_PaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$startdate = $prm['startdate'] . " 00:00:01";
$enddate = $prm['enddate'] . " 23:59:59";
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = " ( T_OrderHeaderDate BETWEEN '{$startdate}' AND '{$enddate}' ) AND ";
if($search != '')
$where = "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
$sql = " SELECT count(*) as total
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') )";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$janji = T_OrderPromiseDateTime;
$janji_hasil = Date_format($janji, "d-m-Y H:i:s");
$sql = "SELECT t_orderheader.*,T_OrderHeaderIsCito as cito,
M_PatientNoReg,
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
M_TitleName,
M_CompanyName,
M_MouName,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
IFNULL(Last_StatusPaymentUnpaid,T_OrderHeaderTotal)as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
'' as notes,
M_MouMinDP as mindp_percent,
GROUP_CONCAT(distinct concat(T_OrderDetailT_TestName,'^',T_OrderDetailIsCito) SEPARATOR ',') as test ,
fn_report_promise_list(T_OrderHeaderID) as janji,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount,
case
when Last_StatusPaymentPaid = '0' then 'BELUM BAYAR'
when Last_StatusPaymentIsLunas = 'Y' then 'LUNAS'
when Last_StatusPaymentIsLunas = 'N' then 'BELUM LUNAS' ELSE '' END as status,
GROUP_CONCAT(distinct M_DeliveryName SEPARATOR ' , ') as delivery
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') )
group by T_OrderHeaderID
ORDER BY `fn_get_cito`(T_OrderHeaderID),T_OrderPromiseDateTime asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['T_OrderHeaderID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,440 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
F_PaymentID as note_id,
F_PaymentDate as note_date,
F_PaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_PaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_PaymentDetailIsActive as note_active
FROM f_payment
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
WHERE
F_PaymentT_OrderHeaderID = {$orderid}
GROUP BY F_PaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search_v2()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$filter = $prm['filter'];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 20;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "";
if($search != '')
$where .= "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
if($filter == 'day')
$where .= " DATE(T_OrderHeaderDate) = CURDATE() AND ";
if($filter == 'notsampled')
$where .= " Last_StatusM_StatusID < 7 AND ";
$sql = " SELECT count(*) as total
FROM(
SELECT T_OrderHeaderID
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
(
('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL))
OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
)x";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$janji = T_OrderPromiseDateTime;
$janji_hasil = Date_format($janji, "d-m-Y H:i:s");
$sql ="
set @counter = 0;
SELECT @counter := @counter +1 no_urut,
t_orderheader.*,T_OrderHeaderIsCito as cito,
M_PatientNoReg,
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
M_CompanyName,
M_MouName,
DATE(T_OrderHeaderDate) as order_date,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
IFNULL(Last_StatusPaymentUnpaid,T_OrderHeaderTotal)as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
Last_StatusM_StatusID as last_status,
'' as notes,
M_MouMinDP as mindp_percent,
GROUP_CONCAT(distinct concat(T_OrderDetailT_TestName,'^',T_OrderDetailIsCito) SEPARATOR ',') as test ,
fn_report_promise_list(T_OrderHeaderID) as janji,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount,
case
when Last_StatusPaymentPaid = '0' then 'BELUM BAYAR'
when Last_StatusPaymentIsLunas = 'Y' then 'LUNAS'
when Last_StatusPaymentIsLunas = 'N' then 'BELUM LUNAS' ELSE ''
END as status,
GROUP_CONCAT(distinct M_DeliveryName SEPARATOR ' , ') as delivery
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
ORDER BY `fn_get_cito`(T_OrderHeaderID),T_OrderPromiseDateTime asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
/*if($rows){
foreach($rows as $k => $v){
$sql = "SELECT * FROM t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID";
$rows[$k]['result_promise'] = $this->add_notes($v['T_OrderHeaderID']);
}
}*/
$result = array("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$filter = $prm['filter'];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 20;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "";
if($search != '')
$where .= "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
if($filter == 'day')
$where .= " DATE(T_OrderHeaderDate) = CURDATE() AND ";
if($filter == 'notsampled')
$where .= " Last_StatusM_StatusID < 7 AND ";
$sql = " SELECT count(*) as total
FROM(
SELECT T_OrderHeaderID
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
(
('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL))
OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
)x";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$janji = T_OrderPromiseDateTime;
$janji_hasil = Date_format($janji, "d-m-Y H:i:s");
$sql = "SELECT '' as rownumber,t_orderheader.*,T_OrderHeaderIsCito as cito,
M_PatientNoReg,
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
M_CompanyName,
M_MouName,
DATE(T_OrderHeaderDate) as order_date,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
IFNULL(Last_StatusPaymentUnpaid,T_OrderHeaderTotal)as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
Last_StatusM_StatusID as last_status,
'' as notes,
M_MouMinDP as mindp_percent,
GROUP_CONCAT(distinct concat(T_OrderDetailT_TestName,'^',T_OrderDetailIsCito) SEPARATOR ',') as test ,
fn_report_promise_list(T_OrderHeaderID) as janji,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount,
case
when Last_StatusPaymentPaid = '0' then 'BELUM BAYAR'
when Last_StatusPaymentIsLunas = 'Y' then 'LUNAS'
when Last_StatusPaymentIsLunas = 'N' then 'BELUM LUNAS' ELSE ''
END as status,
GROUP_CONCAT(distinct M_DeliveryName SEPARATOR ' , ') as delivery,
fn_lookup_external(T_OrderHeaderLabNumber,'L') as external_numbering
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
ORDER BY `fn_get_cito`(T_OrderHeaderID),T_OrderPromiseDateTime asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$xno = ($k + 1) + $number_offset;
$rows[$k]['rownumber'] = $xno;
}
}
$result = array("total" => $tot_page,"total_all"=>$tot_count, "total_filter"=>count($rows),"records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function lookup_promises(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$sql = "SELECT T_OrderPromiseID as id, DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y') as xdate, TIME_FORMAT(T_OrderPromiseDateTime,'%H:%i') as xtime
FROM t_orderpromise
WHERE T_OrderPromiseT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderPromiseIsActive = 'Y'";
//echo $sql;
$query = $this->db_onedev->query($sql)->result_array();
if (!$query) {
$this->sys_error_db("f_paymentdetail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => $query
);
$this->sys_ok($result);
exit;
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id,
'barcode' as type,
T_SampleTypeID,
T_BarcodeLabID,
T_BarcodeLabBarcode,
T_BarcodeLabT_OrderHeaderID as orderid,
T_BarcodeLabCounter,
T_SampleTypeName,
'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = ''
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0 as T_SampleTypeID,0 as T_BarcodeLabID,T_OrderHeaderLabNumber as T_BarcodeLabBarcode,{$prm['T_OrderHeaderID']}, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
UNION
SELECT T_TestID as id,
'nonlab' as type,
T_OrderDetailID as detail_id,
'' as xxx,
'-' as T_BarcodeLabBarcode,
T_OrderHeaderID as order_id,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
T_TestName as T_SampleTypeName,
'N' as chex
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName <> 'lab'
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY T_TestID
UNION
SELECT T_OrderDetailID as id,
'nonlab_group' as type,
T_OrderDetailID as detail_id,
'' as xxx,
GROUP_CONCAT(T_TestName separator ' , ') as T_BarcodeLabBarcode,
T_OrderHeaderID as order_id,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
'Amplop Besar' as T_SampleTypeName,
'N' as chex
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName <> 'lab'
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY T_OrderHeaderID
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_promises(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
foreach($prm['data'] as $k => $v){
$xdatetime = date('Y-m-d H:i:s',strtotime($v['xdate'].' '.$v['xtime']));
$sql = "UPDATE t_orderpromise SET T_OrderPromiseDateTime = '{$xdatetime}' WHERE T_OrderPromiseID = {$v['id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_paymentdetail delete");
exit;
}
}
$sql = "UPDATE t_orderheaderaddon SET T_OrderHeaderAddonIsComing = 'Y'WHERE T_OrderHeaderAddOnT_OrderHeaderID = {$prm['orderid']} AND T_OrderHeaderAddOnIsActive = 'Y'";
$this->db_onedev->query($sql);
$result = array(
"total" => 1 ,
"records" => $prm
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,462 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function scan_patient_checkout(){
$prm = $this->sys_input;
$sql = "SELECT * FROM t_orderheader WHERE T_OrderHeaderLabNumber = ?";
$query = $this->db_onedev->query($sql,array([$prm['labnumber']]));
if (!$query) {
$this->sys_error_db("data patient");
exit;
}
$data_patient = $query->row_array();
//print_r($data_patient);
$result = $this->get_patient($prm['labnumber'],$data_patient['T_OrderHeaderID']);
$this->sys_ok($result);
exit;
}
function search_patient(){
$prm = $this->sys_input;
$result = $this->get_patient($prm['noreg'],$prm['order_id']);
$this->sys_ok($result);
exit;
}
function get_patient($labnumber,$orderid){
//# ambil parameter input
$data_patient = [];
$sql = "
SELECT DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
T_OrderHeaderLabNumber as labnumber,
T_OrderHeaderM_PatientAge as patient_age,
M_PatientName as patient_name,
M_PatientNoReg as noreg,
IF(M_PatientGender = 'male','Laki-laki','Perempuan') as gender,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
M_PatientJob as job,
M_PatientPosisi as posisi,
IF(M_PatientDivisi = '','-',M_PatientDivisi) as divisi,
M_PatientHp as hp,
M_PatientEmail as email,
M_PatientNIP as nip,
CorporateName as corporate_name,
M_PatientPhoto as photo
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN corporate ON T_OrderHeaderCorporateID = CorporateID
WHERE
T_OrderHeaderID = {$orderid} AND T_OrderHeaderLabNumber = '{$labnumber}'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data patient");
exit;
}
$data_patient = $query->row_array();
$data_packet = [];
$sql = "
SELECT T_PacketName as packet_name,
T_PacketID as packet_id,
'' as active,
'' as details
FROM t_orderdetailorder
JOIN t_packet ON T_OrderDetailOrderT_PacketID = T_PacketID
WHERE
T_OrderDetailOrderT_OrderHeaderID = {$orderid} AND
T_OrderDetailOrderIsPacket = 'Y' AND
T_OrderDetailOrderIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data packet");
exit;
}
$data_packet = $query->result_array();
if($data_packet){
foreach ($data_packet as $key => $value) {
$data_packet[$key]['active'] = false;
$sql = "SELECT T_TestName as test_name
FROM t_packetdetail
JOIN t_test ON T_PacketDetailT_TestID = T_TestID
WHERE T_PacketDetailT_PacketID = {$value['packet_id']} AND T_PacketDetailIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data packet detail");
exit;
}
$data_packet_details = $query->result_array();
if(count($data_packet_details) > 0)
$data_packet[$key]['details'] = $data_packet_details;
else
$data_packet[$key]['details'] = [];
}
}
$data_tests = [];
$sql = "
SELECT T_TestName as test_name
FROM t_orderdetailorder
JOIN t_test ON T_OrderDetailOrderT_TestID = T_TestID
WHERE
T_OrderDetailOrderT_OrderHeaderID = {$orderid} AND
T_OrderDetailOrderIsPacket = 'N' AND
T_OrderDetailOrderIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data tests");
exit;
}
$data_tests = $query->result_array();
$data_sample_lab = [];
$sql = "
SELECT T_SampleTypeName as sampletype_name,
T_OrderSampleBarcode as barcode,
IF(ISNULL(T_OrderSampleSamplingDate),'Belum diambil',DATE_FORMAT(T_OrderSampleSamplingDate,'%d-%m-%Y')) as sampling_date,
IF(ISNULL(T_OrderSampleSamplingTime),'',T_OrderSampleSamplingTime) as sample_time,
IF(ISNULL(T_OrderSampleReceiveDate),'Belum dilakukan',DATE_FORMAT(T_OrderSampleReceiveDate,'%d-%m-%Y')) as receive_date,
IF(ISNULL(T_OrderSampleReceiveTime),'',DATE_FORMAT(T_OrderSampleReceiveTime,'%H:%i')) as receive_time,
T_OrderSampleSampling as is_sampling,
T_OrderSampleReceive as is_received,
IFNULL(M_StaffName,'') as staff_name
FROM t_ordersample
JOIN t_sampletype ON T_OrderSampleT_SampleTypeID = T_SampleTypeID
LEFT JOIN m_user ON T_OrderSampleReceiveUserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
WHERE
T_OrderSampleT_OrderHeaderID = {$orderid} AND
T_OrderSampleIsActive = 'Y'
Order BY T_SampleTypeName ASC
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data sample lab");
exit;
}
$data_sample_lab = $query->result_array();
$data_sample_radiodiagnostic = [];
$sql = "
SELECT T_TestName as sampletype_name,
T_OrderHeaderLabNumber as barcode,
IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date,
IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time,
IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date,
IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time,
IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling,
IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received,
IFNULL(M_StaffName,'') as staff_name
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsNonLab = 'RADIODIAGNOSTIC'
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_SamplingSoT_TestID = T_TestID
LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND
T_OrderDetailIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data sample radiodiagnostic");
exit;
}
$data_sample_radiodiagnostic = $query->result_array();
$data_sample_electromedic = [];
$sql = "
SELECT T_TestName as sampletype_name,
T_OrderHeaderLabNumber as barcode,
IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date,
IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time,
IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date,
IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time,
IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling,
IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received,
IFNULL(M_StaffName,'') as staff_name
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsNonLab = 'ELEKTROMEDIS'
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_SamplingSoT_TestID = T_TestID
LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND
T_OrderDetailIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data sample electromedis");
exit;
}
$data_sample_electromedic = $query->result_array();
$data_sample_other = [];
$sql = "
SELECT T_TestName as sampletype_name,
T_OrderHeaderLabNumber as barcode,
IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date,
IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time,
IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date,
IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time,
IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling,
IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received,
IFNULL(M_StaffName,'') as staff_name
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsNonLab = 'OTHERS'
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_SamplingSoT_TestID = T_TestID
LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND
T_OrderDetailIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data sample other");
exit;
}
$data_sample_other = $query->result_array();
$sql = "
SELECT COUNT(*) as xcount,
IF(T_SurveyID IS NULL, 'N','Y') as is_sampling,
IF(T_SurveyID IS NULL, 'N','Y') as is_received,
IFNULL(DATE_FORMAT(T_SurveyCreated,'%d-%m-%Y'),'Klik untuk mengisi survey') as xcreated_date, IFNULL(DATE_FORMAT(T_SurveyCreated,'%H:%i'),'') as xcreated_time
FROM t_orderheader
LEFT JOIN t_survey ON T_OrderHeaderID = T_SurveyT_OrderHeaderID AND
T_SurveyIsActive = 'Y'
WHERE
T_OrderHeaderID = {$orderid} AND T_OrderHeaderLabNumber = '{$labnumber}'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data exist");
exit;
}
$data_exist = $query->row();
$data_survey = [];
if($data_exist->xcount > 0){
$status = "SUCCESS";
$data_survey = [
"sampletype_name" => "Survey",
"barcode" => $labnumber,
"sampling_date" => $data_exist->xcreated_date,
"sample_time" => $data_exist->xcreated_time,
"receive_date" => $data_exist->xcreated_date,
"receive_time" => $data_exist->xcreated_time,
"is_sampling" => $data_exist->is_sampling,
"is_received" => $data_exist->is_received
];
}
$result = array(
"data_patient" => $data_patient?$data_patient:[],
"data_packet" => $data_packet? $data_packet:[],
"data_tests" => $data_tests?$data_tests:[],
"data_sample_lab" => $data_sample_lab?$data_sample_lab:[],
"data_sample_radiodiagnostic" => $data_sample_radiodiagnostic?$data_sample_radiodiagnostic:[],
"data_sample_electromedic" => $data_sample_electromedic?$data_sample_electromedic:[],
"data_sample_other" => $data_sample_other?$data_sample_other:[],
"data_survey" => $data_survey
);
return $result;
}
function load_survey(){
//# ambil parameter input
$prm = $this->sys_input;
$status = "FORM";
$results = [];
$sql = "
SELECT COUNT(*) as xcount
FROM t_survey
JOIN t_orderheader ON T_OrderHeaderID = T_SurveyT_OrderHeaderID AND T_OrderHeaderID = {$prm['order_id']} AND T_OrderHeaderLabNumber = '{$prm['noreg']}'
WHERE
T_SurveyIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data exist");
exit;
}
$data_exist = $query->row()->xcount;
if($data_exist > 0){
$status = "SUCCESS";
}else{
$sql = "
SELECT COUNT(*) as xcount
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['order_id']} AND
T_OrderHeaderLabNumber = '{$prm['noreg']}' AND
T_OrderHeaderIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data patient");
exit;
}
$data_exist_patient = $query->row()->xcount;
if($data_exist_patient == 0){
$status = "PATIENT_NOT_FOUND";
}else{
$sql = "
SELECT M_SurveyID as id,
M_SurveyName as name,
'' as value
FROM m_survey
WHERE
M_SurveyIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data survey");
exit;
}
$results = $query->result_array();
}
}
$result = array(
"records" => $results,
"status" => $status
);
$this->sys_ok($result);
exit;
}
function save_survey(){
//# ambil parameter input
$prm = $this->sys_input;
$status = "FORM";
$results = [];
$sql = "
INSERT INTO t_survey (
T_SurveyT_OrderHeaderID,
T_SurveySaran,
T_SurveyCreated
)
VALUES( ?, ?, NOW())
";
//echo $sql;
$query = $this->db_onedev->query($sql,array(
$prm['order_id'],
$prm['saran']
));
if (!$query) {
$this->sys_error_db("insert header");
exit;
}
$header_id = $this->db_onedev->insert_id();
foreach ($prm['surveys'] as $key => $value) {
$sql = "
INSERT INTO t_surveydetail (
T_SurveryDetailT_SurveyID,
T_SurveryDetailM_SurveyID,
T_SurveryDetailValue,
T_SurveryDetailCreated
)
VALUES(
?,?,?,NOW()
)
";
//echo $sql;
$query = $this->db_onedev->query($sql,array(
$header_id,
$value['id'],
$value['value']
));
if (!$query) {
//echo $this->db_onedev->last_query();
$this->sys_error_db("insert detail ");
exit;
}
}
$status = "SUCCESS";
$result = array(
"status" => $status
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,435 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function search_patient(){
//# ambil parameter input
$prm = $this->sys_input;
$data_patient = [];
$sql = "
SELECT DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i') as order_date,
T_OrderHeaderLabNumber as labnumber,
T_OrderHeaderM_PatientAge as patient_age,
M_PatientName as patient_name,
M_PatientNoReg as noreg,
IF(M_PatientGender = 'male','Laki-laki','Perempuan') as gender,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
M_PatientJob as job,
M_PatientPosisi as posisi,
IF(M_PatientDivisi = '','-',M_PatientDivisi) as divisi,
M_PatientHp as hp,
M_PatientEmail as email,
M_PatientNIP as nip,
CorporateName as corporate_name,
M_PatientPhoto as photo
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN corporate ON T_OrderHeaderCorporateID = CorporateID
WHERE
T_OrderHeaderID = {$prm['order_id']} AND T_OrderHeaderLabNumber = '{$prm['noreg']}'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data patient");
exit;
}
$data_patient = $query->row_array();
$data_packet = [];
$sql = "
SELECT T_PacketName as packet_name,
T_PacketID as packet_id,
'' as active,
'' as details
FROM t_orderdetailorder
JOIN t_packet ON T_OrderDetailOrderT_PacketID = T_PacketID
WHERE
T_OrderDetailOrderT_OrderHeaderID = {$prm['order_id']} AND
T_OrderDetailOrderIsPacket = 'Y' AND
T_OrderDetailOrderIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data packet");
exit;
}
$data_packet = $query->result_array();
if($data_packet){
foreach ($data_packet as $key => $value) {
$data_packet[$key]['active'] = false;
$sql = "SELECT T_TestName as test_name
FROM t_packetdetail
JOIN t_test ON T_PacketDetailT_TestID = T_TestID
WHERE T_PacketDetailT_PacketID = {$value['packet_id']} AND T_PacketDetailIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data packet detail");
exit;
}
$data_packet_details = $query->result_array();
if(count($data_packet_details) > 0)
$data_packet[$key]['details'] = $data_packet_details;
else
$data_packet[$key]['details'] = [];
}
}
$data_tests = [];
$sql = "
SELECT T_TestName as test_name
FROM t_orderdetailorder
JOIN t_test ON T_OrderDetailOrderT_TestID = T_TestID
WHERE
T_OrderDetailOrderT_OrderHeaderID = {$prm['order_id']} AND
T_OrderDetailOrderIsPacket = 'N' AND
T_OrderDetailOrderIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data tests");
exit;
}
$data_tests = $query->result_array();
$data_sample_lab = [];
$sql = "
SELECT T_SampleTypeName as sampletype_name,
T_OrderSampleBarcode as barcode,
IF(ISNULL(T_OrderSampleSamplingDate),'Belum diambil',DATE_FORMAT(T_OrderSampleSamplingDate,'%d-%m-%Y')) as sampling_date,
IF(ISNULL(T_OrderSampleSamplingTime),'',T_OrderSampleSamplingTime) as sample_time,
IF(ISNULL(T_OrderSampleReceiveDate),'Belum dilakukan',DATE_FORMAT(T_OrderSampleReceiveDate,'%d-%m-%Y')) as receive_date,
IF(ISNULL(T_OrderSampleReceiveTime),'',DATE_FORMAT(T_OrderSampleReceiveTime,'%H:%i')) as receive_time,
T_OrderSampleSampling as is_sampling,
T_OrderSampleReceive as is_received,
IFNULL(M_StaffName,'') as staff_name
FROM t_ordersample
JOIN t_sampletype ON T_OrderSampleT_SampleTypeID = T_SampleTypeID
LEFT JOIN m_user ON T_OrderSampleReceiveUserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
WHERE
T_OrderSampleT_OrderHeaderID = {$prm['order_id']} AND
T_OrderSampleIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data sample lab");
exit;
}
$data_sample_lab = $query->result_array();
$data_sample_radiodiagnostic = [];
$sql = "
SELECT T_TestName as sampletype_name,
T_OrderHeaderLabNumber as barcode,
IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date,
IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time,
IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date,
IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time,
IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling,
IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received,
IFNULL(M_StaffName,'') as staff_name
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsNonLab = 'RADIODIAGNOSTIC'
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_SamplingSoT_TestID = T_TestID
LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['order_id']} AND
T_OrderDetailIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data sample radiodiagnostic");
exit;
}
$data_sample_radiodiagnostic = $query->result_array();
$data_sample_electromedic = [];
$sql = "
SELECT T_TestName as sampletype_name,
T_OrderHeaderLabNumber as barcode,
IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date,
IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time,
IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date,
IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time,
IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling,
IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received,
IFNULL(M_StaffName,'') as staff_name
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsNonLab = 'ELEKTROMEDIS'
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_SamplingSoT_TestID = T_TestID
LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['order_id']} AND
T_OrderDetailIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data sample electromedis");
exit;
}
$data_sample_electromedic = $query->result_array();
$data_sample_other = [];
$sql = "
SELECT T_TestName as sampletype_name,
T_OrderHeaderLabNumber as barcode,
IF(ISNULL(T_SamplingSoProcessDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoProcessDate,'%d-%m-%Y')) as sampling_date,
IF(ISNULL(T_SamplingSoProcessTime),'',T_SamplingSoProcessTime) as sample_time,
IF(ISNULL(T_SamplingSoDoneDate),'Belum dilakukan',DATE_FORMAT(T_SamplingSoDoneDate,'%d-%m-%Y')) as receive_date,
IF(ISNULL(T_SamplingSoDoneTime),'',DATE_FORMAT(T_SamplingSoDoneTime,'%H:%i')) as receive_time,
IF(ISNULL(T_SamplingSoFlag),'N','Y') as is_sampling,
IF(ISNULL(T_SamplingSoFlag) OR T_SamplingSoFlag <> 'D','N','Y') as is_received,
IFNULL(M_StaffName,'') as staff_name
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND
T_SampleStationIsNonLab = 'OTHERS'
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_SamplingSoT_TestID = T_TestID
LEFT JOIN m_user ON T_SamplingSoDoneUserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['order_id']} AND
T_OrderDetailIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data sample other");
exit;
}
$data_sample_other = $query->result_array();
$sql = "
SELECT COUNT(*) as xcount, DATE_FORMAT(T_SurveyCreated,'%d-%m-%Y') as xcreated_date, DATE_FORMAT(T_SurveyCreated,'%H:%i') as xcreated_time
FROM t_survey
JOIN t_orderheader ON T_OrderHeaderID = T_SurveyT_OrderHeaderID AND T_OrderHeaderID = {$prm['order_id']} AND T_OrderHeaderLabNumber = '{$prm['noreg']}'
WHERE
T_SurveyIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data exist");
exit;
}
$data_exist = $query->row();
$data_survey = [];
if($data_exist->xcount > 0){
$status = "SUCCESS";
$data_survey = [
"sampletype_name" => "Isi survey",
"barcode" => $prm['noreg'],
"sampling_date" => $data_exist->xcreated_date,
"sample_time" => $data_exist->xcreated_time,
"receive_date" => $data_exist->xcreated_date,
"receive_time" => $data_exist->xcreated_time,
"is_sampling" => 'Y',
"is_received" => 'Y'
];
}
$result = array(
"data_patient" => $data_patient?$data_patient:[],
"data_packet" => $data_packet? $data_packet:[],
"data_tests" => $data_tests?$data_tests:[],
"data_sample_lab" => $data_sample_lab?$data_sample_lab:[],
"data_sample_radiodiagnostic" => $data_sample_radiodiagnostic?$data_sample_radiodiagnostic:[],
"data_sample_electromedic" => $data_sample_electromedic?$data_sample_electromedic:[],
"data_sample_other" => $data_sample_other?$data_sample_other:[],
"data_survey" => $data_survey
);
$this->sys_ok($result);
exit;
}
function load_survey(){
//# ambil parameter input
$prm = $this->sys_input;
$status = "FORM";
$results = [];
$sql = "
SELECT COUNT(*) as xcount
FROM t_survey
JOIN t_orderheader ON T_OrderHeaderID = T_SurveyT_OrderHeaderID AND T_OrderHeaderID = {$prm['order_id']} AND T_OrderHeaderLabNumber = '{$prm['noreg']}'
WHERE
T_SurveyIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data exist");
exit;
}
$data_exist = $query->row()->xcount;
if($data_exist > 0){
$status = "SUCCESS";
}else{
$sql = "
SELECT COUNT(*) as xcount
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['order_id']} AND
T_OrderHeaderLabNumber = '{$prm['noreg']}' AND
T_OrderHeaderIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data patient");
exit;
}
$data_exist_patient = $query->row()->xcount;
if($data_exist_patient == 0){
$status = "PATIENT_NOT_FOUND";
}else{
$sql = "
SELECT M_SurveyID as id,
M_SurveyName as name,
'' as value
FROM m_survey
WHERE
M_SurveyIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("data survey");
exit;
}
$results = $query->result_array();
}
}
$result = array(
"records" => $results,
"status" => $status
);
$this->sys_ok($result);
exit;
}
function save_survey(){
//# ambil parameter input
$prm = $this->sys_input;
$status = "FORM";
$results = [];
$sql = "
INSERT INTO t_survey (
T_SurveyT_OrderHeaderID,
T_SurveySaran,
T_SurveyCreated
)
VALUES( ?, ?, NOW())
";
//echo $sql;
$query = $this->db_onedev->query($sql,array(
$prm['order_id'],
$prm['saran']
));
if (!$query) {
$this->sys_error_db("insert header");
exit;
}
$header_id = $this->db_onedev->insert_id();
foreach ($prm['surveys'] as $key => $value) {
$sql = "
INSERT INTO t_surveydetail (
T_SurveryDetailT_SurveyID,
T_SurveryDetailM_SurveyID,
T_SurveryDetailValue,
T_SurveryDetailCreated
)
VALUES(
?,?,?,NOW()
)
";
//echo $sql;
$query = $this->db_onedev->query($sql,array(
$header_id,
$value['id'],
$value['value']
));
if (!$query) {
//echo $this->db_onedev->last_query();
$this->sys_error_db("insert detail ");
exit;
}
}
$status = "SUCCESS";
$result = array(
"status" => $status
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,858 @@
<?php
class Companyprice extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Corporate Price API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->load->library("SsPriceMou");
}
function search()
{
$input = json_decode(file_get_contents('php://input'), true) ?? [];
$corporate_code = $input['corporate_code'] ?? $this->input->get('corporate_code');
$corporate_name = $input['corporate_name'] ?? $this->input->get('corporate_name');
$search = $input['search'] ?? $this->input->get('search');
$page_val = $input['page'] ?? $this->input->get('page');
$page = $page_val ? intval($page_val) : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$where_clauses = [];
$params = [];
$where_clauses[] = "c.CorporateIsActive = 'Y'";
if (!empty($corporate_code)) {
$where_clauses[] = "c.CorporateCode LIKE ?";
$params[] = "%" . $corporate_code . "%";
}
if (!empty($corporate_name)) {
$where_clauses[] = "c.CorporateName LIKE ?";
$params[] = "%" . $corporate_name . "%";
}
if (!empty($search)) {
$where_clauses[] = "(c.CorporateCode LIKE ? OR c.CorporateName LIKE ?)";
$params[] = "%" . $search . "%";
$params[] = "%" . $search . "%";
}
$where_sql = "";
if (count($where_clauses) > 0) {
$where_sql = " WHERE " . implode(" AND ", $where_clauses);
}
$base_join_sql = "
FROM corporate c
INNER JOIN corporate_price cp
ON c.CorporateID = cp.CorporatePriceCorporateID
AND cp.CorporatePriceIsActive = 'Y'
";
$count_sql = "SELECT COUNT(DISTINCT c.CorporateID) AS total " . $base_join_sql . $where_sql;
$qry_count = $this->db_onedev->query($count_sql, $params);
$total = $qry_count->row()->total ?? 0;
$main_sql = "SELECT
c.CorporateID,
c.CorporateCode,
c.CorporateName,
c.CorporateAddress,
c.CorporatePICName,
c.CorporatePhone,
c.CorporateEmail,
c.CorporateIsActive,
c.CorporateCreated,
cp.CorporatePriceID,
cp.CorporatePriceT_PriceHeaderID,
cp.CorporatePriceIsDefault,
cp.CorporatePriceStartDate,
cp.CorporatePriceEndDate,
cp.CorporatePriceNote
" . $base_join_sql . $where_sql . "
GROUP BY c.CorporateID
ORDER BY
c.CorporateName ASC,
cp.CorporatePriceID DESC
LIMIT ? OFFSET ?
";
$main_params = array_merge($params, [$limit, $offset]);
$qry = $this->db_onedev->query($main_sql, $main_params);
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data corporate.']);
exit;
}
$data = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data corporate.',
'data' => $data,
'total' => $total,
'page' => $page,
'limit' => $limit,
'total_page' => ceil($total / $limit)
]);
exit;
}
function getlistcorporate(){
$input = json_decode(file_get_contents('php://input'), true) ?? [];
$search = $input['search'] ?? $this->input->get('search');
if (empty($search)) {
echo json_encode([
'status' => 'success',
'message' => 'Ketik code atau nama corporate',
'data' => [],
'total' => 0
]);
exit;
}
$sql = "SELECT
CorporateID,
CorporateCode,
CorporateName
FROM corporate
WHERE CorporateIsActive = 'Y'
AND (CorporateCode LIKE ? OR CorporateName LIKE ?)";
$params = ["%" . $search . "%", "%" . $search . "%"];
$sql .= " ORDER BY CorporateName ASC";
$qry = $this->db_onedev->query($sql, $params);
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data corporate.']);
exit;
}
$result = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data corporate.',
'data' => $result,
'total' => count($result)
]);
exit;
}
function getcorporateprice()
{
$sql = "SELECT
cp.*,
c.CorporateName
FROM corporate_price cp
LEFT JOIN corporate c
ON c.CorporateID = cp.CorporatePriceCorporateID
ORDER BY cp.CorporatePriceID DESC";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data price header.']);
exit;
}
$result = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data price header.',
'data' => $result,
'total' => count($result)
]);
exit;
}
function getcorporateprice2($corporateID)
{
$sql = "SELECT
cp.*,
c.CorporateName
FROM corporate_price cp
INNER JOIN corporate c
ON c.CorporateID = cp.CorporatePriceCorporateID
WHERE c.CorporateID = ?
ORDER BY cp.CorporatePriceID DESC";
$qry = $this->db_onedev->query($sql, [$corporateID]);
if (!$qry) {
echo json_encode([
'status' => 'error',
'message' => 'Gagal mengambil data price header.'
]);
exit;
}
$result = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data price header.',
'data' => $result,
'total' => count($result)
]);
exit;
}
function getlistpriceheader(){
$input = json_decode(file_get_contents('php://input'), true) ?? [];
$search = $input['search'] ?? $this->input->get('search');
if (empty($search)) {
echo json_encode([
'status' => 'success',
'message' => 'Ketik code atau nama price header',
'data' => [],
'total' => 0
]);
exit;
}
$sql = "SELECT
T_PriceHeaderID,
T_PriceHeaderCode,
T_PriceHeaderName
FROM t_priceheader
WHERE T_PriceHeaderIsActive = 'Y'
AND (T_PriceHeaderCode LIKE ? OR T_PriceHeaderName LIKE ?)";
$params = ["%" . $search . "%", "%" . $search . "%"];
$sql .= " ORDER BY T_PriceHeaderName ASC";
$qry = $this->db_onedev->query($sql, $params);
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data corporate.']);
exit;
}
$result = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data priceheader.',
'data' => $result,
'total' => count($result)
]);
exit;
}
function gettestbypriceheader()
{
$input = json_decode(file_get_contents("php://input"), true);
if (!isset($input['price_header_id'])) {
echo json_encode([
'status' => 'error',
'message' => 'price_header_id wajib diisi'
]);
exit;
}
$priceHeaderID = $input['price_header_id'];
$search = $input['search'] ?? $this->input->get('search');
$page_val = $input['page'] ?? $this->input->get('page');
$page = $page_val ? intval($page_val) : 1;
$limit = 5;
$offset = ($page - 1) * $limit;
$base_sql = "FROM t_test t
INNER JOIN ss_price_mou s
ON t.T_TestID = s.T_TestID
WHERE s.Ss_PriceMouT_PriceHeaderID = ?";
$params = [$priceHeaderID];
if (!empty($search)) {
$base_sql .= " AND (t.T_TestCode LIKE ? OR t.T_TestName LIKE ?)";
$params[] = "%" . $search . "%";
$params[] = "%" . $search . "%";
}
$count_sql = "SELECT COUNT(t.T_TestID) AS total " . $base_sql;
$qry_count = $this->db_onedev->query($count_sql, $params);
$total = $qry_count->row()->total ?? 0;
$sql = "SELECT
t.T_TestID,
t.T_TestCode,
t.T_TestName,
s.T_PriceAmount,
t.T_TestIsActive
" . $base_sql . "
LIMIT ? OFFSET ?";
$main_params = array_merge($params, [$limit, $offset]);
$qry = $this->db_onedev->query($sql, $main_params);
if (!$qry) {
echo json_encode([
'status' => 'error',
'message' => 'Gagal mengambil data test'
]);
exit;
}
$result = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data test',
'data' => $result,
'total' => $total,
'page' => $page,
'limit' => $limit,
'total_page' => ceil($total / $limit)
]);
exit;
}
function getpacketbypriceheader()
{
$input = json_decode(file_get_contents("php://input"), true);
if (!isset($input['price_header_id'])) {
echo json_encode([
'status' => 'error',
'message' => 'price_header_id wajib diisi'
]);
exit;
}
$priceHeaderID = $input['price_header_id'];
$search = $input['search'] ?? $this->input->get('search');
$page_val = $input['page'] ?? $this->input->get('page');
$page = $page_val ? intval($page_val) : 1;
$limit = 5;
$offset = ($page - 1) * $limit;
$base_sql = "FROM t_packet p
INNER JOIN ss_price_mou s
ON p.T_PacketID = s.packet_id
WHERE s.is_packet = 'Y'
AND s.Ss_PriceMouT_PriceHeaderID = ?
AND p.T_PacketIsActive = 'Y'";
$params = [$priceHeaderID];
if (!empty($search)) {
$base_sql .= " AND (p.T_PacketSasCode LIKE ? OR p.T_PacketName LIKE ?)";
$params[] = "%" . $search . "%";
$params[] = "%" . $search . "%";
}
$count_sql = "SELECT COUNT(DISTINCT p.T_PacketID) AS total " . $base_sql;
$qry_count = $this->db_onedev->query($count_sql, $params);
$total = $qry_count->row()->total ?? 0;
$sql = "SELECT DISTINCT
p.T_PacketID,
p.T_PacketName,
p.T_PacketType,
p.T_PacketPrice,
p.T_PacketIsActive,
p.T_PacketSasCode
" . $base_sql . "
LIMIT ? OFFSET ?";
$main_params = array_merge($params, [$limit, $offset]);
$qry = $this->db_onedev->query($sql, $main_params);
if (!$qry) {
echo json_encode([
'status' => 'error',
'message' => 'Gagal mengambil data packet'
]);
exit;
}
$result = $qry->result_array();
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data packet',
'data' => $result,
'total' => $total,
'page' => $page,
'limit' => $limit,
'total_page' => ceil($total / $limit)
]);
exit;
}
function savecorporateprice()
{
$input = json_decode(file_get_contents("php://input"), true);
$CorporateID = $input['CorporateID'] ?? null;
$T_PriceHeaderID = $input['T_PriceHeaderID'] ?? null;
$StartDate = $input['StartDate'] ?? date('Y-m-d');
$EndDate = $input['EndDate'] ?? date('Y-m-d');
$Note = $input['Note'] ?? '';
if (empty($CorporateID) || empty($T_PriceHeaderID)) {
echo json_encode(['status' => 'error', 'message' => 'CorporateID dan PriceHeaderID harus diisi.']);
exit;
}
$checkSql = "SELECT CorporatePriceID FROM `corporate_price`
WHERE `CorporatePriceCorporateID` = ?
AND `CorporatePriceT_PriceHeaderID` = ?
AND `CorporatePriceIsActive` = 'Y'";
$checkQuery = $this->db_onedev->query($checkSql, [$CorporateID, $T_PriceHeaderID]);
if ($checkQuery->num_rows() > 0) {
echo json_encode([
'status' => 'error',
'message' => 'Gagal simpan: Price Header tersebut sudah terdaftar untuk Corporate ini.'
]);
exit;
}
if ($StartDate > $EndDate) {
echo json_encode([
'status' => 'error',
'message' => 'Gagal simpan: Tanggal Mulai tidak boleh lebih besar dari Tanggal Akhir.'
]);
exit;
}
$T_TestIDs = $input['T_TestIDs'] ?? '';
if(is_array($T_TestIDs)){
$T_TestIDs = implode(',', $T_TestIDs);
}
$T_PacketIDs = $input['T_PacketIDs'] ?? '';
if(is_array($T_PacketIDs)){
$T_PacketIDs = implode(',', $T_PacketIDs);
}
$IsDefault = ($T_PriceHeaderID == 115) ? 'Y' : 'N';
$IsActive = 'Y';
$sql = "INSERT INTO `corporate_price` (
`CorporatePriceCorporateID`,
`CorporatePriceT_PriceHeaderID`,
`CorporatePriceIsDefault`,
`CorporatePriceStartDate`,
`CorporatePriceEndDate`,
`CorporatePriceNote`,
`CorporatePriceT_TestIDs`,
`CorporatePriceT_PacketIDs`,
`CorporatePriceIsActive`,
`CorporatePriceCreated`,
`CorporatePriceCreatedUserID`
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), 1)";
$params = [$CorporateID, $T_PriceHeaderID, $IsDefault, $StartDate, $EndDate, $Note, $T_TestIDs, $T_PacketIDs, $IsActive];
$this->db_onedev->trans_start();
$this->db_onedev->query($sql, $params);
$this->db_onedev->trans_complete();
if ($this->db_onedev->trans_status() === FALSE) {
echo json_encode(['status' => 'error', 'message' => 'Gagal menyimpan data ke database.']);
} else {
echo json_encode([
'status' => 'OK',
'message' => 'Berhasil menyimpan data.',
'data' => ['records' => [], 'total' => 0]
]);
}
exit;
}
function updatecorporateprice()
{
// 1. Ambil Input
$input = json_decode(file_get_contents("php://input"), true);
// Validasi ID Utama
$CorporatePriceID = $input['CorporatePriceID'] ?? null;
if (empty($CorporatePriceID)) {
echo json_encode(['status' => 'error', 'message' => 'CorporatePriceID wajib diisi.']);
exit;
}
// Ambil Parameter Lain
$CorporateID = $input['CorporateID'] ?? null;
$T_PriceHeaderID = $input['T_PriceHeaderID'] ?? null;
$StartDate = $input['StartDate'] ?? date('Y-m-d');
$EndDate = $input['EndDate'] ?? date('Y-m-d');
$Note = $input['Note'] ?? '';
// --- VALIDASI TANGGAL (BARU DITAMBAHKAN) ---
// Menggunakan strtotime agar aman untuk segala format tanggal
if (strtotime($StartDate) > strtotime($EndDate)) {
echo json_encode([
'status' => 'error',
'message' => 'Gagal update: Tanggal Mulai tidak boleh lebih besar dari Tanggal Akhir.'
]);
exit;
}
// -------------------------------------------
// Format Array ke String (Sesuai kolom varchar(500))
$T_TestIDs = $input['T_TestIDs'] ?? '';
if(is_array($T_TestIDs)){
$T_TestIDs = implode(',', $T_TestIDs);
}
$T_PacketIDs = $input['T_PacketIDs'] ?? '';
if(is_array($T_PacketIDs)){
$T_PacketIDs = implode(',', $T_PacketIDs);
}
// Logika Default
$IsDefault = ($T_PriceHeaderID == 115) ? 'Y' : 'N';
// --- 2. AMBIL DATA LAMA (BEFORE) ---
$sqlGet = "SELECT * FROM corporate_price WHERE CorporatePriceID = ?";
$qryGet = $this->db_onedev->query($sqlGet, [$CorporatePriceID]);
$oldData = $qryGet->row_array();
if (!$oldData) {
echo json_encode(['status' => 'error', 'message' => 'Data ID ' . $CorporatePriceID . ' tidak ditemukan.']);
exit;
}
// --- 3. SUSUN DATA BARU (AFTER) UNTUK LOG ---
// Kita copy data lama, lalu timpa value-nya dengan inputan baru
$newData = $oldData;
$newData['CorporatePriceCorporateID'] = $CorporateID;
$newData['CorporatePriceT_PriceHeaderID'] = $T_PriceHeaderID;
$newData['CorporatePriceIsDefault'] = $IsDefault;
$newData['CorporatePriceStartDate'] = $StartDate;
$newData['CorporatePriceEndDate'] = $EndDate;
$newData['CorporatePriceNote'] = $Note;
$newData['CorporatePriceT_TestIDs'] = $T_TestIDs;
$newData['CorporatePriceT_PacketIDs'] = $T_PacketIDs;
// --- 4. MULAI TRANSAKSI DATABASE ---
$this->db_onedev->trans_start();
// A. Query Update Data Utama
$sql = "UPDATE `corporate_price` SET
`CorporatePriceCorporateID` = ?,
`CorporatePriceT_PriceHeaderID` = ?,
`CorporatePriceIsDefault` = ?,
`CorporatePriceStartDate` = ?,
`CorporatePriceEndDate` = ?,
`CorporatePriceNote` = ?,
`CorporatePriceT_TestIDs` = ?,
`CorporatePriceT_PacketIDs` = ?
WHERE `CorporatePriceID` = ?";
$params = [
$CorporateID,
$T_PriceHeaderID,
$IsDefault,
$StartDate,
$EndDate,
$Note,
$T_TestIDs,
$T_PacketIDs,
$CorporatePriceID
];
$this->db_onedev->query($sql, $params);
// B. Query Insert Log
$sqlLog = "INSERT INTO cpone_log.log_corporate_price (
Log_CorporateType,
Log_CorporatePriceCorporateID,
Log_CorporatePriceT_PriceHeaderID,
Log_CorporatePriceBefore,
Log_CorporatePriceAfter,
Log_CorporatePriceUserID,
Log_CorporatePriceCreated
) VALUES (?, ?, ?, ?, ?, ?, NOW())";
$paramsLog = [
'UPDATE',
$oldData['CorporatePriceCorporateID'],
$oldData['CorporatePriceT_PriceHeaderID'],
json_encode($oldData),
json_encode($newData),
1
];
$this->db_onedev->query($sqlLog, $paramsLog);
// --- 5. SELESAI TRANSAKSI ---
$this->db_onedev->trans_complete();
if ($this->db_onedev->trans_status() === FALSE) {
$error = $this->db_onedev->error();
echo json_encode([
'status' => 'error',
'message' => 'Gagal update data: ' . ($error['message'] ?? 'Unknown Error')
]);
} else {
echo json_encode([
'status' => 'OK',
'message' => 'Berhasil mengupdate data.',
'data' => ['records' => [], 'total' => 0]
]);
}
exit;
}
function getlistcorporateprice()
{
$input = json_decode(file_get_contents("php://input"), true);
$CorporateID = $input['CorporateID'] ?? null;
$page_val = $input['page'] ?? 1;
$page = intval($page_val) > 0 ? intval($page_val) : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$where_clauses = ["cp.CorporatePriceIsActive = 'Y'"];
$params = [];
if (!empty($CorporateID)) {
$where_clauses[] = "cp.CorporatePriceCorporateID = ?";
$params[] = $CorporateID;
}
$where_sql = " WHERE " . implode(" AND ", $where_clauses);
$count_sql = "SELECT COUNT(cp.CorporatePriceID) as total
FROM corporate_price cp
" . $where_sql;
$qry_count = $this->db_onedev->query($count_sql, $params);
$total = $qry_count->row()->total ?? 0;
$main_sql = "SELECT
cp.*,
c.CorporateName,
ph.T_PriceHeaderCode,
ph.T_PriceHeaderName,
GROUP_CONCAT(DISTINCT CONCAT(t.T_TestID, '||', t.T_TestCode, '||', t.T_TestName) ORDER BY t.T_TestName SEPARATOR ';;') AS TestDetails,
GROUP_CONCAT(DISTINCT CONCAT(p.T_PacketID, '||', p.T_PacketSasCode, '||', p.T_PacketName, '||', p.T_PacketPrice) ORDER BY p.T_PacketName SEPARATOR ';;') AS PacketDetails
FROM corporate_price cp
LEFT JOIN corporate c
ON c.CorporateID = cp.CorporatePriceCorporateID
LEFT JOIN t_priceheader ph
ON ph.T_PriceHeaderID = cp.CorporatePriceT_PriceHeaderID
LEFT JOIN t_test t
ON FIND_IN_SET(t.T_TestID, cp.CorporatePriceT_TestIDs) > 0
LEFT JOIN t_packet p
ON FIND_IN_SET(p.T_PacketID, cp.CorporatePriceT_PacketIDs) > 0
" . $where_sql . "
GROUP BY cp.CorporatePriceID
ORDER BY cp.CorporatePriceID DESC
LIMIT ? OFFSET ?";
$main_params = array_merge($params, [$limit, $offset]);
$qry = $this->db_onedev->query($main_sql, $main_params);
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil data price header.']);
exit;
}
$result = $qry->result_array();
foreach ($result as &$row) {
$testList = [];
if (!empty($row['TestDetails'])) {
$items = explode(';;', $row['TestDetails']);
foreach ($items as $item) {
$parts = explode('||', $item);
if (count($parts) === 3) {
$testList[] = [
'T_TestID' => $parts[0],
'T_TestCode' => $parts[1],
'T_TestName' => $parts[2]
];
}
}
}
$row['TestDetails'] = $testList;
$packetList = [];
if (!empty($row['PacketDetails'])) {
$items = explode(';;', $row['PacketDetails']);
foreach ($items as $item) {
$parts = explode('||', $item);
if (count($parts) === 4) {
$packetList[] = [
'T_PacketID' => $parts[0],
'T_PacketSasCode' => $parts[1],
'T_PacketName' => $parts[2],
'T_PacketPrice' => $parts[3]
];
}
}
}
$row['PacketDetails'] = $packetList;
}
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil data price header.',
'data' => $result,
'total' => intval($total),
'page' => $page,
'limit' => $limit,
'total_page' => ceil($total / $limit)
]);
exit;
}
function deletecorporateprice()
{
$input = json_decode(file_get_contents("php://input"), true);
$CorporatePriceID = $input['CorporatePriceID'] ?? null;
if (empty($CorporatePriceID)) {
echo json_encode(['status' => 'error', 'message' => 'CorporatePriceID wajib diisi.']);
exit;
}
$sqlGet = "SELECT * FROM corporate_price WHERE CorporatePriceID = ?";
$qryGet = $this->db_onedev->query($sqlGet, [$CorporatePriceID]);
$oldData = $qryGet->row_array();
if (!$oldData) {
echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan.']);
exit;
}
$sql = "UPDATE corporate_price
SET CorporatePriceIsActive = 'N',
CorporatePriceDeleted = NOW(),
CorporatePriceDeletedUserID = 1
WHERE CorporatePriceID = ?";
$this->db_onedev->trans_start();
$this->db_onedev->query($sql, [$CorporatePriceID]);
$newData = $oldData;
$newData['CorporatePriceIsActive'] = 'N';
$newData['CorporatePriceDeleted'] = date('Y-m-d H:i:s');
$newData['CorporatePriceDeletedUserID'] = 1;
$sqlLog = "INSERT INTO cpone_log.log_corporate_price (Log_CorporateType, Log_CorporatePriceCorporateID, Log_CorporatePriceT_PriceHeaderID, Log_CorporatePriceBefore, Log_CorporatePriceAfter, Log_CorporatePriceUserID, Log_CorporatePriceCreated) VALUES (?, ?, ?, ?, ?, ?, NOW())";
$this->db_onedev->query($sqlLog, [
'DELETE',
$oldData['CorporatePriceCorporateID'],
$oldData['CorporatePriceT_PriceHeaderID'],
json_encode($oldData),
json_encode($newData),
1
]);
$this->db_onedev->trans_complete();
if ($this->db_onedev->trans_status() === FALSE) {
echo json_encode(['status' => 'error', 'message' => 'Gagal menghapus data.']);
} else {
echo json_encode([
'status' => 'OK',
'message' => 'Berhasil menghapus data.'
]);
}
exit;
}
function getdetailcorporateprice()
{
$input = json_decode(file_get_contents("php://input"), true);
$CorporatePriceID = $input['CorporatePriceID'] ?? null;
if (empty($CorporatePriceID)) {
echo json_encode(['status' => 'error', 'message' => 'CorporatePriceID wajib diisi.']);
exit;
}
$sql = "SELECT
cp.*,
c.CorporateName,
ph.T_PriceHeaderCode,
ph.T_PriceHeaderName,
GROUP_CONCAT(DISTINCT CONCAT(t.T_TestID, '||', t.T_TestCode, '||', t.T_TestName) ORDER BY t.T_TestName SEPARATOR ';;') AS TestDetails,
GROUP_CONCAT(DISTINCT CONCAT(p.T_PacketID, '||', p.T_PacketSasCode, '||', p.T_PacketName, '||', p.T_PacketPrice) ORDER BY p.T_PacketName SEPARATOR ';;') AS PacketDetails
FROM corporate_price cp
LEFT JOIN corporate c
ON c.CorporateID = cp.CorporatePriceCorporateID
LEFT JOIN t_priceheader ph
ON ph.T_PriceHeaderID = cp.CorporatePriceT_PriceHeaderID
LEFT JOIN t_test t
ON FIND_IN_SET(t.T_TestID, cp.CorporatePriceT_TestIDs) > 0
LEFT JOIN t_packet p
ON FIND_IN_SET(p.T_PacketID, cp.CorporatePriceT_PacketIDs) > 0
WHERE cp.CorporatePriceID = ?
GROUP BY cp.CorporatePriceID";
$qry = $this->db_onedev->query($sql, [$CorporatePriceID]);
if (!$qry) {
echo json_encode(['status' => 'error', 'message' => 'Gagal mengambil detail corporate price.']);
exit;
}
$result = $qry->result_array();
foreach ($result as &$row) {
$testList = [];
if (!empty($row['TestDetails'])) {
$items = explode(';;', $row['TestDetails']);
foreach ($items as $item) {
$parts = explode('||', $item);
if (count($parts) === 3) {
$testList[] = [
'T_TestID' => $parts[0],
'T_TestCode' => $parts[1],
'T_TestName' => $parts[2]
];
}
}
}
$row['TestDetails'] = $testList;
$packetList = [];
if (!empty($row['PacketDetails'])) {
$items = explode(';;', $row['PacketDetails']);
foreach ($items as $item) {
$parts = explode('||', $item);
if (count($parts) === 4) {
$packetList[] = [
'T_PacketID' => $parts[0],
'T_PacketSasCode' => $parts[1],
'T_PacketName' => $parts[2],
'T_PacketPrice' => $parts[3]
];
}
}
}
$row['PacketDetails'] = $packetList;
}
echo json_encode([
'status' => 'success',
'message' => 'Berhasil mengambil detail corporate price.',
'data' => $result,
'total' => count($result)
]);
exit;
}
}

View File

@@ -0,0 +1,10 @@
@baseUrl = https://devcpone.aplikasi.web.id/one-api/mockup/corporate-price/
@contentType = application/json
####
POST {{baseUrl}}/Companyprice/search
Content-Type: application/json
{
}

View File

@@ -0,0 +1,201 @@
<?php
class Done extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SampleStorage API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$groupid = $prm["groupid"];
//$subgroupid = $prm["subgroupid"];
$join_group = '';
if($groupid != '0'){
$join_group = "JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID AND Nat_GroupID = {$groupid}";
}
/*$join_subgroup = '';
if($subgroupid != 0){
$join_group = "JOIN nat_subgroup ON T_TestNat_SubgroupID = Nat_SubgroupID AND Nat_SubgroupID = {$subgroupid}";
}*/
if(!isset($prm['current_page']))
$prm['current_page'] = 1;
$sql_where = "WHERE Result_CourierStatus = 'S' AND JSON_CONTAINS(Result_COurierIds,T_OrderDetailID)";
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
//$sql_param = array();
if ($nolab != "" ) {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " ( T_OrderHeaderLabNumber like '%$nolab%' OR M_PatientName like '%$nolab%' )";
}
/*if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_PatientName like '%$nama%' ";
}*/
$sql = "SELECT Result_CourierID as xid,
T_OrderHeaderID as orderid,
T_OrderHeaderLabNumber as ordernumber,
UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname,
Result_CourierT_TestName as test_name,
'N' as chex
FROM result_courier
join t_orderheader ON Result_CourierT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND JSON_CONTAINS(Result_CourierIds, T_OrderDetailID)
$join_group
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
$sql_where
GROUP BY Result_CourierID
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array("total" => count($rst), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getkerajaan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$rst = array(array('id'=>0,'name'=>'Semua'));
$sql = "SELECT 0 as id, 'Semua' as name UNION SELECT Nat_GroupID as id, Nat_GroupName as name FROM nat_group WHERE Nat_GroupIsActive = 'Y'";
$rst_db = $this->db_onedev->query($sql)->result_array();
//$c = array_combine($rst,$rst_db);
$result = array(
"total" => 1 ,
"records" => $rst_db
);
$this->sys_ok($result);
exit;
}
function dosend(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$selected = $prm['selected'];
foreach($selected as $k => $v){
$sql = "UPDATE result_frontoffice SET Result_FrontOfficeStatus = 'R' WHERE Result_FrontOfficeID = {$v['xid']}";
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function sendemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$ids = "(".$prm['ids'].")";
$sql = "UPDATE result_sendemail SET Result_SendEmailStatus = 'S', Result_SendEmailUserID = {$userid} WHERE Result_SendEmailID IN {$ids}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "SELECT * FROM result_sendemail WHERE Result_SendEmailID IN {$ids}";
$dt_rst = $this->db_onedev->query($sql)->result_array();
foreach($dt_rst as $k => $v){
$dt_log = json_encode($v);
$sql = "INSERT INTO one_log.log_resultsendemail (
Log_ResultSendEmailDatetime,
Log_ResultSendEmailJson,
Log_ResultSendEmailUserID
)
VALUES(
NOW(),
'{$dt_log}',
{$userid}
)";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updateemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$id = $prm['id'];
$sql = "UPDATE t_orderdelivery SET T_OrderDeliveryDestination = '{$prm['edited_email']}', T_OrderDeliveryUserID = {$userid} WHERE T_OrderDeliveryID = {$id}";
//echo $sql;
$this->db_onedev->query($sql);
$result = array ("total" => 0, "records" => array());
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,440 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
F_PaymentID as note_id,
F_PaymentDate as note_date,
F_PaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_PaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_PaymentDetailIsActive as note_active
FROM f_payment
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
WHERE
F_PaymentT_OrderHeaderID = {$orderid}
GROUP BY F_PaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search_v2()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$filter = $prm['filter'];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 20;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "";
if($search != '')
$where .= "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
if($filter == 'day')
$where .= " DATE(T_OrderHeaderDate) = CURDATE() AND ";
if($filter == 'notsampled')
$where .= " Last_StatusM_StatusID < 7 AND ";
$sql = " SELECT count(*) as total
FROM(
SELECT T_OrderHeaderID
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
(
('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL))
OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
)x";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$janji = T_OrderPromiseDateTime;
$janji_hasil = Date_format($janji, "d-m-Y H:i:s");
$sql ="
set @counter = 0;
SELECT @counter := @counter +1 no_urut,
t_orderheader.*,T_OrderHeaderIsCito as cito,
M_PatientNoReg,
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
M_CompanyName,
M_MouName,
DATE(T_OrderHeaderDate) as order_date,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
IFNULL(Last_StatusPaymentUnpaid,T_OrderHeaderTotal)as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
Last_StatusM_StatusID as last_status,
'' as notes,
M_MouMinDP as mindp_percent,
GROUP_CONCAT(distinct concat(T_OrderDetailT_TestName,'^',T_OrderDetailIsCito) SEPARATOR ',') as test ,
fn_report_promise_list(T_OrderHeaderID) as janji,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount,
case
when Last_StatusPaymentPaid = '0' then 'BELUM BAYAR'
when Last_StatusPaymentIsLunas = 'Y' then 'LUNAS'
when Last_StatusPaymentIsLunas = 'N' then 'BELUM LUNAS' ELSE ''
END as status,
GROUP_CONCAT(distinct M_DeliveryName SEPARATOR ' , ') as delivery
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
ORDER BY `fn_get_cito`(T_OrderHeaderID),T_OrderPromiseDateTime asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
/*if($rows){
foreach($rows as $k => $v){
$sql = "SELECT * FROM t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID";
$rows[$k]['result_promise'] = $this->add_notes($v['T_OrderHeaderID']);
}
}*/
$result = array("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$filter = $prm['filter'];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 20;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "";
if($search != '')
$where .= "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
if($filter == 'day')
$where .= " DATE(T_OrderHeaderDate) = CURDATE() AND ";
if($filter == 'notsampled')
$where .= " Last_StatusM_StatusID < 7 AND ";
$sql = " SELECT count(*) as total
FROM(
SELECT T_OrderHeaderID
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
(
('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL))
OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
)x";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$janji = T_OrderPromiseDateTime;
$janji_hasil = Date_format($janji, "d-m-Y H:i:s");
$sql = "SELECT '' as rownumber,t_orderheader.*,T_OrderHeaderIsCito as cito,
M_PatientNoReg,
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
M_CompanyName,
M_MouName,
DATE(T_OrderHeaderDate) as order_date,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
IFNULL(Last_StatusPaymentUnpaid,T_OrderHeaderTotal)as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
Last_StatusM_StatusID as last_status,
'' as notes,
M_MouMinDP as mindp_percent,
GROUP_CONCAT(distinct concat(T_OrderDetailT_TestName,'^',T_OrderDetailIsCito) SEPARATOR ',') as test ,
fn_report_promise_list(T_OrderHeaderID) as janji,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount,
case
when Last_StatusPaymentPaid = '0' then 'BELUM BAYAR'
when Last_StatusPaymentIsLunas = 'Y' then 'LUNAS'
when Last_StatusPaymentIsLunas = 'N' then 'BELUM LUNAS' ELSE ''
END as status,
GROUP_CONCAT(distinct M_DeliveryName SEPARATOR ' , ') as delivery,
fn_lookup_external(T_OrderHeaderLabNumber,'L') as external_numbering
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
ORDER BY `fn_get_cito`(T_OrderHeaderID),T_OrderPromiseDateTime asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$xno = ($k + 1) + $number_offset;
$rows[$k]['rownumber'] = $xno;
}
}
$result = array("total" => $tot_page,"total_all"=>$tot_count, "total_filter"=>count($rows),"records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function lookup_promises(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$sql = "SELECT T_OrderPromiseID as id, DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y') as xdate, TIME_FORMAT(T_OrderPromiseDateTime,'%H:%i') as xtime
FROM t_orderpromise
WHERE T_OrderPromiseT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderPromiseIsActive = 'Y'";
//echo $sql;
$query = $this->db_onedev->query($sql)->result_array();
if (!$query) {
$this->sys_error_db("f_paymentdetail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => $query
);
$this->sys_ok($result);
exit;
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id,
'barcode' as type,
T_SampleTypeID,
T_BarcodeLabID,
T_BarcodeLabBarcode,
T_BarcodeLabT_OrderHeaderID as orderid,
T_BarcodeLabCounter,
T_SampleTypeName,
'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = ''
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0 as T_SampleTypeID,0 as T_BarcodeLabID,T_OrderHeaderLabNumber as T_BarcodeLabBarcode,{$prm['T_OrderHeaderID']}, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
UNION
SELECT T_TestID as id,
'nonlab' as type,
T_OrderDetailID as detail_id,
'' as xxx,
'-' as T_BarcodeLabBarcode,
T_OrderHeaderID as order_id,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
T_TestName as T_SampleTypeName,
'N' as chex
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName <> 'lab'
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY T_TestID
UNION
SELECT T_OrderDetailID as id,
'nonlab_group' as type,
T_OrderDetailID as detail_id,
'' as xxx,
GROUP_CONCAT(T_TestName separator ' , ') as T_BarcodeLabBarcode,
T_OrderHeaderID as order_id,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
'Amplop Besar' as T_SampleTypeName,
'N' as chex
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName <> 'lab'
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY T_OrderHeaderID
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_promises(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
foreach($prm['data'] as $k => $v){
$xdatetime = date('Y-m-d H:i:s',strtotime($v['xdate'].' '.$v['xtime']));
$sql = "UPDATE t_orderpromise SET T_OrderPromiseDateTime = '{$xdatetime}' WHERE T_OrderPromiseID = {$v['id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_paymentdetail delete");
exit;
}
}
$sql = "UPDATE t_orderheaderaddon SET T_OrderHeaderAddonIsComing = 'Y'WHERE T_OrderHeaderAddOnT_OrderHeaderID = {$prm['orderid']} AND T_OrderHeaderAddOnIsActive = 'Y'";
$this->db_onedev->query($sql);
$result = array(
"total" => 1 ,
"records" => $prm
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,520 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
F_PaymentID as note_id,
F_PaymentDate as note_date,
F_PaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_PaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_PaymentDetailIsActive as note_active
FROM f_payment
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
WHERE
F_PaymentT_OrderHeaderID = {$orderid}
GROUP BY F_PaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search_v2()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$filter = $prm['filter'];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 20;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "";
if($search != '')
$where .= "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
if($filter == 'day')
$where .= " DATE(T_OrderHeaderDate) = CURDATE() AND ";
if($filter == 'notsampled')
$where .= " Last_StatusM_StatusID < 7 AND ";
$sql = " SELECT count(*) as total
FROM(
SELECT T_OrderHeaderID
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
left join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
(
('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL))
OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
)x";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$janji = T_OrderPromiseDateTime;
$janji_hasil = Date_format($janji, "d-m-Y H:i:s");
$sql ="
set @counter = 0;
SELECT @counter := @counter +1 no_urut,
t_orderheader.*,T_OrderHeaderIsCito as cito,
M_PatientNoReg,
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
M_CompanyName,
M_MouName,
DATE(T_OrderHeaderDate) as order_date,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
IFNULL(Last_StatusPaymentUnpaid,T_OrderHeaderTotal)as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
Last_StatusM_StatusID as last_status,
'' as notes,
M_MouMinDP as mindp_percent,
GROUP_CONCAT(distinct concat(T_OrderDetailT_TestName,'^',T_OrderDetailIsCito) SEPARATOR ',') as test ,
fn_report_promise_list(T_OrderHeaderID) as janji,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount,
case
when Last_StatusPaymentPaid = '0' then 'BELUM BAYAR'
when Last_StatusPaymentIsLunas = 'Y' then 'LUNAS'
when Last_StatusPaymentIsLunas = 'N' then 'BELUM LUNAS' ELSE ''
END as status,
GROUP_CONCAT(distinct M_DeliveryName SEPARATOR ' , ') as delivery
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y')
OR '{$status}' = 'A'
)
group by T_OrderHeaderID
ORDER BY `fn_get_cito`(T_OrderHeaderID),T_OrderPromiseDateTime asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
/*if($rows){
foreach($rows as $k => $v){
$sql = "SELECT * FROM t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID";
$rows[$k]['result_promise'] = $this->add_notes($v['T_OrderHeaderID']);
}
}*/
$result = array("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$sql = "SELECT Result_CourierSPKID as trx_id,
Result_CourierSPKNumbering as xnumber,
'' as details
FROM result_courierspk
JOIN management_courier ON Management_CourierType = 'DR' AND
Management_CourierReffID = Result_CourierSPKID AND
Management_CourierIsActive = 'Y'
JOIN m_courier ON M_CourierID = Result_CourierSPKM_CourierID AND M_CourierIsActive = 'Y'
JOIN m_user ON M_UserM_StaffID = M_CourierM_StaffID AND M_UserID = {$xuserid}
LEFT JOIN result_couriercominghome ON Result_CourierComingHomeResultCourierSpkID = Result_CourierSpkID AND Result_CourierComingHomeConfirmed = 'Y'
WHERE
( Result_CourierSPKStatus <> 'S' AND Result_CourierSPKStatus <> 'D') AND
ISNULL(Result_CourierComingHomeID) AND
Result_CourierSPKIsActive = 'Y'
ORDER BY Result_CourierSPKDate DESC
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
$sql = "SELECT Result_CourierSPKDetailID as xid,
Result_CourierComingHomeID as cominghome_id,
Result_CourierSPKDetailStatus as status,
M_DeliveryName as delivery_name,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as name,
T_OrderHeaderLabNumberExt as noreg,
M_DeliveryID as delivery_id,
M_DistrictName as district,
REPLACE(T_OrderDeliveryDestination,',',' ') as destination,
IFNULL(T_OrderDeliveryNoteValue,'-') as note,
Last_StatusPaymentIsLunas as status_payment,
Last_StatusPaymentBillTotal as total_bill,
M_MouIsBill as flag_bill,
Last_StatusPaymentPaid as paid,
Last_StatusPaymentUnpaid as rest,
IFNULL(Result_CourierComingHomeDetailsReceiver,'') as receiver,
IFNULL(M_CourierStatusReceiveName,'') as receiver_status_name,
IFNULL(M_CourierStatusReceiveID,'0') as receiver_status_id,
IFNULL(Result_CourierComingHomeDetailsPayment,IF(M_MouIsBill = 'N' ,Last_StatusPaymentUnpaid,0)) as pay,
IFNULL( DATE_FORMAT(Result_CourierComingHomeDetailsReceivedDateTime,'%d-%m-%Y %H:%i'),'-') as received_time
FROM result_courierspk_detail
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDeliveryIsActive = 'Y'
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN result_couriercominghome ON Result_CourierComingHomeResultCourierSpkID = Result_CourierSPKDetailResult_CourierSPKID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
LEFT JOIN t_orderdeliverynote ON T_OrderDeliveryNoteT_OrderDeliveryID = T_OrderDeliveryID AND
T_OrderDeliveryNoteIsActive = 'Y'
LEFT JOIN result_couriercominghome_details ON Result_CourierComingHomeDetailsResult_CourierSPKDetailID = Result_CourierSPKDetailID
LEFT JOIN m_courierstatusreceive ON Result_CourierComingHomeDetailsM_CourierStatusReceiveID = M_CourierStatusReceiveID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$v['trx_id']} AND
Result_CourierSPKDetailStatus NOT IN ('N','O') AND
Result_CourierSPKDetailIsActive = 'Y'
";
//echo $sql;
$details = $this->db_onedev->query($sql)->result_array();
$per_district = array();
foreach($details as $i => $j){
$details[$k]['destination'] = str_replace(',',' ',trim(preg_replace('/\s\s+/', ' ', $v['destination'])));
if($this->exist_in_array($per_district,$j,'delivery_id') == -1){
$details_per_delivery = array();
foreach($details as $ix => $jx){
if($jx['delivery_id'] == $j['delivery_id']){
array_push($details_per_delivery,$jx);
}
}
array_push($per_district,array('delivery_id'=>$j['delivery_id'],'delivery_name'=>$j['delivery_name'],'details'=>$details_per_delivery));
}
}
$rows[$k]['details'] = $per_district;
}
}
$result = array("records" => $rows);
$this->sys_ok($result);
exit;
}
function exist_in_array($arrs,$arr,$key){
$rtn = -1;
foreach($arrs as $k => $v){
if($v[$key] == $arr[$key]){
$rtn = $k;
break;
}
}
return $rtn;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] == '')
{
$rows = array(array('id'=>0,'name'=>'Semua'));
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}else{
$q['search'] = "%{$prm['search']}%";
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
array_push($rows,array('id'=>0,'name'=>'Semua'));
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
}
function lookup_promises(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$sql = "
SELECT T_OrderPromiseID as id,
DATE_FORMAT(T_OrderPromiseDateTime,'%d%m%Y') as xdate,
TIME_FORMAT(T_OrderPromiseDateTime,'%H%i') as xtime,
GROUP_CONCAT(T_TestName SEPARATOR ' , ') as tests
FROM t_orderdetail
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDetailIsActive = 'Y'
GROUP BY T_OrderPromiseID
";
//echo $sql;
$query = $this->db_onedev->query($sql)->result_array();
if (!$query) {
$this->sys_error_db("f_paymentdetail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => $query
);
$this->sys_ok($result);
exit;
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id,
'barcode' as type,
T_SampleTypeID,
T_BarcodeLabID,
T_BarcodeLabBarcode,
T_BarcodeLabT_OrderHeaderID as orderid,
T_BarcodeLabCounter,
T_SampleTypeName,
'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = ''
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0 as T_SampleTypeID,0 as T_BarcodeLabID,T_OrderHeaderLabNumber as T_BarcodeLabBarcode,{$prm['T_OrderHeaderID']}, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
UNION
SELECT T_TestID as id,
'nonlab' as type,
T_OrderDetailID as detail_id,
'' as xxx,
'-' as T_BarcodeLabBarcode,
T_OrderHeaderID as order_id,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
T_TestName as T_SampleTypeName,
'N' as chex
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName <> 'lab'
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY T_TestID
UNION
SELECT T_OrderDetailID as id,
'nonlab_group' as type,
T_OrderDetailID as detail_id,
'' as xxx,
GROUP_CONCAT(T_TestName separator ' , ') as T_BarcodeLabBarcode,
T_OrderHeaderID as order_id,
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
'Amplop Besar' as T_SampleTypeName,
'N' as chex
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName <> 'lab'
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY T_OrderHeaderID
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_statuses(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$sql = "
SELECT M_CourierStatusReceiveID as id,
M_CourierStatusReceiveName as name
FROM m_courierstatusreceive
WHERE
M_CourierStatusReceiveIsActive = 'Y'
";
//echo $sql;
$query = $this->db_onedev->query($sql)->result_array();
if (!$query) {
$this->sys_error_db("f_paymentdetail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => $query
);
$this->sys_ok($result);
exit;
}
function serahkan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$xtime = date('Y-m-d H:i:s');
$sql = "INSERT result_couriercominghome_details(
Result_CourierComingHomeDetailsResult_CourierComingHomeID,
Result_CourierComingHomeDetailsResult_CourierSPKDetailID,
Result_CourierComingHomeDetailsM_CourierStatusReceiveID,
Result_CourierComingHomeDetailsReceiver,
Result_CourierComingHomeDetailsReceivedDateTime ,
Result_CourierComingHomeDetailsPayment,
Result_CourierComingHomeDetailsUserID,
Result_CourierComingHomeDetailsCreated
)
VALUES(
{$prm['cominghome_id']},
{$prm['xid']},
{$prm['receiver_status_id']},
'{$prm['receiver']}',
NOW(),
{$prm['pay']},
{$xuserid},
NOW()
)";
$xinsert = $this->db_onedev->query($sql);
if($xinsert){
$prm['status'] = 'D';
$prm['received_time'] = date('d-m-Y H:i',strtotime($xtime));
}
$result = array(
"total" => 1 ,
"records" => $prm
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,364 @@
<?php
class Done extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SampleStorage API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT Result_CourierSPKDetailResult_CourierSPKID as spk_id,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status_confirmed,
IFNULL(Result_CourierComingHomeID,0) as header_id,
IFNULL(Result_CourierComingHomeDetailsID,0) as detail_id,
Result_CourierSPKDetailID as spk_detail_id,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
'' as selected_receive,
IFNULL(Result_CourierComingHomeDetailsM_CourierStatusReceiveID,0) as received_id,
IFNULL(M_CourierStatusReceiveCode,'XXX') as received_code,
IFNULL(M_CourierStatusReceiveStatus,'') as received_status,
IFNULL(M_CourierStatusReceiveName,'Pilih status') as received_name,
IFNULL(Result_CourierComingHomeDetailsReceiver,'') as receiver_name,
IFNULL(DATE_FORMAT(Result_CourierComingHomeDetailsReceivedDateTime,'%d%m%Y%H%i'),'000000000000') as received_datetime,
DATE_FORMAT(Result_CourierComingHomeDetailsReceivedDateTime,'%d-%m-%Y %H:%i') as received_datetime_ina,
IFNULL(Result_CourierComingHomeDetailsPayment,0) as payment,
Result_CourierSPKDetailForceDone as force_done,
Last_StatusPaymentBillTotal as bill_total,
Last_StatusPaymentPaid as paid,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status,
IFNULL(confirmed_staff.M_StaffName,'Belum dikonfirmasi') as confirmed_by,
Last_StatusPaymentIsLunas as status_payment,
Last_StatusPaymentUnpaid as unpaid
FROM result_courierspk_detail
JOIN result_courierspk ON Result_CourierSPKID = Result_CourierSPKDetailResult_CourierSPKID
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN result_couriercominghome_details ON
Result_CourierComingHomeDetailsResult_CourierSPKDetailID = Result_CourierSPKDetailID
LEFT JOIN result_couriercominghome ON Result_CourierComingHomeDetailsResult_CourierComingHomeID = Result_CourierComingHomeID
LEFT JOIN m_user ON Result_CourierComingHomeConfirmBy = M_UserID
LEFT JOIN m_staff confirmed_staff ON M_UserM_StaffID = confirmed_staff.M_StaffID
LEFT JOIN m_courierstatusreceive ON Result_CourierComingHomeDetailsM_CourierStatusReceiveID = M_CourierStatusReceiveID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKStatus <> 'S' AND
( Result_CourierSPKDetailStatus = 'S' OR Result_CourierSPKDetailStatus = 'D' ) AND
Result_CourierSPKDetailIsActive = 'Y'
GROUP BY spk_detail_id
ORDER BY T_OrderPromiseDateTime ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['chex'] = false;
$rows[$k]['selected_receive'] = array("id"=>$v['received_id'],"code"=>$v['received_code'],"name"=>$v['received_name'],"status"=>$v["received_status"]);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getkerajaan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$rst = array(array('id'=>0,'name'=>'Semua'));
$sql = "SELECT 0 as id, 'Semua' as name UNION SELECT Nat_GroupID as id, Nat_GroupName as name FROM nat_group WHERE Nat_GroupIsActive = 'Y'";
$rst_db = $this->db_onedev->query($sql)->result_array();
//$c = array_combine($rst,$rst_db);
$result = array(
"total" => 1 ,
"records" => $rst_db
);
$this->sys_ok($result);
exit;
}
function dosend(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$selected = $prm['selected'];
foreach($selected as $k => $v){
$sql = "UPDATE result_frontoffice SET Result_FrontOfficeStatus = 'R' WHERE Result_FrontOfficeID = {$v['xid']}";
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function savereport(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$data = $prm['data'];
$spk_id = $data[0]['spk_id'];
$header_id = intval($data[0]['header_id']);
$last_id = $header_id;
if($header_id == 0){
$sql = "INSERT INTO result_couriercominghome(
Result_CourierComingHomeResultCourierSpkID,
Result_CourierComingHomeDateTime,
Result_CourierComingHomeCreated,
Result_CourierComingHomeUserID
)
VALUES(
{$spk_id},
NOW(),
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
$last_id = $this->db_onedev->insert_id();
}
foreach($data as $k => $v){
$detail_id = intval($v['detail_id']);
$xdatetime = $v['received_datetime'];
//echo substr($xdatetime,0,2)."-".substr($xdatetime,2,2)."-".substr($xdatetime,4,4)." ".substr($xdatetime,9,2).":".substr($xdatetime,11,2);
$xdatetime = date("Y-m-d H:i:s", strtotime(substr($xdatetime,0,2)."-".substr($xdatetime,2,2)."-".substr($xdatetime,4,4)." ".substr($xdatetime,8,2).":".substr($xdatetime,10,2)));
//echo $xdatetime;
if($detail_id == 0){
$sql = "INSERT INTO result_couriercominghome_details(
Result_CourierComingHomeDetailsResult_CourierComingHomeID,
Result_CourierComingHomeDetailsResult_CourierSPKDetailID,
Result_CourierComingHomeDetailsM_CourierStatusReceiveID,
Result_CourierComingHomeDetailsReceiver,
Result_CourierComingHomeDetailsPayment,
Result_CourierComingHomeDetailsReceivedDateTime,
Result_CourierComingHomeDetailsUserID,
Result_CourierComingHomeDetailsCreated
)
VALUES(
{$last_id},
{$v['spk_detail_id']},
{$v['received_id']},
'{$v['receiver_name']}',
{$v['payment']},
'{$xdatetime}',
{$userid},
NOW()
)";
}
else{
$sql = "UPDATE result_couriercominghome_details SET
Result_CourierComingHomeDetailsResult_CourierComingHomeID = {$last_id},
Result_CourierComingHomeDetailsResult_CourierSPKDetailID = {$v['spk_detail_id']},
Result_CourierComingHomeDetailsM_CourierStatusReceiveID = {$v['received_id']},
Result_CourierComingHomeDetailsReceiver = '{$v['receiver_name']}',
Result_CourierComingHomeDetailsPayment = {$v['payment']},
Result_CourierComingHomeDetailsReceivedDateTime = '{$xdatetime}',
Result_CourierComingHomeDetailsUserID = {$userid}
WHERE
Result_CourierComingHomeDetailsID = {$detail_id}
";
}
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function confirmreport(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$data = $prm['data'];
$spk_id = $data[0]['spk_id'];
$header_id = intval($data[0]['header_id']);
$last_id = $header_id;
$sql = "UPDATE result_couriercominghome SET
Result_CourierComingHomeConfirmed = 'Y',
Result_CourierComingHomeConfirmBy = {$userid},
Result_CourierComingHomeConfirmDateTime = NOW(),
Result_CourierComingHomeUserID = {$userid}
WHERE
Result_CourierComingHomeID = {$header_id}
";
$this->db_onedev->query($sql);
foreach($data as $k => $v){
$detail_id = intval($v['detail_id']);
$sql = "UPDATE result_couriercominghome_details SET
Result_CourierComingHomeDetailsFlagConfirmed = 'Y',
Result_CourierComingHomeDetailsUserID = {$userid}
WHERE
Result_CourierComingHomeDetailsID = {$detail_id}
";
$this->db_onedev->query($sql);
//echo $sql;
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
public function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'
ORDER BY Result_CourierSPKNumbering ASC";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function sendemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$ids = "(".$prm['ids'].")";
$sql = "UPDATE result_sendemail SET Result_SendEmailStatus = 'S', Result_SendEmailUserID = {$userid} WHERE Result_SendEmailID IN {$ids}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "SELECT * FROM result_sendemail WHERE Result_SendEmailID IN {$ids}";
$dt_rst = $this->db_onedev->query($sql)->result_array();
foreach($dt_rst as $k => $v){
$dt_log = json_encode($v);
$sql = "INSERT INTO one_log.log_resultsendemail (
Log_ResultSendEmailDatetime,
Log_ResultSendEmailJson,
Log_ResultSendEmailUserID
)
VALUES(
NOW(),
'{$dt_log}',
{$userid}
)";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updateemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$id = $prm['id'];
$sql = "UPDATE t_orderdelivery SET T_OrderDeliveryDestination = '{$prm['edited_email']}', T_OrderDeliveryUserID = {$userid} WHERE T_OrderDeliveryID = {$id}";
//echo $sql;
$this->db_onedev->query($sql);
$result = array ("total" => 0, "records" => array());
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,924 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function add_verifications_label($orderid){
$query = " SELECT Result_VerificationsID as id,
IFNULL(Result_VerificationsValueID,0) as xid,
IFNULL(Result_VerificationsValueCheck,'N') as chex,
IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note,
Result_VerificationsLabel as label
FROM result_verifications
LEFT JOIN result_verifications_value ON Result_VerificationsValueResult_VerificationsID = Result_VerificationsID AND
Result_VerificationsValueSo_ResultEntryID = $orderid
WHERE
Result_VerificationIsActive = 'Y'
GROUP BY Result_VerificationsID
";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT Result_CourierSPKDetailID as spk_detail_id,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
'' as selected_receive,
IFNULL(Result_CourierComingHomeDetailsM_CourierStatusReceiveID,0) as received_id,
IFNULL(M_CourierStatusReceiveCode,'XXX') as received_code,
IFNULL(M_CourierStatusReceiveName,'Pilih status') as received_name,
IFNULL(Result_CourierComingHomeDetailsReceiver,'') as receiver_name,
IFNULL(Result_CourierComingHomeDetailsPayment,0) as payment,
Last_StatusPaymentBillTotal as bill_total,
Last_StatusPaymentPaid as paid,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status,
IFNULL(confirmed_staff.M_StaffName,'Belum dikonfirmasi') as confirmed_by,
Last_StatusPaymentIsLunas as status_payment,
Last_StatusPaymentUnpaid as unpaid
FROM result_courierspk_detail
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN result_couriercominghome ON Result_CourierComingHomeResultCourierSpkID = ResultCourierSpkID
LEFT JOIN result_couriercominghome_details ON Result_CourierComingHomeDetailsResult_CourierComingHomeID = Result_CourierComingHomeID
LEFT JOIN m_user ON Result_CourierComingHomeConfirmBy = M_UserID
LEFT JOIN m_staff confirmed_staff ON M_StaffM_UserID = confirmed_staff.M_StaffID
LEFT JOIN m_courierstatusreceive ON Result_CourierComingHomeDetailsM_CourierStatusReceiveID = M_CourierStatusReceiveID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKDetailIsActive = 'Y'
ORDER BY T_OrderPromiseDateTime ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['chex'] = false;
$rows[$k]['selected_receive'] = array("id"=>$v['received_id'],"code"=>$v['received_code'],"name"=>$v['received_name']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getreceivestatus()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT M_CourierStatusReceiveID as id, M_CourierStatusReceiveCode as code, M_CourierStatusReceiveName as name, M_CourierStatusReceiveStatus as status
FROM m_courierstatusreceive
WHERE
M_CourierStatusReceiveIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$rows_semua = array(array('id'=>0,'name'=>'Pilih status'));
$rst = array_merge($rows_semua,$rows);
$result = array("total" => count($rows), "records" => $rst, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function getcourier()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
$status = $prm["status"];
$datepromise = $prm["startdate"];
$filter = " AND Result_SendCourierStatus = '{$status}'";
$having = "HAVING not_ready_count = 0";
if($status == 'X'){
$filter = " AND ISNULL(Result_SendCourierID)";
$having = "HAVING not_ready_count > 0";
}
$sql_where = "WHERE T_OrderDetailIsActive = 'Y' ";
$sql = " SELECT 0 as id, 'Semua' as staff_name, 0 as not_ready_count
UNION
SELECT M_CourierID as id,
M_StaffName as staff_name,
fn_fo_check_status_not_ready_courier(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 2 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND Result_CourierSPKDetailIsActive = 'Y' AND
Result_CourierSPKDetailStatus = 'O'
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
$sql_where $filter
GROUP BY M_CourierID
$having";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function save()
{
try {
$xprm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
//# ambil parameter input
//print_r($xprm);
$prm = $xprm['patient'];
$xstatus = $xprm['act'];
$fostatusid = 3;
$fologcode = 'FO.VERIFICATION.CONFIRM';
$id = $prm['T_OrderHeaderID'];
echo $xstatus;
if($xstatus == 'N'){
$fostatusid = 4;
$fologcode = 'FO.VERIFICATION.REJECT';
}else{
$this->save_barcode_new($id);
}
//print_r($prm);
$xverificationnote = $prm['verification_note'];
//echo $xverificationnote;
$sql = "update t_orderheader
set
T_OrderHeaderVerificationNote = '{$xverificationnote}'
where
T_OrderHeaderID = $id";
//echo $sql;
$query = $this->db_onedev->query($sql);
/*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid);
$xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid);
$xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid);
$xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid);
$xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid);
$xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid);
$xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/
$sql = "insert into fo_status(
Fo_StatusDate,
Fo_StatusT_OrderHeaderID,
Fo_StatusM_StatusID,
Fo_StatusM_UserID,
Fo_StatusCreated,
Fo_StatusUpdated)
values( now(), ?, ?, ?, now(),now())";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$fostatusid,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("fo_status insert");
exit;
}
$data_log = array();
$data_log['orderid'] = $id;
/*$data_log['verification_patient'] = $prm['verification_patient'];
$data_log['verification_doctor'] = $prm['verification_doctor'];
$data_log['verification_companymou'] = $prm['verification_companymou'];
$data_log['verification_payment'] = $prm['verification_payment'];
$data_log['verification_info'] = $prm['verification_info'];
$data_log['verification_px'] = $prm['verification_px'];
$data_log['verification_delivery'] = $prm['verification_delivery'];*/
$json_dt_log = json_encode($data_log);
$sql = "insert into one_log.log_fo(
Log_FoDate,
Log_FoCode,
Log_FoJson,
Log_FoUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.fo_log insert");
exit;
}
if($xstatus == 'Y'){
$msg = 'Verifikasi berhasil dilakukan';
}
else{
$msg = 'Tolak Verifikasi berhasil dilakukan';
$sql = "INSERT INTO t_ordermessage (
T_OrderMessageT_OrderHeaderID,
T_OrderMessageType,
T_OrderMessageMessage,
T_OrderMessageFromUserID,
T_OrderMessageCreated,
T_OrderMessageLastUpdated
)
VALUES(
{$id},
'FO.VERIFICATION.REJECT',
'{$xverificationnote}',
{$xuserid},
NOW(),
NOW()
)";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("one_log.t_ordermessage insert");
exit;
}
}
$rows = array('message'=>$msg);
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_barcode_new($orderid){
$xuserid = $this->sys_user['M_UserID'];
$query =" SELECT T_SampleTypeID as id,
T_SampleTypeName as name,
'' as children
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
WHERE
T_OrderHeaderID = {$orderid}
GROUP BY T_SampleTypeID
";
//echo $query ;
$barcodes = $this->db_onedev->query($query)->result();
foreach($barcodes as $k => $v){
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
T_TestName as testname,
T_SampleTypeName as samplename,
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
FROM t_orderdetail
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
GROUP BY T_BarcodeLabID ";
$v->children = $this->db_onedev->query($query)->result_array();
//$v->children = $barcode_data;
foreach($v->children as $ki => $vi){
if($vi['chex'] == 'N')
$v->children[$ki]['chex'] = false;
else
$v->children[$ki]['chex'] = true;
$sql = "insert into t_barcodelab(
T_BarcodeLabT_OrderHeaderID,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabCreated,
T_BarcodeLabLastUpdated,
T_BarcodeLabUserID)
values( ?, ?, ?, now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$v->children[$ki]['barcodenumber'],
$v->children[$ki]['id'],
$xuserid
)
);
// echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("t_barcodelab insert");
exit;
}
}
}
//insert log
$supplies = array();
$query =" SELECT M_SuppliesID as id,
IFNULL(T_OrderSuppliesID,0) as xid,
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
IFNULL(T_OrderSuppliesQty,1) as qty,
M_SuppliesName as name,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
FROM m_supplies
JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
WHERE
M_SuppliesIsActive = 'Y'
";
//echo $query ;
$supplies = $this->db_onedev->query($query)->result_array();
foreach($supplies as $k => $v){
if($v['chex'] == 'N')
$supplies[$k]['chex'] = false;
else
$supplies[$k]['chex'] = true;
}
$dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes);
$fologcode = 'FO.Verification.BarcodeSupplies';
$json_dt_log = json_encode($dt_log);
$sql = "insert into one_log.log_supplies_barcode(
Log_SuppliesBarcodeDate,
Log_SuppliesBarcodeCode,
Log_SuppliesBarcodeJson,
Log_SuppliesBarcodeUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.log_supplies_barcode insert");
exit;
}
}
function saveverifications($id,$verifications,$type,$userid)
{
try {
//$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID;
//echo $xverificationtypeid;
//print_r($verifications);
foreach($verifications as $k => $v){
//print_r($v);
if(intval($v['xid']) == 0){
$sql = "insert into fo_verification(
Fo_VerificationT_OrderHeaderID,
Fo_VerificationFo_VericationTypeID,
Fo_VerificationIsOK,
Fo_VerificationReason,
Fo_VerificationCreated,
Fo_VerificationLastUpdated,
Fo_VerificationUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
$this->sys_error_db("fo_verification insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_delivery($id,$deliveries,$userid)
{
try {
foreach($deliveries as $k => $v){
if($v['id'] === 0){
$sql = "insert into fo_verification_delivery_add(
Fo_VerificationDeliveryAddT_OrderHeaderID,
Fo_VerificationDeliveryAddM_DeliveryID,
Fo_VerificationDeliveryAddM_DeliveryTypeID,
Fo_VerificationDeliveryAddDestination,
Fo_VerificationDeliveryAddAddressID,
Fo_VerificationDeliveryAddM_KelurahanID,
Fo_VerificationDeliveryAddOK,
Fo_VerificationDeliveryAddReason,
Fo_VerificationDeliveryAddCreated,
Fo_VerificationDeliveryAddLastUpdated,
Fo_VerificationDeliveryAddUserID)
values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['deliveryid'],
$v['typedeliveryid'],
$v['destination'],
$v['addressid'],
$v['vilageid'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_delivery(
Fo_VerificationDeliveryT_OrderHeaderID,
Fo_VerificationDeliveryT_OrderDeliveryID,
Fo_VerificationDeliveryIsOK,
Fo_VerificationDeliveryReason,
Fo_VerificationDeliveryCreated,
Fo_VerificationDeliveryLastUpdated,
Fo_VerificationDeliveryUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery insert");
exit;
}
//echo $this->db_onedev->last_query();
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['ohid']}
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_px($id,$pxs,$userid)
{
try {
foreach($pxs as $k => $v){
if(intval($v['id']) == 0){
$cxh = $v['chex'] == true ?'Y':'N';
$sql = "insert into fo_verification_test_add(
Fo_VerificationTestAddT_OrderHeaderID,
Fo_VerificationTestAddT_TestID,
Fo_VerificationTestAddBruto,
Fo_VerificationTestAddDiscount,
Fo_VerificationTestAddTotal,
Fo_VerificationTestAddIsOK,
Fo_VerificationTestAddIsCito,
Fo_VerificationTestAddCreated,
Fo_VerificationTestAddLastUpdated,
Fo_VerificationTestAddUserID)
values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_test(
Fo_VerificationTestT_OrderHeaderID,
Fo_VerificationTestT_OrderDetailID,
Fo_VerificationTestIsOK,
Fo_VerificationTestReason,
Fo_VerificationTestCreated,
Fo_VerificationTestLastUpdated,
Fo_VerificationTestUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function verify(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xstatus = $prm['act'];
if($xstatus == 'Y'){
$msg = "Berhasil melakukan verifikasi";
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
SELECT {$prm['trx_id']},
Result_VerificationsID,
'Y',
'',
{$userid},
NOW()
FROM result_verifications
WHERE
Result_VerificationIsActive = 'Y'
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = 'Y',
Result_VerificationsValueNote = '',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
$sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE So_ResultEntryID = {$prm['trx_id']}";
$this->db_onedev->query($sql);
}
else{
$msg = "Tolak untuk perbaikan";
$verifications = $prm['verifications'];
foreach($verifications as $k => $v){
$chx = $v['chex'] == true ?'Y':'N';
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
values( {$prm['trx_id']},
{$v['id']},
'{$chx}',
'{$v['note']}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = '{$chx}',
Result_VerificationsValueNote = '{$v['note']}',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
}
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg));
$this->sys_ok($result);
}
public function getstatuspergroup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
$sql =" SELECT Last_StatusPaymentBillTotal as total_bill,
Last_StatusPaymentPaid as paid,
Last_StatusPaymentUnpaid as unpaid,
Last_StatusPaymentIsLunas as status
FROM last_statuspayment
WHERE
Last_StatusPaymentT_OrderHeaderID = {$prm['T_OrderHeaderID']} ";
$rows['info_bill'] = $this->db_onedev->query($sql)->row_array();
$sql =" SELECT T_OrderDeliveryID as id,
IFNULL(Fo_VerificationDeliveryID,0) as xid,
M_DeliveryTypeCode as code,
IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex,
M_DeliveryID as deliveryid,
IFNULL(T_OrderDeliveryNoteValue,'') as note_courier,
M_DeliveryTypeID as typedeliveryid,
T_OrderDeliveryM_KelurahanID as vilageid,
IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note,
'reguler' as type,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName)
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 10 ) THEN CONCAT(M_DeliveryName)
ELSE
CONCAT(M_DeliveryName)
END as label,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 10 THEN M_CompanyAddress
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
ELSE
T_OrderDeliveryDestination
END as destination,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
ELSE
0
END as addressid
FROM t_orderdelivery
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4
LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2
LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y'
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 )
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 )
LEFT JOIN m_company ON T_OrderDeliveryAddressID = M_CompanyID AND ( T_OrderDeliveryM_DeliveryID = 10 )
LEFT JOIN t_orderdeliverynote ON T_OrderDeliveryNoteT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDeliveryNoteIsActive = 'Y'
WHERE
T_OrderDeliveryT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDeliveryID = {$prm['T_OrderDeliveryID']} AND T_OrderDeliveryIsActive = 'Y'
GROUP BY T_OrderDeliveryID
";
//echo $sql ;
$rows['info_deliveries'] = $this->db_onedev->query($sql)->result_array();
$sql = "SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'N'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY Group_ResultID
UNION
SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY T_OrderDetailID
";
$rows['info_test'] = $this->db_onedev->query($sql)->result_array();
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function receivedbycourier(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET Result_CourierSPKDetailStatus = 'S', Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
function confirmspv(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET
Result_CourierSPKDetailStatus = 'O',
Result_CourierSPKDetailConfirmedBy = {$userid},
Result_CourierSPKDetailConfirmedDateTime = NOW(),
Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
}

View File

@@ -0,0 +1,364 @@
<?php
class Done extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SampleStorage API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT Result_CourierSPKDetailResult_CourierSPKID as spk_id,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status_confirmed,
IFNULL(Result_CourierComingHomeID,0) as header_id,
IFNULL(Result_CourierComingHomeDetailsID,0) as detail_id,
Result_CourierSPKDetailID as spk_detail_id,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
'' as selected_receive,
IFNULL(Result_CourierComingHomeDetailsM_CourierStatusReceiveID,0) as received_id,
IFNULL(M_CourierStatusReceiveCode,'XXX') as received_code,
IFNULL(M_CourierStatusReceiveStatus,'') as received_status,
IFNULL(M_CourierStatusReceiveName,'Pilih status') as received_name,
IFNULL(Result_CourierComingHomeDetailsReceiver,'') as receiver_name,
IFNULL(DATE_FORMAT(Result_CourierComingHomeDetailsReceivedDateTime,'%d%m%Y%H%i'),'000000000000') as received_datetime,
DATE_FORMAT(Result_CourierComingHomeDetailsReceivedDateTime,'%d-%m-%Y %H:%i') as received_datetime_ina,
IFNULL(Result_CourierComingHomeDetailsPayment,0) as payment,
Result_CourierSPKDetailForceDone as force_done,
Last_StatusPaymentBillTotal as bill_total,
Last_StatusPaymentPaid as paid,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status,
IFNULL(confirmed_staff.M_StaffName,'Belum dikonfirmasi') as confirmed_by,
Last_StatusPaymentIsLunas as status_payment,
Last_StatusPaymentUnpaid as unpaid
FROM result_courierspk_detail
JOIN result_courierspk ON Result_CourierSPKID = Result_CourierSPKDetailResult_CourierSPKID
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN result_couriercominghome_details ON
Result_CourierComingHomeDetailsResult_CourierSPKDetailID = Result_CourierSPKDetailID
LEFT JOIN result_couriercominghome ON Result_CourierComingHomeDetailsResult_CourierComingHomeID = Result_CourierComingHomeID
LEFT JOIN m_user ON Result_CourierComingHomeConfirmBy = M_UserID
LEFT JOIN m_staff confirmed_staff ON M_UserM_StaffID = confirmed_staff.M_StaffID
LEFT JOIN m_courierstatusreceive ON Result_CourierComingHomeDetailsM_CourierStatusReceiveID = M_CourierStatusReceiveID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKStatus <> 'S' AND
( Result_CourierSPKDetailStatus = 'S' OR Result_CourierSPKDetailStatus = 'D' ) AND
Result_CourierSPKDetailIsActive = 'Y'
GROUP BY spk_detail_id
ORDER BY T_OrderPromiseDateTime ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['chex'] = false;
$rows[$k]['selected_receive'] = array("id"=>$v['received_id'],"code"=>$v['received_code'],"name"=>$v['received_name'],"status"=>$v["received_status"]);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getkerajaan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$rst = array(array('id'=>0,'name'=>'Semua'));
$sql = "SELECT 0 as id, 'Semua' as name UNION SELECT Nat_GroupID as id, Nat_GroupName as name FROM nat_group WHERE Nat_GroupIsActive = 'Y'";
$rst_db = $this->db_onedev->query($sql)->result_array();
//$c = array_combine($rst,$rst_db);
$result = array(
"total" => 1 ,
"records" => $rst_db
);
$this->sys_ok($result);
exit;
}
function dosend(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$selected = $prm['selected'];
foreach($selected as $k => $v){
$sql = "UPDATE result_frontoffice SET Result_FrontOfficeStatus = 'R' WHERE Result_FrontOfficeID = {$v['xid']}";
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function savereport(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$data = $prm['data'];
$spk_id = $data[0]['spk_id'];
$header_id = intval($data[0]['header_id']);
$last_id = $header_id;
if($header_id == 0){
$sql = "INSERT INTO result_couriercominghome(
Result_CourierComingHomeResultCourierSpkID,
Result_CourierComingHomeDateTime,
Result_CourierComingHomeCreated,
Result_CourierComingHomeUserID
)
VALUES(
{$spk_id},
NOW(),
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
$last_id = $this->db_onedev->insert_id();
}
foreach($data as $k => $v){
$detail_id = intval($v['detail_id']);
$xdatetime = $v['received_datetime'];
//echo substr($xdatetime,0,2)."-".substr($xdatetime,2,2)."-".substr($xdatetime,4,4)." ".substr($xdatetime,9,2).":".substr($xdatetime,11,2);
$xdatetime = date("Y-m-d H:i:s", strtotime(substr($xdatetime,0,2)."-".substr($xdatetime,2,2)."-".substr($xdatetime,4,4)." ".substr($xdatetime,8,2).":".substr($xdatetime,10,2)));
//echo $xdatetime;
if($detail_id == 0){
$sql = "INSERT INTO result_couriercominghome_details(
Result_CourierComingHomeDetailsResult_CourierComingHomeID,
Result_CourierComingHomeDetailsResult_CourierSPKDetailID,
Result_CourierComingHomeDetailsM_CourierStatusReceiveID,
Result_CourierComingHomeDetailsReceiver,
Result_CourierComingHomeDetailsPayment,
Result_CourierComingHomeDetailsReceivedDateTime,
Result_CourierComingHomeDetailsUserID,
Result_CourierComingHomeDetailsCreated
)
VALUES(
{$last_id},
{$v['spk_detail_id']},
{$v['received_id']},
'{$v['receiver_name']}',
{$v['payment']},
'{$xdatetime}',
{$userid},
NOW()
)";
}
else{
$sql = "UPDATE result_couriercominghome_details SET
Result_CourierComingHomeDetailsResult_CourierComingHomeID = {$last_id},
Result_CourierComingHomeDetailsResult_CourierSPKDetailID = {$v['spk_detail_id']},
Result_CourierComingHomeDetailsM_CourierStatusReceiveID = {$v['received_id']},
Result_CourierComingHomeDetailsReceiver = '{$v['receiver_name']}',
Result_CourierComingHomeDetailsPayment = {$v['payment']},
Result_CourierComingHomeDetailsReceivedDateTime = '{$xdatetime}',
Result_CourierComingHomeDetailsUserID = {$userid}
WHERE
Result_CourierComingHomeDetailsID = {$detail_id}
";
}
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function confirmreport(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$data = $prm['data'];
$spk_id = $data[0]['spk_id'];
$header_id = intval($data[0]['header_id']);
$last_id = $header_id;
$sql = "UPDATE result_couriercominghome SET
Result_CourierComingHomeConfirmed = 'Y',
Result_CourierComingHomeConfirmBy = {$userid},
Result_CourierComingHomeConfirmDateTime = NOW(),
Result_CourierComingHomeUserID = {$userid}
WHERE
Result_CourierComingHomeID = {$header_id}
";
$this->db_onedev->query($sql);
foreach($data as $k => $v){
$detail_id = intval($v['detail_id']);
$sql = "UPDATE result_couriercominghome_details SET
Result_CourierComingHomeDetailsFlagConfirmed = 'Y',
Result_CourierComingHomeDetailsUserID = {$userid}
WHERE
Result_CourierComingHomeDetailsID = {$detail_id}
";
$this->db_onedev->query($sql);
//echo $sql;
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
public function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'
ORDER BY Result_CourierSPKNumbering ASC";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function sendemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$ids = "(".$prm['ids'].")";
$sql = "UPDATE result_sendemail SET Result_SendEmailStatus = 'S', Result_SendEmailUserID = {$userid} WHERE Result_SendEmailID IN {$ids}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "SELECT * FROM result_sendemail WHERE Result_SendEmailID IN {$ids}";
$dt_rst = $this->db_onedev->query($sql)->result_array();
foreach($dt_rst as $k => $v){
$dt_log = json_encode($v);
$sql = "INSERT INTO one_log.log_resultsendemail (
Log_ResultSendEmailDatetime,
Log_ResultSendEmailJson,
Log_ResultSendEmailUserID
)
VALUES(
NOW(),
'{$dt_log}',
{$userid}
)";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updateemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$id = $prm['id'];
$sql = "UPDATE t_orderdelivery SET T_OrderDeliveryDestination = '{$prm['edited_email']}', T_OrderDeliveryUserID = {$userid} WHERE T_OrderDeliveryID = {$id}";
//echo $sql;
$this->db_onedev->query($sql);
$result = array ("total" => 0, "records" => array());
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,924 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function add_verifications_label($orderid){
$query = " SELECT Result_VerificationsID as id,
IFNULL(Result_VerificationsValueID,0) as xid,
IFNULL(Result_VerificationsValueCheck,'N') as chex,
IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note,
Result_VerificationsLabel as label
FROM result_verifications
LEFT JOIN result_verifications_value ON Result_VerificationsValueResult_VerificationsID = Result_VerificationsID AND
Result_VerificationsValueSo_ResultEntryID = $orderid
WHERE
Result_VerificationIsActive = 'Y'
GROUP BY Result_VerificationsID
";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT Result_CourierSPKDetailID as spk_detail_id,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
'' as selected_receive,
IFNULL(Result_CourierComingHomeDetailsM_CourierStatusReceiveID,0) as received_id,
IFNULL(M_CourierStatusReceiveCode,'XXX') as received_code,
IFNULL(M_CourierStatusReceiveName,'Pilih status') as received_name,
IFNULL(Result_CourierComingHomeDetailsReceiver,'') as receiver_name,
IFNULL(Result_CourierComingHomeDetailsPayment,0) as payment,
Last_StatusPaymentBillTotal as bill_total,
Last_StatusPaymentPaid as paid,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status,
IFNULL(confirmed_staff.M_StaffName,'Belum dikonfirmasi') as confirmed_by,
Last_StatusPaymentIsLunas as status_payment,
Last_StatusPaymentUnpaid as unpaid
FROM result_courierspk_detail
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN result_couriercominghome ON Result_CourierComingHomeResultCourierSpkID = ResultCourierSpkID
LEFT JOIN result_couriercominghome_details ON Result_CourierComingHomeDetailsResult_CourierComingHomeID = Result_CourierComingHomeID
LEFT JOIN m_user ON Result_CourierComingHomeConfirmBy = M_UserID
LEFT JOIN m_staff confirmed_staff ON M_StaffM_UserID = confirmed_staff.M_StaffID
LEFT JOIN m_courierstatusreceive ON Result_CourierComingHomeDetailsM_CourierStatusReceiveID = M_CourierStatusReceiveID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKDetailIsActive = 'Y'
ORDER BY T_OrderPromiseDateTime ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['chex'] = false;
$rows[$k]['selected_receive'] = array("id"=>$v['received_id'],"code"=>$v['received_code'],"name"=>$v['received_name']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getreceivestatus()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT M_CourierStatusReceiveID as id, M_CourierStatusReceiveCode as code, M_CourierStatusReceiveName as name, M_CourierStatusReceiveStatus as status
FROM m_courierstatusreceive
WHERE
M_CourierStatusReceiveIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$rows_semua = array(array('id'=>0,'name'=>'Pilih status'));
$rst = array_merge($rows_semua,$rows);
$result = array("total" => count($rows), "records" => $rst, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function getcourier()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
$status = $prm["status"];
$datepromise = $prm["startdate"];
$filter = " AND Result_SendCourierStatus = '{$status}'";
$having = "HAVING not_ready_count = 0";
if($status == 'X'){
$filter = " AND ISNULL(Result_SendCourierID)";
$having = "HAVING not_ready_count > 0";
}
$sql_where = "WHERE T_OrderDetailIsActive = 'Y' ";
$sql = " SELECT 0 as id, 'Semua' as staff_name, 0 as not_ready_count
UNION
SELECT M_CourierID as id,
M_StaffName as staff_name,
fn_fo_check_status_not_ready_courier(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 2 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND Result_CourierSPKDetailIsActive = 'Y' AND
Result_CourierSPKDetailStatus = 'O'
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
$sql_where $filter
GROUP BY M_CourierID
$having";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function save()
{
try {
$xprm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
//# ambil parameter input
//print_r($xprm);
$prm = $xprm['patient'];
$xstatus = $xprm['act'];
$fostatusid = 3;
$fologcode = 'FO.VERIFICATION.CONFIRM';
$id = $prm['T_OrderHeaderID'];
echo $xstatus;
if($xstatus == 'N'){
$fostatusid = 4;
$fologcode = 'FO.VERIFICATION.REJECT';
}else{
$this->save_barcode_new($id);
}
//print_r($prm);
$xverificationnote = $prm['verification_note'];
//echo $xverificationnote;
$sql = "update t_orderheader
set
T_OrderHeaderVerificationNote = '{$xverificationnote}'
where
T_OrderHeaderID = $id";
//echo $sql;
$query = $this->db_onedev->query($sql);
/*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid);
$xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid);
$xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid);
$xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid);
$xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid);
$xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid);
$xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/
$sql = "insert into fo_status(
Fo_StatusDate,
Fo_StatusT_OrderHeaderID,
Fo_StatusM_StatusID,
Fo_StatusM_UserID,
Fo_StatusCreated,
Fo_StatusUpdated)
values( now(), ?, ?, ?, now(),now())";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$fostatusid,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("fo_status insert");
exit;
}
$data_log = array();
$data_log['orderid'] = $id;
/*$data_log['verification_patient'] = $prm['verification_patient'];
$data_log['verification_doctor'] = $prm['verification_doctor'];
$data_log['verification_companymou'] = $prm['verification_companymou'];
$data_log['verification_payment'] = $prm['verification_payment'];
$data_log['verification_info'] = $prm['verification_info'];
$data_log['verification_px'] = $prm['verification_px'];
$data_log['verification_delivery'] = $prm['verification_delivery'];*/
$json_dt_log = json_encode($data_log);
$sql = "insert into one_log.log_fo(
Log_FoDate,
Log_FoCode,
Log_FoJson,
Log_FoUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.fo_log insert");
exit;
}
if($xstatus == 'Y'){
$msg = 'Verifikasi berhasil dilakukan';
}
else{
$msg = 'Tolak Verifikasi berhasil dilakukan';
$sql = "INSERT INTO t_ordermessage (
T_OrderMessageT_OrderHeaderID,
T_OrderMessageType,
T_OrderMessageMessage,
T_OrderMessageFromUserID,
T_OrderMessageCreated,
T_OrderMessageLastUpdated
)
VALUES(
{$id},
'FO.VERIFICATION.REJECT',
'{$xverificationnote}',
{$xuserid},
NOW(),
NOW()
)";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("one_log.t_ordermessage insert");
exit;
}
}
$rows = array('message'=>$msg);
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_barcode_new($orderid){
$xuserid = $this->sys_user['M_UserID'];
$query =" SELECT T_SampleTypeID as id,
T_SampleTypeName as name,
'' as children
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
WHERE
T_OrderHeaderID = {$orderid}
GROUP BY T_SampleTypeID
";
//echo $query ;
$barcodes = $this->db_onedev->query($query)->result();
foreach($barcodes as $k => $v){
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
T_TestName as testname,
T_SampleTypeName as samplename,
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
FROM t_orderdetail
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
GROUP BY T_BarcodeLabID ";
$v->children = $this->db_onedev->query($query)->result_array();
//$v->children = $barcode_data;
foreach($v->children as $ki => $vi){
if($vi['chex'] == 'N')
$v->children[$ki]['chex'] = false;
else
$v->children[$ki]['chex'] = true;
$sql = "insert into t_barcodelab(
T_BarcodeLabT_OrderHeaderID,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabCreated,
T_BarcodeLabLastUpdated,
T_BarcodeLabUserID)
values( ?, ?, ?, now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$v->children[$ki]['barcodenumber'],
$v->children[$ki]['id'],
$xuserid
)
);
// echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("t_barcodelab insert");
exit;
}
}
}
//insert log
$supplies = array();
$query =" SELECT M_SuppliesID as id,
IFNULL(T_OrderSuppliesID,0) as xid,
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
IFNULL(T_OrderSuppliesQty,1) as qty,
M_SuppliesName as name,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
FROM m_supplies
JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
WHERE
M_SuppliesIsActive = 'Y'
";
//echo $query ;
$supplies = $this->db_onedev->query($query)->result_array();
foreach($supplies as $k => $v){
if($v['chex'] == 'N')
$supplies[$k]['chex'] = false;
else
$supplies[$k]['chex'] = true;
}
$dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes);
$fologcode = 'FO.Verification.BarcodeSupplies';
$json_dt_log = json_encode($dt_log);
$sql = "insert into one_log.log_supplies_barcode(
Log_SuppliesBarcodeDate,
Log_SuppliesBarcodeCode,
Log_SuppliesBarcodeJson,
Log_SuppliesBarcodeUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.log_supplies_barcode insert");
exit;
}
}
function saveverifications($id,$verifications,$type,$userid)
{
try {
//$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID;
//echo $xverificationtypeid;
//print_r($verifications);
foreach($verifications as $k => $v){
//print_r($v);
if(intval($v['xid']) == 0){
$sql = "insert into fo_verification(
Fo_VerificationT_OrderHeaderID,
Fo_VerificationFo_VericationTypeID,
Fo_VerificationIsOK,
Fo_VerificationReason,
Fo_VerificationCreated,
Fo_VerificationLastUpdated,
Fo_VerificationUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
$this->sys_error_db("fo_verification insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_delivery($id,$deliveries,$userid)
{
try {
foreach($deliveries as $k => $v){
if($v['id'] === 0){
$sql = "insert into fo_verification_delivery_add(
Fo_VerificationDeliveryAddT_OrderHeaderID,
Fo_VerificationDeliveryAddM_DeliveryID,
Fo_VerificationDeliveryAddM_DeliveryTypeID,
Fo_VerificationDeliveryAddDestination,
Fo_VerificationDeliveryAddAddressID,
Fo_VerificationDeliveryAddM_KelurahanID,
Fo_VerificationDeliveryAddOK,
Fo_VerificationDeliveryAddReason,
Fo_VerificationDeliveryAddCreated,
Fo_VerificationDeliveryAddLastUpdated,
Fo_VerificationDeliveryAddUserID)
values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['deliveryid'],
$v['typedeliveryid'],
$v['destination'],
$v['addressid'],
$v['vilageid'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_delivery(
Fo_VerificationDeliveryT_OrderHeaderID,
Fo_VerificationDeliveryT_OrderDeliveryID,
Fo_VerificationDeliveryIsOK,
Fo_VerificationDeliveryReason,
Fo_VerificationDeliveryCreated,
Fo_VerificationDeliveryLastUpdated,
Fo_VerificationDeliveryUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery insert");
exit;
}
//echo $this->db_onedev->last_query();
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['ohid']}
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_px($id,$pxs,$userid)
{
try {
foreach($pxs as $k => $v){
if(intval($v['id']) == 0){
$cxh = $v['chex'] == true ?'Y':'N';
$sql = "insert into fo_verification_test_add(
Fo_VerificationTestAddT_OrderHeaderID,
Fo_VerificationTestAddT_TestID,
Fo_VerificationTestAddBruto,
Fo_VerificationTestAddDiscount,
Fo_VerificationTestAddTotal,
Fo_VerificationTestAddIsOK,
Fo_VerificationTestAddIsCito,
Fo_VerificationTestAddCreated,
Fo_VerificationTestAddLastUpdated,
Fo_VerificationTestAddUserID)
values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_test(
Fo_VerificationTestT_OrderHeaderID,
Fo_VerificationTestT_OrderDetailID,
Fo_VerificationTestIsOK,
Fo_VerificationTestReason,
Fo_VerificationTestCreated,
Fo_VerificationTestLastUpdated,
Fo_VerificationTestUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function verify(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xstatus = $prm['act'];
if($xstatus == 'Y'){
$msg = "Berhasil melakukan verifikasi";
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
SELECT {$prm['trx_id']},
Result_VerificationsID,
'Y',
'',
{$userid},
NOW()
FROM result_verifications
WHERE
Result_VerificationIsActive = 'Y'
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = 'Y',
Result_VerificationsValueNote = '',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
$sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE So_ResultEntryID = {$prm['trx_id']}";
$this->db_onedev->query($sql);
}
else{
$msg = "Tolak untuk perbaikan";
$verifications = $prm['verifications'];
foreach($verifications as $k => $v){
$chx = $v['chex'] == true ?'Y':'N';
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
values( {$prm['trx_id']},
{$v['id']},
'{$chx}',
'{$v['note']}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = '{$chx}',
Result_VerificationsValueNote = '{$v['note']}',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
}
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg));
$this->sys_ok($result);
}
public function getstatuspergroup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
$sql =" SELECT Last_StatusPaymentBillTotal as total_bill,
Last_StatusPaymentPaid as paid,
Last_StatusPaymentUnpaid as unpaid,
Last_StatusPaymentIsLunas as status
FROM last_statuspayment
WHERE
Last_StatusPaymentT_OrderHeaderID = {$prm['T_OrderHeaderID']} ";
$rows['info_bill'] = $this->db_onedev->query($sql)->row_array();
$sql =" SELECT T_OrderDeliveryID as id,
IFNULL(Fo_VerificationDeliveryID,0) as xid,
M_DeliveryTypeCode as code,
IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex,
M_DeliveryID as deliveryid,
IFNULL(T_OrderDeliveryNoteValue,'') as note_courier,
M_DeliveryTypeID as typedeliveryid,
T_OrderDeliveryM_KelurahanID as vilageid,
IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note,
'reguler' as type,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName)
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 10 ) THEN CONCAT(M_DeliveryName)
ELSE
CONCAT(M_DeliveryName)
END as label,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 10 THEN M_CompanyAddress
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
ELSE
T_OrderDeliveryDestination
END as destination,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
ELSE
0
END as addressid
FROM t_orderdelivery
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4
LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2
LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y'
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 )
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 )
LEFT JOIN m_company ON T_OrderDeliveryAddressID = M_CompanyID AND ( T_OrderDeliveryM_DeliveryID = 10 )
LEFT JOIN t_orderdeliverynote ON T_OrderDeliveryNoteT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDeliveryNoteIsActive = 'Y'
WHERE
T_OrderDeliveryT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDeliveryID = {$prm['T_OrderDeliveryID']} AND T_OrderDeliveryIsActive = 'Y'
GROUP BY T_OrderDeliveryID
";
//echo $sql ;
$rows['info_deliveries'] = $this->db_onedev->query($sql)->result_array();
$sql = "SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'N'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY Group_ResultID
UNION
SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY T_OrderDetailID
";
$rows['info_test'] = $this->db_onedev->query($sql)->result_array();
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function receivedbycourier(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET Result_CourierSPKDetailStatus = 'S', Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
function confirmspv(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET
Result_CourierSPKDetailStatus = 'O',
Result_CourierSPKDetailConfirmedBy = {$userid},
Result_CourierSPKDetailConfirmedDateTime = NOW(),
Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
}

View File

@@ -0,0 +1,367 @@
<?php
class Done extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SampleStorage API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT T_OrderHeaderID as order_id,
Result_CourierSPKDetailResult_CourierSPKID as spk_id,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status_confirmed,
IFNULL(Result_CourierComingHomeID,0) as header_id,
IFNULL(Result_CourierComingHomeDetailsID,0) as detail_id,
Result_CourierSPKDetailID as spk_detail_id,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
'' as selected_receive,
M_MouIsBill as flag_bill,
IFNULL(Result_CourierComingHomeDetailsM_CourierStatusReceiveID,0) as received_id,
IFNULL(M_CourierStatusReceiveCode,'XXX') as received_code,
IFNULL(M_CourierStatusReceiveStatus,'') as received_status,
IFNULL(M_CourierStatusReceiveName,'Pilih status') as received_name,
IFNULL(Result_CourierComingHomeDetailsReceiver,'') as receiver_name,
IFNULL(DATE_FORMAT(Result_CourierComingHomeDetailsReceivedDateTime,'%d%m%Y%H%i'),'000000000000') as received_datetime,
DATE_FORMAT(Result_CourierComingHomeDetailsReceivedDateTime,'%d-%m-%Y %H:%i') as received_datetime_ina,
IFNULL(Result_CourierComingHomeDetailsPayment,0) as payment,
Result_CourierSPKDetailForceDone as force_done,
Last_StatusPaymentBillTotal as bill_total,
Last_StatusPaymentPaid as paid,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status,
IFNULL(confirmed_staff.M_StaffName,'Belum dikonfirmasi') as confirmed_by,
Last_StatusPaymentIsLunas as status_payment,
Last_StatusPaymentUnpaid as unpaid
FROM result_courierspk_detail
JOIN result_courierspk ON Result_CourierSPKID = Result_CourierSPKDetailResult_CourierSPKID
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDeliveryIsActive = 'Y'
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN result_couriercominghome_details ON
Result_CourierComingHomeDetailsResult_CourierSPKDetailID = Result_CourierSPKDetailID
LEFT JOIN result_couriercominghome ON Result_CourierComingHomeDetailsResult_CourierComingHomeID = Result_CourierComingHomeID
LEFT JOIN m_user ON Result_CourierComingHomeConfirmBy = M_UserID
LEFT JOIN m_staff confirmed_staff ON M_UserM_StaffID = confirmed_staff.M_StaffID
LEFT JOIN m_courierstatusreceive ON Result_CourierComingHomeDetailsM_CourierStatusReceiveID = M_CourierStatusReceiveID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKStatus <> 'S' AND
( Result_CourierSPKDetailStatus = 'S' OR Result_CourierSPKDetailStatus = 'D' ) AND
Result_CourierSPKDetailIsActive = 'Y'
GROUP BY spk_detail_id
ORDER BY T_OrderPromiseDateTime ASC, T_OrderHeaderID ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['chex'] = false;
$rows[$k]['selected_receive'] = array("id"=>$v['received_id'],"code"=>$v['received_code'],"name"=>$v['received_name'],"status"=>$v["received_status"]);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getkerajaan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$rst = array(array('id'=>0,'name'=>'Semua'));
$sql = "SELECT 0 as id, 'Semua' as name UNION SELECT Nat_GroupID as id, Nat_GroupName as name FROM nat_group WHERE Nat_GroupIsActive = 'Y'";
$rst_db = $this->db_onedev->query($sql)->result_array();
//$c = array_combine($rst,$rst_db);
$result = array(
"total" => 1 ,
"records" => $rst_db
);
$this->sys_ok($result);
exit;
}
function dosend(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$selected = $prm['selected'];
foreach($selected as $k => $v){
$sql = "UPDATE result_frontoffice SET Result_FrontOfficeStatus = 'R' WHERE Result_FrontOfficeID = {$v['xid']}";
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function savereport(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$data = $prm['data'];
$spk_id = $data[0]['spk_id'];
$header_id = intval($data[0]['header_id']);
$last_id = $header_id;
if($header_id == 0){
$sql = "INSERT INTO result_couriercominghome(
Result_CourierComingHomeResultCourierSpkID,
Result_CourierComingHomeDateTime,
Result_CourierComingHomeCreated,
Result_CourierComingHomeUserID
)
VALUES(
{$spk_id},
NOW(),
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
$last_id = $this->db_onedev->insert_id();
}
foreach($data as $k => $v){
$detail_id = intval($v['detail_id']);
$xdatetime = $v['received_datetime'];
//echo substr($xdatetime,0,2)."-".substr($xdatetime,2,2)."-".substr($xdatetime,4,4)." ".substr($xdatetime,9,2).":".substr($xdatetime,11,2);
$xdatetime = date("Y-m-d H:i:s", strtotime(substr($xdatetime,0,2)."-".substr($xdatetime,2,2)."-".substr($xdatetime,4,4)." ".substr($xdatetime,8,2).":".substr($xdatetime,10,2)));
//echo $xdatetime;
if($detail_id == 0){
$sql = "INSERT INTO result_couriercominghome_details(
Result_CourierComingHomeDetailsResult_CourierComingHomeID,
Result_CourierComingHomeDetailsResult_CourierSPKDetailID,
Result_CourierComingHomeDetailsM_CourierStatusReceiveID,
Result_CourierComingHomeDetailsReceiver,
Result_CourierComingHomeDetailsPayment,
Result_CourierComingHomeDetailsReceivedDateTime,
Result_CourierComingHomeDetailsUserID,
Result_CourierComingHomeDetailsCreated
)
VALUES(
{$last_id},
{$v['spk_detail_id']},
{$v['received_id']},
'{$v['receiver_name']}',
{$v['payment']},
'{$xdatetime}',
{$userid},
NOW()
)";
}
else{
$sql = "UPDATE result_couriercominghome_details SET
Result_CourierComingHomeDetailsResult_CourierComingHomeID = {$last_id},
Result_CourierComingHomeDetailsResult_CourierSPKDetailID = {$v['spk_detail_id']},
Result_CourierComingHomeDetailsM_CourierStatusReceiveID = {$v['received_id']},
Result_CourierComingHomeDetailsReceiver = '{$v['receiver_name']}',
Result_CourierComingHomeDetailsPayment = {$v['payment']},
Result_CourierComingHomeDetailsReceivedDateTime = '{$xdatetime}',
Result_CourierComingHomeDetailsUserID = {$userid}
WHERE
Result_CourierComingHomeDetailsID = {$detail_id}
";
}
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function confirmreport(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$data = $prm['data'];
$spk_id = $data[0]['spk_id'];
$header_id = intval($data[0]['header_id']);
$last_id = $header_id;
$sql = "UPDATE result_couriercominghome SET
Result_CourierComingHomeConfirmed = 'Y',
Result_CourierComingHomeConfirmBy = {$userid},
Result_CourierComingHomeConfirmDateTime = NOW(),
Result_CourierComingHomeUserID = {$userid}
WHERE
Result_CourierComingHomeID = {$header_id}
";
$this->db_onedev->query($sql);
foreach($data as $k => $v){
$detail_id = intval($v['detail_id']);
$sql = "UPDATE result_couriercominghome_details SET
Result_CourierComingHomeDetailsFlagConfirmed = 'Y',
Result_CourierComingHomeDetailsUserID = {$userid}
WHERE
Result_CourierComingHomeDetailsID = {$detail_id}
";
$this->db_onedev->query($sql);
//echo $sql;
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
public function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'
ORDER BY Result_CourierSPKNumbering ASC";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function sendemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$ids = "(".$prm['ids'].")";
$sql = "UPDATE result_sendemail SET Result_SendEmailStatus = 'S', Result_SendEmailUserID = {$userid} WHERE Result_SendEmailID IN {$ids}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "SELECT * FROM result_sendemail WHERE Result_SendEmailID IN {$ids}";
$dt_rst = $this->db_onedev->query($sql)->result_array();
foreach($dt_rst as $k => $v){
$dt_log = json_encode($v);
$sql = "INSERT INTO one_log.log_resultsendemail (
Log_ResultSendEmailDatetime,
Log_ResultSendEmailJson,
Log_ResultSendEmailUserID
)
VALUES(
NOW(),
'{$dt_log}',
{$userid}
)";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updateemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$id = $prm['id'];
$sql = "UPDATE t_orderdelivery SET T_OrderDeliveryDestination = '{$prm['edited_email']}', T_OrderDeliveryUserID = {$userid} WHERE T_OrderDeliveryID = {$id}";
//echo $sql;
$this->db_onedev->query($sql);
$result = array ("total" => 0, "records" => array());
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,925 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function add_verifications_label($orderid){
$query = " SELECT Result_VerificationsID as id,
IFNULL(Result_VerificationsValueID,0) as xid,
IFNULL(Result_VerificationsValueCheck,'N') as chex,
IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note,
Result_VerificationsLabel as label
FROM result_verifications
LEFT JOIN result_verifications_value ON Result_VerificationsValueResult_VerificationsID = Result_VerificationsID AND
Result_VerificationsValueSo_ResultEntryID = $orderid
WHERE
Result_VerificationIsActive = 'Y'
GROUP BY Result_VerificationsID
";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT Result_CourierSPKDetailID as spk_detail_id,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
'' as selected_receive,
IFNULL(Result_CourierComingHomeDetailsM_CourierStatusReceiveID,0) as received_id,
IFNULL(M_CourierStatusReceiveCode,'XXX') as received_code,
IFNULL(M_CourierStatusReceiveStatus, 'X') as received_status,
IFNULL(M_CourierStatusReceiveName,'Pilih status') as received_name,
IFNULL(Result_CourierComingHomeDetailsReceiver,'') as receiver_name,
IFNULL(Result_CourierComingHomeDetailsPayment,0) as payment,
Last_StatusPaymentBillTotal as bill_total,
Last_StatusPaymentPaid as paid,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(Result_CourierComingHomeConfirmed,'X') as status,
IFNULL(confirmed_staff.M_StaffName,'Belum dikonfirmasi') as confirmed_by,
Last_StatusPaymentIsLunas as status_payment,
Last_StatusPaymentUnpaid as unpaid
FROM result_courierspk_detail
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
LEFT JOIN result_couriercominghome ON Result_CourierComingHomeResultCourierSpkID = ResultCourierSpkID
LEFT JOIN result_couriercominghome_details ON Result_CourierComingHomeDetailsResult_CourierComingHomeID = Result_CourierComingHomeID
LEFT JOIN m_user ON Result_CourierComingHomeConfirmBy = M_UserID
LEFT JOIN m_staff confirmed_staff ON M_StaffM_UserID = confirmed_staff.M_StaffID
LEFT JOIN m_courierstatusreceive ON Result_CourierComingHomeDetailsM_CourierStatusReceiveID = M_CourierStatusReceiveID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKDetailIsActive = 'Y'
ORDER BY T_OrderPromiseDateTime ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['chex'] = false;
$rows[$k]['selected_receive'] = array("id"=>$v['received_id'],"code"=>$v['received_code'],"name"=>$v['received_name']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getreceivestatus()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT M_CourierStatusReceiveID as id, M_CourierStatusReceiveCode as code, M_CourierStatusReceiveName as name, M_CourierStatusReceiveStatus as status
FROM m_courierstatusreceive
WHERE
M_CourierStatusReceiveIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$rows_semua = array(array('id'=>0,'name'=>'Pilih status'));
$rst = array_merge($rows_semua,$rows);
$result = array("total" => count($rows), "records" => $rst, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function getcourier()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
$status = $prm["status"];
$datepromise = $prm["startdate"];
$filter = " AND Result_SendCourierStatus = '{$status}'";
$having = "HAVING not_ready_count = 0";
if($status == 'X'){
$filter = " AND ISNULL(Result_SendCourierID)";
$having = "HAVING not_ready_count > 0";
}
$sql_where = "WHERE T_OrderDetailIsActive = 'Y' ";
$sql = " SELECT 0 as id, 'Semua' as staff_name, 0 as not_ready_count
UNION
SELECT M_CourierID as id,
M_StaffName as staff_name,
fn_fo_check_status_not_ready_courier(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 2 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND Result_CourierSPKDetailIsActive = 'Y' AND
Result_CourierSPKDetailStatus = 'O'
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
$sql_where $filter
GROUP BY M_CourierID
$having";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function save()
{
try {
$xprm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
//# ambil parameter input
//print_r($xprm);
$prm = $xprm['patient'];
$xstatus = $xprm['act'];
$fostatusid = 3;
$fologcode = 'FO.VERIFICATION.CONFIRM';
$id = $prm['T_OrderHeaderID'];
echo $xstatus;
if($xstatus == 'N'){
$fostatusid = 4;
$fologcode = 'FO.VERIFICATION.REJECT';
}else{
$this->save_barcode_new($id);
}
//print_r($prm);
$xverificationnote = $prm['verification_note'];
//echo $xverificationnote;
$sql = "update t_orderheader
set
T_OrderHeaderVerificationNote = '{$xverificationnote}'
where
T_OrderHeaderID = $id";
//echo $sql;
$query = $this->db_onedev->query($sql);
/*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid);
$xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid);
$xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid);
$xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid);
$xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid);
$xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid);
$xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/
$sql = "insert into fo_status(
Fo_StatusDate,
Fo_StatusT_OrderHeaderID,
Fo_StatusM_StatusID,
Fo_StatusM_UserID,
Fo_StatusCreated,
Fo_StatusUpdated)
values( now(), ?, ?, ?, now(),now())";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$fostatusid,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("fo_status insert");
exit;
}
$data_log = array();
$data_log['orderid'] = $id;
/*$data_log['verification_patient'] = $prm['verification_patient'];
$data_log['verification_doctor'] = $prm['verification_doctor'];
$data_log['verification_companymou'] = $prm['verification_companymou'];
$data_log['verification_payment'] = $prm['verification_payment'];
$data_log['verification_info'] = $prm['verification_info'];
$data_log['verification_px'] = $prm['verification_px'];
$data_log['verification_delivery'] = $prm['verification_delivery'];*/
$json_dt_log = json_encode($data_log);
$sql = "insert into one_log.log_fo(
Log_FoDate,
Log_FoCode,
Log_FoJson,
Log_FoUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.fo_log insert");
exit;
}
if($xstatus == 'Y'){
$msg = 'Verifikasi berhasil dilakukan';
}
else{
$msg = 'Tolak Verifikasi berhasil dilakukan';
$sql = "INSERT INTO t_ordermessage (
T_OrderMessageT_OrderHeaderID,
T_OrderMessageType,
T_OrderMessageMessage,
T_OrderMessageFromUserID,
T_OrderMessageCreated,
T_OrderMessageLastUpdated
)
VALUES(
{$id},
'FO.VERIFICATION.REJECT',
'{$xverificationnote}',
{$xuserid},
NOW(),
NOW()
)";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("one_log.t_ordermessage insert");
exit;
}
}
$rows = array('message'=>$msg);
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_barcode_new($orderid){
$xuserid = $this->sys_user['M_UserID'];
$query =" SELECT T_SampleTypeID as id,
T_SampleTypeName as name,
'' as children
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
WHERE
T_OrderHeaderID = {$orderid}
GROUP BY T_SampleTypeID
";
//echo $query ;
$barcodes = $this->db_onedev->query($query)->result();
foreach($barcodes as $k => $v){
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
T_TestName as testname,
T_SampleTypeName as samplename,
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
FROM t_orderdetail
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
GROUP BY T_BarcodeLabID ";
$v->children = $this->db_onedev->query($query)->result_array();
//$v->children = $barcode_data;
foreach($v->children as $ki => $vi){
if($vi['chex'] == 'N')
$v->children[$ki]['chex'] = false;
else
$v->children[$ki]['chex'] = true;
$sql = "insert into t_barcodelab(
T_BarcodeLabT_OrderHeaderID,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabCreated,
T_BarcodeLabLastUpdated,
T_BarcodeLabUserID)
values( ?, ?, ?, now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$v->children[$ki]['barcodenumber'],
$v->children[$ki]['id'],
$xuserid
)
);
// echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("t_barcodelab insert");
exit;
}
}
}
//insert log
$supplies = array();
$query =" SELECT M_SuppliesID as id,
IFNULL(T_OrderSuppliesID,0) as xid,
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
IFNULL(T_OrderSuppliesQty,1) as qty,
M_SuppliesName as name,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
FROM m_supplies
JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
WHERE
M_SuppliesIsActive = 'Y'
";
//echo $query ;
$supplies = $this->db_onedev->query($query)->result_array();
foreach($supplies as $k => $v){
if($v['chex'] == 'N')
$supplies[$k]['chex'] = false;
else
$supplies[$k]['chex'] = true;
}
$dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes);
$fologcode = 'FO.Verification.BarcodeSupplies';
$json_dt_log = json_encode($dt_log);
$sql = "insert into one_log.log_supplies_barcode(
Log_SuppliesBarcodeDate,
Log_SuppliesBarcodeCode,
Log_SuppliesBarcodeJson,
Log_SuppliesBarcodeUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.log_supplies_barcode insert");
exit;
}
}
function saveverifications($id,$verifications,$type,$userid)
{
try {
//$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID;
//echo $xverificationtypeid;
//print_r($verifications);
foreach($verifications as $k => $v){
//print_r($v);
if(intval($v['xid']) == 0){
$sql = "insert into fo_verification(
Fo_VerificationT_OrderHeaderID,
Fo_VerificationFo_VericationTypeID,
Fo_VerificationIsOK,
Fo_VerificationReason,
Fo_VerificationCreated,
Fo_VerificationLastUpdated,
Fo_VerificationUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
$this->sys_error_db("fo_verification insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_delivery($id,$deliveries,$userid)
{
try {
foreach($deliveries as $k => $v){
if($v['id'] === 0){
$sql = "insert into fo_verification_delivery_add(
Fo_VerificationDeliveryAddT_OrderHeaderID,
Fo_VerificationDeliveryAddM_DeliveryID,
Fo_VerificationDeliveryAddM_DeliveryTypeID,
Fo_VerificationDeliveryAddDestination,
Fo_VerificationDeliveryAddAddressID,
Fo_VerificationDeliveryAddM_KelurahanID,
Fo_VerificationDeliveryAddOK,
Fo_VerificationDeliveryAddReason,
Fo_VerificationDeliveryAddCreated,
Fo_VerificationDeliveryAddLastUpdated,
Fo_VerificationDeliveryAddUserID)
values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['deliveryid'],
$v['typedeliveryid'],
$v['destination'],
$v['addressid'],
$v['vilageid'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_delivery(
Fo_VerificationDeliveryT_OrderHeaderID,
Fo_VerificationDeliveryT_OrderDeliveryID,
Fo_VerificationDeliveryIsOK,
Fo_VerificationDeliveryReason,
Fo_VerificationDeliveryCreated,
Fo_VerificationDeliveryLastUpdated,
Fo_VerificationDeliveryUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery insert");
exit;
}
//echo $this->db_onedev->last_query();
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['ohid']}
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_px($id,$pxs,$userid)
{
try {
foreach($pxs as $k => $v){
if(intval($v['id']) == 0){
$cxh = $v['chex'] == true ?'Y':'N';
$sql = "insert into fo_verification_test_add(
Fo_VerificationTestAddT_OrderHeaderID,
Fo_VerificationTestAddT_TestID,
Fo_VerificationTestAddBruto,
Fo_VerificationTestAddDiscount,
Fo_VerificationTestAddTotal,
Fo_VerificationTestAddIsOK,
Fo_VerificationTestAddIsCito,
Fo_VerificationTestAddCreated,
Fo_VerificationTestAddLastUpdated,
Fo_VerificationTestAddUserID)
values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_test(
Fo_VerificationTestT_OrderHeaderID,
Fo_VerificationTestT_OrderDetailID,
Fo_VerificationTestIsOK,
Fo_VerificationTestReason,
Fo_VerificationTestCreated,
Fo_VerificationTestLastUpdated,
Fo_VerificationTestUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function verify(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xstatus = $prm['act'];
if($xstatus == 'Y'){
$msg = "Berhasil melakukan verifikasi";
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
SELECT {$prm['trx_id']},
Result_VerificationsID,
'Y',
'',
{$userid},
NOW()
FROM result_verifications
WHERE
Result_VerificationIsActive = 'Y'
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = 'Y',
Result_VerificationsValueNote = '',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
$sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE So_ResultEntryID = {$prm['trx_id']}";
$this->db_onedev->query($sql);
}
else{
$msg = "Tolak untuk perbaikan";
$verifications = $prm['verifications'];
foreach($verifications as $k => $v){
$chx = $v['chex'] == true ?'Y':'N';
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
values( {$prm['trx_id']},
{$v['id']},
'{$chx}',
'{$v['note']}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = '{$chx}',
Result_VerificationsValueNote = '{$v['note']}',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
}
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg));
$this->sys_ok($result);
}
public function getstatuspergroup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
$sql =" SELECT Last_StatusPaymentBillTotal as total_bill,
Last_StatusPaymentPaid as paid,
Last_StatusPaymentUnpaid as unpaid,
Last_StatusPaymentIsLunas as status
FROM last_statuspayment
WHERE
Last_StatusPaymentT_OrderHeaderID = {$prm['T_OrderHeaderID']} ";
$rows['info_bill'] = $this->db_onedev->query($sql)->row_array();
$sql =" SELECT T_OrderDeliveryID as id,
IFNULL(Fo_VerificationDeliveryID,0) as xid,
M_DeliveryTypeCode as code,
IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex,
M_DeliveryID as deliveryid,
IFNULL(T_OrderDeliveryNoteValue,'') as note_courier,
M_DeliveryTypeID as typedeliveryid,
T_OrderDeliveryM_KelurahanID as vilageid,
IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note,
'reguler' as type,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName)
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 10 ) THEN CONCAT(M_DeliveryName)
ELSE
CONCAT(M_DeliveryName)
END as label,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 10 THEN M_CompanyAddress
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
ELSE
T_OrderDeliveryDestination
END as destination,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
ELSE
0
END as addressid
FROM t_orderdelivery
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4
LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2
LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y'
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 )
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 )
LEFT JOIN m_company ON T_OrderDeliveryAddressID = M_CompanyID AND ( T_OrderDeliveryM_DeliveryID = 10 )
LEFT JOIN t_orderdeliverynote ON T_OrderDeliveryNoteT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDeliveryNoteIsActive = 'Y'
WHERE
T_OrderDeliveryT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDeliveryID = {$prm['T_OrderDeliveryID']} AND T_OrderDeliveryIsActive = 'Y'
GROUP BY T_OrderDeliveryID
";
//echo $sql ;
$rows['info_deliveries'] = $this->db_onedev->query($sql)->result_array();
$sql = "SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'N'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY Group_ResultID
UNION
SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY T_OrderDetailID
";
$rows['info_test'] = $this->db_onedev->query($sql)->result_array();
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function receivedbycourier(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET Result_CourierSPKDetailStatus = 'S', Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
function confirmspv(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET
Result_CourierSPKDetailStatus = 'O',
Result_CourierSPKDetailConfirmedBy = {$userid},
Result_CourierSPKDetailConfirmedDateTime = NOW(),
Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
}

View File

@@ -0,0 +1,205 @@
<?php
class Done extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SampleStorage API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT Result_CourierSPKDetailID as id,T_OrderHeaderID,
T_OrderDeliveryID ,T_OrderPromiseID,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(spv_staff.M_StaffName,'Belum dikonfirmasi') as spv_name,
Result_CourierSPKDetailStatus as status
FROM result_courierspk_detail
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
LEFT JOIN m_user ON Result_CourierSPKDetailConfirmedBy = M_UserID
LEFT JOIN m_staff spv_staff ON M_UserM_StaffID = spv_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKDetailIsActive = 'Y'
ORDER BY T_OrderPromiseDateTime ASC, T_OrderHeaderID ASC ";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['chex'] = false;
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getkerajaan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$rst = array(array('id'=>0,'name'=>'Semua'));
$sql = "SELECT 0 as id, 'Semua' as name UNION SELECT Nat_GroupID as id, Nat_GroupName as name FROM nat_group WHERE Nat_GroupIsActive = 'Y'";
$rst_db = $this->db_onedev->query($sql)->result_array();
//$c = array_combine($rst,$rst_db);
$result = array(
"total" => 1 ,
"records" => $rst_db
);
$this->sys_ok($result);
exit;
}
function dosend(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$selected = $prm['selected'];
foreach($selected as $k => $v){
$sql = "UPDATE result_frontoffice SET Result_FrontOfficeStatus = 'R' WHERE Result_FrontOfficeID = {$v['xid']}";
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
public function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function sendemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$ids = "(".$prm['ids'].")";
$sql = "UPDATE result_sendemail SET Result_SendEmailStatus = 'S', Result_SendEmailUserID = {$userid} WHERE Result_SendEmailID IN {$ids}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "SELECT * FROM result_sendemail WHERE Result_SendEmailID IN {$ids}";
$dt_rst = $this->db_onedev->query($sql)->result_array();
foreach($dt_rst as $k => $v){
$dt_log = json_encode($v);
$sql = "INSERT INTO one_log.log_resultsendemail (
Log_ResultSendEmailDatetime,
Log_ResultSendEmailJson,
Log_ResultSendEmailUserID
)
VALUES(
NOW(),
'{$dt_log}',
{$userid}
)";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updateemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$id = $prm['id'];
$sql = "UPDATE t_orderdelivery SET T_OrderDeliveryDestination = '{$prm['edited_email']}', T_OrderDeliveryUserID = {$userid} WHERE T_OrderDeliveryID = {$id}";
//echo $sql;
$this->db_onedev->query($sql);
$result = array ("total" => 0, "records" => array());
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,886 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function add_verifications_label($orderid){
$query = " SELECT Result_VerificationsID as id,
IFNULL(Result_VerificationsValueID,0) as xid,
IFNULL(Result_VerificationsValueCheck,'N') as chex,
IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note,
Result_VerificationsLabel as label
FROM result_verifications
LEFT JOIN result_verifications_value ON Result_VerificationsValueResult_VerificationsID = Result_VerificationsID AND
Result_VerificationsValueSo_ResultEntryID = $orderid
WHERE
Result_VerificationIsActive = 'Y'
GROUP BY Result_VerificationsID
";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(spv_staff.M_StaffName,'Belum dikonfirmasi') as spv_name
FROM result_courierspk_detail
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
LEFT JOIN m_staff spv_staff ON M_CourierM_StaffID = spv_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKDetailIsActive = 'Y'
ORDER BY T_OrderPromiseDateTime ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['chex'] = false;
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function getcourier()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
$status = $prm["status"];
$datepromise = $prm["startdate"];
$filter = " AND Result_SendCourierStatus = '{$status}'";
$having = "HAVING not_ready_count = 0";
if($status == 'X'){
$filter = " AND ISNULL(Result_SendCourierID)";
$having = "HAVING not_ready_count > 0";
}
$sql_where = "WHERE T_OrderDetailIsActive = 'Y' ";
$sql = " SELECT 0 as id, 'Semua' as staff_name, 0 as not_ready_count
UNION
SELECT M_CourierID as id,
M_StaffName as staff_name,
fn_fo_check_status_not_ready_courier(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 2 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND Result_CourierSPKDetailIsActive = 'Y' AND
Result_CourierSPKDetailStatus = 'O'
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
$sql_where $filter
GROUP BY M_CourierID
$having";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function save()
{
try {
$xprm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
//# ambil parameter input
//print_r($xprm);
$prm = $xprm['patient'];
$xstatus = $xprm['act'];
$fostatusid = 3;
$fologcode = 'FO.VERIFICATION.CONFIRM';
$id = $prm['T_OrderHeaderID'];
echo $xstatus;
if($xstatus == 'N'){
$fostatusid = 4;
$fologcode = 'FO.VERIFICATION.REJECT';
}else{
$this->save_barcode_new($id);
}
//print_r($prm);
$xverificationnote = $prm['verification_note'];
//echo $xverificationnote;
$sql = "update t_orderheader
set
T_OrderHeaderVerificationNote = '{$xverificationnote}'
where
T_OrderHeaderID = $id";
//echo $sql;
$query = $this->db_onedev->query($sql);
/*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid);
$xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid);
$xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid);
$xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid);
$xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid);
$xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid);
$xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/
$sql = "insert into fo_status(
Fo_StatusDate,
Fo_StatusT_OrderHeaderID,
Fo_StatusM_StatusID,
Fo_StatusM_UserID,
Fo_StatusCreated,
Fo_StatusUpdated)
values( now(), ?, ?, ?, now(),now())";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$fostatusid,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("fo_status insert");
exit;
}
$data_log = array();
$data_log['orderid'] = $id;
/*$data_log['verification_patient'] = $prm['verification_patient'];
$data_log['verification_doctor'] = $prm['verification_doctor'];
$data_log['verification_companymou'] = $prm['verification_companymou'];
$data_log['verification_payment'] = $prm['verification_payment'];
$data_log['verification_info'] = $prm['verification_info'];
$data_log['verification_px'] = $prm['verification_px'];
$data_log['verification_delivery'] = $prm['verification_delivery'];*/
$json_dt_log = json_encode($data_log);
$sql = "insert into one_log.log_fo(
Log_FoDate,
Log_FoCode,
Log_FoJson,
Log_FoUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.fo_log insert");
exit;
}
if($xstatus == 'Y'){
$msg = 'Verifikasi berhasil dilakukan';
}
else{
$msg = 'Tolak Verifikasi berhasil dilakukan';
$sql = "INSERT INTO t_ordermessage (
T_OrderMessageT_OrderHeaderID,
T_OrderMessageType,
T_OrderMessageMessage,
T_OrderMessageFromUserID,
T_OrderMessageCreated,
T_OrderMessageLastUpdated
)
VALUES(
{$id},
'FO.VERIFICATION.REJECT',
'{$xverificationnote}',
{$xuserid},
NOW(),
NOW()
)";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("one_log.t_ordermessage insert");
exit;
}
}
$rows = array('message'=>$msg);
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_barcode_new($orderid){
$xuserid = $this->sys_user['M_UserID'];
$query =" SELECT T_SampleTypeID as id,
T_SampleTypeName as name,
'' as children
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
WHERE
T_OrderHeaderID = {$orderid}
GROUP BY T_SampleTypeID
";
//echo $query ;
$barcodes = $this->db_onedev->query($query)->result();
foreach($barcodes as $k => $v){
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
T_TestName as testname,
T_SampleTypeName as samplename,
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
FROM t_orderdetail
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
GROUP BY T_BarcodeLabID ";
$v->children = $this->db_onedev->query($query)->result_array();
//$v->children = $barcode_data;
foreach($v->children as $ki => $vi){
if($vi['chex'] == 'N')
$v->children[$ki]['chex'] = false;
else
$v->children[$ki]['chex'] = true;
$sql = "insert into t_barcodelab(
T_BarcodeLabT_OrderHeaderID,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabCreated,
T_BarcodeLabLastUpdated,
T_BarcodeLabUserID)
values( ?, ?, ?, now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$v->children[$ki]['barcodenumber'],
$v->children[$ki]['id'],
$xuserid
)
);
// echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("t_barcodelab insert");
exit;
}
}
}
//insert log
$supplies = array();
$query =" SELECT M_SuppliesID as id,
IFNULL(T_OrderSuppliesID,0) as xid,
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
IFNULL(T_OrderSuppliesQty,1) as qty,
M_SuppliesName as name,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
FROM m_supplies
JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
WHERE
M_SuppliesIsActive = 'Y'
";
//echo $query ;
$supplies = $this->db_onedev->query($query)->result_array();
foreach($supplies as $k => $v){
if($v['chex'] == 'N')
$supplies[$k]['chex'] = false;
else
$supplies[$k]['chex'] = true;
}
$dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes);
$fologcode = 'FO.Verification.BarcodeSupplies';
$json_dt_log = json_encode($dt_log);
$sql = "insert into one_log.log_supplies_barcode(
Log_SuppliesBarcodeDate,
Log_SuppliesBarcodeCode,
Log_SuppliesBarcodeJson,
Log_SuppliesBarcodeUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.log_supplies_barcode insert");
exit;
}
}
function saveverifications($id,$verifications,$type,$userid)
{
try {
//$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID;
//echo $xverificationtypeid;
//print_r($verifications);
foreach($verifications as $k => $v){
//print_r($v);
if(intval($v['xid']) == 0){
$sql = "insert into fo_verification(
Fo_VerificationT_OrderHeaderID,
Fo_VerificationFo_VericationTypeID,
Fo_VerificationIsOK,
Fo_VerificationReason,
Fo_VerificationCreated,
Fo_VerificationLastUpdated,
Fo_VerificationUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
$this->sys_error_db("fo_verification insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_delivery($id,$deliveries,$userid)
{
try {
foreach($deliveries as $k => $v){
if($v['id'] === 0){
$sql = "insert into fo_verification_delivery_add(
Fo_VerificationDeliveryAddT_OrderHeaderID,
Fo_VerificationDeliveryAddM_DeliveryID,
Fo_VerificationDeliveryAddM_DeliveryTypeID,
Fo_VerificationDeliveryAddDestination,
Fo_VerificationDeliveryAddAddressID,
Fo_VerificationDeliveryAddM_KelurahanID,
Fo_VerificationDeliveryAddOK,
Fo_VerificationDeliveryAddReason,
Fo_VerificationDeliveryAddCreated,
Fo_VerificationDeliveryAddLastUpdated,
Fo_VerificationDeliveryAddUserID)
values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['deliveryid'],
$v['typedeliveryid'],
$v['destination'],
$v['addressid'],
$v['vilageid'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_delivery(
Fo_VerificationDeliveryT_OrderHeaderID,
Fo_VerificationDeliveryT_OrderDeliveryID,
Fo_VerificationDeliveryIsOK,
Fo_VerificationDeliveryReason,
Fo_VerificationDeliveryCreated,
Fo_VerificationDeliveryLastUpdated,
Fo_VerificationDeliveryUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery insert");
exit;
}
//echo $this->db_onedev->last_query();
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['ohid']}
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_px($id,$pxs,$userid)
{
try {
foreach($pxs as $k => $v){
if(intval($v['id']) == 0){
$cxh = $v['chex'] == true ?'Y':'N';
$sql = "insert into fo_verification_test_add(
Fo_VerificationTestAddT_OrderHeaderID,
Fo_VerificationTestAddT_TestID,
Fo_VerificationTestAddBruto,
Fo_VerificationTestAddDiscount,
Fo_VerificationTestAddTotal,
Fo_VerificationTestAddIsOK,
Fo_VerificationTestAddIsCito,
Fo_VerificationTestAddCreated,
Fo_VerificationTestAddLastUpdated,
Fo_VerificationTestAddUserID)
values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_test(
Fo_VerificationTestT_OrderHeaderID,
Fo_VerificationTestT_OrderDetailID,
Fo_VerificationTestIsOK,
Fo_VerificationTestReason,
Fo_VerificationTestCreated,
Fo_VerificationTestLastUpdated,
Fo_VerificationTestUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function verify(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xstatus = $prm['act'];
if($xstatus == 'Y'){
$msg = "Berhasil melakukan verifikasi";
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
SELECT {$prm['trx_id']},
Result_VerificationsID,
'Y',
'',
{$userid},
NOW()
FROM result_verifications
WHERE
Result_VerificationIsActive = 'Y'
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = 'Y',
Result_VerificationsValueNote = '',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
$sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE So_ResultEntryID = {$prm['trx_id']}";
$this->db_onedev->query($sql);
}
else{
$msg = "Tolak untuk perbaikan";
$verifications = $prm['verifications'];
foreach($verifications as $k => $v){
$chx = $v['chex'] == true ?'Y':'N';
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
values( {$prm['trx_id']},
{$v['id']},
'{$chx}',
'{$v['note']}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = '{$chx}',
Result_VerificationsValueNote = '{$v['note']}',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
}
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg));
$this->sys_ok($result);
}
public function getstatuspergroup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
$sql =" SELECT Last_StatusPaymentBillTotal as total_bill,
Last_StatusPaymentPaid as paid,
Last_StatusPaymentUnpaid as unpaid,
Last_StatusPaymentIsLunas as status
FROM last_statuspayment
WHERE
Last_StatusPaymentT_OrderHeaderID = {$prm['T_OrderHeaderID']} ";
$rows['info_bill'] = $this->db_onedev->query($sql)->row_array();
$sql =" SELECT T_OrderDeliveryID as id,
IFNULL(Fo_VerificationDeliveryID,0) as xid,
M_DeliveryTypeCode as code,
IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex,
M_DeliveryID as deliveryid,
IFNULL(T_OrderDeliveryNoteValue,'') as note_courier,
M_DeliveryTypeID as typedeliveryid,
T_OrderDeliveryM_KelurahanID as vilageid,
IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note,
'reguler' as type,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName)
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 10 ) THEN CONCAT(M_DeliveryName)
ELSE
CONCAT(M_DeliveryName)
END as label,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 10 THEN M_CompanyAddress
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
ELSE
T_OrderDeliveryDestination
END as destination,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
ELSE
0
END as addressid
FROM t_orderdelivery
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4
LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2
LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y'
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 )
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 )
LEFT JOIN m_company ON T_OrderDeliveryAddressID = M_CompanyID AND ( T_OrderDeliveryM_DeliveryID = 10 )
LEFT JOIN t_orderdeliverynote ON T_OrderDeliveryNoteT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDeliveryNoteIsActive = 'Y'
WHERE
T_OrderDeliveryT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDeliveryID = {$prm['T_OrderDeliveryID']} AND T_OrderDeliveryIsActive = 'Y'
GROUP BY T_OrderDeliveryID
";
//echo $sql ;
$rows['info_deliveries'] = $this->db_onedev->query($sql)->result_array();
$sql = "SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'N'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY Group_ResultID
UNION
SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY T_OrderDetailID
";
$rows['info_test'] = $this->db_onedev->query($sql)->result_array();
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function receivedbycourier(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET Result_CourierSPKDetailStatus = 'S', Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
function confirmspv(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET
Result_CourierSPKDetailStatus = 'O',
Result_CourierSPKDetailConfirmedBy = {$userid},
Result_CourierSPKDetailConfirmedDateTime = NOW(),
Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
// echo $sql;
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,274 @@
<?php
class Reminder extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Reminder API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function first_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and ( F_BillDueDate - interval 7 DAY) = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Akan jatuh tempo pada {$jatuhtempo}</p>
<p>Demikian pemberitahuan dari kami, mohon dapat melakukan pembayaran tepat pada waktunya. Terima kasih</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
public function final_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and F_BillDueDate = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan telah jatuh tempo hari ini dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Kami masih belum menerima pembayaran di rekening kami sampai tanggal jatuh tempo tersebut, mohon dapat segera melakukan pembayaran.</p>
<p>Demikian pemberitahuan dari kami, terima kasih.</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
function numberToWords($number) {
$words = array(
'0' => 'nol',
'1' => 'satu',
'2' => 'dua',
'3' => 'tiga',
'4' => 'empat',
'5' => 'lima',
'6' => 'enam',
'7' => 'tujuh',
'8' => 'delapan',
'9' => 'sembilan',
'10' => 'sepuluh',
'11' => 'sebelas',
'12' => 'dua belas',
'13' => 'tiga belas',
'14' => 'empat belas',
'15' => 'lima belas',
'16' => 'enam belas',
'17' => 'tujuh belas',
'18' => 'delapan belas',
'19' => 'sembilan belas',
'20' => 'dua puluh',
'30' => 'tiga puluh',
'40' => 'empat puluh',
'50' => 'lima puluh',
'60' => 'enam puluh',
'70' => 'tujuh puluh',
'80' => 'delapan puluh',
'90' => 'sembilan puluh',
'100' => 'seratus',
'1000' => 'seribu'
);
if ($number < 21) {
return $words[$number];
} elseif ($number < 100) {
return $words[10 * floor($number/10)] . (($number % 10 > 0) ? ' ' . $words[$number % 10] : '');
} elseif ($number < 200) {
return 'seratus' . (($number - 100 > 0) ? ' ' . $this->numberToWords($number - 100) : '');
} elseif ($number < 1000) {
return $words[floor($number / 100)] . ' ratus' . (($number % 100 > 0) ? ' ' . $this->numberToWords($number % 100) : '');
} elseif ($number < 2000) {
return 'seribu' . (($number - 1000 > 0) ? ' ' . $this->numberToWords($number - 1000) : '');
} elseif ($number < 1000000) {
return $this->numberToWords(floor($number / 1000)) . ' ribu' . (($number % 1000 > 0) ? ' ' . $this->numberToWords($number % 1000) : '');
} elseif ($number < 1000000000) {
return $this->numberToWords(floor($number / 1000000)) . ' juta' . (($number % 1000000 > 0) ? ' ' . $this->numberToWords($number % 1000000) : '');
} elseif ($number < 1000000000000) {
return $this->numberToWords(floor($number / 1000000000)) . ' miliar' . (($number % 1000000000 > 0) ? ' ' . $this->numberToWords($number % 1000000000) : '');
}
return $number;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,274 @@
<?php
class Reminder extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Reminder API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function first_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and ( F_BillDueDate - interval 7 DAY) = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Akan jatuh tempo pada {$jatuhtempo}</p>
<p>Demikian pemberitahuan dari kami, mohon dapat melakukan pembayaran tepat pada waktunya. Terima kasih</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
public function final_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and F_BillDueDate = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan telah jatuh tempo hari ini dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Kami masih belum menerima pembayaran di rekening kami sampai tanggal jatuh tempo tersebut, mohon dapat segera melakukan pembayaran.</p>
<p>Demikian pemberitahuan dari kami, terima kasih.</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
function numberToWords($number) {
$words = array(
'0' => 'nol',
'1' => 'satu',
'2' => 'dua',
'3' => 'tiga',
'4' => 'empat',
'5' => 'lima',
'6' => 'enam',
'7' => 'tujuh',
'8' => 'delapan',
'9' => 'sembilan',
'10' => 'sepuluh',
'11' => 'sebelas',
'12' => 'dua belas',
'13' => 'tiga belas',
'14' => 'empat belas',
'15' => 'lima belas',
'16' => 'enam belas',
'17' => 'tujuh belas',
'18' => 'delapan belas',
'19' => 'sembilan belas',
'20' => 'dua puluh',
'30' => 'tiga puluh',
'40' => 'empat puluh',
'50' => 'lima puluh',
'60' => 'enam puluh',
'70' => 'tujuh puluh',
'80' => 'delapan puluh',
'90' => 'sembilan puluh',
'100' => 'seratus',
'1000' => 'seribu'
);
if ($number < 21) {
return $words[$number];
} elseif ($number < 100) {
return $words[10 * floor($number/10)] . (($number % 10 > 0) ? ' ' . $words[$number % 10] : '');
} elseif ($number < 200) {
return 'seratus' . (($number - 100 > 0) ? ' ' . $this->numberToWords($number - 100) : '');
} elseif ($number < 1000) {
return $words[floor($number / 100)] . ' ratus' . (($number % 100 > 0) ? ' ' . $this->numberToWords($number % 100) : '');
} elseif ($number < 2000) {
return 'seribu' . (($number - 1000 > 0) ? ' ' . $this->numberToWords($number - 1000) : '');
} elseif ($number < 1000000) {
return $this->numberToWords(floor($number / 1000)) . ' ribu' . (($number % 1000 > 0) ? ' ' . $this->numberToWords($number % 1000) : '');
} elseif ($number < 1000000000) {
return $this->numberToWords(floor($number / 1000000)) . ' juta' . (($number % 1000000 > 0) ? ' ' . $this->numberToWords($number % 1000000) : '');
} elseif ($number < 1000000000000) {
return $this->numberToWords(floor($number / 1000000000)) . ' miliar' . (($number % 1000000000 > 0) ? ' ' . $this->numberToWords($number % 1000000000) : '');
}
return $number;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,274 @@
<?php
class Reminder extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Reminder API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function first_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and ( F_BillDueDate - interval 7 DAY) = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Akan jatuh tempo pada {$jatuhtempo}</p>
<p>Demikian pemberitahuan dari kami, mohon dapat melakukan pembayaran tepat pada waktunya. Terima kasih</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
public function final_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and F_BillDueDate = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan telah jatuh tempo hari ini dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Kami masih belum menerima pembayaran di rekening kami sampai tanggal jatuh tempo tersebut, mohon dapat segera melakukan pembayaran.</p>
<p>Demikian pemberitahuan dari kami, terima kasih.</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
function numberToWords($number) {
$words = array(
'0' => 'nol',
'1' => 'satu',
'2' => 'dua',
'3' => 'tiga',
'4' => 'empat',
'5' => 'lima',
'6' => 'enam',
'7' => 'tujuh',
'8' => 'delapan',
'9' => 'sembilan',
'10' => 'sepuluh',
'11' => 'sebelas',
'12' => 'dua belas',
'13' => 'tiga belas',
'14' => 'empat belas',
'15' => 'lima belas',
'16' => 'enam belas',
'17' => 'tujuh belas',
'18' => 'delapan belas',
'19' => 'sembilan belas',
'20' => 'dua puluh',
'30' => 'tiga puluh',
'40' => 'empat puluh',
'50' => 'lima puluh',
'60' => 'enam puluh',
'70' => 'tujuh puluh',
'80' => 'delapan puluh',
'90' => 'sembilan puluh',
'100' => 'seratus',
'1000' => 'seribu'
);
if ($number < 21) {
return $words[$number];
} elseif ($number < 100) {
return $words[10 * floor($number/10)] . (($number % 10 > 0) ? ' ' . $words[$number % 10] : '');
} elseif ($number < 200) {
return 'seratus' . (($number - 100 > 0) ? ' ' . $this->numberToWords($number - 100) : '');
} elseif ($number < 1000) {
return $words[floor($number / 100)] . ' ratus' . (($number % 100 > 0) ? ' ' . $this->numberToWords($number % 100) : '');
} elseif ($number < 2000) {
return 'seribu' . (($number - 1000 > 0) ? ' ' . $this->numberToWords($number - 1000) : '');
} elseif ($number < 1000000) {
return $this->numberToWords(floor($number / 1000)) . ' ribu' . (($number % 1000 > 0) ? ' ' . $this->numberToWords($number % 1000) : '');
} elseif ($number < 1000000000) {
return $this->numberToWords(floor($number / 1000000)) . ' juta' . (($number % 1000000 > 0) ? ' ' . $this->numberToWords($number % 1000000) : '');
} elseif ($number < 1000000000000) {
return $this->numberToWords(floor($number / 1000000000)) . ' miliar' . (($number % 1000000000 > 0) ? ' ' . $this->numberToWords($number % 1000000000) : '');
}
return $number;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,274 @@
<?php
class Reminder extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Reminder API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function first_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and ( F_BillDueDate - interval 7 DAY) = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Akan jatuh tempo pada {$jatuhtempo}</p>
<p>Demikian pemberitahuan dari kami, mohon dapat melakukan pembayaran tepat pada waktunya. Terima kasih</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
public function final_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and F_BillDueDate = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan telah jatuh tempo hari ini dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Kami masih belum menerima pembayaran di rekening kami sampai tanggal jatuh tempo tersebut, mohon dapat segera melakukan pembayaran.</p>
<p>Demikian pemberitahuan dari kami, terima kasih.</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
function numberToWords($number) {
$words = array(
'0' => 'nol',
'1' => 'satu',
'2' => 'dua',
'3' => 'tiga',
'4' => 'empat',
'5' => 'lima',
'6' => 'enam',
'7' => 'tujuh',
'8' => 'delapan',
'9' => 'sembilan',
'10' => 'sepuluh',
'11' => 'sebelas',
'12' => 'dua belas',
'13' => 'tiga belas',
'14' => 'empat belas',
'15' => 'lima belas',
'16' => 'enam belas',
'17' => 'tujuh belas',
'18' => 'delapan belas',
'19' => 'sembilan belas',
'20' => 'dua puluh',
'30' => 'tiga puluh',
'40' => 'empat puluh',
'50' => 'lima puluh',
'60' => 'enam puluh',
'70' => 'tujuh puluh',
'80' => 'delapan puluh',
'90' => 'sembilan puluh',
'100' => 'seratus',
'1000' => 'seribu'
);
if ($number < 21) {
return $words[$number];
} elseif ($number < 100) {
return $words[10 * floor($number/10)] . (($number % 10 > 0) ? ' ' . $words[$number % 10] : '');
} elseif ($number < 200) {
return 'seratus' . (($number - 100 > 0) ? ' ' . $this->numberToWords($number - 100) : '');
} elseif ($number < 1000) {
return $words[floor($number / 100)] . ' ratus' . (($number % 100 > 0) ? ' ' . $this->numberToWords($number % 100) : '');
} elseif ($number < 2000) {
return 'seribu' . (($number - 1000 > 0) ? ' ' . $this->numberToWords($number - 1000) : '');
} elseif ($number < 1000000) {
return $this->numberToWords(floor($number / 1000)) . ' ribu' . (($number % 1000 > 0) ? ' ' . $this->numberToWords($number % 1000) : '');
} elseif ($number < 1000000000) {
return $this->numberToWords(floor($number / 1000000)) . ' juta' . (($number % 1000000 > 0) ? ' ' . $this->numberToWords($number % 1000000) : '');
} elseif ($number < 1000000000000) {
return $this->numberToWords(floor($number / 1000000000)) . ' miliar' . (($number % 1000000000 > 0) ? ' ' . $this->numberToWords($number % 1000000000) : '');
}
return $number;
}
}

View File

@@ -0,0 +1,33 @@
POST https://devcpone.aplikasi.web.id/one-api/mockup/cpone-bill-v4/bill/searchproject
Content-Type: application/json
{
"search": "",
"id": "99",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyVXNlcm5hbWUiOiJqb2tvQGdtYWlsLmNvbSIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtbWN1LXJlc3VtZS1pbmRpdmlkdS1jcG9uZXY1XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIxIiwiTV9TdGFmZk5hbWUiOiJQRVRVR0FTIFNBTVBMRSBMQUIiLCJpc19jb3VyaWVyIjoiTiIsIk1fQnJhbmNoSUQiOm51bGwsIk1fQnJhbmNoTmFtZSI6bnVsbCwidGltZV9hdXRvbG9nb3V0IjoiNTAiLCJpcCI6IjE0OS4xMTMuOTQuMTM5IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTMzLjAuMC4wIFNhZmFyaVwvNTM3LjM2IiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDMtMTAgMDk6MjI6NTAifQ._8v-b8cSgp71s8_Y4IvEPqmtR40w6HVE_51R0goZi-Y"
}
###
POST https://devcpone.aplikasi.web.id/one-api/mockup/cpone-bill-v4/bill/search
Content-Type: application/json
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyVXNlcm5hbWUiOiJqb2tvQGdtYWlsLmNvbSIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtbWN1LXJlc3VtZS1pbmRpdmlkdS1jcG9uZXY1XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIxIiwiTV9TdGFmZk5hbWUiOiJQRVRVR0FTIFNBTVBMRSBMQUIiLCJpc19jb3VyaWVyIjoiTiIsIk1fQnJhbmNoSUQiOm51bGwsIk1fQnJhbmNoTmFtZSI6bnVsbCwidGltZV9hdXRvbG9nb3V0IjoiNTAiLCJpcCI6IjE0OS4xMTMuOTQuMTM5IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTMzLjAuMC4wIFNhZmFyaVwvNTM3LjM2IiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDMtMTAgMDk6MjI6NTAifQ._8v-b8cSgp71s8_Y4IvEPqmtR40w6HVE_51R0goZi-Y",
"nama": "",
"snorm": "",
"status": "N",
"current_page": 1
}
###
POST https://devcpone.aplikasi.web.id/one-api/mockup/cpone-bill-v4/bill/getpatient
Content-Type: application/json
{
"id": 210,
"packetid": 0,
"mgmmcuid": "0",
"enddate": "2025-03-11",
"search": "",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyVXNlcm5hbWUiOiJqb2tvQGdtYWlsLmNvbSIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtbWN1LXJlc3VtZS1pbmRpdmlkdS1jcG9uZXY1XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIxIiwiTV9TdGFmZk5hbWUiOiJQRVRVR0FTIFNBTVBMRSBMQUIiLCJpc19jb3VyaWVyIjoiTiIsIk1fQnJhbmNoSUQiOm51bGwsIk1fQnJhbmNoTmFtZSI6bnVsbCwidGltZV9hdXRvbG9nb3V0IjoiNTAiLCJpcCI6IjE0OS4xMTMuOTQuMTM5IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTMzLjAuMC4wIFNhZmFyaVwvNTM3LjM2IiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDMtMTAgMDk6MjI6NTAifQ._8v-b8cSgp71s8_Y4IvEPqmtR40w6HVE_51R0goZi-Y"
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,274 @@
<?php
class Reminder extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Reminder API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function first_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and ( F_BillDueDate - interval 7 DAY) = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Akan jatuh tempo pada {$jatuhtempo}</p>
<p>Demikian pemberitahuan dari kami, mohon dapat melakukan pembayaran tepat pada waktunya. Terima kasih</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
public function final_reminder(){
$XEmailOutboxSubject = 'Reminder Pelunasan';
$sql = "SELECT f_bill.*,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') jatuhtempo,
CONCAT('Rp. ',FORMAT(F_BillTotal,0),',00') nominal,
CorporateName
FROM f_bill
JOIN corporate ON CorporateID = F_BillCorporateID
WHERE
F_BillIsActive = 'Y'
and F_BillIsLunas = 'N'
and F_BillIsNotif = 'Y'
and F_BillDueDate = date(now())
group by F_BillID";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows_bill = $qry->result_array();
foreach ($rows_bill as $r) {
$pid = $r["F_BillID"];
$recipients = $this->db_onedev->query("SELECT CorporateName as name, F_BillPICEmail as email
FROM f_bill JOIN corporate ON CorporateID = F_BillCorporateID WHERE F_BillID = '{$pid}'")->result_array();
$XEmailOutboxRecipients = json_encode($recipients);
$XEmailOutboxIsHtml = 'Y';
$pname = $r["F_BillPIC"];
$jatuhtempo = $r["jatuhtempo"];
$nominal = $r["nominal"];
$terbilang = $this->numberToWords($r["F_BillTotal"]) . ' rupiah';
$nomor = $r["F_BillNo"];
$XEmailOutboxBody = "<h4>Reminder Pelunasan</h4>
<p>Bapak/Ibu yang terhormat {$pname}</p>
<p>Dalam kesempatan ini kami ingin menyampaikan bahwa tagihan telah jatuh tempo hari ini dengan data sebagai berikut :</p>
<table>
<tbody>
</tr>
<tr>
<td>
<p>Nominal</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nominal}</p>
</td>
</tr>
<tr>
<td>
<p>Terbilang</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$terbilang}</p>
</td>
</tr>
<tr>
<td>
<p>Nomor Invoice</p>
</td>
<td>
<p>:</p>
</td>
<td>
<p>{$nomor}</p>
</td>
</tr>
</tbody>
</table>
<p>Kami masih belum menerima pembayaran di rekening kami sampai tanggal jatuh tempo tersebut, mohon dapat segera melakukan pembayaran.</p>
<p>Demikian pemberitahuan dari kami, terima kasih.</p>
<p>&nbsp;</p>
<p>Hormat kami</p>
<p><br /><br /></p>
<table>
";
$XEmailOutboxType = 'KEU';
$sql = "insert into x_email_outbox(XEmailOutboxSubject,
XEmailOutboxRecipients,
XEmailOutboxIsHtml,
XEmailOutboxBody,
XEmailOutboxType) values(?,?,?,?,?)";
$this->db_onedev->query($sql,array($XEmailOutboxSubject,$XEmailOutboxRecipients,$XEmailOutboxIsHtml,$XEmailOutboxBody,$XEmailOutboxType));
// echo $query;
$rows = $this->db_onedev->query($query);
}
$result = array(
"total" => count($rows_bill) ,
"records" => $rows_bill
);
$this->sys_ok($result);
exit;
}
}
function numberToWords($number) {
$words = array(
'0' => 'nol',
'1' => 'satu',
'2' => 'dua',
'3' => 'tiga',
'4' => 'empat',
'5' => 'lima',
'6' => 'enam',
'7' => 'tujuh',
'8' => 'delapan',
'9' => 'sembilan',
'10' => 'sepuluh',
'11' => 'sebelas',
'12' => 'dua belas',
'13' => 'tiga belas',
'14' => 'empat belas',
'15' => 'lima belas',
'16' => 'enam belas',
'17' => 'tujuh belas',
'18' => 'delapan belas',
'19' => 'sembilan belas',
'20' => 'dua puluh',
'30' => 'tiga puluh',
'40' => 'empat puluh',
'50' => 'lima puluh',
'60' => 'enam puluh',
'70' => 'tujuh puluh',
'80' => 'delapan puluh',
'90' => 'sembilan puluh',
'100' => 'seratus',
'1000' => 'seribu'
);
if ($number < 21) {
return $words[$number];
} elseif ($number < 100) {
return $words[10 * floor($number/10)] . (($number % 10 > 0) ? ' ' . $words[$number % 10] : '');
} elseif ($number < 200) {
return 'seratus' . (($number - 100 > 0) ? ' ' . $this->numberToWords($number - 100) : '');
} elseif ($number < 1000) {
return $words[floor($number / 100)] . ' ratus' . (($number % 100 > 0) ? ' ' . $this->numberToWords($number % 100) : '');
} elseif ($number < 2000) {
return 'seribu' . (($number - 1000 > 0) ? ' ' . $this->numberToWords($number - 1000) : '');
} elseif ($number < 1000000) {
return $this->numberToWords(floor($number / 1000)) . ' ribu' . (($number % 1000 > 0) ? ' ' . $this->numberToWords($number % 1000) : '');
} elseif ($number < 1000000000) {
return $this->numberToWords(floor($number / 1000000)) . ' juta' . (($number % 1000000 > 0) ? ' ' . $this->numberToWords($number % 1000000) : '');
} elseif ($number < 1000000000000) {
return $this->numberToWords(floor($number / 1000000000)) . ' miliar' . (($number % 1000000000 > 0) ? ' ' . $this->numberToWords($number % 1000000000) : '');
}
return $number;
}
}

View File

@@ -0,0 +1,33 @@
POST https://devcpone.aplikasi.web.id/one-api/mockup/cpone-bill-v4/bill/searchproject
Content-Type: application/json
{
"search": "",
"id": "99",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyVXNlcm5hbWUiOiJqb2tvQGdtYWlsLmNvbSIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtbWN1LXJlc3VtZS1pbmRpdmlkdS1jcG9uZXY1XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIxIiwiTV9TdGFmZk5hbWUiOiJQRVRVR0FTIFNBTVBMRSBMQUIiLCJpc19jb3VyaWVyIjoiTiIsIk1fQnJhbmNoSUQiOm51bGwsIk1fQnJhbmNoTmFtZSI6bnVsbCwidGltZV9hdXRvbG9nb3V0IjoiNTAiLCJpcCI6IjE0OS4xMTMuOTQuMTM5IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTMzLjAuMC4wIFNhZmFyaVwvNTM3LjM2IiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDMtMTAgMDk6MjI6NTAifQ._8v-b8cSgp71s8_Y4IvEPqmtR40w6HVE_51R0goZi-Y"
}
###
POST https://devcpone.aplikasi.web.id/one-api/mockup/cpone-bill-v4/bill/search
Content-Type: application/json
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyVXNlcm5hbWUiOiJqb2tvQGdtYWlsLmNvbSIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtbWN1LXJlc3VtZS1pbmRpdmlkdS1jcG9uZXY1XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIxIiwiTV9TdGFmZk5hbWUiOiJQRVRVR0FTIFNBTVBMRSBMQUIiLCJpc19jb3VyaWVyIjoiTiIsIk1fQnJhbmNoSUQiOm51bGwsIk1fQnJhbmNoTmFtZSI6bnVsbCwidGltZV9hdXRvbG9nb3V0IjoiNTAiLCJpcCI6IjE0OS4xMTMuOTQuMTM5IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTMzLjAuMC4wIFNhZmFyaVwvNTM3LjM2IiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDMtMTAgMDk6MjI6NTAifQ._8v-b8cSgp71s8_Y4IvEPqmtR40w6HVE_51R0goZi-Y",
"nama": "",
"snorm": "",
"status": "N",
"current_page": 1
}
###
POST https://devcpone.aplikasi.web.id/one-api/mockup/cpone-bill-v4/bill/getpatient
Content-Type: application/json
{
"id": 210,
"packetid": 0,
"mgmmcuid": "0",
"enddate": "2025-03-11",
"search": "",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyVXNlcm5hbWUiOiJqb2tvQGdtYWlsLmNvbSIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtbWN1LXJlc3VtZS1pbmRpdmlkdS1jcG9uZXY1XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIxIiwiTV9TdGFmZk5hbWUiOiJQRVRVR0FTIFNBTVBMRSBMQUIiLCJpc19jb3VyaWVyIjoiTiIsIk1fQnJhbmNoSUQiOm51bGwsIk1fQnJhbmNoTmFtZSI6bnVsbCwidGltZV9hdXRvbG9nb3V0IjoiNTAiLCJpcCI6IjE0OS4xMTMuOTQuMTM5IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTMzLjAuMC4wIFNhZmFyaVwvNTM3LjM2IiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDMtMTAgMDk6MjI6NTAifQ._8v-b8cSgp71s8_Y4IvEPqmtR40w6HVE_51R0goZi-Y"
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More