<?php $this->load->view("common/header"); ?>
<!-- end: HEAD -->


<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->
<!-- end: HEAD -->
<!-- start: BODY -->
<body>

<!-- start: HEADER -->
<div class="navbar navbar-inverse navbar-fixed-top"> 
  <!-- start: TOP NAVIGATION CONTAINER -->
  <div class="container">
    <div class="navbar-header"> 
      <!-- start: RESPONSIVE MENU TOGGLER -->
      <button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button"> <span class="clip-list-2"></span> </button>
      <!-- end: RESPONSIVE MENU TOGGLER --> 
      <!-- start: LOGO -->
      <?php $this->load->view("common/logo"); ?>
      <!-- end: LOGO --> 
    </div>
    <div class="navbar-tools"> 
      <!-- start: TOP NAVIGATION MENU -->
      <?php $this->load->view("common/notifications.php"); ?>
      <!-- end: TOP NAVIGATION MENU --> 
    </div>
  </div>
  <!-- end: TOP NAVIGATION CONTAINER --> 
</div>
<!-- end: HEADER --> 
<!-- start: MAIN CONTAINER -->
<div class="main-container">
<div class="navbar-content"> 
  <!-- start: SIDEBAR -->
  <?php $this->load->view("common/navigation"); ?>
  <!-- end: SIDEBAR --> 
</div>
<!-- start: PAGE -->
<div class="main-content">
<!-- end: SPANEL CONFIGURATION MODAL FORM -->
<div class="container">
<!-- start: PAGE HEADER -->
<div class="row">
  <div class="col-sm-12"> 
    <!-- start: PAGE TITLE & BREADCRUMB -->
    <ol class="breadcrumb">
      <li> <a href="#"> Dashboard </a> </li>
      <li> <a href="<?php echo base_url('sales2?s='.rand()); ?>"> Loading </a> </li>
      <li class="active"> Delivery Current Status </li>
      <li class="search-box">
        <form class="sidebar-search">
          <div class="form-group">
            <input type="text" placeholder="Start Searching...">
            <button class="submit"> <i class="clip-search-3"></i> </button>
          </div>
        </form>
      </li>
    </ol>
    <div class="page-header">
      <h1>Delivery Current Status</h1>
    </div>
  </div>
</div>
<!-- end: PAGE HEADER --> 
<!-- start: PAGE CONTENT 
                    <!-- start grid -->

