db_smartone = $this->load->database("onedev", true); } public function search() { $prm = $this->sys_input; $max_rst = 12; $search = '%' . $prm["search"] . '%'; // QUERY TOTAL $sql = "select count(Mcu_ReportTemplateID) total from mcu_reporttemplate where Mcu_ReportTemplateName like ? and Mcu_ReportTemplateIsActive = 'Y'"; $query = $this->db_smartone->query($sql, array($search)); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("mcu report template count", $this->db_smartone); exit; } $sql = "select Mcu_ReportTemplateID, Mcu_ReportTemplateName from mcu_reporttemplate where Mcu_ReportTemplateName like ? and Mcu_ReportTemplateIsActive = 'Y' order by Mcu_ReportTemplateName limit 0, {$max_rst}"; $query = $this->db_smartone->query($sql, array($search)); if ($query) { $rows = $query->result_array(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("mcu report template rows", $this->db_smartone); exit; } } public function search_detail() { $prm = $this->sys_input; $max_rst = 12; $t_id = $prm["template_id"]; // QUERY TOTAL $sql = "select count(Mcu_ReportTemplateDetailID) total from mcu_reporttemplatedetail where Mcu_ReportTemplateDetailMcu_ReportTemplateID like ? and Mcu_ReportTemplateDetailIsActive = 'Y'"; $query = $this->db_smartone->query($sql, array($t_id)); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("mcu report template detail count", $this->db_smartone); exit; } $sql = "select Mcu_ReportTemplateDetailID, Mcu_ReportTemplateDetailIsTest, Mcu_ReportTemplateDetailT_TestID, Mcu_ReportTemplateDetailT_TestCode, Mcu_ReportTemplateDetailDesc, Mcu_ReportTemplateDetailLeftMargin from mcu_reporttemplatedetail where Mcu_ReportTemplateDetailMcu_ReportTemplateID like ? and Mcu_ReportTemplateDetailIsActive = 'Y' order by Mcu_ReportTemplateDetailLeft"; $query = $this->db_smartone->query($sql, array($t_id)); if ($query) { $rows = $query->result_array(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("mcu report template detail rows", $this->db_smartone); exit; } } function save() { $prm = $this->sys_input; $r = $this->db_smartone->set('Mcu_ReportTemplateName', $prm['template_name']) ->insert('mcu_reporttemplate'); if ($r) { $id = $this->db_smartone->insert_id(); $this->sys_ok($id); } else { $this->sys_error_db("mcu report template insert", $this->db_smartone); exit; } } function save_detail() { $prm = $this->sys_input; $r = $this->db_smartone->query("CALL sp_mcu_report_template_detail_new('{$prm['template_id']}', '{$prm['desc']}', '{$prm['is_test']}', '{$prm['test_id']}', '{$prm['pos']}', '{$prm['from_id']}')") ->row(); if ($r->status == "OK") { $this->sys_ok($r->data); } else { $this->sys_error_db("mcu report template insert", $this->db_smartone); exit; } } public function search_px() { $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "select count(*) total from t_test where T_TestIsActive = 'Y' and (T_TestName like ? OR T_TestCode LIKE ?)"; $query = $this->db_smartone->query($sql, array($q['search'], $q['search'])); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("px count",$this->db_smartone); exit; } $sql = "select T_TestID, T_TestName, T_TestCode from t_test where T_TestIsActive = 'Y' and (T_TestName like ? OR T_TestCode LIKE ?)"; $query = $this->db_smartone->query($sql, array($q['search'], $q['search'])); if ($query) { $rows = $query->result_array(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("px rows",$this->db_smartone); exit; } } }