update / proses add akun pusat di media jurnal & move barcode to serah terima
This commit is contained in:
255
application/controllers/mockup/supplierpaymentcashierv5/Bill.php
Normal file
255
application/controllers/mockup/supplierpaymentcashierv5/Bill.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?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 SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
SupplierPaymentID as note_id,
|
||||
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
|
||||
SupplierPaymentDate as note_date,
|
||||
SupplierPaymentNumber as note_number,
|
||||
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') as paymenttypes_name,
|
||||
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||
n.M_UserUsername as note_user,
|
||||
SupplierPaymentDetailIsActive as note_active,
|
||||
'xxx' as tests,
|
||||
'N' as show_detail,
|
||||
SupplierPaymentNote as keterangan,
|
||||
SupplierPaymentCoaID,
|
||||
coaID,
|
||||
coaDescription,
|
||||
SupplierPaymentIsConfirm,
|
||||
CONCAT('Confirmed by : ',c.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentConfirmDate,'%d-%m-%Y %H:%i')) as d_confirm,
|
||||
SupplierPaymentIsApproved,
|
||||
CONCAT('Approved by : ',a.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentApprovedDate,'%d-%m-%Y %H:%i')) as d_approved,
|
||||
CONCAT('Verified by : ',b.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentVerifDate,'%d-%m-%Y %H:%i')) as d_verif
|
||||
FROM supplier_payment
|
||||
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||
LEFT JOIN coa ON SupplierPaymentCoaID = coaID
|
||||
LEFT JOIN m_user n ON SupplierPaymentUserID = n.M_UserID
|
||||
LEFT JOIN m_user c ON SupplierPaymentConfirmUserID = c.M_UserID
|
||||
LEFT JOIN m_user a ON SupplierPaymentApprovedUserID = a.M_UserID
|
||||
LEFT JOIN m_user b ON SupplierPaymentVerifUserID = b.M_UserID
|
||||
WHERE
|
||||
SupplierPaymentSupplierInvoiceID = {$orderid}
|
||||
AND
|
||||
SupplierPaymentIsActive = 'Y'
|
||||
GROUP BY SupplierPaymentID";
|
||||
$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 SupplierInvoiceID as tagihan_id,
|
||||
PurchaseOrderNumber as tagihan_number,
|
||||
jurnalTxDescription as pasien,
|
||||
jurnalTxCredit as tagihan_total,
|
||||
IF(SupplierPaymentDetailID IS NULL , jurnalTxCredit, jurnalTxCredit - SUM(SupplierPaymentDetailAmount)) as tagihan_tagihan,
|
||||
0 as tagihan_bayar,
|
||||
DATE_FORMAT(SupplierInvoiceDueDate,'%d-%m-%Y') as tagihan_duedate,
|
||||
SupplierInvoiceIsActive as tagihan_active,
|
||||
'N' as show_detail,
|
||||
jurnalTxID SupplierInvoiceDetailID,
|
||||
PurchaseOrderID SupplierInvoiceDetailPurchaseOrderID
|
||||
FROM supplier_invoice
|
||||
JOIN purchase_order ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierInvoiceIsActive = 'Y'
|
||||
LEFT JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID AND SupplierPaymentDetailIsActive = 'Y'
|
||||
WHERE SupplierInvoiceID = ?
|
||||
GROUP BY jurnalTxID";
|
||||
$query = $this->db_onedev->query($sql, [$orderid]);
|
||||
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 SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
SupplierPaymentID as note_id,
|
||||
SupplierPaymentDate as note_date,
|
||||
SupplierPaymentNumber as note_number,
|
||||
GROUP_CONCAT(coaDescription separator ' , ') as paymenttypes_name,
|
||||
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||
M_UserUsername as note_user,
|
||||
SupplierPaymentDetailIsActive as note_active,
|
||||
PurchaseOrderNumber,
|
||||
SupplierInvoiceDetailTotal,
|
||||
SupplierPaymentDetailAmount
|
||||
FROM supplier_payment
|
||||
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
|
||||
LEFT JOIN supplier_invoice_detail ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID
|
||||
LEFT JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
||||
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||
LEFT JOIN m_user ON SupplierPaymentDetailUserID = M_UserID
|
||||
WHERE
|
||||
SupplierPaymentID = {$orderid}
|
||||
GROUP BY SupplierPaymentDetailID";
|
||||
$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;
|
||||
$supplier = $prm["supplier"];
|
||||
$search = $prm["search"];
|
||||
$status = $prm["status"];
|
||||
$startdate = $prm["startdate"];
|
||||
$enddate = $prm["enddate"];
|
||||
$regionalid = $this->sys_user['S_RegionalID'];
|
||||
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$where = "SupplierInvoiceIsActive = 'Y'
|
||||
AND SupplierPaymentIsApproved = 'Y'
|
||||
AND SupplierPaymentIsVerif = 'Y'
|
||||
AND SupplierPaymentIsConfirm = '{$status}'
|
||||
AND (SupplierInvoiceNumber LIKE '%{$search}%' OR SupplierInvoiceSupplierInvoiceNumber LIKE '%{$search}%')
|
||||
AND SupplierName LIKE '%{$supplier}%'
|
||||
AND ReceiveOrderPoS_RegionalID = {$regionalid}
|
||||
AND SupplierInvoiceDraftPaymentDate BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||
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("supplier_invoice count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT supplier_invoice.*,
|
||||
SupplierName,
|
||||
'' M_MouName,
|
||||
0 as totalbill,
|
||||
0 as paid,
|
||||
0 as unpaid,
|
||||
SupplierInvoiceIsLunas as flaglunas,
|
||||
'' as SupplierPaymentNumber,
|
||||
0 as SupplierPaymentAmount,
|
||||
'' as SupplierPaymentDate,
|
||||
'' as SupplierInvoiceIssueRefNumber,
|
||||
'' as notes,
|
||||
'' as tagihans,
|
||||
'N' as isbillterpusat,
|
||||
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
|
||||
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d%m%Y') as tanggalbayartext,
|
||||
IF(SupplierPaymentID IS NULL,'N','Y') as status_invoice,
|
||||
SupplierPaymentID,
|
||||
SupplierPaymentIsConfirm,
|
||||
DATE_FORMAT(IFNULL(SupplierInvoiceSupplierInvoiceDate,''),'%d-%m-%Y') as tanggalinvoice,
|
||||
0 xrounding,
|
||||
'' chex,
|
||||
IFNULL(SupplierPaymentCashierNumber,'') SupplierPaymentCashierNumber
|
||||
|
||||
|
||||
FROM supplier_invoice
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
WHERE
|
||||
$where
|
||||
GROUP BY SupplierInvoiceID
|
||||
ORDER BY SupplierInvoiceID 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]['chex'] = false;
|
||||
$s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
|
||||
GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate
|
||||
FROM supplier_payment
|
||||
WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row();
|
||||
|
||||
$s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||
WHERE SupplierInvoiceID = {$v['SupplierInvoiceID']}
|
||||
GROUP BY SupplierInvoiceID")->row();
|
||||
$amount = $s_payment->SupplierPaymentAmount ? $s_payment->SupplierPaymentAmount : "0.00";
|
||||
$unpaid = (float)$s_jurnal->totalbill - (float)$amount;
|
||||
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber;
|
||||
$rows[$k]['SupplierPaymentAmount'] = $amount;
|
||||
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
|
||||
$rows[$k]['paid'] = $amount;
|
||||
$rows[$k]['totalbill'] = $s_jurnal->totalbill ? $s_jurnal->totalbill : "0.00";
|
||||
$rows[$k]['unpaid'] = number_format($unpaid, 2, '.', '');
|
||||
|
||||
$rows[$k]['notes'] = $this->add_notes($v['SupplierInvoiceID']);
|
||||
$rows[$k]['tagihans'] = $this->add_tagihans($v['SupplierInvoiceID']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
<?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 SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
SupplierPaymentID as note_id,
|
||||
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
|
||||
SupplierPaymentDate as note_date,
|
||||
SupplierPaymentNumber as note_number,
|
||||
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') as paymenttypes_name,
|
||||
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||
M_UserUsername as note_user,
|
||||
SupplierPaymentDetailIsActive as note_active,
|
||||
'xxx' as tests,
|
||||
'N' as show_detail,
|
||||
SupplierPaymentNote as keterangan,
|
||||
SupplierPaymentCoaID,
|
||||
coaID,
|
||||
coaDescription,
|
||||
SupplierPaymentIsConfirm
|
||||
FROM supplier_payment
|
||||
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
|
||||
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||
LEFT JOIN m_user ON SupplierPaymentUserID = M_UserID
|
||||
WHERE
|
||||
SupplierPaymentSupplierInvoiceID = {$orderid}
|
||||
AND
|
||||
SupplierPaymentIsActive = 'Y'
|
||||
GROUP BY SupplierPaymentID";
|
||||
$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 SupplierInvoiceID as tagihan_id,
|
||||
PurchaseOrderNumber as tagihan_number,
|
||||
'' as pasien,
|
||||
CAST(IFNULL(SupplierInvoiceGrandTotal,0) AS UNSIGNED) as tagihan_total,
|
||||
CAST(IFNULL(SupplierInvoiceUnpaid,0) AS UNSIGNED) as tagihan_tagihan,
|
||||
0 as tagihan_bayar,
|
||||
DATE_FORMAT(SupplierInvoiceDueDate,'%d-%m-%Y') as tagihan_duedate,
|
||||
SupplierInvoiceIsActive as tagihan_active,
|
||||
'N' as show_detail,
|
||||
SupplierInvoiceDetailID,
|
||||
SupplierInvoiceDetailPurchaseOrderID
|
||||
FROM supplier_invoice
|
||||
JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierInvoiceID AND SupplierInvoiceDetailIsActive = 'Y'
|
||||
JOIN purchase_order ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
|
||||
WHERE
|
||||
SupplierInvoiceID = {$orderid}
|
||||
GROUP BY SupplierInvoiceID";
|
||||
$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 SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
SupplierPaymentID as note_id,
|
||||
SupplierPaymentDate as note_date,
|
||||
SupplierPaymentNumber as note_number,
|
||||
GROUP_CONCAT(coaDescription separator ' , ') as paymenttypes_name,
|
||||
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||
M_UserUsername as note_user,
|
||||
SupplierPaymentDetailIsActive as note_active,
|
||||
PurchaseOrderNumber,
|
||||
SupplierInvoiceDetailTotal,
|
||||
SupplierPaymentDetailAmount
|
||||
FROM supplier_payment
|
||||
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
|
||||
LEFT JOIN supplier_invoice_detail ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID
|
||||
LEFT JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
||||
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||
LEFT JOIN m_user ON SupplierPaymentDetailUserID = M_UserID
|
||||
WHERE
|
||||
SupplierPaymentID = {$orderid}
|
||||
GROUP BY SupplierPaymentDetailID";
|
||||
$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;
|
||||
$supplier = $prm["supplier"];
|
||||
$search = $prm["search"];
|
||||
$status = $prm["status"];
|
||||
$regionalid = $this->sys_user['S_RegionalID'];
|
||||
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$where = "(SupplierInvoiceIsActive = 'Y'
|
||||
AND SupplierInvoiceGrandTotal > 0
|
||||
AND SupplierInvoiceIsLunas = '{$status}'
|
||||
AND (SupplierInvoiceNumber LIKE '%{$search}%' OR SupplierPaymentNumber LIKE '%{$search}%') AND SupplierName LIKE '%{$supplier}%')
|
||||
AND PurchaseOrderS_RegionalID = {$regionalid}";
|
||||
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM supplier_invoice
|
||||
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN purchase_order ON PurchaseOrderID = SupplierInvoicePurchaseOrderID
|
||||
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("supplier_invoice count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT supplier_invoice.*, supplier_payment.*,
|
||||
SupplierName,
|
||||
'' M_MouName,
|
||||
CAST(IFNULL(SupplierInvoiceGrandTotal,0) AS UNSIGNED) as totalbill,
|
||||
CAST(IFNULL(SupplierInvoiceGrandTotal,0) AS UNSIGNED) - CAST(IFNULL(SupplierInvoiceUnpaid,0) AS UNSIGNED) as paid,
|
||||
CAST(IFNULL(SupplierInvoiceUnpaid,0) AS UNSIGNED) as unpaid,
|
||||
SupplierInvoiceIsLunas as flaglunas,
|
||||
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||
SUM(CAST(IFNULL(SupplierPaymentAmount,0) AS UNSIGNED)) as SupplierPaymentAmount,
|
||||
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') as SupplierPaymentDate,
|
||||
'' as SupplierInvoiceIssueRefNumber,
|
||||
'' as notes,
|
||||
'' as tagihans,
|
||||
'N' as isbillterpusat
|
||||
FROM supplier_invoice
|
||||
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN purchase_order ON PurchaseOrderID = SupplierInvoicePurchaseOrderID
|
||||
WHERE
|
||||
$where
|
||||
GROUP BY SupplierInvoiceID
|
||||
ORDER BY SupplierInvoiceID 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['SupplierInvoiceID']);
|
||||
$rows[$k]['tagihans'] = $this->add_tagihans($v['SupplierInvoiceID']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
<?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 SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
SupplierPaymentID as note_id,
|
||||
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
|
||||
SupplierPaymentDate as note_date,
|
||||
SupplierPaymentNumber as note_number,
|
||||
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') as paymenttypes_name,
|
||||
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||
M_UserUsername as note_user,
|
||||
SupplierPaymentDetailIsActive as note_active,
|
||||
'xxx' as tests,
|
||||
'N' as show_detail,
|
||||
SupplierPaymentNote as keterangan,
|
||||
SupplierPaymentCoaID,
|
||||
coaID,
|
||||
coaDescription,
|
||||
SupplierPaymentIsConfirm
|
||||
FROM supplier_payment
|
||||
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||
LEFT JOIN m_user ON SupplierPaymentUserID = M_UserID
|
||||
WHERE
|
||||
SupplierPaymentSupplierInvoiceID = {$orderid}
|
||||
AND
|
||||
SupplierPaymentIsActive = 'Y'
|
||||
GROUP BY SupplierPaymentID";
|
||||
$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 SupplierInvoiceID as tagihan_id,
|
||||
PurchaseOrderNumber as tagihan_number,
|
||||
jurnalTxDescription as pasien,
|
||||
jurnalTxCredit as tagihan_total,
|
||||
IF(SupplierPaymentDetailID IS NULL , jurnalTxCredit, jurnalTxCredit - SUM(SupplierPaymentDetailAmount)) as tagihan_tagihan,
|
||||
0 as tagihan_bayar,
|
||||
DATE_FORMAT(SupplierInvoiceDueDate,'%d-%m-%Y') as tagihan_duedate,
|
||||
SupplierInvoiceIsActive as tagihan_active,
|
||||
'N' as show_detail,
|
||||
jurnalTxID SupplierInvoiceDetailID,
|
||||
PurchaseOrderID SupplierInvoiceDetailPurchaseOrderID
|
||||
|
||||
FROM supplier_invoice
|
||||
JOIN purchase_order ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierInvoiceIsActive = 'Y'
|
||||
LEFT JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID AND SupplierPaymentDetailIsActive = 'Y'
|
||||
WHERE
|
||||
SupplierInvoiceID = {$orderid}
|
||||
GROUP BY jurnalTxID
|
||||
";
|
||||
$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 SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
SupplierPaymentID as note_id,
|
||||
SupplierPaymentDate as note_date,
|
||||
SupplierPaymentNumber as note_number,
|
||||
GROUP_CONCAT(coaDescription separator ' , ') as paymenttypes_name,
|
||||
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||
M_UserUsername as note_user,
|
||||
SupplierPaymentDetailIsActive as note_active,
|
||||
PurchaseOrderNumber,
|
||||
SupplierInvoiceDetailTotal,
|
||||
SupplierPaymentDetailAmount
|
||||
FROM supplier_payment
|
||||
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
|
||||
LEFT JOIN supplier_invoice_detail ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID
|
||||
LEFT JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
||||
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||
LEFT JOIN m_user ON SupplierPaymentDetailUserID = M_UserID
|
||||
WHERE
|
||||
SupplierPaymentID = {$orderid}
|
||||
GROUP BY SupplierPaymentDetailID";
|
||||
$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;
|
||||
$supplier = $prm["supplier"];
|
||||
$search = $prm["search"];
|
||||
$status = $prm["status"];
|
||||
$regionalid = $this->sys_user['S_RegionalID'];
|
||||
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$where = "(SupplierInvoiceIsActive = 'Y'
|
||||
AND SupplierInvoiceGrandTotal > 0
|
||||
AND SupplierInvoiceIsLunas = '{$status}'
|
||||
AND (SupplierInvoiceNumber LIKE '%{$search}%' OR SupplierPaymentNumber LIKE '%{$search}%') AND SupplierName LIKE '%{$supplier}%')
|
||||
AND PurchaseOrderS_RegionalID = {$regionalid}";
|
||||
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM supplier_invoice
|
||||
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN purchase_order ON PurchaseOrderID = SupplierInvoicePurchaseOrderID
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||
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("supplier_invoice count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT supplier_invoice.*,
|
||||
SupplierName,
|
||||
'' M_MouName,
|
||||
SUM(jurnalTxCredit) as totalbill,
|
||||
SUM(IFNULL(SupplierPaymentAmount,0)) as paid,
|
||||
SUM(jurnalTxCredit) - SUM(IFNULL(SupplierPaymentAmount,0)) as unpaid,
|
||||
SupplierInvoiceIsLunas as flaglunas,
|
||||
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
|
||||
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') as SupplierPaymentDate,
|
||||
'' as SupplierInvoiceIssueRefNumber,
|
||||
'' as notes,
|
||||
'' as tagihans,
|
||||
'N' as isbillterpusat
|
||||
FROM supplier_invoice
|
||||
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN purchase_order ON PurchaseOrderID = SupplierInvoicePurchaseOrderID
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||
WHERE
|
||||
$where
|
||||
GROUP BY SupplierInvoiceID
|
||||
ORDER BY SupplierInvoiceID 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['SupplierInvoiceID']);
|
||||
$rows[$k]['tagihans'] = $this->add_tagihans($v['SupplierInvoiceID']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1582
application/controllers/mockup/supplierpaymentcashierv5/Payment.php
Normal file
1582
application/controllers/mockup/supplierpaymentcashierv5/Payment.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,660 @@
|
||||
<?php
|
||||
|
||||
class PaymentV2 extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function paymanual()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$param = $this->sys_input;
|
||||
$users = $this->sys_user;
|
||||
|
||||
# Generate number supplier payment #
|
||||
$sql_gennumber = "SELECT `fn_numbering`(?) as numberx";
|
||||
$paygroupnum = $this->db->query($sql_gennumber, ['PC'])->row()->numberx;
|
||||
$paynumber = $this->db->query($sql_gennumber, ['PN'])->row()->numberx;
|
||||
|
||||
if ($paygroupnum == '' || $paynumber == '') {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] generate number supplier payment");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rounding = 0;
|
||||
if (doubleval($param['xrounding'] > 0)) {
|
||||
$sisa = doubleval($param['xrounding']) - doubleval($param['amount']);
|
||||
$rounding = round($sisa, 2);
|
||||
}
|
||||
|
||||
# UPDATE header supplier payment #
|
||||
$sql_updateheader = "UPDATE supplier_payment SET
|
||||
SupplierPaymentIsConfirm = 'Y',
|
||||
SupplierPaymentConfirmUserID = ?,
|
||||
SupplierPaymentGroupNumber = ?,
|
||||
SupplierPaymentCashierNumber = ?,
|
||||
SupplierPaymentRounding = ?,
|
||||
SupplierPaymentConfirmDate = now(),
|
||||
SupplierPaymentNote = ?,
|
||||
SupplierPaymentCoaID = ?
|
||||
WHERE SupplierPaymentID = ?";
|
||||
$que_updateheader = $this->db->query($sql_updateheader, [
|
||||
$users['M_UserID'],
|
||||
$paygroupnum,
|
||||
$paynumber,
|
||||
$rounding,
|
||||
$param['keterangan'],
|
||||
$param['paymenttype'],
|
||||
$param['orderid']
|
||||
]);
|
||||
if (!$que_updateheader) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update supplier payment header");
|
||||
exit;
|
||||
}
|
||||
|
||||
# UPDATE status lunas supplier invoice #
|
||||
$sql_suppinvoice = "UPDATE supplier_invoice
|
||||
SET SupplierInvoiceIsLunas = 'Y'
|
||||
WHERE SupplierInvoiceID = ?";
|
||||
$que_suppinvoice = $this->db->query($sql_suppinvoice, [$param['SupplierInvoiceID']]);
|
||||
if (!$que_suppinvoice) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status lunas invoice");
|
||||
exit;
|
||||
}
|
||||
|
||||
# GET Latest data supplier payment #
|
||||
$sql_suppayment = "SELECT * FROM supplier_payment WHERE SupplierPaymentID = ?";
|
||||
$que_suppayment = $this->db->query($sql_suppayment, [$param['orderid']]);
|
||||
if (!$que_suppayment) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data latest supplier payment");
|
||||
exit;
|
||||
}
|
||||
$suppayment_header = $que_suppayment->row_array();
|
||||
|
||||
$sql_suppaymentdetail = "SELECT * FROM supplier_payment_detail
|
||||
WHERE SupplierPaymentDetailSupplierPaymentID = ?";
|
||||
$que_suppaymentdetail = $this->db->query($sql_suppaymentdetail, [$param['orderid']]);
|
||||
if (!$que_suppaymentdetail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data latest supplier payment detail");
|
||||
exit;
|
||||
}
|
||||
$suppayment_detail = $que_suppaymentdetail->result_array();
|
||||
|
||||
$data_log = [
|
||||
"header" => $suppayment_header,
|
||||
"detail" => $suppayment_detail
|
||||
];
|
||||
|
||||
# LOG activity confirm payment #
|
||||
$messg = "Pembayaran Faktur No: {$suppayment_header['SupplierPaymentNumber']}";
|
||||
$messg .= " telah dikonfirmasi oleh {$users['M_UserUsername']} dengan nomor";
|
||||
$messg .= " pembayaran kasir: {$suppayment_header['SupplierPaymentCashierNumber']}";
|
||||
$this->insert_activity_log(
|
||||
"PF",
|
||||
"CONFIRM",
|
||||
$messg,
|
||||
$param['orderid'],
|
||||
$data_log,
|
||||
$users['M_UserID']
|
||||
);
|
||||
|
||||
# INSERT JURNAL #
|
||||
$detail_transac = [];
|
||||
|
||||
# GET data hutang #
|
||||
$sql_datahutang = "SELECT
|
||||
SupplierPaymentNumber AS addonvalue,
|
||||
SupplierPaymentDetailID,
|
||||
jurnalTxCoaID AS coaID,
|
||||
jurnalTxDescription AS coaDescription,
|
||||
SupplierPaymentDetailAmount,
|
||||
SupplierInvoiceDetailItemID
|
||||
FROM supplier_payment
|
||||
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
|
||||
JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierPaymentSupplierInvoiceID
|
||||
AND SupplierInvoiceDetailIsActive = 'Y'
|
||||
JOIN jurnal_tx ON SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID
|
||||
WHERE SupplierPaymentID = ?
|
||||
AND SupplierPaymentDetailIsActive = 'Y'";
|
||||
$que_datahutang = $this->db->query($sql_datahutang, [$param['orderid']]);
|
||||
if (!$que_datahutang) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data hutang item");
|
||||
exit;
|
||||
}
|
||||
$data_hutang = $que_datahutang->result_array();
|
||||
foreach ($data_hutang as $key => $debt) {
|
||||
$detail_transac[] = [
|
||||
"coaID" => $debt['coaID'],
|
||||
"coaDescription" => $debt['coaDescription'],
|
||||
"debit" => $debt['SupplierPaymentDetailAmount'],
|
||||
"credit" => 0,
|
||||
"addoncode" => "JFA",
|
||||
"addonvalue" => $debt['addonvalue'],
|
||||
"addonitemid" => $debt['SupplierInvoiceDetailItemID']
|
||||
];
|
||||
}
|
||||
|
||||
# GET data bayar #
|
||||
$sql_databayar = "SELECT
|
||||
CONCAT('Jurnal Payment Invoice Nomor : ',
|
||||
SupplierPaymentNumber, DATE_FORMAT(now(),
|
||||
', Tanggal : %d-%m-%Y ')
|
||||
) AS jurnaltitle,
|
||||
CONCAT('Nomor pembayaran kasir : ',
|
||||
SupplierPaymentCashierNumber,
|
||||
' dan Nomor grup pembayaran : ',
|
||||
SupplierPaymentGroupNumber
|
||||
) AS jurnaldesc,
|
||||
SupplierPaymentNumber AS no_payinv,
|
||||
SupplierPaymentCashierNumber AS addonvalue,
|
||||
SupplierPaymentCoaID AS coaID,
|
||||
coaDescription,
|
||||
SupplierPaymentAmount AS amount,
|
||||
SupplierPaymentRounding AS rounding,
|
||||
(SupplierPaymentAmount + SupplierPaymentRounding) AS bayar
|
||||
FROM supplier_payment
|
||||
JOIN coa ON coaID = SupplierPaymentCoaID
|
||||
WHERE SupplierPaymentID = ?";
|
||||
$que_databayar = $this->db->query($sql_databayar, [$param['orderid']]);
|
||||
if (!$que_databayar) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data bayar");
|
||||
exit;
|
||||
}
|
||||
$data_bayar = $que_databayar->row_array();
|
||||
$detail_transac[] = [
|
||||
"coaID" => $data_bayar['coaID'],
|
||||
"coaDescription" => $data_bayar['coaDescription'],
|
||||
"debit" => 0,
|
||||
"credit" => abs($data_bayar['bayar']),
|
||||
"addoncode" => "PAYINVSG",
|
||||
"addonvalue" => $data_bayar['addonvalue'],
|
||||
"addonitemid" => 0
|
||||
];
|
||||
|
||||
# rugi / untung dari rounding #
|
||||
$sql_lossprofit = "SELECT coaID, coaDescription
|
||||
FROM coa WHERE coaAccountNo = ? AND coaIsActive = 'Y'";
|
||||
$data_round = doubleval($data_bayar['rounding']);
|
||||
if ($data_round > 0) {
|
||||
# loss #
|
||||
$que_lossprofit = $this->db->query($sql_lossprofit, ['6120402001']);
|
||||
if (!$que_lossprofit) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data coa loss sisa kas");
|
||||
exit;
|
||||
}
|
||||
$loss_coa = $que_lossprofit->row_array();
|
||||
|
||||
$detail_transac[] = [
|
||||
"coaID" => $loss_coa['coaID'],
|
||||
"coaDescription" => $loss_coa['coaDescription'],
|
||||
"debit" => abs($data_round),
|
||||
"credit" => 0,
|
||||
"addoncode" => "PAYINVSG",
|
||||
"addonvalue" => $data_bayar['addonvalue'],
|
||||
"addonitemid" => 0
|
||||
];
|
||||
} elseif ($data_round < 0) {
|
||||
# profit #
|
||||
$que_lossprofit = $this->db->query($sql_lossprofit, ['6110500001']);
|
||||
if (!$que_lossprofit) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data coa profit sisa kas");
|
||||
exit;
|
||||
}
|
||||
$profit_coa = $que_lossprofit->row_array();
|
||||
|
||||
$detail_transac[] = [
|
||||
"coaID" => $profit_coa['coaID'],
|
||||
"coaDescription" => $profit_coa['coaDescription'],
|
||||
"debit" => 0,
|
||||
"credit" => abs($data_round),
|
||||
"addoncode" => "PAYINVSG",
|
||||
"addonvalue" => $data_bayar['addonvalue'],
|
||||
"addonitemid" => 0
|
||||
];
|
||||
}
|
||||
|
||||
$this->insertJurnal($users, $data_bayar, $detail_transac);
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success update v2 test");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function payinvoicemulti()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$users = $this->sys_user;
|
||||
|
||||
# Generate number supplier payment #
|
||||
$sql_gennumber = "SELECT `fn_numbering`(?) as numberx";
|
||||
$paygroupnum = $this->db->query($sql_gennumber, ['PC'])->row()->numberx;
|
||||
|
||||
if ($paygroupnum == '') {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] generate number group supplier payment");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rounding = 0;
|
||||
if (doubleval($param['xrounding'] > 0)) {
|
||||
$sisa = doubleval($param['xrounding']) - doubleval($param['total']);
|
||||
$rounding = round($sisa, 2);
|
||||
}
|
||||
|
||||
|
||||
$lastIndex = count($param['details']) - 1;
|
||||
# LOOP details invoice payment #
|
||||
foreach ($param['details'] as $idx => $obj) {
|
||||
$paynumber = $this->db->query($sql_gennumber, ['PN'])->row()->numberx;
|
||||
if ($paynumber == '') {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] generate number kasir supplier payment");
|
||||
exit;
|
||||
}
|
||||
|
||||
$SupplierPaymentID = $obj['SupplierPaymentID'];
|
||||
$SupplierInvoiceID = $obj['SupplierInvoiceID'];
|
||||
|
||||
# CEK index invoice terakhir #
|
||||
$roundvalue = 0;
|
||||
if ($idx == $lastIndex) {
|
||||
$roundvalue = $rounding;
|
||||
}
|
||||
|
||||
# UPDATE header supplier payment #
|
||||
$sql_updateheader = "UPDATE supplier_payment SET
|
||||
SupplierPaymentIsConfirm = 'Y',
|
||||
SupplierPaymentConfirmUserID = ?,
|
||||
SupplierPaymentGroupNumber = ?,
|
||||
SupplierPaymentCashierNumber = ?,
|
||||
SupplierPaymentRounding = ?,
|
||||
SupplierPaymentConfirmDate = now(),
|
||||
SupplierPaymentNote = ?,
|
||||
SupplierPaymentCoaID = ?
|
||||
WHERE SupplierPaymentID = ?";
|
||||
$que_updateheader = $this->db->query($sql_updateheader, [
|
||||
$users['M_UserID'],
|
||||
$paygroupnum,
|
||||
$paynumber,
|
||||
$roundvalue,
|
||||
$param['keterangan'],
|
||||
$param['paymenttype'],
|
||||
$SupplierPaymentID
|
||||
]);
|
||||
if (!$que_updateheader) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update supplier payment header");
|
||||
exit;
|
||||
}
|
||||
|
||||
# UPDATE status lunas supplier invoice #
|
||||
$sql_suppinvoice = "UPDATE supplier_invoice
|
||||
SET SupplierInvoiceIsLunas = 'Y'
|
||||
WHERE SupplierInvoiceID = ?";
|
||||
$que_suppinvoice = $this->db->query($sql_suppinvoice, [$SupplierInvoiceID]);
|
||||
if (!$que_suppinvoice) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update status lunas invoice");
|
||||
exit;
|
||||
}
|
||||
|
||||
# GET Latest data supplier payment #
|
||||
$sql_suppayment = "SELECT * FROM supplier_payment WHERE SupplierPaymentID = ?";
|
||||
$que_suppayment = $this->db->query($sql_suppayment, [$SupplierPaymentID]);
|
||||
if (!$que_suppayment) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data latest supplier payment");
|
||||
exit;
|
||||
}
|
||||
$suppayment_header = $que_suppayment->row_array();
|
||||
|
||||
$sql_suppaymentdetail = "SELECT * FROM supplier_payment_detail
|
||||
WHERE SupplierPaymentDetailSupplierPaymentID = ?";
|
||||
$que_suppaymentdetail = $this->db->query($sql_suppaymentdetail, [$SupplierPaymentID]);
|
||||
if (!$que_suppaymentdetail) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data latest supplier payment detail");
|
||||
exit;
|
||||
}
|
||||
$suppayment_detail = $que_suppaymentdetail->result_array();
|
||||
|
||||
$data_log = [
|
||||
"header" => $suppayment_header,
|
||||
"detail" => $suppayment_detail
|
||||
];
|
||||
|
||||
# LOG activity confirm payment #
|
||||
$messg = "Pembayaran Faktur No: {$suppayment_header['SupplierPaymentNumber']}";
|
||||
$messg .= " telah dikonfirmasi oleh {$users['M_UserUsername']} dengan nomor";
|
||||
$messg .= " pembayaran kasir: {$suppayment_header['SupplierPaymentCashierNumber']}";
|
||||
$this->insert_activity_log(
|
||||
"PF",
|
||||
"CONFIRM",
|
||||
$messg,
|
||||
$SupplierPaymentID,
|
||||
$data_log,
|
||||
$users['M_UserID']
|
||||
);
|
||||
|
||||
## INSERT jurnal ##
|
||||
$detail_transac = [];
|
||||
|
||||
# GET data hutang #
|
||||
$sql_datahutang = "SELECT
|
||||
SupplierPaymentNumber AS addonvalue,
|
||||
SupplierPaymentDetailID,
|
||||
jurnalTxCoaID AS coaID,
|
||||
jurnalTxDescription AS coaDescription,
|
||||
SupplierPaymentDetailAmount,
|
||||
SupplierInvoiceDetailItemID
|
||||
FROM supplier_payment
|
||||
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
|
||||
JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierPaymentSupplierInvoiceID
|
||||
AND SupplierInvoiceDetailIsActive = 'Y'
|
||||
JOIN jurnal_tx ON SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID
|
||||
WHERE SupplierPaymentID = ?
|
||||
AND SupplierPaymentDetailIsActive = 'Y'";
|
||||
$que_datahutang = $this->db->query($sql_datahutang, [$SupplierPaymentID]);
|
||||
if (!$que_datahutang) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data hutang item");
|
||||
exit;
|
||||
}
|
||||
$data_hutang = $que_datahutang->result_array();
|
||||
foreach ($data_hutang as $key => $debt) {
|
||||
$detail_transac[] = [
|
||||
"coaID" => $debt['coaID'],
|
||||
"coaDescription" => $debt['coaDescription'],
|
||||
"debit" => $debt['SupplierPaymentDetailAmount'],
|
||||
"credit" => 0,
|
||||
"addoncode" => "JFA",
|
||||
"addonvalue" => $debt['addonvalue'],
|
||||
"addonitemid" => $debt['SupplierInvoiceDetailItemID']
|
||||
];
|
||||
}
|
||||
|
||||
# GET data bayar #
|
||||
$sql_databayar = "SELECT
|
||||
CONCAT('Jurnal Payment Invoice Nomor : ',
|
||||
SupplierPaymentNumber, DATE_FORMAT(now(),
|
||||
', Tanggal : %d-%m-%Y ')
|
||||
) AS jurnaltitle,
|
||||
CONCAT('Nomor pembayaran kasir : ',
|
||||
SupplierPaymentCashierNumber,
|
||||
' dan Nomor grup pembayaran : ',
|
||||
SupplierPaymentGroupNumber
|
||||
) AS jurnaldesc,
|
||||
SupplierPaymentNumber AS no_payinv,
|
||||
SupplierPaymentGroupNumber AS addonvalue,
|
||||
SupplierPaymentCoaID AS coaID,
|
||||
coaDescription,
|
||||
SupplierPaymentAmount AS amount,
|
||||
SupplierPaymentRounding AS rounding,
|
||||
(SupplierPaymentAmount + SupplierPaymentRounding) AS bayar
|
||||
FROM supplier_payment
|
||||
JOIN coa ON coaID = SupplierPaymentCoaID
|
||||
WHERE SupplierPaymentID = ?";
|
||||
$que_databayar = $this->db->query($sql_databayar, [$SupplierPaymentID]);
|
||||
if (!$que_databayar) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data bayar");
|
||||
exit;
|
||||
}
|
||||
$data_bayar = $que_databayar->row_array();
|
||||
$detail_transac[] = [
|
||||
"coaID" => $data_bayar['coaID'],
|
||||
"coaDescription" => $data_bayar['coaDescription'],
|
||||
"debit" => 0,
|
||||
"credit" => abs($data_bayar['bayar']),
|
||||
"addoncode" => "PAYINVGR",
|
||||
"addonvalue" => $data_bayar['addonvalue'],
|
||||
"addonitemid" => 0
|
||||
];
|
||||
|
||||
# rugi / untung dari rounding #
|
||||
$sql_lossprofit = "SELECT coaID, coaDescription
|
||||
FROM coa WHERE coaAccountNo = ? AND coaIsActive = 'Y'";
|
||||
$data_round = doubleval($data_bayar['rounding']);
|
||||
if ($data_round > 0) {
|
||||
# loss #
|
||||
$que_lossprofit = $this->db->query($sql_lossprofit, ['6120402001']);
|
||||
if (!$que_lossprofit) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data coa loss sisa kas");
|
||||
exit;
|
||||
}
|
||||
$loss_coa = $que_lossprofit->row_array();
|
||||
|
||||
$detail_transac[] = [
|
||||
"coaID" => $loss_coa['coaID'],
|
||||
"coaDescription" => $loss_coa['coaDescription'],
|
||||
"debit" => abs($data_round),
|
||||
"credit" => 0,
|
||||
"addoncode" => "PAYINVGR",
|
||||
"addonvalue" => $data_bayar['addonvalue'],
|
||||
"addonitemid" => 0
|
||||
];
|
||||
} elseif ($data_round < 0) {
|
||||
# profit #
|
||||
$que_lossprofit = $this->db->query($sql_lossprofit, ['6110500001']);
|
||||
if (!$que_lossprofit) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data coa profit sisa kas");
|
||||
exit;
|
||||
}
|
||||
$profit_coa = $que_lossprofit->row_array();
|
||||
|
||||
$detail_transac[] = [
|
||||
"coaID" => $profit_coa['coaID'],
|
||||
"coaDescription" => $profit_coa['coaDescription'],
|
||||
"debit" => 0,
|
||||
"credit" => abs($data_round),
|
||||
"addoncode" => "PAYINVGR",
|
||||
"addonvalue" => $data_bayar['addonvalue'],
|
||||
"addonitemid" => 0
|
||||
];
|
||||
}
|
||||
|
||||
$this->insertJurnal($users, $data_bayar, $detail_transac);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] success multi payment invoice");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
private function insertJurnal($users, $databayar, $detailtrx)
|
||||
{
|
||||
# GET periode jurnal #
|
||||
$sql_periode = "SELECT periodeID FROM periode
|
||||
WHERE DATE(NOW()) BETWEEN periodeStartDate AND periodeEndDate
|
||||
AND periodeIsActive = 'Y' AND periodeIsClosed = 'N'";
|
||||
$que_periode = $this->db->query($sql_periode, []);
|
||||
if (!$que_periode) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] find periode id");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($que_periode->num_rows() === 0) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] Waktu periode tidak ditemukan");
|
||||
exit;
|
||||
}
|
||||
$JurnalPeriode = $que_periode->row_array()['periodeID'];
|
||||
|
||||
# GENERATE nomor jurnal #
|
||||
$sql_jurnalno = "SELECT `fn_numbering`('J') AS jnumber";
|
||||
$que_jurnalno = $this->db->query($sql_jurnalno, []);
|
||||
if (!$que_jurnalno) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] generate jurnal number");
|
||||
exit;
|
||||
}
|
||||
$JurnalNumber = $que_jurnalno->row_array()['jnumber'];
|
||||
$JurnalTitle = $databayar['jurnaltitle'];
|
||||
$JurnalDescp = $databayar['jurnaldesc'];
|
||||
|
||||
# GET jurnal type #
|
||||
$sql_jurnaltype = "SELECT JurnalTypeID FROM jurnal_type
|
||||
WHERE JurnalTypeCode = 'PAYMENTINV' AND JurnalTypeIsActive = 'Y'";
|
||||
$que_jurnaltype = $this->db->query($sql_jurnaltype, []);
|
||||
if (!$que_jurnaltype) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get jurnal type");
|
||||
exit;
|
||||
}
|
||||
$JurnalType = $que_jurnaltype->row_array()['JurnalTypeID'];
|
||||
|
||||
# INSERT jurnal header #
|
||||
$sql_insheader = "INSERT INTO jurnal (
|
||||
jurnalM_BranchCompanyID,
|
||||
JurnalS_RegionalID,
|
||||
jurnalM_BranchCode,
|
||||
jurnalperiodeID,
|
||||
jurnalNo,
|
||||
jurnalTitle,
|
||||
jurnalDescription,
|
||||
jurnalDate,
|
||||
jurnalJurnalTypeID,
|
||||
jurnalM_UserID
|
||||
) VALUES (?,?,?,?,?,?,?,NOW(),?,?)";
|
||||
$que_inserjurnal = $this->db->query($sql_insheader, [
|
||||
$users['M_BranchCompanyID'],
|
||||
$users['S_RegionalID'],
|
||||
$users['M_BranchCode'],
|
||||
$JurnalPeriode,
|
||||
$JurnalNumber,
|
||||
$JurnalTitle,
|
||||
$JurnalDescp,
|
||||
$JurnalType,
|
||||
$users['M_UserID']
|
||||
]);
|
||||
if (!$que_inserjurnal) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert jurnal header");
|
||||
exit;
|
||||
}
|
||||
$JurnalID = $this->db->insert_id();
|
||||
|
||||
# INSERT jurnal tx #
|
||||
foreach ($detailtrx as $key => $trax) {
|
||||
$sql_trax = "INSERT INTO jurnal_tx (
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxM_UserID
|
||||
) VALUES (?,?,?,?,?,?)";
|
||||
$que_trax = $this->db->query($sql_trax, [
|
||||
$JurnalID,
|
||||
$trax['coaID'],
|
||||
$trax['coaDescription'],
|
||||
$trax['debit'],
|
||||
$trax['credit'],
|
||||
$users['M_UserID']
|
||||
]);
|
||||
if (!$que_trax) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert jurnal tx");
|
||||
exit;
|
||||
}
|
||||
$JurnalTxID = $this->db->insert_id();
|
||||
|
||||
# INSERT jurnal addon #
|
||||
$sql_addon = "INSERT INTO jurnal_addon (
|
||||
jurnalAddOnJurnalID,
|
||||
jurnalAddOnJurnalTxID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnM_ItemID,
|
||||
jurnalAddOnCreated,
|
||||
jurnalAddOnCreatedUserID
|
||||
) VALUES (?,?,?,?,?,NOW(),?)";
|
||||
$que_addon = $this->db->query($sql_addon, [
|
||||
$JurnalID,
|
||||
$JurnalTxID,
|
||||
$trax['addoncode'],
|
||||
$trax['addonvalue'],
|
||||
$trax['addonitemid'],
|
||||
$users['M_UserID']
|
||||
]);
|
||||
if (!$que_addon) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert jurnal addon");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function insert_activity_log($actcode, $status, $desc, $refID, $data, $userID)
|
||||
{
|
||||
$json = json_encode($data);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error("[Error] encode data into json for log activity");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO user_activity(
|
||||
UserActivityCode,
|
||||
UserActivityStatus,
|
||||
UserActivityDescription,
|
||||
UserActivityRefID,
|
||||
UserActivityData,
|
||||
UserActivityUserID,
|
||||
UserActivityCreated
|
||||
) VALUES (?,?,?,?,?,?,NOW())";
|
||||
$que = $this->db->query($sql, [
|
||||
$actcode,
|
||||
$status,
|
||||
$desc,
|
||||
$refID,
|
||||
$json,
|
||||
$userID
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert into table log activity");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user