<?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="{{ csrf_token() }}">
<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-eye"></i>  {{ __('report.view_inc_exp') }} - {{ __('report.search_records') }} </h3>
			</div>
			<div class="widget-content">		
				<div class="row">
					<div class="col-md-4">{{ __('mylanguage.member_id') }}
						<input type="text" class="form-control" id="member_id" name="member_id"  value="{{ $data['member_id']  }}" >
					</div>
					<div class="col-md-4">{{ __('mylanguage.select_grade') }}
						<input type="hidden" id="edit_grd_id" name="edit_grd_id" value="{{ isset($data) ? $data['grd_id'] : '0'  }}">
						<select id="grd_id" name="grd_id" class="form-control" >
							<option value="">-- {{ __('mylanguage.select_grade') }} --</option>
						</select>
					</div>
					<div class="col-md-4">{{ __('report.fund_type') }}
						<input type="hidden" id="edit_ftyp_id" name="edit_ftyp_id" value="{{ isset($data) ? $data['ftyp_id'] : '0'  }}">
						<select name="ftyp_id" id="ftyp_id" class="form-control">
							<option value=""> -- {{ __('grade.fund_type') }} --</option>
						</select>
					</div>
				</div>
				<div class="row">
					<div class="col-md-4">{{ __('report.transaction_type') }} 
						<input type="hidden" id="edit_grfn_paycycle" name="edit_grfn_paycycle" value="{{ $data['grfn_paycycle'] }}">
						<select name="grfn_paycycle" id="grfn_paycycle" class="form-control" required>
							<option value="">-- {{ __('grade.billing_cycle') }} --</option>
							<option value="Payment">Payment</option>
							<option value="Daily">{{ __('grade.Daily') }}</option>
							<option value="Weekly">{{ __('grade.Weekly') }}</option>
							<option value="Monthly">{{ __('grade.Monthly') }}</option>
							<option value="Quarterly">{{ __('grade.Quarterly') }}</option>
							<option value="Semiannually">{{ __('grade.Semiannually') }}</option>
							<option value="Yearly">{{ __('grade.Yearly') }}</option>
							<option value="Onetime">{{ __('grade.Onetime') }}</option>
						</select>
					</div>
					<div class="col-md-4">{{ __('report.transaction_fdate') }}
					<input type="date" class="form-control" name="fdate" id="fdate"  value="{{ isset($data) ? $data['fdate'] : date('Y-m-d') }}">
					</div>
					<div class="col-md-4">{{ __('report.transaction_tdate') }}
					<input type="date" class="form-control" name="tdate" id="tdate"  value="{{ 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> {{ __('report.view_inc_exp_detail') }}</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: 35px;'>{{ __('report.slno') }}</th>
							<th style='width: 75px;'>{{ __('report.billno') }}</th>
							<th style='width: 100px;'>{{ __('report.transaction_date') }}</th>
							<th style='width: 75px;'>{{ __('mylanguage.member_id') }}</th>
							<th>{{ __('mylanguage.name') }}</th>
							<th>{{ __('report.transaction_type') }}</th>
							<?php /* <th>{{ __('report.transaction_particular') }}</th> */ ?>
							<th style='width: 65px;text-align: right;'>{{ __('report.transaction_bill') }}</th>
							<th style='width: 65px;text-align: right;'>{{ __('report.transaction_payment')  }}</th>
							<th style='width: 65px;text-align: right;'>{{ __('report.transaction_sum') }}</th>		
						</tr>
					</thead>
					<tbody>
			<?php
			$payable = 0;
			$paid = 0;
			$totamt = 0;
			$slno = 1;
			?>
						@foreach($data['trn_transaction'] as $trn_val)
