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


<!-- 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">
<!-- start: PANEL CONFIGURATION MODAL FORM -->
<div class="modal fade" id="panel-config" tabindex="-1" role="dialog" aria-hidden="true">
  <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">Panel Configuration</h4>
      </div>
      <div class="modal-body"> Here will be a configuration form </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button>
        <button type="button" class="btn btn-primary"> Save changes </button>
      </div>
    </div>
    <!-- /.modal-content --> 
  </div>
  <!-- /.modal-dialog --> 
</div>
<!-- /.modal --> 
<!-- end: SPANEL CONFIGURATION MODAL FORM -->
<div class="container"> 
  <!-- start: PAGE HEADER -->
  <div class="row">
    <div class="col-sm-12"> 
      <!-- start: PAGE TITLE & BREADCRUMB -->
      
      
    
   <?php 
   if(!$loan_id){
	$loan_title='New Loan';
	
}else {
	 if(isset($hdr_data->loan_ref))
	 {
		 $loan_title='Loan Ref : '.$hdr_data->loan_ref;}else{ $loan_title='Loan Ref : ';}
}
   ?>   
      <ol class="breadcrumb">
        <li> <a href="<?php echo base_url('dashboard'); ?>"> Dashboard </a> </li>
        <li> <a href="<?php echo base_url('loan'); ?>"> Loans </a> </li>
        <li class="active"><?php echo $loan_title ?></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>
      <br>
      
      <!-- end: PAGE TITLE & BREADCRUMB --> 
    </div>
 
  <!-- start grid -->       
             
               
                <br>
              </div>
              <!--service_tab-->
              
               <?php 
										$config = array('role' =>'form', 'class'=>'form-horizontal','id'=>'loan_item_save', 'name'=>'loan_item_save');
										echo form_open_multipart("#",$config);
										?>
                                        
                                        <input value="<?php echo $loan_id?>" name="loan_id" id="loan_id" type="hidden">
                                        
                                        
              
              <div class="tab-pane in active" id="extra_items_tab">
                <legend> Add Cheques <a href="#" data-toggle="modal" id="modal_ajax_service_btn_del" title=" Add Payment" style="text-align:right" onClick="addExtraItemToListByID(1,1,1,1,1)"> <span class="title"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></span></a></legend> 
                <div class="clearfix"></div>
                
                <!-- item add box-->
                
                <div class="well well-sm">
                  
                  <div class="clearfix"></div>
                  <div class="control-group table-group"> <br>
                    <label class="table-label">Cheque</label>
                    
                   
                   



  
                    <div class="controls table-controls">
                  
                      <table class="table items table-striped table-bordered table-condensed table-hover" id="ExtraItemTable">
                        <thead>
                          <tr>
                            <th class="text-right" style="width:30px;">#</th>
                            <th class="text-right" style="width:100px;">Paying By</th>
                         	<th class="text-right col-sm-2">Bank<span class="currency"></span> </th>
                            <th class="text-right col-sm-2">Branch</th>
                            <th class="text-right">Cheque No </th>
                            <th class="col-sm-2">Cheque/Cash Date<br/> (dd-mm-yyyy)</th>                   
                            <th class="text-right">Amount</th>
                            <th style="width: 30px !important; text-align: center;"><i class="fa fa-trash-o"></i></th>
                           	</tr>
                        </thead>
                        <tbody>
                        
                        <?php 
						$no_of_terms=5;
						
						
                                                $tmp_th_e=0;
												$extra_item_tot_amount=0;
                                             
                                     foreach ($loan_payment_list as $row){
                                      {
                                       $tmp_th_e++;							
                                                 ?>
                       	 <tr id="row_e_<?php echo $tmp_th_e;?>" class="child">
                          <td class="text-right"><?php echo $tmp_th_e;?></td>
                          <td class="text-right">
                          <?php //echo $row->pymnt_paying_by;?>
                          <select class="form-control paid_by" id="pymnt_paying_by_<?php echo $tmp_th_e;?>" name="row_e[<?php echo $tmp_th_e;?>][pymnt_paying_by][]" data-bv-field="pymnt_paying_by" tabindex="-1" title="Paying by *" onChange="changePayingbyLoan(this.value,<?php echo $tmp_th_e;?>)">
    <?php 
					$sel_cash='';
					$sel_cheque='';
					if(isset($row->pymnt_paying_by) && $row->pymnt_paying_by=='Cash'){
						$sel_cash=' selected';
					}
					if(isset($row->pymnt_paying_by) && $row->pymnt_paying_by=='Cheque'){
						$sel_cheque=' selected';
					}
					
					
				?>  
<option <?php echo $sel_cheque;?> value="Cheque">Cheque</option>                     
<option <?php echo $sel_cash;?> value="Cash">Cash</option>

</select>
                          </td>
                         <td class="text-right">
                         <?php if($row->pymnt_paying_by=='Cheque'){?>
                        <select id="bank_id_<?php echo $tmp_th_e;?>" class="form-control" name="row_e[<?php echo $tmp_th_e;?>][bank_id][]" onChange="$('#last_bank_id').val(this.value)">
                  <option value="">-- Select Bank --</option>
                  <?php 
																 
                                                              foreach ($bank_list as $row2)
                                                              {
																  $sel='';
																  $list_last_namk_id=$row->bank_id;
																  if($row->bank_id==$row2['bank_id'])
																  {
																	  $sel=' selected="selected"';
																  }
                                                              ?>
                  <option <?php echo $sel?> value="<?php echo $row2['bank_id']; ?>"> 
				  <?php echo $row2['bank_code']; ?> / <?php echo $row2['bank_name']; ?> 
                  </option>
                  <?php }?>
                </select>
                 <?php }?>
                         
                        </td>
                         <td>
                         <?php if($row->pymnt_paying_by=='Cheque'){?>
                        <input type="text" value="<?php echo $row->pymnt_branch; ?>" id="pymnt_branch_<?php echo $tmp_th_e;?>" name="row_e[<?php echo $tmp_th_e;?>][pymnt_branch][]" style="text-align:left" class="form-control">
                         <?php }?>
                        </td>
                        
                        <td>
                        <?php if($row->pymnt_paying_by=='Cheque'){?>
                        <input type="text" value="<?php echo $row->pymnt_cheque_no; ?>" id="pymnt_cheque_no_<?php echo $tmp_th_e;?>" name="row_e[<?php echo $tmp_th_e;?>][pymnt_cheque_no][]" style=" text-align:left" class="form-control">
                         <?php }?>
                        </td>
                        <td>
                       
                        <div class="input-group" style="width:100%;">
                        
										<input id="pymnt_cheque_date_<?php echo $tmp_th_e;?>" type="date" data-date-format="dd-mm-yyyy" data-date-viewmode="years" class="form-control date-picker" name="row_e[<?php echo $tmp_th_e;?>][pymnt_cheque_date][]" value="<?php if(isset($row->pymnt_cheque_date)) echo date('d-m-Y', strtotime($row->pymnt_cheque_date));?>" style="width:100%; text-align:center;">
                                        
                                        
										
									</div>
                                    
                                    
                                    
                        </td>
                       
                          <td class="text-right">
                        <input type="text" value="<?php echo $row->pymnt_amount; ?>" id="pymnt_amount_<?php echo $tmp_th_e;?>" name="row_e[<?php echo $tmp_th_e;?>][pymnt_amount][]" style="width:100%;   text-align:right; height:100%;" class="pymnt_amount">
                        
                        
                        <input name="row_e[<?php echo $tmp_th_e;?>][pymnt_returned][]" type="hidden" value="<?php if($row->pymnt_returned==1) echo 1; else 0;?>" <?php if($row->pymnt_returned==1) echo 'checked';?> title="Returned" id="pymnt_returned_<?php echo $tmp_th_e;?>">
                        
                         <input type="hidden" value="<?php if($row->pymnt_deposited==1) echo 1; else 0;?>" name="row_e[<?php echo $tmp_th_e;?>][pymnt_deposited][]" <?php if($row->pymnt_deposited==1) echo 'checked';?> title="Deposited" id="pymnt_deposited_<?php echo $tmp_th_e;?>">
                         
                         <input type="hidden" value="<?php if($row->pymnt_collected==1) echo 1; else 0;?>" name="row_e[<?php echo $tmp_th_e;?>][pymnt_collected][]" <?php if($row->pymnt_collected==1) echo 'checked';?> title="Collected" id="pymnt_collected_<?php echo $tmp_th_e;?>">
                         
                        </td>
                        <td><a onClick="deleteExtraItem(<?php echo $tmp_th_e;?>)"><i style="cursor:pointer;" title="Remove" id="1446800197032" class="fa fa-times tip podel"></i></a></td></tr>
                        <?php } }?>
                        <tfoot>
                          <tr data-item-id="144680019784" class="row_144680019784" id="row_1446800197032">
                          
                            
                            <td colspan="6" class="text-right">Total Amount</td>
                             <td class="text-right"><input readonly type="hidden" value="<?php echo $extra_item_tot_amount ?>" id="extra_item_tot_amount" name="extra_item_tot_amount" style="width:100px; text-align:right; float:right;">
                             <span id="extra_item_tot_amount_txt"></span>
                             </td>
                              <td class="text-right"></td>
                          </tr>
                          </tfoot>
                        <tr>
                          <td>                          
                          <td>                          
                        </tbody>
                        <tfoot>
                          <tr class="tfoot active" id="tfoot">
                         <th class="text-right" style="width:30px;">#</th>
                            <th class="text-right" style="width:100px;">Paying By</th>
                         	<th class="text-right col-sm-2">Bank<span class="currency"></span> </th>
                            <th class="text-right col-sm-2">Branch</th>
                            <th class="text-right">Cheque No </th>
                            <th class="col-sm-2">Cheque/Cash Date<br/> (dd-mm-yyyy)</th>                   
                            <th class="text-right">Amount</th>
                            <th style="width: 30px !important; text-align: center;"><i class="fa fa-trash-o"></i></th>
                            </tr>
                        </tfoot>
                      </table>
                      
                      <!-- start list --> 
                      <!-- end list --> 
                    </div>
                  </div>
                </div>
                <!-- end item add box-->
                
                
                <div class="form-group">
                  <div class="col-sm-12">
                  
                  <input type="submit" style="margin-right:10px;" id="loan_add_extra_items" name="loan_add_extra_items" value="Add Cheques" class="pull-right btn btn-primary">
                  
                  <!--<a class="btn btn-primary show-tab pull-right" href="#" onClick="vehicle_service_save()" style="margin-right:10px;"> Save <i class="fa fa-save"></i> </a>--> </div>
                </div>
                <!--end service details--> 
                <br>
              </div>
              <!--parts_tab-->
              
              <div class="tab-pane" id="technician_tab">
                
                
                <!--start service details--> 
                
                <!-- item add box-->
                
                <div class="well well-sm">
                  <div class=""> 
                    <!-- auto complete start -->
                    <!--<div class="input-group wide-tip">
                      <div style="padding-left: 10px; padding-right: 10px;" class="input-group-addon"> <i class="fa fa-2x fa-barcode addIcon"></i> </div>
                      <input type="text" placeholder="Please add Technician to order list" id="add_item_technician_tab" class="form-control input-lg" value="" name="add_item"  style="border-radius: 6px;font-size: 18px;height: 46px;line-height: 1.33;padding: 10px 16px;">
                      <div style="padding-left: 10px; padding-right: 10px;" class="input-group-addon"> <a href="#" data-toggle="modal" id="modal_ajax_service_btn" title=" Add Service"> <span class="title"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></span></a> </div>
                    </div>-->
                    <!-- end auto complete end --> 
                    
                  </div>
                  <div class="clearfix"></div>
                  <div class="control-group table-group"> <br>
                    
                    <div class="controls table-controls"><!-- start list --> 
                      <!-- end list --> 
                    </div>
                  </div>
                </div>
                <!-- end item add box-->
                <div class="form-group">
                  <div class="col-sm-12"> 
                    
                    
                    <!-- <a  id="technician_save"class="btn btn-primary show-tab pull-right" href="#" style="margin-right:10px;"> Save <i class="fa fa-save"></i> </a>--> </div>
                </div>
                <!--end service details--> 
                <br>
              </div>
              <!--technician_tab-->
              
             
                <!--end service details--> 
                <br>
              </div>
              <!--summary_tab--> 
              
            </div>
        
          </div>
        </div>
      </div>
      <!-- end: INLINE TABS PANEL -->
      
      <input name="sale_inv_discount_amount" type="hidden" id="sale_inv_discount_amount" value="0">
      <input name="sale_total" type="hidden" id="sale_total" value="0">
      <input name="sale_paid" type="hidden" id="sale_paid" value="0">
      <input name="sale_balance" type="hidden" id="sale_balance" value="0">
    
      <input name="rowCount" type="hidden" id="rowCount" value="<?php if(isset($tmp_id)){echo $tmp_id;} ?>">
     
      <input name="rowCount_e" type="hidden" id="rowCount_e" value="<?php echo $tmp_th_e; ?>">
    
       <input name="rowCount_sr" type="hidden" id="rowCount_sr" value="<?php if(isset($tmp_sr_id)){ echo $tmp_sr_id;} ?>">
       <input name="loan_payable_total_amount" type="hidden" id="loan_payable_total_amount" value="0">
       
       <input name="tmpVal" type="hidden" id="tmpVal" value="">
       <input name="last_bank_id" type="hidden" id="last_bank_id" value="<?php if(isset($list_last_namk_id)) echo $list_last_namk_id;?>">
       
       <input name="last_pymnt_cheque_date" type="hidden" id="last_pymnt_cheque_date" value="<?php if(isset($hdr_data->loan_date)) echo $hdr_data->loan_date;?>">
       
       
      </form>
      <!-- end tab --> 
      
    </div>
    <!-- end grid --> 
    <?php if(isset($hdr_data->loan_id)){?>
    <!-- footer amount details -->
   <!--<div style="margin-bottom: 0px; position: fixed; bottom: 0px; width: 1082px; z-index: 50000;" class=" well-sm well" id="bottom-total">
      <table style="margin-bottom:0;" class="table table-bordered table-condensed totals">
        <tbody>
          <tr class="warning">
           <td>Menu Amount <span id="bkng_menu_amount_ftr" class="totals_val pull-right">
		   <?php if(isset($hdr_data->bkng_menu_amount)) echo number_format($hdr_data->bkng_menu_amount, 2, '.', ',') ?></span></td>
            <td>Extra Menu Items <span id="bkng_extra_menu_item_amount_ftr" class="totals_val pull-right"><?php echo number_format(($service_sub_tot), 2, '.', ',') ?></span></td>
            <td>Extra Items <span id="bkng_extra_item_amount_ftr" class="totals_val pull-right"><?php echo number_format(($parts_sub_tot), 2, '.', ',') ?></span></td>
           
           
            <td id="discount_td">Discount <span id="dscount_sub_tot_footer_dis" class="totals_val pull-right">0.00</span></td>
              <td id="discount_per_head_td">Discount Per Head<span id="dscount_per_head_sub_tot_footer_dis" class="totals_val pull-right">0.00</span></td>
         
            <td>Grand Total <span id="bkng_tot_amount_ftr" class="totals_val pull-right"><?php echo number_format(($grand_total_sub_tot), 2, '.', ',') ?></span></td>
          </tr>
        </tbody>
      </table>
    </div>-->
    <!-- end footer amount details --> 
    <?php }?>

  </div>
  <!-- end: PAGE --> 
