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

class Controller extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        $this->load->database();
        $this->load->helper('url');

        $this->load->library('grocery_CRUD');
		
         

    }

	/* This function used to show the main page of the screen */
    public function _controller_output($output = null)
    {
        $this->load->view('AssetDetails',(array)$output);
		
    }
	
	public function home($ouput =null)
	{ 
		 
		 $this->config->load('grocery_crud');
		 $crud = new grocery_CRUD();

            
         $crud->set_table('T_PurchaseOrderDetails');
		 $crud->required_fields('PONO');
            $crud->columns('PONO','POType','PODate','SpecialOrder','UserID');
			
			$crud->unset_add();
			$crud->unset_read();
			$crud->unset_edit();
			$crud->unset_delete();
			$crud->unset_export();
			$crud->unset_print();
			
		   $output = $crud->render();

				
				$this->_controller_output($output);
			
			}

    public function offices()
    {
        $output = $this->grocery_crud->render();

        $this->_controller_output($output);
    }

    public function index()
    {
		 
        $this->_controller_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
    }
 

   public function purchase_order()
    {  
        try{
            $crud = new grocery_CRUD();

            
            $crud->set_table('T_PurchaseOrderDetails');
            $crud->set_subject('Purchase Order');
            $crud->required_fields('PONO');
            $crud->columns('PONO','POType','PODate','SpecialOrder','UserID', 'RequesterEmail','RequesterPh','RequestedDate','BudgetManager','BudgetManagerDepartment','PurchasingCategory','PurchasingJustification','OrderValue','DiscountType','DiscountValue','PackagingType','PackagingValue','ExciseDuty','Vat','Freight','CreatedOn','Create_By');
			/* These functions to hide add , view(read) ,edit , delete in form */
			$crud->unset_add();
			$crud->unset_read();
			$crud->unset_edit();
			$crud->unset_delete();
			$crud->unset_export();
			$crud->unset_print();
			
		   $output = $crud->render();

				if($crud->getState() != 'list') {
				$this->_controller_output($output);
			} else {
				return $output;
			} 
				 

        }catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
    }
	 public function purchase_order2()
    {  
        try{
            $crud = new grocery_CRUD();

            
            $crud->set_table('T_PurchaseOrderDetails');
            $crud->set_subject('Purchase Order');
            $crud->required_fields('PONO');
            $crud->columns('PONO','POType','PODate','SpecialOrder','UserID', 'RequesterEmail','RequesterPh','RequestedDate','BudgetManager','BudgetManagerDepartment','PurchasingCategory','PurchasingJustification','OrderValue','DiscountType','DiscountValue','PackagingType','PackagingValue','ExciseDuty','Vat','Freight','CreatedOn','Create_By');
            $output = $crud->render();

			$this->_controller_output($output);
			 } 
			catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }	 

        }
    
    public function Purchase_Order_Line_Item()
    { 
        try{
            $crud = new grocery_CRUD();

            
            $crud->set_table('T_PurchaseOrderLineItem');
            $crud->set_subject('Purchase Order Line Item');
            $crud->required_fields('POLine');
            $crud->columns('POLineNo','PONO','Material_ID','UOM','Quantity','UnitPrice','ModifiedOn');

            $output = $crud->render();

			   if($crud->getState() != 'list') {
				//$this->_controller_output($output);
				 $this->load->view('Mainpage.php',(array)$output);
			} else {
				return $output;
			}
        }catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
    }
 
    

public function Supplier_Details()
    {
        try{
            $crud = new grocery_CRUD();

            
            $crud->set_table('T_SupplierDetails');
            $crud->set_subject('Supplier Details');
            $crud->required_fields('Supplierid');
            $crud->columns('SupplierID','SupplierName','Address','Contactnumber','AlternateContactNumber','EmailAddress','TIN','PAN');
  /* These functions to hide add , view(read) ,edit , delete in form */
			$crud->unset_add();
			$crud->unset_read();
			$crud->unset_edit();
			$crud->unset_delete();
			$crud->unset_export();
			$crud->unset_print();
			
            $output = $crud->render();
			
			/* if else should be use , if we are using the same function in many screen*/
			if($crud->getState() != 'list') {
				$this->_controller_output($output);
			} else {
				return $output;
			} 
        }catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
    }
	
	public function Supplier_Details2()
    {
        try{
            $crud = new grocery_CRUD();

            
            $crud->set_table('T_SupplierDetails');
            $crud->set_subject('Supplier Details');
            $crud->required_fields('Supplierid');
            $crud->columns('SupplierID','SupplierName','Address','Contactnumber','AlternateContactNumber','EmailAddress','TIN','PAN');

            $output = $crud->render();
			
			 	 
				$this->_controller_output($output);
			 
        }catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
    }
   public function RawMaterial()
    {
        try{
            $crud = new grocery_CRUD();

            
            $crud->set_table('T_RawMaterialDetails');
            $crud->set_subject('RawMaterialDetails');
            $crud->required_fields('Metarial_ID');
            $crud->columns('Metarial_ID','Material_Name','Material_Type','SuplierID','Create_date');

			/* These functions to hide add , view(read) ,edit , delete in form */
			$crud->unset_add();
			$crud->unset_read();
			$crud->unset_edit();
			$crud->unset_delete();
			$crud->unset_export();
			$crud->unset_print();
			
            $output = $crud->render();

           if($crud->getState() != 'list') {
				$this->_controller_output($output);
			} else {
				return $output;
			}
        }catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
    }
	public function RawMaterial2()
    {
        try{
            $crud = new grocery_CRUD();

            
            $crud->set_table('T_RawMaterialDetails');
            $crud->set_subject('RawMaterialDetails');
            $crud->required_fields('Metarial_ID');
            $crud->columns('Metarial_ID','Material_Name','Material_Type','SuplierID','Create_date');

            $output = $crud->render();

            $this->_controller_output($output);

        }catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
    }
	
	/* To call AssetDetail details  */
	public function AssetDetails()
    {
        try{
            $crud = new grocery_CRUD();

           
            $crud->set_table('T_AssetDetails');
            $crud->set_subject('AssetDetails');
            $crud->required_fields('Asset_Code');
            $crud->columns('Asset_Code','Asset_Name','Description','Department','Location','AssetOwner','SupplierName','DateOfPurchase','DateOfCommissioning','SupportVendor','SupportFrom','SupportTo','Created_date');

            $output = $crud->render();

            $this->_controller_output($output);
			// $this->load->view('AssetDetails.php',(array)$output);

        }catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
		
    }	


}