<style type="text/css">
.fa-3x {
  font-size: 2em !important;
}
.report_view_th{
	background-color:#428bca;
	color:#fff !important;
	font-size:14px;	
}
.table-responsive td{
	font-size:14px;	
}
h4{
	font-size:13px;
}
</style>
		
		</style>

	<?php $this->load->view("common/header"); ?>
	<!-- end: HEAD -->
       
		<!-- start: CSS REQUIRED FOR THIS PAGE ONLY -->
		<link rel="stylesheet" type="text/css" href="<?php echo asset_url(); ?>plugins/select2/select2.css" />
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/DataTables/media/css/DT_bootstrap.css" />
		<link href="<?php echo asset_url(); ?>plugins/bootstrap-modal/css/bootstrap-modal-bs3patch.css" rel="stylesheet" type="text/css"/>
		<link href="<?php echo asset_url(); ?>plugins/bootstrap-modal/css/bootstrap-modal.css" rel="stylesheet" type="text/css"/>
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-fileupload/bootstrap-fileupload.min.css">
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/select2/select2.css">


		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/select2/select2.css">
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/datepicker/css/datepicker.css">
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css">
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-daterangepicker/daterangepicker-bs3.css">
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.css">
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/jQuery-Tags-Input/jquery.tagsinput.css">
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-fileupload/bootstrap-fileupload.min.css">
		<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/summernote/build/summernote.css">
        
          <link rel="stylesheet" type="text/css" href="<?php echo asset_url(); ?>css/jquery.dataTables.css">
          
          
          
          


		<!-- 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="<?php echo base_url('dashboard'); ?>">
										 Dashboard 
									</a>
								</li>
								<li>
									<a href="<?php echo base_url('sales'); ?>">
										  Issue Cards
									</a>
								</li>
                               
								<li class="active">
									Cash Collction Details
								</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">  
                               <?php  
							   $message = $this->session->flashdata('message');
							   if($message){ ?>
                               	<div class="alert alert-success">
									<button type="button" class="close" data-dismiss="alert">×</button>
<?php echo $message ?> </div>
                               		
                               <?php
                               }
							    ?>
                               
                                 
							</div>

                            
						</div>
					</div>
					<!-- end: PAGE HEADER -->
					<!-- start: PAGE CONTENT 
                    <!-- start grid -->
                   
						<div class="col-md-12">
							<!-- start: DYNAMIC TABLE PANEL -->
							
                                
                                <div class="panel-heading">
                                
                                
                                
									<i class="fa fa-external-link-square"></i> 
									 <?php  if(isset($issue_card_details)){echo "Cash Collction No :" .$issue_card_details['issue_card_ref_no']." \ ";}else{ echo "Sorry .There is no any issue card for you.";}?><?php if(isset($issue_card_details)){echo " Date: ". $issue_card_details['issue_card_date']." \ ";}?> <?php if(isset($cash_collector_details)){ echo $cash_collector_details['user_first_name']." \ ";}?><?php if(isset($wharehose_details)){echo $wharehose_details['name'];}?> 
                
                
                
                
                                    
                                     
									
                                    
                                  
								</div> <!--panel-heading-->
                                
                                
                                 <div class="col-md-8">  
               
                
                
                
                
                
                
                
                
                </div>
                
                <div class="col-md-4"> 
                  <select  id="cash_collector_id" class="form-control" name="cash_collector_id" onChange="add_recevble_invoice()">
<option value="">-Select Cash Collector-</option>
						
  <?php 						
						foreach ($cash_collector_list as $row)
							{?>
                            
                            <option  value="<?php echo $row['user_id'];?>"><?php echo $row['user_first_name'];?></option>						   
                            
							<?php }  ?>									 
						     						
</select>
                </div>
                
                              
                              
                              
                               
                              
                               
                                
								
									 




  
  







<input name="sale_id" type="hidden" id="sale_id" value="">
<input type="hidden" id="sale_type" name="sale_type" value="sale">





<div class="table-responsive">
<table class="table table-bordered table-hover table-striped print-table order-table" id="cash_collect_list">
<thead>
<tr class="report_view_th">
<th style="text-align:center; vertical-align:middle;">No</th>
<th>Customer Name</th>
<th style="text-align:center; vertical-align:middle;">Sales Referance Number</th>
<th style="text-align:center; vertical-align:middle;">To Be Paid</th>
<th style=" text-align:center; padding-right:20px;">Outstanding</th>
<th style=" text-align:center;padding-right:20px;">Payment</th>

<th style=" text-align:center;padding-center:20px;">Action</th>
</tr>
</thead>
<tbody id="tbodyid">
<?php 

