Initial import
This commit is contained in:
188
one-api/application/controllers/mockup/billpayment/Bill.php
Normal file
188
one-api/application/controllers/mockup/billpayment/Bill.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user