<div class="row">
  <div class="col-md-12"> 
    <!-- start: DYNAMIC TABLE PANEL -->
    <div class="panel panel-default">
      <div class="panel-heading"> <i class="fa fa-plus"></i> Delivery Current Status </div>
      <div class="panel-body">
        <div class="alert alert-danger" style="display:none;">
          <button class="close" data-dismiss="alert"> × </button>
          <i class="fa fa-times-circle"></i> <strong></strong> <span class="errortxt"></span> </div>
        <div class="alert alert-success" style="display:none;">
          <button class="close" data-dismiss="alert"> × </button>
          <i class="fa fa-check-circle"></i> <strong></strong><span class="succetxt"></span> </div>
        <form role="form" class="form-horizontal" id="create_sales_form" action="#" method="post">
          <div class="col-md-12"></div>
          <!--col-md-12-->
          <div class="col-md-12">
            <div class="col-md-12">
              <div class="panel panel-default">
                <div class="panel-heading" style="font-weight: 700;">Date Time - <?php echo $delivary_details['loading_date_time']?> | Route - <?php echo $delivary_details['area_name']?> | Vehicle - <?php echo $delivary_details['vehicle_code']?> | Sales Rep - <?php echo $delivary_details['user_first_name']?> </div>
                <div class="panel-body">
                  <input type="hidden" name="delivary_id" value="<?php echo $delivary_details['id']?>">
                  <input type="hidden" name="route_id" value="<?php echo $delivary_details['route_id']?>">
                  <div class="col-md-12">
                    <div class="form-group">
                      <label> <h4>Sample List</h4></label>
                      <table class="table items table-striped table-bordered table-condensed table-hover" id="term_table">
                        <thead>
                          <tr>
                            <th class="col-md-7">Product</th>
                             <th class="col-md-1">Total<br>Qty</th>
                            <th class="col-md-1">Issued<br> Qty</th>
                            <th class="col-md-1">Balance<br> Qty</th>
                            <th class="col-md-1">Issued sample value</th>
                            <th class="col-md-1">Issued sample cost</th>
                          </tr>
                        </thead>
                        <tbody>
                          <?php
						  $total_sample_value=0;
						  $total_sample_cost=0;
						  $total_sample_qty=0;
						  $total_issued_sample_qty=0;
						  $total_balance_sample_qty=0;
						  
 						  foreach($delivary_items_sample as $row2){  
						  $total_sample_value+=$row2['issue_qty']*$row2['product_price'];
						  $total_sample_cost+=$row2['issue_qty']*$row2['product_cost'];
						  $total_sample_qty+=$row2['salse_rep_issue_qty'];
						  $total_issued_sample_qty+=$row2['issue_qty'];
						  $total_balance_sample_qty+=$row2['salse_rep_issue_qty']-$row2['issue_qty'];
 
 ?>
                          <tr data-item-id="144680019784" id="row_1446800197032">
                          <td><?php echo $row2['product_name']?> - (<?php echo $row2['book_year']?>) </td>
                          <td style="text-align:center"><?php echo $row2['salse_rep_issue_qty']?></td>
                          <td style="text-align:center" ><?php echo $row2['issue_qty']?></td>
                          <td style="text-align:center"><?php echo $row2['salse_rep_issue_qty']-$row2['issue_qty']?></td>
                          <td style="text-align:end"><?php if($row2['issue_qty']>0){echo number_format($row2['issue_qty']*$row2['product_price'],2);}?></td>
                          <td style="text-align:end"><?php if($row2['issue_qty']>0){echo number_format($row2['issue_qty']*$row2['product_cost'],2);}?></td>
                          </tr>
                          <?php }?>
                        </tbody>
                        <tfoot>
                         <tr class="tfoot active" id="tfoot">
                         <th >Total </th>
                         <th style="text-align:center" ><?php echo number_format($total_sample_qty,2);?></th>
                         <th style="text-align:center" ><?php echo number_format($total_issued_sample_qty,2);?></th>
                         <th style="text-align:center" ><?php echo number_format($total_balance_sample_qty,2);?></th>
                         <th style="text-align:end" ><?php echo number_format($total_sample_value,2);?></th>
                         <th style="text-align:end" ><?php echo number_format($total_sample_cost,2);?></th>
                         </tr>
                        </tfoot>
                      </table>
                      
     <hr>   
       <label><h4> Collected Payment </h4></label>
                      <table class="table items table-striped table-bordered table-condensed table-hover" id="term_table">
                        <thead>
                          <tr>
                            <th class="col-md-3">Customer<br>Code/Name </th>
                            
                            <th class="col-md-1">Settu<br>Number</th>
                            <th class="col-md-1">Settu Term<br> Value</th>
                            <th class="col-md-1">Enter By</th>
                            <th class="col-md-1">Tracking<br>Number</th>
                            <th class="col-md-1">Payment<br> Date</th>
                            <th class="col-md-1">Payment<br> Amount</th>
                            
                          </tr>
                        </thead>
                        <tbody>
                          <?php
						 
						  $total_collected_payment=0;
						
						  
 						  foreach($delivary_payment as $row3){  
						  $total_collected_payment+=$row3['received_amount'];
						 
 
 ?>
                          <tr data-item-id="144680019784" id="row_1446800197032">
                          <td>(<?php echo $row3['cus_code']?>) - <?php echo $row3['cus_name']?> </td>
                          <td style="text-align:center"><?php echo $row3['card_ref_number']."-".$row3['chit_id']?></td>
                          <td style="text-align:center" ><?php echo $row3['chit_term_value']?></td>
                          <td ><?php echo $row3['user_first_name']?></td>
                          <td ><?php echo $row3['document_ref_no']?></td>
                          <td ><?php echo $row3['system_added_date_time']?></td>
                          <td style="text-align:end"  ><?php echo $row3['received_amount']?></td>
                         
                          </tr>
                          <?php }?>
                        </tbody>
                        <tfoot>
                         <tr class="tfoot active" id="tfoot">
                         
                         <th class="col-md-3">Customer<br>Code/Name </th>
                         <th class="col-md-1">Settu<br>Number</th>
                            <th class="col-md-1">Settu Term<br> Value</th>
                            <th class="col-md-1">Enter By</th>
                            <th class="col-md-1">Tracking<br>Number</th>
                            <th class="col-md-1">Payment<br> Date</th>
                         <th style="text-align:end" ><?php echo number_format($total_collected_payment,2);?></th>
                         </tr>
                        </tfoot>
                      </table>
                      
     <hr>                               
  <label> <h4>Seettu Customers Order List </h4></label>                    
  <table class="table items table-striped table-bordered table-condensed table-hover" id="term_table" >
                        <thead>
                          <tr>
                          <th>Seettu Number</th>
                          <th>Order<br>Date</th> 
                          <th>Invoice<br>Date</th>                         
                           <th>Cus<br>No</th>  
                           <th >Customer</th>
                            <th>Tracking<br> Number</th>
                            <th >Product</th>
                            <th >Order<br>Qty</th>
                            <th >Invoice<br>Qty</th>
                            <th >Balance<br>Qty</th>
                             <th >Order<br>Rs.</th>
                            <th >Sale<br>Rs.</th>
                            <th >Cost<br>Rs.</th>
                            <th >Profit<br>Rs.</th>
                          </tr>
                        </thead>
                        <tbody>
                          <?php