if(isset($issue_card_items_details))
{
 $tmpcount=0;
 $tmptot=0;
 
 
  foreach ($issue_card_items_details as $row)
 {

	$tmpcount++;
	$tmptot=$tmptot+$row['invoice_total'];
	$invoice_total=$row['invoice_total'];
	$downpayment= $row['totat_down_payment'];
	$term_amount= $row['term_amount'];  
	$no_of_days= $row['no_of_days']; 
	$sale_paid= $row['sale_pymnt_amount'];
	$record_date_temp= $row['sale_datetime']; 	
	$record_date= new DateTime($record_date_temp);
	$record_date_final = $record_date->format('Y-m-d');
	$now_date = new DateTime();
	$now_date_final = $now_date->format('Y-m-d');
	
	
	
	
	$date1=date_create($record_date_final);
	$date2=date_create($now_date_final);
	$diff=date_diff($date1,$date2);
	$diffdate= $diff->format("%a");
	
	
	if($no_of_days>=$diffdate)
	{
	$shoud_be_paid=$downpayment+($term_amount*$diffdate);	
	}
	else 
	{
	$shoud_be_paid=$downpayment+($term_amount*$no_of_days);	
	}
	
	$temp=$shoud_be_paid-$sale_paid;
	
	if($temp>0)
	{
	$shoud_be_paid_today=$shoud_be_paid-$sale_paid;	
		
	}
	else
	{
	$shoud_be_paid_today=$invoice_total-$sale_paid;	
	}
	
	
	
	 
	
	
	
	
	
	?>
    
    
    
    <br>
    
    

   
	
    
<tr>
<td style="text-align:center; width:40px; vertical-align:middle;"><?php echo $tmpcount ?></td>
<td style="vertical-align:middle; "> <?php echo $row['cus_name'];?>

</td>

<td style="text-align:center; width:120px; padding-right:10px;"> <?php echo sprintf("%05d",$row['sale_id'])   ?></td>
<td style="text-align:right; width:120px; padding-left:10px;"><?php echo number_format($row['invoice_total']-$row['sale_pymnt_amount'], 2, '.', ','); ?></td>
 <td style="text-align:right; width:120px; padding-right:10px;"><?php echo number_format($shoud_be_paid_today, 2, '.', ','); ?></td>
<td style="text-align:right; width:120px; padding-center:10px;"><input type="text" align="center" name="payment" id="<?php echo 'p_'. $row['sale_id']; ?>" value="0.00"  class="form-control datetime text-right"></td>

<td style="text-align:right; width:120px; padding-right:10px;"><div class="btn-group" onClick="cash_collect(<?php echo $row['sale_id']; ?>)"><a title="" class="btn btn-primary btn-xs" data-original-title="Add"><i class="fa fa-money"></i> <span class="hidden-sm hidden-xs">Add</span></a>
</div> <?php echo '<div class="btn-group text-left">
                       
					        <button data-toggle="dropdown" class="btn btn-default btn-xs btn-primary dropdown-toggle" type="button">Actions <span class="caret"></span></button>
                            <ul role="menu" class="dropdown-menu pull-right">
                           
							<li><a href="'.base_url().'sales2/view/'.$row['sale_id'].'"><i class="fa fa-file-text-o"></i>Sale Details</a></li>
							
							<li><a href="'.base_url().'cash_collect/print_payment_slip?sale_id='.$row['sale_id'].'"><i class="fa fa-file-text-o"></i>Print Payment Slip</a></li>
							
                            </ul></div>'; ;?>



</td>
</tr>
<?php }}?>
</tbody>
<tfoot>









<tr>
  <td style="text-align:right; padding-right:10px;" colspan="6">&nbsp;</td>
  <td style="text-align:right; padding-right:10px;">&nbsp;</td>
</tr>
</tfoot>
</table>



</div> <!--table-responsive-->



<div class="clearfix"></div>

<!-- payment list -->


<div class="clearfix"></div>
<br>
<div class="clearfix"></div>
<!-- end payment list-->




                                     
                                   
								</div> <!--panel-body-->
							</div><!--panel-->
							
						</div> <!--col-md-12-->
					</div> <!--row-->

					
                    <!-- 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>

		<!-- 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"); ?>
		<!-- end: MAIN JAVASCRIPTS -->

        
  
        
		<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
		<script src="<?php echo asset_url(); ?>plugins/jquery-inputlimiter/jquery.inputlimiter.1.3.1.min.js"></script>
		<script src="<?php echo asset_url(); ?>plugins/jquery.maskedinput/src/jquery.maskedinput.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>plugins/bootbox/bootbox.min.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>plugins/jquery-mockjax/jquery.mockjax.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>plugins/DataTables/media/js/jquery.dataTables.min.js"></script>
		<script type="text/javascript" src="<?php echo asset_url(); ?>plugins/DataTables/media/js/DT_bootstrap.js"></script>
		<script src="<?php echo asset_url(); ?>js/table-data.js"></script>
		<script src="<?php echo asset_url(); ?>plugins/bootstrap-modal/js/bootstrap-modal.js"></script>
		<script src="<?php echo asset_url(); ?>plugins/bootstrap-modal/js/bootstrap-modalmanager.js"></script>
		<script src="<?php echo asset_url(); ?>js/ui-modals.js"></script>
		<script src="<?php echo asset_url(); ?>plugins/bootstrap-fileupload/bootstrap-fileupload.min.js"></script>
		<script src="<?php echo asset_url(); ?>plugins/select2/select2.min.js"></script>
        
       <script src="<?php echo asset_url(); ?>plugins/jQuery-lib/2.0.3/jquery.min.js"></script>
		<script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/jquery.dataTables.js"></script>

		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
		<script>
			jQuery(document).ready(function() {
				//TableData.init();
				//Main.init();
				//TableData.init();
				//UIModals.init();

			});
		</script>
        
