97 lines
4.0 KiB
PHP
97 lines
4.0 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
class Units extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
checkLogin();
|
|
}
|
|
public function _remap($alias = "", $params = array())
|
|
{
|
|
|
|
$data['dataValue'] = $this->session;
|
|
|
|
$data['pageTitle'] = "Master - Units";
|
|
|
|
switch ($alias) {
|
|
case 'add':
|
|
if (isset($_POST['submit'])) {
|
|
$title = filter_var($_POST['title']);
|
|
$description = filter_var($_POST['description']);
|
|
$this->db->where('title',$title);
|
|
$this->db->or_where('description',$description);
|
|
$query = $this->db->get('tbl_units');
|
|
if($query->num_rows() > 0){
|
|
echo "Title or code already exists.";die;
|
|
}else{
|
|
$TableData = array(
|
|
'title' => filter_var($_POST['title']),
|
|
'alias' => filter_var($_POST['alias']),
|
|
'description' => filter_var($_POST['description']),
|
|
'display_order' => filter_var($_POST['display_order']),
|
|
'status' => 1,
|
|
'remarks' => filter_var($_POST['remarks']),
|
|
'created_on' => date('Y-m-d H:i:s'),
|
|
'created_by' => 'admin',
|
|
);
|
|
$this->db->insert('tbl_units', $TableData);
|
|
redirect("inventory/units/list");
|
|
}
|
|
|
|
}
|
|
loadView("inventory/units/add", $data);
|
|
break;
|
|
case 'edit':
|
|
if (isset($_POST['submit'])) {
|
|
$id = $this->uri->segment(4);
|
|
|
|
$title = filter_var($_POST['title']);
|
|
$description = filter_var($_POST['description']);
|
|
$this->db->where('status',1);
|
|
$this->db->where('unit_id !=', $id);
|
|
$this->db->where('title',$title);
|
|
$this->db->or_where('description',$description);
|
|
|
|
$query = $this->db->get('tbl_units');
|
|
if($query->num_rows() > 0){
|
|
echo "Title or description already exists.";die;
|
|
}else{
|
|
$TableData = array(
|
|
'title' => filter_var($_POST['title']),
|
|
'alias' => filter_var($_POST['alias']),
|
|
'description' => filter_var($_POST['description']),
|
|
'display_order' => filter_var($_POST['display_order']),
|
|
'status' => 1,
|
|
'remarks' => filter_var($_POST['remarks']),
|
|
'created_on' => date('Y-m-d H:i:s'),
|
|
'created_by' => 'admin',
|
|
);
|
|
$this->db->where('unit_id', $id);
|
|
$this->db->update('tbl_units', $TableData);
|
|
redirect("inventory/units/list");
|
|
}
|
|
}
|
|
$id = $this->uri->segment(4);
|
|
$this->db->where('unit_id', $id);
|
|
$data['unit'] = $this->db->get("tbl_units")->row();
|
|
loadView("inventory/units/list", $data);
|
|
break;
|
|
case 'delete':
|
|
$id = $this->uri->segment(4);
|
|
if (!$this->myaccounts->hasTransaction("units", $id)) {
|
|
$this->db->where('unit_id', $id);
|
|
$this->db->delete('tbl_units');
|
|
}
|
|
else
|
|
{
|
|
echo "Transaction Exists!!! Can't Delete";die;
|
|
}
|
|
redirect("inventory/units/list");
|
|
break;
|
|
default:
|
|
loadView("inventory/units/list", $data);
|
|
}
|
|
}
|
|
}
|