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

class Sosetup extends CI_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('5', 'setup');
		if(!$query){
			echo '<script>alert("Not authorised..");
				window.location.replace("'.base_url().'Error");
				</script>';
		}
		$this->load->library('layouts');
		$this->load->model('menu');
	}

	public function index()
	{
		
	}
	
	public function SalesPrice(){
	  $this->lang->load("salesprice",$this->session->userdata('language'));
      $this->load->model('SalesPrice');
	  if($this->input->post('mysubmit')){
		  if($this->input->post('ID')==NULL){
			$query = $this->SalesPrice->SalesPrice_Insert();
			if($query){
				echo '<script>alert("'.$this->lang->line('message3').'");
				window.location.replace("'.base_url().'sosetup/SalesPrice");
				</script>';
			}
		  }else{
			  $updateData = array(
				'umID' => $this->input->post('umID'),
				'startDate' => date("Y-m-d", strtotime($this->input->post('startDate'))),
				'endDate' => date("Y-m-d", strtotime($this->input->post('endDate'))),
				'price' => $this->input->post('price'),
				'updatedBy' => element('role', $this->session->userdata('logged_in'))
			  );
			$query = $this->SalesPrice->SalesPrice_Update($this->input->post('ID'), $updateData);
			if($query){
				echo '<script>alert("'.$this->lang->line('message3').'");
				window.location.replace("'.base_url().'sosetup/SalesPrice");
				</script>';
			}
		  }
	  }else{
		$ID = $this->uri->segment(3);
		$this->load->model('Sysum');
		$this->load->model('Currency');
		$this->load->model('customer/customer_model');
		$this->load->model('employee/employee_model');
		$this->load->model('item/ItemSetup_model');
		$data['items'] = $this->ItemSetup_model->get_all();
		$data['employees'] = $this->employee_model->employeemaster_all();
		$data['um'] = $this->Sysum->sysum_all();
		$data['currency'] = $this->Currency->currency_all();
		$data['customers'] = $this->customer_model->customermaster_all();
		$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
				->add_includes('js/validationengine/jquery.validationEngine.js')
				->add_includes('js/accounting.js')
				->add_includes('js/datatables/jquery.dataTables.min.js');
		if($ID != ''){
			$query = $this->SalesPrice->SalesPrice_ID($ID);
			$data['itemprice'] = $query[0];
			$this->layouts->view('so/setups/salesPriceEdit', array('latest' => 'sidebar/latest'), $data);
		}else{
			$this->layouts->view('so/setups/salesPrice', array('latest' => 'sidebar/latest'), $data);
		}
	  }
	}
	public function price_delete(){
	  $this->lang->load("salesprice",$this->session->userdata('language'));
      $this->load->model('SalesPrice');
	  $query = $this->SalesPrice->SalesPrice_Delete($this->input->post('fldid'));
		if($query){
			print json_encode(array(
				"status"=>"success", 
				"message"=>$this->lang->line('message4')
				));
		}else{
			print json_encode(array("status"=>"false", "message"=>$this->lang->line('message5')));
		}
	}
	public function selectCurrency(){
		$this->load->model('customer/customer_model');
		$query = $this->customer_model->customermaster_id($this->input->post('customerID'));
		if($query){
			print json_encode(array(
				"status"=>"success", 
				"message"=>$query[0]
				));
		}else{
			print json_encode(array("status"=>"false", "message"=>''));
		}
	}
}

	
/* End of file artransaction.php */
/* Location: ./application/controller/artransaction.php */