</div>
<!-- end: MAIN CONTAINER --> 
<!-- start: FOOTER -->
<div class="footer clearfix">
  <div class="footer-inner"> <?php echo date("Y");?> &copy; Financial Management System by sallelanka solutions. </div>
  <div class="footer-items"> <span class="go-top"><i class="clip-chevron-up"></i></span> </div>
</div>
<!-- end: FOOTER --> 
<!-- start: RIGHT SIDEBAR -->
<div id="page-sidebar"> <a class="sidebar-toggler sb-toggle" href="#"><i class="fa fa-indent"></i></a>
  <div class="sidebar-wrapper">
    <ul class="nav nav-tabs nav-justified" id="sidebar-tab">
      <li class="active"> <a href="#users" role="tab" data-toggle="tab"><i class="fa fa-users"></i></a> </li>
      <li> <a href="#favorites" role="tab" data-toggle="tab"><i class="fa fa-heart"></i></a> </li>
      <li> <a href="#settings" role="tab" data-toggle="tab"><i class="fa fa-gear"></i></a> </li>
    </ul>
  </div>
</div>

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


		
 
                                    
		<!-- end: RIGHT SIDEBAR -->
		<!-- 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 -->
        <script src="<?php echo asset_url(); ?>js/form-validation-loan_add.js"></script> 
<script src="<?php echo asset_url(); ?>js/loan_add.js"></script> 
<script src="<?php echo asset_url(); ?>js/loan_extra_itm_add.js"></script> 


		<script src="<?php echo asset_url(); ?>/plugins/jquery-inputlimiter/jquery.inputlimiter.1.3.1.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/autosize/jquery.autosize.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/select2/select2.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/jquery.maskedinput/src/jquery.maskedinput.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/jquery-maskmoney/jquery.maskMoney.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-timepicker/js/bootstrap-timepicker.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-daterangepicker/moment.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-colorpicker/js/commits.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/jQuery-Tags-Input/jquery.tagsinput.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-fileupload/bootstrap-fileupload.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/summernote/build/summernote.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/ckeditor/ckeditor.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/ckeditor/adapters/jquery.js"></script>
		<script src="<?php echo asset_url(); ?>/js/form-elements.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>
		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
		<script>
			jQuery(document).ready(function() {
				//Main.init();
				FormElements.init();
				//$('#loan_date').val('29-07-2016')
				
				//loan_date
				<?php //if(isset($hdr_data->loan_date)){?>
					/*$('#loan_date').val('<?php //$hdr_data->loan_date;?>;*/
				<?php //} ?>
				
				calculate_payble_abount();
				calculateExtraItemTotal();
		
			});
			
			
			
			
			
			
			
function load_interest_rate(id)
{	
 var x = document.getElementById("loan_interest");
x.remove(x.selectedIndex);  
   
	$.post("<?php echo  base_url(); ?>loan/get_all_interest_by_payment_term_id?R="+id, function(data) {

var sel = $("#loan_interest");
   
sel.empty();
$("#loan_interest").append('<option value="" selected> - select interest -</option>');
$.each(data, function(i, item){
$("#loan_interest").append('<option value="' + i + '">'+ item + '</option>');
})
},"json");
	
	
}
			
			
			
//save invoice header
$( "#loan_inv_hdr" ).click(function() {
	 $("#loan_inv_hdr").prop("disabled", true);
		 $("#loan_inv_hdr").val('Please wait..');
		 
   var fields = $("#loan_item_save").serialize();
   
   $.post( "<?php echo base_url();?>loan/loan_header_save", fields)
	  .done(function( data ) {
		 var obj = jQuery.parseJSON(data);
		 
			if(obj.error==0){
				//sendUrl='<?php //echo base_url();?>loan/manage/'+obj.loan_id;
				//window.location.href = sendUrl;
				alert("Recode successfully saved");
				location.reload();
			}
			if(obj.error==1){
				$("#loan_inv_hdr").prop("disabled", false);
		 		$("#loan_inv_hdr").val('Next');
				 bootbox.alert(obj.msg, function () {                        
                    });
					$("#loan_inv_hdr").prop("disabled", false);
		 			$("#loan_inv_hdr").val('Next');
					//$table_name				
			}
	 });
});
			
			
			
			
		function load_customer_old_recod(cus_id)
		{
		  $('#products_table').DataTable({
					        "ajax": "<?php echo base_url('loan/get_list_loan_by_customer?cus_id=')?>"+cus_id,
					        "bDestroy": true,
					        "iDisplayLength": 50,
							"order": [[ 0, "desc" ]]
					    });	
			
		}
			
			
			
			
			
			
			
			
			
			
			
			
			<!-------------------------------------------------------------------->
			
function changePayingbyLoan(val,row_id){
	//alert(val);
	var bank_id_fld='#bank_id_'+row_id;
	var pymnt_branch_fld='#pymnt_branch_'+row_id;
	var pymnt_cheque_no_fld='#pymnt_cheque_no_'+row_id;
	
	var pymnt_collected_fld='#pymnt_collected_'+row_id;
	var pymnt_deposited_fld='#pymnt_deposited_'+row_id;
	var pymnt_cheque_no_fld='#pymnt_cheque_no_'+row_id;
	
	if(val=='Cheque'){
		$(bank_id_fld).show();
		$(pymnt_branch_fld).show();
		$(pymnt_cheque_no_fld).show();
		//$(pymnt_collected_fld).hide();
		
	}else {
		$(bank_id_fld).hide();
		$(pymnt_branch_fld).hide();
		$(pymnt_cheque_no_fld).hide();
		
		//$(pymnt_deposited_fld).hide();
		//$(pymnt_returned_fld).hide();
	}
	
}

$( "#menu_item_save" ).click(function() {
	//alert();
	 var fields = $("#loan_item_save").serialize();
	 $.post( "<?php echo base_url();?>loan/loan_menu_item_save", fields)
	.done(function( data ) {
		  //alert();
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
				$('.alert-success').hide();
				$('.alert-danger').show();
				$( ".errortxt" ).text( obj.disMsg );
			}
			if(obj.error==0){
				displayNotice('page','Menu items successfully added!');
				
				 $("#vcl_sr_itm_save").prop("disabled", false);
		 		 $("#vcl_sr_itm_save").val('Add Service');
				 calculateLoanGrandTotal();
				 
				//clearForm();
			}
	  });
	return false;
	
});

