<?php
session_start();
$companyname=$_SESSION['companyname'];//;
$adminemailid=$_SESSION['emailid'];//;
if(($adminemailid !="")&&($companyname!="")){
require_once('../Control/sales.php');
$objsales=new salesctrl();
require_once('../Control/employee.php');
$objemployee=new employeectrl();
require_once('../Control/pipeline.php');
$objpipeline=new pipelinectrl();
$emp_res=$objsales->salesselectall($companyname, $adminemailid, "signupdetails", "no");
//print_r($emp_res);
$j=0;
foreach($emp_res as $emp_row){
 $emp_emailid_a[$j++]=$emp_row['emailid'];   
}


?>
<!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>
                       
    </head>
    
    <body>
        <input type="hidden" id="condition_button" value="123"/>
                 <input type="hidden" id="startmonth" name="startmonth" value="<?php echo date('m');?>">
                    <input type="hidden" id="startmonth1" name="startmonth1" value="<?php echo date('Y');?>">
                    <input type="hidden" id="startmonth2" name="startmonth2" value="<?php echo date('Y');?>">
        <div class="row">
            
            <div class="col-md-3">
                
            </div>

            <div class="col-sm-9" id="monthlyshow">
                <!--<div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                    <button id="m11" class="btn btn-default pull-right" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php if(date('m')<7){ echo "Jan"; }else{ echo "Jul"; } ?>&nbsp;&nbsp;<?php echo $prevmonth = date('Y', strtotime('-1 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="m22" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php if(date('m')<7){ echo "Feb"; }else{ echo "Aug"; } ?>&nbsp;&nbsp;<?php echo $prevmonth = date('Y');?></b></button></center>
                </div>
                <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                    <center><button id="m33" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php if(date('m')<7){ echo "Mar"; }else{ echo "Sep"; } ?>&nbsp;&nbsp;<?php echo $prevmonth = date('Y', strtotime('1 months'));?></b></button></center>
                </div>
                <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                    <center><button id="m44" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php if(date('m')<7){ echo "Apr"; }else{ echo "Oct"; } ?>&nbsp;&nbsp;<?php echo $prevmonth = date('Y', strtotime('2 months'));?></b></button></center>
                </div>
                <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                    <center><button id="m55" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php if(date('m')<7){ echo "May"; }else{ echo "Nov"; } ?>&nbsp;&nbsp;<?php echo $prevmonth = date('Y', strtotime('3 months'));?></b></button></center>
                </div>
                <div class="col-sm-2" style="padding:5px 0px;">
                    <center><button id="m66" class="btn btn-default pull-left" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php if(date('m')<7){ echo "Jun"; }else{ echo "Dec"; } ?>&nbsp;&nbsp;<?php echo $prevmonth = date('Y', strtotime('4 months'));?></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 class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <button id="m11" class="btn btn-default pull-right" next_month="<?php echo date('M',strtotime($month)); ?>" my_year="<?php echo $year;?>"  style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M'); ?>&nbsp;&nbsp;<?php echo date('Y');?></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="m22" class="btn btn-default"  style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime($month .'+1 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime($months .'+1 month')); ?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="m33" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime($month .'+2 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime($months .'+2 month')); ?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="m44" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime($month .'+3 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime($months .'+3 month')); ?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;border-right:1px solid #D5D5D5;">
                                <center><button id="m55" class="btn btn-default" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime($month .'+4 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime($months .'+4 month')); ?></b></button></center>
                            </div>
                            <div class="col-sm-2" style="padding:5px 0px;">
                                <center><button id="m66" class="btn btn-default pull-left" style="display:inline;padding:5px;border:none;background-color:#f6f6f6;"><b><?php echo date('M', strtotime($month .'+5 month')); ?>&nbsp;&nbsp;<?php echo date('Y', strtotime($months .'+5 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>
            
            
        </div>
         <script>
                            function previewsrecordmonth(){
                                var month=$("#startmonth").val();//['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
                                //var year=$("#startmonth1").val();
                                var year=$("#startmonth2").val();
                                if(month==1){
                                    var con_but=$('#condition_button').val();
                                    if(con_but!="next"){
                                    var m11='Dec '+(Number(year));
                                    var m22='Jan '+(Number(year)+1);
                                    var m33='Feb '+(Number(year)+1);
                                    var m44='Mar '+(Number(year)+1);
                                    var m55='Apr '+(Number(year)+1);
                                    var m66='May '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(12);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"12",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                   
                                    }
                                    else{
                                       var m11='Dec '+(Number(year)-1);
                                    var m22='Jan '+(Number(year));
                                    var m33='Feb '+(Number(year));
                                    var m44='Mar '+(Number(year));
                                    var m55='Apr '+(Number(year));
                                    var m66='May '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(12);
                                    $("#startmonth2").val(Number(year)-1);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"12",yea:(Number(year)-1)},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                    }
                                }
                                if(month==2){
                                    var m11='Jan '+(Number(year));
                                    var m22='Feb '+(Number(year));
                                    var m33='Mar '+(Number(year));
                                    var m44='Apr '+(Number(year));
                                    var m55='May '+(Number(year));
                                    var m66='Jun '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(1);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"01",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                     $("#startmonth1").val(Number(year));
                                    $("#startmonth2").val(Number(year)-1);
                                }
                                if(month==3){
                                    var m11='Feb '+(Number(year));
                                    var m22='Mar '+(Number(year));
                                    var m33='Apr '+(Number(year));
                                    var m44='May '+(Number(year));
                                    var m55='Jun '+(Number(year));
                                    var m66='Jul '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(2);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"02",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                if(month==4){
                                    var m11='Mar '+(Number(year));
                                    var m22='Apr '+(Number(year));
                                    var m33='May '+(Number(year));
                                    var m44='Jun '+(Number(year));
                                    var m55='Jul '+(Number(year));
                                    var m66='Aug '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(3);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"03",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                if(month==5){
                                    var m11='Apr '+(Number(year));
                                    var m22='May '+(Number(year));
                                    var m33='Jun '+(Number(year));
                                    var m44='Jul '+(Number(year));
                                    var m55='Aug '+(Number(year));
                                    var m66='Sep '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(4);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"04",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                   
                                }
                                if(month==6){
                                    var m11='May '+(Number(year));
                                    var m22='Jun '+(Number(year));
                                    var m33='Jul '+(Number(year));
                                    var m44='Aug '+(Number(year));
                                    var m55='Sep '+(Number(year));
                                    var m66='Oct '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(5);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"05",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                 if(month==7){
                                    var m11='Jun '+(Number(year));
                                    var m22='Jul '+(Number(year));
                                    var m33='Aug '+(Number(year));
                                    var m44='Sep '+(Number(year));
                                    var m55='Oct '+(Number(year));
                                    var m66='Nov '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(6);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"06",yea:year},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                if(month==8){
                                    var m11='Jul '+(Number(year));
                                    var m22='Aug '+(Number(year));
                                    var m33='Sep '+(Number(year));
                                    var m44='Oct '+(Number(year));
                                    var m55='Nov '+(Number(year));
                                    var m66='Dec '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(7);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"07",yea:year},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                               if(month==9){
                                    var m11='Aug '+(Number(year));
                                    var m22='Sep '+(Number(year));
                                    var m33='Oct '+(Number(year));
                                    var m44='Nov '+(Number(year));
                                    var m55='Dec '+(Number(year));
                                    var m66='Jan '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(8);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"08",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                     
                                }
                                if(month==10){
                                    var m11='Sep '+(Number(year));
                                    var m22='Oct '+(Number(year));
                                    var m33='Nov '+(Number(year));
                                    var m44='Dec '+(Number(year));
                                    var m55='Jan '+(Number(year)+1);
                                    var m66='Feb '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(9);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"09",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                   
                                }
                                if(month==11){
                                    var m11='Oct '+(Number(year));
                                    var m22='Nov '+(Number(year));
                                    var m33='Dec '+(Number(year));
                                    var m44='Jan '+(Number(year)+1);
                                    var m55='Feb '+(Number(year)+1);
                                    var m66='Mar '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(10);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"10",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                if(month==12){
                                    var m11='Nov '+(Number(year));
                                    var m22='Dec '+(Number(year));
                                    var m33='Jan '+(Number(year)+1);
                                    var m44='Feb '+(Number(year)+1);
                                    var m55='Mar '+(Number(year)+1);
                                    var m66='Apr '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(11);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"11",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                  $('#condition_button').val('previous');
                            }
                        </script>
                        <script>
                            function nextrecordmonth(){
                               
                                var month=$("#startmonth").val();//['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
                                var year=$("#startmonth2").val();
                                //var year1=$("#startmonth2").val();
                                                               
                                if(month==1){
                                    var con_but=$('#condition_button').val();
                                    if(con_but=="previous"){
                                        
                                    var m11='Feb '+(Number(year)+1);
                                    var m22='Mar '+(Number(year)+1);
                                    var m33='Apr '+(Number(year)+1);
                                    var m44='May '+(Number(year)+1);
                                    var m55='Jun '+(Number(year)+1);
                                    var m66='Jul '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(2);
                                    $("#startmonth2").val(Number(year)+1);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"02",yea:(Number(year)+1)},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                    
                                    }
                                    else{
                                    var m11='Feb '+(Number(year));
                                    var m22='Mar '+(Number(year));
                                    var m33='Apr '+(Number(year));
                                    var m44='May '+(Number(year));
                                    var m55='Jun '+(Number(year));
                                    var m66='Jul '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(2);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"02",yea:year},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                   
                                    }
                                }
                                if(month==2){
                                    var m11='Mar '+(Number(year));
                                    var m22='Apr '+(Number(year));
                                    var m33='May '+(Number(year));
                                    var m44='Jun '+(Number(year));
                                    var m55='Jul '+(Number(year));
                                    var m66='Aug '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(3);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"03",yea:year},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                if(month==3){
                                    var m11='Apr '+(Number(year));
                                    var m22='May '+(Number(year));
                                    var m33='Jun '+(Number(year));
                                    var m44='Jul '+(Number(year));
                                    var m55='Aug '+(Number(year));
                                    var m66='Sep '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(4);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"04",yea:year},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                if(month==4){
                                    var m11='May '+(Number(year));
                                    var m22='Jun '+(Number(year));
                                    var m33='Jul '+(Number(year));
                                    var m44='Aug '+(Number(year));
                                    var m55='Sep '+(Number(year));
                                    var m66='Oct '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(5);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"05",yea:year},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                }
                                if(month==5){
                                    var m11='Jun '+(Number(year));
                                    var m22='Jul '+(Number(year));
                                    var m33='Aug '+(Number(year));
                                    var m44='Sep '+(Number(year));
                                    var m55='Oct '+(Number(year));
                                    var m66='Nov '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(6);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"06",yea:year},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                }
                                if(month==6){
                                    var m11='Jul '+(Number(year));
                                    var m22='Aug '+(Number(year));
                                    var m33='Sep '+(Number(year));
                                    var m44='Oct '+(Number(year));
                                    var m55='Nov '+(Number(year));
                                    var m66='Dec '+(Number(year));
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(7);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"07",yea:year},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                  if(month==7){
                                    var m11='Aug '+(Number(year));
                                    var m22='Sep '+(Number(year));
                                    var m33='Oct '+(Number(year));
                                    var m44='Nov '+(Number(year));
                                    var m55='Dec '+(Number(year));
                                    var m66='Jan '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(8);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"08",yea:(Number(year))},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                if(month==8){
                                    var m11='Sep '+(Number(year));
                                    var m22='Oct '+(Number(year));
                                    var m33='Nov '+(Number(year));
                                    var m44='Dec '+(Number(year));
                                    var m55='Jan '+(Number(year)+1);
                                    var m66='Feb '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(9);
                                   $.post("pipeline_employee_target_intermediate.php",{mon:"09",yea:(Number(year))},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                }
                               if(month==9){
                                    var m11='Oct '+(Number(year));
                                    var m22='Nov '+(Number(year));
                                    var m33='Dec '+(Number(year));
                                    var m44='Jan '+(Number(year)+1);
                                    var m55='Feb '+(Number(year)+1);
                                    var m66='Mar '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(10);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"10",yea:(Number(year))},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                }
                                if(month==10){
                                    var m11='Nov '+(Number(year));
                                    var m22='Dec '+(Number(year));
                                    var m33='Jan '+(Number(year)+1);
                                    var m44='Feb '+(Number(year)+1);
                                    var m55='Mar '+(Number(year)+1);
                                    var m66='Apr '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(11);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"11",yea:(Number(year))},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                }
                                if(month==11){
                                    var m11='Dec '+(Number(year));
                                    var m22='Jan '+(Number(year)+1);
                                    var m33='Feb '+(Number(year)+1);
                                    var m44='Mar '+(Number(year)+1);
                                    var m55='Apr '+(Number(year)+1);
                                    var m66='May '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(12);
                                    $.post("pipeline_employee_target_intermediate.php",{mon:"12",yea:(Number(year))},function test(data){
                                        
                                        $('#exe_result1').html(data);
                                    });
                                    
                                }
                                if(month==12){
                                    var m11='Jan '+(Number(year)+1);
                                    var m22='Feb '+(Number(year)+1);
                                    var m33='Mar '+(Number(year)+1);
                                    var m44='Apr '+(Number(year)+1);
                                    var m55='May '+(Number(year)+1);
                                    var m66='Jun '+(Number(year)+1);
                                    $("#m11").html('<b>'+m11+'</b>');
                                    $("#m22").html('<b>'+m22+'</b>');
                                    $("#m33").html('<b>'+m33+'</b>');
                                    $("#m44").html('<b>'+m44+'</b>');
                                    $("#m55").html('<b>'+m55+'</b>');
                                    $("#m66").html('<b>'+m66+'</b>');
                                    $("#startmonth").val(1);
                                    $("#startmonth2").val(Number(year)+1);
                                  $.post("pipeline_employee_target_intermediate.php",{mon:"01",yea:year},function test(data){
                                       
                                        $('#exe_result1').html(data);
                                    });
                                }
                                $('#condition_button').val('next');
                            }
                            
                        </script>
            
            <?php
            for($lm=0;$lm<count($emp_emailid_a);$lm++){
                $email1=$emp_emailid_a[$lm];
                $employeename=$objemployee->salesemployeename($email1);
                $commom_res=$objpipeline->salescommontarget($companyname,$email1);
                $commomamount1=0;
                $string = preg_replace('/[^\p{L}\p{N}\s]/u', '', $email1);
                foreach($commom_res as $commom_row){
                    $commomamount1=$commom_row['common_amt'];
                }
                if($commom_res->rowCount()>0){
                    $commomamount=$commomamount1;
                }else{
                    $commomamount=5000;
                }
            ?>
            <script>
                function showrefresh(hide1, show1){
                    $("#"+hide1).hide();
                    $("#"+show1).show();
                }
            </script>
            <div class="row" style="padding-top:5px;padding-bottom:5px;<?php if($lm%2==0){ ?>background-color:#f5f5f5; <?php }else{ ?>background-color:white;<?php } ?>">
            
                <div class="col-md-3">
                    <b><?php echo $employeename;?></b><br>
                    Default&nbsp; &nbsp; &#8360 &nbsp;<?php echo $commomamount;?>&nbsp;&nbsp; <span onclick="showrefresh('<?php echo "hide".$string;?>','<?php echo $string;?>')" id="<?php echo 'hide'.$string;?>"><i class="glyphicon glyphicon-pencil"></i></span>
                    <span style="display:none;" id="<?php echo $string;?>">
                        <input type="text" name="<?php echo $string.'common_amount_update';?>" value="<?php echo $commomamount;?>" id="<?php echo $string.'common_amount_update';?>">
                        <span  style="color:green;cursor:pointer;" onclick="commontargetfun('<?php echo $string.'common_amount_update';?>','<?php echo $email1;?>','<?php echo $commomamount;?>')"><i class="glyphicon glyphicon-refresh"></i></span>
                    </span>
                </div>
                
                
                <div class="col-md-9"  id="exe_result1">
                
                
                            <?php
                            $i=date('m');
                                $year=date('Y');
                                $months=$year."-".$i."-01";
                                //salespipelineemployeetarget($companyname,$email,$year,$month) $emp_emailid_a
                                    $traget_amount=0;
                                        $totaldeal_res=$objpipeline->salespipelineemployeetarget($companyname,$email1,$year,$i);
                                        $totaldealwon=0;
                                        if($totaldeal_res->rowCount()>0){
                                        foreach($totaldeal_res as $totaldeal_row){
                                            $totaldealwon=$totaldeal_row['amount'];
                                        }
                                        $traget_amount=$traget_amount+$totaldealwon;
                                        }else{
                                            $traget_amount=$traget_amount+5000;
                                        }
                                        if($traget_amount==null){
                                            $traget_amount=5000;
                                        }
                            ?> 
                            <div class="col-md-2">
                                <input type="text" class="form-control" name="<?php echo $string.'@@@'.$i.'@@@'.$year;?>" onchange="getinputfunction('<?php echo $email1."@@@".$i."@@@".$year;?>','<?php echo $string."___".$i."___".$year;?>')" id="<?php echo $string.'___'.$i.'___'.$year;?>" value="<?php echo $traget_amount;?>">
                            </div>
                           
                           
                           
                            <?php
                            $i=date('m',strtotime($months.'+1 months'));
                                $year=date('Y',strtotime($months.'+1 months'));
                                
                                //salespipelineemployeetarget($companyname,$email,$year,$month) $emp_emailid_a
                                    $traget_amount=0;
                                        $totaldeal_res=$objpipeline->salespipelineemployeetarget($companyname,$email1,$year,$i);
                                        $totaldealwon=0;
                                        if($totaldeal_res->rowCount()>0){
                                        foreach($totaldeal_res as $totaldeal_row){
                                            $totaldealwon=$totaldeal_row['amount'];
                                        }
                                        $traget_amount=$traget_amount+$totaldealwon;
                                        }else{
                                            $traget_amount=$traget_amount+5000;
                                        }
                                        if($traget_amount==null){
                                            $traget_amount=5000;
                                        }
                            ?> 
                            <div class="col-md-2">
                                <input type="text" class="form-control" name="<?php echo $string.'@@@'.$i.'@@@'.$year;?>" onchange="getinputfunction('<?php echo $email1."@@@".$i."@@@".$year;?>','<?php echo $string."___".$i."___".$year;?>')" id="<?php echo $string.'___'.$i.'___'.$year;?>" value="<?php echo $traget_amount;?>">
                            </div>
                     
                      
                            <?php
                            $i=date('m',strtotime($months.'+2 months'));
                                $year=date('Y',strtotime($months.'+2 months'));
                                
                                //salespipelineemployeetarget($companyname,$email,$year,$month) $emp_emailid_a
                                    $traget_amount=0;
                                        $totaldeal_res=$objpipeline->salespipelineemployeetarget($companyname,$email1,$year,$i);
                                        $totaldealwon=0;
                                        if($totaldeal_res->rowCount()>0){
                                        foreach($totaldeal_res as $totaldeal_row){
                                            $totaldealwon=$totaldeal_row['amount'];
                                        }
                                        $traget_amount=$traget_amount+$totaldealwon;
                                        }else{
                                            $traget_amount=$traget_amount+5000;
                                        }
                                        if($traget_amount==null){
                                            $traget_amount=5000;
                                        }
                            ?> 
                            <div class="col-md-2">
                                <input type="text" class="form-control" name="<?php echo $string.'@@@'.$i.'@@@'.$year;?>" onchange="getinputfunction('<?php echo $email1."@@@".$i."@@@".$year;?>','<?php echo $string."___".$i."___".$year;?>')" id="<?php echo $string.'___'.$i.'___'.$year;?>" value="<?php echo $traget_amount;?>">
                            </div>
                            
                            <?php
                            $i=date('m',strtotime($months.'+3 months'));
                                $year=date('Y',strtotime($months.'+3 months'));
                                
                                //salespipelineemployeetarget($companyname,$email,$year,$month) $emp_emailid_a
                                    $traget_amount=0;
                                        $totaldeal_res=$objpipeline->salespipelineemployeetarget($companyname,$email1,$year,$i);
                                        $totaldealwon=0;
                                        if($totaldeal_res->rowCount()>0){
                                        foreach($totaldeal_res as $totaldeal_row){
                                            $totaldealwon=$totaldeal_row['amount'];
                                        }
                                        $traget_amount=$traget_amount+$totaldealwon;
                                        }else{
                                            $traget_amount=$traget_amount+5000;
                                        }
                                        if($traget_amount==null){
                                            $traget_amount=5000;
                                        }
                            ?> 
                            <div class="col-md-2">
                                <input type="text" class="form-control" name="<?php echo $string.'@@@'.$i.'@@@'.$year;?>" onchange="getinputfunction('<?php echo $email1."@@@".$i."@@@".$year;?>','<?php echo $string."___".$i."___".$year;?>')" id="<?php echo $string.'___'.$i.'___'.$year;?>" value="<?php echo $traget_amount;?>">
                            </div>
                            
                            <?php
                            $i=date('m',strtotime($months.'+4 months'));
                                $year=date('Y',strtotime($months.'+4 months'));
                                
                                //salespipelineemployeetarget($companyname,$email,$year,$month) $emp_emailid_a
                                    $traget_amount=0;
                                        $totaldeal_res=$objpipeline->salespipelineemployeetarget($companyname,$email1,$year,$i);
                                        $totaldealwon=0;
                                        if($totaldeal_res->rowCount()>0){
                                        foreach($totaldeal_res as $totaldeal_row){
                                            $totaldealwon=$totaldeal_row['amount'];
                                        }
                                        $traget_amount=$traget_amount+$totaldealwon;
                                        }else{
                                            $traget_amount=$traget_amount+5000;
                                        }
                                        if($traget_amount==null){
                                            $traget_amount=5000;
                                        }
                            ?> 
                            <div class="col-md-2">
                                <input type="text" class="form-control" name="<?php echo $string.'@@@'.$i.'@@@'.$year;?>" onchange="getinputfunction('<?php echo $email1."@@@".$i."@@@".$year;?>','<?php echo $string."___".$i."___".$year;?>')" id="<?php echo $string.'___'.$i.'___'.$year;?>" value="<?php echo $traget_amount;?>">
                            </div>
                            
                            <?php
                            $i=date('m',strtotime($months.'+5 months'));
                                $year=date('Y',strtotime($months.'+5 months'));
                                
                                //salespipelineemployeetarget($companyname,$email,$year,$month) $emp_emailid_a
                                    $traget_amount=0;
                                        $totaldeal_res=$objpipeline->salespipelineemployeetarget($companyname,$email1,$year,$i);
                                        $totaldealwon=0;
                                        if($totaldeal_res->rowCount()>0){
                                        foreach($totaldeal_res as $totaldeal_row){
                                            $totaldealwon=$totaldeal_row['amount'];
                                        }
                                        $traget_amount=$traget_amount+$totaldealwon;
                                        }else{
                                            $traget_amount=$traget_amount+5000;
                                        }
                                        if($traget_amount==null){
                                            $traget_amount=5000;
                                        }
                            ?> 
                            <div class="col-md-2">
                                <input type="text" class="form-control" name="<?php echo $string.'@@@'.$i.'@@@'.$year;?>" onchange="getinputfunction('<?php echo $email1."@@@".$i."@@@".$year;?>','<?php echo $string."___".$i."___".$year;?>')" id="<?php echo $string.'___'.$i.'___'.$year;?>" value="<?php echo $traget_amount;?>">
                            </div>
                </div>
            
            </div>
            <?php
            }
            ?>
            
            <textarea class="form-control" id="update_employee_target" style="display:none;"></textarea>
        
        
        <br>
        <center><input type="submit" onclick="savethetarget();" class="btn btn-primary"></center>
        
        <script>
            function getinputfunction(id,id1){
                var value=$("#"+id1).val();
                /*alert(value);
                alert(id);*/
                var text=$("#update_employee_target").val();
                var value1=text+""+id+"@@@"+value+"___";
                //alert(value1);
                $("#update_employee_target").val(value1);
                
            }
        </script>
        <script>
            function savethetarget(){
                var text=$("#update_employee_target").val();
                //alert(text);
                if(text!=""){
                $.ajax({
                   url:"pipeline_intermediate.php",
                   data:{text:text},
                   type:"post",
                   success:function(respond){
                       alert(respond);
                      window.location.reload();
                   }
                });
                }
            }
        </script>

        <script>
            function commontargetfun(id, em, default1){
                var value=$("#"+id).val();
                //alert(value);
                if(default1!=value){
                    $.ajax({
                       url:"pipeline_intermediate.php",
                       data:{common:value, em:em},
                       type:"post",
                       success:function(respond){
                           //alert(respond);
                          window.location.reload();
                       }
                    });
                }
            }
        </script>
        
    </body>
    
</html>
<?php
}else{
echo "<script> location.replace('http://fieldcloud.in/Login.php') </script>";
}?>