<?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()); ?>">
<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(__('mylanguage.member_id')); ?>

						<input type="text" class="form-control" id="member_id" name="member_id"  value="<?php echo e($data['member_id']); ?>" >
					</div>
					<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_type')); ?> 
						<input type="hidden" id="edit_grfn_paycycle" name="edit_grfn_paycycle" value="<?php echo e(isset($data) ? $data['grfn_paycycle'] : '0'); ?>">
						<select name="grfn_paycycle" id="grfn_paycycle" class="form-control" required>
							<option value="">-- <?php echo e(__('grade.billing_cycle')); ?> --</option>
							<option value="sPayment">Payment</option>
							<option value="Special">Special Fund</option>
						</select>
					</div>
				</div>
				<div class="row">
					<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 echo e(__('report.specialmemberrpt')); ?></h3>
			</div>
			<div class="widget-content">
				<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable">
					<thead>
						<tr>
							<th style='width: 75px;'><?php echo e(__('report.slno')); ?></th>
							<th style='width: 100px;'><?php echo e(__('report.transaction_date')); ?></th>
							<th style='width: 75px;'><?php echo e(__('mylanguage.member_id')); ?></th>
							<th><?php echo e(__('mylanguage.name')); ?></th>
							<th><?php echo e(__('report.transaction_type')); ?></th>
							<?php /* <th>{{ __('report.transaction_particular') }}</th> */ ?>
							<th style='width: 65px;text-align: right;'><?php echo e(__('report.transaction_bill')); ?></th>
							<th style='width: 65px;text-align: right;'><?php echo e(__('report.transaction_payment')); ?></th>
							<th style='width: 65px;text-align: right;'><?php echo e(__('report.transaction_sum')); ?></th>		
						</tr>
					</thead>
					<tbody>
			<?php
			$payable = 0;
			$paid = 0;
			$totamt = 0;
			?>
						<?php $__currentLoopData = $data['trn_transaction']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trn_val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<?php
if($trn_val->trn_type == "Special" || $trn_val->trn_type == "sPayment" )
{
	if($trn_val->trn_type == "Special")
	{
		echo "<tr style='color: #2b2121;'>";
		echo "<td>" . $trn_val->trn_id . "</td>";
	}
	if($trn_val->trn_type == "sPayment")
	{
		echo "<tr style='color: green;'>";
		echo "<th>" . $trn_val->trn_billno . "</th>";
	}	

		echo "<td>" . date("d-m-Y",strtotime($trn_val->trn_date))  . "</td>";
		echo "<td>" . $trn_val->cst_code  . "</td>";
		echo "<td>" . $trn_val->cst_name  . "</td>";
		echo "<td>";
		if($trn_val->trn_type == "sPayment")
		{
			echo "Payment";
		}
		else
		{
			echo $trn_val->ftyp_fundtype ;
		}
		echo "</td>";
		//echo "<td>" . $trn_val->ftyp_fundtype . "</td>";
	if($trn_val->trn_type == "Special")
	{
		$payable = $payable + $trn_val->billamt;
		$totamt = $totamt + $trn_val->billamt;
		echo "<th style='text-align: right;'>"  . $trn_val->billamt  ."</th>";
	}
	else
	{
		echo "<th style='text-align: right;'></th>";
	}
	if($trn_val->trn_type == "sPayment")
	{
		$totamt = $totamt - $trn_val->billamt;
		$paid = $paid + $trn_val->billamt;
		echo "<th style='text-align: right;'>"  . $trn_val->billamt  ."</th>";
	}
	else
	{
		echo "<th style='text-align: right;'></th>";
	}
		echo  "<th style='text-align: right;'>"  . $totamt  ."</th>";
		echo  "</tr>";
}
?>						
						<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>	
					</tbody>
					<tfoot>
						<tr>
							<th></th>
							<th></th>
							<th></th>
							<th></th>
							<th style='text-align: right;'>Total :</th>
							<th style='text-align: right;'><?php echo e($payable); ?></th>	 	 
							<th style='text-align: right;'><?php echo e($paid); ?></th>
							<th style='text-align: right;'><?php echo e($totamt); ?></th>				
						</tr>
					</tfoot>
				</table>
			</div>
			<div class="widget-header">
				<center>
				<?php
				$urlparameter = "";
				if(isset($_SERVER['QUERY_STRING']))
				{
				$urlparameter = $_SERVER['QUERY_STRING'];
				}
				?>
		<a type="button" id="btnprintreport" name="btnprintreport" href="spltransactionreportprint?urlparameter=<?php echo e($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 -->
<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 Full fund types 	edit_ftyp_id edit_grd_id
	$(document).ready(function(){
		var edit_ftyp_id = $('#edit_ftyp_id').val();
		$.ajax({
		type: "GET",
		url:"/spclloadfundtypelist",
		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>
	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: "/spltransactionreport",
					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 _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();
	var tdate =  $('#tdate').val();
	e.preventDefault();
	$('#sideMenu').load('specialmembertransrpt?member_id=' + member_id + '&grfn_paycycle='+ grfn_paycycle  + '&ftyp_id='+ ftyp_id  + '&fdate='+fdate + '&tdate='+tdate+'&submit=submit');
});
</script>
<script>
	$(document).ready(function(){
		var selectedval = document.getElementById("edit_grfn_paycycle").value;		
		$('#grfn_paycycle').val(selectedval);
	});
</script>