<form method="post"  autocomplete="off" class="formSubmission" action="<?php echo e(route('student_payments.store')); ?>" enctype="multipart/form-data" target="_blank">
	<?php echo e(csrf_field()); ?>

						
	<input type="hidden" class="form-control" name="invoice_id" value="<?php echo e($invoice_id); ?>" required>
    <?php $currency = get_option('currency_symbol'); ?>
	
	<?php if(!empty($history)): ?>
	<div class="col-md-12">
		<table class="table table-bordered">
		    <thead>
			   <th colspan="4" class="text-center"><?php echo e(_lang('Payment History')); ?></th>
			</thead>
			<thead>
			   <th><?php echo e(_lang('Date')); ?></th>
			   <th><?php echo e(_lang('Amount')); ?></th>
			   <th><?php echo e(_lang('Note')); ?></th>
			   <th><?php echo e(_lang('payment Head')); ?></th>
			</thead>
			<tbody>
			<?php $__currentLoopData = $history; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
			   <tr>
			     <td><?php echo e($payment->date); ?></td>
			     <td><?php echo e($currency." ".$payment->amount); ?></td>
			     <td><?php echo e($payment->note); ?></td>
				 <td> Income </td>
			   </tr>
			<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
			</tbody>
		</table>
	</div>	
	<?php endif; ?>
	<?php if($invoice->status=="Unpaid"): ?>
	<div class="col-md-6">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Student Total Balance')." ".$currency); ?></label>						
		<input type="text" class="form-control" value="<?php echo e(\App\Invoice::where('student_id',$invoice->student_id)->sum('total') - \App\Invoice::where('student_id',$invoice->student_id)->sum('paid')); ?>" readOnly="true">
	  </div>
	</div>
	<div class="col-md-6">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Total Amount')." ".$currency); ?></label>						
		<input type="text" class="form-control" value="<?php echo e($invoice->total); ?>" readOnly="true">
	  </div>
	</div>
	
	<div class="col-md-6">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Total Paid')." ".$currency); ?></label>						
		<input type="text" class="form-control" value="<?php echo e($invoice->paid); ?>" readOnly="true">
	  </div>
	</div>

	<div class="col-md-6">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Payable Amount')." ".$currency); ?></label>	
		<input type="number" class="form-control float-field" readOnly="true" name="payable" value="<?php echo e($invoice->total-$invoice->paid); ?>" max="<?php echo e($invoice->total-$invoice->paid); ?>" required>
	 </div>
	</div>
	<div class="col-md-6">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Date')); ?></label>						
		<input type="text" class="form-control datepicker" name="date" value="<?php echo e($payment_date); ?>" required>
	  </div>
	</div>
	<div class="col-md-6">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Payment Method')); ?></label>						
		<select class="form-control select2" name="account_id">
				<?php $__currentLoopData = $accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
				<option value="<?php echo e($account['id']); ?>"><?php echo e($account['account_name']); ?></option>
				<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
			</select>
	  </div>
	</div>
	<!-- <div class="col-md-6">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Income Type')); ?></label>						
		<select class="form-control select2" name="chart_id" required>
			 <?php $__currentLoopData = $invoiceItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $id => $fee_type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <option value="<?php echo e($id); ?>" <?php echo e(old('chart_id') == $id ? 'selected' : ''); ?>>
            <?php echo e($fee_type); ?>

        </option>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
		</select>
	  </div>
	</div> --> 
	<?php //print_r($invoiceItems); ?>
	<?php $__currentLoopData = $invoiceItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <div class="col-md-6">
        <div class="form-group">
            <?php echo get_fee_selectbox('select2', $item->fee_id); ?>

        </div>
    </div> 
    <div class="col-md-6">
        <div class="form-group">
            <?php
                // Get total amount already paid for this specific fee item
                $paidAmount = \App\Transaction::where('chart_id', $item->fee_id)
                                ->where('invoice_id', $invoice->id)
                                ->sum('amount');

                // Calculate the remaining amount
                $remainingAmount = $item->amount - $paidAmount;
            ?>

            <input 
                type="number" 
                class="form-control amount" 
                name="amount[]" 
                value="<?php echo e($remainingAmount); ?>" 
                max="<?php echo e($remainingAmount); ?>" 
                min="0"
                required>
        </div>
    </div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

	<input type="hidden" name="trans_type" value="income">
	<input type="hidden" name="trans_source_type" value="Student">
	<input type="hidden" name="school_id" value="<?php echo e($invoice->school_id); ?>">
	<input type="hidden" name="dr_cr" value="cr">

	<div class="col-md-6">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Receipt No')); ?></label>						
		<input type="text" class="form-control" name="receipt_no" value="<?php echo e($invoice_paid); ?>"> 	
	  </div>
	</div>
	<div class="col-md-12">
	  <div class="form-group">
		<label class="control-label"><?php echo e(_lang('Note')); ?></label>						
		<textarea class="form-control" name="note"><?php echo e(old('note')); ?></textarea>
	  </div>
	</div>

				
	<div class="col-md-12">
	  <div class="form-group">
		<button type="submit" class="btn btn-primary save-print" name= "save_print" value="save_print"><?php echo e(_lang(' Print and Save')); ?></button>

		

		<button type="submit" class="btn btn-primary" name="save_back" value="save_back"><?php echo e(_lang('Save')); ?></button>

	</div>
	</div>
	<?php endif; ?>
</form>
<script>
	$('.formSubmission').on('submit', function(e) {
		setTimeout(function() {
			$('#main_modal').modal('hide');
		}, 1000);
	});

	$('.save-pdf ').on('click', function(){
		setTimeout(() => {
			
			$("#preloader").css("display", "block");
            window.location.href = "<?php echo e(url('/invoices')); ?>";
        }, 2000); // delay to ensure download is triggered
	})
	</script><?php /**PATH /home/hostelmanager/public_html/test.hostelmanager.pk/resources/views/backend/student_payment/modal/create.blade.php ENDPATH**/ ?>