//Save Extra Items
$( "#loan_add_extra_items" ).click(function() {
	//alert();
	 var fields = $("#loan_item_save").serialize();
	 
	// alert(fields);
	 $.post( "<?php echo base_url();?>loan/loan_extra_item_save", fields)
	.done(function( data ) {
		  //alert();
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
				//$('.alert-success').hide();
				//$('.alert-danger').show();
			//	$( ".errortxt" ).text( obj.disMsg );
				bootbox.alert(obj.disMsg, function () {
                        
                    });
			}
			if(obj.error==0){
				 displayNotice('page','Cheques successfully added!');
				 $("#loan_add_extra_items").prop("disabled", false);
		 		 $("#loan_add_extra_items").val('Add Cheques');
				//clearForm();
				//calculateLoanGrandTotal();
				
			}
	  });
	return false;
	
});



		//service tab text field start
		
        $("#add_item_service_tab").autocomplete({
            source: '<?php echo base_url();?>loan/menu_item_suggestions?w='+$("#warehouse_id").val(),
            minLength: 1,
            autoFocus: false,
            delay: 5,
            response: function (event, ui) {
				
			
				if (ui.content.length == 1 && ui.content[0].product_id != 0)
				{
					//ui.item = ui.content[0];
 					//$(this).data('ui-autocomplete')._trigger('select', 'autocompleteselect', ui);
					//$(this).autocomplete('close');
                   // $(this).removeClass('ui-autocomplete-loading');
				}else if(ui.content.length ==0){
					var noResult = { value:"",label:"No matching result found! Service might be out of stock in the selected warehouse." };
            		ui.content.push(noResult);
				}else {

				}
			
            },
            select: function (event, data) {
				//alert( "You selected: " + data.item.product_id );
				if(data.item.value){
					
					//check is added prodcut
					rowCount=parseInt($('#rowCount_sr').val());
					
					var tmp='';
					if(rowCount){
	  					tmp=isAddedProduct(data.item.item_id);
					}
	   				if(!tmp){
						addServiceToListByID(data.item.item_id,data.item.item_code,data.item.item_name,data.item.item_price);
					}else {
						calculateTotal();
						displayNotice('page','Already added menu item');
					}
				
				
				$("#add_item_service_tab").val('');
					 return false;
				}
				$(this).autocomplete('close');
                    $(this).removeClass('ui-autocomplete-loading');
				
            }
        });
		//service tab text field end
		
		
		//extra item start
        $("#add_extra_item_tab").autocomplete({
            source: '<?php echo base_url();?>loan/menu_extra_item_suggestions?w='+$("#warehouse_id").val(),
            minLength: 1,
            autoFocus: false,
            delay: 5,
            response: function (event, ui) {
				
			
				if (ui.content.length == 1 && ui.content[0].product_id != 0)
				{
					//ui.item = ui.content[0];
 					//$(this).data('ui-autocomplete')._trigger('select', 'autocompleteselect', ui);
					//$(this).autocomplete('close');
                    //$(this).removeClass('ui-autocomplete-loading');
				}else if(ui.content.length ==0){
					var noResult = { value:"",label:"No matching result found! Service might be out of stock in the selected warehouse." };
            		ui.content.push(noResult);
				}else {

				}
			
            },
            select: function (event, data) {
				//alert( "You selected: " + data.item.product_id );
				if(data.item.value){
					
					//check is added prodcut
					rowCount=parseInt($('#rowCount_e').val());
					
					var tmp='';
					if(rowCount){
	  					tmp=isExtraAddedProduct(data.item.item_id);
					}
	   				if(!tmp){
						addExtraItemToListByID(data.item.item_id,data.item.item_code,data.item.item_name,data.item.item_price,data.item.unit_code);
					}else {
						calculateTotal();
						displayNotice('page','Already added menu item');
					}
				
				
				$("#add_extra_item_tab").val('');
					 return false;
				}
				$(this).autocomplete('close');
                    $(this).removeClass('ui-autocomplete-loading');
				
            }
        });
		//end extra item

		
		