<script type="text/javascript" language="javascript" >


/*var j = jQuery.noConflict();
function loadGrid(){
	alert();
	j('#employee-grid').DataTable().ajax.reload();
}
	jQuery(document).ready(function() {
		var dataTable = j('#employee-grid').DataTable( {
			"processing": true,
			"serverSide": true,
			"ajax":{
				url :"sales/list_sales", // json datasource
				type: "post",  // method  , by default get
				error: function(){  // error handling
					j(".employee-grid-error").html("");
					j("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
					//$("#employee-grid_processing").css("display","none");
				}
			}
		} );
		
	} );
*/


function cash_collect(id)

{
	
	var sale_id=id;
	var amount=(document.getElementById("p_"+id).value);
	var sale_type="sale";
	window.alert(amount);
	
	
	
	if($.isNumeric(amount)){
	
	var fields='';
	$.post( '<?php echo base_url() ?>cash_collect/add_sale_payments?sale_id='+id+'&sale_type=sale&amount='+amount, fields)
	.done(function( data ) {
		  //alert();
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){

			}
			if(obj.error==0){
				displayNotice('page','Payment Added!');
			}
			
	  });
	  }else{
		displayNotice('page','Invalid Amount');
	}
	return false;
	
	
	
	
	
}
	/*jQuery(document).ready(function() {
				//TableData.init();
				Main.init();
				//TableData.init();
				UIModals.init();

			});
	
	
	
	window.alert("sale id : "+id);
	
	window.alert("amount : "+amount);
	var $modal = $('#ajax-modal');
	//$('body').modalmanager('loading');
	
	setTimeout(function () {
//						 
                       $modal.modal();
						$('#sale_pymnt_amount').focus(); 
                    });
                }, 1000);
}
				
				function popUpPaymentBox(){
			
               
               var $modal = $('#ajax-modal');
                setTimeout(function () {
                    $modal.load('<?php// echo base_url("sales/payments?id='+sale_id+'&sale_type="); ?>'+sale_type, '', function () {
                        $modal.modal();
						$('#sale_pymnt_amount').focus(); 
                    });
                }, 1000);
				
				
	
}
*/


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

	
}


function add_recevble_invoice()
{ 


$("#tbodyid").empty();



$.ajax({
      type: 'POST',
      url: "<?php echo  base_url(); ?>cash_collect/get_all_recivble_invoice_by_cash_collectr_id?CI="+$("#cash_collector_id").val(),
      success: function(result) {
        
		
		
				var obj = JSON.parse(result);
				
				Object.size = function(obj) {
   				 var size = 0, key;
   			 for (key in obj) {
       			 if (obj.hasOwnProperty(key)) size++;
  				  }
  			  return size;
				};
				
				var size = Object.size(obj);
				
				for(c=0;c<size;c++)
				{
		       		var sale_id=obj[c].sale_id;
					var sale_reference_no=obj[c].sale_reference_no;
					var sale_total=obj[c].sale_total;
					var sale_pymnt_amount=obj[c].sale_pymnt_amount;
					var totat_down_payment=obj[c].totat_down_payment;
					var term_amount=obj[c].term_amount;
					var no_of_days=obj[c].no_of_days;
					var sale_datetime=obj[c].sale_datetime;
					
					
					
					var record_date = new Date(sale_datetime).toLocaleDateString(); 				
					var system_date = new Date().toLocaleDateString(); 
                    
					//window.alert(system_date);
					//window.alert(record_date);
					
					var date1 = new Date(record_date);
					var date2 = new Date(system_date);
					var timeDiff = Math.abs(date2.getTime() - date1.getTime());
					var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
					
					window.alert(sale_id+"-"+sale_reference_no+"-"+sale_total);
					
				}
		
		
		
		
		
		
		
		
      },
  });













/*
$.post("<?php //echo  base_url(); ?>issue_cards/get_all_sales_by_route_id?RI="+$("#route_id").val(), 


function(data) {

count=0;


 $.each(data[i], function(key,val) {
            alert(key+val);
count=count+1;

addProductToListByID(count,i,key,val); 

 
 

})
},"json");
*/



$('#warehouse_id option:not(:selected)').prop('disabled', true);


}


jQuery(document).ready(function() {
				
				loadGrid();
			});


			function loadGrid() {

					    $('#cash_collect_list').DataTable({
					        "ajax": "<?php echo base_url() ?>cash_collect/get_all_recivble_invoice_by_cash_collectr_id?CI="+$("#cash_collector_id").val(),
					        "bDestroy": true,
					        "iDisplayLength": 10,
							"order": [[ 1, "desc" ]], "fnFooterCallback": function (nRow, aaData, iStart, iEnd, aiDisplay) 
{           

}


});
}

					








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