<?php
$user = auth()->user();
?>
<script src="assets/js/king-table.js"></script>
<!-- @@@@ CODING FOR DROPDOWN BOX STARTS HERE@@@ -->
<script type="text/javascript" src="http://davidstutz.de/bootstrap-multiselect/dist/js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" type="text/css" href="http://davidstutz.de/bootstrap-multiselect/dist/css/bootstrap-multiselect.css">
<!-- @@@@ CODING FOR DROPDOWN BOX ENDS HERE@@@ -->
<div class="content">
	<div class="main-content">
		
<!-- 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"><?php echo e(__('report.search_records')); ?></h4>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
			<form id="frmothercharges" name="frmothercharges" method="post" data-parsley-validate novalidate>
			<?php echo csrf_field(); ?>

				<div class="row">
<div class="col-md-6"><?php echo e(__('report.jamath_list')); ?><br>
	<script>
	$(function() {
		$('#jamath_list').multiselect({
			includeSelectAllOption: true
		});
	});
	</script>
	<select id="jamath_list" name="jamath_list[]" multiple="multiple" class="form-control">
	<?php
	if(isset($data['arrjamath_listmod']))
	{
	$arrrec = $data['arrjamath_listmod']; 
	}
	else
	{
		$arrrec=array("0");
	}
	foreach($data['JamathList'] as $reclist)
	{
		if(in_array($reclist->ftyp_id,$arrrec))
		{
		echo "<option value='$reclist->ftyp_id' selected>$reclist->ftyp_fundtype</option>";
		}
		else
		{
			echo "<option value='$reclist->ftyp_id'>$reclist->ftyp_fundtype</option>";
		}
	}
	?>
	</select>						
</div>
					<div class="col-md-6"><?php echo e(__('report.specialmember_list')); ?><br>
						<script>
						$(function() {
							$('#specialmember_list').multiselect({
								includeSelectAllOption: true
							});
						});
						</script>
						<select id="specialmember_list" name="specialmember_list[]"  multiple="multiple" class="form-control">
						<?php
						if(isset($data['arrspecialmember_listmod']))
						{
						$arrrec = $data['arrspecialmember_listmod']; 
						}
						else
						{
							$arrrec=array("0");
						}
						foreach($data['SpecialList'] as $reclist)
						{
							if(in_array($reclist->ftyp_id, $arrrec))
							{
							echo "<option value='$reclist->ftyp_id' selected>$reclist->ftyp_fundtype</option>";
							}
							else
							{
								echo "<option value='$reclist->ftyp_id'>$reclist->ftyp_fundtype</option>";
							}
						}
						?>
						</select>
					</div>
				</div>
				<div class="row">
					<div class="col-md-6"><?php echo e(__('report.income_list')); ?><br>
						<script>
						$(function() {
							$('#income_list').multiselect({
								includeSelectAllOption: true
							});
						});
						</script>
						<select id="income_list" name="income_list[]"  multiple="multiple" class="form-control">
						<?php
	if(isset($data['arrincome_listmod']))
	{
	$arrrec = $data['arrincome_listmod']; 
	}
	else
	{
		$arrrec=array("0");
	}
						foreach($data['IncomeList'] as $reclist)
						{
							if(in_array($reclist->ftyp_id, $arrrec))
							{
							echo "<option value='$reclist->ftyp_id' selected>$reclist->ftyp_fundtype</option>";
							}
							else
							{
								echo "<option value='$reclist->ftyp_id'>$reclist->ftyp_fundtype</option>";
							}
						}
						?>
						</select>
					</div>
					<div class="col-md-6"><?php echo e(__('report.expense_list')); ?><br>
						<script>
						$(function() {
							$('#expense_list').multiselect({
								includeSelectAllOption: true
							});
						});
						</script>
						<select id="expense_list" name="expense_list[]"  multiple="multiple" class="form-control">
						<?php
	if(isset($data['arrexpense_listmod']))
	{
	$arrrec = $data['arrexpense_listmod']; 
	}
	else
	{
		$arrrec=array("0");
	}
						foreach($data['ExpenseList'] as $reclist)
						{
							if(in_array($reclist->ftyp_id,$arrrec))
							{
							echo "<option value='$reclist->ftyp_id' selected>$reclist->ftyp_fundtype</option>";
							}
							else
							{
								echo "<option value='$reclist->ftyp_id'>$reclist->ftyp_fundtype</option>";
							}
						}
						?>
						</select>
					</div>
					<div class="col-md-6"><?php echo e(__('report.loan_list')); ?><br>
						<script>
						$(function() {
							$('#loan_list').multiselect({
								includeSelectAllOption: true
							});
						});
						</script>
						<select id="loan_list" name="loan_list[]"  multiple="multiple" class="form-control">
						<?php
	if(isset($data['arrloan_listmod']))
	{
	$arrrec = $data['arrloan_listmod']; 
	}
	else
	{
		$arrrec=array("0");
	}
						foreach($data['LoanList'] as $reclist)
						{
							if(in_array($reclist->ftyp_id, $arrrec))
							{
							echo "<option value='$reclist->ftyp_id' selected>$reclist->ftyp_fundtype</option>";
							}
							else
							{
								echo "<option value='$reclist->ftyp_id'>$reclist->ftyp_fundtype</option>";
							}
						}
						?>
						</select>
					</div>
					
					
					<div class="col-md-6"><?php echo e(__('mylanguage.others')); ?><br>
