<?php
session_start();
$companyname=$_SESSION['companyname'];//;
$adminemailid=$_SESSION['emailid'];//;
$companytype=$_SESSION['companytype'];
include('sesssion_clear.php');
$employeetype=$_SESSION['employeetype'];
//if(($adminemailid !="")&&($companyname!="")){
        include('../Model/configuration.php');
require_once('../Control/sales.php');
$objsales=new salesctrl();
require_once('../Control/pipeline.php');
$objpipeline=new pipelinectrl();
$pipelinetype_res=$objsales->salesselectall($companyname, $adminemailid, "sales_pipe_type", "no");
$i=0;
$pipe_name=array();
$pipe_percentage=array();
foreach($pipelinetype_res as $pipelinetype_row){
    $pipe_id[$i]=$pipelinetype_row['id'];
    $pipe_name[$i]=$pipelinetype_row['pipe_name'];
    $pipe_percentage[$i]=$pipelinetype_row['pipe_percentage'];
    //echo $pipelinetype_row['pipe_percentage'];
    $i++;
}
//print_r($pipe_name);

$pipelinetype_res=$objpipeline->salespipelinedeal($companyname,"");
$emp_res=$objsales->salesselectall($companyname, $adminemailid, "signupdetails", "no");
$email_array=[];
$employeename_array=[];

$j=0;
foreach($emp_res as $emp_row){
 $emp_emailid_a[$j++]=$emp_row['emailid'];  
 $emp_employeename[$j++]=$emp_row['employeename'];
  array_push($email_array,$emp_row['emailid']);
    array_push($employeename_array,$emp_row['employeename']);
}
$emp_count= count($emp_emailid_a);

?>
<?php

$mon=date('m');
$yea=date('Y');


$month=date('M');
$year=date('Y');
$months=$year."-".$month;

?>

<!doctype html>
<html>
    <head>
    
<link rel="icon" href="../../Images/cloud-icon-27.png">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../../Bootstrap/css/bootstrap.min.css">
<script src="../../Bootstrap/jquery.min.js"></script>
<script src="../../Bootstrap/js/bootstrap.min.js"></script>
<script src="../../Bootbox/bootbox.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.js"></script>
        
    <!-- data Table -->
<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/Css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/Css/buttons.bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/Css/dataTables.bootstrap.min.css"/>


<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/hide/responsive.bootstrap.min.css"/>

<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/buttons.bootstrap.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/jszip.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/pdfmake.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/vfs_fonts.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/buttons.html5.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/buttons.print.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/buttons.colVis.min.js"></script>


<link rel="stylesheet" type="text/css" href="Css/pipeline.css"/>
<style>
    .row{
        margin:0px;
        padding:0px;
    }
::-webkit-scrollbar {
    width: .1em;
    height: .1em
}

    #pipeline1{
        background: #db1b56;
        height: 40px;
        display: block;
        color: #ffffff;
        font-size: 21px;
        font-family: "Open Sans Bold", Arial, Helvetica, sans-serif;
        font-weight: normal;
        line-height: 0.7;
        padding: 9px 0 0px 0;
        margin: 0 -10px;
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        border-radius: 4px;
        box-sizing: border-box;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        -ms-box-sizing: border-box;
    }
    #pipeline2{
        background: #9999cc;
        height: 50px;
        display: block;
        color: #ffffff;
        font-size: 21px;
        font-family: "Open Sans Bold", Arial, Helvetica, sans-serif;
        font-weight: normal;
        line-height: 0.6;
        padding: 9px 0 0px 0;
        margin: 0 -10px;
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        border-radius: 4px;
        box-sizing: border-box;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        -ms-box-sizing: border-box;
    }
    #pipeline3{
        background: #c6c3be;
        height: 40px;
        display: block;
        color: #ffffff;
        font-size: 21px;
        font-family: "Open Sans Bold", Arial, Helvetica, sans-serif;
        font-weight: normal;
        line-height: 0.6;
        padding: 9px 0 0px 0;
        margin: 0 -10px;
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        border-radius: 4px;
        box-sizing: border-box;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        -ms-box-sizing: border-box;
    }
    .open>.dropdown-menu {
    display: block;
    margin: 38px -250px;
}
             .menu>li.sales a:hover:before{
                background-position: -20px 0;
            }
            .menu>li.sales a.active:before {
                background-position: -20px 0;
            }
             .menu>li.sales a:before {
                width: 13px;
                height: 11px;
                background-position: -20px 0;
                top: 5px;
                left: 27px;
            }
             .menu>li.sales a:after {
                width: 13px;
                height: 11px;
                background-position: -20px 0;
                top: 5px;
                left: 27px;
            }
             .menu>li.activity a:hover:before{
                background-position: -80px 0;
            }
            .menu>li.activity a.active:before {
                background-position: -80px 0;
            }
             .menu>li.activity a:before {
                width: 13px;
                height: 11px;
                background-position: -20px 0;
                top: 3px;
                left: 23px;
            }
            .menu>li.sales a:before {
                background: url(Image/pipelinemenu.png) no-repeat 0 0 transparent;
                width: 18px;
                height: 18px;
                display: block;
                position: absolute;
                content: "";
                background-position: -35px 0;
            }
            .menu>li.activity a:before {
                background: url(Image/pipelinemenu.png) no-repeat 0 0 transparent;
                width: 18px;
                height: 18px;
                display: block;
                position: absolute;
                content: "";
                background-position: -60px 0px;
            }
             .menu>li.user a:hover:before{
                background-position: -80px 0;
            }
            .menu>li.user a.active:before {
                background-position: -80px 0;
            }
             .menu>li.user a:before {
                width: 13px;
                height: 11px;
                background-position: -20px 0;
                top: 3px;
                left: 23px;
            }
            .menu>li.user a:before {
                background: url(Image/activity_icons.png) no-repeat 0 0 transparent;
                width: 18px;
                height: 18px;
                display: block;
                position: absolute;
                content: "";
                background-position: -16px -61px;
            }
            .left-link {
                width: 183px;
                padding: 7px 0px 7px 0px;
                width: 135px;
                display: block;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }
            .left-link:hover{
                background: #ecf6fd;
                cursor:pointer;
            }
            .my_team{
                max-height:100%;
                background-color: #F5F5F5;
            }
</style>
   
    </head>
    
    <body style="padding-top:50px;">
        <nav id="mainNav" class="navbar navbar-inverse  navbar-fixed-top">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header page-scroll">
                 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
                <a href="#page-top"><img alt="Cloud" src="http://fieldcloud.in/Web/Images/cloud-icon-27.png" width="50px" height="50px"> <span style="font-size:2em;color: White;"> Field</span><span style="font-size:2em;color: orange;">Cloud</span></a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                
          
                 <ul class="nav navbar-nav navbar-right menu">
                    <li>
                        <a class="page-scroll pull-left" href="dashboard.php">Action Stream</a>
                    </li>
                    <li>
                        <a class="page-scroll pull-left" href="dashboard_contact.php">Contact</a>
                    </li>
                    <li class="sales">
                        <a style="top:5px;" style="color:white;" href="pipeline_view.php">Pipeline</a>
                    </li>
                    <li class="activity">
                        <a style="top:5px;"  href="activity_all.php">Activity</a>
                    </li>
                    
                    <?php if($employeetype=="admin") {?>
                    <li class="user">
                        <a style="top:5px;"  href="user_dashboard.php">User</a>
                    </li>
                    <?php } ?>
                    
                    <li>
                    <a href="logout.php">Logout</a>
                    </li>
                    <?php if((strpos($companytype,'Project') !== false) || (strpos($companytype,'Service') !== false)){ ?>
                    <li>
                    <a  href="../../../home.php">Switch to Home</a>
                    </li>
                    <?php } ?>
                    </ul>
                    
                    </li>
                    </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
        </nav>
       
        <script>
            function modelboxpipeline(){
                $("#addpipelineeditpage").load('pipeline_edit.php');
            }
        </script>
<!-- Modal -->
<div id="modalpipeline" class="modal fade" role="dialog">
  <div class="modal-dialog modal-lg">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-body">
          <div class="row">
            <span style="font-size:20px;font-family: 'Times New Roman', Times, serif;"><b><center>Add/Edit funnel stages</center></b></span>
             <span style="pull-right"><button type="button" class="close" data-dismiss="modal">&times;</button></span>
         </div>
        <div id="addpipelineeditpage" ></div>
      </div>
    </div>

  </div>
