137 lines
4.4 KiB
PHP
137 lines
4.4 KiB
PHP
<?php
|
|
class Publicholiday extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function index()
|
|
{
|
|
echo "SUB GROUP API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function load()
|
|
{
|
|
try {
|
|
// $prm = $this->sys_input;
|
|
// $search = $prm['search'];
|
|
// $sql = "select COUNT(*) as total
|
|
// from m_public_holiday
|
|
// where
|
|
// M_Public_HolidayIsActive= 'Y'";
|
|
// $sql_param = array($search);
|
|
// $total = $this->db->query($sql, $sql_param)->row()->total;
|
|
|
|
|
|
$sql = "select M_Public_HolidayID as id, M_Public_HolidayDate as tanggal,
|
|
M_Public_HolidayName as nama
|
|
from m_public_holiday
|
|
where
|
|
M_Public_HolidayIsActive = 'Y'
|
|
and M_Public_HolidayDate >= CURDATE()";
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$total = count($rows); // Hitung jumlah baris yang diambil
|
|
} else {
|
|
$this->sys_error_db("m_public_holiday select");
|
|
exit;
|
|
}
|
|
|
|
$result = array("total" => $total, "total_filter" => $total, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$date = $prm['M_Public_HolidayDate'];
|
|
$name = $prm['M_Public_HolidayName'];
|
|
|
|
// Buat query untuk insert data
|
|
$sql = "INSERT INTO m_public_holiday (M_Public_HolidayDate, M_Public_HolidayName, M_Public_HolidayIsActive)
|
|
VALUES (?, ?, 'Y')";
|
|
|
|
// Eksekusi query dengan parameter
|
|
$this->db->query($sql, array($date, $name));
|
|
|
|
// Cek apakah insert berhasil
|
|
if ($this->db->affected_rows() > 0) {
|
|
$this->sys_ok("Data berhasil ditambahkan");
|
|
} else {
|
|
$this->sys_error("Gagal menambahkan data");
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function deactivate()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$id = $prm['M_Public_HolidayID'];
|
|
|
|
// Buat query untuk update data
|
|
$sql = "UPDATE m_public_holiday SET M_Public_HolidayIsActive = 'N' WHERE M_Public_HolidayID = ?";
|
|
|
|
// Eksekusi query dengan parameter
|
|
$this->db->query($sql, array($id));
|
|
|
|
// Cek apakah update berhasil
|
|
if ($this->db->affected_rows() > 0) {
|
|
$this->sys_ok("Data berhasil diupdate");
|
|
} else {
|
|
$this->sys_error("Gagal mengupdate data");
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$id = $prm['M_Public_HolidayID'];
|
|
$newDate = $prm['M_Public_HolidayDate'];
|
|
$newName = $prm['M_Public_HolidayName'];
|
|
|
|
// Mulai transaksi
|
|
$this->db->trans_start();
|
|
|
|
// Nonaktifkan data lama
|
|
$sql_update = "UPDATE m_public_holiday SET M_Public_HolidayIsActive = 'N' WHERE M_Public_HolidayID = ?";
|
|
$this->db->query($sql_update, array($id));
|
|
|
|
// Insert data baru
|
|
$sql_insert = "INSERT INTO m_public_holiday (M_Public_HolidayDate, M_Public_HolidayName, M_Public_HolidayIsActive)
|
|
VALUES (?, ?, 'Y')";
|
|
$this->db->query($sql_insert, array($newDate, $newName));
|
|
|
|
// Selesaikan transaksi
|
|
$this->db->trans_complete();
|
|
|
|
// Cek apakah transaksi berhasil
|
|
if ($this->db->trans_status() === FALSE) {
|
|
$this->sys_error("Gagal mengupdate data");
|
|
} else {
|
|
$this->sys_ok("Data berhasil diupdate");
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|