	<?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(); ?>css/table_response_css.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">

		<style type="text/css">
			.table > thead:first-child > tr:first-child > th, .table > thead:first-child > tr:first-child > td, .table-striped thead tr.primary:nth-child(2n+1) th {
			    background-color: #428bca;
			    border-color: #357ebd;
			    border-top: 1px solid #357ebd;
			    color: white;
			    text-align: center;
			}

		</style>
		<!-- 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('dashboard'); ?>">
										  Cash Collection
									</a>
								</li>
                               
								<li class="active">
									Cash Collection  (Admin)
								</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">
								<h4>Cash Collection</h4>
							</div>

                            <p>Please use the table below to navigate or filter the results. </p>
						</div>
					</div>
					<!-- end: PAGE HEADER -->
					<!-- start: PAGE CONTENT 
                    <!-- start grid -->
                    <div class="row">
                    
						
                        <div class="col-md-12">
                        
                         <div class="col-sm-4">
                          <div class="form-group">
							<label>From Date  </label>                               
                             <input id="srh_from_date" name="srh_from_date" type='text' class="form-control date-picker" value="" data-bv-field="date"/>
                                                                                                       
							</div>
							</div>
                        
                        </div>
                        
                        <div class="col-md-12">
                        
							<!-- start: DYNAMIC TABLE PANEL -->
							<div class="panel panel-default">
								<div class="panel-heading">
                                
									<i class="fa fa-external-link-square"></i>
									Cash Collection
                                    <div class="panel-tools" style="top:2px;">
												  <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>
								</div>
								</div>
							  <div class="panel-body">
							    <div id="error"></div>
								  <table class="table table-bordered table-condensed table-hover table-striped dataTable" id="warehouse_table" align="center">
									  <thead>
							            <tr>
                                    <th style="text-align:center; width:40px; vertical-align:middle;">Date</th>
                                    <th style="text-align:center;  vertical-align:middle;">Customer Name</th>
                                    <th style="text-align:center;  vertical-align:middle;">Invoice No</th>
                                    <th style="text-align:center;  vertical-align:middle;">To Be Paid</th>
                                     <th style="text-align:center;  vertical-align:middle;">Rental amount</th>	
                                    <th style="text-align:center;  vertical-align:middle;">Outstanding</th>	
                                   	
                                    <th style="text-align:center;  vertical-align:middle;">Payment Amount</th>							
                                    <th>Action</th>
                                    </tr>
							          </thead>
							          <tfoot>
											  <tr>
                                    <th>Date</th>
                                    <th style="text-align:center;  vertical-align:middle;">Customer Name</th>
                                    <th style="text-align:center; width:40px; vertical-align:middle;">Invoice No</th>
                                   	<th style="text-align:center; width:40px; vertical-align:middle;" >To Be Paid</th>
                                     <th style="text-align:center; width:40px;  vertical-align:middle;">Rental amount</th>	
                                     <th style="text-align:center; width:40px; vertical-align:middle;">Outstanding</th>
                                    
                                     <th style="text-align:center; width:40px;  vertical-align:middle;">Payment Amount</th>	
									<th style="text-align:center;">Action</th>
                                    </tr>
								           
						          </table>
								</div>
							</div>
							<!-- 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>

		<!-- 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 -->
		<script type="text/javascript" src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
		<script type="text/javascript" src="https://cdn.datatables.net/1.10.10/js/dataTables.bootstrap.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>
          <script type="text/javascript" src="<?php echo asset_url(); ?>js/jquery.dataTables.min.js"></script>
          <script type="text/javascript" src="<?php echo asset_url(); ?>js/dataTables.bootstrap.min.js"></script>
          <script type="text/javascript" src="<?php echo asset_url(); ?>js/bootbox.min.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>
		
		
		
		
		function add_recevble_invoice()
		{
			jQuery(document).ready(function() {
				
				loadGrid();
			});


			function loadGrid() {

					    $('#warehouse_table').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) 
{ 


				var to_be_total_amount=0;
				var outstanding_amount=0;
				var renatal_total_amount=0;
				
				//var sales_rtn=0;
                for (var i = 0; i < aaData.length; i++) {
					//alert(aaData[[i]][5]);
                   // p = (aaData[aiDisplay[i]][2]).split('__');
				   
				  // 	var number = Number(aaData[[i]][4].replace(/[^0-9\.]+/g,""));
					
					
					var floatedValue1 = parseFloat(aaData[[i]][3].replace(/[^\d\.]/, ''));
					var floatedValue2 = parseFloat(aaData[[i]][5].replace(/[^\d\.]/, ''));
					var floatedValue3 = parseFloat(aaData[[i]][4].replace(/[^\d\.]/, ''));
					
					if(isNaN (floatedValue3))
					{
					}
					else
					{
						renatal_total_amount += parseFloat(floatedValue3);					
					}
					
					
					
					
					
					
					if(isNaN (floatedValue2))
					{
					}
					else
					{
						outstanding_amount += parseFloat(floatedValue2);					
					}
					
					
					if(isNaN (floatedValue1))
					{
					}
					else
					{
						to_be_total_amount += parseFloat(floatedValue1);				
					}
					
					
					
					
					
					
					
					
					
					
					
					
						
                }
                var nCells = nRow.getElementsByTagName('th');
				
				
				
				nCells[3].innerHTML = '<div class="text-right">'+accounting.formatMoney(to_be_total_amount, "", 2, ",", ".")+' </div>';
				nCells[5].innerHTML = '<div class="text-right">'+accounting.formatMoney(outstanding_amount, "", 2, ",", ".")+' </div>';
				nCells[4].innerHTML = '<div class="text-right">'+accounting.formatMoney(renatal_total_amount, "", 2, ",", ".")+' </div>';
				
				/*var sales_rtn_tot_cost=ser_tot1;
				var sales_rtn_tot_val=ser_tot2;
				$('#sales-rtn-cost-fld').val(accounting.formatMoney(sales_rtn_tot_cost, "", 2, ",", "."));
				$('#sales-rtn-val-fld').val(accounting.formatMoney(sales_rtn_tot_val, "", 2, ",", "."));
				$('#sales-rtn-cost-tbl').text(accounting.formatMoney(sales_rtn_tot_cost, "", 2, ",", "."));
				$('#sales-rtn-val-tbl').text(accounting.formatMoney(sales_rtn_tot_val, "", 2, ",", "."));*/
				
				
				
				

          

}


});
}


		}



