<?php
$user = auth()->user();
?>
<script src="assets/js/king-table.js"></script>
<div class="content">
	<div class="main-content">
		<!-- DATA EXPORT -->
		<form id="frmothercharges" name="frmothercharges" method="post" data-parsley-validate novalidate>
<input type="hidden" name="_token" id="_token" value="<?php echo e(csrf_token()); ?>">
<input type="hidden" name="ftyp_module" id="ftyp_module" class="form-control" value="<?php echo $data['ftyp_module']; ?>" readonly >
<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-eye"></i> <?php echo e(__('report.search_records')); ?> </h3>
			</div>
			<div class="widget-content">		
				<div class="row">
					<div class="col-md-4"><?php echo e(__('report.fund_type')); ?>

						<input type="hidden" id="edit_ftyp_id" name="edit_ftyp_id" value="<?php echo e(isset($data) ? $data['ftyp_id'] : '0'); ?>">
						<select name="ftyp_id" id="ftyp_id" class="form-control">
							<option value=""> -- <?php echo e(__('grade.fund_type')); ?> --</option>
						</select>
					</div>
					<div class="col-md-4"><?php echo e(__('report.transaction_fdate')); ?>

						<input type="date" class="form-control" name="fdate" id="fdate"  value="<?php echo e(isset($data) ? $data['fdate'] : date('Y-m-d')); ?>">
					</div>
					<div class="col-md-4"><?php echo e(__('report.transaction_tdate')); ?>

						<input type="date" class="form-control" name="tdate" id="tdate"  value="<?php echo e(isset($data) ? $data['tdate'] : date('Y-m-d')); ?>">
					</div>
				</div>
			</div>
			<div class="widget-header">
				<center>
		<button type="button" id="btnsubmitall" name="btnsubmitall" class="btn btn-default sideClick1" ><i class="fa fa-arrows" aria-hidden="true"></i> Filter Records</button>
				</center>
			</div>
		</div>
		</form>
		<!-- END DATA EXPORT -->
<hr>
		<!-- DATA EXPORT -->
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i><?php
									if($data['ftyp_module'] == "Income")
									{
										echo __('fundtype.income_transaction');
									}
									if($data['ftyp_module'] == "Expense")
									{
										echo __('fundtype.expense_transaction');
									}
									if($data['ftyp_module'] == "Loan")
									{
										echo __('fundtype.loan_transaction');
									}
									?></h3>
			</div>
			<div class="widget-content">
				<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable" border="1" >
					<thead>
						<tr>
							<th style='width: 35px;'><?php echo e(__('report.slno')); ?></th>
							<?php /*<th style='width: 75px;'>{{ __('report.billno') }}</th>*/ ?>
							<th style='width: 100px;'><?php echo e(__('report.transaction_date')); ?></th>
							<?php /*<th>{{ __('mylanguage.name') }}</th>*/ ?>
							<th><?php echo e(__('report.transaction_type')); ?></th>
							<th><?php echo e(__('report.transaction_particular')); ?></th>
							<th style='width: 65px;text-align: right;'><?php echo e(__('report.transaction_payment')); ?></th>
							<th style='width: 65px;'><?php echo e(__('mylanguage.action')); ?></th>		
						</tr>
					</thead>
					<tbody>
			<?php
			$payable = 0;
			$paid = 0;
			$totamt = 0;
			$slno = 1;
			?>
						<?php $__currentLoopData = $data['trn_transaction']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trn_val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<?php