</div>



        <div class="row" style="padding-top: 30px;height: 72px;padding-left:100px;padding-right:100px;border-bottom:2px solid grey">
            <span class="col-md-3 col-sm-3">
                
                <select class="form-control" onchange="fetch_pipeline_employee()" id="emp_email">
                    <option value="all" selected>All Team Members</option>
                     <?php 
                   foreach($email_array as $a=>$b){ ?>
                   
                   <option  value="<?php echo $email_array[$a]?>"><?php if($email_array[$a]==$adminemailid){echo "me($employeename_array[$a])"; } else { echo $employeename_array[$a];}?></option>
                   <?php
                   }
                 ?>    
                </select>
            </span>
            <span class="pull-right" style="margin-right:20px;">
                <span onclick="modelboxpipeline()"  data-toggle="modal" data-target="#modalpipeline" style="color:#999;cursor:pointer;"><i class="glyphicon glyphicon-pencil"></i> &nbsp;Edit</span>
            </span>
        </div>
        <script>
            function fetch_pipeline_employee(){
                var emp_email=$("#emp_email").val();
                if(emp_email=="all"){
                    $("#employee_list").hide();
                    $("#full_employee_list").show();
                }else{
                    $("#employee_list").show();
                    $("#full_employee_list").hide();
                    $.post("pipeline_employee_filter.php",{filtebyemp:emp_email},function myresult(data1){
                       $('#employee_list').html(data1);
                   }); 
                }
            }
        </script>
        
        <script>
            $(document).ready(function(){
               
                 $('#monthly_view').show();
                $('#yearly_view').hide();
                 $('#quartely_view').hide();
                
            });
        </script>
        <script>
            function funcshowrecord1(id1, id2, id3){
                $(id1).show();
                $(id2).hide();
                $(id3).hide();
                $('#monthly_view').show();
                $('#yearly_view').hide();
                  $('#quartely_view').hide();
                $("#btnm1").addClass("active");
                $("#btnm2").removeClass("active");
                $("#btnm3").removeClass("active");
                
            }
            
            function funcshowrecord2(id1, id2, id3){
                $(id1).show();
                $(id2).hide();
                $(id3).hide();
                $('#monthly_view').hide();
                $('#yearly_view').hide();
                  $('#quartely_view').show();
                $("#btnm2").addClass("active");
                $("#btnm1").removeClass("active");
                $("#btnm3").removeClass("active");
                
            }
            
            function funcshowrecord3(id1, id2, id3){
                $(id1).show();
                $(id2).hide();
                $(id3).hide();
                $('#monthly_view').hide();
                $('#yearly_view').show();
                  $('#quartely_view').hide();
                $("#btnm3").addClass("active");
                $("#btnm2").removeClass("active");
                $("#btnm1").removeClass("active");
                
            }
        </script>
    <div id="full_employee_list">
        <div style="background-color:#f6f6f6">
            
            <div class="summary" style="padding: 20px 100px ;" id="show_emp_filter">
                
                
                <div style="border:1px solid #D5D5D5;padding:5px;width:98%;margin-left: 6px;">  
                    <div class="row">
                        <div class="col-sm-3"style="padding-top:5px;">
                            <button onclick="funcshowrecord1('#monthlyshow','#quarterlyshow','#yearlyshow')" id="btnm1" class="btn btn-default active" style="margin-left:0px">Month</button>
                            <button onclick="funcshowrecord2('#quarterlyshow','#monthlyshow','#yearlyshow')" id="btnm2" class="btn btn-default" style="margin-left:-6px">Quarter</button>
                            <button onclick="funcshowrecord3('#yearlyshow','#quarterlyshow','#monthlyshow')" id="btnm3" class="btn btn-default" style="margin-left:-6px">Year</button>
                        </div>
                        <div class="col-sm-9" id="monthlyshow">
                            <div id="my-month">
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <button id="m1" class="btn btn-default pull-right" next_month="<?php echo date('M', strtotime("-2 months") ); ?>" my_year="<?php echo date('Y', strtotime("-2 months") );?>"  style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime("-2 months")); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime("-2 months"));?></b></button>
                                <button class="btn btn-primary pull-left" onclick="previewsrecordmonth()" style="display:inline;padding:5px;"><i class="glyphicon glyphicon-triangle-left"></i></button>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="m2" class="btn btn-default"  style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime('-1 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime('-1 month')); ?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="m3" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M'); ?>&nbsp;&nbsp;<?php echo date('Y'); ?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="m4" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime('+1 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime('+3 month')); ?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="m5" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime('+2 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime('+2 month')); ?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;">
                                <center><button id="m6" class="btn btn-default pull-left" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime('+3 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime('+3 month')); ?></b></button></center>
                                <button  class="btn btn-primary pull-right" onclick="nextrecordmonth()" style="display:inline;padding:5px;"><i class="glyphicon glyphicon-triangle-right"></i></button>
                            </div>
                            </div>
                            <input type="hidden" id="condition_button" value="123"/>
                        </div>
                       
                        <?php
                        $mm=date('m', strtotime("-6 months"));
                        $yy=date('Y', strtotime("-6 months"));
                        if($mm<=3){
                             $Q11="Q1 ".$yy;
                            $Q12="Q2 ".$yy;
                            $Q13="Q3 ".$yy;
                            $Q14="Q4 ".$yy;
                            $Q15="Q1 ".($yy+1);
                            $Q16="Q2 ".($yy+1);
                        }
                        if($mm>=4 && $mm <=6){
                            $Q11="Q2 ".$yy;
                            $Q12="Q3 ".$yy;
                            $Q13="Q4 ".$yy;
                            $Q14="Q1 ".($yy+1);
                            $Q15="Q2 ".($yy+1);
                            $Q16="Q3 ".($yy+1);
                        }if($mm>=7 && $mm <=9){
                            $Q11="Q3 ".$yy;
                            $Q12="Q4 ".$yy;
                            $Q13="Q1 ".($yy+1);
                            $Q14="Q2 ".($yy+1);
                            $Q15="Q3 ".($yy+1);
                            $Q16="Q4 ".($yy+1);
                        }if($mm>=10 && $mm <=12){
                            $Q11="Q4 ".$yy;
                            $Q12="Q1 ".($yy+1);
                            $Q13="Q2 ".($yy+1);
                            $Q14="Q3 ".($yy+1);
                            $Q15="Q4 ".($yy+1);
                            $Q16="Q1 ".($yy+2);
                        }
                        ?>
                        <div class="col-sm-9" id="quarterlyshow" style="display:none;">
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <button id="q1" class="btn btn-default pull-right" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo $Q11;?></b></button>
                                <button class="btn btn-primary pull-left" onclick="mypreviousquarterly();" style="display:inline;padding:5px;"><i class="glyphicon glyphicon-triangle-left"></i></button>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="q2" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo $Q12?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="q3" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo $Q13;?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="q4" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo $Q14;?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="q5" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo $Q15;?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;">
                                <center><button id="q6" class="btn btn-default pull-left" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo $Q16;?></b></button></center>
                                <button  class="btn btn-primary pull-right" onclick="mynextquarterly();" style="display:inline;padding:5px;"><i class="glyphicon glyphicon-triangle-right"></i></button>
                            </div>
                       
                        </div>
                        
                        <div class="col-sm-9" id="yearlyshow" style="display:none;" >
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <button id="y1" class="btn btn-default pull-right" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('Y',strtotime('-2 year'));?></b></button>
                                <button class="btn btn-primary pull-left" onclick="mypreviousyear()" style="display:inline;padding:5px;"><i class="glyphicon glyphicon-triangle-left"></i></button>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="y2" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('Y',strtotime('-1 year'));?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="y3" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('Y');?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="y4" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('Y',strtotime('+1 year'));?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="y5" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('Y',strtotime('+2 year'));?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;">
                                <center><button id="y6" class="btn btn-default pull-left" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('Y',strtotime('+3 year'));?></b></button></center>
                                <button  class="btn btn-primary pull-right" onclick="mynextyear()" style="display:inline;padding:5px;"><i class="glyphicon glyphicon-triangle-right"></i></button>
                            </div>
                            
                        </div>
                    </div>
                   
                   <script>
                       function fetch_won(){
                           $('#wonpending').val("won");  
                           var whattype=$("#whattype").val();
                           if(whattype=="monthly"){
                               var startmonth=$("#startmonth").val();
                               $.post("date_intermediate1.php",{expected_won:startmonth},function myresult(data){
                                  $('#mycontent').html('Total Won');
                                   $('#exe_result').html(data);
                               });
                           }
                           var value=$.trim(value1);
                   //alert(value);
                       }
                       
                       function fetch_won_expected(){
                           $('#wonpending').val("wonpending");  
                           var whattype=$("#whattype").val();
                           if(whattype=="monthly"){ 
                               var startmonth=$("#startmonth").val();
                               $.post("date_intermediate1.php",{expected_won_pending:startmonth},function myresult(data1){
                                  $('#mycontent').html('Won+Pending');
                                   $('#exe_result').html(data1);
                               }); 
                           }
                       }
                       function headmonth(month,year){
                            var month_array = ["","Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct", "Nov", "Dec"];
                           month=parseInt(month);
                           year=parseInt(year);
                            if(month==1){
                                m1=month_array[1];m2=month_array[2];m3=month_array[3];m4=month_array[4];m5=month_array[5];m6=month_array[6];
                                y1=year;y2=year;y3=year;y4=year;y5=year;y6=year;
                            }
                            if(month==2){
                                m1=month_array[2];m2=month_array[3];m3=month_array[4];m4=month_array[5];m5=month_array[6];m6=month_array[7];
                                y1=year;y2=year;y3=year;y4=year;y5=year;y6=year;
                            }
                            if(month==3){
                                m1=month_array[3];m2=month_array[4];m3=month_array[5];m4=month_array[6];m5=month_array[7];m6=month_array[8];
                                y1=year;y2=year;y3=year;y4=year;y5=year;y6=year;
                            }
                            if(month==4){
                                m1=month_array[4];m2=month_array[5];m3=month_array[6];m4=month_array[7];m5=month_array[8];m6=month_array[9];
                                y1=year;y2=year;y3=year;y4=year;y5=year;y6=year;
                            }
                            if(month==5){
                                m1=month_array[5];m2=month_array[6];m3=month_array[7];m4=month_array[8];m5=month_array[9];m6=month_array[10];
                                y1=year;y2=year;y3=year;y4=year;y5=year;y6=year;
                            }
                            if(month==6){
                                m1=month_array[6];m2=month_array[7];m3=month_array[8];m4=month_array[9];m5=month_array[10];m6=month_array[11];
                                y1=year;y2=year;y3=year;y4=year;y5=year;y6=year;
                            }
                            if(month==7){
                                m1=month_array[7];m2=month_array[8];m3=month_array[9];m4=month_array[10];m5=month_array[11];m6=month_array[12];
                                y1=year;y2=year;y3=year;y4=year;y5=year;y6=year;
                            }
                            if(month==8){
                                m1=month_array[8];m2=month_array[9];m3=month_array[10];m4=month_array[11];m5=month_array[12];m6=month_array[1];
                                y1=year;y2=year;y3=year;y4=year;y5=year;y6=year+1;
                            }
                            if(month==9){
                                m1=month_array[9];m2=month_array[10];m3=month_array[11];m4=month_array[12];m5=month_array[1];m6=month_array[2];
                                y1=year;y2=year;y3=year;y4=year;y5=year+1;y6=year+1;
                            }
                            if(month==10){
                                m1=month_array[10];m2=month_array[11];m3=month_array[12];m4=month_array[1];m5=month_array[2];m6=month_array[3];
                                y1=year;y2=year;y3=year;y4=year+1;y5=year+1;y6=year+1;
                            }
                            if(month==11){
                                m1=month_array[11];m2=month_array[12];m3=month_array[1];m4=month_array[2];m5=month_array[3];m6=month_array[4];
                                y1=year;y2=year;y3=year+1;y4=year+1;y5=year+1;y6=year+1;
                            }
                            if(month==12){
                                m1=month_array[12];m2=month_array[1];m3=month_array[2];m4=month_array[3];m5=month_array[4];m6=month_array[5];
                                y1=year;y2=year+1;y3=year+1;y4=year+1;y5=year+1;y6=year+1;
                            }
                            m1="<b>"+m1+"&nbsp;&nbsp;"+y1+"</b>";
                            $("#m1").html(m1);
                            m2="<b>"+m2+"&nbsp;&nbsp;"+y2+"</b>";
                            $("#m2").html(m2);
                            m3="<b>"+m3+"&nbsp;&nbsp;"+y3+"</b>";
                            $("#m3").html(m3);
                            m4="<b>"+m4+"&nbsp;&nbsp;"+y4+"</b>";
                            $("#m4").html(m4);
                            m5="<b>"+m5+"&nbsp;&nbsp;"+y5+"</b>";
                            $("#m5").html(m5);
                            m6="<b>"+m6+"&nbsp;&nbsp;"+y6+"</b>";
                            $("#m6").html(m6);
                            
                       }
                       function previewsrecordmonth(){
                            var startmonth=$("#startmonth").val();
                            date=""+startmonth[8]+startmonth[9];
                            month=parseInt(startmonth[5]+startmonth[6])-1;
                            year=""+startmonth[0]+startmonth[1]+startmonth[2]+startmonth[3];
                            if(month==0){
                            year=parseInt(year)-1;
                            month=12;
                            }
                            headmonth(month,year);
                            if(month<10){
                            makeDate=year+"-0"+month+"-"+date;
                            }else{
                            makeDate=year+"-"+month+"-"+date;
                            }
                            $("#startmonth").val(makeDate);
                            var wonpending=$("#wonpending").val();
                            if(wonpending=="wonpending"){
                                $.post("date_intermediate1.php",{expected_won_pending:makeDate},function myresult(data1){
                                  $('#mycontent').html('Won+Pending');
                                   $('#exe_result').html(data1);
                               }); 
                            }else{
                                $.post("date_intermediate1.php",{expected_won:makeDate},function myresult(data){
                                    $('#mycontent').html('Total Won');
                                    $('#exe_result').html(data);
                               });
                            }
                            $.post("date_intermediate1.php",{monthly_body:makeDate},function myresult(data1){
                              $('#mycontent').html('Won+Pending');
                               $('#per_result').html(data1);
                           });
                            $.post("date_intermediate1.php",{monthly_tot_pending:makeDate},function myresult(data1){
                              $('#mycontent').html('Won+Pending');
                               $('#momthly_pending_tot').html(data1);
                           }); 
                            $.post("date_intermediate1.php",{monthly_target:makeDate},function myresult(data1){
                               $('#monthly_target_response').html(data1);
                           }); 
                       }
                       
                       function nextrecordmonth(){
                            var startmonth=$("#startmonth").val();
                            date=""+startmonth[8]+startmonth[9];
                            month=parseInt(startmonth[5]+startmonth[6])+1;
                            year=""+startmonth[0]+startmonth[1]+startmonth[2]+startmonth[3];
                            if(month==13){
                            year=parseInt(year)+1;
                            month=1;
                            }
                            headmonth(month,year);
                            if(month<10){
                            makeDate=year+"-0"+month+"-"+date;
                            }else{
                            makeDate=year+"-"+month+"-"+date;
                            }
                            $("#startmonth").val(makeDate);
                            var wonpending=$("#wonpending").val();
                            if(wonpending=="wonpending"){
                                $.post("date_intermediate1.php",{expected_won_pending:makeDate},function myresult(data1){
                                  $('#mycontent').html('Won+Pending');
                                   $('#exe_result').html(data1);
                               }); 
                            }else{
                                $.post("date_intermediate1.php",{expected_won:makeDate},function myresult(data){
                                    $('#mycontent').html('Total Won');
                                    $('#exe_result').html(data);
                               });
                            }
                            $.post("date_intermediate1.php",{monthly_body:makeDate},function myresult(data1){
                               $('#per_result').html(data1);
                           });
                            $.post("date_intermediate1.php",{monthly_tot_pending:makeDate},function myresult(data1){
                               $('#momthly_pending_tot').html(data1);
                           }); 
                            $.post("date_intermediate1.php",{monthly_target:makeDate},function myresult(data1){
                               $('#monthly_target_response').html(data1);
                           }); 
                       }
                   </script>
                    
                <input type="hidden" id="wonpending" name="wonpending" value="wonpending">
                <input type="hidden" id="whattype" name="whattype" value="monthly">
                 
                <input type="hidden" id="startmonth" name="startmonth" value="<?php echo date('Y-m-24', strtotime("-2 months"));?>">
                
                
                   
                 
                 
                    
                </div>
                <!--monthly view-->
                <div class="row" id="monthly_view">
                <br>
                
                <div style="padding:3px 0px;">
                    <div class="row" style="height:50px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center><span id="pipeline2">
                                <span class="dropdown">
                                    <span class="dropdown-toggle" data-toggle="dropdown">
                                    <span class="col-xs-10"><b><span style="font-size:16px;"><center>Expected Total</center></span> </b><br><span id="mycontent" style="font-size:12px;">Won + Pending</span></span>
                                    <span class="col-xs-2" style="padding-top:10px;"> <span class="caret"></span></span></span> 
                                    <ul class="dropdown-menu">
                                        <li onclick="fetch_won()"><a>Total Won</a></li>
                                        <li onclick="fetch_won_expected()"><a>Expected(Won + Pending)</a></li>
                                    </ul>
                                </span>
                            </span></center>
                        </div>
                        <div class="col-md-9" id="exe_result" style="height:50px;">
                            
                            <?php
                            
                            $year=date('Y');
                            $mon=date('m');
                            $month=date('Y-m-d');
                            for($iiiii=-2;$iiiii<4;$iiiii++){
                                $months= date('m', strtotime($month.'+'.$iiiii.' month'));
                                $year=date('Y', strtotime($month.'+'.$iiiii.' month')); 
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and Month(d_date)="'.$months.'" and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                            ?>
                            
                            <div class="col-md-2" style="color:black;cursor:pointer;padding-top:15px;height:50px;background-color:#fff;border-right:1px solid #ddd;">
                                         <?php if($total_amount>0){ ?>
                                        <a style="color:black;font-size:14px;" data-toggle="modal" data-target="#myModal_view_pipeline_deal" onclick="show_pipeline_total_deal_month('<?php echo $companyname;?>','<?php echo $months;?>','<?php echo $year;?>')"><center>&#8360&nbsp;<b><?php echo $total_amount; ?></b></center></a>
                                        <?php  } else { ?>
                                        <center><span style="color: #ccc;text-decoration: none;">&#8360&nbsp;0</span></center>
                                        <?php } ?>
                            </div> 
                            
                            <?php
                            }
                            ?>
                                
                        </div>
                    </div>
                </div>
                
                <?php
                $year=date('Y');
                $month=date('m');
                ?>
                 <div style="padding:3px 0px;">
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center>
                                <span id="pipeline3">
                                    <span class="col-xs-6"><b>Target</b></span>
                                    <span class="col-xs-6">
                                        <span class="pull-right" data-toggle="modal" data-target="#myModal_view_set_target" onclick="show_pipeline_set_target('<?php echo $companyname;?>','<?php echo $month;?>','<?php echo $year;?>')" style="font-size:12px;padding-top:5px;cursor:pointer;">Edit</span>
                                    </span>
                                </span>
                            </center>
                        </div>
                        <div class="col-md-9" style="height:40px;"  id="monthly_target_response">
                            
                            
                            <?php
                            
                            $year=date('Y');
                            $month=date('m');
                            $month=$year."-".$mon."-01";
                            for($iiiii=-2;$iiiii<4;$iiiii++){
                                $months= date('m', strtotime($month.'+'.$iiiii.' month'));
                                $year=date('Y', strtotime($month.'+'.$iiiii.' month')); 
                                $sql21='SELECT count(*) as count1 FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                $resultans21 = $pdo->query($sql21);
                                foreach($resultans21 as $rowans21){
                                    $count1=$rowans21['count1'];
                                }
                                if(intval($count1)<1){
                                    for($rft=0;$rft<count($email_array);$rft++){
                                        $mail=$email_array[$rft];
                                        $sqlfun="select sales_generate_employee_target('".$companyname."','".$mail."','".$year."')";
                                        $resultansfun = $pdo->query($sqlfun);
                                    }
                                }
                                if(intval($months)==1){
                                    $sqlans1='SELECT sum(t_1) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==2){
                                    $sqlans1='SELECT sum(t_2) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==3){
                                    $sqlans1='SELECT sum(t_3) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==4){
                                    $sqlans1='SELECT sum(t_4) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==5){
                                    $sqlans1='SELECT sum(t_5) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==6){
                                    $sqlans1='SELECT sum(t_6) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==7){
                                    $sqlans1='SELECT sum(t_7) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==8){
                                    $sqlans1='SELECT sum(t_8) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==9){
                                    $sqlans1='SELECT sum(t_9) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==10){
                                    $sqlans1='SELECT sum(t_10) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if(intval($months)==11){
                                    $sqlans1='SELECT sum(t_11) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else{
                                    $sqlans1='SELECT sum(t_12) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                } 
                                $resultans1 = $pdo->query($sqlans1);
                                $traget_amount="";
                                foreach($resultans1 as $rowans1){
                                    $traget_amount=$rowans1['amount'];
                                }
                                $traget_amount=round($traget_amount);
                                   
                            ?>
                             <div class="col-md-2" style="color:black;cursor:pointer;padding-top:10px;height:40px;background-color:#fff;border-right:1px solid #ddd;">
                                <span style="color:grey;font-size:14px;"><center>&#8360&nbsp;<b><?php echo $traget_amount;?></b></center></span>
                            </div>
                            
                            <?php
                            }
                            ?>
                            
                        </div>
                    </div>
                </div>
                
               
                <br>

                <div style="padding:3px 0px;" id="per_result">
                <?php //$pipe_percentage $pipe_name
                for($i1=0;$i1<count($pipe_percentage);$i1++){
                        $j=100-($i1*10)."%";
                        $stage=$pipe_id[$i1];
                        $percentage=$pipe_percentage[$i1];
                        $p_name=$pipe_name[$i1];
                ?>
                                
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center><span id="pipeline1" style="width:<?php echo $j;?>"><span ><?php echo $percentage;?><br><span style="font-size:12px;"><?php echo $p_name;?></span></span></span></center>
                        </div>
                        <div class="col-md-9"  style="height:40px;">
                            
                            
                            <?php
                            
                            $year=date('Y');
                            $month=date('m');
                            $month=$year."-".$mon."-01";
                            for($iiiii=-2;$iiiii<4;$iiiii++){
                                $months= date('m', strtotime($month.'+'.$iiiii.' month'));
                                $year=date('Y', strtotime($month.'+'.$iiiii.' month')); 
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and Month(d_date)="'.$months.'" and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss" and `d_stage`="'.$stage.'"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                            ?>
                            
                            <div class="col-md-2" style="color:black;cursor:pointer;padding-top:15px;height:50px;background-color:#fff;border-right:1px solid #ddd;">
                                         <?php if($total_amount>0){ ?>
                                        <a style="color:black;font-size:14px;" data-toggle="modal" data-target="#myModal_view_pipeline_deal" onclick="show_pipeline_total_deal_month('<?php echo $companyname;?>','<?php echo $months;?>','<?php echo $year;?>')"><center>&#8360&nbsp;<b><?php echo $total_amount; ?></b></center></a>
                                        <?php  } else { ?>
                                        <center><span style="color: #ccc;text-decoration: none;">&#8360&nbsp;0</span></center>
                                        <?php } ?>
                            </div> 
                            
                            <?php
                            }
                            ?>
                        </div>
                    </div>
                    <br>
                
<?php
}
?>
                </div>
                
                
                <div style="padding:3px 0px;">
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#db1b56;border-radius:5px;">
                            <center><span id="pipeline1"><b>Total pending</b></span></center>
                        </div>
                        <div class="col-md-9" id="momthly_pending_tot" style="height:40px;">
                            
                            
                            <?php
                            
                            $year=date('Y');
                            $month=date('m');
                            $month=$year."-".$mon."-01";
                            for($iiiii=-2;$iiiii<4;$iiiii++){
                                $months= date('m', strtotime($month.'+'.$iiiii.' month'));
                                $year=date('Y', strtotime($month.'+'.$iiiii.' month')); 
                                $sqlans1='SELECT sum((d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) ) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and Month(d_date)="'.$months.'" and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss" and `d_stage`!="Won"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                            ?>
                            
                                <div class="col-md-2" style="color:black;cursor:pointer;padding-top:10px;height:40px;background-color:#fff;<?php if($i!=6){ ?>border-right:1px solid #ddd; <?php } ?>">
                                    <center><span style="color: #db1b56;font-size:14px;text-decoration: none;">&#8360&nbsp;<b><?php echo $total_amount;?></b></span></center>
                                </div>
                            <?php
                            }
                            ?> 
                        </div>
                    </div>
                </div>
                
                </div>
                
                
                             <script>
                                function year_fetch_won(){
                                   $('#year_wonpending').val("won");  
                                   var startyear=$("#myyear").val();
                                   $.post("year_intermediate.php",{expected_won:startyear},function myresult(data){
                                      $('#yearlymycontent').html('Total Won');
                                       $('#yearly_exe_result').html(data);
                                   });
                                   var value=$.trim(value1);
                                //alert(value);
                                }
                               
                                function year_fetch_won_expected(){
                                   $('#year_wonpending').val("wonpending");  
                                   var startyear=$("#myyear").val();
                                   $.post("year_intermediate.php",{expected_won_pending:startyear},function myresult(data1){
                                      $('#yearlymycontent').html('Won+Pending');
                                       $('#yearly_exe_result').html(data1);
                                   }); 
                                }
                                function headyear(year){
                                    var y1=parseInt(year);
                                    var y2=parseInt(year)+1;
                                    var y3=parseInt(year)+2;
                                    var y4=parseInt(year)+3;
                                    var y5=parseInt(year)+4;
                                    var y6=parseInt(year)+5;
                                   $("#y1").html("<b>"+y1+"</b>");
                                    $("#y2").html("<b>"+y2+"</b>");
                                    $("#y3").html("<b>"+y3+"</b>");
                                    $("#y4").html("<b>"+y4+"</b>");
                                    $("#y5").html("<b>"+y5+"</b>");
                                    $("#y6").html("<b>"+y6+"</b>");
                                }
                                function mynextyear(){
                                    var year=$('#myyear').val();
                                    var y1=parseInt(year)+1;
                                    //alert(y1);
                                    headyear(y1);
                                    $('#myyear').val(y1);
                                    var wonpending=$("#year_wonpending").val();
                                    if(wonpending=="wonpending"){
                                        $.post("year_intermediate.php",{expected_won_pending:y1},function myresult(data1){
                                          $('#yearlymycontent').html('Won+Pending');
                                           $('#yearly_exe_result').html(data1);
                                       }); 
                                    }else{
                                        $.post("year_intermediate.php",{expected_won:y1},function myresult(data){
                                            $('#yearlymycontent').html('Total Won');
                                            $('#yearly_exe_result').html(data);
                                       });
                                    }
                                    $.post("year_intermediate.php",{yearly_body:y1},function test1(data){
                                        $('#per_yearly_result').html(data);
                                    });
                                    $.post("year_intermediate.php",{yearly_tot_pending:y1},function test2(data){
                                        $('#yearly_pending_tot').html(data);
                                    });
                                    $.post("year_intermediate.php",{yearly_target:y1},function test2(data){
                                        $('#yearly_target').html(data);
                                    });
                                    
                                }
                                
                                function mypreviousyear(){
                                    var year=$('#myyear').val();
                                    var y1=parseInt(year)-1;
                                    headyear(y1);
                                    //alert(y1);
                                    $('#myyear').val(y1);
                                    var wonpending=$("#year_wonpending").val();
                                    if(wonpending=="wonpending"){
                                        $.post("year_intermediate.php",{expected_won_pending:y1},function myresult(data1){
                                          $('#yearlymycontent').html('Won+Pending');
                                           $('#yearly_exe_result').html(data1);
                                       }); 
                                    }else{
                                        $.post("year_intermediate.php",{expected_won:y1},function myresult(data){
                                            $('#yearlymycontent').html('Total Won');
                                            $('#yearly_exe_result').html(data);
                                       });
                                    }
                                    $.post("year_intermediate.php",{yearly_body:y1},function test1(data){
                                        $('#per_yearly_result').html(data);
                                    });
                                    $.post("year_intermediate.php",{yearly_tot_pending:y1},function test2(data){
                                        $('#yearly_pending_tot').html(data);
                                    });
                                    $.post("year_intermediate.php",{yearly_target:y1},function test2(data){
                                        $('#yearly_target').html(data);
                                    });
                                        
                                }
                            </script>
                   
                <input type="hidden" id="year_wonpending" name="wonpending" value="wonpending">
                <input type="hidden" id="year_whattype" name="whattype" value="yearly">
                <input type="hidden" id="myyear" value="<?php echo date('Y', strtotime('-2 years'))?>" />
                               
                <!--Yearly view-->
                <div class="row" id="yearly_view">
                <br>
                
                <div style="padding:3px 0px;">
                    <div class="row" style="height:50px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center><span id="pipeline2">
                                <span class="dropdown">
                                    <span class="dropdown-toggle" data-toggle="dropdown">
                                    <span class="col-xs-10"><b><span style="font-size:16px;"><center>Expected Total</center></span> </b><br><span id="yearlymycontent" style="font-size:12px;">Won + Pending</span></span>
                                    <span class="col-xs-2" style="padding-top:10px;"> <span class="caret"></span></span></span> 
                                    <ul class="dropdown-menu">
                                        <li onclick="year_fetch_won()"><a>Total Won</a></li>
                                        <li onclick="year_fetch_won_expected()"><a>Expected(Won + Pending)</a></li>
                                    </ul>
                                </span>
                            </span></center>
                        </div>
                        <div class="col-md-9" id="yearly_exe_result" style="height:50px;">
                            
                            <?php
                            
                            $year=date('Y');
                            $month=date('Y-m-10');
                            for($iiiii=-2;$iiiii<4;$iiiii++){
                                $year=date('Y', strtotime($month.'+'.$iiiii.' year')); 
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                            ?>
                            
                            <div class="col-md-2" style="color:black;cursor:pointer;padding-top:15px;height:50px;background-color:#fff;border-right:1px solid #ddd;">
                                         <?php if($total_amount>0){ ?>
                                        <a style="color:black;font-size:14px;" data-toggle="modal" data-target="#myModal_view_pipeline_deal" onclick="show_pipeline_total_deal_year('<?php echo $companyname;?>','<?php echo $year;?>')"><center>&#8360&nbsp;<b><?php echo $total_amount; ?></b></center></a>
                                        <?php  } else { ?>
                                        <center><span style="color: #ccc;text-decoration: none;">&#8360&nbsp;0</span></center>
                                        <?php } ?>
                            </div> 
                            
                            <?php
                            }
                            ?>
                                
                        </div>
                    </div>
                </div>
                <script>
                    function show_pipeline_total_deal_year(companyname,year){
                        $.ajax({
                            url:"pipeline_total_month_data.php",
                            data:{cmp:companyname,yr:year},
                            type:"post",
                            success:function(respond){
                                $("#show_pipe_deal").html(respond);
                            }
                        });
                    }
                </script>
                <?php
                $year=date('Y');
                $month=date('m');
                ?>
                <div style="padding:3px 0px;">
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center>
                                <span id="pipeline3">
                                    <span class="col-xs-6"><b>Target</b></span>
                                    <span class="col-xs-6">
                                        <span class="pull-right" data-toggle="modal" data-target="#myModal_view_set_target" onclick="show_pipeline_set_target('<?php echo $companyname;?>','<?php echo $month;?>','<?php echo $year;?>')" style="font-size:12px;padding-top:5px;cursor:pointer;">Edit</span>
                                    </span>
                                </span>
                            </center>
                        </div>
                        <div class="col-md-9" style="height:40px;" id="yearly_target">
                            
                            <?php
                            
                            $year=date('Y');
                            $month=date('Y-m-d');
                            for($iiiii=-2;$iiiii<4;$iiiii++){
                                $year=date('Y', strtotime($month.'+'.$iiiii.' year')); 
                                $sql21='SELECT count(*) as count1 FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                $resultans21 = $pdo->query($sql21);
                                foreach($resultans21 as $rowans21){
                                    $count1=$rowans21['count1'];
                                }
                                if(intval($count1)<1){
                                    for($rft=0;$rft<count($email_array);$rft++){
                                        $mail=$email_array[$rft];
                                        $sqlfun="select sales_generate_employee_target('".$companyname."','".$mail."','".$year."')";
                                        $resultansfun = $pdo->query($sqlfun);
                                    }
                                }
                                $sqlans1='SELECT sum(t_1+t_2+t_3+t_4+t_5+t_6+t_7+t_8+t_9+t_10+t_11+t_12) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                
                                $resultans1 = $pdo->query($sqlans1);
                                $traget_amount=0;
                                foreach($resultans1 as $rowans1){
                                    $traget_amount=$rowans1['amount'];
                                }
                                $traget_amount=round($traget_amount);
                                   
                            ?>
                             <div class="col-md-2" style="color:black;cursor:pointer;padding-top:10px;height:40px;background-color:#fff;border-right:1px solid #ddd;">
                                <span style="color:grey;font-size:14px;"><center>&#8360&nbsp;<b><?php echo $traget_amount;?></b></center></span>
                            </div>
                            
                            <?php
                            }
                            ?>
                        </div>
                    </div>
                </div>
                
               
                <br>

                <div style="padding:3px 0px;" id="per_yearly_result">
                <?php //$pipe_percentage $pipe_name
                for($i1=0;$i1<count($pipe_percentage);$i1++){
                        $j=100-($i1*10)."%";
                        $stage=$pipe_id[$i1];
                        $percentage=$pipe_percentage[$i1];
                        $p_name=$pipe_name[$i1];
                ?>
                
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center><span id="pipeline1" style="width:<?php echo $j;?>"><span ><?php echo $percentage;?><br><span style="font-size:12px;"><?php echo $p_name;?></span></span></span></center>
                        </div>
                        <div class="col-md-9"  style="height:40px;">
                            
                            
                            <?php
                            
                            $year=date('Y');
                            $mon=date('m');
                            $month=$year."-".$mon."-01";
                            for($iiiii=-2;$iiiii<4;$iiiii++){
                                $year=date('Y', strtotime($month.'+'.$iiiii.' year')); 
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss" and `d_stage`="'.$stage.'"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount=0;
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                            ?>
                            
                            <div class="col-md-2" style="color:black;cursor:pointer;padding-top:15px;height:50px;background-color:#fff;border-right:1px solid #ddd;">
                                <?php if($total_amount>0){ ?>
                                <a style="color:black;font-size:14px;" data-toggle="modal" data-target="#myModal_view_pipeline_deal" onclick="show_pipeline_total_deal_month('<?php echo $companyname;?>','<?php echo $months;?>','<?php echo $year;?>')"><center>&#8360&nbsp;<b><?php echo $total_amount; ?></b></center></a>
                                <?php  } else { ?>
                                <center><span style="color: #ccc;text-decoration: none;">&#8360&nbsp;0</span></center>
                                <?php } ?>
                            </div> 
                            
                            <?php
                            }
                            ?>
                        </div>
                    </div>
                    <br>
                
<?php
}
?>
                </div>
                <br>
                
                
                <div style="padding:3px 0px;">
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#db1b56;border-radius:5px;">
                            <center><span id="pipeline1"><b>Total pending</b></span></center>
                        </div>
                        <div class="col-md-9" id="yearly_pending_tot" style="height:40px;">
                            
                            
                            <?php
                            
                            $year=date('Y');
                            $mon=date('m');
                            $month=$year."-".$mon."-01";
                            for($iiiii=-2;$iiiii<4;$iiiii++){
                                $year=date('Y', strtotime($month.'+'.$iiiii.' year')); 
                                $sqlans1='SELECT sum((d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) ) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss" and `d_stage`!="Won"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount=0;
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                            ?>
                            
                                <div class="col-md-2" style="color:black;cursor:pointer;padding-top:10px;height:40px;background-color:#fff;<?php if($i!=6){ ?>border-right:1px solid #ddd; <?php } ?>">
                                    <center><span style="color: #db1b56;font-size:14px;text-decoration: none;">&#8360&nbsp;<b><?php echo $total_amount;?></b></span></center>
                                </div>
                            <?php
                            }
                            ?> 
                        </div>
                    </div>
                </div>
                
                </div>
                
                
                             <script>
                                function quarterly_fetch_won(){
                                   $('#quarterly_wonpending').val("won");  
                                   var startyear=$("#myyear").val();
                                   $.post("month_intermediate.php",{expected_won:startyear},function myresult(data){
                                      $('#quarterlymycontent').html('Total Won');
                                       $('#quarterly_exe_result').html(data);
                                   });
                                   var value=$.trim(value1);
                                //alert(value);
                                }
                               
                                function quarterly_fetch_won_expected(){
                                   $('#quarterly_wonpending').val("wonpending");  
                                   var startyear=$("#myyear").val();
                                   $.post("month_intermediate.php",{expected_won_pending:startyear},function myresult(data1){
                                      $('#quarterlymycontent').html('Won+Pending');
                                       $('#quarterly_exe_result').html(data1);
                                   }); 
                                }
                                function headquarterly(oonth,year){
                                    var month_array = ["","Q1", "Q2", "Q3", "Q4"];
                                   month=parseInt(month);
                                   year=parseInt(year);
                                    if(month<4){
                                        m1=month_array[1];m2=month_array[2];m3=month_array[3];m4=month_array[4];m5=month_array[1];m6=month_array[2];
                                        y1=year;y2=year;y3=year;y4=year;y5=year+1;y6=year+1;
                                    }else if(month<7){
                                        m1=month_array[2];m2=month_array[3];m3=month_array[4];m4=month_array[1];m5=month_array[2];m6=month_array[3];
                                        y1=year;y2=year;y3=year;y4=year+1;y5=year+1;y6=year+1;
                                    }else if(month<10){
                                        m1=month_array[3];m2=month_array[4];m3=month_array[1];m4=month_array[2];m5=month_array[3];m6=month_array[4];
                                        y1=year;y2=year;y3=year+1;y4=year+1;y5=year+1;y6=year+1;
                                    }else{
                                        m1=month_array[4];m2=month_array[1];m3=month_array[2];m4=month_array[3];m5=month_array[4];m6=month_array[1];
                                        y1=year;y2=year+1;y3=year+1;y4=year+1;y5=year+1;y6=year+2;
                                    }
                                    m1="<b>"+m1+"&nbsp;&nbsp;"+y1+"</b>";
                                    $("#q1").html(m1);
                                    m2="<b>"+m2+"&nbsp;&nbsp;"+y2+"</b>";
                                    $("#q2").html(m2);
                                    m3="<b>"+m3+"&nbsp;&nbsp;"+y3+"</b>";
                                    $("#q3").html(m3);
                                    m4="<b>"+m4+"&nbsp;&nbsp;"+y4+"</b>";
                                    $("#q4").html(m4);
                                    m5="<b>"+m5+"&nbsp;&nbsp;"+y5+"</b>";
                                    $("#q5").html(m5);
                                    m6="<b>"+m6+"&nbsp;&nbsp;"+y6+"</b>";
                                    $("#q6").html(m6);
                                }
                                function mynextquarterly(){
                                    var myquarterly=$('#myquarterly').val();
                                    date=""+myquarterly[8]+myquarterly[9];
                                    month=parseInt(myquarterly[5]+myquarterly[6])+3;
                                    year=""+myquarterly[0]+myquarterly[1]+myquarterly[2]+myquarterly[3];
                                    if(month==13){
                                    year=parseInt(year)+1;
                                    month=1;
                                    }
                                    if(month==14){
                                    year=parseInt(year)+1;
                                    month=2;
                                    }
                                    if(month>15){
                                    year=parseInt(year)+1;
                                    month=3;
                                    }
                                    headquarterly(month,year);
                                    if(month<10){
                                    makeDate=year+"-0"+month+"-"+date;
                                    }else{
                                    makeDate=year+"-"+month+"-"+date;
                                    }
                                    //alert(makeDate);
                                    $("#myquarterly").val(makeDate);
                                    //alert(makeDate););
                                    var wonpending=$("#quarterly_wonpending").val();
                                    if(wonpending=="wonpending"){
                                        $.post("month_intermediate.php",{expected_won_pending:makeDate},function myresult(data1){
                                          $('#quarterlymycontent').html('Won+Pending');
                                           $('#quarterly_exe_result').html(data1);
                                       }); 
                                    }else{
                                        $.post("month_intermediate.php",{expected_won:makeDate},function myresult(data){
                                            $('#quarterlymycontent').html('Total Won');
                                            $('#quarterly_exe_result').html(data);
                                       });
                                    }
                                    $.post("month_intermediate.php",{quarterly_body:makeDate},function test1(data){
                                        $('#per_quarterly_result').html(data);
                                    });
                                    $.post("month_intermediate.php",{quarterly_tot_pending:makeDate},function test2(data){
                                        $('#quarterly_pending_tot').html(data);
                                    });
                                    $.post("month_intermediate.php",{quarterly_target:makeDate},function test2(data){
                                        $('#quarterly_target').html(data);
                                    });
                                    
                                }
                                
                                function mypreviousquarterly(){
                                    var myquarterly=$('#myquarterly').val();
                                    date=""+myquarterly[8]+myquarterly[9];
                                    month=parseInt(myquarterly[5]+myquarterly[6])-3;
                                    year=""+myquarterly[0]+myquarterly[1]+myquarterly[2]+myquarterly[3];
                                    if(month==0){
                                    year=parseInt(year)-1;
                                    month=12;
                                    }
                                    if(month==-1){
                                    year=parseInt(year)-1;
                                    month=11;
                                    }
                                    if(month==-2){
                                    year=parseInt(year)-1;
                                    month=10;
                                    }
                                    if(month<10){
                                    makeDate=year+"-0"+month+"-"+date;
                                    }else{
                                    makeDate=year+"-"+month+"-"+date;
                                    }
                                    //alert(makeDate);
                                    headquarterly(month,year);
                                    //alert(makeDate);
                                    $("#myquarterly").val(makeDate);
                                    var wonpending=$("#quarterly_wonpending").val();
                                    if(wonpending=="wonpending"){
                                        $.post("month_intermediate.php",{expected_won_pending:makeDate},function myresult(data1){
                                          $('#quarterlymycontent').html('Won+Pending');
                                           $('#quarterly_exe_result').html(data1);
                                       }); 
                                    }else{
                                        $.post("month_intermediate.php",{expected_won:makeDate},function myresult(data){
                                            $('#quarterlymycontent').html('Total Won');
                                            $('#quarterly_exe_result').html(data);
                                       });
                                    }
                                    $.post("month_intermediate.php",{quarterly_body:makeDate},function test1(data){
                                        $('#per_quarterly_result').html(data);
                                    });
                                    $.post("month_intermediate.php",{quarterly_tot_pending:makeDate},function test2(data){
                                        $('#quarterly_pending_tot').html(data);
                                    });
                                    $.post("month_intermediate.php",{quarterly_target:makeDate},function test2(data){
                                        $('#quarterly_target').html(data);
                                    });
                                        
                                }
                            </script>
                   
                <input type="hidden" id="quarterly_wonpending" name="wonpending" value="wonpending">
                <input type="hidden" id="quarterly_whattype" name="whattype" value="quarterly">
                <input type="hidden" id="myquarterly" value="<?php echo date('Y-m-01', strtotime('-6 month'));?>" />
                               
                <!--Yearly view-->
                <div class="row" id="quartely_view">
                <br>
                
                <div style="padding:3px 0px;">
                    <div class="row" style="height:50px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center><span id="pipeline2">
                                <span class="dropdown">
                                    <span class="dropdown-toggle" data-toggle="dropdown">
                                    <span class="col-xs-10"><b><span style="font-size:16px;"><center>Expected Total</center></span> </b><br><span id="quarterlymycontent" style="font-size:12px;">Won + Pending</span></span>
                                    <span class="col-xs-2" style="padding-top:10px;"> <span class="caret"></span></span></span> 
                                    <ul class="dropdown-menu">
                                        <li onclick="quarterly_fetch_won()"><a>Total Won</a></li>
                                        <li onclick="quarterly_fetch_won_expected()"><a>Expected(Won + Pending)</a></li>
                                    </ul>
                                </span>
                            </span></center>
                        </div>
                        <div class="col-md-9" id="quarterly_exe_result" style="height:50px;">
                            
                            <?php
                            
                            $year=date('Y', strtotime('-6 month'));
                            $month=date('Y-m-01', strtotime('-6 month'));
                            $qu=["q1","q2","q3","q4"];
                            $mno=date('m', strtotime('-6 month'));
                            if($mno<4){
                                $va=0;
                            }elseif($mno<7){
                                $va=1;
                            }elseif($mno<10){
                                $va=2;
                            }else{
                                $va=3;
                            }
                            
                            for($iiiii=0,$v1=intval($va);$iiiii<6;$iiiii++){
                                if($qu[$v1]=="q1"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="01" or  Month(d_date)="02" or  Month(d_date)="03")and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else if($qu[$v1]=="q2"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="04" or  Month(d_date)="05" or  Month(d_date)="06")and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else if($qu[$v1]=="q3"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="07" or  Month(d_date)="08" or  Month(d_date)="09")and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else{
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="10" or  Month(d_date)="11" or  Month(d_date)="12")and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }
                                $v1++;
                                if($v1>3){
                                    $v1=0;
                                    $year=intval($year)+1;
                                }
                            ?>
                            
                            <div class="col-md-2" style="color:black;cursor:pointer;padding-top:15px;height:50px;background-color:#fff;border-right:1px solid #ddd;">
                                         <?php if($total_amount>0){ ?>
                                        <a style="color:black;font-size:14px;" data-toggle="modal" data-target="#myModal_view_pipeline_deal" onclick="show_pipeline_total_deal_year('<?php echo $companyname;?>','<?php echo $year;?>')"><center>&#8360&nbsp;<b><?php echo $total_amount; ?></b></center></a>
                                        <?php  } else { ?>
                                        <center><span style="color: #ccc;text-decoration: none;">&#8360&nbsp;0</span></center>
                                        <?php } ?>
                            </div> 
                            
                            <?php
                            }
                            ?>
                                
                        </div>
                    </div>
                </div>
                <script>
                    function show_pipeline_total_deal_year(companyname,year){
                        $.ajax({
                            url:"pipeline_total_month_data.php",
                            data:{cmp:companyname,yr:year},
                            type:"post",
                            success:function(respond){
                                $("#show_pipe_deal").html(respond);
                            }
                        });
                    }
                </script>
                <?php
                $year=date('Y');
                $month=date('m');
                ?>
                <div style="padding:3px 0px;">
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center>
                                <span id="pipeline3">
                                    <span class="col-xs-6"><b>Target</b></span>
                                    <span class="col-xs-6">
                                        <span class="pull-right" data-toggle="modal" data-target="#myModal_view_set_target" onclick="show_pipeline_set_target('<?php echo $companyname;?>','<?php echo $month;?>','<?php echo $year;?>')" style="font-size:12px;padding-top:5px;cursor:pointer;">Edit</span>
                                    </span>
                                </span>
                            </center>
                        </div>
                        <div class="col-md-9" style="height:40px;" id="quarterly_target">
                            
                            <?php
                            
                            
                            $year=date('Y', strtotime('-6 month'));
                            $month=date('Y-m-01', strtotime('-6 month'));
                            $qu=["q1","q2","q3","q4"];
                            $mno=date('m', strtotime('-6 month'));
                            if($mno<4){
                                $va=0;
                            }elseif($mno<7){
                                $va=1;
                            }elseif($mno<10){
                                $va=2;
                            }else{
                                $va=3;
                            }
                            
                            for($iiiii=0,$v1=intval($va);$iiiii<6;$iiiii++){
                                $sql21='SELECT count(*) as count1 FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                $resultans21 = $pdo->query($sql21);
                                foreach($resultans21 as $rowans21){
                                    $count1=$rowans21['count1'];
                                }
                                if(intval($count1)<1){
                                    for($rft=0;$rft<count($email_array);$rft++){
                                        $mail=$email_array[$rft];
                                        $sqlfun="select sales_generate_employee_target('".$companyname."','".$mail."','".$year."')";
                                        $resultansfun = $pdo->query($sqlfun);
                                    }
                                }
                                $sqlans1="";
                                if($qu[$v1]=="q1"){
                                $sqlans1='SELECT sum(t_1+t_2+t_3) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if($qu[$v1]=="q2"){
                                $sqlans1='SELECT sum(t_4+t_5+t_6) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else if($qu[$v1]=="q3"){
                                $sqlans1='SELECT sum(t_7+t_8+t_9) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }else{
                                $sqlans1='SELECT sum(t_10+t_11+t_12) as amount FROM `sales_employee_target1` WHERE `t_company`="'.$companyname.'" and `t_year`="'.$year.'"';
                                }
                                //echo $sqlans1;
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount=0;
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['amount'];
                                }
                                $traget_amount=round($total_amount);
                                $v1++;
                                if($v1>3){
                                    $v1=0;
                                    $year=intval($year)+1;
                                }
                                   
                            ?>
                             <div class="col-md-2" style="color:black;cursor:pointer;padding-top:10px;height:40px;background-color:#fff;border-right:1px solid #ddd;">
                                <span style="color:grey;font-size:14px;"><center>&#8360&nbsp;<b><?php echo $traget_amount;?></b></center></span>
                            </div>
                            
                            <?php
                            }
                            ?>
                        </div>
                    </div>
                </div>
                
               
                <br>

                <div style="padding:3px 0px;" id="per_quarterly_result">
                <?php //$pipe_percentage $pipe_name
                for($i1=0;$i1<count($pipe_percentage);$i1++){
                        $j=100-($i1*10)."%";
                        $stage=$pipe_id[$i1];
                        $percentage=$pipe_percentage[$i1];
                        $p_name=$pipe_name[$i1];
                ?>
                
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#f6f6f6;">
                            <center><span id="pipeline1" style="width:<?php echo $j;?>"><span ><?php echo $percentage;?><br><span style="font-size:12px;"><?php echo $p_name;?></span></span></span></center>
                        </div>
                        <div class="col-md-9"  style="height:40px;">
                            
                            
                            <?php
                            
                            $year=date('Y', strtotime('-6 month'));
                            $month=date('Y-m-01', strtotime('-6 month'));
                            $qu=["q1","q2","q3","q4"];
                            $mno=date('m', strtotime('-6 month'));
                            if($mno<4){
                                $va=0;
                            }elseif($mno<7){
                                $va=1;
                            }elseif($mno<10){
                                $va=2;
                            }else{
                                $va=3;
                            }
                            
                            for($iiiii=0,$v1=intval($va);$iiiii<6;$iiiii++){
                                if($qu[$v1]=="q1"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="01" or  Month(d_date)="02" or  Month(d_date)="03")and YEAR(`d_date`)="'.$year.'" and `d_stage`="'.$stage.'"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else if($qu[$v1]=="q2"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="04" or  Month(d_date)="05" or  Month(d_date)="06")and YEAR(`d_date`)="'.$year.'" and `d_stage`="'.$stage.'"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else if($qu[$v1]=="q3"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="07" or  Month(d_date)="08" or  Month(d_date)="09")and YEAR(`d_date`)="'.$year.'" and `d_stage`="'.$stage.'"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else{
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="10" or  Month(d_date)="11" or  Month(d_date)="12")and YEAR(`d_date`)="'.$year.'" and `d_stage`="'.$stage.'"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }
                                $v1++;
                                if($v1>3){
                                    $v1=0;
                                    $year=intval($year)+1;
                                }
                            ?>
                            
                            <div class="col-md-2" style="color:black;cursor:pointer;padding-top:15px;height:50px;background-color:#fff;border-right:1px solid #ddd;">
                                <?php if($total_amount>0){ ?>
                                <a style="color:black;font-size:14px;" data-toggle="modal" data-target="#myModal_view_pipeline_deal" onclick="show_pipeline_total_deal_month('<?php echo $companyname;?>','<?php echo $months;?>','<?php echo $year;?>')"><center>&#8360&nbsp;<b><?php echo $total_amount; ?></b></center></a>
                                <?php  } else { ?>
                                <center><span style="color: #ccc;text-decoration: none;">&#8360&nbsp;0</span></center>
                                <?php } ?>
                            </div> 
                            
                            <?php
                            }
                            ?>
                        </div>
                    </div>
                    <br>
                