$totqty=0;
$totinvoice=0;
$tot_sale=0;
$tot_cos=0;
$tot_order_value=0;
$count_cus=0;
$last_cus=0;
$total_order_vale=0;
 foreach($delivary_items_settu_order as $row2){
	$totqty+=$row2['product_qty'];
	$totinvoice+=$row2['inv_qty'];
	$tot_sale+=$row2['sale_value'];
	$tot_cos+=$row2['cost_value'];
	$balance_qty=$row2['product_qty']-$row2['inv_qty'];  
	$total_order_vale+=$row2['product_order_sale'];
	 if($last_cus!=$row2['cus_id'])
	 {
		$count_cus++; 
	 }
	 $last_cus=$row2['cus_id'];

?>
                          <tr data-item-id="144680019784" id="row_1446800197032">
                          
                          <td> <?php echo $row2['card_ref_number']."-".$row2['seetu_cus_master_id']?>      </td>                           <td> <?php echo $row2['order_date']?>      </td>
                          <td style="text-align:center"> <?php echo $row2['invoice_date']?>      </td>  
                          <td><?php echo $count_cus?></td>          
                             <td><?php echo $row2['cus_name']?></td>
                            
                            <td><?php echo $row2['inv_document_ref_number'];?></td>
                            <td> <?php echo $row2['product_name']?> - (<?php echo $row2['book_year']?>)  </td>
                             <td style="text-align:center"><?php  echo $row2['product_qty']?></td>
                              <td style="text-align:center"><?php if($row2['inv_qty']>0){echo number_format($row2['inv_qty'],2);}?></td>
                              <td style="text-align:center"><?php if($row2['inv_qty']!=0&&$balance_qty!=0){echo number_format($row2['product_qty']-$row2['inv_qty'],2);}?></td>
                            
                            
                            
                             <td style="text-align:end"><?php if($row2['product_order_sale']){echo number_format($row2['product_order_sale'],2);}?></td>
                             <td style="text-align:end"><?php if($row2['sale_value']>0){echo number_format($row2['sale_value'],2);}?></td>
                            <td style="text-align:end"><?php if($row2['cost_value']>0){echo number_format($row2['cost_value'],2);}?></td>
                            <td style="text-align:end"><?php if($row2['sale_value']>0){echo number_format($row2['sale_value']- $row2['cost_value'],2);}?></td>
                          </tr>
                          
                          <?php }?>
                        </tbody>
                        <tfoot>
                          <tr class="tfoot active" id="tfoot">
                          <th class="col-md-1">Seettu Number</th>
                           <th>Order Date</th> 
                           <th>Invoice<br>Date</th>
                           <th>Cus<br>No</th>                         
                            <th >Customer</th>                            
                            <th>Tracking<br> Number</th>
                            <th >Product</th>
                              <th style="text-align:center" ><?php echo number_format($totqty,2);?></th>
                            <th style="text-align:center" ><?php echo number_format($totinvoice,2);?></th>
                            <th style="text-align:center"><?php echo number_format($totqty-$totinvoice,2);?></th>
                             <th style="text-align:end"><?php echo number_format($total_order_vale,2);?></th>
                             <th style="text-align:end"><?php echo number_format($tot_sale,2);?></th>
                            <th style="text-align:end" ><?php echo number_format($tot_cos,2);?></th> 
                           
                            <th style="text-align:end" ><?php echo number_format($tot_sale-$tot_cos,2);?></th> 
                          </tr>
                        </tfoot>
                      </table>
                      
                       <hr>                 
  <label> <h4>Seettu Free Issue Order List</h4></label>                    
  <table class="table items table-striped table-bordered table-condensed table-hover" id="term_table">
                        <thead>
                          <tr>
                          <th class="col-md-1">Order Date</th>
                            <th class="col-md-2">Product</th>
                            <th class="col-md-1">Order<br>QTY</th>
                            <th class="col-md-1">Issue<br>Status</th>
                            <th class="col-md-1">Balance<br>QTY</th>
                            <th class="col-md-2">Customer</th>
                            <th class="col-md-2">Route</th>
                            <th class="col-md-2">City</th>
                          </tr>
                        </thead>
                        <tbody>
                          <?php
