<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CI_Controller {
    
    public function __construct() {
        parent::__construct();
         if (! $this->session->userdata ( 'user_logged_in' ) || !company_url($this->session->userdata ('company_slag'))) {
            redirect ( 'login', 'refresh' );
        }
        $this->load->vars ( array (
                'global' => 'Available to all views',
                'header' => 'common/header',
                'left' => 'common/left',
                'footer' => 'common/footer' 
        ) );
        $this->load->model('Bank_model');
        $this->load->model('Invoice_model');        
        $this->load->model('Product_model');
        $this->load->model('Color_model');
    }

    /*public function index(){
        $data['bank_list'] = $this->Bank_model->get_bank_list();		
		$bank_deposit_list = $this->Bank_model->get_bank_deposit_details();
        $data['bank_deposit_list'] = array();
        if (count($bank_deposit_list) > 0) {
            foreach ($bank_deposit_list as $key => $value) {
                $data['bank_deposit_list'][$value->account_id]['debit'] = $value->debit;
                $data['bank_deposit_list'][$value->account_id]['credit'] = $value->credit;
            }
        }		
        $this->load->view('bank_list',$data);		
    }*/
       
    
    public function index(){
        $data['category_list'] = $this->Product_model->category_list();			
        
       /* echo "<pre>";
        print_r($data);
        exit(); */		
		
        $this->load->view('category_list',$data);		
    }
    

    public function newcategory(){
        $data=array();
        $token=$this->input->post('token');
        if(!empty($token)){
            $data['catagory']=$this->Color_model->GetARecordWithWhereRowDESC("categories",array('id'=>$token));
        }
        $this->load->view('new_category',$data);
    }

    public function savecategory(){
       $data=$this->input->post();

        if (($data['id'] != '')) {
            $this->Color_model->Edit('categories',$data,'id',$data['id']);
        } else {
            unset($data['id']);
            $this->Color_model->Add('categories',$data);
        }
        echo 1;   
    }
public function delcategory(){
    $token=$this->input->post('token');
    if(!empty($token)){
        $this->Color_model->DelWhere("categories",array('id'=>$token));
    }
    redirect(base_url().'category');
}	
	public function deposit(){
        $data['bank_id'] = !empty($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $where_bank = array('status' => 1);
        $data['accounts'] = $this->Invoice_model->get_from_table('bank_accounts','*',$where_bank);
        $this->load->view('new_bank_deposit',$data);
    }

    public function deposit_amount(){
        $deposit_arr['to_acc_id'] = $this->input->post('bank_id'); 
        $deposit_arr['from_acc_id'] = $this->input->post('from_acc_id'); 
        $deposit_arr['receive_via'] = $this->input->post('receive_via'); 
        $deposit_arr['reference'] = $this->input->post('reference'); 
        $deposit_arr['amount'] = $this->input->post('amount'); 
        $deposit_arr['notes'] = $this->input->post('notes'); 
        $t_date = $this->input->post('tran_date');
        $arr1 = explode("/",$t_date);
        $deposit_arr['tran_date'] = $arr1[2]."-".$arr1[1]."-".$arr1[0];
        $deposit_arr['date_added'] = $arr1[2]."-".$arr1[1]."-".$arr1[0];
        $this->Bank_model->insert_bank_deposit($deposit_arr);
        echo 1;
    }
	
}
?>