update / proses add akun pusat di media jurnal & move barcode to serah terima
This commit is contained in:
@@ -139,9 +139,7 @@ class Journalcashv2 extends MY_Controller
|
|||||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||||
WHERE $where_sql
|
WHERE $where_sql
|
||||||
GROUP BY jurnalID
|
GROUP BY jurnalID
|
||||||
ORDER BY jurnalID DESC
|
ORDER BY jurnalID DESC";
|
||||||
";
|
|
||||||
|
|
||||||
// Ambil total count
|
// Ambil total count
|
||||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||||
$qry_total = $this->db->query($sql_total, $params);
|
$qry_total = $this->db->query($sql_total, $params);
|
||||||
@@ -165,7 +163,6 @@ class Journalcashv2 extends MY_Controller
|
|||||||
// Tambahkan LIMIT OFFSET
|
// Tambahkan LIMIT OFFSET
|
||||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||||
|
|
||||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||||
|
|
||||||
if ($qry) {
|
if ($qry) {
|
||||||
@@ -276,12 +273,12 @@ class Journalcashv2 extends MY_Controller
|
|||||||
$regionalId = $prm["regionalId"] ?? null;
|
$regionalId = $prm["regionalId"] ?? null;
|
||||||
|
|
||||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||||
FROM s_regional
|
FROM s_regional
|
||||||
WHERE S_RegionalIsActive = 'Y'
|
WHERE S_RegionalIsActive = 'Y'
|
||||||
AND S_RegionalID = ?
|
AND (S_RegionalID = ? OR 0 = ?)
|
||||||
ORDER BY S_RegionalName ASC";
|
ORDER BY S_RegionalID ASC";
|
||||||
|
|
||||||
$qry = $this->db->query($sql, [$regionalId]);
|
$qry = $this->db->query($sql, [$regionalId, $regionalId]);
|
||||||
if (!$qry) {
|
if (!$qry) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("select regional", $this->db);
|
$this->sys_error_db("select regional", $this->db);
|
||||||
@@ -364,6 +361,7 @@ class Journalcashv2 extends MY_Controller
|
|||||||
$this->sys_error($message);
|
$this->sys_error($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserApproveLevel()
|
function getUserApproveLevel()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ class Journalgoodreceive extends MY_Controller
|
|||||||
periodeMonth,
|
periodeMonth,
|
||||||
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
CONCAT(periodeYear, ' - ',periodeMonth) as yearandmonth,
|
||||||
periodeName,
|
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
|
FROM periode
|
||||||
WHERE periodeIsActive = 'Y'
|
WHERE periodeIsActive = 'Y'
|
||||||
AND periodeIsClosed = 'N'
|
AND periodeIsClosed = 'N'
|
||||||
@@ -70,9 +72,9 @@ class Journalgoodreceive extends MY_Controller
|
|||||||
$prm = $this->sys_input;
|
$prm = $this->sys_input;
|
||||||
$user = $this->sys_user;
|
$user = $this->sys_user;
|
||||||
|
|
||||||
$regionalId = $prm["regionalId"] ?? $user["S_RegionalID"];
|
$regionalId = $prm["regionalId"];
|
||||||
$branchCode = $prm["branchCode"] == "" ? $user["M_BranchCode"] : $prm["branchCode"];
|
$branchCode = $prm["branchCode"];
|
||||||
$periodeid = $prm["periodeid"] ?? null;
|
$periodeid = $prm["periodeid"] ?? 0;
|
||||||
$xdate = $prm["xdate"] ?? null;
|
$xdate = $prm["xdate"] ?? null;
|
||||||
$search = $prm["search"] ?? "";
|
$search = $prm["search"] ?? "";
|
||||||
$search = "%" . trim($search) . "%";
|
$search = "%" . trim($search) . "%";
|
||||||
@@ -87,17 +89,33 @@ class Journalgoodreceive extends MY_Controller
|
|||||||
$params = [$periodeid, $xdate, $search];
|
$params = [$periodeid, $xdate, $search];
|
||||||
|
|
||||||
// Filter login level
|
// Filter login level
|
||||||
if ($loginLevel == "branch") {
|
switch ($loginLevel) {
|
||||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
case 'pusat':
|
||||||
$params[] = $branchCode;
|
$where_conditions[] = "(jurnalS_RegionalID = ? OR 0 = ?)";
|
||||||
} elseif ($loginLevel == "regional") {
|
$params[] = $regionalId;
|
||||||
$where_conditions[] = "jurnalS_RegionalID = ?";
|
$params[] = $regionalId;
|
||||||
$params[] = $regionalId;
|
|
||||||
|
|
||||||
if (!empty($branchCode)) {
|
if (!empty($branchCode)) {
|
||||||
|
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||||
|
$params[] = $branchCode;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'regional':
|
||||||
|
$where_conditions[] = "jurnalS_RegionalID = ?";
|
||||||
|
$params[] = $regionalId;
|
||||||
|
|
||||||
|
if (!empty($branchCode)) {
|
||||||
|
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||||
|
$params[] = $branchCode;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'branch':
|
||||||
$where_conditions[] = "jurnalM_BranchCode = ?";
|
$where_conditions[] = "jurnalM_BranchCode = ?";
|
||||||
$params[] = $branchCode;
|
$params[] = $branchCode;
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
|
$this->sys_error_db("user login level not found", $this->db);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gabungkan WHERE SQL
|
// Gabungkan WHERE SQL
|
||||||
@@ -131,16 +149,18 @@ class Journalgoodreceive extends MY_Controller
|
|||||||
'' as ErrMsg,
|
'' as ErrMsg,
|
||||||
'' as detailtx
|
'' as detailtx
|
||||||
FROM jurnal
|
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 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'
|
AND JurnalTypeCode = 'AUTOGOODRECEIVE'
|
||||||
JOIN s_regional ON JurnalS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
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'
|
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||||
WHERE $where_sql
|
WHERE $where_sql
|
||||||
GROUP BY jurnalID
|
GROUP BY jurnalID
|
||||||
ORDER BY jurnalID DESC
|
ORDER BY jurnalID DESC";
|
||||||
";
|
|
||||||
|
|
||||||
// Ambil total count
|
// Ambil total count
|
||||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
$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;
|
$totalCount = $qry_total->row()->total ?? 0;
|
||||||
$totalPage = ceil($totalCount / $number_limit);
|
$totalPage = ceil($totalCount / $number_limit);
|
||||||
} else {
|
} else {
|
||||||
$this->db->trans_rollback();
|
|
||||||
$this->sys_error_db("select jurnal count error", $this->db);
|
$this->sys_error_db("select jurnal count error", $this->db);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@@ -171,20 +190,18 @@ class Journalgoodreceive extends MY_Controller
|
|||||||
if ($qry) {
|
if ($qry) {
|
||||||
$rows = $qry->result_array();
|
$rows = $qry->result_array();
|
||||||
} else {
|
} else {
|
||||||
$this->db->trans_rollback();
|
|
||||||
$this->sys_error_db("select jurnal error", $this->db);
|
$this->sys_error_db("select jurnal error", $this->db);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($rows as $key => $value) {
|
foreach ($rows as $key => $value) {
|
||||||
$sql_err = "SELECT JurnalErr_ID,
|
$sql_err = "SELECT JurnalErr_ID,
|
||||||
JurnalErr_Msg
|
JurnalErr_Msg
|
||||||
FROM jurnal_errors
|
FROM jurnal_errors
|
||||||
WHERE JurnalErr_IsActive = 'Y'
|
WHERE JurnalErr_IsActive = 'Y'
|
||||||
AND JurnalErr_JurnalID = ?";
|
AND JurnalErr_JurnalID = ?";
|
||||||
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
$qry_err = $this->db->query($sql_err, [$value["jurnalID"]]);
|
||||||
if (!$qry_err) {
|
if (!$qry_err) {
|
||||||
$this->db->trans_rollback();
|
|
||||||
$this->sys_error_db("select jurnal msg error", $this->db);
|
$this->sys_error_db("select jurnal msg error", $this->db);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@@ -204,48 +221,43 @@ class Journalgoodreceive extends MY_Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql_detail = "SELECT
|
$sql_detail = "SELECT
|
||||||
jurnalTxID,
|
jurnalTxID,
|
||||||
jurnalTxJurnalID,
|
jurnalTxJurnalID,
|
||||||
jurnalTxCoaID,
|
jurnalTxCoaID,
|
||||||
jurnalTxDescription,
|
jurnalTxDescription,
|
||||||
jurnalTxDebit,
|
jurnalTxDebit,
|
||||||
jurnalTxCredit,
|
jurnalTxCredit,
|
||||||
coaID,
|
coaID,
|
||||||
coaAccountNo,
|
coaAccountNo,
|
||||||
coaDescription,
|
coaDescription,
|
||||||
coaSubDescription,
|
coaSubDescription,
|
||||||
coaAccountType,
|
coaAccountType,
|
||||||
coaIsInput,
|
coaIsInput,
|
||||||
coaReportSchedule,
|
coaReportSchedule,
|
||||||
coaCurrencyCode,
|
coaCurrencyCode,
|
||||||
coaCashFlowCategory,
|
coaCashFlowCategory,
|
||||||
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') AS jurnalAddOnCode,
|
GROUP_CONCAT(jurnalAddOnCode SEPARATOR ', ') AS jurnalAddOnCode,
|
||||||
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') AS jurnalAddOnValue,
|
GROUP_CONCAT(jurnalAddOnValue SEPARATOR ' | ') AS jurnalAddOnValue,
|
||||||
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
GROUP_CONCAT(M_ItemDesc SEPARATOR ', ') AS jurnalAddOnItem
|
||||||
FROM jurnal_tx
|
FROM jurnal_tx
|
||||||
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
JOIN coa ON jurnalTxCoaID = coaID AND coaIsActive = 'Y'
|
||||||
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
LEFT JOIN jurnal_addon ON jurnalTxID = jurnalAddOnJurnalTxID AND jurnalAddOnIsActive = 'Y'
|
||||||
-- AND (jurnalAddOnCode = 'RONUMB')
|
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
||||||
LEFT JOIN m_item ON M_ItemID = jurnalAddOnM_ItemID
|
WHERE jurnalTxIsActive = 'Y'
|
||||||
WHERE jurnalTxIsActive = 'Y'
|
AND jurnalTxJurnalID = ?
|
||||||
AND jurnalTxJurnalID = ?
|
GROUP BY jurnalTxID
|
||||||
GROUP BY jurnalTxID
|
ORDER BY
|
||||||
ORDER BY
|
CASE
|
||||||
CASE
|
WHEN jurnalTxDebit > 0 THEN 0
|
||||||
WHEN jurnalTxDebit > 0 THEN 0
|
ELSE 1
|
||||||
ELSE 1
|
END,
|
||||||
END,
|
jurnalTxID ASC";
|
||||||
jurnalTxID ASC";
|
|
||||||
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
$qry_detail = $this->db->query($sql_detail, [$value["jurnalID"]]);
|
||||||
if (!$qry_detail) {
|
if (!$qry_detail) {
|
||||||
$this->db->trans_rollback();
|
|
||||||
$this->sys_error_db("select jurnal tx error", $this->db);
|
$this->sys_error_db("select jurnal tx error", $this->db);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// echo $this->db->last_query();
|
|
||||||
// exit;
|
|
||||||
|
|
||||||
$rows_detail = $qry_detail->result_array();
|
$rows_detail = $qry_detail->result_array();
|
||||||
if (count($rows_detail) > 0) {
|
if (count($rows_detail) > 0) {
|
||||||
$rows[$key]["detailtx"] = $rows_detail;
|
$rows[$key]["detailtx"] = $rows_detail;
|
||||||
@@ -276,15 +288,15 @@ class Journalgoodreceive extends MY_Controller
|
|||||||
$this->sys_error("Invalid Token");
|
$this->sys_error("Invalid Token");
|
||||||
}
|
}
|
||||||
$prm = $this->sys_input;
|
$prm = $this->sys_input;
|
||||||
$regionalId = $prm["regionalId"] ?? null;
|
$regionalId = $prm["regionalId"] ?? 0;
|
||||||
|
|
||||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||||
FROM s_regional
|
FROM s_regional
|
||||||
WHERE S_RegionalIsActive = 'Y'
|
WHERE S_RegionalIsActive = 'Y'
|
||||||
AND S_RegionalID = ?
|
AND (S_RegionalID = ? OR 0 = ?)
|
||||||
ORDER BY S_RegionalName ASC";
|
ORDER BY S_RegionalName ASC";
|
||||||
|
|
||||||
$qry = $this->db->query($sql, [$regionalId]);
|
$qry = $this->db->query($sql, [$regionalId, $regionalId]);
|
||||||
if (!$qry) {
|
if (!$qry) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("select regional", $this->db);
|
$this->sys_error_db("select regional", $this->db);
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ class Mditem extends MY_Controller
|
|||||||
Fa_ClassID,
|
Fa_ClassID,
|
||||||
Fa_ClassName,
|
Fa_ClassName,
|
||||||
Fa_ClassFlagType,
|
Fa_ClassFlagType,
|
||||||
Fa_InventarisGolID,
|
M_InventarisGolID,
|
||||||
Fa_InventarisGolName,
|
M_InventarisGolName,
|
||||||
ItemUnitID,
|
ItemUnitID,
|
||||||
ItemUnitCode,
|
ItemUnitCode,
|
||||||
GROUP_CONCAT(ItemUnitName) as ItemUnitName,
|
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_group ON M_ItemNat_GroupID = Nat_GroupID
|
||||||
LEFT JOIN nat_subgroup ON M_ItemNat_SubGroupID = Nat_SubGroupID
|
LEFT JOIN nat_subgroup ON M_ItemNat_SubGroupID = Nat_SubGroupID
|
||||||
LEFT JOIN fa_class ON M_ItemFa_ClassID = Fa_ClassID
|
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
|
LEFT JOIN itemunitmap ON M_ItemID = ItemUnitMapM_ItemID
|
||||||
AND ItemUnitMapIsActive = 'Y'
|
AND ItemUnitMapIsActive = 'Y'
|
||||||
LEFT JOIN itemunit ON ItemUnitMapItemUnitID = ItemUnitID
|
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_group ON M_ItemNat_GroupID = Nat_GroupID
|
||||||
LEFT JOIN nat_subgroup ON M_ItemNat_SubGroupID = Nat_SubGroupID
|
LEFT JOIN nat_subgroup ON M_ItemNat_SubGroupID = Nat_SubGroupID
|
||||||
LEFT JOIN fa_class ON M_ItemFa_ClassID = Fa_ClassID
|
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
|
LEFT JOIN itemunitmap ON M_ItemID = ItemUnitMapM_ItemID
|
||||||
AND ItemUnitMapIsActive = 'Y'
|
AND ItemUnitMapIsActive = 'Y'
|
||||||
LEFT JOIN itemunit ON ItemUnitMapItemUnitID = ItemUnitID
|
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 {
|
try {
|
||||||
if (!$this->isLogin) {
|
if (!$this->isLogin) {
|
||||||
@@ -420,21 +420,20 @@ class Mditem extends MY_Controller
|
|||||||
$search = isset($prm["search"]) ? $prm["search"] : "";
|
$search = isset($prm["search"]) ? $prm["search"] : "";
|
||||||
|
|
||||||
$sql = "SELECT
|
$sql = "SELECT
|
||||||
Fa_InventarisGolID,
|
M_InventarisGolID,
|
||||||
Fa_InventarisGolName,
|
M_InventarisGolName,
|
||||||
Fa_InventarisGolCreated,
|
M_InventarisGolCreated,
|
||||||
Fa_InventarisGolLastUpdated,
|
M_InventarisGolLastUpdated,
|
||||||
Fa_InventarisGolIsActive,
|
M_InventarisGolIsActive,
|
||||||
Fa_InventarisGolUserID
|
M_InventarisGolUserID
|
||||||
FROM fa_inventaris_gol
|
FROM m_inventaris_gol
|
||||||
WHERE Fa_InventarisGolIsActive = 'Y'
|
WHERE M_InventarisGolIsActive = 'Y'
|
||||||
|
ORDER BY M_InventarisGolID DESC";
|
||||||
ORDER BY Fa_InventarisGolID DESC";
|
|
||||||
|
|
||||||
$query = $this->db->query($sql);
|
$query = $this->db->query($sql);
|
||||||
|
|
||||||
if (!$query) {
|
if (!$query) {
|
||||||
$this->sys_error_db("fa inventaris gol list", $this->db);
|
$this->sys_error_db("m inventaris gol list", $this->db);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ class Fakturv4 extends MY_Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!$this->isLogin) {
|
if (!$this->isLogin) {
|
||||||
$this->sys_error();
|
$this->sys_error("invalid token");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,31 +438,39 @@ class Fakturv4 extends MY_Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sqltal = "SELECT COUNT(*) as total
|
$sqltal = "SELECT COUNT(*) as total
|
||||||
FROM supplier_invoice
|
FROM supplier_invoice
|
||||||
JOIN supplier_invoice_detail ON SupplierInvoiceID = SupplierInvoiceDetailSupplierInvoiceID
|
JOIN supplier_invoice_detail ON SupplierInvoiceID = SupplierInvoiceDetailSupplierInvoiceID
|
||||||
JOIN receive_order_po ON SupplierInvoiceDetailReceiveOrderPoID = ReceiveOrderPoID
|
JOIN receive_order_po ON SupplierInvoiceDetailReceiveOrderPoID = ReceiveOrderPoID
|
||||||
JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
||||||
LEFT JOIN warehouse ON ReceiveOrderPoWarehouseID = WarehouseID
|
LEFT JOIN warehouse ON ReceiveOrderPoWarehouseID = WarehouseID
|
||||||
AND WarehouseM_BranchID = ?
|
AND WarehouseM_BranchID = ?
|
||||||
JOIN supplier ON SupplierID = SupplierInvoiceSupplierID
|
JOIN supplier ON SupplierID = SupplierInvoiceSupplierID
|
||||||
AND SupplierIsActive = 'Y'
|
AND SupplierIsActive = 'Y'
|
||||||
LEFT JOIN m_branch ON M_BranchID = WarehouseM_BranchID
|
LEFT JOIN m_branch ON M_BranchID = WarehouseM_BranchID
|
||||||
LEFT JOIN s_regional ON S_RegionalID = WarehouseS_RegionalID
|
LEFT JOIN s_regional ON S_RegionalID = WarehouseS_RegionalID
|
||||||
WHERE SupplierInvoiceIsActive = 'Y'
|
WHERE SupplierInvoiceIsActive = 'Y'
|
||||||
AND (
|
AND (
|
||||||
SupplierInvoiceNumber LIKE ? OR
|
SupplierInvoiceNumber LIKE ? OR
|
||||||
SupplierInvoiceDeliveryOrderNumber LIKE ? OR
|
SupplierInvoiceRefNumber LIKE ? OR
|
||||||
SupplierInvoiceSupplierInvoiceNumber LIKE ?
|
SupplierInvoiceSupplierInvoiceNumber LIKE ?
|
||||||
)
|
)
|
||||||
AND SupplierInvoiceDate >= DATE(?)
|
AND SupplierInvoiceDate >= DATE(?)
|
||||||
AND SupplierInvoiceDate <= DATE(?)
|
AND SupplierInvoiceDate <= DATE(?)
|
||||||
AND (? = 'All' OR SupplierInvoiceStatus = ?)
|
AND (? = 'All' OR SupplierInvoiceStatus = ?)
|
||||||
AND (? = '0' OR SupplierInvoiceSupplierID = ?)
|
AND (? = '0' OR SupplierInvoiceSupplierID = ?)
|
||||||
GROUP BY SupplierInvoiceID
|
GROUP BY SupplierInvoiceID
|
||||||
ORDER BY SUpplierInvoiceID DESC";
|
ORDER BY SUpplierInvoiceID DESC";
|
||||||
$quetal = $this->db->query($sqltal, [
|
$quetal = $this->db->query($sqltal, [
|
||||||
$branchID, $nomo, $nomo, $nomo, $date, $enddate,
|
$branchID,
|
||||||
$status, $status, $supplier, $supplier
|
$nomo,
|
||||||
|
$nomo,
|
||||||
|
$nomo,
|
||||||
|
$date,
|
||||||
|
$enddate,
|
||||||
|
$status,
|
||||||
|
$status,
|
||||||
|
$supplier,
|
||||||
|
$supplier
|
||||||
]);
|
]);
|
||||||
if (!$quetal) {
|
if (!$quetal) {
|
||||||
$this->sys_error_db("[Error] get total data faktur");
|
$this->sys_error_db("[Error] get total data faktur");
|
||||||
@@ -471,51 +479,60 @@ class Fakturv4 extends MY_Controller
|
|||||||
$total = $quetal->result_array()[0]['total'];
|
$total = $quetal->result_array()[0]['total'];
|
||||||
|
|
||||||
$sqlfak = "SELECT
|
$sqlfak = "SELECT
|
||||||
SupplierInvoiceID,
|
SupplierInvoiceID,
|
||||||
SupplierInvoiceNumber,
|
SupplierInvoiceNumber,
|
||||||
SupplierInvoiceDate,
|
SupplierInvoiceDate,
|
||||||
SupplierInvoiceDueDate,
|
SupplierInvoiceDueDate,
|
||||||
SupplierInvoiceDraftPaymentDate,
|
SupplierInvoiceDraftPaymentDate,
|
||||||
SupplierInvoiceSupplierID,
|
SupplierInvoiceSupplierID,
|
||||||
SupplierName,
|
SupplierName,
|
||||||
SupplierInvoiceStatus,
|
SupplierInvoiceStatus,
|
||||||
SupplierInvoiceNote,
|
SupplierInvoiceNote,
|
||||||
SupplierInvoiceGrandTotal,
|
SupplierInvoiceGrandTotal,
|
||||||
SupplierInvoiceSupplierInvoiceNumber,
|
SupplierInvoiceSupplierInvoiceNumber,
|
||||||
CASE
|
CASE
|
||||||
WHEN WarehouseType = 'B' THEN CONCAT(WarehouseCode,' ', WarehouseName, ' - ', M_BranchName)
|
WHEN WarehouseType = 'B' THEN CONCAT(WarehouseCode,' ', WarehouseName, ' - ', M_BranchName)
|
||||||
WHEN WarehouseType = 'R' THEN CONCAT(WarehouseCode,' ', WarehouseName, ' - ', S_RegionalName)
|
WHEN WarehouseType = 'R' THEN CONCAT(WarehouseCode,' ', WarehouseName, ' - ', S_RegionalName)
|
||||||
ELSE ''
|
ELSE ''
|
||||||
END as WarehouseName,
|
END as WarehouseName,
|
||||||
ReceiveOrderPoID,
|
ReceiveOrderPoID,
|
||||||
PurchaseOrderItemCategoryID
|
PurchaseOrderItemCategoryID
|
||||||
FROM supplier_invoice
|
FROM supplier_invoice
|
||||||
JOIN supplier_invoice_detail ON SupplierInvoiceID = SupplierInvoiceDetailSupplierInvoiceID
|
JOIN supplier_invoice_detail ON SupplierInvoiceID = SupplierInvoiceDetailSupplierInvoiceID
|
||||||
JOIN receive_order_po ON SupplierInvoiceDetailReceiveOrderPoID = ReceiveOrderPoID
|
JOIN receive_order_po ON SupplierInvoiceDetailReceiveOrderPoID = ReceiveOrderPoID
|
||||||
JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
||||||
LEFT JOIN warehouse ON ReceiveOrderPoWarehouseID = WarehouseID
|
LEFT JOIN warehouse ON ReceiveOrderPoWarehouseID = WarehouseID
|
||||||
AND WarehouseM_BranchID = ?
|
AND WarehouseM_BranchID = ?
|
||||||
JOIN supplier ON SupplierID = SupplierInvoiceSupplierID
|
JOIN supplier ON SupplierID = SupplierInvoiceSupplierID
|
||||||
AND SupplierIsActive = 'Y'
|
AND SupplierIsActive = 'Y'
|
||||||
LEFT JOIN m_branch ON M_BranchID = WarehouseM_BranchID
|
LEFT JOIN m_branch ON M_BranchID = WarehouseM_BranchID
|
||||||
LEFT JOIN s_regional ON S_RegionalID = WarehouseS_RegionalID
|
LEFT JOIN s_regional ON S_RegionalID = WarehouseS_RegionalID
|
||||||
WHERE SupplierInvoiceIsActive = 'Y'
|
WHERE SupplierInvoiceIsActive = 'Y'
|
||||||
AND (
|
AND (
|
||||||
SupplierInvoiceNumber LIKE ? OR
|
SupplierInvoiceNumber LIKE ? OR
|
||||||
SupplierInvoiceDeliveryOrderNumber LIKE ? OR
|
SupplierInvoiceRefNumber LIKE ? OR
|
||||||
SupplierInvoiceSupplierInvoiceNumber LIKE ?
|
SupplierInvoiceSupplierInvoiceNumber LIKE ?
|
||||||
)
|
)
|
||||||
AND SupplierInvoiceDate >= DATE(?)
|
AND SupplierInvoiceDate >= DATE(?)
|
||||||
AND SupplierInvoiceDate <= DATE(?)
|
AND SupplierInvoiceDate <= DATE(?)
|
||||||
AND (? = 'All' OR SupplierInvoiceStatus = ?)
|
AND (? = 'All' OR SupplierInvoiceStatus = ?)
|
||||||
AND (? = '0' OR SupplierInvoiceSupplierID = ?)
|
AND (? = '0' OR SupplierInvoiceSupplierID = ?)
|
||||||
GROUP BY SupplierInvoiceID
|
GROUP BY SupplierInvoiceID
|
||||||
ORDER BY SUpplierInvoiceID DESC
|
ORDER BY SUpplierInvoiceID DESC
|
||||||
LIMIT ? OFFSET ?";
|
LIMIT ? OFFSET ?";
|
||||||
$quefak = $this->db->query($sqlfak, [
|
$quefak = $this->db->query($sqlfak, [
|
||||||
$branchID, $nomo, $nomo, $nomo, $date, $enddate,
|
$branchID,
|
||||||
$status, $status, $supplier, $supplier,
|
$nomo,
|
||||||
$limit, $hal
|
$nomo,
|
||||||
|
$nomo,
|
||||||
|
$date,
|
||||||
|
$enddate,
|
||||||
|
$status,
|
||||||
|
$status,
|
||||||
|
$supplier,
|
||||||
|
$supplier,
|
||||||
|
$limit,
|
||||||
|
$hal
|
||||||
]);
|
]);
|
||||||
if (!$quefak) {
|
if (!$quefak) {
|
||||||
$this->sys_error_db("[Error] get list data faktur");
|
$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 {
|
try {
|
||||||
if (!$this->isLogin) {
|
if (!$this->isLogin) {
|
||||||
$this->sys_error("invalid token");
|
$this->sys_error("invalid token");
|
||||||
@@ -647,7 +665,7 @@ class Fakturv4 extends MY_Controller
|
|||||||
FROM receive_order_po_document
|
FROM receive_order_po_document
|
||||||
WHERE ReceiveOrderPoDocumentReceiveOrderPoID = ?
|
WHERE ReceiveOrderPoDocumentReceiveOrderPoID = ?
|
||||||
AND ReceiveOrderPoDocumentIsActive = 'Y'";
|
AND ReceiveOrderPoDocumentIsActive = 'Y'";
|
||||||
$que = $this->db->query($sql, [ $para['roID'] ]);
|
$que = $this->db->query($sql, [$para['roID']]);
|
||||||
if (!$que) {
|
if (!$que) {
|
||||||
$this->sys_error_db("[Error] failed get data attachment inventaris");
|
$this->sys_error_db("[Error] failed get data attachment inventaris");
|
||||||
exit;
|
exit;
|
||||||
@@ -657,7 +675,10 @@ class Fakturv4 extends MY_Controller
|
|||||||
foreach ($rows as $key => $value) {
|
foreach ($rows as $key => $value) {
|
||||||
$rows[$key]['category'] = $para['category'];
|
$rows[$key]['category'] = $para['category'];
|
||||||
}
|
}
|
||||||
$data[] = $rows;
|
|
||||||
|
if (count($rows) > 0) {
|
||||||
|
$data = $rows;
|
||||||
|
}
|
||||||
|
|
||||||
$this->sys_ok($data);
|
$this->sys_ok($data);
|
||||||
} catch (Exception $exc) {
|
} catch (Exception $exc) {
|
||||||
@@ -672,7 +693,7 @@ class Fakturv4 extends MY_Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!$this->isLogin) {
|
if (!$this->isLogin) {
|
||||||
$this->sys_error();
|
$this->sys_error("invalid token");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -847,7 +868,7 @@ class Fakturv4 extends MY_Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!$this->isLogin) {
|
if (!$this->isLogin) {
|
||||||
$this->sys_error();
|
$this->sys_error("invalid token");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
$para = $this->sys_input;
|
$para = $this->sys_input;
|
||||||
@@ -1538,38 +1559,29 @@ class Fakturv4 extends MY_Controller
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
} else if ($item['M_ItemItem_CategoryID'] == '2') {
|
} else if ($item['M_ItemItem_CategoryID'] == '2') {
|
||||||
// Mapping JurnalTx sama dengan Persediaan hanya beda CoA
|
if (empty($item['M_ItemM_InventarisGolID'])) {
|
||||||
// TODO: Update dengan CoA yang Benar
|
|
||||||
|
|
||||||
// Jika ItemNatsubGroup belum termapping return error
|
|
||||||
if (empty($item['M_ItemNat_SubGroupID'])) {
|
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] Item {$item['M_ItemDesc']} tidak memiliki Nat_SubGroupID");
|
$this->sys_error_db("[Error] item golongan inventaris belum ditentukan");
|
||||||
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");
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
$itemGroup = $quesgp->row_array();
|
|
||||||
|
|
||||||
if (
|
$sql_coainv = "SELECT
|
||||||
empty($itemGroup['MapNatGroup_Debt_coaID']) ||
|
CoaMapInventarisHutangCoaID,
|
||||||
empty($itemGroup['MapNatGroup_Debt_coaAccNo']) ||
|
CoaMapInventarisHutangCoaNo,
|
||||||
empty($itemGroup['MapNatGroup_Debt_coaDesc'])
|
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->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;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1581,8 +1593,8 @@ class Fakturv4 extends MY_Controller
|
|||||||
|
|
||||||
$status = $this->InsertJurnalTx(
|
$status = $this->InsertJurnalTx(
|
||||||
$jurnalID,
|
$jurnalID,
|
||||||
$itemGroup['MapNatGroup_Debt_coaID'],
|
$item_coainv['CoaMapInventarisHutangCoaID'],
|
||||||
$itemGroup['MapNatGroup_Debt_coaDesc'],
|
$item_coainv['CoaMapInventarisHutangCoaDesc'],
|
||||||
$user['M_UserID'],
|
$user['M_UserID'],
|
||||||
0,
|
0,
|
||||||
$kredit
|
$kredit
|
||||||
@@ -1626,57 +1638,7 @@ class Fakturv4 extends MY_Controller
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
} else if ($item['M_ItemItem_CategoryID'] == '4') {
|
} 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']);
|
$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
|
$sql_coa = "SELECT
|
||||||
JasaCoaMapHutangCoaID,
|
JasaCoaMapHutangCoaID,
|
||||||
JasaCoaMapHutangCoaNo,
|
JasaCoaMapHutangCoaNo,
|
||||||
@@ -1740,9 +1703,12 @@ class Fakturv4 extends MY_Controller
|
|||||||
$kredit = round($price + $taxPPN, 2);
|
$kredit = round($price + $taxPPN, 2);
|
||||||
|
|
||||||
$insert = $this->InsertJurnalTx(
|
$insert = $this->InsertJurnalTx(
|
||||||
$jurnalID, $coajasa['JasaCoaMapHutangCoaID'],
|
$jurnalID,
|
||||||
|
$coajasa['JasaCoaMapHutangCoaID'],
|
||||||
$coajasa['JasaCoaMapHutangCoaDesc'],
|
$coajasa['JasaCoaMapHutangCoaDesc'],
|
||||||
$userid, 0, $kredit
|
$userid,
|
||||||
|
0,
|
||||||
|
$kredit
|
||||||
);
|
);
|
||||||
if (!$insert) {
|
if (!$insert) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
|
|||||||
@@ -929,6 +929,11 @@ class PurchaseRequestNonPersediaan extends MY_Controller
|
|||||||
$params[] = $itemSubGroup;
|
$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[] = $itemCategory;
|
$params[] = $itemCategory;
|
||||||
$params[] = '%' . $search . '%';
|
$params[] = '%' . $search . '%';
|
||||||
@@ -938,22 +943,23 @@ class PurchaseRequestNonPersediaan extends MY_Controller
|
|||||||
|
|
||||||
|
|
||||||
$sql = "SELECT COUNT(*) as total FROM (
|
$sql = "SELECT COUNT(*) as total FROM (
|
||||||
SELECT
|
SELECT
|
||||||
DISTINCT M_ItemID
|
DISTINCT M_ItemID
|
||||||
FROM m_item
|
FROM m_item
|
||||||
JOIN itemunitmap ON ItemUnitMapM_ItemID = M_ItemID AND
|
JOIN itemunitmap ON ItemUnitMapM_ItemID = M_ItemID AND
|
||||||
((ItemUnitMapIsPurchase = 'Y' AND ? = 'purchase') OR
|
((ItemUnitMapIsPurchase = 'Y' AND ? = 'purchase') OR
|
||||||
(ItemUnitMapIsBase = 'Y' AND ? = 'base')) AND
|
(ItemUnitMapIsBase = 'Y' AND ? = 'base')) AND
|
||||||
ItemUnitMapIsActive = 'Y'
|
ItemUnitMapIsActive = 'Y'
|
||||||
JOIN itemunit ON ItemUnitID = ItemUnitMapItemUnitID AND
|
JOIN itemunit ON ItemUnitID = ItemUnitMapItemUnitID AND
|
||||||
ItemUnitIsActive = 'Y'
|
ItemUnitIsActive = 'Y'
|
||||||
$filterDivision
|
$filterDivision
|
||||||
$filterItemGroup
|
$filterItemGroup
|
||||||
$filterItemSubGroup
|
$filterItemSubGroup
|
||||||
WHERE M_ItemIsActive = 'Y' AND
|
$filterCoaInventaris
|
||||||
( M_ItemItem_CategoryID = ? OR ? = '' )
|
WHERE M_ItemIsActive = 'Y' AND
|
||||||
AND M_ItemDesc LIKE ?
|
( M_ItemItem_CategoryID = ? OR ? = '' )
|
||||||
) as item";
|
AND M_ItemDesc LIKE ?
|
||||||
|
) as item";
|
||||||
|
|
||||||
$query = $this->db->query($sql, $params);
|
$query = $this->db->query($sql, $params);
|
||||||
if (!$query) {
|
if (!$query) {
|
||||||
@@ -981,20 +987,21 @@ class PurchaseRequestNonPersediaan extends MY_Controller
|
|||||||
'N' as isEditingPrice,
|
'N' as isEditingPrice,
|
||||||
0 as remaining_stock
|
0 as remaining_stock
|
||||||
FROM m_item
|
FROM m_item
|
||||||
JOIN itemunitmap ON ItemUnitMapM_ItemID = M_ItemID AND
|
JOIN itemunitmap ON ItemUnitMapM_ItemID = M_ItemID
|
||||||
((ItemUnitMapIsPurchase = 'Y' AND ? = 'purchase') OR
|
AND ((ItemUnitMapIsPurchase = 'Y' AND ? = 'purchase') OR
|
||||||
(ItemUnitMapIsBase = 'Y' AND ? = 'base')) AND
|
(ItemUnitMapIsBase = 'Y' AND ? = 'base'))
|
||||||
ItemUnitMapIsActive = 'Y'
|
AND ItemUnitMapIsActive = 'Y'
|
||||||
JOIN itemunit ON ItemUnitID = ItemUnitMapItemUnitID AND
|
JOIN itemunit ON ItemUnitID = ItemUnitMapItemUnitID
|
||||||
ItemUnitIsActive = 'Y'
|
AND ItemUnitIsActive = 'Y'
|
||||||
$filterDivision
|
$filterDivision
|
||||||
$filterItemGroup
|
$filterItemGroup
|
||||||
$filterItemSubGroup
|
$filterItemSubGroup
|
||||||
WHERE M_ItemIsActive = 'Y' AND
|
$filterCoaInventaris
|
||||||
( M_ItemItem_CategoryID = ? OR ? = '' )
|
WHERE M_ItemIsActive = 'Y'
|
||||||
|
AND ( M_ItemItem_CategoryID = ? OR ? = '' )
|
||||||
AND M_ItemDesc LIKE ?
|
AND M_ItemDesc LIKE ?
|
||||||
ORDER BY M_ItemDesc ASC
|
ORDER BY M_ItemDesc ASC
|
||||||
LIMIT ? OFFSET ?";
|
LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
// Parameter akhir yang digunakan untuk query
|
// Parameter akhir yang digunakan untuk query
|
||||||
$searchParam = $params;
|
$searchParam = $params;
|
||||||
|
|||||||
@@ -62,13 +62,13 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
$search = $payload['search'] . '%';
|
$search = $payload['search'] . '%';
|
||||||
|
|
||||||
$sql = "SELECT M_RuanganID,
|
$sql = "SELECT M_RuanganID,
|
||||||
M_RuanganM_BranchID,
|
M_RuanganM_BranchID,
|
||||||
M_RuanganName,
|
M_RuanganName,
|
||||||
M_RuanganCode
|
M_RuanganCode
|
||||||
FROM m_ruangan
|
FROM m_ruangan
|
||||||
WHERE M_RuanganIsActive = 'Y'
|
WHERE M_RuanganIsActive = 'Y'
|
||||||
AND M_RuanganM_BranchID = ?
|
AND M_RuanganM_BranchID = ?
|
||||||
AND M_RuanganName LIKE ?
|
AND M_RuanganName LIKE ?
|
||||||
ORDER BY M_RuanganName ASC";
|
ORDER BY M_RuanganName ASC";
|
||||||
$qry = $this->db->query($sql, [$user['M_BranchID'], $search]);
|
$qry = $this->db->query($sql, [$user['M_BranchID'], $search]);
|
||||||
|
|
||||||
@@ -630,37 +630,39 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
$user = $this->sys_user;
|
$user = $this->sys_user;
|
||||||
$param = $this->sys_input;
|
$param = $this->sys_input;
|
||||||
|
|
||||||
// $sql = "SELECT DISTINCT
|
if ($param['isSerahTerima'] == 'Y') {
|
||||||
// u.M_UserID,
|
$sql = "SELECT DISTINCT
|
||||||
// u.M_UserUsername
|
u.M_UserID,
|
||||||
// FROM receive_order_po ro
|
u.M_UserUsername
|
||||||
// JOIN receive_order_po_detail rod
|
FROM receive_order_po ro
|
||||||
// ON rod.ReceiveOrderPoDetailReceiveOrderPoID = ro.ReceiveOrderPoID
|
JOIN receive_order_po_detail rod
|
||||||
// AND rod.ReceiveOrderPoDetailIsActive = 'Y'
|
ON rod.ReceiveOrderPoDetailReceiveOrderPoID = ro.ReceiveOrderPoID
|
||||||
// JOIN purchase_order_detail pod
|
AND rod.ReceiveOrderPoDetailIsActive = 'Y'
|
||||||
// ON pod.PurchaseOrderDetailID = rod.ReceiveOrderPoDetailPurchaseOrderDetailID
|
JOIN purchase_order_detail pod
|
||||||
// AND pod.PurchaseOrderDetailIsActive = 'Y'
|
ON pod.PurchaseOrderDetailID = rod.ReceiveOrderPoDetailPurchaseOrderDetailID
|
||||||
// JOIN purchase_request pr
|
AND pod.PurchaseOrderDetailIsActive = 'Y'
|
||||||
// ON pr.PurchaseRequestID = pod.PurchaseOrderDetailPurchaseRequestID
|
JOIN purchase_request pr
|
||||||
// AND pr.PurchaseRequestIsActive = 'Y'
|
ON pr.PurchaseRequestID = pod.PurchaseOrderDetailPurchaseRequestID
|
||||||
// JOIN m_user u
|
AND pr.PurchaseRequestIsActive = 'Y'
|
||||||
// ON u.M_UserID = pr.PurchaseRequestRequestedBy
|
JOIN m_user u
|
||||||
// AND u.M_UserIsActive = 'Y'
|
ON u.M_UserID = pr.PurchaseRequestRequestedBy
|
||||||
// WHERE
|
AND u.M_UserIsActive = 'Y'
|
||||||
// ro.ReceiveOrderPoID = ?
|
WHERE
|
||||||
// AND ro.ReceiveOrderPoIsActive = 'Y'";
|
ro.ReceiveOrderPoID = ?
|
||||||
// $que = $this->db->query($sql, [$param['ROID']]);
|
AND ro.ReceiveOrderPoIsActive = 'Y'";
|
||||||
//
|
$que = $this->db->query($sql, [$param['ROID']]);
|
||||||
|
} else {
|
||||||
|
$sql = "SELECT
|
||||||
|
M_UserID,
|
||||||
|
M_UserUsername
|
||||||
|
FROM m_user
|
||||||
|
WHERE M_UserM_BranchID = ?
|
||||||
|
AND M_UserS_RegionalID = ?
|
||||||
|
AND M_UserIsActive = 'Y'
|
||||||
|
ORDER BY M_UserUsername";
|
||||||
|
$que = $this->db->query($sql, [$user['M_BranchID'], $user['S_RegionalID']]);
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "SELECT
|
|
||||||
M_UserID,
|
|
||||||
M_UserUsername
|
|
||||||
FROM m_user
|
|
||||||
WHERE M_UserM_BranchID = ?
|
|
||||||
AND M_UserS_RegionalID = ?
|
|
||||||
AND M_UserIsActive = 'Y'
|
|
||||||
ORDER BY M_UserUsername";
|
|
||||||
$que = $this->db->query($sql, [$user['M_BranchID'], $user['S_RegionalID']]);
|
|
||||||
if (!$que) {
|
if (!$que) {
|
||||||
$this->sys_error_db("[Error] get staff");
|
$this->sys_error_db("[Error] get staff");
|
||||||
exit;
|
exit;
|
||||||
@@ -926,42 +928,42 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
|
|
||||||
$RODetailID = $this->db->insert_id();
|
$RODetailID = $this->db->insert_id();
|
||||||
|
|
||||||
if (intval($obj['qty']) > 0) {
|
// if (intval($obj['qty']) > 0) {
|
||||||
$qty = intval($obj['qty']);
|
// $qty = intval($obj['qty']);
|
||||||
for ($i = 0; $i < $qty; $i++) {
|
// for ($i = 0; $i < $qty; $i++) {
|
||||||
# generate nomor barcode #
|
// # generate nomor barcode #
|
||||||
$noBarcode = $this->generateNoBarcode($user, $param['lokasiID'], 'BNP', $obj['M_ItemID']);
|
// $noBarcode = $this->generateNoBarcode($user, $param['lokasiID'], 'BNP', $obj['M_ItemID']);
|
||||||
|
|
||||||
# INSERT INTO t_barcode_barang #
|
// # INSERT INTO t_barcode_barang #
|
||||||
$sqlInsertBarcode = "INSERT INTO t_barcode_barang(
|
// $sqlInsertBarcode = "INSERT INTO t_barcode_barang(
|
||||||
T_BarcodeBarangReceiveOrderPoID,
|
// T_BarcodeBarangReceiveOrderPoID,
|
||||||
T_BarcodeBarangReceiveOrderPoDetailID,
|
// T_BarcodeBarangReceiveOrderPoDetailID,
|
||||||
T_BarcodeBarangRefType,
|
// T_BarcodeBarangRefType,
|
||||||
T_BarcodeBarangM_ItemID,
|
// T_BarcodeBarangM_ItemID,
|
||||||
T_BarcodeBarangItemUnitID,
|
// T_BarcodeBarangItemUnitID,
|
||||||
T_BarcodeBarangNumber,
|
// T_BarcodeBarangNumber,
|
||||||
T_BarcodeBarangM_RuanganID,
|
// T_BarcodeBarangM_RuanganID,
|
||||||
T_BarcodeBarangM_BranchID,
|
// T_BarcodeBarangM_BranchID,
|
||||||
T_BarcodeBarangIsActive,
|
// T_BarcodeBarangIsActive,
|
||||||
T_BarcodeBarangUserID,
|
// T_BarcodeBarangUserID,
|
||||||
T_BarcodeBarangCreated) VALUES(?,?,'PO',?,?,?,?,?,'Y',?,NOW())";
|
// T_BarcodeBarangCreated) VALUES(?,?,'PO',?,?,?,?,?,'Y',?,NOW())";
|
||||||
$qryInsertBarcode = $this->db->query($sqlInsertBarcode, array(
|
// $qryInsertBarcode = $this->db->query($sqlInsertBarcode, array(
|
||||||
$roID,
|
// $roID,
|
||||||
$RODetailID,
|
// $RODetailID,
|
||||||
$obj['M_ItemID'],
|
// $obj['M_ItemID'],
|
||||||
$obj['ItemUnitID'],
|
// $obj['ItemUnitID'],
|
||||||
$noBarcode,
|
// $noBarcode,
|
||||||
$param['lokasiID'],
|
// $param['lokasiID'],
|
||||||
$user['M_BranchID'],
|
// $user['M_BranchID'],
|
||||||
$user['M_UserID']
|
// $user['M_UserID']
|
||||||
));
|
// ));
|
||||||
if (!$qryInsertBarcode) {
|
// if (!$qryInsertBarcode) {
|
||||||
$this->db->trans_rollback();
|
// $this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] insert data barcode item");
|
// $this->sys_error_db("[Error] insert data barcode item");
|
||||||
exit;
|
// exit;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
# INSERT INTO receive_order_po_inspeksi #
|
# INSERT INTO receive_order_po_inspeksi #
|
||||||
$inspeksi = $obj['inspeksi_item'];
|
$inspeksi = $obj['inspeksi_item'];
|
||||||
@@ -1770,34 +1772,31 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
|
|
||||||
# INSERT JURNAL TX #
|
# INSERT JURNAL TX #
|
||||||
if (intval($item_cek['M_ItemItem_CategoryID']) == 2) {
|
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->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']}");
|
{$detail['PurchaseOrderNumber']}");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql_item_group = "SELECT * FROM map_nat_subgroup
|
$sql_coa_inv = "SELECT
|
||||||
WHERE MapNatSub_NatGroupID = ?
|
CoaMapInventarisCoaID,
|
||||||
AND MapNatSub_NatSubGroupID = ?
|
CoaMapInventarisCoaNo,
|
||||||
AND MapNatSub_IsActive = 'Y'";
|
CoaMapInventarisCoaDesc
|
||||||
$que_item_group = $this->db->query($sql_item_group, [
|
FROM coa_map_inventaris
|
||||||
$item_cek['M_ItemNat_GroupID'],
|
WHERE CoaMapInventarisM_InventarisGolID = ?
|
||||||
$item_cek['M_ItemNat_SubGroupID']
|
AND CoaMapInventarisIsActive = 'Y'";
|
||||||
]);
|
$que_coa_inv = $this->db->query($sql_coa_inv, [$item_cek['M_ItemM_InventarisGolID']]);
|
||||||
if (!$que_item_group) {
|
if (!$que_coa_inv) {
|
||||||
$this->db->trans_rollback();
|
$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;
|
exit;
|
||||||
}
|
}
|
||||||
$item_group = $que_item_group->row_array();
|
$iteminv_coa = $que_coa_inv->row_array();
|
||||||
if (
|
|
||||||
empty($item_group['MapNatSub_BiayaCoaID']) ||
|
if (empty($iteminv_coa['CoaMapInventarisCoaID'])) {
|
||||||
empty($item_group['MapNatSub_BiayaCoaAccountNo']) ||
|
|
||||||
empty($item_group['MapNatSub_BiayaCoaDescription'])
|
|
||||||
) {
|
|
||||||
$this->db->trans_rollback();
|
$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;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1815,8 +1814,8 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
) VALUES (?,?,?,?,?,?)";
|
) VALUES (?,?,?,?,?,?)";
|
||||||
$que_tx_jurnal = $this->db->query($sql_tx_jurnal, [
|
$que_tx_jurnal = $this->db->query($sql_tx_jurnal, [
|
||||||
$jurnal_ID,
|
$jurnal_ID,
|
||||||
$item_group['MapNatSub_BiayaCoaID'],
|
$iteminv_coa['CoaMapInventarisCoaID'],
|
||||||
$item_group['MapNatSub_BiayaCoaDescription'],
|
$iteminv_coa['CoaMapInventarisCoaDesc'],
|
||||||
$debet,
|
$debet,
|
||||||
0,
|
0,
|
||||||
$user['M_UserID']
|
$user['M_UserID']
|
||||||
@@ -1829,7 +1828,7 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
}
|
}
|
||||||
$juranl_tx_ID = $this->db->insert_id();
|
$juranl_tx_ID = $this->db->insert_id();
|
||||||
$each_desc[] = "- Add detail Jurnal debet {$item_cek['M_ItemDesc']}
|
$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 #
|
# INSERT JURNAL ADDON #
|
||||||
$sql_addon_jurnal = "INSERT INTO jurnal_addon (
|
$sql_addon_jurnal = "INSERT INTO jurnal_addon (
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
152
application/controllers/v1/system/Auth.php
Normal file
152
application/controllers/v1/system/Auth.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
171
application/controllers/v1/system/Authv2.php
Normal file
171
application/controllers/v1/system/Authv2.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
377
application/controllers/v1/system/Authv3.php
Normal file
377
application/controllers/v1/system/Authv3.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
application/controllers/v1/system/Genno.php
Normal file
33
application/controllers/v1/system/Genno.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
46
application/controllers/v1/system/Verify.php
Normal file
46
application/controllers/v1/system/Verify.php
Normal 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"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user