<?php
$user = auth()->user();
?>
<script src="assets/js/king-table.js"></script>
<div class="content">
	<div class="main-content">
		<!-- DATA EXPORT -->
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> <?php echo e(__('mylanguage.jamath_list')); ?> - <?php echo e($data['rectype']); ?></h3>
<div class='btn-toolbar pull-right'>
    <div class='btn-group'>
		<button type='button' class='btn btn-warning' id="idreload1" onclick="loadjamathrecords('All')" title="Matrimonial Certificate" ><i class="fa fa-american-sign-language-interpreting" aria-hidden="true"></i>All Accounts</button>
		<button type='button' class='btn btn-danger' id="idreload2" onclick="loadjamathrecords('Pending')" title="Matrimonial Certificate" ><i class="fa fa-thumbs-down" aria-hidden="true"></i>Pending Accounts</button>
		<button type='button' class='btn btn-success' id="idreload3" onclick="loadjamathrecords('Paid')" title="Matrimonial Certificate" ><i class="fa fa-thumbs-up" aria-hidden="true"></i>Paid Accounts</button>
    </div>
</div>
			</div>
			<div class="widget-content">			
<table id="mydatatable" class="table table-sorting table-striped table-hover table-bordered datatable">
	<thead>
		<tr>
			<th><?php echo e(__('mylanguage.slno')); ?></th>
			<th><?php echo e(__('mylanguage.grade')); ?></th>
			<th><?php echo e(__('mylanguage.member_id')); ?></th>
			<th><?php echo e(__('mylanguage.name')); ?></th>
			<?php /* <th>{{ __('mylanguage.dob') }}</th> */ ?>
			<th><?php echo e(__('mylanguage.Mobno')); ?></th>
			<th style="text-align: right;"><?php echo e(__('mylanguage.Total_amount')); ?></th>		
			<th style="text-align: right;"><?php echo e(__('mylanguage.Paid_amount')); ?></th>	
			<th style="text-align: right;"><?php echo e(__('mylanguage.balance_amount')); ?></th>		
			<th><?php echo e(__('mylanguage.action')); ?></th>					
		</tr>
	</thead>
	<tbody>
		<?php  $i=1;
		$totalamt=0;
		$paidamt=0;
		?>
		<?php $__currentLoopData = $data['LoadJamathRecords']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $LoadJamathRec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
		<?php
		$resaddr = unserialize($LoadJamathRec->cst_resaddress);
		$permaddr = unserialize($LoadJamathRec->cst_permaddress);
		?>
		<tr>
			<td> <?php echo $i; ?></td>
			<td><?php echo e($LoadJamathRec->grd_grade); ?></a></td>
			<td><?php echo e($LoadJamathRec->grd_prefix); ?><?php echo e($LoadJamathRec->cst_code); ?></a></td>
			<td><?php echo e($LoadJamathRec->cst_name); ?> </td>
			<?php /* <td>{{date("d-m-Y",strtotime($LoadJamathRec->cst_dob))}}</td> */ ?>
			<td><?php echo e($resaddr[4]); ?></td>			
			<td style="text-align: right;" id="tot_<?php echo e($LoadJamathRec->cst_id); ?>"><?php echo e($LoadJamathRec->totalamt); ?></td>			
			<td style="text-align: right;" id="paid_<?php echo e($LoadJamathRec->cst_id); ?>"><?php echo e($LoadJamathRec->paidamt + $LoadJamathRec->advamt + $LoadJamathRec->prepayamt); ?></td>			
			<td style="text-align: right;" id="bal_<?php echo e($LoadJamathRec->cst_id); ?>"><?php echo e(($LoadJamathRec->totalamt) - ($LoadJamathRec->paidamt  + $LoadJamathRec->advamt + $LoadJamathRec->prepayamt)); ?></td>
			<th>		
				<button class="btn btn-default btn-xs"  data-toggle="modal"  id="<?php echo e($LoadJamathRec->cst_id); ?>" data-target="#myotheramt"  title="Add Funds"><i class="fa fa-paper-plane" aria-hidden="true"></i></button>			 
				<button class="btn btn-default btn-xs"  data-toggle="modal"  id="<?php echo e($LoadJamathRec->cst_id); ?>" data-target="#mypayment"  title="Make payment"><i class="fa fa-paypal" aria-hidden="true"></i></button>		 
				<button class="btn btn-default btn-xs"  onclick="EditJamathMembers(<?php echo e($LoadJamathRec->cst_id); ?>)" title="View" ><i class="fa fa-eye" aria-hidden="true"></i></button>
			</th>		
		</tr>
		<?php
		$totalamt = $totalamt + $LoadJamathRec->totalamt;
		$paidamt = $paidamt + $LoadJamathRec->paidamt;
		$i= $i+1;
		?>
		<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>	
	</tbody>
	<tfoot>
		<tr>
			<th></th>
			<th></th>
			<th></th>
			<th></th>
			<th>Total</th>
			<th style="text-align: right;" id="tbltotalamt"><?php echo $totalamt; ?></th>		
			<th style="text-align: right;" id="tblpaidamt"><?php echo $paidamt; ?></th>	
			<th style="text-align: right;" id="tblbalamt"><?php echo $totalamt - $paidamt; ?></th>		
			<th></th>					
		</tr>
	</tfoot>
