<?php
class pipelinedb{
    public function sales_total_pending_deal_amount($companyname, $month, $year){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_total_pending_deal_amount("'.$companyname.'","'.$month.'","'.$year.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_total_pending_deal_amount_yearly($companyname,$ye){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_total_pending_deal_amount_yearly("'.$companyname.'","","'.$ye.'","yearly")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_insert_common_target($companyname, $emailid, $amount, $createby, $createtype, $datetime){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_insert_common_target("'.$companyname.'","'.$emailid.'","'.$amount.'","'.$createby.'","'.$createtype.'","'.$datetime.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_insert_pipeline_target_month($companyname, $emailid, $amount, $month, $year, $createby, $createtype, $datetime){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_insert_pipeline_target_month("'.$companyname.'","'.$emailid.'","'.$amount.'","'.$month.'","'.$year.'","'.$createby.'","'.$createtype.'","'.$datetime.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_pipeline_deal($companyname,$emailid){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_deal("'.$companyname.'","'.$emailid.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_pipeline_deal_month($companyname,$month,$year){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_deal_month("'.$companyname.'","'.$month.'","'.$year.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_pipeline_deal_year($cmp,$year){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_deal_year("'.$cmp.'","'.$year.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_pipeline_deal_month_stage($companyname,$month,$year,$stage){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_deal_month_stage("'.$companyname.'","'.$month.'","'.$year.'","'.$stage.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_pipeline_employee_target($companyname,$email,$year,$month){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_employee_target("'.$companyname.'","'.$email.'","'.$year.'","'.$month.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_common_target($companyname,$email){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_common_target("'.$companyname.'","'.$email.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_pipeline_employee_deal_month($email,$year,$month){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_employee_deal_month("'.$email.'","'.$year.'","'.$month.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);ssales_pipeline_employee_deal_month_stage
        return $result;
    }
    public function sales_pipeline_employee_deal_month_stage($email,$year,$month,$stage){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_employee_deal_month_stage("'.$email.'","'.$year.'","'.$month.'","'.$stage.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_employee_total_pending_deal_amount($email, $year, $month){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_employee_total_pending_deal_amount("'.$email.'","'.$year.'","'.$month.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_pipe_line_expected_total($companyname, $month, $year){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_expected_total("'.$companyname.'","'.$month.'","'.$year.'","expected_total")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_pipeline_find_percentage($stage){
        include 'configuration.php';
        $sql="SELECT `pipe_percentage` FROM `sales_pipeline_type` WHERE `id`='$stage'";
        $result=mysqli_query($conn,$sql);
        return $result;
    }
    
    public function sales_pipeline_stage_total($companyname, $month, $year){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_expected_total("'.$companyname.'","'.$month.'","'.$year.'","expected_stage")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_pipe_line_expected_yearly_total($companyname,$year){
         include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_expected_total("'.$companyname.'","","'.$year.'","yearly_total")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    public function sales_pipe_line_expected_quartely_total($companyname,$mon1,$mon2,$mon3,$year){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_expected_quaretely_total("'.$companyname.'","'.$mon1.'","'.$mon2.'","'.$mon3.'","'.$year.'","expected")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_per_quartely_select_stage($companyname,$stage,$mon1,$mon2,$mon3,$year){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_percentage_quartely_total("'.$companyname.'","'.$stage.'","'.$mon1.'","'.$mon2.'","'.$mon3.'","'.$year.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_total_pending_deal_amount_quartely($companyname,$mon1,$mon2,$mon3,$y_q){
         include 'configuration.php';
         $result=$pdo->prepare('call sales_pipeline_expected_quaretely_total("'.$companyname.'","'.$mon1.'","'.$mon2.'","'.$mon3.'","'.$y_q.'","pending_quartely")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_pipeline_deal_year_stage($companyname,$year,$stage){
        include 'configuration.php';
        $result=$pdo->prepare('call sales_pipeline_deal_year_stage("'.$companyname.'","'.$year.'","'.$stage.'")');
        $result->execute();
        $pdo=null;
        //print_r($result);
        return $result;
    }
    
    public function sales_pipeline_deal_quart($companyname,$mon1,$mon2,$mon3, $year){
         include 'configuration.php';
         $sql="select * from sales_pipeline_deal where ( (MONTH(d_date) ='$mon1') OR (MONTH(d_date) ='$mon2') OR (MONTH(d_date) ='$mon3') ) and year(d_date)='$year' and companyname='$companyname' ";
        $result=$pdo->prepare($sql);
        $result->execute();
        $pdo=null;
        return $result;
    }
    
    public function sales_pipeline_deal_quart_stage($companyname,$mon1,$mon2,$mon3, $year,$stage){
         include 'configuration.php';
         $sql="select * from sales_pipeline_deal where ( (MONTH(d_date)='$mon1') OR (MONTH(d_date)='$mon2') OR (MONTH(d_date)='$mon3') ) and year(d_date)='$year' and sales_pipeline_deal.d_deal_by='$companyname' and sales_pipeline_deal.d_stage='$stage'";
        $result=$pdo->prepare($sql);
        $result->execute();
        return $result;
    }
    
}
?>