

<?php $__env->startSection('content'); ?>
<style type="text/css">

</style>

<div class="row">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-heading">
			  <span class="panel-title" ><?php echo e(_lang('Student Ledger')); ?></span>
			  	<div class="row" style="margin-top: 4px;">
					<div class="col-md-3">
						<select id="student_id" class="form-control select2">
						   <option value="0"><?php echo e(_lang('Select Student')); ?></option>
							<?php $__currentLoopData = $students; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
							<option value="<?php echo e($data->id); ?>" <?php if($data->id ==$student_id): ?> selected <?php endif; ?>><?php echo e($data->register_no); ?>-<?php echo e($data->first_name); ?>-<?php echo e($data->section_name); ?></option>
							<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
						</select>
					</div>
					<div class="col-md-2">
						<select id="status" class="form-control select2">
						   	<option value="All" <?php if($status=='All'): ?> selected <?php endif; ?>><?php echo e(_lang('All Status')); ?></option>
							<option value="Paid" <?php if($status=='Paid'): ?> selected <?php endif; ?>>Paid</option>
							<option value="Unpaid" <?php if($status=='Unpaid'): ?> selected <?php endif; ?>>Unpaid</option>
						</select>
					</div>
					<div class="col-md-1">
			  			<span class="btn btn-danger btn-sm" style="margin-left: 7px;margin-top: 3px;" onclick="showClass();"><?php echo e(_lang('View Result')); ?></span>
					</div>

					<div class="col-md-6">
					    <span class="btn btn-primary pull-right hand" style="margin-top:3px;margin-right:10px;background: #e74c3c;color: #fff;border:0px;"><?php echo e(_lang('Blance')); ?> : <?php echo e($total_blance); ?></span>
						<?php if($status !='Paid'): ?>
					    <span class="btn btn-warning pull-right hand d-none fee_ledger_button" id="fee_bill_button" style="margin-top:3px;margin-right:10px;"><?php echo e(_lang('Print Fee Bill')); ?></span>
					    <?php endif; ?>
						<?php if($status !='Unpaid'): ?>
					    <span class="btn btn-success pull-right hand d-none fee_ledger_button" id="pay_sllip_button" style="margin-top:3px;margin-right:10px;"><?php echo e(_lang('Print Pay Sllip')); ?></span>
					    <?php endif; ?>
					</div>
				</div>

				
			</div>

			<div class="panel-body">
			<?php if(count($invoices)>0): ?>
			  	<div style="max-height: 500px;overflow-y: scroll;">
					<table class="table table-bordered">
						<thead>
						  <tr>
							<th>
								<div style="display: inline-flex;">
	                                <input type="checkbox" class="check-all" />
	                                <div>
	                                    <label></label>
	                                </div>
	                            </div>
	                        </th>
							<th>Inv#</th>
							<th class="text-center"><?php echo e(_lang('Due Date')); ?></th>
							<th class="text-center"><?php echo e(_lang('Payment Date')); ?></th>
							<th><?php echo e(_lang('Status')); ?></th>
							<th class="text-right"><?php echo e(_lang('Total')); ?></th>
							<th class="text-right"><?php echo e(_lang('Paid')); ?></th>
							<th class="text-right"><?php echo e(_lang('Due')); ?></th>
				        	<?php if(count($fees)>0): ?>
				        	<?php $__currentLoopData = $fees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
				        	<th class="text-right"><?php echo e($fee->fee_type); ?></th>
				        	<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
				        	<?php endif; ?>
						  </tr>
						</thead>
						<tbody>
						  <?php $__currentLoopData = $invoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $invoice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
						  <tr id="row_<?php echo e($invoice->id); ?>">
								<td>
									<div style="display: inline-flex;">
	                                    <input type="checkbox" class="check-single" name="invoice_id[]" data-class="#row_<?php echo e($invoice->id); ?>" value="<?php echo e($invoice->id); ?>" data-student_id="<?php echo e($invoice->student_id); ?>"/>
	                                    <div>
	                                        <label></label>
	                                    </div>
	                                </div>								
								</td>
								<td>
									<?php if($invoice->status=="Paid" || $invoice->paid>0): ?>
									<a href="<?php echo e(url('invoices/feebill/'.$invoice->id.'?type=pay_sllip')); ?>" target="_blank" title="Print"><?php echo e($invoice->id); ?></a>
									<?php else: ?>
									<a href="<?php echo e(url('invoices/feebill/'.$invoice->id.'?type=fee_bill')); ?>" target="_blank" title="Print"><?php echo e($invoice->id); ?></a>
									<?php endif; ?>
								</td>
								<td class="text-center"><?php echo e(date('d-M-Y', strtotime($invoice->due_date))); ?></td>
								<td class="text-center">
									<?php if($invoice->payment_date): ?>
									<?php echo e(date('d-M-Y', strtotime($invoice->payment_date))); ?>

									<?php else: ?>
									--
									<?php endif; ?>
								</td>
								<td><?php echo $invoice->status=="Paid" ? '<i class="fa fa-circle paid"></i>'.$invoice->status : '<i class="fa fa-circle unpaid"></i>'.$invoice->status; ?></td>
								<td class="text-right"><?php echo e($invoice->total); ?></td>
								<td class="text-right"><?php echo e($invoice->paid); ?></td>
								<td class="text-right"><?php echo e($invoice->total - $invoice->paid); ?></td>
								<?php if(count($fees)>0): ?>
				                <?php $total = 0; ?>
						        <?php $__currentLoopData = $fees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
						        	<?php if(count($invoice->invoice_item)>0): ?>

							        	<?php $item_price=0; ?>
							        	<?php $__currentLoopData = $invoice->invoice_item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
								        	<?php if($item->fee_id == $fee->id): ?>
								        	<?php $item_price = ($item->amount - $item->discount); ?>
								        	<?php endif; ?>
							        	<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
							        	<?php if(!empty($item_price)): ?>
				            			<td class="text-right"><?php echo e($item_price); ?></td>
							        	<?php else: ?>
							        	<td class="text-right">0</td>
							        	<?php endif; ?>
						        	<?php else: ?>
						        	<td class="text-right">0</td>

						        	<?php endif; ?>
					        	<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
					        	<?php endif; ?>
						  </tr>
						  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
						</tbody>
				  	</table>
				</div>
		  	<?php else: ?>
		  		<p class="text-center text-danger">Data not found!</p>
		  	<?php endif; ?>
			</div>
		</div>
	</div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js-script'); ?>