</table>
			</div>			
				<div class="widget">
					<div class="widget-header">
<button class="btn btn-info btn-default" onclick="printjamathreport('<?php echo e($data['rectype']); ?>')" ><span class="fa fa-print"></span> PRINT</button>
					</div>
				</div>
			
		</div>
		<!-- END DATA EXPORT -->
	</div>
</div>
<!-- /main -->

<!-- The Modal Other amount starts here-->
	<div class="modal" id="myotheramt">
    <div class="modal-dialog">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Add Charges</h4>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
			<form id="frmothercharges" name="frmothercharges" method="post" data-parsley-validate novalidate>
				<input type="hidden" name="_token1" id="_token1" value="<?php echo e(csrf_token()); ?>">
				<input type="hidden" name="fund_cust_id" id="fund_cust_id" value="0">
				<input type="hidden" class="form-control" id="grfn_id" name="grfn_id" value="0" >
				<input type="hidden" class="form-control" id="fyr_id" name="fyr_id" value="<?php echo e($data['fiscalyear'][0]->fyr_id); ?>" >
				<input type="hidden" class="form-control" id="grfn_status" name="grfn_status" value="Deleted" >
				<input type="hidden" id="grd_id" name="grd_id" value="0">
				<input type="hidden" id="edit_grd_id" name="edit_grd_id" value="0">
<?php echo csrf_field(); ?>           
<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li><?php echo e(__('grade.enter_details')); ?>...</ul>
</div>						
<div class="alert alert-success print-success-msg" style="display:none">
    <ul></ul>
</div>	
<div class="alert alert-danger print-error-msg" style="display:none">
    <ul></ul>
</div>

<div class="row">		
	<div class="form-group col-md-6">
		<label for="text-input1"><?php echo e(__('mylanguage.name')); ?></label>
		<input type="text" name="cstname" id="cstname" class="form-control" readonly>
	</div>
	<div class="form-group col-md-6">
		<label for="text-input1"><?php echo e(__('mylanguage.member_id')); ?></label>
		<input type="text" name="memid" id="memid" class="form-control" readonly>
	</div>
</div>

<div class="row">
	<div class="form-group col-md-6">
		<label for="text-input1"><?php echo e(__('grade.fund_type')); ?>*</label>
		<input type="hidden" id="edit_ftyp_id" name="edit_ftyp_id" value="0">
		<select name="ftyp_id" id="ftyp_id" class="form-control" required>
			<option value=""> -- <?php echo e(__('grade.fund_type')); ?> -- </option>
		</select>
		<small class="text-danger" id="errftyp_id"></small>
	</div>
				
	<div class="form-group col-md-6">
		<label for="text-input1"><?php echo e(__('grade.billing_cycle')); ?>*</label>
		<select name="grfn_paycycle" id="grfn_paycycle" class="form-control" required>
			<option value="">-- <?php echo e(__('grade.billing_cycle')); ?> --</option>
			<option value="Daily"><?php echo e(__('grade.Daily')); ?></option>
			<option value="Weekly"><?php echo e(__('grade.Weekly')); ?></option>
			<option value="Monthly"><?php echo e(__('grade.Monthly')); ?></option>
			<option value="Quarterly"><?php echo e(__('grade.Quarterly')); ?></option>
			<option value="Semiannually"><?php echo e(__('grade.Semiannually')); ?></option>
			<option value="Yearly"><?php echo e(__('grade.Yearly')); ?></option>
			<option value="One time"><?php echo e(__('grade.Onetime')); ?></option>
		</select>
		<small class="text-danger" id="errgrfn_paycycle"></small>
	</div>