<script>
$(function() {
	$('#other_list').multiselect({
		includeSelectAllOption: true
	});
});
</script>
<select id="other_list" name="other_list[]"  multiple="multiple" class="form-control">
	<?php
	$tirodi = __('matrimonial.mrg_thirodi');
	$advance = __('report.j_advpay');
	if(isset($data['arrother_listmod']))
	{
	$arrrec = $data['arrother_listmod']; 
	}
	else
	{
	$arrrec=array("0");
	}
	$arr = array(array("Matrimonial","$tirodi"),array("Advance","$advance"));
	for($ar=0; $ar<count($arr);$ar++)
	{
		if(in_array($arr[$ar][0], $arrrec))
		{
			echo "<option value='". $arr[$ar][0] ."' selected>" . $arr[$ar][1] ."</option>";
		}
		else
		{
			echo "<option value='". $arr[$ar][0] ."'>" . $arr[$ar][1] ."</option>";
		}
	}
	?>
</select>
					</div>
					
					
				</div>
				<div class="row">
					<div class="col-md-6"><?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-6"><?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>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
		  <button type="button" id="btnsubmitall" name="btnsubmitall" class="btn btn-default sideClick1" ><i class="fa fa-arrows" aria-hidden="true"></i> Filter Records</button>
        </div>
	</form>
      </div>
    </div>