<?php
if($trn_val->trn_type == "Daily" || $trn_val->trn_type == "Weekly" || $trn_val->trn_type == "Monthly" ||  $trn_val->trn_type == "Quarterly" ||  $trn_val->trn_type == "Semiannually" ||  $trn_val->trn_type == "Yearly" ||  $trn_val->trn_type == "One time" || $trn_val->trn_type == "Payment" )
{
				if($trn_val->trn_type == "Daily")
				{
					$bilr_paycycle = "ಪ್ರತಿದಿನ";
				}
				else if($trn_val->trn_type == "Weekly")
				{
					$bilr_paycycle = "ವಾರಕ್ಕೊಮ್ಮೆ";
				}
				else if($trn_val->trn_type == "Monthly")
				{
					$bilr_paycycle = "ಮಾಸಿಕ";
				}
				else if($trn_val->trn_type == "Quarterly")
				{
					$bilr_paycycle = "ಮೂರು ತಿಂಗಳಿಗೊಮ್ಮೆ";
				}
				else if($trn_val->trn_type == "Semiannually")
				{
					$bilr_paycycle = "ಅರ್ಧ ವಾರ್ಷಿಕ";
				}
				else if($trn_val->trn_type == "Yearly")
				{
					$bilr_paycycle = "ವಾರ್ಷಿಕ";
				}
				else if($trn_val->trn_type == "One time")
				{
					$bilr_paycycle = "ಒಂದು ಬಾರಿ";
				}
	if($trn_val->trn_type == "Daily" || $trn_val->trn_type == "Weekly" || $trn_val->trn_type == "Monthly" ||  $trn_val->trn_type == "Quarterly" ||  $trn_val->trn_type == "Semiannually" ||  $trn_val->trn_type == "Yearly" ||  $trn_val->trn_type == "One time")
	{
		echo "<tr style='color: #2b2121;'>";
		echo "<td>" . $slno . "</td>";
		echo "<td>" . $trn_val->trn_id . "</td>";
	}
	if($trn_val->trn_type == "Payment")
	{
		echo "<tr style='color: green;'>";
		echo "<td>" . $slno . "</td>";
		echo "<th>" . $trn_val->trn_billno . "</th>";
	}	
		echo "<td>" . date("d-m-Y",strtotime($trn_val->trn_date))  . "</td>";
		echo "<td>" . $trn_val->cstgrdprefix . $trn_val->cst_code  . "</td>";
		echo "<td>" . $trn_val->cst_name  . "</td>";
		echo "<td>";
		if($trn_val->trn_type == "Payment")
		{
			echo $trn_val->trn_type;
		}
		else
		{
			echo $trn_val->ftyp_fundtype . " (" . $bilr_paycycle .")";
		}
		echo "</td>";
		//echo "<td>" . $trn_val->ftyp_fundtype . "</td>";
	if($trn_val->trn_type == "Daily" || $trn_val->trn_type == "Weekly" || $trn_val->trn_type == "Monthly" ||  $trn_val->trn_type == "Quarterly" ||  $trn_val->trn_type == "Semiannually" ||  $trn_val->trn_type == "Yearly" ||  $trn_val->trn_type == "One time")
	{
		$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 == "Payment")
	{
		$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>";
		$slno=$slno+1;
}
?>						
						@endforeach	
						<tr>
							<th></th>
							<th></th>
							<th></th>
							<th></th>
							<th></th>
							<th style='text-align: right;'>Total :</th>
							<th style='text-align: right;'>{{ $payable }}</th>	 	 
							<th style='text-align: right;'>{{ $paid }}</th>
							<th style='text-align: right;'>{{ $totamt }}</th>				
						</tr>
					</tbody>
				</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="transactionreportprint?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 -->
<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_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>
	//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:"/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>
	$(document).ready(function(){
		var selectedval = document.getElementById("edit_grfn_paycycle").value;
		$('#grfn_paycycle').val(selectedval);
	});
</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 _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();
	var submit =  $('#btnsubmitall').val();
	e.preventDefault();
	$('#sideMenu').load('transactionreport?member_id=' + member_id + '&grd_id='+grd_id + '&ftyp_id='+ ftyp_id + '&grfn_paycycle='+grfn_paycycle + '&fdate='+fdate + '&tdate='+tdate+'&submit=submit');
});
</script>