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

class Load_account extends CI_Controller {

	private $userInfo = array();

    public function __construct()
    {
        parent::__construct();
		$this->load->model("user_model");
        $this->load->model("account_model");

		//$this->userInfo = $this->user_model->userInfo("first_name,last_name");
    }
public function getbalance($id=0)
    {
        echo $this->account_model->id_('head',$id,'id')['balance'];
    }
    public function projectagainstprog($v=0)
        
        {
            
        if(!empty($v))
        {
            $result = $this->db->query("SELECT id,p_name from project where is_delete=0 and program_id=$v ")->result_array();
            foreach ($result as $key => $value) {
                echo "<option value='".$value['id']."'>".$value['p_name']."</option>";
            }
        }
        else
            echo "";

        }
    public function level2assign_view($mainid=0,$branch=0)
    {
         if(!empty($mainid))
             {
                 $result = $this->db->query("SELECT * FROM `assign_account` where main_head=$mainid and branch=$branch and is_delete=0 and level3=0")->result_array();
                 
                 $return="";
                 $i=1;
                 foreach ($result as $key => $value) {
                     $bname=$this->account_model->SearchId("branch",$value['branch']);   
                     $headname=$this->account_model->SearchId("head",$value['main_head']);   
                     $l2name=$this->account_model->SearchId("head",$value['level2']);   
                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
             $return .= "<td>".$bname." </td>";
             $return .= "<td>".$headname." </td>";
             $return .= "<td>".$l2name." </td>";
               
             $return .= "<td>
             <a href='".base_url()."account/delete_assign/".$value['id']."'><i class='fa fa-trash'></i></a>
              
             <a href='".base_url()."account/level2/".$value['id']."/assign'><i class='fa fa-edit'></i></a>";
             $return .= "</td></tr>";
        
                 }
                 
                 echo $return;
            }
            else
                echo "";
    }
    public function level3assign_view($bid=0,$mid=0,$l2id=0)
    {
        if(!empty($bid))
             {
                 $result = $this->db->query("SELECT * FROM `assign_account` where main_head=$mid and branch=$bid and level2=$l2id and is_delete=0 and level3!=0")->result_array();
                
                 $return="";
                 $i=1;
                 foreach ($result as $key => $value) {
                     $bname=$this->account_model->SearchId("branch",$value['branch']);   
                     $headname=$this->account_model->SearchId("head",$value['main_head']);   
                     $l2name=$this->account_model->SearchId("head",$value['level2']);
                     $l3name=$this->account_model->SearchId("head",$value['level3']);

                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
             $return .= "<td>".$bname." </td>";
             $return .= "<td>".$headname." </td>";
             $return .= "<td>".$l2name." </td>";
             $return .= "<td>".$l3name." </td>";
               
             $return .= "<td>
             <a href='".base_url()."account/delete_assign/".$value['id']."'><i class='fa fa-trash'></i></a>
              
             <a href='".base_url()."account/level3/".$value['id']."/assign'><i class='fa fa-edit'></i></a>";
             $return .= "</td></tr>";
        
                 }
                 
                 echo $return;
            }
            else
                echo "";
 
    }
    public function level4assign_view($bid=0,$mid=0,$l2id=0,$l3=0)
    {
        if(!empty($bid))
             {
                 $result = $this->db->query("SELECT * FROM `assign_account` where main_head=$mid and branch=$bid and level2=$l2id and level3=$l3 and is_delete=0 and level4!=0")->result_array();
                
                 $return="";
                 $i=1;
                 foreach ($result as $key => $value) {

                     $bname=$this->account_model->SearchId("branch",$value['branch']);   
                     $headname=$this->account_model->SearchId("head",$value['main_head']);   
                     $l2name=$this->account_model->SearchId("head",$value['level2']);
                     $l3name=$this->account_model->SearchId("head",$value['level3']);
                     $l4name=$this->account_model->SearchId("head",$value['level4']);
                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
             $return .= "<td>" .$bname." </td>";
             $return .= "<td>".$headname." </td>";
             $return .= "<td>".$l2name." </td>";
             $return .= "<td>".$l3name." </td>";
             $return .= "<td>".$l4name." </td>";
               
             $return .= "<td>
             <a href='".base_url()."account/delete_assign/".$value['id']."'><i class='fa fa-trash'></i></a>
              
             <a href='".base_url()."account/level4/".$value['id']."/assign'><i class='fa fa-edit'></i></a>";
             $return .= "</td></tr>";
        
                 }
                 
                 echo $return;
            }
            else
                echo "";
 
    }
     public function level5assign_view($bid=0,$mid=0,$l2id=0,$l3=0,$l4=0)
    {
        if(!empty($bid))
             {
                 $result = $this->db->query("SELECT * FROM `assign_account` where main_head=$mid and branch=$bid and level2=$l2id and level3=$l3 and is_delete=0 and level4=$l4 and level5!=0 ")->result_array();
                
                 $return="";
                
                 $i=1;
                 foreach ($result as $key => $value) {
                      $bname=$this->account_model->SearchId("branch",$value['branch']);   
                     $headname=$this->account_model->SearchId("head",$value['main_head']);   
                     $l2name=$this->account_model->SearchId("head",$value['level2']);
                     $l3name=$this->account_model->SearchId("head",$value['level3']);
                     $l4name=$this->account_model->SearchId("head",$value['level4']);
                     $l5name=$this->account_model->SearchId("head",$value['level5']);


                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
             $return .= "<td>".$bname." </td>";
             $return .= "<td>".$headname." </td>";
             $return .= "<td>".$l2name." </td>";
             $return .= "<td>".$l3name." </td>";
             $return .= "<td>".$l4name." </td>";
             $return .= "<td>".$l5name." </td>";
               
             $return .= "<td>
             <a href='".base_url()."account/delete_assign/".$value['id']."'><i class='fa fa-trash'></i></a>
              
             <a href='".base_url()."account/level5/".$value['id']."/assign'><i class='fa fa-edit'></i></a>";
             $return .= "</td></tr>";
        
                 }
                 
                 echo $return;
            }
            else
                echo "";
 
    }
    public function pro_again_branch($id=0){
        
        if(!empty($id)){
            $r=$this->db->query("SELECT branch.name as branchname,program.name,assign_account.id FROM `assign_account` inner join branch on branch.id=assign_account.branch inner join program on program.id=assign_account.programe_id where assign_account.branch=$id and assign_account.is_delete=0 and assign_account.project=0")->result_array();
            $return="";
                 $i=1;
                 foreach ($r as $key => $value) {

                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
             $return .= "<td>".$value['branchname']."</td>";
             $return .= "<td>".$value['name']." </td>";
             
            $return .= "<td>
             <a href='".base_url()."account/index/?abc=".urlencode($this->encrypt->encode($value['id']))."'><i class='fa fa-edit'></i></a>
              <a href='".base_url()."account/delete_assign/programe/?abc=".urlencode($this->encrypt->encode($value['id']))."'><i class='fa fa-trash'></i></a>
             </td>";
             $return .= "</tr>";
        
                 }
                 echo $return;
        }else{
             echo "";
        }
    }
     public function proj_assign($id=0,$b){
        
        if(!empty($id)){
        $this->db->where('assign_account.is_delete','0')->where('assign_account.programe_id',$id)->where('assign_account.branch',$b)->where('project.is_delete',0);
        $this->db->select(" branch.name as bname,program.name as pname,project.p_name,assign_account.id"); 
        $this->db->from('assign_account');
        $this->db->join('branch','branch.id=assign_account.branch');
        $this->db->join('program','program.id=assign_account.programe_id');
        $this->db->join('project','project.id=assign_account.project');
        
        $r = $this->db->get()->result_array();
            $return="";
            
                 $i=1;
                 foreach ($r as $key => $value) {

                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
             $return .= "<td>".$value['bname']." </td>";
             $return .= "<td>".$value['pname']." </td>";
              $return .= "<td>".$value['p_name']." </td>";
            $return .= "<td>
             <a href='".base_url()."account/project/?abc=".urlencode($this->encrypt->encode($value['id']))."'><i class='fa fa-edit'></i></a>
              <a href='".base_url()."account/delete_assign/project/?abc=".urlencode($this->encrypt->encode($value['id']))."'><i class='fa fa-trash'></i></a>
             </td>";
             $return .= "</tr>";
        
                 }
                 echo $return;
        }else{
             echo "";
        }
    }
     public function proj_again_prog($id=0){
        
        if(!empty($id)){
            $this->db->where('project.is_delete','0')->where('project.program_id',$id);
        $this->db->select("project.id,project.p_name,program.name"); 
        $this->db->from('project');
        
        $this->db->join('program','program.id=project.program_id');
        
        $r = $this->db->get()->result_array();
            $return="";
                 $i=1;
                 foreach ($r as $key => $value) {

                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
$return .= "<td>".$value['name']." </td>";             
$return .= "<td>".$value['p_name']." </td>";
              
            $return .= "<td>
             <a href='".base_url()."account/index/?abc=".urlencode($this->encrypt->encode($value['id']))."'><i class='fa fa-edit'></i></a>
              <a href='".base_url()."account/delete_program/?abc=".urlencode($this->encrypt->encode($value['id']))."'><i class='fa fa-trash'></i></a>
             </td>";
             $return .= "</tr>";
        
                 }
                 echo $return;
        }else{
             echo "";
        }
    }
    public function proagainstbranch($v=0)
        {
        if(!empty($v))
        {
            $result = $this->db->query("SELECT program.id,program.name FROM `assign_account` join program on program.id=assign_account.programe_id where assign_account.branch=$v and assign_account.project=0 and assign_account.is_delete=0")->result_array();
            foreach ($result as $key => $value) {
                echo "<option value='".$value['id']."'>".$value['name']."</option>";
            }
        }
        else
            echo "";

        }