</div>
<?php /* Start date disabled for timebeing */ ?>
<input type="hidden" name="date_from" id="date_from" class="form-control" value="<?php echo date("Y-m-d"); ?>" >

<div class="row">
	<div class="form-group col-md-6">
		<label for="text-input1"><?php echo e(__('grade.amount')); ?>*</label>
		<input type="text" name="grfn_amt" id="grfn_amt" class="form-control" >
		<small class="text-danger" id="errgrfn_amt"></small>
	</div>
	<div class="form-group col-md-6">
		<label for="text-input1"><?php echo e(__('grade.description')); ?></label>
		<input type="text" name="grfn_description" id="grfn_description" class="form-control" >
		<small class="text-danger" id="errgrfn_description"></small>
	</div>

</div>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
		  <button type="button" class="btn btn-primary submitgradefund">Submit</button>
        </div>
	</form>
      </div>
    </div>
  </div>
<!-- The Modal Other amount ends here -->
<style>
.modal-dialog.modal-100 {
    width: 90%;
    /*margin: 30px auto;*/
}
</style>
<!-- ###### The Modal payment amount starts here ###### -->
<div class="modal" id="mypayment">
    <div class="modal-dialog paymentmodal modal-100">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Make Payment</h4>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
			<form id="frmpayment" name="frmpayment" data-parsley-validate novalidate>
					<input type="hidden" name="_token2" id="_token2" value="<?php echo e(csrf_token()); ?>">
				<input type="hidden" name="pay_cust_id" id="pay_cust_id" value="0">
<?php
/*
<div class="alert alert-paymentinfo" >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li>{{ __('grade.enter_details') }}...</ul>
</div>						
<div class="alert alert-success print-success-msg" style="display:none">
    <ul></ul>
</div>	
<div class="alert alert-danger print-error-msg" style="display:none">
    <ul></ul>
</div>
*/
?>
				<div class="row">		
					<div class="form-group col-md-3">
						<label for="text-input1"><?php echo e(__('mylanguage.name')); ?></label>
						<input type="text" name="paycstname" id="paycstname" class="form-control" readonly>

						<label for="text-input1"><?php echo e(__('mylanguage.member_id')); ?></label>
						<input type="text" name="paymemid" id="paymemid" class="form-control" readonly>

						<label for="text-input1"><?php echo e(__('mylanguage.Total_amount')); ?></label>
						<input type="text" name="payTotal_amount" id="payTotal_amount" class="form-control" readonly>

						<label for="text-input1"><?php echo e(__('mylanguage.Paid_amount')); ?></label>
						<input type="text" name="payPaid_amount" id="payPaid_amount" class="form-control" readonly>
	
						<label for="text-input1"><?php echo e(__('mylanguage.balance_amount')); ?></label>
						<input type="text" name="paybalance_amount" id="paybalance_amount" class="form-control" readonly>
						
						<label for="text-input1"><?php echo e(__('mylanguage.amt_payable')); ?></label><small class="text-danger" id="erramt_payable"></small>
						<input type="text" name="amt_payable" id="amt_payable" class="form-control" placeholder="0" onkeyup="paymentcalculation()" >
					</div>
					<div class="col-md-9" id="idpaymentlist"></div>
				</div>
			</form>
        </div>
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> 
		  <button type="button" class="btn btn-primary submitpayment">Make Payment</button>
        </div>        
      </div>
    </div>
</div>
<!-- ###### The Modal payment amount ends here ###### -->
<!-- ###### The Modal Payment Receipt starts here ###### -->
<div class="modal" id="modprintpaymentreceipt">
		<div class="modal-dialog paymentmodal">
		  <div class="modal-content">
			<!-- Modal Header -->
			<div class="modal-header">
			  <h4 class="modal-title">Payment Receipt...</h4>
			</div>
			
			<!-- Modal body -->
			<div class="modal-body" id="divbillprint">
				<!-- PRINT RECEIPT START HERE -->
