isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = ""; if (isset($prm["search"])) { $search = trim($prm["search"]); if ($search != "") { $search = "%" . $prm["search"] . "%"; } else { $search = "%%"; } } $number_offset = 0; $number_limit = 10; if ($prm["current_page"] > 0) { $number_offset = ($prm["current_page"] - 1) * $number_limit; } $sql_filter = "SELECT count(*) as total FROM m_satuan WHERE M_SatuanIsActive = 'Y' AND M_SatuanName LIKE ? ORDER BY M_SatuanID"; $qry_filter = $this->db->query($sql_filter, [$search]); $tot_count = 0; $tot_page = 0; if ($qry_filter) { $tot_count = $qry_filter->result_array()[0]["total"]; $tot_page = ceil($tot_count / $number_limit); } else { $this->sys_error_db("count satuan error", $this->db); exit; } $sql = "SELECT M_SatuanID, M_SatuanName, '' as rownumber FROM m_satuan WHERE M_SatuanIsActive = 'Y' AND M_SatuanName LIKE ? ORDER BY M_SatuanID LIMIT ? OFFSET ?"; $qry = $this->db->query($sql, [$search, $number_limit, $number_offset]); if ($qry) { $rows = $qry->result_array(); } else { $this->sys_error_db("satuan error", $this->db); exit; } foreach ($rows as $k => $v) { $xno = ($k + 1) + $number_offset; $rows[$k]['rownumber'] = $xno; } $result = array( "total_page" => $tot_page, "total_filter" => $tot_count, "records" => $rows ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function addSatuan() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db->trans_begin(); $prm = $this->sys_input; $userid = $this->sys_user['M_UserID']; $name = ""; if (isset($prm["name"])) { $name = trim($prm["name"]); } $sql = "INSERT INTO m_satuan( M_SatuanName, M_SatuanIsActive, M_SatuanCreated, M_SatuanLastUpdated, M_SatuanM_UserID) VALUES(?,'Y',NOW(),NOW(),?)"; $qry = $this->db->query($sql, array($name, $userid)); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("save satuan error", $this->db); exit; } $this->db->trans_commit(); $result = array( "total" => 1, "affected_rows" => $this->db->affected_rows() ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function edit() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db->trans_begin(); $prm = $this->sys_input; $userid = $this->sys_user['M_UserID']; $name = ""; if (isset($prm["name"])) { $name = trim($prm["name"]); } $id = ""; if (isset($prm["id"])) { $id = trim($prm["id"]); } $sql = "UPDATE m_satuan SET M_SatuanName = ?, M_SatuanLastUpdated = NOW(), M_SatuanM_UserID = ? WHERE M_SatuanID = ?"; $qry = $this->db->query($sql, array($name, $userid, $id)); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("edit satuan error", $this->db); exit; } $this->db->trans_commit(); $result = array( "total" => 1, "affected_rows" => $this->db->affected_rows() ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function deleteRow() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db->trans_begin(); $prm = $this->sys_input; $userid = $this->sys_user['M_UserID']; $id = ""; if (isset($prm["id"])) { $id = trim($prm["id"]); } $sql = "UPDATE m_satuan SET M_SatuanIsActive = 'N', M_SatuanLastUpdated = NOW(), M_SatuanM_UserID = ? WHERE M_SatuanID = ?"; $qry = $this->db->query($sql, array($userid, $id)); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("delete satuan error", $this->db); exit; } $this->db->trans_commit(); $result = array( "total" => 1, "affected_rows" => $this->db->affected_rows() ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function searchConsumable() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = ""; if (isset($prm["search"])) { $search = trim($prm["search"]); if ($search != "") { $search = "%" . $prm["search"] . "%"; } else { $search = "%%"; } } $number_offset = 0; $number_limit = 10; if ($prm["current_page"] > 0) { $number_offset = ($prm["current_page"] - 1) * $number_limit; } $sql_filter = "SELECT count(*) as total FROM m_consumable LEFT JOIN m_satuan ON M_ConsumableDefaultM_SatuanID = M_SatuanID AND M_SatuanIsActive = 'Y' WHERE M_ConsumableIsActive = 'Y' AND (M_ConsumableCode LIKE ? OR M_ConsumableName LIKE ?) ORDER BY M_ConsumableName ASC"; $qry_filter = $this->db->query($sql_filter, array($search, $search)); $tot_count = 0; $tot_page = 0; if ($qry_filter) { $tot_count = $qry_filter->result_array()[0]["total"]; $tot_page = ceil($tot_count / $number_limit); } else { $this->sys_error_db("count item error", $this->db); exit; } $sql = "SELECT M_ConsumableID, M_ConsumableCode, M_ConsumableName, M_ConsumableDefaultM_SatuanID, M_ConsumableDefaultShow, M_ConsumableDefaultQty, M_SatuanName, '' as rownumber FROM m_consumable LEFT JOIN m_satuan ON M_ConsumableDefaultM_SatuanID = M_SatuanID AND M_SatuanIsActive = 'Y' WHERE M_ConsumableIsActive = 'Y' AND (M_ConsumableCode LIKE ? OR M_ConsumableName LIKE ?) ORDER BY M_ConsumableName ASC LIMIT ? OFFSET ?"; $qry = $this->db->query($sql, array($search, $search, $number_limit, $number_offset)); if ($qry) { $rows = $qry->result_array(); } else { $this->sys_error_db("select item error", $this->db); exit; } foreach ($rows as $k => $v) { $xno = ($k + 1) + $number_offset; $rows[$k]['rownumber'] = $xno; } $result = array( "total" => $tot_page, "total_display" => sizeof($rows), "records" => $rows ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function get_satuan() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT M_SatuanID, M_SatuanName FROM m_satuan WHERE M_SatuanIsActive = 'Y' ORDER BY M_SatuanName"; $qry = $this->db->query($sql); if ($qry) { $rows = $qry->result_array(); } else { $this->sys_error_db("select satuan error", $this->db); exit; } $result = array( "records" => $rows ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function addconsumable() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db->trans_begin(); $prm = $this->sys_input; $userid = $this->sys_user['M_UserID']; $code = ""; if (isset($prm["code"])) { $code = trim($prm["code"]); } $name = ""; if (isset($prm["name"])) { $name = trim($prm["name"]); } $satuanId = ""; if (isset($prm["satuanId"])) { $satuanId = trim($prm["satuanId"]); } $defaultShow = ""; if (isset($prm["defaultShow"])) { $defaultShow = trim($prm["defaultShow"]); } $defaultQty = ""; if (isset($prm["defaultQty"])) { $defaultQty = trim($prm["defaultQty"]); } $sql = "INSERT INTO m_consumable( M_ConsumableCode, M_ConsumableName, M_ConsumableDefaultM_SatuanID, M_ConsumableDefaultShow, M_ConsumableDefaultQty, M_ConsumableIsActive, M_ConsumableUserID, M_ConsumableCreated, M_ConsumableLastUpdated) VALUES(?,?,?,?,?,'Y',?,NOW(),NOW())"; $qry = $this->db->query($sql, array( $code, $name, $satuanId, $defaultShow, $defaultQty, $userid )); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("save item error", $this->db); exit; } $this->db->trans_commit(); $result = array( "total" => 1, "affected_rows" => $this->db->affected_rows() ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function editconsumable() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db->trans_begin(); $prm = $this->sys_input; $userid = $this->sys_user['M_UserID']; $id = ""; if (isset($prm["id"])) { $id = trim($prm["id"]); } $code = ""; if (isset($prm["code"])) { $code = trim($prm["code"]); } $name = ""; if (isset($prm["name"])) { $name = trim($prm["name"]); } $satuanId = ""; if (isset($prm["satuanId"])) { $satuanId = trim($prm["satuanId"]); } $defaultShow = ""; if (isset($prm["defaultShow"])) { $defaultShow = trim($prm["defaultShow"]); } $defaultQty = ""; if (isset($prm["defaultQty"])) { $defaultQty = trim($prm["defaultQty"]); } $sql = "UPDATE m_consumable SET M_ConsumableCode = ?, M_ConsumableName = ?, M_ConsumableDefaultM_SatuanID = ?, M_ConsumableDefaultShow = ?, M_ConsumableDefaultQty = ?, M_ConsumableUserID = ?, M_ConsumableLastUpdated = NOW() WHERE M_ConsumableID = ?"; $qry = $this->db->query($sql, array( $code, $name, $satuanId, $defaultShow, $defaultQty, $userid, $id )); if (!$qry) { $this->sys_error_db("update consumable error", $this->db); exit; } $this->db->trans_commit(); $result = array( "total" => 1, "affected_rows" => $this->db->affected_rows() ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function deleteitem() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db->trans_begin(); $prm = $this->sys_input; $userid = $this->sys_user['M_UserID']; $id = ""; if (isset($prm["id"])) { $id = trim($prm["id"]); } $sql = "UPDATE m_consumable SET M_ConsumableIsActive = 'N', M_ConsumableUserID = ?, M_ConsumableLastUpdated = NOW() WHERE M_ConsumableID = ?"; $qry = $this->db->query($sql, array($userid, $id)); if (!$qry) { $this->sys_error_db("delete item error", $this->db); exit; } $this->db->trans_commit(); $result = array( "total" => 1, "affected_rows" => $this->db->affected_rows() ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }