Batch 6a: application controllers base
This commit is contained in:
990
application/controllers/training/Report.php
Normal file
990
application/controllers/training/Report.php
Normal file
@@ -0,0 +1,990 @@
|
||||
<?php
|
||||
class Report extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "API : TAMBAH REPORT";
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
}
|
||||
|
||||
// report group
|
||||
function searchgroup()
|
||||
{
|
||||
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 r_reportgroup
|
||||
WHERE R_ReportGroupIsActive = 'Y'
|
||||
AND (R_ReportGroupCode LIKE ? OR R_ReportGroupName LIKE ?)
|
||||
ORDER BY R_ReportGroupID";
|
||||
|
||||
$qry_filter = $this->db->query($sql_filter, [$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("report group count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT R_ReportGroupID,
|
||||
R_ReportGroupCode,
|
||||
R_ReportGroupName,
|
||||
R_ReportGroupColor
|
||||
FROM r_reportgroup
|
||||
WHERE R_ReportGroupIsActive = 'Y'
|
||||
AND (R_ReportGroupCode LIKE ? OR R_ReportGroupName LIKE ?)
|
||||
ORDER BY R_ReportGroupID
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$qry = $this->db->query($sql, [$search, $search, $number_limit, $number_offset]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("report group error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$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 addgroup()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$code = "";
|
||||
if (isset($prm["code"])) {
|
||||
$code = trim($prm["code"]);
|
||||
}
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$color = "";
|
||||
if (isset($prm["color"])) {
|
||||
$color = trim($prm["color"]);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO r_reportgroup(
|
||||
R_ReportGroupCode,
|
||||
R_ReportGroupName,
|
||||
R_ReportGroupCreated,
|
||||
R_ReportGroupLastUpdated,
|
||||
R_ReportGroupIsActive,
|
||||
R_ReportGroupColor
|
||||
) VALUES(?,?,NOW(),NOW(),'Y',?)";
|
||||
|
||||
$qry = $this->db->query($sql, array($code, $name, $color));
|
||||
// $last_qry = $this->db->last_query();
|
||||
// print_r($last_qry);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("save report group 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 editgroup()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$code = "";
|
||||
if (isset($prm["code"])) {
|
||||
$code = trim($prm["code"]);
|
||||
}
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$color = "";
|
||||
if (isset($prm["color"])) {
|
||||
$color = trim($prm["color"]);
|
||||
}
|
||||
$id = "";
|
||||
if (isset($prm['id'])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
|
||||
$sql = "UPDATE r_reportgroup
|
||||
SET R_ReportGroupCode = ?,
|
||||
R_ReportGroupName = ?,
|
||||
R_ReportGroupLastUpdated = NOW(),
|
||||
R_ReportGroupColor = ?
|
||||
WHERE R_ReportGroupID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($code, $name, $color, $id));
|
||||
// $last_qry = $this->db->last_query();
|
||||
// print_r($last_qry);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update report group 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 deletegroup()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$id = "";
|
||||
if (isset($prm['id'])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
|
||||
$sql_delete = "UPDATE r_reportgroup
|
||||
SET R_ReportGroupLastUpdated = NOW(),
|
||||
R_ReportGroupIsActive = 'N'
|
||||
WHERE R_ReportGroupID = ?";
|
||||
$qry_delete = $this->db->query($sql_delete, $id);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_delete) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// reports
|
||||
function searchreports()
|
||||
{
|
||||
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 = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$reportgroup_id = "";
|
||||
if (isset($prm['reportgroup_id'])) {
|
||||
$reportgroup_id = trim($prm["reportgroup_id"]);
|
||||
}
|
||||
|
||||
$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 r_report
|
||||
JOIN r_reportgroup
|
||||
ON R_ReportR_ReportGroupID = R_ReportGroupID
|
||||
AND R_ReportGroupID = ?
|
||||
WHERE R_ReportIsActive = 'Y'
|
||||
AND (R_ReportCode LIKE ? OR R_ReportName LIKE ?)
|
||||
ORDER BY R_ReportID";
|
||||
|
||||
$qry_filter = $this->db->query($sql_filter, array($reportgroup_id, $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("reports count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT R_ReportID,
|
||||
R_ReportR_ReportGroupID as reportgroupID,
|
||||
R_ReportCode,
|
||||
R_ReportUrl,
|
||||
R_ReportName
|
||||
FROM r_report
|
||||
JOIN r_reportgroup
|
||||
ON R_ReportR_ReportGroupID = R_ReportGroupID
|
||||
AND R_ReportGroupID = ?
|
||||
WHERE R_ReportIsActive = 'Y'
|
||||
AND (R_ReportCode LIKE ? OR R_ReportName LIKE ?)
|
||||
ORDER BY R_ReportID
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($reportgroup_id, $search, $search, $number_limit, $number_offset));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("reports select error", $this->db);
|
||||
}
|
||||
|
||||
$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 get_reportgroup()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT R_ReportGroupID as reportgroupid,
|
||||
R_ReportGroupCode,
|
||||
R_ReportGroupName,
|
||||
R_ReportGroupColor
|
||||
FROM r_reportgroup
|
||||
WHERE R_ReportGroupIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function addreport()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$code = "";
|
||||
if (isset($prm["code"])) {
|
||||
$code = trim($prm["code"]);
|
||||
}
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$url = "";
|
||||
if (isset($prm["url"])) {
|
||||
$url = trim($prm["url"]);
|
||||
}
|
||||
$reportgroupid = "";
|
||||
if (isset($prm["reportgroupid"])) {
|
||||
$reportgroupid = trim($prm["reportgroupid"]);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO r_report(
|
||||
R_ReportR_ReportGroupID,
|
||||
R_ReportCode,
|
||||
R_ReportName,
|
||||
R_ReportUrl,
|
||||
R_ReportCreated,
|
||||
R_ReportLastUpdated,
|
||||
R_ReportIsActive
|
||||
) VALUES(?,?,?,?,NOW(),NOW(),'Y')";
|
||||
|
||||
$qry = $this->db->query($sql, array(
|
||||
$reportgroupid,
|
||||
$code,
|
||||
$name,
|
||||
$url
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("save reports 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 editreport()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$code = "";
|
||||
if (isset($prm["code"])) {
|
||||
$code = trim($prm["code"]);
|
||||
}
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$url = "";
|
||||
if (isset($prm["url"])) {
|
||||
$url = trim($prm["url"]);
|
||||
}
|
||||
$reportgroupid = "";
|
||||
if (isset($prm["reportgroupid"])) {
|
||||
$reportgroupid = trim($prm["reportgroupid"]);
|
||||
}
|
||||
$id = "";
|
||||
if (isset($prm["id"])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
|
||||
$sql = "UPDATE r_report
|
||||
SET R_ReportR_ReportGroupID = ?,
|
||||
R_ReportCode = ?,
|
||||
R_ReportName = ?,
|
||||
R_ReportUrl = ?,
|
||||
R_ReportLastUpdated = NOW()
|
||||
WHERE R_ReportID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($reportgroupid, $code, $name, $url, $id));
|
||||
// $last_qry = $this->db->last_query();
|
||||
// print_r($last_qry);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update reports 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 deletereport()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$id = "";
|
||||
if (isset($prm['id'])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
|
||||
$sql_delete = "UPDATE r_report
|
||||
SET R_ReportLastUpdated = NOW(),
|
||||
R_ReportIsActive = 'N'
|
||||
WHERE R_ReportID = ?";
|
||||
$qry_delete = $this->db->query($sql_delete, $id);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_delete) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
// Report parameter
|
||||
function searchparam()
|
||||
{
|
||||
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 = "%%";
|
||||
}
|
||||
}
|
||||
|
||||
$report_id = "";
|
||||
if (isset($prm['report_id'])) {
|
||||
$report_id = trim($prm["report_id"]);
|
||||
}
|
||||
|
||||
$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 r_reportdetail
|
||||
JOIN r_report
|
||||
ON R_ReportDetailR_ReportID = R_ReportID
|
||||
AND R_ReportID = ?
|
||||
AND R_ReportIsActive = 'Y'
|
||||
WHERE R_ReportDetailIsActive = 'Y'
|
||||
AND (R_ReportDetailName LIKE ? OR R_ReportDetailParam LIKE ?)
|
||||
ORDER BY R_ReportDetailID";
|
||||
|
||||
$qry_filter = $this->db->query($sql_filter, array($report_id, $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("report parameter count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT R_ReportDetailID,
|
||||
R_ReportID,
|
||||
R_ReportName,
|
||||
R_ReportDetailName,
|
||||
R_ReportDetailLabel,
|
||||
R_ReportDetailParam,
|
||||
R_ReportDetailDepParam,
|
||||
R_ReportDetailSourceSp,
|
||||
R_ReportDetailSourceUrl,
|
||||
R_ReportDetailR_InputTypeID as inputypeID,
|
||||
R_ReportDetailPriority,
|
||||
R_InputTypeName
|
||||
FROM r_reportdetail
|
||||
JOIN r_report
|
||||
ON R_ReportDetailR_ReportID = R_ReportID
|
||||
AND R_ReportID = ?
|
||||
AND R_ReportIsActive = 'Y'
|
||||
JOIN r_inputtype ON R_ReportDetailR_InputTypeID = R_InputTypeID
|
||||
AND R_InputTypeIsActive = 'Y'
|
||||
WHERE R_ReportDetailIsActive = 'Y'
|
||||
AND (R_ReportDetailName LIKE ? OR R_ReportDetailParam LIKE ?)
|
||||
ORDER BY R_ReportDetailID LIMIT ? OFFSET ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($report_id, $search, $search, $number_limit, $number_offset));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("report parameter select error", $this->db);
|
||||
}
|
||||
|
||||
$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 get_reports()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$reportid = "";
|
||||
if (isset($prm["reportid"])) {
|
||||
$reportid = trim($prm["reportid"]);
|
||||
}
|
||||
|
||||
$sql = "SELECT DISTINCT R_ReportID,
|
||||
R_ReportCode,
|
||||
R_ReportName
|
||||
FROM r_report
|
||||
WHERE R_ReportIsActive = 'Y'
|
||||
AND R_ReportID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, [$reportid]);
|
||||
// $last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reports select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function get_reportsold()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
$reportid = "";
|
||||
if (isset($prm["reportid"])) {
|
||||
$reportid = trim($prm["reportid"]);
|
||||
}
|
||||
|
||||
$sql = "SELECT DISTINCT R_ReportID,
|
||||
R_ReportCode,
|
||||
R_ReportName
|
||||
FROM r_report
|
||||
WHERE R_ReportIsActive = 'Y'
|
||||
AND R_ReportID = ?
|
||||
AND (
|
||||
R_ReportName LIKE ?
|
||||
) LIMIT ?";
|
||||
|
||||
$qry = $this->db->query($sql, [$reportid, $search, $number_limit]);
|
||||
// $last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reports select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
$sql_filter = "SELECT COUNT(DISTINCT R_ReportID, R_ReportCode, R_ReportName) as total
|
||||
FROM r_report
|
||||
WHERE R_ReportIsActive = 'Y'
|
||||
AND R_ReportID = ?
|
||||
AND (
|
||||
R_ReportName LIKE ?
|
||||
) LIMIT ?";
|
||||
|
||||
$tot_count = 0;
|
||||
$qry_filter = $this->db->query($sql_filter, [$reportid, $search, $number_limit]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("reports count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_count,
|
||||
"total_display" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function get_type()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT R_InputTypeID as typeid,
|
||||
R_InputTypeName
|
||||
FROM r_inputtype
|
||||
WHERE R_InputTypeIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function addparam()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$reportsid = "";
|
||||
if (isset($prm["reportsid"])) {
|
||||
$reportsid = trim($prm["reportsid"]);
|
||||
}
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$label = "";
|
||||
if (isset($prm["label"])) {
|
||||
$label = trim($prm["label"]);
|
||||
}
|
||||
$parameter = "";
|
||||
if (isset($prm["parameter"])) {
|
||||
$parameter = trim($prm["parameter"]);
|
||||
}
|
||||
$sourcesp = "";
|
||||
if (isset($prm["sourcesp"])) {
|
||||
$sourcesp = trim($prm["sourcesp"]);
|
||||
}
|
||||
$url = "";
|
||||
if (isset($prm["url"])) {
|
||||
$url = trim($prm["url"]);
|
||||
}
|
||||
$type = "";
|
||||
if (isset($prm["type"])) {
|
||||
$type = trim($prm["type"]);
|
||||
}
|
||||
$priority = "";
|
||||
if (isset($prm["priority"])) {
|
||||
$priority = trim($prm["priority"]);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO r_reportdetail(
|
||||
R_ReportDetailR_ReportID,
|
||||
R_ReportDetailName,
|
||||
R_ReportDetailLabel,
|
||||
R_ReportDetailParam,
|
||||
R_ReportDetailSourceSp,
|
||||
R_ReportDetailSourceUrl,
|
||||
R_ReportDetailR_InputTypeID,
|
||||
R_ReportDetailPriority,
|
||||
R_ReportDetailIsActive,
|
||||
R_ReportDetailCreated,
|
||||
R_ReportDetailLastUpdated,
|
||||
R_ReportDetailUserID) VALUES(?,?,?,?,?,?,?,?,'Y',NOW(),NOW(),?)";
|
||||
|
||||
$qry = $this->db->query($sql, array(
|
||||
$reportsid,
|
||||
$name,
|
||||
$label,
|
||||
$parameter,
|
||||
$sourcesp,
|
||||
$url,
|
||||
$type,
|
||||
$priority,
|
||||
$userid
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("insert 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 editparam()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$reportsid = "";
|
||||
if (isset($prm["reportsid"])) {
|
||||
$reportsid = trim($prm["reportsid"]);
|
||||
}
|
||||
$name = "";
|
||||
if (isset($prm["name"])) {
|
||||
$name = trim($prm["name"]);
|
||||
}
|
||||
$label = "";
|
||||
if (isset($prm["label"])) {
|
||||
$label = trim($prm["label"]);
|
||||
}
|
||||
$parameter = "";
|
||||
if (isset($prm["parameter"])) {
|
||||
$parameter = trim($prm["parameter"]);
|
||||
}
|
||||
$sourcesp = "";
|
||||
if (isset($prm["sourcesp"])) {
|
||||
$sourcesp = trim($prm["sourcesp"]);
|
||||
}
|
||||
$url = "";
|
||||
if (isset($prm["url"])) {
|
||||
$url = trim($prm["url"]);
|
||||
}
|
||||
$type = "";
|
||||
if (isset($prm["type"])) {
|
||||
$type = trim($prm["type"]);
|
||||
}
|
||||
$priority = "";
|
||||
if (isset($prm["priority"])) {
|
||||
$priority = trim($prm["priority"]);
|
||||
}
|
||||
$id = "";
|
||||
if (isset($prm["id"])) {
|
||||
$id = trim($prm["id"]);
|
||||
}
|
||||
|
||||
$sql = "UPDATE r_reportdetail
|
||||
SET R_ReportDetailR_ReportID = ?,
|
||||
R_ReportDetailName = ?,
|
||||
R_ReportDetailLabel = ?,
|
||||
R_ReportDetailParam = ?,
|
||||
R_ReportDetailSourceSp = ?,
|
||||
R_ReportDetailSourceUrl = ?,
|
||||
R_ReportDetailR_InputTypeID = ?,
|
||||
R_ReportDetailPriority = ?,
|
||||
R_ReportDetailLastUpdated = NOW(),
|
||||
R_ReportDetailUserID = ?
|
||||
WHERE R_ReportDetailID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array(
|
||||
$reportsid,
|
||||
$name,
|
||||
$label,
|
||||
$parameter,
|
||||
$sourcesp,
|
||||
$url,
|
||||
$type,
|
||||
$priority,
|
||||
$userid,
|
||||
$id
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->db->sys_error_db("edit param 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 deleteparam()
|
||||
{
|
||||
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 r_reportdetail
|
||||
SET R_ReportDetailIsActive = 'N',
|
||||
R_ReportDetailLastUpdated = NOW(),
|
||||
R_ReportDetailUserID = ?
|
||||
WHERE R_ReportDetailID = ?";
|
||||
$qry = $this->db->query($sql, array($userid, $id));
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user