<div class="widget widget-table">
	<div class="widget-content">
	
		<div class="row">
			<div class="col-md-12">
				<center>
					<center><img src="img/printlogo.png" style="width: 100%;"></center>
				</center>
				<hr>
				<center><b><?php echo e(__('mylanguage.pay_receipt')); ?></b></center>
				<hr>
			</div>
			
			<div class="col-md-6">
				<b><?php echo e(__('mylanguage.member_id')); ?> <label id="receiptmember_id" ></label></b><br>
				<b><?php echo e(__('mylanguage.name')); ?> <label id="receiptname"></label></b>
			</div>
			<div class="col-md-6 text-right">
				<b><?php echo e(__('mylanguage.billno')); ?> <label id="receiptbillno"></label></b><br>
				<b><?php echo e(__('mylanguage.date')); ?> <label id="receiptdate" >00-00-0000</label></b>
			</div>

			<div class="col-md-12"><hr></div>

			<div class="col-md-12" id="receipttable"></div>
			
<input type="hidden" name="transaction_id" id="transaction_id" value="">

			<div class="col-md-6"><h1 style="border:1px solid #cecece;">Rs. <label id="receiptamt1">000</label>/-</h2>Subject to realisation</div>
			<div class="col-md-6 text-right">For <b><?php echo e(__('mylanguage.mosquename')); ?></b> <br><br><br><br>Authorised Signatury
			</div>
			
		</div>
	</div>
</div>
<!-- PRINT RECEIPT ENDS HERE -->
			</div>
			<!-- Modal footer -->
			<div class="modal-footer">			
				<button type="button" class="btn btn-primary"  onclick="printDiv('divbillprint')">Print</button>
				<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> 
			</div>
			
		  </div>
		</div>
</div>
<!-- ###### The Modal Payment Receipt ends here ###### -->
<script>
	$('.createMod').click(function(e)
	{   
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href'));
	});
	
	function loadloanrecord(id)
	{
		$.ajax({
			url: 'loadcreateloanapplication',
			type: 'GET',
			data:'&lacc_id='+id,
			success: function(data)
			{
				$('.content').html(data);
				//$('.loadcreateloanapplication').html(data);
				//$('#sideMenu').load('loadcreateloanapplication');
			}
		});
	}
	
	$('.edit').click(function(e)
	{
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href')); 
	});
	
	function DeleteloanApp(a)
	{
		$.confirm({
			title: 'Confirm!',
			content: 'Are you confirm Delete!',
			buttons: {
				confirm: function () {
					sureDeleteloanApp(a);
				},
				cancel: function () {
					$.alert('Canceled!');
				}
				
			}
		});
	}
	
	function sureDeleteloanApp(a)
	{
		$.ajax({
			url: 'sureDeleteloanApp',
			type: 'GET',
			data:'&lacc_id='+a,
			success: function(data)
			{
				$.toast({
					heading: 'Delete!',
					text: 'Sucessfully Deleted.',
					showHideTransition: 'slide',
					icon: 'success',
					loaderBg: '#d9534f'
				});
				$('#sideMenu').load('/LoadViewLoanApplicantion');
			}
		});
	}	
	function EditJamathMembers(cst_id)
	{
		$.ajax({
			url: 'EditJamathApplication',
			type: 'GET',
			data:'&cst_id='+cst_id,
			success: function(data)
			{
				$('#sideMenu').html(data);
			}
		});
	}
//Modal other payment starts here	
	$('#myotheramt').on('show.bs.modal', function(e) {
        var $modal = $(this),
            fund_cust_id = e.relatedTarget.id;
			$('#fund_cust_id').val(fund_cust_id);
			$.ajax({
				url: 'LoadSingleCust',
				type: 'GET',
				data:'&cst_id='+fund_cust_id,
				success: function(data)
				{
					$('#cstname').val(data.cst_name);
					$('#memid').val(data.cst_code);
				}
			});
    })
