<?php
class pipelinectrl{
    public function salestotalpendingdealamount($companyname, $month, $year){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_total_pending_deal_amount($companyname, $month, $year);
        //print_r($result);
        return $result;
    }
    
    public function salestotalpendingdealamountyearly($companyname,$ye){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_total_pending_deal_amount_yearly($companyname,$ye);
        //print_r($result);
        return $result;
    }
    public function salesinsertcommontarget($companyname, $emailid, $amount, $createby, $createtype, $datetime){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_insert_common_target($companyname, $emailid, $amount, $createby, $createtype, $datetime);
        //print_r($result);
        return $result;
    }
    public function salesinsertpipelinetargetmonth($companyname, $emailid, $amount, $month, $year, $createby, $createtype, $datetime){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_insert_pipeline_target_month($companyname, $emailid, $amount, $month, $year, $createby, $createtype, $datetime);
        print_r($result);
        return $result;
    }
    public function salespipelinedeal($companyname,$emailid){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_deal($companyname,$emailid);
        return $result;
    }
    public function salespipelinedealmonth($companyname,$month,$year){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_deal_month($companyname,$month,$year);
        return $result;
    }
    public function salespipelinedealmonthstage($companyname,$month,$year,$stage){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_deal_month_stage($companyname,$month,$year,$stage);
        return $result;
    }
    public function salespipelineemployeetarget($companyname,$email,$year,$month){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_employee_target($companyname,$email,$year,$month);
        return $result;
    }
    public function salescommontarget($companyname,$email){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_common_target($companyname,$email);
        return $result;
    }
    public function salespipelineemployeedealmonth($email, $year, $month){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_employee_deal_month($email,$year,$month);
        foreach($result as $totaldeal_row){
                    $totaldealwon=$totaldealwon+$totaldeal_row['d_amount'];
            }
        return $totaldealwon;    
    }
    public function salespipelineemployeedealmonthstage($email,$year,$month,$stage){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_employee_deal_month_stage($email,$year,$month,$stage);
        return $result;
    }
    public function salesemployeetotalpendingdealamount($email, $year, $month){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_employee_total_pending_deal_amount($email, $year, $month);
        //print_r($result);
        return $result;
    }
    
    public function salespipelineexpected_total($companyname,$month,$year){
      include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipe_line_expected_total($companyname, $month, $year);
        //print_r($result);
        foreach($result as $r){
            $value=$r['deal_amount'];
        }
        return $value;  
    }
    
    public function salespipeline_find_percentage($stage){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_find_percentage($stage);
        //print_r($result);
        foreach($result as $r){
            $value=$r['pipe_percentage'];
        }
        return $value;   
    }
    public function salespipelinestage_total($companyname,$month,$year){
      include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_stage_total($companyname, $month, $year);
        //print_r($result);
        
        return $result;  
    }
    
    public function salespipelineexpected_yearly_total($companyname,$year){
         include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipe_line_expected_yearly_total($companyname,$year);
        //print_r($result);
        foreach($result as $r){
            $value=$r['deal_amount'];
        }
        return $value; 
    }
    
    public function salespipelineexpected_quartely_total($companyname,$id,$year){
       if($id==01){
           $mon1="01";
           $mon2="02";
           $mon3="03";
       }
        if($id==02){
           $mon1="04";
           $mon2="05";
           $mon3="06";
       }
       if($id==03){
           $mon1="07";
           $mon2="08";
           $mon3="09";
       }
       if($id==04){
           $mon1="10";
           $mon2="11";
           $mon3="12";
       }
       include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipe_line_expected_quartely_total($companyname,$mon1,$mon2,$mon3,$year);
        //print_r($result);
        foreach($result as $r){
            $value=$r['deal_amount'];
        }
        return $value; 
    }
    
    public function sales_per_quartely_select($companyname,$stage,$id,$y_q){
        if($id==01){
           $mon1="01";
           $mon2="02";
           $mon3="03";
       }
        if($id==02){
           $mon1="04";
           $mon2="05";
           $mon3="06";
       }
       if($id==03){
           $mon1="07";
           $mon2="08";
           $mon3="09";
       }
       if($id==04){
           $mon1="10";
           $mon2="11";
           $mon3="12";
       }
       include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_per_quartely_select_stage($companyname,$stage,$mon1,$mon2,$mon3,$y_q);
        //print_r($result);
        foreach($result as $r){
            $value=$r['deal_amount'];
        }
        return $value;
    }
    
    public function salestotalpendingdealamountquartely($companyname,$id,$y_q){
         if($id==01){
           $mon1="01";
           $mon2="02";
           $mon3="03";
       }
        if($id==02){
           $mon1="04";
           $mon2="05";
           $mon3="06";
       }
       if($id==03){
           $mon1="07";
           $mon2="08";
           $mon3="09";
       }
       if($id==04){
           $mon1="10";
           $mon2="11";
           $mon3="12";
       }
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_total_pending_deal_amount_quartely($companyname,$mon1,$mon2,$mon3,$y_q);
        //print_r($result);
       
        return $result;
    }
    
    public function salespipelinedealyear($cmp,$year){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_deal_year($cmp,$year);
        return $result;
    }
    
    public function salespipelinedealyearstage($companyname,  $year, $stage){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_deal_year_stage($companyname,$year,$stage);
        return $result;
    }
    
    public function salespipelinedealquart($companyname,$mon1,$mon2,$mon3, $year){
        include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_deal_quart($companyname,$mon1,$mon2,$mon3, $year);
        return $result;
    }
    
    public function salespipelinedealquartstage($companyname, $mon1,$mon2,$mon3, $year, $stage){
         include_once('../Model/pipeline.php');
        $dbobj=new pipelinedb();
        $result=$dbobj->sales_pipeline_deal_quart_stage($companyname,$mon1,$mon2,$mon3, $year,$stage);
        return $result;
    }
    
}
?>