if($trn_val->trn_type == "Income" || $trn_val->trn_type == "Expense" || $trn_val->trn_type == "Loan"  )
{
		if($trn_val->trn_type == "Income")
		{
			$bilr_paycycle = __('fundtype.income');
		}
		else if($trn_val->trn_type == "Expense")
		{
			$bilr_paycycle = __('fundtype.expense');
		}
		else if($trn_val->trn_type == "Loan")
		{
			$bilr_paycycle = __('fundtype.loan');
		}

		echo "<tr>";
		echo "<td>$slno</td>";
		echo "<td>" . date("d-m-Y",strtotime($trn_val->trn_date))  . "</td>";
		echo "<td>";
			echo $trn_val->ftyp_fundtype;
		echo "</td>";
		echo "<td> " . $trn_val->trn_note . "</td>";
	if($trn_val->trn_type == "Income" || $trn_val->trn_type == "Expense" || $trn_val->trn_type == "Loan")
	{
		$payable = $payable + $trn_val->billamt;
		$totamt = $totamt + $trn_val->billamt;
		echo "<th style='text-align: right;'>"  . $trn_val->billamt  ."</th>";
	}
		echo "<td>";
	if($trn_val->trn_type == "Expense")
	{
		echo "<button class='btn btn-default btn-xs' onclick='BillPrint($trn_val->trn_id)'  title='Print Record'><i class='fa fa-print' aria-hidden='true'></i></button> ";
	}
	if($trn_val->trn_type == "Loan")
	{
		echo "<button class='btn btn-default btn-xs' onclick='BillLoanPrint($trn_val->trn_id)'  title='Print Record'><i class='fa fa-print' aria-hidden='true'></i></button> ";
	}
		echo "<button class='btn btn-danger btn-xs' onclick='deleterec($trn_val->trn_id)'  title='Delete Record'><i class='fa fa-trash-o' aria-hidden='true'></i></button>";
		echo "</td>";
		echo  "</tr>";
		$slno=$slno+1;
}
?>						
						<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>	
					</tbody>
					<tfoot>
						<tr>
							<th></th>
							<th></th>
							<th style='text-align: right;'></th>	 
							<th style='text-align: right;'>Total :</th>
							<th style='text-align: right;'><?php echo e($totamt); ?></th>	
							<th></th>
						</tr>
					</tfoot>
				</table>
			</div>
				<?php
				/*
			<div class="widget-header">
				<center>
				<?php
				$urlparameter = "";
				if(isset($_SERVER['QUERY_STRING']))
				{
				$urlparameter = $_SERVER['QUERY_STRING'];
				}
				?>
		<a type="button" id="btnprintreport" name="btnprintreport" href="incexptransreportprint?urlparameter={{ $urlparameter }}" class="btn btn-default" target="_blank" ><i class="fa fa-print" aria-hidden="true"  ></i> Print report</a>
				</center>
			</div>
			*/
			?>
		</div>
		<!-- END DATA EXPORT -->
	</div>
</div>
<!-- /main -->
<!-- ###### 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>CASH VOUCHER</b></center>
				<hr>
			</div>
			
			<div class="col-md-6">
				<b><?php echo e(__('mylanguage.billno')); ?> <label id="receiptbillno"></label></b></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.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">
				<label id="trnnote"></label>
			</div>
			<div class="col-md-6 text-right"><h1 style="border:1px solid #cecece;">Rs. <label id="receiptamt1">000</label>/-</h2></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 ###### -->
<!-- ###### The Modal Loan Payment Receipt starts here ###### -->
<div class="modal" id="modloanprintpaymentreceipt">
		<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>LOAN VOUCHER</b></center>
				<hr>
			</div>
			
			<div class="col-md-6">
				<b><?php echo e(__('mylanguage.billno')); ?> <label id="receiptbillnoa"></label></b></b><br>
				<b><?php echo e(__('mylanguage.name')); ?> <label id="receiptnamea"></label></b>
			</div>
			<div class="col-md-6 text-right">
				<b><?php echo e(__('mylanguage.date')); ?> <label id="receiptdatea" >00-00-0000</label></b>
			</div>

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

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

			<div class="col-md-6 text-left"><font style="border:1px solid #cecece;padding: 10px;"><?php echo e(__('incexp.credited_details')); ?>: <label id="trnnotea"></label></font></div>
			<div class="col-md-6 text-right"><h1 style="border:1px solid #cecece;">Rs. <label id="receiptamt1a">000</label>/-</h2></div>
			
		</div>
	</div>
</div>
<!-- PRINT RECEIPT ENDS HERE -->
			</div>
			<!-- Modal footer -->
			<div class="modal-footer">			
				<button type="button" class="btn btn-primary"  onclick="printDivloan('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 ###### -->
<style>
.modal-dialog.modal-100 {
    width: 90%;
    /*margin: 30px auto;*/
}
</style>

<script>
	$('.createMod').click(function(e)
	{   
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href'));
	});