//Modal other payment ends here	
//Moday Make Payment Starts here
	$('#mypayment').on('show.bs.modal', function(e) 
	{
			$('#amt_payable').val('');
			amt=0;
			grandbal=0;
			var $modal = $(this),
            payment_cust_id = e.relatedTarget.id;
			$('#pay_cust_id').val(payment_cust_id);
			$.ajax({
				url: 'CalculatePayment',
				type: 'GET',
				data:'&cst_id='+payment_cust_id,
				success: function(data)
				{
					$('#paycstname').val(data.payrecord[0].cst_name);
					$('#paymemid').val(data.payrecord[0].cst_code);
					$('#payTotal_amount').val(""+data.payrecord[0].totalamt);
					paidamt= parseFloat(parseFloat(data.payrecord[0].paidamt) + parseFloat(data.payrecord[0].advamt) + parseFloat(data.payrecord[0].prepayamt));
					$('#payPaid_amount').val(""+paidamt);
					amt= parseFloat(data.payrecord[0].totalamt) - (parseFloat(data.payrecord[0].paidamt) + parseFloat(data.payrecord[0].advamt) + parseFloat(data.payrecord[0].prepayamt));
					$('#paybalance_amount').val(""+amt);
					$('#idpaymentlist').html(data.billingtable);
					$('#grandtotbal').val(amt);
					$('#grandpaidbal').val("0");
					grandbal = amt - 0;
					$('#grandbal').val(""+grandbal);
				}
			});
    })
//Modal Make Payment Ends here
//Payment Receipt starts here
	function funPaymentReceipt(billno,dt,amt,textamt,paytype,lins_no,towards)
	{
		document.getElementById("receiptbillno").innerHTML=billno;
		document.getElementById("receiptdate").innerHTML=dt;
		document.getElementById("receiptdate1").innerHTML=dt;
		document.getElementById("textsum").innerHTML=textamt;
		document.getElementById("receiptpaytype").innerHTML=paytype;
		document.getElementById("receiptname").innerHTML=document.getElementById("lacc_custname").value;
		document.getElementById("receiptlacc_no").innerHTML=document.getElementById("lacc_no").value;
		document.getElementById("receipttowards").innerHTML=towards;
		document.getElementById("receiptamt").innerHTML=amt;
		$('#modprintpaymentreceipt').modal({show:true});		 
	}
//Payment Receipt ends here
</script>
<script>
	$(document).ready(function(){
		var edit_ftyp_id = $('#edit_ftyp_id').val();
		$.ajax({
		type: "GET",
		url:"/loadfundtypelist",
		dataType: "json",
		success: function (data) {
		$.each(data,function(i,obj)
		{
			if(edit_ftyp_id ==0)
			{
				var div_data="<option value="+obj.ftyp_id+">"+obj.ftyp_fundtype+"</option>";	
			}
			else 
			{
				if(edit_ftyp_id == obj.ftyp_id)
				{
					var div_data="<option value="+obj.ftyp_id+" selected>"+obj.ftyp_fundtype+"</option>";	
				}
				else{
					var div_data="<option value="+obj.ftyp_id+">"+obj.ftyp_fundtype+"</option>";		
				}
			}
		 $(div_data).appendTo('#ftyp_id'); 
		});  
		}
		});
	});
</script>		  
<script>
	//load Full fund types 	edit_grd_id edit_grd_id
	$(document).ready(function(){
		var edit_grd_id = $('#edit_grd_id').val();
		$.ajax({
		type: "GET",
		url:"/loadgradelist",
		dataType: "json",
		success: function (data) {
		$.each(data,function(i,obj)
		{
			if(edit_grd_id ==0)
			{
				var div_data="<option value="+obj.grd_id+">"+obj.grd_grade+" (" + obj.grd_prefix + ")</option>";	
			}
			else 
			{
				if(edit_grd_id == obj.grd_id)
				{
					var div_data="<option value="+obj.grd_id+" selected>"+obj.grd_grade+" (" + obj.grd_prefix + ")</option>";	
				}
				else{
					var div_data="<option value="+obj.grd_id+">"+obj.grd_grade+" (" + obj.grd_prefix + ")</option>";		
				}
			}
			$(div_data).appendTo('#grd_id');
			$(div_data).appendTo('#grd_selectgradeid');
		});  
		}
		});
	});