var table = $('#warehouse_table').DataTable();
 
$('#warehouse_table tbody').on( 'click', 'tr', function () {
    
} );







function cash_collect(id)

{
	
	var sale_id=id;
	var amount=(document.getElementById("p_"+id).value);
	var outstanding=(document.getElementById("os_"+id).value);
	var sale_type="sale";
	var srh_from_date=$('#srh_from_date').val();
	
	var floatedValue1 = parseFloat(outstanding.replace(/[^\d\.]/, ''));
	
	
	if($.isNumeric(amount)){
		
		if(amount>0){
	
	
		if(outstanding==amount)	
		{
			add_payment(id,amount);
		}
		else
		{
		    bootbox.confirm({
        message: "Customer outstanding is Rs. "+outstanding+" . But you are trying to add Rs. "+amount+" . Please confirm to Proceed !",
        buttons: {
            confirm: {
                label: 'Yes',
                className: 'btn-success'
            },
            cancel: {
                label: 'No',
                className: 'btn-danger'
            }
        },
        callback: function (result) {
          
		   if(result==true)
		   {
			 add_payment(id,amount,srh_from_date);
			   
		   }
		   else
		   {
			 displayNotice('page','Payment Canceled');  
		   }
        }
    });
		}
	
	  
		}
		else
		
		{
			displayNotice('page','Amount Not Acceptable');
		}
	  
	  
	  
	  }else{
		displayNotice('page','Invalid Amount');
	}
	
	
	return false;
	
	
	
	
	
}


function add_payment(id,amount,srh_from_date)
{
	
var fields='';
	$.post( '<?php echo base_url() ?>cash_collect/add_sale_payments?sale_id='+id+'&sale_type=sale&amount='+amount+'&srh_from_date='+srh_from_date, fields)
	.done(function( data ) {
		  //alert();
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
			
			}
			if(obj.error==0){
				displayNotice('page','Payment Added!');
				document.getElementById("p_"+id).value="0.00";
			}
			
	  });	
	
		add_recevble_invoice();
				// window.location.reload();
	
}

$('#srh_from_date').datetimepicker({
					defaultDate: new Date()
				});


		</script>

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