178 lines
8.9 KiB
PHP
178 lines
8.9 KiB
PHP
|
<?php
|
||
|
defined('BASEPATH') or exit('No direct script access allowed');
|
||
|
class Accategories extends CI_Controller
|
||
|
{
|
||
|
function __construct()
|
||
|
{
|
||
|
parent::__construct();
|
||
|
$this->load->helper("accounts");
|
||
|
checkLogin();
|
||
|
}
|
||
|
public function _remap($alias = "", $params = array())
|
||
|
{
|
||
|
$data['dataValue'] = $this->session;
|
||
|
$q = "SELECT COUNT(*) as num FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tbl_accategories' AND COLUMN_NAME = 'parent_category_id'";
|
||
|
$n = $this->db->query($q)->row()->num;
|
||
|
if ($n == 0) {
|
||
|
$q = "ALTER TABLE tbl_accategories ADD COLUMN parent_category_id INT(1) NOT NULL DEFAULT 0";
|
||
|
$this->db->query($q);
|
||
|
}
|
||
|
//echo $n;die;
|
||
|
|
||
|
$data['pageTitle'] = "Account Categories";
|
||
|
|
||
|
switch ($alias) {
|
||
|
case 'add':
|
||
|
if (isset($_POST['submit'])) {
|
||
|
$TableData = array(
|
||
|
'acgroup_id' => filter_var($_POST['acgroup_id']),
|
||
|
'accategory_code' => generateACCategoryCode($_POST['acgroup_id']),
|
||
|
'parent_category_id' => filter_var($_POST['parent_category_id']),
|
||
|
'accategory_name' => filter_var($_POST['accategory_name']),
|
||
|
'created_on' => date('Y-m-d H:i:s'),
|
||
|
'created_by' => 'admin',
|
||
|
'remarks' => filter_var($_POST['remarks']),
|
||
|
'status' => 1,
|
||
|
);
|
||
|
$this->db->insert('tbl_accategories', $TableData);
|
||
|
redirect("master/accategories/list");
|
||
|
}
|
||
|
loadView("accounts/accategories/add", $data);
|
||
|
break;
|
||
|
case 'add_parent':
|
||
|
if (isset($_POST['submit'])) {
|
||
|
if (!$this->checkifCategoryExists(trim($_POST['accategory_name']))) {
|
||
|
$TableData = array(
|
||
|
'acgroup_id' => filter_var($_POST['acgroup_id']),
|
||
|
'accategory_code' => generateACCategoryCode($_POST['acgroup_id']),
|
||
|
'parent_category_id' => 0,
|
||
|
'accategory_name' => filter_var($_POST['accategory_name']),
|
||
|
'created_on' => date('Y-m-d H:i:s'),
|
||
|
'created_by' => 'admin',
|
||
|
'remarks' => filter_var($_POST['remarks']),
|
||
|
'status' => 1,
|
||
|
);
|
||
|
$this->db->insert('tbl_accategories', $TableData);
|
||
|
redirect("master/accategories/parent");
|
||
|
} else {
|
||
|
echo "CATEGORY ALREADY EXISTS";
|
||
|
die;
|
||
|
}
|
||
|
}
|
||
|
loadView("accounts/accategories/add-parent", $data);
|
||
|
break;
|
||
|
case 'add_child':
|
||
|
if (isset($_POST['submit'])) {
|
||
|
// print_r($_POST);
|
||
|
// die();
|
||
|
if (!$this->checkifCategoryExists(trim($_POST['accategory_name']))) {
|
||
|
$TableData = array(
|
||
|
'parent_category_id' => filter_var($_POST['parent_category_id']),
|
||
|
'acgroup_id' => filter_var(getFieldfromValue("tbl_accategories", "acgroup_id", "accategory_id", $_POST['parent_category_id'])),
|
||
|
'accategory_code' => generateACCategoryCode($_POST['acgroup_id']),
|
||
|
'accategory_name' => filter_var($_POST['accategory_name']),
|
||
|
'created_on' => date('Y-m-d H:i:s'),
|
||
|
'created_by' => 'admin',
|
||
|
'remarks' => filter_var($_POST['remarks']),
|
||
|
'status' => 1,
|
||
|
);
|
||
|
$this->db->insert('tbl_accategories', $TableData);
|
||
|
redirect("master/accategories/childs");
|
||
|
} else {
|
||
|
echo "CATEGORY ALREADY EXISTS";
|
||
|
die;
|
||
|
}
|
||
|
}
|
||
|
loadView("accounts/accategories/add-child", $data);
|
||
|
break;
|
||
|
case 'edit':
|
||
|
$id = $this->uri->segment(4);
|
||
|
|
||
|
if (isset($_POST['submit'])) {
|
||
|
|
||
|
$TableData = array(
|
||
|
'acgroup_id' => filter_var($_POST['acgroup_id']),
|
||
|
'accategory_code' => generateACCategoryCode($_POST['acgroup_id']),
|
||
|
'parent_category_id' => filter_var($_POST['parent_category_id']),
|
||
|
'accategory_name' => filter_var($_POST['accategory_name']),
|
||
|
'created_on' => date('Y-m-d H:i:s'),
|
||
|
'created_by' => 'admin',
|
||
|
'remarks' => filter_var($_POST['remarks']),
|
||
|
'status' => 1,
|
||
|
);
|
||
|
$this->db->where('accategory_id', $id);
|
||
|
$this->db->update('tbl_accategories', $TableData);
|
||
|
redirect("master/accategories");
|
||
|
}
|
||
|
$data['AccountCategory'] = $this->db->query("select * from tbl_accategories where accategory_id =\"$id\" ")->row();
|
||
|
loadView("accounts/accategories/edit", $data);
|
||
|
break;
|
||
|
case 'edit_parents':
|
||
|
$id = $this->uri->segment(4);
|
||
|
$data['pageTitle'] = "Edit Category";
|
||
|
|
||
|
if (isset($_POST['submit'])) {
|
||
|
|
||
|
$TableData = array(
|
||
|
'acgroup_id' => filter_var($_POST['acgroup_id']),
|
||
|
'accategory_code' => generateACCategoryCode($_POST['acgroup_id']),
|
||
|
'parent_category_id' => filter_var($_POST['parent_category_id']),
|
||
|
'accategory_name' => filter_var($_POST['accategory_name']),
|
||
|
'created_on' => date('Y-m-d H:i:s'),
|
||
|
'created_by' => 'admin',
|
||
|
'remarks' => filter_var($_POST['remarks']),
|
||
|
'status' => 1,
|
||
|
);
|
||
|
$this->db->where('accategory_id', $id);
|
||
|
$this->db->update('tbl_accategories', $TableData);
|
||
|
redirect("master/accategories/parent");
|
||
|
}
|
||
|
$data['AccountCategory'] = $this->db->query("select * from tbl_accategories where accategory_id =\"$id\" ")->row();
|
||
|
loadView("accounts/accategories/edit-parents", $data);
|
||
|
break;
|
||
|
case 'delete':
|
||
|
$id = $this->uri->segment(4);
|
||
|
if (!$this->myaccounts->hasTransaction("accategory", $id)) {
|
||
|
$this->db->set('status', "-1");
|
||
|
$this->db->set('remarks', "Deleted on" . date("Y-m-d H:i:s") . " by " . $this->session->userdata("loggedUser"));
|
||
|
$this->db->where('accategory_id', $id);
|
||
|
$this->db->update('tbl_accategories');
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
echo "Transaction Exists!!! Can't Delete";die;
|
||
|
}
|
||
|
redirect("master/accategories/childs");
|
||
|
break;
|
||
|
case 'delete_parent':
|
||
|
$id = $this->uri->segment(4);
|
||
|
$this->db->set('status', "-1");
|
||
|
$this->db->set('remarks', "Deleted on" . date("Y-m-d H:i:s") . " by " . $this->session->userdata("loggedUser"));
|
||
|
$this->db->where('accategory_id', $id);
|
||
|
$this->db->update('tbl_accategories');
|
||
|
redirect("master/accategories/parent");
|
||
|
break;
|
||
|
case 'parent':
|
||
|
$data['pageTitle'] = "Account Categories";
|
||
|
$data['ACCategories'] = $this->myaccounts->getAccountCategories();
|
||
|
loadView("accounts/accategories/list-parents-only", $data);
|
||
|
break;
|
||
|
case 'childs':
|
||
|
$data['pageTitle'] = "Account Groups";
|
||
|
|
||
|
// $data['ACCategories'] = $this->db->query("select *, (select accategory_name from tbl_accategories as a where a.parent_category_id=b.accategory_id) as parent_category, (select acgroup_name from tbl_acgroups where tbl_acgroups.acgroup_id=b.acgroup_id) as acgroup_name from tbl_accategories as b where status=1")->result();
|
||
|
$data['ACCategories'] = $this->myaccounts->getAccountCategories();
|
||
|
loadView("accounts/accategories/list-childs-only", $data);
|
||
|
break;
|
||
|
default:
|
||
|
$data['pageTitle'] = "Account Categories";
|
||
|
$data['ACCategories'] = $this->myaccounts->getAccountCategories();
|
||
|
loadView("accounts/accategories/list-parents-only", $data);
|
||
|
}
|
||
|
}
|
||
|
function checkifCategoryExists($accategory_name)
|
||
|
{
|
||
|
return ($this->db->query("select * from tbl_accategories where UPPER(accategory_name)='" . strtoupper($accategory_name) . "'")->num_rows() > 0) ? true : false;
|
||
|
}
|
||
|
}
|