</script>
<script type="application/javascript">
	$('.submitgradefund').click(function()
	{
		i=0;
		amt=0;
			$(".alert-info").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Processing...');
			var _token = $("input[name='_token1']").val();
			var ftyp_id =  $('#ftyp_id').val();
			var grd_id =  $('#grd_id').val();
			var fyr_id =  $('#fyr_id').val();
			var grfn_amt =  $('#grfn_amt').val();
			var grfn_paycycle = $('#grfn_paycycle').val();
			var grfn_description = $("input[name='grfn_description']").val();
			var grfn_status = $("#grfn_status").val();
			var fund_cust_id = $("#fund_cust_id").val();
			document.getElementById("errftyp_id").innerHTML = "";
			document.getElementById("errgrfn_amt").innerHTML = "";
			document.getElementById("errgrfn_paycycle").innerHTML = "";
			document.getElementById("errgrfn_description").innerHTML = "";		   	
	
			if(ftyp_id == "")
			{
				document.getElementById("errftyp_id").innerHTML = "Kindly select Fund Type...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');				
			}
			else if(grfn_paycycle == "")
			{
				document.getElementById("errgrfn_paycycle").innerHTML = "Kindly select Billing Cycle...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');				
			}
			else if(grfn_amt == "")
			{
				document.getElementById("errgrfn_amt").innerHTML = "Amount Shoud not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
			}
			else
			{
			  if(i==0)
			  {
			   i++;
			   //alert(i);
					$.ajax({
						url: "/inscstgradefund",
						type:'POST',
						data: $('#frmothercharges').serialize(),
						success: function(data) {											
							if(data.status == 1)
							{
								$('#tot_'+fund_cust_id).html(""+data.bil_billrec[0].totalamt);
								paidamt= parseFloat(parseFloat(data.bil_billrec[0].paidamt) + parseFloat(data.bil_billrec[0].advamt) + parseFloat(data.bil_billrec[0].prepayamt));
								$('#paid_'+fund_cust_id).html(""+ paidamt);
								amt= parseFloat(data.bil_billrec[0].totalamt) - (parseFloat(data.bil_billrec[0].paidamt) + parseFloat(data.bil_billrec[0].advamt) + parseFloat(data.bil_billrec[0].prepayamt));
								$('#bal_'+fund_cust_id).html(""+amt);
								$('#grfn_amt').val('');
								$("input[name='grfn_description']").val('');
								$('#myotheramt').modal('toggle');
								printSuccessMsg(data.message);
							}
							else
							{
								printErrorMsg(data.message)
							}
						}
					});
				}
			}			
		return false;
	});
	function printErrorMsg (msg) {			
		$(".alert-info").css('display','none');
		$(".print-success-msg").css('display','none');
		$(".print-error-msg").find("ul").html('');
		$(".print-error-msg").css('display','block');
		$(".print-error-msg").find("ul").append('<li class="fa fa-times-circle fa-1x fa-fw"></li>'+msg);
	}	
	function printSuccessMsg (msg) {
		$(".alert-info").css('display','none');
		$(".print-error-msg").css('display','none');
		$(".print-success-msg").find("ul").html('');
		$(".print-success-msg").css('display','block');
		$(".print-success-msg").find("ul").append('<li class="fa fa-check  fa-1x fa-fw"></li>'+msg);
	}