<?php
}
?>
                </div>
                <br>
                
                
                <div style="padding:3px 0px;">
                    <div class="row" style="height:40px;">
                        <div class="col-md-3" style="background-color:#db1b56;border-radius:5px;">
                            <center><span id="pipeline1"><b>Total pending</b></span></center>
                        </div>
                        <div class="col-md-9" id="quarterly_pending_tot" style="height:40px;">
                            
                            
                            <?php
                            
                            $year=date('Y', strtotime('-6 month'));
                            $month=date('Y-m-01', strtotime('-6 month'));
                            $qu=["q1","q2","q3","q4"];
                            $mno=date('m', strtotime('-6 month'));
                            if($mno<4){
                                $va=0;
                            }elseif($mno<7){
                                $va=1;
                            }elseif($mno<10){
                                $va=2;
                            }else{
                                $va=3;
                            }
                            
                            for($iiiii=0,$v1=intval($va);$iiiii<6;$iiiii++){
                                if($qu[$v1]=="q1"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="01" or  Month(d_date)="02" or  Month(d_date)="03")and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss" and `d_stage`!="won"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else if($qu[$v1]=="q2"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="04" or  Month(d_date)="05" or  Month(d_date)="06")and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss" and `d_stage`!="won"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else if($qu[$v1]=="q3"){
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="07" or  Month(d_date)="08" or  Month(d_date)="09")and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss" and `d_stage`!="won"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }else{
                                $sqlans1='SELECT sum( case when `d_stage`="Won" then `d_amount` else (d_amount * cast(REPLACE(sales_pipeline_type.pipe_percentage, "%", "") as UNSIGNED INTEGER) / 100) end) as total_amount FROM `sales_deal_pipeline` left join sales_pipeline_type on sales_pipeline_type.id=sales_deal_pipeline.d_stage WHERE sales_deal_pipeline.`companyname`="'.$companyname.'" and ( Month(d_date)="10" or  Month(d_date)="11" or  Month(d_date)="12")and YEAR(`d_date`)="'.$year.'" and `d_stage`!="loss" and `d_stage`!="won"';
                                $resultans1 = $pdo->query($sqlans1);
                                $total_amount="";
                                foreach($resultans1 as $rowans1){
                                    $total_amount=$rowans1['total_amount'];
                                }
                                $total_amount=round($total_amount);
                                }
                                $v1++;
                                if($v1>3){
                                    $v1=0;
                                    $year=intval($year)+1;
                                }
                            ?>
                            
                                <div class="col-md-2" style="color:black;cursor:pointer;padding-top:10px;height:40px;background-color:#fff;<?php if($i!=6){ ?>border-right:1px solid #ddd; <?php } ?>">
                                    <center><span style="color: #db1b56;font-size:14px;text-decoration: none;">&#8360&nbsp;<b><?php echo $total_amount;?></b></span></center>
                                </div>
                            <?php
                            }
                            ?> 
                        </div>
                    </div>
                </div>
                
                </div>
                
                
                 
                    
            </div>
            
        </div>
        
        <div style="background-color:#ffffff;padding:10px 100px">
            
            <div style="background-color:#f6f6f6;">
                <br>
                <span style="padding:0px 5px;font-size:20px;"><b>DEAL LIST</b></span><br>
                <div id="pipelinedeallistview"></div> 
                
            </div>
            
            
        </div>
    </div>
        
        <div id="employee_list" style="display:none;"></div>
    <script>
        function show_pipeline_set_target(companyname, year, month){
            var empid=new Array();
            empid=<?php echo json_encode($emp_emailid_a);?>;
            $.ajax({
               url:"pipeline_employee_traget_data.php",
               data:{companyname:companyname, empid:empid, month:month, year:year},
               type:"post",
               success:function(respond){
                   $("#show_target_view").html(respond);
               }
            });
        }
    </script>
	<div class="modal right fade" id="myModal_view_set_target" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
		<div class="modal-dialog" role="document">
			<div class="modal-content">


				<div class="modal-body">
					<button type="button" class="close pull-left" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title" id="myModalLabel2"><center>Edit Employee Target</center></h4>
					<span id="show_target_view"></span>
				</div>

			</div><!-- modal-content -->
		</div><!-- modal-dialog -->
	</div><!-- modal -->
        
        
	<!-- Modal -->
	<div class="modal right fade" id="myModal_view_pipeline_deal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
		<div class="modal-dialog" role="document">
			<div class="modal-content">


				<div class="modal-body">
					<button type="button" class="close pull-left" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title" id="myModalLabel2"><center>Deal</center></h4>
					<span id="show_pipe_deal"></span>
				</div>

			</div><!-- modal-content -->
		</div><!-- modal-dialog -->
	</div><!-- modal -->
	<!-- Modal -->
	
	
        
        <script>
            function show_pipeline_total_deal_month(companyname, month, year){
                
                $.ajax({
                   url:"pipeline_total_month_data.php",
                   data:{companyname:companyname, month:month, year:year},
                   type:"post",
                   success:function(respond){
                      
                       $("#show_pipe_deal").html(respond);
                   }
                });
            }
        </script>
        
        <script>
            $(document).ready(function(){
                var s="";
                $.ajax({
                   url:"pipeline_data.php",
                   data:{s:s},
                   type:"post",
                   success:function(respond){
                       $("#pipelinedeallistview").html(respond);
                   }
                });
               
            });
        </script>
    </body>
    
</html>