$totqty=0;
 foreach($delivary_items_free_issue_order as $row2){  

?>
                          <tr data-item-id="144680019784" id="row_1446800197032">
                          <td> <?php echo $row2['order_date']?>      </td>
                            <td>
                              <?php echo $row2['product_name']?> - (<?php echo $row2['book_year']?>)  </td>
                              <td><?php echo $row2['quantity'];?></td>
                              <td><?php if($row2['total_issue_qty']>0){echo $row2['total_issue_qty'];}?></td>
                              <td><?php if($row2['total_issue_qty']>0){echo number_format( $row2['quantity']-$row2['total_issue_qty'],2);}?></td>
                            <td><?php echo $row2['cus_name']?></td>
                            <td><?php echo $row2['route_name']?></td>
                            <td><?php echo $row2['city_name']?></td>
                          </tr>
                          <?php }?>
                        </tbody>
                        <tfoot>
                          <tr class="tfoot active" id="tfoot">
                           <th>Order Date</th>
                            <th>Product</th>
                            <th>Order<br>QTY</th>
                            <th>Issue<br>QTY</th>
                            <th>Balance<br>QTY</th>
                            <th>Customer</th>
                            <th>Route</th>
                            <th>City</th>
                          </tr>
                        </tfoot>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!--col-md-8-->
          
          <div class="col-md-12">
            <div class="modal-footer" style="margin-bottom:10px;">
           
            </div>
          </div>
        </form>
        
        <!-- end: DYNAMIC TABLE PANEL --> 
        
      </div>
    </div>
    
    <!-- end grid --> 
    
  </div>
  <!-- end: PAGE --> 
</div>
<!-- end: MAIN CONTAINER --> 
<!-- start: FOOTER -->
<div class="footer clearfix">
  <div class="footer-inner"> 2014 &copy; clip-one by cliptheme. </div>
  <div class="footer-items"> <span class="go-top"><i class="clip-chevron-up"></i></span> </div>
</div>
<!-- end: FOOTER --> 
<!-- start: RIGHT SIDEBAR --> 
<!-- end: RIGHT SIDEBAR -->
<div id="event-management" class="modal fade" tabindex="-1" data-width="760" style="display: none;">
  <div class="modal-dialog">
    <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">Event Management</h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-light-grey"> Close </button>
        <button type="button" class="btn btn-danger remove-event no-display"> <i class='fa fa-trash-o'></i> Delete Event </button>
        <button type='submit' class='btn btn-success save-event'> <i class='fa fa-check'></i> Save </button>
      </div>
    </div>
  </div>