</script>
<script>
	// ### load Fund Type starts here
	//$(document).ready(function(){
		var edit_ftyp_id = $('#edit_ftyp_id').val();
		var ftyp_module = $('#ftyp_module').val();
		$.ajax({
		type: "GET",
		url:"/loadfundtypecmb?ftyp_module="+ftyp_module,
		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'); 
		});  
		}
		});
	//});
	// ### load Fund Type ends here
</script>
<script>
	function reloadtransreport()
	{
			document.getElementById("btnsubmitall").innerHTML = "<i class='fa fa-arrows fa-spin' aria-hidden='true'></i> Fetching Records";
			var _token = $("input[name='_token']").val();
			var member_id =  $('#member_id').val();
			var grd_id =  $('#grd_id').val();
			var ftyp_id  =  $('#ftyp_id').val();
			var grfn_paycycle =  $('#grfn_paycycle').val();
			var fdate =  $('#fdate').val();
				$.ajax({
					url: "/transactionreport",
					type: 'get',
					//data: {_token:_token, member_id:member_id, grd_id: grd_id, ftyp_id: ftyp_id, grfn_paycycle: grfn_paycycle, fdate:fdate, tdate:tdate},
					success: function(data)
					{
						$('#reloadrecord').html(data);
						document.getElementById("btnsubmitall").innerHTML = "<i class='fa fa-arrows' aria-hidden='true'></i> Filter Records";
					}
				});
	}
</script>
<script>
$('.sideClick1').click(function(e)
{
	document.getElementById("btnsubmitall").innerHTML = "<i class='fa fa-arrows fa-spin' aria-hidden='true'></i> Fetching Records";
	var ftyp_id  =  $('#ftyp_id').val();
	var fdate =  $('#fdate').val();
	var tdate =  $('#tdate').val();
	var ftyp_module =  $('#ftyp_module').val();
	e.preventDefault();
	$('#sideMenu').load('viewincomeexpenserecsearch?ftyp_module='+ftyp_module+"&ftyp_id="+ftyp_id+"&fdate="+fdate+"&tdate="+tdate+'&btnsubmitall=btnsubmitall');
});
</script>
<script>
function deleterec(trn_id)
{
	var ftyp_id  =  $('#ftyp_id').val();
	var fdate =  $('#fdate').val();
	var tdate =  $('#tdate').val();
	var ftyp_module =  $('#ftyp_module').val();
	if(confirm("Are you sure want to delete this record?") == true)
	{
		k = 0;
		if(k == 0)
		{
			k++;
			$.ajax({
				url: 'deleteincomeexpenserec',
				type: 'GET',
				data:'&trn_id='+trn_id+'&ftyp_module='+ftyp_module+"&ftyp_id="+ftyp_id+"&fdate="+fdate+"&tdate="+tdate,
				success: function(data)
				{
					$('#sideMenu').html(data);
				}
			});
		}
	}
}
</script>
<script>
	//### Billing submission entry code ends here
	function BillPrint(transaction_id)
	{
		$("#modprintpaymentreceipt").modal();
		$.ajax({
			url: 'printexpensebill',
			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;
				document.getElementById("trnnote").innerHTML=data.trn_note;
				$('#receipttable').html(data.transrecord);
			}
		});
	}
	function BillLoanPrint(transaction_id)
	{
		$("#modloanprintpaymentreceipt").modal();
		$.ajax({
			url: 'printloanbill',
			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("receiptbillnoa").innerHTML=data.trn_billno;
				//document.getElementById("receiptmember_id").innerHTML= data.cst_grade_prefix + "-" + data.cst_code;
				document.getElementById("receiptdatea").innerHTML=data.trn_date;
				document.getElementById("receiptnamea").innerHTML=data.cst_name;
				document.getElementById("receiptamt1a").innerHTML=data.bilr_gtotal;
				document.getElementById("transaction_id1").value=transaction_id;
				document.getElementById("trnnotea").innerHTML=data.trn_note;
				$('#receipttablea').html(data.transrecord);
			}
		});
	}
	
	function printDiv(divName)
	{
		var transaction_id = document.getElementById("transaction_id").value;
		window.open('printexpensebillvoucher?transaction_id=' + transaction_id + '&ftyp_module=Expense'  ,'_blank');
	}
	function printDivloan(divName)
	{
		var transaction_id = document.getElementById("transaction_id1").value;
		window.open('printexpensebillvoucher?transaction_id=' + transaction_id + '&ftyp_module=Loan' ,'_blank');
	}
</script>