        public function proagainstproject($v=0)
        {
            $branch=$this->user_model->getbranch();
        if(!empty($v))
        {
            $result = $this->db->query("SELECT project.id,project.p_name FROM assign_account JOIN project on project.id=assign_account.project WHERE assign_account.branch=$branch and assign_account.programe_id=$v and project.is_delete=0 group by project.id ")->result_array();
            foreach ($result as $key => $value) {
                echo "<option value='".$value['id']."'>".$value['p_name']."</option>";
            }
        }
        else
            echo "";

        }

    public function level2_assign($v=0)
    {
        $branch=$this->user_model->getbranch();
            if(!empty($v))
            {
                $result = $this->db->query("SELECT head.id,head.name FROM `assign_account` join head on head.id=assign_account.level2 where branch=$branch and head.parent_id=$v and head.is_active=1 GROUP by(head.id)")->result_array();
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
     
    }
     public function level2_assign_json($v=0)
    {
        $branch=$this->user_model->getbranch();
            if(!empty($v))
            {
                $result = $this->db->query("SELECT head.id,head.name FROM `assign_account` join head on head.id=assign_account.level2 where branch=$branch and head.parent_id=$v and head.is_active=1 GROUP by(head.id)")->result_array();
                
            }
            echo json_encode($result);
           
    }
    public function level2_db($v=0)
    {
            if(!empty($v))
            {
                $result = $this->db->query("SELECT `id`,`name` FROM `head` WHERE parent_id=$v  AND is_active='1'")->result_array();
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
     
    }
    public function level3_assign($v=0)
    {       $branch=$this->user_model->getbranch();
            if(!empty($v))
            {
                $result = $this->db->query("SELECT head.id,head.name FROM `assign_account` join head on head.id=assign_account.level3 where branch=$branch and head.parent_id=$v GROUP by(head.id)")->result_array();
               
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
     
    }
    public function level4_assign($v=0)
    {       $branch=$this->user_model->getbranch();
            if(!empty($v))
            {
                $result = $this->db->query("SELECT head.id,head.name FROM `assign_account` join head on head.id=assign_account.level4 where branch=$branch and head.parent_id=$v GROUP by(head.id)")->result_array();
               
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
     
    }
    public function level5_assign($v=0)
    {       $branch=$this->user_model->getbranch();
            if(!empty($v))
            {
                $result = $this->db->query("SELECT head.id,head.name FROM `assign_account` join head on head.id=assign_account.level5 where branch=$branch and head.parent_id=$v GROUP by(head.id)")->result_array();
               
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
     
    }
    
    public function level3_db($v=0)
    {
            if(!empty($v))
            {
                $result = $this->db->query("SELECT id,name from head where parent_id=$v and is_active=1")->result_array();
               
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
     
    }
     public function level4_db($v=0)
    {
            if(!empty($v))
            {
                $result = $this->db->query("SELECT id,name FROM `head` where is_active=1 and parent_id=$v")->result_array();
               
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
     
    }
         public function level5_db($v=0)
    {
            if(!empty($v))
            {
                $result = $this->db->query("SELECT id,name FROM `head` where is_active=1 and parent_id=$v")->result_array();
               
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
     
    }
    public function level3_againl2($id=0)
    {
        if(!empty($id))
            {
                $result = $this->db->query("SELECT id,name FROM `level_3` where level_2_id=$id and is_delete=0")->result_array();
               
                foreach ($result as $key => $value) {
                    echo "<option value='".$value['id']."'>".$value['name']."</option>";
                }
            }
            else
                echo "";
    }
    public function level3_view($id=0)
    {
            if(!empty($id))
             {
                $result=$this->account_model->getParent($id,3);
                 $name=$this->db->query("SELECT id,name from head where is_active=1 and parent_id=$id ")->result_array();
                 
                 $return="";
                 $a=1;
                 for($i=0;$i<count($name);$i++){
                 foreach ($result as $key => $value) {
                    $level = 3; 
                        
                          $val = $value['level_'.$level];
                          foreach($val as $key2 => $v) {
                            
                            $val2 = $v['level_'.($level - 1)];
                              foreach($val2 as $key3 => $vv) {
                                 
                              
                 
                         $return .= "<tr>";
             $return .= "<td>".$a++."</td>";
            
             $return .= "<td>".$vv['name']." </td>";
             $return .= "<td>".$v['name']." </td>";
             $return .= "<td>".$value['name']." </td>";
             $return .= "<td>".$name[$i]['name']."</td>";
             $return .= "<td>
             <a href='".base_url()."account/delete_level4/".$name[$i]['id']."'><i class='fa fa-trash'></i></a>
             <a     href='".base_url()."account/level4/".$name[$i]['id']."/l4'><i class='fa fa-edit'></i></a></td>";
             $return .= "</tr>";
        
                 }}}}
                 echo $return;
                 
            }
            else
                echo "";
        
    }
      public function level4_view($id=0)
    {
            if(!empty($id))
             {
                 $result=$this->account_model->getParent($id,4);
                  
                 
                 
                 $return="";
                 $a=1;
                 
                 $name=$this->db->query("SELECT id,name from head where is_active=1 and parent_id=$id ")->result_array();
                        
                 for($i=0;$i<count($name);$i++){
                 foreach ($result as $key => $value) {
                    $level = 4; 
                        
                          $val = $value['level_'.$level];
                          foreach($val as $key2 => $v) {
                            
                            $val2 = $v['level_'.($level - 1)];
                              foreach($val2 as $key3 => $vv) {
                                 
                              $val3 = $vv['level_'.($level - 2)];
                              foreach ($val3 as $key => $vvv) {
                             
                   $name12=$vvv['name'];
                         $return .= "<tr>";
             $return .= "<td>".$a++."</td>";
             $return .= "<td>".$vvv['name']." </td>";
             $return .= "<td>".$vv['name']." </td>";
             $return .= "<td>".$v['name']." </td>";
             $return .= "<td>".$value['name']." </td>";
             $return .= "<td>".$name[$i]['name']."</td>";
             $return .= "<td>
             <a href='".base_url()."account/delete_level5/".$name[$i]['id']."'><i class='fa fa-trash'></i></a>
             <a     href='".base_url()."account/level5/".$name[$i]['id']."/l5'><i class='fa fa-edit'></i></a></td>";
             $return .= "</tr>";
        
                 }}}}}
                 echo $return;
                 
            }
            else
                echo "";
        
    }
     public function level2_view($id=0)
    {
            if(!empty($id))
             {
                 $result=$this->account_model->getParent($id,2);
                 
                 $return="";
                 $a=1;
                 $name=$this->db->query("SELECT id,name from head where is_active=1 and parent_id=$id ")->result_array();
                 
                  for($i=0;$i<count($name);$i++){
                 foreach ($result as $key => $value) {
                    $level = 2; 
                        
                          $val = $value['level_'.$level];
                          foreach($val as $key2 => $v) {
                            
                           
                             
                   
                         $return .= "<tr>";
             $return .= "<td>".$a++."</td>";
            $return .= "<td>".$v['name']." </td>";
             $return .= "<td>".$value['name']." </td>";
             $return .= "<td>".$name[$i]['name']."</td>";
             $return .= "<td>
             <a     href='".base_url()."account/level3/".$name[$i]['id']."/l3'><i class='fa fa-edit'></i></a>
             <a href='".base_url()."account/delete_level3/".$name[$i]['id']."'><i class='fa fa-trash'></i></a>
             </td>";
             $return .= "</tr>";
        
                 }}}
                 echo $return;
            }
            else
                echo "";
        
    }
    public function HeadAgainstLevel2View($id=0)
    {
            if(!empty($id))
             {
                 $result = $this->db->query("SELECT * FROM `head` where parent_id=$id and is_active=1")->result_array();
                 $return="";
                 $i=1;
                 foreach ($result as $key => $value) {
                    $headname=$this->account_model->SearchId("head",$value['parent_id']);
                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
             $return .= "<td>".$headname." </td>";
             $return .= "<td>".$value['name']." </td>";
             $return .= "<td>".$value['opbalance']." </td>";
             $return .= "<td>".$value['cr_dr']." </td>";
               
             $return .= "<td>
             <a href='".base_url()."account/level2/".$value['id']."/l2'><i class='fa fa-edit'></i></a>
              
             <a href='".base_url()."account/delete_level/".$value['id']."'><i class='fa fa-trash'></i></a>";
             $return .= "</td></tr>";
        
                 }
                 echo $return;
            }
            else
                echo "";
        
    }
      public function Branch_wise($id)
    {

            if(!empty($id))
             {
                 $result = $this->db->query("SELECT main_head.id,main_head.name as mh_name,branch.name as bname,level_2.name as name FROM `level_2` inner JOIN `main_head` ON main_head.id=level_2.main_head_id inner join branch on branch.id=level_2.branch  WHERE level_2.is_delete='0' and level_2.branch=$id")->result_array();

                 $return="";
                 $i=1;
                 foreach ($result as $key => $value) {

                         $return .= "<tr>";
             $return .= "<td>".$i++."</td>";
             $return .= "<td>".$value['name']." </td>";
             $return .= "<td>".$value['mh_name']." </td>";
                $return .= "<td>".$value['bname']." </td>";
             $return .= "<td>
             <a href='".base_url()."account/delete_level3/".$value['id']."'><i class='fa fa-trash'></i></a></td>";
             $return .= "</tr>";
        
                 }
                 echo $return;
            }
            else
                echo "";
        
    }
    //_+++++++++++++++++++++++++++++++++++Ajax function for transaction+++++++++++++++++++++++++++++++++
    public function programe_against($v=0,$type="")
    {
        if($v!=0){

            $type=urldecode($type);
            $branch=$this->user_model->getbranch();
            $this->db->select("trans.*"); 
            $this->db->from('trans');
            $this->db->join('project', 'project.id=trans.project_id');
            $this->db->where('type',$type)->where('project.program_id',$v);
            if($branch!=0){
                $this->db->where('trans.branch',$branch);
            }
            $recipt = $this->db->get()->result_array();
            $rec=array();
            $i=0;
            foreach ($recipt as $key1 => $valuef) {
                $rec[$i]['name']=$valuef['name'];
                $rec[$i]['id']=$valuef['id'];
                $rec[$i]['bank']=@$this->account_model->GetBankId($valuef['bankid'])['b_name'];
                $rec[$i]['voucher#']=$valuef['voucher_no'];
                $rec[$i]['date']=$valuef['date'];
                $rec[$i]['description']=$valuef['description'];
                $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
                $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
                $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
                $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
                $junction_data=$this->account_model->search_junction($valuef['id']);
            
                foreach ($junction_data as $key => $value) {
                        if($value['dr']!=0 && $value['cr']==0){
                    $rec[$i]['detail'][$key]['type']="Dr";
                }else if($value['cr']!=0 && $value['dr']==0){
                    $rec[$i]['detail'][$key]['type']="Cr";
                }
                $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
                $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
                $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
                $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
                $rec[$i]['detail'][$key]['ammount']=$value['amount'];
            }
            $i++;
            }
            
            $return="";
            $i=1;

            if($rec!=null){
            foreach ($rec as $key => $value) 
            {
                foreach ($value['detail'] as $key => $v) 
            {  
                
                $return .= "<tr>";
                $return .= "<td>".$i++."</td>";
                $return .= "<td>".$value['programme']."</td>";
                $return .= "<td>".$value['project']."</td>";
                $return .= "<td>".$value['main']."</td>";
                $return .= "<td>".$v['level2']."</td>";
                $return .= "<td>".$v['level3']."</td>";
                $return .= "<td>".$v['level4']."</td>";
                $return .= "<td>".$v['level5']."</td>";
                if($type=="bank payment" || $type=="bank receipt" || $type=="Cash deposite"){
                    $return .= "<td>".$value['bank']."</td>";
                }
                $return .= "<td>".$value['name']."</td>";
                if($type=="journal Voucher"){

                    if ($v['type']=="Dr") { 
                        $id=0;
                        $return .= "<td>".$v['ammount']."</td>";    
                        $return .= "<td>" .$id. "</td>"; }
                    else if($v['type']=="Cr") {
                            $id=0;
                        $return .= "<td>".$id."</td>";    
                        $return .= "<td>".$v['ammount']."</td>";
                        }
                        
                }else{
                $return .= "<td>".$v['ammount']."</td>";
                }
                $return .= "<td>".$value['description']."</td>";
                $return .= "<td>".$value['date']."</td>";
                $return .= "</tr>"; 
            }
            }
            }
            echo $return;
        }
    }
    public function bank_against($v=0,$type="")
    {
        $type=urldecode($type);
        $branch=$this->user_model->getbranch();
        $this->db->select("trans.*"); 
        $this->db->from('trans');
        $this->db->join('bank_def', 'bank_def.id=trans.bankid');
        $this->db->where('trans.type',$type)->where('bank_def.id',$v);
        $this->db->where('trans.branch',$branch);
        
        $recipt = $this->db->get()->result_array();
        $return="";
        $i=1;
        $rec=array();
        $i=0;
        foreach ($recipt as $key1 => $valuef) {
            $rec[$i]['name']=$valuef['name'];
            $rec[$i]['id']=$valuef['id'];
            $rec[$i]['voucher#']=$valuef['voucher_no'];
            $rec[$i]['date']=$valuef['date'];
            $rec[$i]['bank']=@$this->account_model->GetBankId($valuef['bankid'])['b_name'];
            $rec[$i]['description']=$valuef['description'];
            $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
            $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
            $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
            $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
            $junction_data=$this->account_model->search_junction($valuef['id']);
        
            foreach ($junction_data as $key => $value) {
            $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
            $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
            $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
            $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
            $rec[$i]['detail'][$key]['ammount']=$value['amount'];
        }
        $i++;
        }
        $i=1;
        if($rec!=null){
        foreach ($rec as $key => $value) 
        {
         foreach ($value['detail'] as $key => $v) 
        {  
            $return .= "<tr>";
            $return .= "<td>".$i++."</td>";
            $return .= "<td>".$value['programme']."</td>";
            $return .= "<td>".$value['project']."</td>";
            $return .= "<td>".$value['main']."</td>";
            $return .= "<td>".$v['level2']."</td>";
            $return .= "<td>".$v['level3']."</td>";
            $return .= "<td>".$v['level4']."</td>";
            $return .= "<td>".$v['level5']."</td>";
            if($type=="bank payment" || $type=="bank receipt" || $type=="Cash deposite"){
                $return .= "<td>".$value['bank']."</td>";
            }
            $return .= "<td>".$value['name']."</td>";
            $return .= "<td>".$v['ammount']."</td>";
            $return .= "<td>".$value['description']."</td>";
            $return .= "<td>".$value['date']."</td>";
            $return .= "</tr>"; 
        }
        }
        }
        echo $return;
    }
    public function getbankinfo($id=0)
    {
        $this->db->select('*');
        $res=$this->db->where('id',$id)->get('bank_def')->row_array();
        if($res['o_balance']!=0){
            $res=array('msg' =>"Could not Edit",'o_balance'=>$res['o_balance']);
            echo json_encode($res);
        }else{
        echo json_encode($res);
    }
    }
    public function getl5byid($id=0)
    {
        $this->db->select('*');
        $res=$this->db->where('id',$id)->get('head')->row_array();
        
        echo json_encode($res);
    }
    public function project_against($v=0,$type="")
    {
        $type=urldecode($type);
        $branch=$this->user_model->getbranch();
        $this->db->select("trans.*"); 
        $this->db->from('trans');
        $this->db->join('project', 'project.id=trans.project_id');
        $this->db->where('trans.type',$type)->where('project.id',$v);
        if($branch!=0){
           $this->db->where('trans.branch',$branch);
        }
        $recipt = $this->db->get()->result_array();
        $return="";
        $i=1;
        $rec=array();
        $i=0;
        foreach ($recipt as $key1 => $valuef) {
            $rec[$i]['name']=$valuef['name'];
            $rec[$i]['id']=$valuef['id'];
            $rec[$i]['voucher#']=$valuef['voucher_no'];
            $rec[$i]['date']=$valuef['date'];
            $rec[$i]['bank']=@$this->account_model->GetBankId($valuef['bankid'])['b_name'];
            $rec[$i]['description']=$valuef['description'];
            $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
            $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
            $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
            $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
            $junction_data=$this->account_model->search_junction($valuef['id']);
        
            foreach ($junction_data as $key => $value) {
                    if($value['dr']!=0 && $value['cr']==0){
                $rec[$i]['detail'][$key]['type']="Dr";
            }else if($value['cr']!=0 && $value['dr']==0){
                $rec[$i]['detail'][$key]['type']="Cr";
            }
            $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
            $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
            $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
            $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
            $rec[$i]['detail'][$key]['ammount']=$value['amount'];
        }
        $i++;
        }
        
        $return="";
        $i=1;

        if($rec!=null){
        foreach ($rec as $key => $value) 
        {
         foreach ($value['detail'] as $key => $v) 
        {  
         
            $return .= "<tr>";
            $return .= "<td>".$i++."</td>";
            $return .= "<td>".$value['programme']."</td>";
            $return .= "<td>".$value['project']."</td>";
            $return .= "<td>".$value['main']."</td>";
            $return .= "<td>".$v['level2']."</td>";
            $return .= "<td>".$v['level3']."</td>";
            $return .= "<td>".$v['level4']."</td>";
            $return .= "<td>".$v['level5']."</td>";
            if($type=="bank payment" || $type=="bank receipt" || $type=="Cash deposite"){
                $return .= "<td>".$value['bank']."</td>";
            }
            $return .= "<td>".$value['name']."</td>";
            if($type=="journal Voucher"){

                if ($v['type']=="Dr") { 
                    $id=0;
                    $return .= "<td>".$v['ammount']."</td>";    
                    $return .= "<td>" .$id. "</td>"; }
                else if($v['type']=="Cr") {
                     $id=0;
                    $return .= "<td>".$id."</td>";    
                    $return .= "<td>".$v['ammount']."</td>";
                 }
                    
            }else{
            $return .= "<td>".$v['ammount']."</td>";
            }
            $return .= "<td>".$value['description']."</td>";
            $return .= "<td>".$value['date']."</td>";
            $return .= "</tr>"; 
        }
        }
        }
        echo $return;
        }
    
    public function main_head_against($v=0,$p=0,$type="")
    {
        $type=urldecode($type);
        $branch=$this->user_model->getbranch();$this->db->select("trans.*"); 
        $this->db->from('trans');
        $this->db->join('project', 'project.id=trans.project_id');
        $this->db->where('trans.type',$type)->where('trans.main_head',$v)->where('project.program_id',$p);
        if($branch!=0){
           $this->db->where('trans.branch',$branch);
        }
        $recipt = $this->db->get()->result_array();
        $return="";
        $i=1;
        $rec=array();
        $i=0;
            foreach ($recipt as $key1 => $valuef) {
            $rec[$i]['name']=$valuef['name'];
            $rec[$i]['id']=$valuef['id'];
            $rec[$i]['voucher#']=$valuef['voucher_no'];
            $rec[$i]['date']=$valuef['date'];
            $rec[$i]['bank']=@$this->account_model->GetBankId($valuef['bankid'])['b_name'];
            $rec[$i]['description']=$valuef['description'];
            $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
            $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
            $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
            $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
            $junction_data=$this->account_model->search_junction($valuef['id']);
        
            foreach ($junction_data as $key => $value) {
                    if($value['dr']!=0 && $value['cr']==0){
                $rec[$i]['detail'][$key]['type']="Dr";
            }else if($value['cr']!=0 && $value['dr']==0){
                $rec[$i]['detail'][$key]['type']="Cr";
            }
            $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
            $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
            $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
            $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
            $rec[$i]['detail'][$key]['ammount']=$value['amount'];
        }
        $i++;
        }
        
        $return="";
        $i=1;

        if($rec!=null){
        foreach ($rec as $key => $value) 
        {
         foreach ($value['detail'] as $key => $v) 
        {  
         
            $return .= "<tr>";
            $return .= "<td>".$i++."</td>";
            $return .= "<td>".$value['programme']."</td>";
            $return .= "<td>".$value['project']."</td>";
            $return .= "<td>".$value['main']."</td>";
            $return .= "<td>".$v['level2']."</td>";
            $return .= "<td>".$v['level3']."</td>";
            $return .= "<td>".$v['level4']."</td>";
            $return .= "<td>".$v['level5']."</td>";
            if($type=="bank payment" || $type=="bank receipt" || $type=="Cash deposite"){
                $return .= "<td>".$value['bank']."</td>";
            }
            $return .= "<td>".$value['name']."</td>";
            if($type=="journal Voucher"){

                if ($v['type']=="Dr") { 
                    $id=0;
                    $return .= "<td>".$v['ammount']."</td>";    
                    $return .= "<td>" .$id. "</td>"; }
                else if($v['type']=="Cr") {
                     $id=0;
                    $return .= "<td>".$id."</td>";    
                    $return .= "<td>".$v['ammount']."</td>";
                 }
                    
            }else{
            $return .= "<td>".$v['ammount']."</td>";
            }
            $return .= "<td>".$value['description']."</td>";
            $return .= "<td>".$value['date']."</td>";
            $return .= "</tr>"; 
        }
        }
        }
        echo $return;
        }
    
    public function level2_against($m=0,$v=0,$p=0,$type="")
    {
        $type=urldecode($type);
        $branch=$this->user_model->getbranch();
        $this->db->select('trans.*');
        $this->db->from('trans');
        $this->db->join('project', 'project.id=trans.project_id');
        $this->db->join('transaction_detail','trans.id=transaction_detail.transaction_id');
        $this->db->where('trans.type',$type)->where('transaction_detail.level2',$v)->where('project.id',$p)->where('trans.main_head',$m);
        if($branch!=0){
           $this->db->where('trans.branch',$branch);
        }
        $recipt = $this->db->group_by('trans.id')->get()->result_array();
        $return="";
        $rec=array();
        $i=0;
            foreach ($recipt as $key1 => $valuef) {
            $rec[$i]['name']=$valuef['name'];
            $rec[$i]['id']=$valuef['id'];
            $rec[$i]['voucher#']=$valuef['voucher_no'];
            $rec[$i]['date']=$valuef['date'];
            $rec[$i]['bank']=@$this->account_model->GetBankId($valuef['bankid'])['b_name'];
            $rec[$i]['description']=$valuef['description'];
            $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
            $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
            $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
            $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
            $junction_data=$this->account_model->search_junction($valuef['id']);
        
            foreach ($junction_data as $key => $value) {
                    if($value['dr']!=0 && $value['cr']==0){
                $rec[$i]['detail'][$key]['type']="Dr";
            }else if($value['cr']!=0 && $value['dr']==0){
                $rec[$i]['detail'][$key]['type']="Cr";
            }
            $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
            $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
            $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
            $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
            $rec[$i]['detail'][$key]['ammount']=$value['amount'];
        }
        $i++;
        }
        
        $return="";
        $i=1;

        if($rec!=null){
        foreach ($rec as $key => $value) 
        {
         foreach ($value['detail'] as $key => $v) 
        {  
         
            $return .= "<tr>";
            $return .= "<td>".$i++."</td>";
            $return .= "<td>".$value['programme']."</td>";
            $return .= "<td>".$value['project']."</td>";
            $return .= "<td>".$value['main']."</td>";
            $return .= "<td>".$v['level2']."</td>";
            $return .= "<td>".$v['level3']."</td>";
            $return .= "<td>".$v['level4']."</td>";
            $return .= "<td>".$v['level5']."</td>";
            if($type=="bank payment" || $type=="bank receipt" || $type=="Cash deposite"){
                $return .= "<td>".$value['bank']."</td>";
            }
            $return .= "<td>".$value['name']."</td>";
            if($type=="journal Voucher"){

                if ($v['type']=="Dr") { 
                    $id=0;
                    $return .= "<td>".$v['ammount']."</td>";    
                    $return .= "<td>" .$id. "</td>"; }
                else if($v['type']=="Cr") {
                     $id=0;
                    $return .= "<td>".$id."</td>";    
                    $return .= "<td>".$v['ammount']."</td>";
                 }
                    
            }else{
            $return .= "<td>".$v['ammount']."</td>";
            }
            $return .= "<td>".$value['description']."</td>";
            $return .= "<td>".$value['date']."</td>";
            $return .= "</tr>"; 
        }
        }
        }
        echo $return;
        }
    
    public function level3_against($m=0,$v=0,$p=0,$l2=0,$type="")
    {
        $type=urldecode($type);
        $branch=$this->user_model->getbranch();
        $this->db->select('trans.*');
        $this->db->from('trans');
        $this->db->join('project', 'project.id=trans.project_id');
        $this->db->join('transaction_detail','trans.id=transaction_detail.transaction_id');
        $this->db->where('trans.type',$type)->where('transaction_detail.level2',$l2)->where('transaction_detail.level3',$v)->where('project.id',$p)->where('trans.main_head',$m);
        if($branch!=0){
           $this->db->where('trans.branch',$branch);
        }
        $recipt = $this->db->group_by('trans.id')->get()->result_array();
        $return="";
        
        $rec=array();
        $i=0;
            foreach ($recipt as $key1 => $valuef) {
            $rec[$i]['name']=$valuef['name'];
            $rec[$i]['id']=$valuef['id'];
            $rec[$i]['voucher#']=$valuef['voucher_no'];
            $rec[$i]['date']=$valuef['date'];
            $rec[$i]['bank']=@$this->account_model->GetBankId($valuef['bankid'])['b_name'];
            $rec[$i]['description']=$valuef['description'];
            $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
            $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
            $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
            $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
            $junction_data=$this->account_model->search_junction($valuef['id']);
        
            foreach ($junction_data as $key => $value) {
                    if($value['dr']!=0 && $value['cr']==0){
                $rec[$i]['detail'][$key]['type']="Dr";
            }else if($value['cr']!=0 && $value['dr']==0){
                $rec[$i]['detail'][$key]['type']="Cr";
            }
            $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
            $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
            $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
            $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
            $rec[$i]['detail'][$key]['ammount']=$value['amount'];
        }
        $i++;
        }
        
        $return="";
        $i=1;

        if($rec!=null){
        foreach ($rec as $key => $value) 
        {
         foreach ($value['detail'] as $key => $v) 
        {  
         
            $return .= "<tr>";
            $return .= "<td>".$i++."</td>";
            $return .= "<td>".$value['programme']."</td>";
            $return .= "<td>".$value['project']."</td>";
            $return .= "<td>".$value['main']."</td>";
            $return .= "<td>".$v['level2']."</td>";
            $return .= "<td>".$v['level3']."</td>";
            $return .= "<td>".$v['level4']."</td>";
            $return .= "<td>".$v['level5']."</td>";
            if($type=="bank payment" || $type=="bank receipt" || $type=="Cash deposite"){
                $return .= "<td>".$value['bank']."</td>";
            }
            $return .= "<td>".$value['name']."</td>";
            if($type=="journal Voucher"){

                if ($v['type']=="Dr") { 
                    $id=0;
                    $return .= "<td>".$v['ammount']."</td>";    
                    $return .= "<td>" .$id. "</td>"; }
                else if($v['type']=="Cr") {
                     $id=0;
                    $return .= "<td>".$id."</td>";    
                    $return .= "<td>".$v['ammount']."</td>";
                 }
                    
            }else{
            $return .= "<td>".$v['ammount']."</td>";
            }
            $return .= "<td>".$value['description']."</td>";
            $return .= "<td>".$value['date']."</td>";
            $return .= "</tr>"; 
        }
        }
        }
        echo $return;
        }
    
     public function level4_against($m=0,$v=0,$p=0,$l2=0,$l3=0,$type="")
    {
        $type=urldecode($type);
        $branch=$this->user_model->getbranch();
        $this->db->select('trans.*');
        $this->db->from('trans');
        $this->db->join('project', 'project.id=trans.project_id');
        $this->db->join('transaction_detail','trans.id=transaction_detail.transaction_id');
        $this->db->where('trans.type',$type)->where('transaction_detail.level2',$l2)->where('transaction_detail.level3',$l3)->where('transaction_detail.level4',$v)->where('project.id',$p)->where('trans.main_head',$m);
        if($branch!=0){
           $this->db->where('trans.branch',$branch);
        }
        $recipt = $this->db->group_by('trans.id')->get()->result_array();
        $return="";
        
        $rec=array();
        $i=0;
            foreach ($recipt as $key1 => $valuef) {
            $rec[$i]['name']=$valuef['name'];
            $rec[$i]['id']=$valuef['id'];
            $rec[$i]['voucher#']=$valuef['voucher_no'];
            $rec[$i]['date']=$valuef['date'];
            $rec[$i]['bank']=@$this->account_model->GetBankId($valuef['bankid'])['b_name'];
            $rec[$i]['description']=$valuef['description'];
            $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
            $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
            $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
            $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
            $junction_data=$this->account_model->search_junction($valuef['id']);
        
            foreach ($junction_data as $key => $value) {
                    if($value['dr']!=0 && $value['cr']==0){
                $rec[$i]['detail'][$key]['type']="Dr";
            }else if($value['cr']!=0 && $value['dr']==0){
                $rec[$i]['detail'][$key]['type']="Cr";
            }
            $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
            $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
            $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
            $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
            $rec[$i]['detail'][$key]['ammount']=$value['amount'];
        }
        $i++;
        }
        
        $return="";
        $i=1;

        if($rec!=null){
        foreach ($rec as $key => $value) 
        {
         foreach ($value['detail'] as $key => $v) 
        {  
         
            $return .= "<tr>";
            $return .= "<td>".$i++."</td>";
            $return .= "<td>".$value['programme']."</td>";
            $return .= "<td>".$value['project']."</td>";
            $return .= "<td>".$value['main']."</td>";
            $return .= "<td>".$v['level2']."</td>";
            $return .= "<td>".$v['level3']."</td>";
            $return .= "<td>".$v['level4']."</td>";
            $return .= "<td>".$v['level5']."</td>";
            if($type=="bank payment" || $type=="bank receipt" || $type=="Cash deposite"){
                $return .= "<td>".$value['bank']."</td>";
            }
            $return .= "<td>".$value['name']."</td>";
            if($type=="journal Voucher"){

                if ($v['type']=="Dr") { 
                    $id=0;
                    $return .= "<td>".$v['ammount']."</td>";    
                    $return .= "<td>" .$id. "</td>"; }
                else if($v['type']=="Cr") {
                     $id=0;
                    $return .= "<td>".$id."</td>";    
                    $return .= "<td>".$v['ammount']."</td>";
                 }
                    
            }else{
            $return .= "<td>".$v['ammount']."</td>";
            }
            $return .= "<td>".$value['description']."</td>";
            $return .= "<td>".$value['date']."</td>";
            $return .= "</tr>"; 
        }
        }
        }
        echo $return;
        }
    
      public function level5_against($m=0,$v=0,$p=0,$l2=0,$l3=0,$l4=0,$type="")
    {
        $type=urldecode($type);
        $branch=$this->user_model->getbranch();
        $this->db->select('trans.*');
        $this->db->from('trans');
        $this->db->join('project', 'project.id=trans.project_id');
        $this->db->join('transaction_detail','trans.id=transaction_detail.transaction_id');
        $this->db->where('trans.type',$type)->where('transaction_detail.level2',$l2)->where('transaction_detail.level3',$l3)->where('transaction_detail.level4',$l4)->where('transaction_detail.level5',$v)->where('project.id',$p)->where('trans.main_head',$m);
        if($branch!=0){
           $this->db->where('trans.branch',$branch);
        }
        $recipt = $this->db->group_by('trans.id')->get()->result_array();
        $return="";
        
        $rec=array();
        $i=0;
            foreach ($recipt as $key1 => $valuef) {
            $rec[$i]['name']=$valuef['name'];
            $rec[$i]['id']=$valuef['id'];
            $rec[$i]['voucher#']=$valuef['voucher_no'];
            $rec[$i]['date']=$valuef['date'];
            $rec[$i]['bank']=@$this->account_model->GetBankId($valuef['bankid'])['b_name'];
            $rec[$i]['description']=$valuef['description'];
            $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
            $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
            $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
            $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
            $junction_data=$this->account_model->search_junction($valuef['id']);
        
            foreach ($junction_data as $key => $value) {
                    if($value['dr']!=0 && $value['cr']==0){
                $rec[$i]['detail'][$key]['type']="Dr";
            }else if($value['cr']!=0 && $value['dr']==0){
                $rec[$i]['detail'][$key]['type']="Cr";
            }
            $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
            $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
            $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
            $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
            $rec[$i]['detail'][$key]['ammount']=$value['amount'];
        }
        $i++;
        }
        
        $return="";
        $i=1;

        if($rec!=null){
        foreach ($rec as $key => $value) 
        {
         foreach ($value['detail'] as $key => $v) 
        {  
         
            $return .= "<tr>";
            $return .= "<td>".$i++."</td>";
            $return .= "<td>".$value['programme']."</td>";
            $return .= "<td>".$value['project']."</td>";
            $return .= "<td>".$value['main']."</td>";
            $return .= "<td>".$v['level2']."</td>";
            $return .= "<td>".$v['level3']."</td>";
            $return .= "<td>".$v['level4']."</td>";
            $return .= "<td>".$v['level5']."</td>";
            if($type=="bank payment" || $type=="bank receipt" || $type=="Cash deposite"){
                $return .= "<td>".$value['bank']."</td>";
            }
            $return .= "<td>".$value['name']."</td>";
            if($type=="journal Voucher"){

                if ($v['type']=="Dr") { 
                    $id=0;
                    $return .= "<td>".$v['ammount']."</td>";    
                    $return .= "<td>" .$id. "</td>"; }
                else if($v['type']=="Cr") {
                     $id=0;
                    $return .= "<td>".$id."</td>";    
                    $return .= "<td>".$v['ammount']."</td>";
                 }
                    
            }else{
            $return .= "<td>".$v['ammount']."</td>";
            }
            $return .= "<td>".$value['description']."</td>";
            $return .= "<td>".$value['date']."</td>";
            $return .= "</tr>"; 
        }
        }
        }
        echo $return;
        }
    
    public function datewise_cash_entry($d1='0000-00-00',$d2='0000-00-00',$type="")
    {
        $type=urldecode($type);
        $branch=$this->user_model->getbranch();
        $this->db->select('trans.*');
        $this->db->from('trans');
        $this->db->where('trans.type',$type)->where('trans.branch',$branch)->where('trans.date >=', $d1)->where('trans.date <=',$d2);
        $recipt = $this->db->get()->result_array();
        $return="";
        $rec=array();
        $i=0;
        foreach ($recipt as $key1 => $valuef) {
            $rec[$i]['name']=$valuef['name'];
            $rec[$i]['id']=$valuef['id'];
            $rec[$i]['voucher#']=$valuef['voucher_no'];
            $rec[$i]['date']=$valuef['date'];
            $rec[$i]['description']=$valuef['description'];
            $rec[$i]['project']=$this->account_model->All_project_id($valuef['project_id'])['p_name'];        
            $pid=$this->account_model->All_project_id($valuef['project_id'])['program_id'];
            $rec[$i]['programme']=$this->account_model->All_programme_id($pid)['name'];
            $rec[$i]['main']=$this->account_model->getname($valuef['main_head'])['name'];
            $junction_data=$this->account_model->search_junction($valuef['id']);
        
            foreach ($junction_data as $key => $value) {
            $rec[$i]['detail'][$key]['level2']=$this->account_model->getname($value['level2'])['name'];
            $rec[$i]['detail'][$key]['level3']=$this->account_model->getname($value['level3'])['name'];
            $rec[$i]['detail'][$key]['level4']=$this->account_model->getname($value['level4'])['name'];
            $rec[$i]['detail'][$key]['level5']=$this->account_model->getname($value['level5'])['name'];
            $rec[$i]['detail'][$key]['ammount']=$value['amount'];
        }
        $i++;
        }
        
        $return="";
        $i=1;

        if($rec!=null){
        foreach ($rec as $key => $value) 
        {
         foreach ($value['detail'] as $key => $v) 
        {  
            $return .= "<tr>";
            $return .= "<td>".$i++."</td>";
            $return .= "<td>".$value['programme']."</td>";
            $return .= "<td>".$value['project']."</td>";
            $return .= "<td>".$value['main']."</td>";
            $return .= "<td>".$v['level2']."</td>";
            $return .= "<td>".$v['level3']."</td>";
            $return .= "<td>".$v['level4']."</td>";
            $return .= "<td>".$v['level5']."</td>";
            $return .= "<td>".$value['name']."</td>";
            $return .= "<td>".$v['ammount']."</td>";
            $return .= "<td>".$value['description']."</td>";
            $return .= "<td>".$value['date']."</td>";
            $return .= "</tr>"; 
        }
        }
        }
        echo $return;
    }
    
//--=============================================Bank Payment================================

public function programe_against_bank($v=0)
{
    $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as name,project.p_name,bank_payment.main_head_id,bank_payment.level_2_id,bank_payment.level_3_id,bank_payment.level4,bank_payment.level5,bank_payment.amount,bank_payment.date,bank_payment.to_payment,bank_payment.id"); 
    $this->db->from('bank_payment');
    $this->db->join('project', 'project.id=bank_payment.project_id');
    $this->db->join('bank_def', 'bank_def.id=bank_payment.bank_id');
    $this->db->join('program','program.id=project.program_id');
    $this->db->where('bank_payment.is_delete',0)->where('bank_payment.branch',$branch)->where('project.program_id',$v);
    $query = $this->db->get()->result_array();
    
    foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
    echo json_encode($query);
}

public function project_against_bank($v=0)
{
     $branch=$this->user_model->getbranch();
   $this->db->select("bank_def.b_name,program.name as name,project.p_name,bank_payment.main_head_id,bank_payment.level_2_id,bank_payment.level_3_id,bank_payment.level4,bank_payment.level5,bank_payment.amount,bank_payment.date,bank_payment.to_payment,bank_payment.id"); 
    $this->db->from('bank_payment');
        $this->db->join('project', 'project.id=bank_payment.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_payment.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_payment.is_delete',0)->where('bank_payment.branch',$branch)->where('bank_payment.project_id',$v);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function main_head_against_bank($v=0,$p=0)
{
     $branch=$this->user_model->getbranch();
        $this->db->select("bank_def.b_name,program.name as name,project.p_name,bank_payment.main_head_id,bank_payment.level_2_id,bank_payment.level_3_id,bank_payment.level4,bank_payment.level5,bank_payment.amount,bank_payment.date,bank_payment.to_payment,bank_payment.id"); 
    $this->db->from('bank_payment');
        $this->db->join('project', 'project.id=bank_payment.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_payment.bank_id');
       $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_payment.is_delete',0)->where('bank_payment.branch',$branch)->where('bank_payment.main_head_id',$v)->where('bank_payment.project_id',$p);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function level2_against_bank($m=0,$v=0,$p=0)
{
     $branch=$this->user_model->getbranch();
        $this->db->select("bank_def.b_name,program.name as name,project.p_name,bank_payment.main_head_id,bank_payment.level_2_id,bank_payment.level_3_id,bank_payment.level4,bank_payment.level5,bank_payment.amount,bank_payment.date,bank_payment.to_payment,bank_payment.id"); 
    $this->db->from('bank_payment');
        $this->db->join('project', 'project.id=bank_payment.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_payment.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_payment.is_delete',0)->where('bank_payment.branch',$branch)->where('bank_payment.level_2_id',$v)->where('project.id',$p)->where('bank_payment.main_head_id',$m);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function level3_against_bank($m=0,$v=0,$p=0,$l2=0)
{
     $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as name,project.p_name,bank_payment.main_head_id,bank_payment.level_2_id,bank_payment.level_3_id,bank_payment.level4,bank_payment.level5,bank_payment.amount,bank_payment.date,bank_payment.to_payment,bank_payment.id"); 
    $this->db->from('bank_payment');
        $this->db->join('project', 'project.id=bank_payment.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_payment.bank_id');
       
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_payment.is_delete',0)->where('bank_payment.branch',$branch)->where('bank_payment.level_2_id',$l2)->where('bank_payment.level_3_id',$v)->where('project.id',$p)->where('bank_payment.main_head_id',$m);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
    public function level4_against_bank($m=0,$v=0,$p=0,$l2=0,$l3=0)
{
     $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as name,project.p_name,bank_payment.main_head_id,bank_payment.level_2_id,bank_payment.level_3_id,bank_payment.level4,bank_payment.level5,bank_payment.amount,bank_payment.date,bank_payment.to_payment,bank_payment.id"); 
    $this->db->from('bank_payment');
        $this->db->join('project', 'project.id=bank_payment.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_payment.bank_id');
       $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_payment.is_delete',0)->where('bank_payment.branch',$branch)->where('bank_payment.level_2_id',$l2)->where('bank_payment.level_3_id',$l3)->where('project.id',$p)->where('bank_payment.main_head_id',$m)->where('bank_payment.level4',$v);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
} public function level5_against_bank($m=0,$v=0,$p=0,$l2=0,$l3=0,$l4=0)
{
     $branch=$this->user_model->getbranch();
   $this->db->select("bank_def.b_name,program.name as name,project.p_name,bank_payment.main_head_id,bank_payment.level_2_id,bank_payment.level_3_id,bank_payment.level4,bank_payment.level5,bank_payment.amount,bank_payment.date,bank_payment.to_payment,bank_payment.id"); 
    $this->db->from('bank_payment');
        $this->db->join('project', 'project.id=bank_payment.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_payment.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_payment.is_delete',0)->where('bank_payment.branch',$branch)->where('bank_payment.level_2_id',$l2)->where('bank_payment.level_3_id',$l3)->where('project.id',$p)->where('bank_payment.main_head_id',$m)->where('bank_payment.level4',$l4)->where('bank_payment.level5',$v);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
//========================================Bank Receipt============================================
        public function programe_against_bank_recpt($v=0)
    {
        $branch=$this->user_model->getbranch();
        $this->db->select("bank_def.b_name,program.name as programename,project.p_name,bank_recpt.main_head_id,bank_recpt.level_2_id,bank_recpt.level_3_id,bank_recpt.level4,bank_recpt.level5,bank_recpt.amount,bank_recpt.date,bank_recpt.from_recpt,bank_recpt.id"); 
        $this->db->from('bank_recpt');
        $this->db->join('project', 'project.id=bank_recpt.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_recpt.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_recpt.is_delete',0)->where('bank_recpt.branch',$branch)->where('project.program_id',$v);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
        public function programe_against_cash_deposit($v=0)
{
        $branch=$this->user_model->getbranch();
       $this->db->select("bank_def.b_name,program.name as programename,project.p_name,cash_deposit.main_head_id,cash_deposit.level_2_id,cash_deposit.level_3_id,cash_deposit.level4,cash_deposit.level5,cash_deposit.amount,cash_deposit.date,cash_deposit.submit_by,cash_deposit.id"); 
        $this->db->from('cash_deposit');
        $this->db->join('project', 'project.id=cash_deposit.project_id');
        $this->db->join('bank_def', 'bank_def.id=cash_deposit.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('cash_deposit.is_delete',0)->where('cash_deposit.branch',$branch)->where('project.program_id',$v);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function bank_against_recpt($v=0)
{
    $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as programename,project.p_name,bank_recpt.main_head_id,bank_recpt.level_2_id,bank_recpt.level_3_id,bank_recpt.level4,bank_recpt.level5,bank_recpt.amount,bank_recpt.date,bank_recpt.from_recpt,bank_recpt.id"); 
        $this->db->from('bank_recpt');
        $this->db->join('project', 'project.id=bank_recpt.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_recpt.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_recpt.is_delete',0)->where('bank_recpt.branch',$branch)->where('bank_recpt.bank_id',$v);
       $query = $this->db->get()->result_array();
      foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function bank_against_cash_deposit($v=0)
{
    $branch=$this->user_model->getbranch();
     $this->db->select("bank_def.b_name,program.name as programename,project.p_name,cash_deposit.main_head_id,cash_deposit.level_2_id,cash_deposit.level_3_id,cash_deposit.level4,cash_deposit.level5,cash_deposit.amount,cash_deposit.date,cash_deposit.submit_by,cash_deposit.id"); 
        $this->db->from('cash_deposit');
        $this->db->join('project', 'project.id=cash_deposit.project_id');
        $this->db->join('bank_def', 'bank_def.id=cash_deposit.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('cash_deposit.is_delete',0)->where('cash_deposit.branch',$branch)->where('cash_deposit.bank_id',$v);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function project_against_bank_recpt($v=0)
{
    $branch=$this->user_model->getbranch();
       $this->db->select("bank_def.b_name,program.name as programename,project.p_name,bank_recpt.main_head_id,bank_recpt.level_2_id,bank_recpt.level_3_id,bank_recpt.level4,bank_recpt.level5,bank_recpt.amount,bank_recpt.date,bank_recpt.from_recpt,bank_recpt.id"); 
        $this->db->from('bank_recpt');
        $this->db->join('project', 'project.id=bank_recpt.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_recpt.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_recpt.is_delete',0)->where('bank_recpt.branch',$branch)->where('bank_recpt.project_id',$v);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function project_against_cash_deposit($v=0)
{
    $branch=$this->user_model->getbranch();
       $this->db->select("bank_def.b_name,program.name as programename,project.p_name,cash_deposit.main_head_id,cash_deposit.level_2_id,cash_deposit.level_3_id,cash_deposit.level4,cash_deposit.level5,cash_deposit.amount,cash_deposit.date,cash_deposit.submit_by,cash_deposit.id"); 
        $this->db->from('cash_deposit');
        $this->db->join('project', 'project.id=cash_deposit.project_id');
        $this->db->join('bank_def', 'bank_def.id=cash_deposit.bank_id');
       $this->db->join('program','program.id=project.program_id');
        $this->db->where('cash_deposit.is_delete',0)->where('cash_deposit.branch',$branch)->where('cash_deposit.project_id',$v);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function main_head_against_bank_recpt($v=0,$p=0)
{   
    $branch=$this->user_model->getbranch();
        $this->db->select("bank_def.b_name,program.name as programename,project.p_name,bank_recpt.main_head_id,bank_recpt.level_2_id,bank_recpt.level_3_id,bank_recpt.level4,bank_recpt.level5,bank_recpt.amount,bank_recpt.date,bank_recpt.from_recpt,bank_recpt.id"); 
        $this->db->from('bank_recpt');
        $this->db->join('project', 'project.id=bank_recpt.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_recpt.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_recpt.is_delete',0)->where('bank_recpt.branch',$branch)->where('bank_recpt.main_head_id',$v)->where('bank_recpt.project_id',$p);
        $query = $this->db->get()->result_array();
       foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function main_head_against_cash_deposit($v=0,$p=0)
{   
    $branch=$this->user_model->getbranch();
      $this->db->select("bank_def.b_name,program.name as programename,project.p_name,cash_deposit.main_head_id,cash_deposit.level_2_id,cash_deposit.level_3_id,cash_deposit.level4,cash_deposit.level5,cash_deposit.amount,cash_deposit.date,cash_deposit.submit_by,cash_deposit.id"); 
        $this->db->from('cash_deposit');
        $this->db->join('project', 'project.id=cash_deposit.project_id');
        $this->db->join('bank_def', 'bank_def.id=cash_deposit.bank_id');
       $this->db->join('program','program.id=project.program_id');
        $this->db->where('cash_deposit.is_delete',0)->where('cash_deposit.branch',$branch)->where('cash_deposit.main_head_id',$v)->where('cash_deposit.project_id',$p);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function level2_against_bank_recpt($m=0,$v=0,$p=0)
{
    $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as programename,project.p_name,bank_recpt.main_head_id,bank_recpt.level_2_id,bank_recpt.level_3_id,bank_recpt.level4,bank_recpt.level5,bank_recpt.amount,bank_recpt.date,bank_recpt.from_recpt,bank_recpt.id"); 
        $this->db->from('bank_recpt');
        $this->db->join('project', 'project.id=bank_recpt.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_recpt.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_recpt.is_delete',0)->where('bank_recpt.branch',$branch)->where('bank_recpt.level_2_id',$v)->where('project.id',$p)->where('bank_recpt.main_head_id',$m);
        $query = $this->db->get()->result_array();
       foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function level2_against_cash_deposit($m=0,$v=0,$p=0)
{
    $branch=$this->user_model->getbranch();
       $this->db->select("bank_def.b_name,program.name as programename,project.p_name,cash_deposit.main_head_id,cash_deposit.level_2_id,cash_deposit.level_3_id,cash_deposit.level4,cash_deposit.level5,cash_deposit.amount,cash_deposit.date,cash_deposit.submit_by,cash_deposit.id"); 
        $this->db->from('cash_deposit');
        $this->db->join('project', 'project.id=cash_deposit.project_id');
        $this->db->join('bank_def', 'bank_def.id=cash_deposit.bank_id');
       $this->db->join('program','program.id=project.program_id');
        $this->db->where('cash_deposit.is_delete',0)->where('cash_deposit.branch',$branch)->where('cash_deposit.level_2_id',$v)->where('project.id',$p)->where('cash_deposit.main_head_id',$m);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function level3_against_bank_recpt($m=0,$v=0,$p=0,$l2=0)
{
    $branch=$this->user_model->getbranch();
        $this->db->select("bank_def.b_name,program.name as programename,project.p_name,bank_recpt.main_head_id,bank_recpt.level_2_id,bank_recpt.level_3_id,bank_recpt.level4,bank_recpt.level5,bank_recpt.amount,bank_recpt.date,bank_recpt.from_recpt,bank_recpt.id"); 
        $this->db->from('bank_recpt');
        $this->db->join('project', 'project.id=bank_recpt.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_recpt.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_recpt.is_delete',0)->where('bank_recpt.branch',$branch)->where('bank_recpt.level_2_id',$l2)->where('bank_recpt.level_3_id',$v)->where('project.id',$p)->where('main_head.id',$m);
        $query = $this->db->get()->result_array();
       foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function level4_against_bank_recpt($m=0,$v=0,$p=0,$l2=0,$l3=0)
{
    $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as programename,project.p_name,bank_recpt.main_head_id,bank_recpt.level_2_id,bank_recpt.level_3_id,bank_recpt.level4,bank_recpt.level5,bank_recpt.amount,bank_recpt.date,bank_recpt.from_recpt,bank_recpt.id"); 
        $this->db->from('bank_recpt');
        $this->db->join('project', 'project.id=bank_recpt.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_recpt.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_recpt.is_delete',0)->where('bank_recpt.branch',$branch)->where('bank_recpt.level_2_id',$l2)->where('bank_recpt.level4',$v)->where('project.id',$p)->where('bank_recpt.main_head_id',$m)->where('bank_recpt.level_3_id',$l3);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
public function level5_against_bank_recpt($m=0,$v=0,$p=0,$l2=0,$l3=0,$l4=0)
{
    $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as programename,project.p_name,bank_recpt.main_head_id,bank_recpt.level_2_id,bank_recpt.level_3_id,bank_recpt.level4,bank_recpt.level5,bank_recpt.amount,bank_recpt.date,bank_recpt.from_recpt,bank_recpt.id"); 
        $this->db->from('bank_recpt');
        $this->db->join('project', 'project.id=bank_recpt.project_id');
        $this->db->join('bank_def', 'bank_def.id=bank_recpt.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('bank_recpt.is_delete',0)->where('bank_recpt.branch',$branch)->where('bank_recpt.level_2_id',$l2)->where('bank_recpt.level5',$v)->where('project.id',$p)->where('bank_recpt.main_head_id',$m)->where('bank_recpt.level4',$l4)->where('bank_recpt.level_3_id',$l3);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
    public function level3_against_cash_deposit($m=0,$v=0,$p=0,$l2=0)
{
    $branch=$this->user_model->getbranch();
     $this->db->select("bank_def.b_name,program.name as programename,project.p_name,cash_deposit.main_head_id,cash_deposit.level_2_id,cash_deposit.level_3_id,cash_deposit.level4,cash_deposit.level5,cash_deposit.amount,cash_deposit.date,cash_deposit.submit_by,cash_deposit.id"); 
        $this->db->from('cash_deposit');
        $this->db->join('project', 'project.id=cash_deposit.project_id');
        $this->db->join('bank_def', 'bank_def.id=cash_deposit.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('cash_deposit.is_delete',0)->where('cash_deposit.branch',$branch)->where('cash_deposit.level_2_id',$l2)->where('cash_deposit.level_3_id',$v)->where('project.id',$p)->where('cash_deposit.main_head_id',$m);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
     
          public function level4_against_cash_deposit($m=0,$v=0,$p=0,$l2=0,$l3=0)
{
    $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as programename,project.p_name,cash_deposit.main_head_id,cash_deposit.level_2_id,cash_deposit.level_3_id,cash_deposit.level4,cash_deposit.level5,cash_deposit.amount,cash_deposit.date,cash_deposit.submit_by,cash_deposit.id"); 
        $this->db->from('cash_deposit');
        $this->db->join('project', 'project.id=cash_deposit.project_id');
        $this->db->join('bank_def', 'bank_def.id=cash_deposit.bank_id');
        $this->db->join('program','program.id=project.program_id');
        $this->db->where('cash_deposit.is_delete',0)->where('cash_deposit.branch',$branch)->where('cash_deposit.level_2_id',$l2)->where('cash_deposit.level4',$v)->where('project.id',$p)->where('cash_deposit.main_head_id',$m)->where('cash_deposit.level_3_id',$l3);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
    public function level5_against_cash_deposit($m=0,$v=0,$p=0,$l2=0,$l3=0,$l4=0)
{
    $branch=$this->user_model->getbranch();
    $this->db->select("bank_def.b_name,program.name as programename,project.p_name,cash_deposit.main_head_id,cash_deposit.level_2_id,cash_deposit.level_3_id,cash_deposit.level4,cash_deposit.level5,cash_deposit.amount,cash_deposit.date,cash_deposit.submit_by,cash_deposit.id"); 
        $this->db->from('cash_deposit');
        $this->db->join('project', 'project.id=cash_deposit.project_id');
        $this->db->join('bank_def', 'bank_def.id=cash_deposit.bank_id');
       $this->db->join('program','program.id=project.program_id');
        $this->db->where('cash_deposit.is_delete',0)->where('cash_deposit.branch',$branch)->where('cash_deposit.level_2_id',$l2)->where('cash_deposit.level5',$v)->where('project.id',$p)->where('cash_deposit.main_head_id',$m)->where('cash_deposit.level_3_id',$l3)->where('cash_deposit.level4',$l4);
        $query = $this->db->get()->result_array();
        foreach ($query as $key => $value) {
        $main=$this->account_model->getname($value['main_head_id'])['name'];
        $l2=$this->account_model->getname($value['level_2_id'])['name'];
        $l3=$this->account_model->getname($value['level_3_id'])['name'];
        $l4=$this->account_model->getname($value['level4'])['name'];
        $l5=$this->account_model->getname($value['level5'])['name'];
        $query[$key]['main'] = $main;
        $query[$key]['l2'] = $l2;
        $query[$key]['l3'] = $l3;
        $query[$key]['l4'] = $l4;
        $query[$key]['l5'] = $l5;
        }
        echo json_encode($query);
}
    public function level5againstallhead($id=0)
    {
        $this->db->select('*')->where('id',$id)->where('is_delete',0);
        $result=$this->db->get('assign_account')->result_array();
        $re=array();
        foreach ($result as $key => $value) {
            $re['main_name']=$this->account_model->getname($value['main_head'])['name'];
            $re['main_id']=$this->account_model->getname($value['main_head'])['id'];
            $re['level2_name']=$this->account_model->getname($value['level2'])['name'];
            $re['level2_id']=$this->account_model->getname($value['level2'])['id'];
            $re['level3_name']=$this->account_model->getname($value['level3'])['name'];
            $re['level3_id']=$this->account_model->getname($value['level3'])['id'];
            $re['level4_name']=$this->account_model->getname($value['level4'])['name'];
            $re['level4_id']=$this->account_model->getname($value['level4'])['id'];
            $re['opbalance']=$this->account_model->search('head',$value['level5'])['opbalance'];
            $re['cr_dr']=$this->account_model->search('head',$value['level5'])['cr_dr'];
        }
        echo json_encode($re);
    }
    public function check_assigning()
    {
        if($_POST){
            $data=$_POST;
            $this->db->select('*');
            $this->db->where('branch',$data['branch'])->where('programe_id',$data['prog'])->where('project',$data['proj']);
            $this->db->where('main_head',$data['main'])->where('level2',$data['l2'])->where('level3',$data['l3']);
            $this->db->where('level4',$data['l4'])->where('level5',$data['l5'])->where('bankid',$data['bank'])->where('is_delete',0);
            $v=$this->db->get('assign_account')->row_array();
            $count=count($v);
            if($count>0){
            echo 1;
            }else{
                echo 0;
            }
        }else{        echo "could not post";}
        
        
    }

  
  
}