</div>
<input name="tmpVal" type="hidden" id="tmpVal" value="0">
<input name="" id="type_sale" type="hidden" value="22">
<!-- start ajax model -->
<div id="ajax-modal" class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
<!-- end ajax model --> 

<!-- start: MAIN JAVASCRIPTS -->
<?php $this->load->view("common/footer"); ?>
<script src="<?php echo asset_url(); ?>js/jquery-ui.js" ></script> 
<script src="<?php echo asset_url(); ?>js/moment-with-locales.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/bootstrap-datetimepicker.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/bootbox.min.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.min.js"></script> 

<!-- end: MAIN JAVASCRIPTS --> 

<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY VALIDATION--> 
<script src="<?php echo asset_url(); ?>js/form-validation-create_chit.js"></script> 
<script src="<?php echo asset_url(); ?>js/chit_invoice.js"></script> 
<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION--> 

<script>




clearForm();






function insertSalesData(){
	
	
	var type='A';
	var sale_reference_no=$('#sale_reference_no').val();
	 var fields = $("#create_sales_form").serialize();
	  
	  var rowCount=$('#rowCount').val();

	  if(rowCount!=0){
		  $("#add_sale").prop("disabled", true);
		  $("#add_sale").val('Please wait...');

		
	$.post( "<?php echo base_url();?>marketing_order_management/save_arrangend_free_issue_order", fields)
	  .success ( function( data ) {
		  //window.alert(fields);
		  
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
				
				$('.alert-success').hide();
				$('.alert-danger').show();
				$( ".errortxt" ).text( obj.disMsg );
				window.scrollTo(500, 0);
				//empty item table
				
			}
			if(obj.error==0){
				
				window.scrollTo(500, 0);
				
				
				displayNotice('page','Seettu successfully added!');
				
				clearForm();
				 window.location.reload();
				//empty footer details
				
			
				
			}
			
		
			
			
	  }).fail(function (jqXHR, textStatus, error) {
    // Handle error here
    alert("Errror : All Data required. You miss some data - "+ error);
	location.reload();
	
}); 


	  }
	  else  
	  {
		 bootbox.alert('Please add terms.', function () {
                        $('#add_item').focus();
                    });
	  }
	  
}



 


//function to initiate bootstrap-datepicker
$(function () {
	//showKeys();
	
	var currentDate = new Date();
	
	
	$('#open_datetime').datetimepicker({
		defaultDate: new Date()
		});
	
	
	$("#supp_id").select2();
	$("#customer_id").select2();
	$("#route_id").select2();
	$("#sales_rep_id").select2();
	$("#warehouse_id").select2();
	
	
});	

$(document).ready(function() {
	
	 $('#in_type').focus();
	 
	

$(".noEnterSubmit").on('keyup', function (e) {
  
});



$('#add_sale').keypress(function(event){
	
});	
	
  $(window).keydown(function(event){
	 $(":focus").each(function() {
    //alert("Focused Elem_id = "+ this.id );
	focus_id=this.id;
	//	alert(focus_id);
	  //	alert(event.keyCode);
	  var rowCount=$('#rowCount').val();
	  var fld='quantity_'+rowCount;
	  if(focus_id==fld){
		if(event.keyCode == 16) {
			  $('#add_item').focus();
		}
	  }
    if(event.keyCode == 18) {
		
		
	setTimeout(function(){
  //alert();
	  $("#create_sales_form").submit()
    //do something special
	
	
	
	
  }, 1000);
  
  
	//	alert(114);
	
		
		//$('#create_sales_form').submit(function(){return true;});
     // event.preventDefault();
     // return false;
    }
		  
    if(event.keyCode == 13) {
      event.preventDefault();
     return false;
    }
  });
  
  });
});


function pickup_sheet_print(id) 
{
	u=location.href;
	t=document.title;
	window.open('<?php echo base_url() ?>marketing_delivery_process/pick_up_sheet_print?id='+id,'sharer','toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');return false;
}

function delivery_sheet_print(id) 
{
	u=location.href;
	t=document.title;
	window.open('<?php echo base_url() ?>marketing_delivery_process/delivery_sheet_print?id='+id,'sharer','toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');return false;
}










</script>
</body>
<!-- end: BODY -->
</html>