</div>
<!-- The Modal Other amount ends here -->
		<!-- DATA EXPORT -->
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> <?php echo e(__('report.global_report')); ?></h3>
<div class='btn-toolbar pull-right'>
    <div class='btn-group'>
		<button type='button' class='btn btn-primary' id="idreload" data-toggle="modal" data-target="#myotheramt" title="Search Record" ><i class="fa fa-search" aria-hidden="true"></i></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 style='width: 35px;'><?php echo e(__('report.slno')); ?></th>
							<th style='width: 50px;'><?php echo e(__('report.billno')); ?></th>
							<th style='width: 100px;'><?php echo e(__('report.transaction_date')); ?></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.income')); ?></th>
							<th style='width: 65px;text-align: right;'><?php echo e(__('report.expense')); ?></th>
							<th style='width: 65px;text-align: right;'><?php echo e(__('mylanguage.adv_amt')); ?></th>		
						</tr>
					</thead>
					<tbody>
			<?php
			$payable = 0;
			$paid = 0;
			$totamt = 0;
			$slno = 1;
			?>
			<?php
			if(isset($data['trn_transaction']))
			{
			?>
						<?php $__currentLoopData = $data['trn_transaction']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trn_val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<?php
if($trn_val->bil_type == "Payment" || $trn_val->bil_type == "Advance"  || $trn_val->bil_type == "sPayment"  || $trn_val->bil_type == "Income"   || $trn_val->bil_type == "Expense" || $trn_val->bil_type == "Loan" || $trn_val->bil_type == "Matrimonial")
{
	if($trn_val->bil_type == "Payment")
	{
		$trn_type = "<font color='green'>" ."ಜಮಾತ್ ಪಾವತಿ" ." (". $trn_val->ftyp_fundtype  .")</font>";
	}
	if($trn_val->bil_type == "Advance")
	{
		$trn_type = "<font color='#1d92af'>" ."ಜಮಾತ್ ಪಾವತಿ (ಮುಂಗಡ ಪಾವತಿ)" . "</font>";
	}
	if($trn_val->bil_type == "sPayment")
	{
		$trn_type = "<font color='purple'>" ."ವಿಶೇಷ ಪಾವತಿ" ." (". $trn_val->ftyp_fundtype  .")". "</font>";
	}
	if($trn_val->bil_type == "Income")
	{
		$trn_type = "<font color='#b3842a'>" . __('report.income') ." (". $trn_val->ftyp_fundtype  .")". "</font>";
	}
	if($trn_val->bil_type == "Expense")
	{
		$trn_type = "<font color='red'>" .__('report.expense') ." (". $trn_val->ftyp_fundtype  .")</font>";
	}
	if($trn_val->bil_type == "Loan")
	{
		$trn_type = "<font color='blue'>" .__('report.loan') ." (". $trn_val->ftyp_fundtype  .")</font>";
	}
	if($trn_val->bil_type == "Matrimonial")
	{
		$trn_type = "<font color='#8c2f26'>" .__('matrimonial.mrg_thirodi') ."</font>";
	}
		echo "<tr>";
		echo "<td>" . $slno . "</td>";
		echo "<td>" . $trn_val->trn_billno . "</td>";

		echo "<td>" . date("d-m-Y",strtotime($trn_val->trn_date))  . "</td>";
		echo "<th style='font-size: 14px;'>". $trn_type . "</th>";
		echo "<td> " ;
		if($trn_val->cst_code != 0)
		{
		echo $trn_val->cst_name . "(" . $trn_val->grd_prefix . $trn_val->cst_code .")<br>";
		}
		echo $trn_val->trn_note . "</td>";
	if($trn_val->trn_type == "Payment" || $trn_val->trn_type == "Advance"  || $trn_val->trn_type == "sPayment"  || $trn_val->trn_type == "Income"  || $trn_val->trn_type == "Loan" || $trn_val->trn_type == "Matrimonial")
	{
		$payable = $payable + $trn_val->bil_amt;
		$totamt = $totamt + $trn_val->bil_amt;
		echo "<th style='text-align: right;'>"  . $trn_val->bil_amt  ."</th>";
	}
	else
	{
		echo "<th style='text-align: right;'></th>";
	}
	if($trn_val->trn_type == "Expense")
	{
		$totamt = $totamt - $trn_val->bil_amt;
		$paid = $paid + $trn_val->bil_amt;
		echo "<th style='text-align: right;'>"  . $trn_val->bil_amt  ."</th>";
	}
	else
	{
		echo "<th style='text-align: right;'></th>";
	}
		echo  "<th style='text-align: right;'>"  . $totamt  ."</th>";
		echo  "</tr>";
		$slno=$slno+1;
}
?>						
						<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>	
					
			<?php
			}
			?>
					
					</tbody>
					<tfoot>
						<tr style='background-color: grey; color: white;'>
							<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="globaltransactionreportprint?<?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>
	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)
{
	//jamath_list specialmember_list income_list expense_list loan_list fdate tdate
	//document.getElementById("btnsubmitall").innerHTML = "<i class='fa fa-arrows fa-spin' aria-hidden='true'></i> Fetching Records";
	var _token = $("input[name='_token']").val();
	var fdate =  $('#fdate').val();
	var tdate =  $('#tdate').val();
	var other_list =  $('#other_list').val();
	var submit =  $('#btnsubmitall').val();
	var url = "";
		
		var jamath_list= document.getElementsByName("jamath_list[]");
		var specialmember_list= document.getElementsByName("specialmember_list[]");
		var income_list= document.getElementsByName("income_list[]");
		var expense_list= document.getElementsByName("expense_list[]");
		var loan_list= document.getElementsByName("loan_list[]");
		var other_list= document.getElementsByName("other_list[]");
		
		var jamath_list = $("#jamath_list option:selected");
		jamath_list.each( function () {
			//message += $( this).val() + " " + $(this).text() + "\n";
			url = url + "&arrjamath_list[]="+$(this).val();
		});
		var specialmember_list = $("#specialmember_list option:selected");
		var message = "";
		specialmember_list.each( function () {
			url = url + "&arrspecialmember_list[]="+$(this).val();
		});		
		var income_list = $("#income_list option:selected");
		var message = "";
		income_list.each( function () {
			url = url + "&arrincome_list[]="+$(this).val();
		});		
		var expense_list = $("#expense_list option:selected");
		var message = "";
		expense_list.each( function () {
			url = url + "&arrexpense_list[]="+$(this).val();
		});		
		var loan_list = $("#loan_list option:selected");
		var message = "";
		loan_list.each( function () {
			url = url + "&arrloan_list[]="+$(this).val();
		});
		var other_list = $("#other_list option:selected");
		var message = "";
		other_list.each( function () {
			url = url + "&arrother_list[]="+$(this).val();
		});
		
		/*
		$.ajax({
			url: "globaltransactionreport",
			type:'POST',
			dataType: 'json',
    //cache : false,
	//processData: false,
			data: {_token:_token,arrjamath_list:arrjamath_list, arrspecialmember_list:arrspecialmember_list, arrincome_list:arrincome_list, arrexpense_list:arrexpense_list, arrloan_list:arrloan_list, fdate:fdate, tdate:tdate,submit:submit},
			success: function(data)
			{
				$('#sideMenu').html(data);
				//alert(data['trn_transaction']);
				//document.getElementById("btnsubmitall").innerHTML = "<i class='fa fa-arrows' aria-hidden='true'></i> Filter Records";
			}
		});
		*/
	$('#myotheramt').modal('toggle');
	url = 'globaltransactionreport?fdate='+fdate + '&tdate='+tdate+'&submit=submit'+url
	//alert(url);
	$('#sideMenu').load(url);
	e.preventDefault();
});
$(document).ready( function () {
    $('#mydatatable').DataTable({
		"sDom": '<"H"lfrp>t<"F"ip>',
	});
} );
</script>