<script>
	$('.check-all').on('change', function(){
		$('.check-single').prop('checked', $(this).prop('checked'));
        fee_ledger();
    });
	$('.check-single').on('change', function(){
        fee_ledger();
    });
	$('.allReceiptDate').on('change', function(){
        var allDate = $(this).val();
        $('.receipt_date_input').val(allDate);
    });

    var checked_ids=[];
    var fee_bill_url=null;
    var pay_sllip_url=null;
	function fee_ledger() {
		var selected=0;
        $('.check-single').each(function(){
            if($(this).prop("checked")) ++selected;
        });
        if(selected) $('.fee_ledger_button').removeClass('d-none');
        else $('.fee_ledger_button').addClass('d-none');

        var checkbox_ids=[];

        $('.check-single').each(function(){

            var id=$(this).val();
            var student_id=$(this).data('student_id');
            var status=0;

            if($(this).prop('checked')) status=1;

            checkbox_ids.push({
                id: id,
                student_id: student_id,
                status: status
            });

        });
        checked_ids=[];
        same_student_id=[];
        checkbox_ids.filter(function (el) {
          if (el.status) {
            checked_ids.push(el.id);
            same_student_id.push(el.student_id);
            
          }
        });
        if(same_student_id.length >0 && same_student_id.every( g => g === same_student_id[0])){
            $('.fee_ledger_button').removeClass('d-none');
        }else{
        	$('.fee_ledger_button').addClass('d-none');
        }

        fee_bill_url="<?php echo e(route('student_ledger_print')); ?>?type=fee_bill&invoice_id="+checked_ids;
        pay_sllip_url="<?php echo e(route('student_ledger_print')); ?>?type=pay_sllip&invoice_id="+checked_ids;
	}
	function getData(val) {
		var _token=$('input[name=_token]').val();
		var class_id=$('select[name=class_id]').val();
		$.ajax({
			type: "POST",
			url: "<?php echo e(url('sections/section')); ?>",
			data:{_token:_token,class_id:class_id,all_section:'All'},
			beforeSend: function(){
				$("#preloader").css("display","block");
			},success: function(sections){
				$("#preloader").css("display","none");
				$('select[name=section_id]').html(sections);				
			}
		});
	}
	function showClass(){
		var status = $('#status option:selected').val();
		var student_id = $('#student_id option:selected').val();
		window.location = "<?php echo url('invoices/student/ledger') ?>/"+student_id+"/"+status;
	}

	$('#fee_bill_button').on('click', function(){
		window.open(fee_bill_url,'_blank');
    });
	$('#pay_sllip_button').on('click', function(){
		window.open(pay_sllip_url,'_blank');
    });
</script>
<?php $__env->stopSection(); ?>



<?php echo $__env->make('layouts.backend', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/hostelmanager/public_html/test.hostelmanager.pk/resources/views/backend/invoice/student_ledger.blade.php ENDPATH**/ ?>