$( "#loan_complete" ).click(function() {
	//alert();
	
   var fields = $("#loan_item_save").serialize();
   var loan_id=$("#loan_id").val();
   
   
   
      $.post( "<?php echo base_url();?>loan/loan_complete", fields)
	  .done(function( data ) {
		 var obj = jQuery.parseJSON(data);
		 
			if(obj.error==0){
				var sendUrl='<?php echo base_url();?>loan/details/'+loan_id;
				//var sendUrl='<?php echo base_url();?>loan/manage/'+loan_id;
				
				window.location.href = sendUrl;
				return false;
			}
			if(obj.error==1){
				return false;			
			}
	 });
	 
  	
 	// alert(loan_id);

return false;	
});

$( "#loan_inv_hdr_update" ).click(function() {
				
	 var fields = $("#loan_item_save").serialize();
	 $.post( "<?php echo base_url();?>loan/loan_header_save", fields)
	.done(function( data ) {
		  //alert();
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
				$('.alert-success').hide();
				$('.alert-danger').show();
				//$( ".errortxt" ).text( obj.disMsg );
				bootbox.alert(obj.msg, function () {
                        
                    });
			}
			if(obj.error==0){
				displayNotice('page','Loan details successfully updated!');
				
				sendUrl='<?php echo base_url();?>loan/manage/'+obj.loan_id;
				window.location.href = sendUrl;
				
				 $("#vcl_sr_itm_save").prop("disabled", false);
		 		 $("#vcl_sr_itm_save").val('Add Service');
				//clearForm();
			}
			
	  });
	return false;
	
});



function addExtraItemToListByID(item_id,item_code,item_name,item_price,unit_code){
	$('#rowCount_e').val(parseInt($('#rowCount_e').val())+1);
	
	//start get data
	$.ajax({
					    url : "<?php echo base_url();?>loan/get_cheque_details_row",
					    type: "POST",
					    data : {rowCount_e:$('#rowCount_e').val()
							/*loan_payment_term:$('#loan_payment_term').val(),
							last_bank_id:$('#last_bank_id').val(),
							
							last_pymnt_cheque_date:$('#last_pymnt_cheque_date').val()*/
							},
					    success: function(data)
					    {
							console.log(data);
	                            var obj = jQuery.parseJSON(data);
	                            if (obj.status==1) 
	                                {
										
										//alert(obj.bkng_refno);
	                                 	//bkng_refno=obj.bkng_refno;
										//bkng_id=obj.bkng_id;
										var row_details=obj.row_details;
										$('#ExtraItemTable tr:last').before(row_details);
										var datefld='#pymnt_cheque_date_'+(parseInt($('#rowCount_e').val()))
										console.log(datefld);
										
										$( datefld ).datepicker(
										{
											defaultDate: new Date(),
											autoclose: true,
   											closeOnDateSelect: true,
											
   										}									
										);										
										//alert(row_details);
										return false;									
                
	                                } 
	                                
					    }
	    			});
}
		</script>
	</body>
	<!-- end: BODY -->
</html>