<?php
	class Sales_model extends CI_model
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->database();
		}
		// Advance Orders list
		public function get_advance_ordersdetails()
		{
		    $branchs = $_SESSION['branch_name'];
		    $branch='';
		    if($branchs == 'CW-DK' || $branchs == 'CW-CTR'){
		        $branch='CW1';
		    } else if($branchs =='CW2-FFK' || $branchs == 'CW2-CTR'){
		        $branch='CW2';
		    } else if($branchs =='CW3-FFK' || $branchs == 'CW3-CTR'){
		        $branch='CW3';
		    } else if($branchs =='CW4-CLD' || $branchs == 'CW4-CTR'){
		        $branch='CW4';
		    } else if($branchs == 'CW5-CTR'){
		        $branch='CW5';
		    }
		    $current_date = date('Y-m-d');
		    $query=$this->db1->query("SELECT branch_slno,branch FROM outlet_deatils WHERE status='Active' and  branch='$branch'");
    		$total_branch = $query->result_array();
    		foreach ($total_branch as $brans) 
    		{
    			$branch_code = $brans['branch_slno'];
    			$branches = $brans['branch'];
    			if ($branch == $branches)
    			{
        		    $table = 'product_billdetail'.$branch_code;
        			$query10=$this->db1->query("SELECT *,bill_id as bid FROM $table WHERE bno !='0' and mop !='CREDIT' and status ='pending' and delivery_date ='$current_date' order by `delivery_time` asc");
        			$result10 = $query10->result();
        	        return $result10;
    			}
    		}
	    }	
	    
	    public function get_advance_billproductdetail_toedit($bid,$branch)
    	{
		    $current_date = date('Y-m-d');
		    $query1=$this->db1->query("SELECT branch_slno,branch FROM outlet_deatils WHERE status='Active' and  branch='$branch'");
    		$total_branch = $query1->result_array();
    		foreach ($total_branch as $brans) 
    		{
    			$branch_code = $brans['branch_slno'];
    			$branches = $brans['branch'];
    			if ($branch == $branches)
    			{
        		    $table = 'product_billdetail'.$branch_code;
        		    $table1 = 'billed_product'.$branch_code;
        			$query=$this->db1->query("SELECT *,P.bill_id as bid FROM $table P left join $table1 B  on P.bill_id=B.bill_id  WHERE B.bill_id='$bid'");
        			$result = $query->result();
            		return $result;
    			}
    		}
    	}
    	public function get_total_amt($bid,$branch)
    	{
		    $current_date = date('Y-m-d');
		    $query1=$this->db1->query("SELECT branch_slno,branch FROM outlet_deatils WHERE status='Active' and  branch='$branch'");
    		$total_branch = $query1->result_array();
    		foreach ($total_branch as $brans) 
    		{
    			$branch_code = $brans['branch_slno'];
    			$branches = $brans['branch'];
    			if ($branch == $branches)
    			{
        		    $table = 'product_billdetail'.$branch_code;
        		    $table1 = 'billed_product'.$branch_code;
        			$query=$this->db1->query("SELECT sum(price) as price,sum(sgst_tax_amount) as sgst_tax_amt from $table1 where bill_id=$bid group by bill_id");
        			$result = $query->result();	
            		return $result;
    			}
    		}
    	}
    	
    	public function get_invoice_tax($bid,$branch)
    	{
		    $current_date = date('Y-m-d');
		    $query1=$this->db1->query("SELECT branch_slno,branch FROM outlet_deatils WHERE status='Active' and  branch='$branch'");
    		$total_branch = $query1->result_array();
    		foreach ($total_branch as $brans) 
    		{
    			$branch_code = $brans['branch_slno'];
    			$branches = $brans['branch'];
    			if ($branch == $branches)
    			{
        		    $table = 'product_billdetail'.$branch_code;
        		    $table1 = 'billed_product'.$branch_code;
        			$query=$this->db1->query("SELECT sgst_tax,sum(sgst_tax_amount) as sgst_tax_amt,sum(cgst_tax_amount) as cgst_tax_amt from $table1 where bill_id=$bid group by sgst_tax order by sgst_tax desc");
        			$result = $query->result();
            		return $result;
    			}
    		}
    	}
    	public function get_payment_mode() 
        {
        // 		$query=$this->db->query("SELECT distinct(setting_title) FROM application_setting WHERE ((setting_type='payment'or setting_type='Other_Payment') and (setting_access='1'))");
            $query=$this->db1->query("SELECT distinct(setting_title) FROM application_setting WHERE setting_type='payment' and setting_access='1' and (setting_title != 'MULTI' and setting_title != 'CHEQUE' and setting_title!= 'DOTPE' and setting_title!= 'NEFT')");
            $result = $query->result();
            return $result;
        }
        public function get_outlets_information($branch)
    	{
    		// $branch = $this->session->userdata('branch');
    		$query = $this->db1->query("SELECT * from outlet_deatils where branch='$branch'");
    		$result = $query->result();        
    		return $result;
    	}
    	
    	// get chef list details
    	public function get_advance_cheflist()
    	{
    	    $query = $this->db->query("SELECT * FROM `chef`");
    		$result = $query->result();        
    		return $result;
    	}
    	public function get_points_information($branch)
    	{
    		// $branch = $this->session->userdata('branch');
    		$query = $this->db1->query("SELECT master_details FROM masters_creation WHERE masters_status='disclaimer' and branch='$branch'");
    		$result = $query->result();        
    		return $result;
    	}
    	public function get_points_information_logo($branch)
    	{
    		// $branch = $this->session->userdata('branch');
    		$query = $this->db1->query("SELECT master_image_path FROM masters_creation WHERE masters_status='client_logo' and branch='$branch'");
    		$result = $query->result();        
    		return $result;
    	}
    	public function get_points_information_branch_list($branch)
    	{
    		// $branch = $this->session->userdata('branch');
    		$query = $this->db1->query("SELECT master_details FROM masters_creation WHERE masters_status='branch_title' and branch='$branch'");
    		$result = $query->result();        
    		return $result;
    	}
    	public function get_points_information_social_list($branch)
    	{
    		// $branch = $this->session->userdata('branch');
    		$query = $this->db1->query("SELECT C.masters_status,C.master_details FROM  master M INNER join masters_creation C  on C.master_id=M.master_id WHERE M.master_type='Social_footer' and C.branch='$branch' ORDER BY C.masterId desc");
    		$result = $query->result();        
    		return $result;
    	}
    	
    
	}
?>  