update / proses add akun pusat di media jurnal & move barcode to serah terima

This commit is contained in:
2026-05-13 16:51:39 +07:00
parent 4234c37e75
commit dc4e16329f
16 changed files with 4227 additions and 551 deletions

View File

@@ -139,9 +139,7 @@ class Journalcashv2 extends MY_Controller
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
WHERE $where_sql
GROUP BY jurnalID
ORDER BY jurnalID DESC
";
ORDER BY jurnalID DESC";
// Ambil total count
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
$qry_total = $this->db->query($sql_total, $params);
@@ -165,7 +163,6 @@ class Journalcashv2 extends MY_Controller
// Tambahkan LIMIT OFFSET
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
$qry = $this->db->query($sql_paginated, $params_paginated);
if ($qry) {
@@ -278,10 +275,10 @@ class Journalcashv2 extends MY_Controller
$sql = "SELECT S_RegionalID, S_RegionalName
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalID = ?
ORDER BY S_RegionalName ASC";
AND (S_RegionalID = ? OR 0 = ?)
ORDER BY S_RegionalID ASC";
$qry = $this->db->query($sql, [$regionalId]);
$qry = $this->db->query($sql, [$regionalId, $regionalId]);
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("select regional", $this->db);
@@ -364,6 +361,7 @@ class Journalcashv2 extends MY_Controller
$this->sys_error($message);
}
}
function getUserApproveLevel()
{
try {

View File

@@ -41,7 +41,9 @@ class Journalgoodreceive extends MY_Controller
periodeMonth,
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
periodeName,
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode
CONCAT(DATE_FORMAT(periodeStartDate, '%d %M %Y'), ' - ', DATE_FORMAT(periodeEndDate, '%d %M %Y')) as periode,
periodeEndDate AS periode_end,
periodeStartDate AS periode_start
FROM periode
WHERE periodeIsActive = 'Y'
AND periodeIsClosed = 'N'
@@ -70,9 +72,9 @@ class Journalgoodreceive extends MY_Controller
$prm = $this->sys_input;
$user = $this->sys_user;
$regionalId = $prm["regionalId"] ?? $user["S_RegionalID"];
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
$periodeid = $prm["periodeid"] ?? null;
$regionalId = $prm["regionalId"];
$branchCode = $prm["branchCode"];
$periodeid = $prm["periodeid"] ?? 0;
$xdate = $prm["xdate"] ?? null;
$search = $prm["search"] ?? "";
$search = "%" . trim($search) . "%";
@@ -87,10 +89,18 @@ class Journalgoodreceive extends MY_Controller
$params = [$periodeid, $xdate, $search];
// Filter login level
if ($loginLevel == "branch") {
switch ($loginLevel) {
case 'pusat':
$where_conditions[] = "(jurnalS_RegionalID = ? OR 0 = ?)";
$params[] = $regionalId;
$params[] = $regionalId;
if (!empty($branchCode)) {
$where_conditions[] = "jurnalM_BranchCode = ?";
$params[] = $branchCode;
} elseif ($loginLevel == "regional") {
}
break;
case 'regional':
$where_conditions[] = "jurnalS_RegionalID = ?";
$params[] = $regionalId;
@@ -98,6 +108,14 @@ class Journalgoodreceive extends MY_Controller
$where_conditions[] = "jurnalM_BranchCode = ?";
$params[] = $branchCode;
}
break;
case 'branch':
$where_conditions[] = "jurnalM_BranchCode = ?";
$params[] = $branchCode;
break;
default:
$this->sys_error_db("user login level not found", $this->db);
exit;
}
// Gabungkan WHERE SQL
@@ -131,16 +149,18 @@ class Journalgoodreceive extends MY_Controller
'' as ErrMsg,
'' as detailtx
FROM jurnal
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
JOIN m_branch_company ON jurnalM_BranchCompanyID = M_BranchCompanyID
AND M_BranchCompanyIsActive = 'Y'
JOIN periode ON jurnalperiodeID = periodeID AND periodeIsActive = 'Y'
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID AND JurnalTypeIsActive = 'Y' AND JurnalTypeIsAuto = 'Y'
JOIN jurnal_type ON jurnalJurnalTypeID = JurnalTypeID
AND JurnalTypeIsActive = 'Y'
AND JurnalTypeIsAuto = 'Y'
AND JurnalTypeCode = 'AUTOGOODRECEIVE'
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
WHERE $where_sql
GROUP BY jurnalID
ORDER BY jurnalID DESC
";
ORDER BY jurnalID DESC";
// Ambil total count
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
@@ -157,7 +177,6 @@ class Journalgoodreceive extends MY_Controller
$totalCount = $qry_total->row()->total ?? 0;
$totalPage = ceil($totalCount / $number_limit);
} else {
$this->db->trans_rollback();
$this->sys_error_db("select jurnal count error", $this->db);
exit();
}
@@ -171,7 +190,6 @@ class Journalgoodreceive extends MY_Controller
if ($qry) {
$rows = $qry->result_array();
} else {
$this->db->trans_rollback();
$this->sys_error_db("select jurnal error", $this->db);
exit();
}
@@ -184,7 +202,6 @@ class Journalgoodreceive extends MY_Controller
AND JurnalErr_JurnalID = ?";
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
if (!$qry_err) {
$this->db->trans_rollback();
$this->sys_error_db("select jurnal msg error", $this->db);
exit();
}
@@ -225,7 +242,6 @@ class Journalgoodreceive extends MY_Controller
FROM jurnal_tx
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
-- AND (jurnalAddOnCode = 'RONUMB')
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
WHERE jurnalTxIsActive = 'Y'
AND jurnalTxJurnalID = ?
@@ -238,14 +254,10 @@ class Journalgoodreceive extends MY_Controller
jurnalTxID ASC";
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
if (!$qry_detail) {
$this->db->trans_rollback();
$this->sys_error_db("select jurnal tx error", $this->db);
exit();
}
// echo $this->db->last_query();
// exit;
$rows_detail = $qry_detail->result_array();
if (count($rows_detail) > 0) {
$rows[$key]["detailtx"] = $rows_detail;
@@ -276,15 +288,15 @@ class Journalgoodreceive extends MY_Controller
$this->sys_error("Invalid Token");
}
$prm = $this->sys_input;
$regionalId = $prm["regionalId"] ?? null;
$regionalId = $prm["regionalId"] ?? 0;
$sql = "SELECT S_RegionalID, S_RegionalName
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalID = ?
AND (S_RegionalID = ? OR 0 = ?)
ORDER BY S_RegionalName ASC";
$qry = $this->db->query($sql, [$regionalId]);
$qry = $this->db->query($sql, [$regionalId, $regionalId]);
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("select regional", $this->db);

View File

@@ -67,8 +67,8 @@ class Mditem extends MY_Controller
Fa_ClassID,
Fa_ClassName,
Fa_ClassFlagType,
Fa_InventarisGolID,
Fa_InventarisGolName,
M_InventarisGolID,
M_InventarisGolName,
ItemUnitID,
ItemUnitCode,
GROUP_CONCAT(ItemUnitName) as ItemUnitName,
@@ -78,7 +78,7 @@ class Mditem extends MY_Controller
LEFT JOIN nat_group ON M_ItemNat_GroupID = Nat_GroupID
LEFT JOIN nat_subgroup ON M_ItemNat_SubGroupID = Nat_SubGroupID
LEFT JOIN fa_class ON M_ItemFa_ClassID = Fa_ClassID
LEFT JOIN fa_inventaris_gol ON M_ItemM_InventarisGolID = Fa_InventarisGolID
LEFT JOIN m_inventaris_gol ON M_ItemM_InventarisGolID = M_InventarisGolID
LEFT JOIN itemunitmap ON M_ItemID = ItemUnitMapM_ItemID
AND ItemUnitMapIsActive = 'Y'
LEFT JOIN itemunit ON ItemUnitMapItemUnitID = ItemUnitID
@@ -140,7 +140,7 @@ class Mditem extends MY_Controller
LEFT JOIN nat_group ON M_ItemNat_GroupID = Nat_GroupID
LEFT JOIN nat_subgroup ON M_ItemNat_SubGroupID = Nat_SubGroupID
LEFT JOIN fa_class ON M_ItemFa_ClassID = Fa_ClassID
LEFT JOIN fa_inventaris_gol ON M_ItemM_InventarisGolID = Fa_InventarisGolID
LEFT JOIN m_inventaris_gol ON M_ItemM_InventarisGolID = M_InventarisGolID
LEFT JOIN itemunitmap ON M_ItemID = ItemUnitMapM_ItemID
AND ItemUnitMapIsActive = 'Y'
LEFT JOIN itemunit ON ItemUnitMapItemUnitID = ItemUnitID
@@ -408,7 +408,7 @@ class Mditem extends MY_Controller
}
}
function get_fa_inventaris_gol()
function get_inventaris_gol()
{
try {
if (!$this->isLogin) {
@@ -420,21 +420,20 @@ class Mditem extends MY_Controller
$search = isset($prm["search"]) ? $prm["search"] : "";
$sql = "SELECT
Fa_InventarisGolID,
Fa_InventarisGolName,
Fa_InventarisGolCreated,
Fa_InventarisGolLastUpdated,
Fa_InventarisGolIsActive,
Fa_InventarisGolUserID
FROM fa_inventaris_gol
WHERE Fa_InventarisGolIsActive = 'Y'
ORDER BY Fa_InventarisGolID DESC";
M_InventarisGolID,
M_InventarisGolName,
M_InventarisGolCreated,
M_InventarisGolLastUpdated,
M_InventarisGolIsActive,
M_InventarisGolUserID
FROM m_inventaris_gol
WHERE M_InventarisGolIsActive = 'Y'
ORDER BY M_InventarisGolID DESC";
$query = $this->db->query($sql);
if (!$query) {
$this->sys_error_db("fa inventaris gol list", $this->db);
$this->sys_error_db("m inventaris gol list", $this->db);
exit;
}

View File

@@ -263,7 +263,7 @@ class Fakturv4 extends MY_Controller
{
try {
if (!$this->isLogin) {
$this->sys_error();
$this->sys_error("invalid token");
exit;
}
@@ -451,7 +451,7 @@ class Fakturv4 extends MY_Controller
WHERE SupplierInvoiceIsActive = 'Y'
AND (
SupplierInvoiceNumber LIKE ? OR
SupplierInvoiceDeliveryOrderNumber LIKE ? OR
SupplierInvoiceRefNumber LIKE ? OR
SupplierInvoiceSupplierInvoiceNumber LIKE ?
)
AND SupplierInvoiceDate >= DATE(?)
@@ -461,8 +461,16 @@ class Fakturv4 extends MY_Controller
GROUP BY SupplierInvoiceID
ORDER BY SUpplierInvoiceID DESC";
$quetal = $this->db->query($sqltal, [
$branchID, $nomo, $nomo, $nomo, $date, $enddate,
$status, $status, $supplier, $supplier
$branchID,
$nomo,
$nomo,
$nomo,
$date,
$enddate,
$status,
$status,
$supplier,
$supplier
]);
if (!$quetal) {
$this->sys_error_db("[Error] get total data faktur");
@@ -502,7 +510,7 @@ class Fakturv4 extends MY_Controller
WHERE SupplierInvoiceIsActive = 'Y'
AND (
SupplierInvoiceNumber LIKE ? OR
SupplierInvoiceDeliveryOrderNumber LIKE ? OR
SupplierInvoiceRefNumber LIKE ? OR
SupplierInvoiceSupplierInvoiceNumber LIKE ?
)
AND SupplierInvoiceDate >= DATE(?)
@@ -513,9 +521,18 @@ class Fakturv4 extends MY_Controller
ORDER BY SUpplierInvoiceID DESC
LIMIT ? OFFSET ?";
$quefak = $this->db->query($sqlfak, [
$branchID, $nomo, $nomo, $nomo, $date, $enddate,
$status, $status, $supplier, $supplier,
$limit, $hal
$branchID,
$nomo,
$nomo,
$nomo,
$date,
$enddate,
$status,
$status,
$supplier,
$supplier,
$limit,
$hal
]);
if (!$quefak) {
$this->sys_error_db("[Error] get list data faktur");
@@ -630,7 +647,8 @@ class Fakturv4 extends MY_Controller
}
}
public function LookupAttachment() {
public function LookupAttachment()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
@@ -647,7 +665,7 @@ class Fakturv4 extends MY_Controller
FROM receive_order_po_document
WHERE ReceiveOrderPoDocumentReceiveOrderPoID = ?
AND ReceiveOrderPoDocumentIsActive = 'Y'";
$que = $this->db->query($sql, [ $para['roID'] ]);
$que = $this->db->query($sql, [$para['roID']]);
if (!$que) {
$this->sys_error_db("[Error] failed get data attachment inventaris");
exit;
@@ -657,7 +675,10 @@ class Fakturv4 extends MY_Controller
foreach ($rows as $key => $value) {
$rows[$key]['category'] = $para['category'];
}
$data[] = $rows;
if (count($rows) > 0) {
$data = $rows;
}
$this->sys_ok($data);
} catch (Exception $exc) {
@@ -672,7 +693,7 @@ class Fakturv4 extends MY_Controller
{
try {
if (!$this->isLogin) {
$this->sys_error();
$this->sys_error("invalid token");
exit;
}
@@ -847,7 +868,7 @@ class Fakturv4 extends MY_Controller
{
try {
if (!$this->isLogin) {
$this->sys_error();
$this->sys_error("invalid token");
exit;
}
$para = $this->sys_input;
@@ -1538,38 +1559,29 @@ class Fakturv4 extends MY_Controller
exit;
}
} else if ($item['M_ItemItem_CategoryID'] == '2') {
// Mapping JurnalTx sama dengan Persediaan hanya beda CoA
// TODO: Update dengan CoA yang Benar
// Jika ItemNatsubGroup belum termapping return error
if (empty($item['M_ItemNat_SubGroupID'])) {
if (empty($item['M_ItemM_InventarisGolID'])) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] Item {$item['M_ItemDesc']} tidak memiliki Nat_SubGroupID");
exit;
};
$sqlsgp = "SELECT map_nat_group.*
FROM map_nat_group
JOIN map_nat_subgroup ON MapNatSub_NatGroupID = MapNatGroup_NatGroupID
AND MapNatSub_IsActive = 'Y'
WHERE MapNatGroup_NatGroupID = ?
AND MapNatSub_NatSubGroupID = ?
AND MapNatGroup_IsActive = 'Y'";
$quesgp = $this->db->query($sqlsgp, [$item['M_ItemNat_GroupID'], $item['M_ItemNat_SubGroupID']]);
if (!$quesgp) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] get map_nat_subgroup");
$this->sys_error_db("[Error] item golongan inventaris belum ditentukan");
exit;
}
$itemGroup = $quesgp->row_array();
if (
empty($itemGroup['MapNatGroup_Debt_coaID']) ||
empty($itemGroup['MapNatGroup_Debt_coaAccNo']) ||
empty($itemGroup['MapNatGroup_Debt_coaDesc'])
) {
$sql_coainv = "SELECT
CoaMapInventarisHutangCoaID,
CoaMapInventarisHutangCoaNo,
CoaMapInventarisHutangCoaDesc
FROM coa_map_inventaris
WHERE CoaMapInventarisM_InventarisGolID = ?
AND CoaMapInventarisIsActive = 'Y'";
$que_coainv = $this->db->query($sql_coainv, [$item['M_ItemM_InventarisGolID']]);
if (!$que_coainv) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] coa item tidak ditemukan / belum dimapping");
$this->sys_error_db("[Error] failed to get coa inventaris gol");
exit;
}
$item_coainv = $que_coainv->row_array();
if (empty($item_coainv)) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] item inventaris coa not found");
exit;
}
@@ -1581,8 +1593,8 @@ class Fakturv4 extends MY_Controller
$status = $this->InsertJurnalTx(
$jurnalID,
$itemGroup['MapNatGroup_Debt_coaID'],
$itemGroup['MapNatGroup_Debt_coaDesc'],
$item_coainv['CoaMapInventarisHutangCoaID'],
$item_coainv['CoaMapInventarisHutangCoaDesc'],
$user['M_UserID'],
0,
$kredit
@@ -1626,57 +1638,7 @@ class Fakturv4 extends MY_Controller
exit;
}
} else if ($item['M_ItemItem_CategoryID'] == '4') {
// if (empty($item['M_ItemNat_SubGroupID'])) {
// $this->db->trans_rollback();
// $this->sys_error_db("[Error] Item {$item['M_ItemDesc']} tidak memiliki Nat_SubGroupID");
// exit;
// };
$this->InsertJurnalTxJasa($jurnalID, $item['M_ItemID'], $inv, $user['M_UserID']);
// $sqlsgp = "SELECT map_nat_group.*
// FROM map_nat_group
// JOIN map_nat_subgroup ON MapNatSub_NatGroupID = MapNatGroup_NatGroupID
// AND MapNatSub_IsActive = 'Y'
// WHERE MapNatGroup_NatGroupID = ?
// AND MapNatSub_NatSubGroupID = ?
// AND MapNatGroup_IsActive = 'Y'";
// $quesgp = $this->db->query($sqlsgp, [$item['M_ItemNat_GroupID'], $item['M_ItemNat_SubGroupID']]);
// if (!$quesgp) {
// $this->db->trans_rollback();
// $this->sys_error_db("[Error] get map_nat_subgroup");
// exit;
// }
// $itemGroup = $quesgp->row_array();
// if (
// empty($itemGroup['MapNatGroup_Debt_coaID']) ||
// empty($itemGroup['MapNatGroup_Debt_coaAccNo']) ||
// empty($itemGroup['MapNatGroup_Debt_coaDesc'])
// ) {
// $this->db->trans_rollback();
// $this->sys_error_db("[Error] coa item tidak ditemukan / belum dimapping");
// exit;
// }
// $price = (doubleval($inv['SupplierInvoiceDetailTotal']) - doubleval($inv['SupplierInvoiceDetailDiscountPoProrata']));
// // $taxPPH = doubleval($inv['SupplierInvoiceTaxPercentPph']) * $price / 100;
// $taxPPN = doubleval($inv['SupplierInvoiceTaxPercentPpn']) * $price / 100;
// $kredit = round($price + $taxPPN, 2);
// $status = $this->InsertJurnalTx(
// $jurnalID,
// $itemGroup['MapNatGroup_Debt_coaID'],
// $itemGroup['MapNatGroup_Debt_coaDesc'],
// $user['M_UserID'],
// 0,
// $kredit
// );
// if (!$status) {
// $this->sys_error_db($status['msg']);
// exit;
// }
}
}
@@ -1709,7 +1671,8 @@ class Fakturv4 extends MY_Controller
}
}
private function InsertJurnalTxJasa($jurnalID, $itemid, $invoice, $userid) {
private function InsertJurnalTxJasa($jurnalID, $itemid, $invoice, $userid)
{
$sql_coa = "SELECT
JasaCoaMapHutangCoaID,
JasaCoaMapHutangCoaNo,
@@ -1740,9 +1703,12 @@ class Fakturv4 extends MY_Controller
$kredit = round($price + $taxPPN, 2);
$insert = $this->InsertJurnalTx(
$jurnalID, $coajasa['JasaCoaMapHutangCoaID'],
$jurnalID,
$coajasa['JasaCoaMapHutangCoaID'],
$coajasa['JasaCoaMapHutangCoaDesc'],
$userid, 0, $kredit
$userid,
0,
$kredit
);
if (!$insert) {
$this->db->trans_rollback();

View File

@@ -929,6 +929,11 @@ class PurchaseRequestNonPersediaan extends MY_Controller
$params[] = $itemSubGroup;
}
$filterCoaInventaris = "";
if ($itemCategory == "2") {
$filterCoaInventaris = "JOIN coa_map_inventaris ON CoaMapInventarisM_InventarisGolID = M_ItemM_InventarisGolID AND CoaMapInventarisIsActive = 'Y'";
}
$params[] = $itemCategory;
$params[] = $itemCategory;
$params[] = '%' . $search . '%';
@@ -950,6 +955,7 @@ class PurchaseRequestNonPersediaan extends MY_Controller
$filterDivision
$filterItemGroup
$filterItemSubGroup
$filterCoaInventaris
WHERE M_ItemIsActive = 'Y' AND
( M_ItemItem_CategoryID = ? OR ? = '' )
AND M_ItemDesc LIKE ?
@@ -981,17 +987,18 @@ class PurchaseRequestNonPersediaan extends MY_Controller
'N' as isEditingPrice,
0 as remaining_stock
FROM m_item
JOIN itemunitmap ON ItemUnitMapM_ItemID = M_ItemID AND
((ItemUnitMapIsPurchase = 'Y' AND ? = 'purchase') OR
(ItemUnitMapIsBase = 'Y' AND ? = 'base')) AND
ItemUnitMapIsActive = 'Y'
JOIN itemunit ON ItemUnitID = ItemUnitMapItemUnitID AND
ItemUnitIsActive = 'Y'
JOIN itemunitmap ON ItemUnitMapM_ItemID = M_ItemID
AND ((ItemUnitMapIsPurchase = 'Y' AND ? = 'purchase') OR
(ItemUnitMapIsBase = 'Y' AND ? = 'base'))
AND ItemUnitMapIsActive = 'Y'
JOIN itemunit ON ItemUnitID = ItemUnitMapItemUnitID
AND ItemUnitIsActive = 'Y'
$filterDivision
$filterItemGroup
$filterItemSubGroup
WHERE M_ItemIsActive = 'Y' AND
( M_ItemItem_CategoryID = ? OR ? = '' )
$filterCoaInventaris
WHERE M_ItemIsActive = 'Y'
AND ( M_ItemItem_CategoryID = ? OR ? = '' )
AND M_ItemDesc LIKE ?
ORDER BY M_ItemDesc ASC
LIMIT ? OFFSET ?";

View File

@@ -630,28 +630,28 @@ class ReceiveItemPoInventaris extends MY_Controller
$user = $this->sys_user;
$param = $this->sys_input;
// $sql = "SELECT DISTINCT
// u.M_UserID,
// u.M_UserUsername
// FROM receive_order_po ro
// JOIN receive_order_po_detail rod
// ON rod.ReceiveOrderPoDetailReceiveOrderPoID = ro.ReceiveOrderPoID
// AND rod.ReceiveOrderPoDetailIsActive = 'Y'
// JOIN purchase_order_detail pod
// ON pod.PurchaseOrderDetailID = rod.ReceiveOrderPoDetailPurchaseOrderDetailID
// AND pod.PurchaseOrderDetailIsActive = 'Y'
// JOIN purchase_request pr
// ON pr.PurchaseRequestID = pod.PurchaseOrderDetailPurchaseRequestID
// AND pr.PurchaseRequestIsActive = 'Y'
// JOIN m_user u
// ON u.M_UserID = pr.PurchaseRequestRequestedBy
// AND u.M_UserIsActive = 'Y'
// WHERE
// ro.ReceiveOrderPoID = ?
// AND ro.ReceiveOrderPoIsActive = 'Y'";
// $que = $this->db->query($sql, [$param['ROID']]);
//
if ($param['isSerahTerima'] == 'Y') {
$sql = "SELECT DISTINCT
u.M_UserID,
u.M_UserUsername
FROM receive_order_po ro
JOIN receive_order_po_detail rod
ON rod.ReceiveOrderPoDetailReceiveOrderPoID = ro.ReceiveOrderPoID
AND rod.ReceiveOrderPoDetailIsActive = 'Y'
JOIN purchase_order_detail pod
ON pod.PurchaseOrderDetailID = rod.ReceiveOrderPoDetailPurchaseOrderDetailID
AND pod.PurchaseOrderDetailIsActive = 'Y'
JOIN purchase_request pr
ON pr.PurchaseRequestID = pod.PurchaseOrderDetailPurchaseRequestID
AND pr.PurchaseRequestIsActive = 'Y'
JOIN m_user u
ON u.M_UserID = pr.PurchaseRequestRequestedBy
AND u.M_UserIsActive = 'Y'
WHERE
ro.ReceiveOrderPoID = ?
AND ro.ReceiveOrderPoIsActive = 'Y'";
$que = $this->db->query($sql, [$param['ROID']]);
} else {
$sql = "SELECT
M_UserID,
M_UserUsername
@@ -661,6 +661,8 @@ class ReceiveItemPoInventaris extends MY_Controller
AND M_UserIsActive = 'Y'
ORDER BY M_UserUsername";
$que = $this->db->query($sql, [$user['M_BranchID'], $user['S_RegionalID']]);
}
if (!$que) {
$this->sys_error_db("[Error] get staff");
exit;
@@ -926,42 +928,42 @@ class ReceiveItemPoInventaris extends MY_Controller
$RODetailID = $this->db->insert_id();
if (intval($obj['qty']) > 0) {
$qty = intval($obj['qty']);
for ($i = 0; $i < $qty; $i++) {
# generate nomor barcode #
$noBarcode = $this->generateNoBarcode($user, $param['lokasiID'], 'BNP', $obj['M_ItemID']);
// if (intval($obj['qty']) > 0) {
// $qty = intval($obj['qty']);
// for ($i = 0; $i < $qty; $i++) {
// # generate nomor barcode #
// $noBarcode = $this->generateNoBarcode($user, $param['lokasiID'], 'BNP', $obj['M_ItemID']);
# INSERT INTO t_barcode_barang #
$sqlInsertBarcode = "INSERT INTO t_barcode_barang(
T_BarcodeBarangReceiveOrderPoID,
T_BarcodeBarangReceiveOrderPoDetailID,
T_BarcodeBarangRefType,
T_BarcodeBarangM_ItemID,
T_BarcodeBarangItemUnitID,
T_BarcodeBarangNumber,
T_BarcodeBarangM_RuanganID,
T_BarcodeBarangM_BranchID,
T_BarcodeBarangIsActive,
T_BarcodeBarangUserID,
T_BarcodeBarangCreated) VALUES(?,?,'PO',?,?,?,?,?,'Y',?,NOW())";
$qryInsertBarcode = $this->db->query($sqlInsertBarcode, array(
$roID,
$RODetailID,
$obj['M_ItemID'],
$obj['ItemUnitID'],
$noBarcode,
$param['lokasiID'],
$user['M_BranchID'],
$user['M_UserID']
));
if (!$qryInsertBarcode) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] insert data barcode item");
exit;
}
}
}
// # INSERT INTO t_barcode_barang #
// $sqlInsertBarcode = "INSERT INTO t_barcode_barang(
// T_BarcodeBarangReceiveOrderPoID,
// T_BarcodeBarangReceiveOrderPoDetailID,
// T_BarcodeBarangRefType,
// T_BarcodeBarangM_ItemID,
// T_BarcodeBarangItemUnitID,
// T_BarcodeBarangNumber,
// T_BarcodeBarangM_RuanganID,
// T_BarcodeBarangM_BranchID,
// T_BarcodeBarangIsActive,
// T_BarcodeBarangUserID,
// T_BarcodeBarangCreated) VALUES(?,?,'PO',?,?,?,?,?,'Y',?,NOW())";
// $qryInsertBarcode = $this->db->query($sqlInsertBarcode, array(
// $roID,
// $RODetailID,
// $obj['M_ItemID'],
// $obj['ItemUnitID'],
// $noBarcode,
// $param['lokasiID'],
// $user['M_BranchID'],
// $user['M_UserID']
// ));
// if (!$qryInsertBarcode) {
// $this->db->trans_rollback();
// $this->sys_error_db("[Error] insert data barcode item");
// exit;
// }
// }
// }
# INSERT INTO receive_order_po_inspeksi #
$inspeksi = $obj['inspeksi_item'];
@@ -1770,34 +1772,31 @@ class ReceiveItemPoInventaris extends MY_Controller
# INSERT JURNAL TX #
if (intval($item_cek['M_ItemItem_CategoryID']) == 2) {
if (empty($item_cek['M_ItemNat_SubGroupID'])) {
if (empty($item_cek['M_ItemM_InventarisGolID'])) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] subgroup item {$item_cek['M_ItemDesc']} tidak ditemukan pada PO
$this->sys_error_db("[Error] golongan inventaris item {$item_cek['M_ItemDesc']} tidak ditemukan pada PO
{$detail['PurchaseOrderNumber']}");
exit;
}
$sql_item_group = "SELECT * FROM map_nat_subgroup
WHERE MapNatSub_NatGroupID = ?
AND MapNatSub_NatSubGroupID = ?
AND MapNatSub_IsActive = 'Y'";
$que_item_group = $this->db->query($sql_item_group, [
$item_cek['M_ItemNat_GroupID'],
$item_cek['M_ItemNat_SubGroupID']
]);
if (!$que_item_group) {
$sql_coa_inv = "SELECT
CoaMapInventarisCoaID,
CoaMapInventarisCoaNo,
CoaMapInventarisCoaDesc
FROM coa_map_inventaris
WHERE CoaMapInventarisM_InventarisGolID = ?
AND CoaMapInventarisIsActive = 'Y'";
$que_coa_inv = $this->db->query($sql_coa_inv, [$item_cek['M_ItemM_InventarisGolID']]);
if (!$que_coa_inv) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] get item group/subgroup");
$this->sys_error_db("[Error] failed to get coa biaya item inventaris");
exit;
}
$item_group = $que_item_group->row_array();
if (
empty($item_group['MapNatSub_BiayaCoaID']) ||
empty($item_group['MapNatSub_BiayaCoaAccountNo']) ||
empty($item_group['MapNatSub_BiayaCoaDescription'])
) {
$iteminv_coa = $que_coa_inv->row_array();
if (empty($iteminv_coa['CoaMapInventarisCoaID'])) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] Account inventory item {$item_cek['M_ItemDesc']} tidak ditemukan");
$this->sys_error_db("[Error] coa gol inventaris not found");
exit;
}
@@ -1815,8 +1814,8 @@ class ReceiveItemPoInventaris extends MY_Controller
) VALUES (?,?,?,?,?,?)";
$que_tx_jurnal = $this->db->query($sql_tx_jurnal, [
$jurnal_ID,
$item_group['MapNatSub_BiayaCoaID'],
$item_group['MapNatSub_BiayaCoaDescription'],
$iteminv_coa['CoaMapInventarisCoaID'],
$iteminv_coa['CoaMapInventarisCoaDesc'],
$debet,
0,
$user['M_UserID']
@@ -1829,7 +1828,7 @@ class ReceiveItemPoInventaris extends MY_Controller
}
$juranl_tx_ID = $this->db->insert_id();
$each_desc[] = "- Add detail Jurnal debet {$item_cek['M_ItemDesc']}
{$item_group['MapNatSub_BiayaCoaDescription']} sejumlah {$this->formatRupiah($debet)}";
{$iteminv_coa['CoaMapInventarisCoaDesc']} sejumlah {$this->formatRupiah($debet)}";
# INSERT JURNAL ADDON #
$sql_addon_jurnal = "INSERT INTO jurnal_addon (

View 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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,152 @@
<?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, M_UserDefaultT_SampleStationID,
M_StaffName, 'N' as is_courier,
IFNULL(S_SystemsAutoLogoutTime,0) as time_autologout
from m_user
join m_usergroup ON M_UserM_UserGroupID = M_UserGroupID
left join m_staff on M_UserM_StaffID = M_StaffID
left join conf_systems ON S_SystemsIsActive = 'Y'
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;
}
// echo $this->db_onedev->last_query();
$rows = $query->result_array();
if (count($rows) > 0 ) {
$user = $rows[0];
$user['ip'] = $_SERVER['REMOTE_ADDR'];
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
//v2
$user['version'] = 'v2';
$user['last-login'] = date('Y-m-d H:i:s');
if (isset($prm['M_SatelliteID'])) {
$user['M_SatelliteID'] = $prm['M_SatelliteID'];
} else {
$user['M_SatelliteID'] = 0;
}
$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(), M_UserActiveToken = '{$token}' WHERE M_UserID = ?
",array($user['M_UserID']));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$query = $this->db_onedev->query("INSERT INTO acc_one_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'],'LOGIN','SUCCESS',$prm["username"]));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$query = $this->db_onedev->query("INSERT INTO acc_one_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'),$this->input->ip_address(),'LOGIN','FAILED',$prm["username"]));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_error_db("Invalid UserName / Password");
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function logout()
{
$prm = $this->sys_input;
try
{
$query = $this->db_onedev->query("
UPDATE m_user
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
WHERE M_UserID = ?",
array($this->sys_user['M_UserID']));
if (!$query)
{
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->db_onedev->query("INSERT INTO one_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $this->sys_user['M_UserUsername']));
$this->sys_ok("OK");
}
catch(Exception $exc)
{
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}
?>

View File

@@ -0,0 +1,171 @@
<?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 Authv2 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 getsatellite(){
$sql = $this->db_onedev->query("SELECT M_BranchHaveSatellite FROM m_branch
WHERE M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'")->row();
$hassatellite = $sql->M_BranchHaveSatellite;
$rows = [];
$query =" SELECT 0 as M_SatelliteID, M_BranchName as M_SatelliteName
FROM m_branch
WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'
UNION SELECT M_SatelliteID, M_SatelliteName
FROM m_satellite
WHERE
M_SatelliteIsActive = 'Y'";
//echo $query;
$rows['satellites'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
"hassatellite" => $hassatellite
);
$this->sys_ok($result);
exit;
}
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, M_UserDefaultT_SampleStationID,
M_StaffName, IF(M_CourierID = NULL, 'N','Y') as is_courier
from m_user
join m_usergroup ON M_UserM_UserGroupID = M_UserGroupID
left join m_staff on M_UserM_StaffID = M_StaffID
left join m_courier ON M_CourierM_StaffID = M_StaffID AND M_CourierIsActive = 'Y'
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['ip'] = $_SERVER['REMOTE_ADDR'];
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
if (isset($prm['M_SatelliteID'])) {
$user['M_SatelliteID'] = $prm['M_SatelliteID'];
} else {
$user['M_SatelliteID'] = 0;
}
$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(), M_UserActiveToken = '{$token}' WHERE M_UserID = ?
",array($user['M_UserID']));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$query = $this->db_onedev->query("INSERT INTO one_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'],'LOGIN','SUCCESS',$prm["username"]));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$query = $this->db_onedev->query("INSERT INTO one_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'),$this->input->ip_address(),'LOGIN','FAILED',$prm["username"]));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_error_db("Invalid UserName / Password");
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function logout()
{
$prm = $this->sys_input;
try
{
$query = $this->db_onedev->query("
UPDATE m_user
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
WHERE M_UserID = ?",
array($this->sys_user['M_UserID']));
if (!$query)
{
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->db_onedev->query("INSERT INTO one_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $this->sys_user['M_UserUsername']));
$this->sys_ok("OK");
}
catch(Exception $exc)
{
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}
?>

View File

@@ -0,0 +1,377 @@
<?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 Authv3 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, M_UserDefaultT_SampleStationID,
M_StaffName, 'N' as is_courier, M_UserM_ApproveLevelID,
IFNULL(S_SystemsAutoLogoutTime,0) as time_autologout
FROM m_user
JOIN m_usergroup ON M_UserM_UserGroupID = M_UserGroupID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
LEFT JOIN conf_systems ON S_SystemsIsActive = 'Y'
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;
}
// echo $this->db_onedev->last_query();
$rows = $query->result_array();
if (count($rows) > 0) {
$user = $rows[0];
$sql = "SELECT
M_UserLocationID,
M_UserLocationM_UserID,
M_UserLocationFlag,
M_UserLocationS_RegionalID,
M_UserLocationM_BranchID,
IFNULL(S_RegionalName, '') S_RegionalName,
IFNULL(S_RegionalID, '') S_RegionalID,
IFNULL(M_BranchName, '') M_BranchName,
IFNULL(M_BranchID, '0') M_BranchID,
IFNULL(M_BranchCode, '') M_BranchCode
FROM m_userlocation
LEFT JOIN s_regional ON M_UserLocationS_RegionalID = S_RegionalID
AND S_RegionalIsActive = 'Y'
LEFT JOIN m_branch ON M_UserLocationM_BranchID = M_BranchID
AND M_BranchIsActive = 'Y'
WHERE M_UserLocationM_UserID = ?
AND M_UserLocationIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, array($user['M_UserID']));
if (!$qry) {
$this->sys_error_db("Error get regional");
exit;
}
$userLocation = $qry->result_array();
if (count($userLocation) == 0) {
$this->sys_error('User belum disetting');
exit;
}
$location = $userLocation[0];
$user['M_UserLocationID'] = $location['M_UserLocationID'];
$user['M_UserLocationFlag'] = $location['M_UserLocationFlag'];
$user['S_RegionalName'] = $location['S_RegionalName'];
$user['S_RegionalID'] = $location['S_RegionalID'];
$user['M_BranchName'] = $location['M_BranchName'];
$user['M_BranchCode'] = $location['M_BranchCode'];
$user['M_BranchID'] = $location['M_BranchID'];
switch ($location['M_UserLocationFlag']) {
case 'P':
$user['S_RegionalName'] = '';
$user['S_RegionalID'] = 0;
$user['M_BranchName'] = '';
$user['M_BranchCode'] = '';
$user['M_BranchID'] = 0;
$user['loginLevel'] = 'pusat';
break;
case 'R':
if ($prm['branch'] != '0') {
$sql = "SELECT
M_BranchID as branchID,
M_BranchS_RegionalID as branchRegionalID,
M_BranchCode as branchCode ,
M_BranchName as branchName,
M_BranchCompanyDetailM_BranchCompanyID branchCompanyID
FROM m_branch JOIN m_branch_companydetail ON M_BranchCode = M_BranchCompanyDetailM_BranchCode
WHERE M_BranchS_RegionalID = ?
AND M_BranchCompanyDetailIsActive = 'Y'
AND M_BranchCompanyDetailM_BranchCompanyID = ?
AND M_BranchID = ?
AND M_BranchIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, array($prm['regional'], $prm['company'], $prm['branch']));
if (!$qry) {
$this->sys_error_db("Error get branch");
exit;
}
$result = $qry->result_array();
if (count($result) == 0) {
$this->sys_error('User regional tidak memiliki akses cabang yang dipilih');
exit;
}
$user['M_BranchName'] = $result[0]['branchName'];
$user['M_BranchCode'] = $result[0]['branchCode'];
$user['M_BranchID'] = $result[0]['branchID'];
}
$user['M_UserLocationFlag'] = 'R';
$user['loginLevel'] = 'regional';
break;
case 'B':
$user['loginLevel'] = 'branch';
if ($location['M_UserLocationM_BranchID'] != $prm['branch']) {
$this->sys_error('User tidak memiliki akses cabang yang dipilih');
exit;
}
break;
default:
$this->sys_error('User belum disetting');
exit;
}
$filterBranch = "";
if ($location['M_UserLocationFlag'] == 'B') {
$filterBranch = " AND M_BranchID = {$prm['branch']} ";
}
$sql = "SELECT
M_BranchCompanyID,
M_BranchCompanyName,
M_BranchCompanyDetailM_BranchCode,
M_branchName
FROM m_branch_company
JOIN m_branch_companydetail ON M_BranchCompanyID = M_BranchCompanyDetailM_BranchCompanyID
AND M_BranchCompanyDetailIsActive = 'Y'
JOIN m_branch ON M_BranchCompanyDetailM_BranchCode = M_BranchCode
AND M_BranchIsActive = 'Y'
AND M_BranchS_RegionalID = ?
$filterBranch
WHERE M_BranchCompanyID = ?
AND M_BranchCompanyDetailIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, array($prm['regional'], $prm['company']));
if (!$qry) {
$this->sys_error_db("Error get company access");
exit;
}
$branchCompany = $qry->result_array();
if (count($branchCompany) == 0) {
$this->sys_error_db("Company tidak memiliki akses ke cabang yang dipilih");
exit;
}
$company = $branchCompany[0];
$user['M_BranchCompanyID'] = $company['M_BranchCompanyID'];
$user['M_BranchCompanyName'] = $company['M_BranchCompanyName'];
$user['ip'] = $_SERVER['REMOTE_ADDR'];
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
//v2
$user['version'] = 'v2';
$user['last-login'] = date('Y-m-d H:i:s');
if (isset($prm['M_SatelliteID'])) {
$user['M_SatelliteID'] = $prm['M_SatelliteID'];
} else {
$user['M_SatelliteID'] = 0;
}
$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(),
M_UserActiveToken = '{$token}'
WHERE M_UserID = ?",
array($user['M_UserID'])
);
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$query = $this->db_onedev->query("INSERT INTO acc_one_log.log_login(
Log_LoginDateTime,
Log_LoginIP,
Log_LoginType,
Log_LoginStatus,
Log_LoginLogin
) VALUES (?,?,?,?,?)",
array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGIN', 'SUCCESS', $prm["username"])
);
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$query = $this->db_onedev->query("INSERT INTO acc_one_log.log_login(
Log_LoginDateTime,
Log_LoginIP,
Log_LoginType,
Log_LoginStatus,
Log_LoginLogin
) VALUES (?,?,?,?,?)",
array(date('Y-m-d H:i:s'), $this->input->ip_address(), 'LOGIN', 'FAILED', $prm["username"])
);
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_error_db("Invalid UserName / Password");
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function logout()
{
$prm = $this->sys_input;
try {
$query = $this->db_onedev->query(
"
UPDATE m_user
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
WHERE M_UserID = ?",
array($this->sys_user['M_UserID'])
);
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->db_onedev->query("INSERT INTO one_log.log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
", array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $this->sys_user['M_UserUsername']));
$this->sys_ok("OK");
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getRegional()
{
$prm = $this->sys_input;
try {
$sql = "SELECT
S_RegionalID regionalID,
S_RegionalName regionalName
FROM s_regional
WHERE S_RegionalIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, array());
if (!$qry) {
// $this->db->trans_rollback();
$this->sys_error_db("Error get regional");
exit;
}
$result = $qry->result_array();
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getBranch($regionalID, $companyID)
{
$prm = $this->sys_input;
try {
$sql = "SELECT
M_BranchID as branchID,
M_BranchS_RegionalID as branchRegionalID,
M_BranchCode as branchCode ,
M_BranchName as branchName,
M_BranchCompanyDetailM_BranchCompanyID branchCompanyID
FROM m_branch
JOIN m_branch_companydetail
ON M_BranchCode = M_BranchCompanyDetailM_BranchCode
WHERE M_BranchS_RegionalID = ?
AND M_BranchCompanyDetailIsActive = 'Y'
AND M_BranchCompanyDetailM_BranchCompanyID = ?
AND M_BranchIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, array($regionalID, $companyID));
if (!$qry) {
// $this->db->trans_rollback();
$this->sys_error_db("Error get branch");
exit;
}
$result = $qry->result_array();
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getCompany()
{
$prm = $this->sys_input;
try {
$sql = "SELECT
M_BranchCompanyID branchCompanyID,
M_BranchCompanyName branchCompanyName
FROM m_branch_company
WHERE M_BranchCompanyIsActive ='Y'";
$qry = $this->db_onedev->query($sql, array());
if (!$qry) {
// $this->db->trans_rollback();
$this->sys_error_db("Error get branch");
exit;
}
$result = $qry->result_array();
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,33 @@
<?php
class Genno extends MY_Controller {
var $db_onedev;
public function index()
{
$sql = "truncate noreg_prefix;";
$this->db_onedev->query($ql);
$sql = "insert into noreg_prefix(NoregPrefixYear,
NoregPrefixMonth, NoregPrefixCode )
values(?,?,?)";
$year = 2019;
$month = 12;
$xcode = 0;
for($i_y= $year ; $i_y < 2030 ; $i_y++ ) {
$s_month = 1;
if ($i_y == 2019 ) $s_month = 12;
for($i_x = $s_month; $i_x < 13; $i_x++) {
$scode = sprintf("%03d",$xcode);
$this->db_onedev->query($sql, array($i_y,$i_x, $scode));
if ($scode == "999") break;
$xcode++;
}
}
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
}
?>

View File

@@ -0,0 +1,46 @@
<?php
class Verify extends MY_Controller {
function __construct() {
parent::__construct();
}
function do() {
if ($this->isLogin === false ) {
echo json_encode(
array(
"status" => "Error",
"message" => "Unauthorized User"
));
exit;
}
$userID = $this->sys_user["M_UserID"];
$sql = "select count(*) total from m_user where M_UserID = ? and M_UserIsActive = 'Y'";
$qry = $this->db->query($sql,[$userID]);
if (!$qry) {
echo json_encode(
array(
"status" => "ERR",
"message" => "Error " . $this->db->error()['message']
)
);
exit;
}
$rows = $qry->result_array();
if(count($rows) == 0) {
echo json_encode(
array(
"status" => "ERR",
"message" => "Invalid User"
)
);
exit;
}
echo json_encode(
array(
"status" => "OK",
"message" => "Invalid User"
)
);
}
}
?>