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

class SalesOrder extends CI_Controller {
	public function __construct(){
		parent::__construct();
			$this->load->library('layouts');
		$this->load->model('menu');
	}
	
	public function index()
	{
			$this->lang->load("so",$this->session->userdata('language'));
			$this->layouts->add_includes('js/charts/excanvas.min.js')
				->add_includes('js/charts/jquery.flot.resize.js')
				->add_includes('js/accounting.js')
				->add_includes('js/charts/jquery.flot.js');
			$this->layouts->view('so/home', array('latest' => 'sidebar/latest'));
		}
	public function openPurchaseInvoice(){
		$this->load->model('purchaseInvoice_list');
		$query = $this->purchaseInvoice_list->purchaseInvoice_allOpen();
		if($query){
   			print json_encode(array(
				"status"=>"success", 
				"message"=>$query,
				));
		}else{
   			print json_encode(array(
				"status"=>"failed", 
				"message"=>'',
				));
		}
	}
	public function SalesByCustomer(){
		$this->lang->load("salesorder",$this->session->userdata('language'));
		$this->load->model('Saleschart_model');
		$this->load->model('Compfinancialyear');
			$add_year = date("Y");
			$add_period = date("m");
			$startDate = date("Y-m-01");
			$endDate = date("Y-m-t");
			$query2 = $this->Compfinancialyear->compfinancialyear_date1(date("Y-m-d"));
			if($query2){
				$startDate = $query2[0]->startDate;
				$endDate = $query2[0]->endDate;
			}
		$data['selyear'] = $add_year;
		$data['selper'] = $add_period;
		$query = $this->Saleschart_model->Sales_all_date_byCustomer($startDate, $endDate);
		if($query){
   			print json_encode(array(
				"status"=>"success", 
				"message"=>$query,
				));
		}else{
   			print json_encode(array(
				"status"=>"failed", 
				"message"=>'',
				));
		}
	}
	public function SalesByItems(){
		$this->lang->load("salesorder",$this->session->userdata('language'));
		$this->load->model('Saleschart_model');
		$this->load->model('Compfinancialyear');
			$add_year = date("Y");
			$add_period = date("m");
			$startDate = date("Y-m-01");
			$endDate = date("Y-m-t");
			$query2 = $this->Compfinancialyear->compfinancialyear_date1(date("Y-m-d"));
			if($query2){
				$startDate = $query2[0]->startDate;
				$endDate = $query2[0]->endDate;
			}
		$data['selyear'] = $add_year;
		$data['selper'] = $add_period;
		$query = $this->Saleschart_model->Sales_all_date_byItem($startDate, $endDate);
		if($query){
   			print json_encode(array(
				"status"=>"success", 
				"message"=>$query,
				));
		}else{
   			print json_encode(array(
				"status"=>"failed", 
				"message"=>'',
				));
		}
	}
}

?>