</script>
<script>
function paymentcalculation() 
{
	var varpaid = 0;
	var gradbalamt1 = 0;
	var amt_payable=0;
	if (isNaN(parseFloat($('#amt_payable').val()))) 
	{
		amt_payable = 0;
	}
	else
	{
		amt_payable = parseFloat($('#amt_payable').val());
	}
	var trn_id = document.getElementsByName('trn_id[]');
	var totbalamt = document.getElementsByName('totbalamt[]');
	var paidamt = document.getElementsByName('paidamt[]');
	var balamt = document.getElementsByName('balamt[]');
	var grandtot = $('#grandtotbal').val();
	for (var i = 0; i <trn_id.length; i++)
	{
		//trn_id[i].value totbalamt[i].value paidamt[i].value balamt[i].value
		if(parseFloat(totbalamt[i].value) >= amt_payable)
		{
			varpaid = amt_payable;
			amt_payable = 0;
		}
		else
		{
			varpaid = totbalamt[i].value;				
			amt_payable =  amt_payable - parseFloat(totbalamt[i].value);
		}
		paidamt[i].value = varpaid;
		balamt[i].value = parseFloat(totbalamt[i].value) - parseFloat(paidamt[i].value);
		$('#grandpaidbal').val($('#amt_payable').val());
		gradbalamt1 = gradbalamt1 + parseFloat(balamt[i].value);
	}
	document.getElementById("grandbal").value = gradbalamt1;
	document.getElementById("adv_amt").value = amt_payable;
}
</script>
<script>
function calculatetotalamt()
{
	var varpaid = 0;
	var varsum = 0;
	var gradbalamt1 = 0;
	document.getElementById("amt_payable").value = 0;
	var totbalamt = document.getElementsByName('totbalamt[]');
	var paidamt = document.getElementsByName('paidamt[]');
	var balamt = document.getElementsByName('balamt[]');
	for (var i = 0; i <paidamt.length; i++)
	{ 
		if(paidamt[i].value > 0) 
		{
			varpaid = paidamt[i].value;
		}
		else
		{
			 varpaid = 0;
		}
		varsum = varsum + parseFloat(varpaid);
		balamt[i].value = parseFloat(totbalamt[i].value) - parseFloat(varpaid);
		gradbalamt1 = gradbalamt1 + parseFloat(balamt[i].value);
	}
	$('#amt_payable').val(varsum)
	$('#grandpaidbal').val(varsum)
	$('#grandbal').val(gradbalamt1)
}
</script>
<script>
	$('.submitpayment').click(function()
	{
		i=0;
		amt=0;
		//$(".alert-paymentinfo").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Processing...');
		var _token = $("input[name='_token2']").val();
		var pay_cust_id =  $('#pay_cust_id').val();
		var paycstname =  $('#paycstname').val();
		var payTotal_amount =  $('#payTotal_amount').val();
		var payPaid_amount =  $('#payPaid_amount').val();
		var paybalance_amount =  $('#paybalance_amount').val();
		if (isNaN(parseFloat($('#amt_payable').val()))) 
		{
			amt_payable = 0;
		}
		else
		{
			amt_payable = parseFloat($('#amt_payable').val());
		}
		var adv_amt = $('#adv_amt').val();
		document.getElementById("erramt_payable").innerHTML = "";
		arrtrn_id = [];
		arrslno = [];
		arrftype = [];
		arrpaycycle = [];
		arrtotbalamt = [];
		arrpaidamt = [];
		arrbalamt = [];
		arrfy_id = [];
		arrgrd_id = [];
		arrgrfn_id = [];
		arrftyp_id = [];
		var trn_id= document.getElementsByName("trn_id[]");
		var slno= document.getElementsByName("slno[]");
		var ftype= document.getElementsByName("ftype[]");
		var paycycle= document.getElementsByName("paycycle[]");
		var totbalamt= document.getElementsByName("totbalamt[]");
		var paidamt= document.getElementsByName("paidamt[]");
		var balamt= document.getElementsByName("balamt[]");
		   
		var fy_id= document.getElementsByName("fy_id[]");
		var grd_id= document.getElementsByName("grd_id[]");
		var grfn_id= document.getElementsByName("grfn_id[]");
		var ftyp_id= document.getElementsByName("ftyp_id[]");
		
		var grandtotbal= document.getElementsByName("grandtotbal");
		var grandpaidbal= document.getElementsByName("grandpaidbal");
		var grandbal= document.getElementsByName("grandbal");
		var validationbalamt = 0;
		for (index = 0; index < trn_id.length; ++index)
		{
			arrtrn_id[index] = trn_id[index].value;
			arrslno[index] = slno[index].value;
			arrftype[index] = ftype[index].value;
			arrpaycycle[index] = paycycle[index].value;
			arrtotbalamt[index] = totbalamt[index].value;
			arrpaidamt[index] = paidamt[index].value;
			arrbalamt[index] = balamt[index].value;
			arrfy_id[index] = fy_id[index].value;
			arrgrd_id[index] = grd_id[index].value;
			arrgrfn_id[index] = grfn_id[index].value;
			arrftyp_id[index] = ftyp_id[index].value;
			if(parseFloat(balamt[index].value) < 0)
			{
				validationbalamt = 1;
			}
		}

		if(amt_payable == 0)
		{
			document.getElementById("erramt_payable").innerHTML = " Mandatory Field..";
		}
		else if(validationbalamt ==1)
		{
			alert("Balance amount should not be negative");
		}
		else
		{
		  if(i==0)
		  {
				i++;		
				$.ajax({
					url: "makebillingpayment",
					type:'POST',
					dataType: 'json',
					//cache : false,
					//processData: false,
					data: {_token:_token,pay_cust_id:pay_cust_id, paycstname:paycstname, payTotal_amount:payTotal_amount, payPaid_amount:payPaid_amount, paybalance_amount:paybalance_amount, amt_payable:amt_payable,adv_amt:adv_amt, arrtrn_id:arrtrn_id,arrslno:arrslno,arrftype:arrftype,arrpaycycle:arrpaycycle,arrtotbalamt:arrtotbalamt,arrpaidamt:arrpaidamt,arrbalamt:arrbalamt,arrfy_id:arrfy_id,arrgrd_id:arrgrd_id,arrgrfn_id:arrgrfn_id,arrftyp_id:arrftyp_id},
					success: function(data)
					{
						if(data.status == "Success")
						{
							alert("Billing Record inserted Sucessfully");
							BillPrint(data.transaction_id);
						}
						else
						{
							alert("Failed to Generate Purchase Bill..");
							//printErrorMsg(data.message)
						}
					}
				});
			}
		}
		return false;
	});
		
	function BillPrint(transaction_id)
	{
		$('#mypayment').modal('toggle');
		$("#modprintpaymentreceipt").modal();
		$.ajax({
			url: 'printpaymentbill',
			type: 'get',
			data:'&transaction_id='+transaction_id,
			success: function(data)
			{
				//Update balance in table starts here
				$('#tot_'+data.trn_transaction.cst_id).html(""+data.bil_billrec[0].totalamt);
				paidamt= parseFloat(parseFloat(data.bil_billrec[0].paidamt) + parseFloat(data.bil_billrec[0].advamt) + parseFloat(data.bil_billrec[0].prepayamt));
				$('#paid_'+data.trn_transaction.cst_id).html(""+ paidamt);
				amt= parseFloat(data.bil_billrec[0].totalamt) - (parseFloat(data.bil_billrec[0].paidamt) + parseFloat(data.bil_billrec[0].advamt) + parseFloat(data.bil_billrec[0].prepayamt));
				$('#bal_'+data.trn_transaction.cst_id).html(""+amt);
				//Update balance in table ends here							
				document.getElementById("receiptbillno").innerHTML=data.trn_billno;
				document.getElementById("receiptmember_id").innerHTML= data.cst_grade_prefix + "-" + data.cst_code;
				document.getElementById("receiptdate").innerHTML=data.trn_date;
				document.getElementById("receiptname").innerHTML=data.cst_name;
				document.getElementById("receiptamt1").innerHTML=data.bilr_gtotal;
				document.getElementById("transaction_id").value=transaction_id;
				$('#receipttable').html(data.transrecord);
			}
		});
	}
	function printDiv(divName)
	{
		var transaction_id = document.getElementById("transaction_id").value;
		window.open('printprintbill?transaction_id=' + transaction_id  ,'_blank');
	}
