195 lines
7.0 KiB
PHP
195 lines
7.0 KiB
PHP
<?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;
|
|
}
|
|
|
|
|
|
}
|