<?php
  if(stripos($_SERVER['SCRIPT_NAME'],"/admin/")===false?false:true){
		
?>
	<!-- Select SalesmanQuota Year Modal -->
    <div class="modal fade" id="selectSalesmanQuotaYear" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Select Year</h4>
          </div>
          <div class="modal-body">
            <div>
            <div class="form-group">
            	<label for="salesmanQuotaYear">Year:</label>
            		<input class="form-control" type="text" name="salesmanQuotaYear" id="salesmanQuotaYear" value="<?= date("Y") ?>" />
            </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" id="modalSalesmanQuotaYearGo" class="btn btn-primary">Go</button>
          </div>
        </div>
      </div>
    </div>
		<script>
			$('#modalSalesmanQuotaYearGo').on('click', function(){
				window.location = "mod.php?p=salesmanquota&a=manage&year=" + 	$('#salesmanQuotaYear').val();
			});
		</script>
    <!-- Select Date Modal End -->
		
		
		<div class="modal fade" id="editSalesmanQuota" tabindex="-1" role="dialog">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title">Edit Quota</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal">
							<div class="form-group">
								<label for="editSalesmanQuotaSalesman" class="col-sm-4 control-label">Salesman</label>
								<div class="col-sm-8">
									<input type="text" readonly class="form-control" id="editSalesmanQuotaSalesman" placeholder="">
								</div>
							</div>
							<div class="form-group">
								<label for="editSalesmanQuotaSalesmanName" class="col-sm-4 control-label">Salesman Name</label>
								<div class="col-sm-8">
									<input type="text" readonly class="form-control" id="editSalesmanQuotaSalesmanName" placeholder="">
								</div>
							</div>
							
							<div class="form-group">
								<label for="editSalesmanQuotaMonthYear" class="col-sm-4 control-label">Month - Year</label>
								<div class="col-sm-8">
									<input type="text" readonly class="form-control" id="editSalesmanQuotaMonthYear" placeholder="">
								</div>
							</div>
							<div class="form-group">
								<label for="editSalesmanQuotaMTD" class="col-sm-4 control-label">MTD</label>
								<div class="col-sm-8">
									<input type="text" readonly class="form-control" id="editSalesmanQuotaMTD" placeholder="">
								</div>
							</div>
							<div class="form-group">
								<label for="editSalesmanQuotaTarget" class="col-sm-4 control-label">Target</label>
								<div class="col-sm-8">
									<input type="text" readonly class="form-control" id="editSalesmanQuotaTarget" placeholder="">
								</div>
							</div>
							<div class="form-group">
								<label for="editSalesmanQuotaQuota" class="col-sm-4 control-label">Quota</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="editSalesmanQuotaQuota" placeholder="">
								</div>
							</div>
							<div class="form-group">
								<label for="editSalesmanQuotaDifference" class="col-sm-4 control-label"></label>
								<div class="col-sm-8">
									<input type="text" readonly class="form-control" id="editSalesmanQuotaDifference" placeholder="">
								</div>
							</div>
							<input type="hidden" id="editSalesmanQuotaMonth">
							<input type="hidden" id="editSalesmanQuotaYear">
							<input type="hidden" id="editSalesmanQuotaOriginalQuota">
							<div class="form-group">
								<label for="editSalesmanQuotaPercent" class="col-sm-4 control-label">Modify by Percent</label>
								<div class="col-sm-3">
									<div class="input-group">
										<span class="input-group-btn">
											<button class="btn btn-default" id="editSalesmanQuotaPercent-" type="button">-</button>
										</span>
										<input type="text" class="form-control" id="editSalesmanQuotaPercent" name="editSalesmanQuotaPercent" placeholder="%">
										<span class="input-group-btn">
											<button class="btn btn-default" id="editSalesmanQuotaPercent+" type="button">+</button>
										</span>
									</div><!-- /input-group -->
								</div>
							</div><!-- /.col-lg-6 -->
						</form>
						<script>
							var quotaPercent = 0;
							$('#editSalesmanQuotaPercent-').on('click', function(){
								quotaPercent = $('#editSalesmanQuotaPercent').val();
								if(quotaPercent === ''){
									quotaPercent = 0;
								}
								quotaPercent--;
								$('#editSalesmanQuotaPercent').val(quotaPercent);
								$('#editSalesmanQuotaPercent').trigger('change');
								
							});
							$('#editSalesmanQuotaPercent+').on('click', function(){
								quotaPercent = $('#editSalesmanQuotaPercent').val();
								if(quotaPercent === ''){
									quotaPercent = 0;
								}
								quotaPercent++;
								$('#editSalesmanQuotaPercent').val(quotaPercent);
								$('#editSalesmanQuotaPercent').trigger('change');
								
							});
							$('#editSalesmanQuotaPercent').on('change', function(){
								quotaPercent = $('#editSalesmanQuotaPercent').val();
								quotaPercent = 1 + parseFloat(quotaPercent)/100;
								var originalQuota = $('#editSalesmanQuotaOriginalQuota').val();
								$('#editSalesmanQuotaQuota').val(Math.round((originalQuota* quotaPercent)*100)/100);
							});
						</script>
						
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
						<button type="button" class="btn btn-primary" onclick="saveSalesmanQuota();">Save changes</button>
					</div>
				</div><!-- /.modal-content -->
			</div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
<?php
  }elseif(!$isCustomer){
?>

<!-- SALESMAN QUOTA MODAL -->
    	<div class="modal fade" id="salesmanQuotaModal"  tabindex="-1" role="dialog" aria-labelledby="salesmanQuotaModal" aria-hidden="true">
          <div class="modal-dialog modal-sm">
            <div class="modal-content">
              <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                      <h4 class="modal-title" id="salesmanQuotaModalTitle">This Month Quota:</h4>
              </div>
              <div class="modal-body">
				<div class="container-fluid">
					<div class="row">
						<div style="font-weight: bold;" class="col-md-8">Goal:</div>
						<div class="col-md-4"><span id="salesmanQuotaGoal"></span></div>
					</div>
					<div class="row">
						<div style="font-weight: bold;" class="col-md-8">Current Sales:</div>
						<div class="col-md-4"><span id="salesmanQuotaCurrSales"></span></div>
					</div>
					<div class="row">
						<div style="font-weight: bold;" class="col-md-8">Daily Sales Required: </div>
						<div class="col-md-4"><span id="salesmanQuotaDaily"></span></div>
					</div>
					<div class="row">
						<div style="font-weight: bold;" class="col-md-8">Current Payments: </div>
						<div class="col-md-4"><span id="salesmanQuotaCurrPayments"></span></div>
					</div>
					<br>
					<div class="row">
						<div style="font-weight: bold;" class="col-md-12">Completed Progress:
							<div class="progress">
								<div class="progress-bar" id="salesmanQuotaProgress" role="progressbar" aria-valuenow="" aria-valuemin="0" aria-valuemax="100" style="width:0%">
									70%
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div id="QuotaMonthArrows" style="font-weight: bold; text-align: center;" class="col-md-12">YTD Progress
							
						</div>
					</div>
				</div>
                   
					 <span><b> </b></span><br />
					 
	          </div>
              <div class="modal-footer">
	           
              </div>
                
            </div>
          </div>
        </div>
        <script type="text/javascript">

        function openSalesmanQuota(){
					$('#salesmanQuotaModal').modal('show');
					$.get('mod.php?p=salesmanquota&a=functions&f=getSalesmanQuota&sid=' + "<?= $_SESSION['SalesmanID']  ?>", function(data){
							data = JSON.parse(data);
							$('#salesmanQuotaCurrSales').text(moneyFormat(data.MTD));
							$('#salesmanQuotaGoal').text(moneyFormat(data.Goal));
							$('#salesmanQuotaDaily').text(moneyFormat(data.Average));
							$('#salesmanQuotaCurrPayments').text(moneyFormat(data.Payments));
							$('#salesmanQuotaProgress').text((data.Percent*100).toFixed(2) + "%");
							$('#salesmanQuotaProgress').attr("aria-valuenow", (data.Percent*100));
							$('#salesmanQuotaProgress').css("width", (data.Percent*100) + "%");
							$('#QuotaMonthArrows').html(data.Arrows);
							$(document).ready(function(){
								$('[data-toggle="popover"]').popover();		
							});
							
					});
				}
            
            
        </script>
        <!-- END SALESMAN QUOTA MODAL -->
<?php
  }

?>