$(document).ready( function () {
    $('#mydatatable').DataTable({
		"sDom": '<"H"lfrp>t<"F"ip>',
	});
} );
function loadjamathrecords(rectype) // Pending Accounts Paid Accounts
{
	if(rectype == "All")
	{
		document.getElementById("idreload1").innerHTML = "<i class='fa  fa-american-sign-language-interpreting fa-spin' aria-hidden='true'></i>All Accounts";
	}
	if(rectype == "Pending")
	{
		document.getElementById("idreload2").innerHTML = "<i class='fa  fa-thumbs-down fa-spin' aria-hidden='true'></i>Pending Accounts";
	}
	if(rectype == "Paid")
	{
		document.getElementById("idreload3").innerHTML = "<i class='fa  fa-thumbs-up fa-spin' aria-hidden='true'></i>Paid Accounts";
	}
	var pagename = "viewJamathApplicant";
	$.ajax({
		url: pagename,
		type: 'get',
		data:'&rectype='+rectype,
		success: function(data)
		{
			$('#sideMenu').html(data);
			if(rectype == "All")
			{
				document.getElementById("idreload1").innerHTML = "<i class='fa  fa-american-sign-language-interpreting' aria-hidden='true'></i>All Accounts";
			}
			if(rectype == "Pending")
			{
				document.getElementById("idreload2").innerHTML = "<i class='fa fa-thumbs-down' aria-hidden='true'></i>Pending Accounts";
			}
			if(rectype == "Paid")
			{
				document.getElementById("idreload3").innerHTML = "<i class='fa fa-thumbs-up' aria-hidden='true'></i>Paid Accounts";
			}
		}
	});
}
function printjamathreport(rectype)
{
	window.open('printjamathmembersreport?rectype='+rectype,'_blank');
}
</script>