IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/resources/views/schools/buses/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/resources/views/schools/buses/busfeedetails_royal.blade.php

@extends('schools.school_layout')
@section('content')
<div role="tabpanel" class="tab-pane in active" id="details" aria-expanded="true">
    <div class="card" id="details">
        <div class="body">                                
            <div class="row">
                <div class="col-sm-6 col-sm-offset-1">
                    <address>
                        <strong> Student Name : </strong>{{$student->firstName}} {{$student->middleName}} {{$student->lastName}}<br>
                        <strong> Father Name : </strong>{{$student->father_fname}} {{$student->father_lname or ''}}<br>
                        <strong> Mobile : </strong>{{$student->father_mobile}}<br>
                        <strong> Class : </strong>{{$student->classM->className}}<br>
                        <strong> Section : </strong>{{$student->section->sectionName}}<br>
                        <strong> Ec No. : </strong>{{$student->ecNo}}<br> <input type="hidden" value="{{json_encode($sessionPending)}}"/>
                        <ul>
                        @foreach($sessionPending as $key => $value)
                        @if($value > 0)
                        <?php $isCollectionAllowed = "Y"; ?>
                        <li style="color:red"><u>Note</u>: Student has an outstanding amount of Rs. {{$value}} for session {{$key}}.</li>
                        @endif
                        @endforeach
                        </ul>
                    </address>
                </div>
            </div>

            @if($plan == '')
            <div class="row">
                <div class="col-sm-6 col-sm-offset-1">
                    <address>

                        <form action="{{url('school/busfees/'.$stdtransport->idStdTransport.'/details')}}" method= "get">
                            
                                <div class="row clearfix">
                                    <div class="col-sm-4 form-control-label">
                                        <label for="classname"><strong>Payable Mode </strong></label>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                        <input type="radio" id="paymode1" name="paymode" value="Plan A" <?php if($type == "Plan A") echo 'checked';?>>
                                        <label for="paymode1">Fees in Full Payment</label><br>
                                        <input type="radio" id="paymode2" name="paymode" value="Plan B" <?php if($type == "Plan B") echo 'checked';?>>
                                        <label for="paymode2">Fees in Terms</label> <br>  
                                        <input type="radio" id="paymode3" name="paymode" value="Plan C" <?php if($type == "Plan C") echo 'checked';?>>
                                        <label for="paymode3">Fees in Installments</label> <br>  
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                    <input class="btn btn-primary btn-round" type="submit" value="View" style="background-color:black;color:white;"/>
                                </div>
                        </form>

                    </address>
                </div>
            </div>
            @endif
            <div class="mt-40"></div>
            <div class="row">
               <div class="col-sm-12">
                   <div class="table-responsive">
                       {!! Form::open(['url' => 'school/busfees', 'class' => 'form-horizontal','id'=>'feesubmission']) !!}
                       <input type="hidden" name="idStudent" value="{{$student->idStudent}}">
                       <input type="hidden" name="idFinancialYear" value="{{Session::get('idFinancialYear')}}">
                       <table class="table table-hover">
                           <thead>
                               <tr>
                                   <th></th>
                                   <th style="width:60px;">Due Date</th>
                                   <th>Particular</th>
                                   <th>Amount</th>
                                   <th>Discount</th>
                                   <th>Fine</th>
                                   <th>Fine Collected</th>
                                   <th>Amount Collected</th>
                                   <th>Status</th>
                               </tr>
                           </thead>
                           <tbody>
                                <?php 
                                    $paidFine=0; $disableHeader = true; $totalPaid = 0;$totalAmount = 0;  $accessAmount = 0;$balance = 0;
                                    $outstanding = DB::table('student_transaction_outstanding')->where('idStudent',$student->idStudent)->first();
                                    if($outstanding != null){
                                        if(Session::get('idFinancialYear') != $outstanding->idFinancialYear)
                                        $outstanding = null;
                                    }
                                ?>   
                                
                                @foreach($feeData as $var)
                                @php 
                                $paidFine = $paidFine + $var['transaction']['paid_fine'];
                                $totalPaid = $totalPaid + $var['transaction']['paid'];
                                $balance = $balance + $var['balance'];
                                $accessAmount = $accessAmount + $var['extra_amount'];
                                $totalAmount = $totalAmount + $var['total_amount'];
                                @endphp
                                <tr>
                                    <td>
                                        @if($var['isEnabled'] == true && $var['isPaid'] != "Paid")
                                        <div class="checkbox-inline" style="padding-left:10px;">
                                            @if($disableHeader)
                                            <input type="checkbox" name="selectedHeaders[]" value="{{$var['idBusFeehead']}}" class="feeclass">
                                            <?php $disableHeader = false; ?>
                                            @endif
                                        </div>
                                        @endif
                                    </td>
                                    <td>{{ Carbon\Carbon::parse($var['toDate'])->format('d-m-Y') }}</td>
                                    <td>
                                    {{$var['feeheadName']}}
                                    <input type="hidden" name='feeheads[{{$var['idBusFeehead']}}][idBusFeehead]' value="{{$var['idBusFeehead']}}">
                                    </td>
                                    <td class='amt'>
                                    {{$var['amount']}}
                                    <input type="hidden" name='feeheads[{{$var['idBusFeehead']}}][famount]' value="{{$var['amount']}}">
                                    </td>
                                    <td class="discount">
                                    {{$var['discount']}}
                                    <input type="hidden" name='feeheads[{{$var['idBusFeehead']}}][discount]' value="{{$var['discount']}}">
                                    </td>
                                    <td class="fine">
                                    {{$var['fine']}}
                                    <input type="hidden" name='feeheads[{{$var['idBusFeehead']}}][fine]' value="{{$var['fine']}} ">
                                    </td>
                                    <td>{{$var['transaction']['paid_fine']}}</td>
                                    <td>{{$var['transaction']['paid']}}</td>
                                    <td>
                                    @if($var['isPaid'] == "Upcoming")
                                    <span class="badge badge-info">UPCOMING</span>
                                    @else
                                        @if($var['isPaid'] == "Paid")
                                        <span class="badge badge-success">Paid </span>
                                        @else
                                        @if($var['isPaid'] == "Due")
                                        <span class="badge badge-danger">DUE</span>
                                        @else
                                        <span class="badge badge-info">Partial-Paid</span>
                                        @endif
                                        @endif
                                    @endif    
                                    </td>
                                </tr>       
                                @endforeach
                               
                                @if($outstanding != null)
                                <tr>
                                   <td>
                                        <div class="checkbox-inline" style="padding-left:10px;">
                                            @if($outstanding->isPaid == 0)
                                            <input type="checkbox" name="outstanding" value="{{$outstanding->idOutstanding}}" class="feeclass">
                                            @endif
                                        </div>
                                    </td>
                                   <td>Current Year</td>
                                   <td>
                                      Outstanding Amount
                                   </td>
                                   <td class='amt'>
                                       {{$outstanding->amount}}
                                   </td>
                                   <td class="discount">
                                      0.00
                                   </td>
                                   <td class="fine">
                                        0.00
                                   </td>
                                   <td></td>
                                   <td></td>
                                   <td>
                                        @if($outstanding->isPaid == 1)
                                            <span class="badge badge-success">Paid </span>
                                        @else
                                            <span class="badge badge-danger">DUE</span>
                                       @endif
                                    </td>
                               </tr>
                                @endif
                           </tbody>
                       </table>
                   </div>
                </div>
                <?php 
                    $additional = 0;
                    $paidFine = 0;
                ?>
                <div class="row col-sm-12">
                    <div class="table-responsive col-sm-6">
                        <h5>Full Paid Receipt</h5>
                        <table class="table table-hover">
                               <thead>
                                   <tr>
                                       <th>Date</th>
                                       <th>Header</th>
                                       <th>Total Paid</th>
                                       <th>Fine</th>
                                       <th>Receipt No & Mode</th>
                                       <th>Print</th>
                                   </tr>
                               </thead>
                               <tbody>
                                   @foreach($paidfees as $var)
                                   <?php $additional = $additional + $var->additionalAmount;
                                          $chqPenalty =0;
                                          foreach($var->details as $det) {
                                            $chqPenalty =  $chqPenalty + $det->chqPenalty;
                                          }
                                          $excessAmount = 0;
                                          $argc =  DB::table('bus_excess_transaction')->where('idBusTransaction',$var->idBusTransaction)->where('isActive','Y')->first();
                                          if($argc != null){
                                            $excessAmount = $argc->excessAmount;
                                          }
                                    ?>
                                    <tr>
                                       <td>{{$var->paymentDate}}</td>
                                       @php 
                                        $headers = \App\BusTransactionDetail::where('idBusTransaction', $var->idBusTransaction)->where(function($query) {
                                                    $query->whereNull('status');
                                                    $query->orWhere('status', '=', 'In-Process');
                                                    $query->orWhere('status', '=', 'Cleared');
                                                    $query->orWhere('status', '=', 'Success');
                                                    $query->orWhere('status', '=', 'Bounced');
                                                })->pluck('idBusFeehead')->toArray();
                                        $headerName =  \DB::table('busfeeheads')->whereIn('idBusFeehead',$headers)->pluck('feeheadName')->toArray();      
                                       @endphp
                                       <td>
                                        @foreach( $headerName as $key =>$value)
                                        {{$value}}<br>
                                        @endforeach
                                       </td>
                                       @if(isset($var->outstandingAmount))
                                       <td>{{$var->totalPaid + $var->outstandingAmount + $var->additionalAmount + $chqPenalty + $excessAmount}}</td>
                                       @else
                                       <td>{{$var->totalPaid + $var->additionalAmount + $chqPenalty + $excessAmount}}</td>
                                       @endif
                                       <td>{{$var->fine}}<?php $paidFine = $paidFine+ $var->fine;?></td>
                                       <td>{{$var->receiptNo}} - {{$var->paymentMode}}</td>
                                       @if($var->status == 'Cleared' || $var->status == null || $var->status == 'Success')
                                       <td><a href="{{url('school/busfees/'.$var->idBusTransaction.'/print')}}" target="_blank" class="btn btn-sm btn-info">Print</a></td>
                                       @elseif($var->status == 'Bounced')
                                       <td><span class="badge badge-danger">Bounced</span></td>
                                       @elseif($student->idSchool == 25)
                                       <td><a href="{{url('school/busfees/'.$var->idBusTransaction.'/print')}}" target="_blank" class="btn btn-sm btn-info">Print</a></td>
                                       @endif
                                       
                                   </tr>
                                   @endforeach
                                </tbody>
                        </table>
                    </div>
                    <div class="table-responsive col-sm-6">
                        <h5>Lesser Paid Receipt</h5>
                        <p><u>Note</u> : Fine is included in total paid</p>
                        <table class="table table-hover">
                               <thead>
                                   <tr>
                                       <th>Date</th>
                                       <th>Header</th>
                                       <th>Total Paid</th>
                                       <th>Fine</th>
                                       <th>Payment Mode</th>
                                       <th>Print</th>
                                   </tr>
                               </thead>
                               <tbody>
                                   @foreach($lesserfees as $var)
                                   <?php 
                                   $additional = $additional + $var->additionalAmount; 
                                   $details = \App\BusLesserTransaction::selectRaw('SUM(bus_lesser_transaction.fine) as fine')->where('idBusLesserTransaction',$var->idBusLesserTransaction)->first();
                                   ?>
                                    <tr>
                                       <td>{{$var->paymentDate}}</td>
                                       @php 
                                        $headers = DB::table('bus_lesser_transaction_details')->where('idBusLesserTransaction', $var->idBusLesserTransaction)->where(function($query) {
                                                    $query->whereNull('status');
                                                    $query->orWhere('status', '=', 'In-Process');
                                                    $query->orWhere('status', '=', 'Cleared');
                                                    $query->orWhere('status', '=', 'Success');
                                                    $query->orWhere('status', '=', 'Bounced');
                                                })->pluck('idBusFeehead')->toArray();
                                        $headerName = \DB::table('busfeeheads')->whereIn('idBusFeehead',$headers)->pluck('feeheadName')->toArray();      
                                       @endphp
                                       <td>
                                        @foreach( $headerName as $key =>$value)
                                        {{$value}}<br>
                                        @endforeach
                                       </td>
                                       <td>{{$var->totalPaid + $var->additionalAmount + $var->chqPenalty}}</td>
                                       <td><?php if(isset($details->fine))
                                       {
                                        $paidFine = $paidFine+ $details->fine;
                                        echo $details->fine;
                                       }?></td>
                                       <td>{{$var->paymentMode}}</td>
                                       <td>@if($var->status == 'Cleared' || $var->status == null || $var->status == 'In-Process' )
                                        <a href="{{url('school/busfees/lessamt/'.$var->idBusLesserTransaction.'/print')}}" target="_blank" class="btn btn-sm btn-info">Print</a>
                                       @endif
                                       @if($var->status == 'Bounced')
                                       <span class="badge badge-danger">Bounced</span>
                                       @endif</td>
                                   </tr>
                                   @endforeach
                                </tbody>
                        </table>
                    </div>
                    <div class="col-sm-6"></div>
                    <div class="table-responsive col-sm-6 mt-40">
                    <h5>Reversal Receipt</h5>
                        <table class="table table-hover">
                               <thead>
                                   <tr>
                                       <th>Date</th>
                                       <th>Total Paid</th>
                                       <th>Fine</th>
                                       <th>Payment Mode</th>
                                       <th>Print</th>
                                   </tr>
                               </thead>
                               <tbody>
                                   <?php
                                        $reversal = DB::table('student_rollback_transaction_bus')
                                        ->where('student_rollback_transaction_bus.idStudent', '=', $student->idStudent)
                                        ->where('student_rollback_transaction_bus.idFinancialYear', '=', Session::get('idFinancialYear'))
                                        ->get();
                                   ?>
                                   @foreach($reversal as $var)
                                    <tr>
                                       <td>{{\Carbon\Carbon::parse($var->paymentDate)->format('d-m-Y')}}</td>
                                       <td>{{$var->totalPaid}}</td>
                                       <td>{{$var->fine}}</td>
                                       <td>{{$var->paymentMode}}</td>
                                       <td><span class="badge badge-danger">{{$var->status}}</span></td>
                                   </tr>
                                   @endforeach
                                </tbody>
                        </table>
                    </div>

                </div>
               
                
            </div>

            <hr>
            <div class="row">
                <div class="col-md-5">
                        <div class="row clearfix">
                            <div class="col-sm-5 form-control-label">
                                <label for="classname">Payment Date</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <input type="text"  name="paymentDate" class="form-control datepicker" id="payment_date">
                                </div>
                            </div>
                        </div>
                        <div class="row clearfix">
                            <div class="col-sm-5 form-control-label">
                                <label for="classname">Payable Amount</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                            @if(isset($prevaccess_fee->excessAmount))
                            @if($prevaccess_fee->excessAmount > 0)
                            <label id="access_note"><b>Excess Amount Available: </b>{{$prevaccess_fee->excessAmount}} </label>
                            @endif
                            @endif
                            
                            
                                    <input type="text" name="payable" class="form-control payableAmount" readonly="readonly"  style="color: black;font-size: 1.2em;">
                                </div>
                            </div>
                        </div>
                        <div class="row clearfix">
                            <div class="col-sm-5 form-control-label">
                                <label for="classname">Pay Amount</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <input type="text" name="totalPaid" class="form-control" onkeypress = 'return onlyNumbersandSpecialChar(event)'>
                                    @if ($errors->has('totalPaid'))
                                    <label id="minmaxlength-error" class="error" for="minmaxlength">
                                        <strong>{{ $errors->first('totalPaid') }}</strong>
                                    </label>
                                    @endif
                                    <span id='totalerror'></span>
                                </div>
                            </div>
                        </div>
                        @if(auth()->user()->idSchool == 25)
                        <div class="row clearfix">
                            <div class="col-sm-5 form-control-label">
                                <label for="classname">Additional Amount</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <input type="text" name="additionalAmount" class="form-control" onkeypress = 'return onlyNumbersandSpecialChar(event)'>
                                    @if ($errors->has('additionalAmount'))
                                    <label id="minmaxlength-error" class="error" for="minmaxlength">
                                        <strong>{{ $errors->first('additionalAmount') }}</strong>
                                    </label>
                                    @endif
                                    <span id='totalerror'></span>
                                </div>
                            </div>
                        </div>
                        <div class="row clearfix">
                            <div class="col-sm-5 form-control-label">
                                <label for="classname">Remarks</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <input type="text" name="remarks" class="form-control">
                                    @if ($errors->has('remarks'))
                                    <label id="minmaxlength-error" class="error" for="minmaxlength">
                                        <strong>{{ $errors->first('remarks') }}</strong>
                                    </label>
                                    @endif
                                    <span id='totalerror'></span>
                                </div>
                            </div>
                        </div>
                        <div class="row clearfix">
                            <div class="col-sm-5 form-control-label">
                                <label for="classname">Bank (Paid To)</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    {!! Form::select('bankName',[''=>'NA','A' => 'Axis Bank','B' => 'NKGSB Bank'],null,['class' => 'form-control show-tick ms']) !!}
                                </div>
                            </div>
                        </div>
                        @endif
                        <div class="row clearfix">
                            <div class="col-sm-5 form-control-label">
                                <label for="classname">Select Payment Mode</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    {!! Form::select('paymentMode',payMode(),null,['class' => 'form-control show-tick ms paymentMode','id'=>'paymode']) !!}
                                </div>
                            </div>
                        </div>
                        <div class="row clearfix cardpayment">
                            <div class="col-sm-5 form-control-label">
                                <label for="classname">CardNo./Trans ID</label>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <input type="text" name="cardNo" class="form-control">
                                    <span id='cardnoerror'></span>
                                </div>
                            </div>
                        </div>

                </div>
                <div class="col-md-6 text-right">
                    <p class="m-b-0"><b>Fee Total: </b><span id='total_fee'></span>
                        <input type="hidden" name="feeTotal" id="feetotal">
                    </p>
                    <p class="m-b-0">
                        <b>Discount: </b>
                        <span  id='total_discount'></span>
                        <input type="hidden" name="discount" id="discounttotal">
                    </p> 
                    <p class="m-b-0">
                        <b>Additional Amount: </b>
                        {{$additional}}
                    </p>    
                    <p class="m-b-0">
                        <b>Fine: </b>
                        <span id='total_fine'></span>
                        <input type="hidden" name="fine" id="finetotal">
                    </p>
                    <p class="m-b-0">
                        <b>Cheque Bounce Penalty: </b>
                        <span id="penaltyAmt"></span>
                         <?php $chqbounce = \App\StudentTransaction::where('idStudent','=',$student->idStudent)
                                ->where('idFinancialYear','=',$student->idFinancialYear)
                                ->where('status','=','Bounced')
                                ->get();
                                
                                $chqPenaltyAmount=0;
                                $chqPenaltyPaid=0;
                                $chqPenaltyUnPaid=0;
                                if(isset($chqbounce)){
                                foreach($chqbounce as $chqFine)
                                    {
                                        if($chqFine->chqFineStatus == 1)
                                        $chqPenaltyPaid=$chqPenaltyPaid+$chqFine->chequeBounceCharge;
                                        else
                                        $chqPenaltyUnPaid=$chqPenaltyUnPaid+$chqFine->chequeBounceCharge;
                                        
                                        $chqPenaltyAmount=$chqPenaltyAmount+$chqFine->chequeBounceCharge;
                                    }
                                }
                            ?>
                            @if(isset($chqbounce))
                            {{$chqPenaltyAmount}}
                            @if($chqPenaltyAmount==0)
                            <span></span>
                            @elseif($chqPenaltyAmount > $chqPenaltyPaid)
                            <span style="color:red"> | {{$chqPenaltyUnPaid}}(Unpaid)</span>
                            @else
                            <span style="color:green">(Paid)</span>
                            @endif
                            @else
                            <span>0.00</span>
                            @endif
                    </p>
                    <p class="m-b-0"><b>Excess Amount : </b>
                            @if(isset($prevaccess_fee->excessAmount))
                            {{$prevaccess_fee->excessAmount + $accessAmount}}
                            @else
                            <span>{{$accessAmount}}</span>
                            @endif
                    </p>
                    <p class="m-b-0"><b>Fine Amount : </b>
                    {{$paidFine}}
                    </p> 
                    <p class="m-b-0"><b>Total Amount : </b> 
                    {{$totalAmount}}
                    </p> 
                    <p class="m-b-0"><b>Total Paid: </b>
                        <span id='total_paid'>
                        {{$totalPaid}}
                        </span>
                    </p>
                    <p class="m-b-0"><b>Balance Amount: </b>           
                        {{$balance}}             
                        <input type="hidden" name="totalBalance" id="totalBalance" value="{{$balance}}">
                    </p>
                </div>
            </div>
            <!--<hr>-->
            <div class="row otherpaymode">
                <div class="col-sm-12">
                    <hr>
                    
                   <div class="row clearfix">
                        <div class="col-sm-3 form-control-label required">
                            <label for="classname">Bank</label>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                {!! Form::select('idBank',banks(),null,['class' => 'form-control show-tick ms select2']) !!}
                                <span id='bankerror'></span>
                            </div>
                        </div>
                        <div class="col-sm-3 form-control-label required">
                            <label for="classname">Cheque No. / DD No.</label>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <input type="text" name="chequeNo" class="form-control">
                                    <span id='chequenoerror'></span>
                            </div>
                        </div>
                    </div>
                    <div class="row clearfix">
                        
                        <div class="col-sm-3 form-control-label required">
                            <label for="classname">Cheque / DD Date</label>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <input type="text" name="chequeDate" class="form-control datepicker">
                                   <span id='chequedateerror'></span>
                            </div>
                        </div>
                        <div class="col-sm-3 form-control-label required">
                            <label for="classname">Amount</label>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <input type="text" name="amount" class="form-control" onkeypress = 'return onlyNumbersandSpecialChar(event)'>
                                <span id='amounterror'></span>
                            </div>
                        </div>
                    </div>
              
<!--                    <h5>Note</h5>
                    <p>Etsy doostang zoodles disqus groupon greplin oooj voxy zoodles, weebly ning heekya handango imeem plugg dopplr jibjab, movity jajah plickers sifteo edmodo ifttt zimbra.</p>-->
                </div>
                
            </div>
            <hr>
            <div class="hidden-print col-md-12 text-right">
                @if(auth()->user()->isSchool == 'N' || isset($_GET['open']))
                <button class="btn btn-primary btn-round" id='submit-btn'>Submit</button>
                @else 
                <p style="color:red"><u>Note</u>: You cannot collect fee as administrator user please make user and use that user login for payment collection.</p>
                @endif
            </div>
        </div>
    </div>
</div>
@stop
@section('script')
<script>
    // Saving form data
@if(auth()->user()->isSchool == 'N' || isset($_GET['open']))
$('#feesubmission').on('submit',function(e){
    var isCash="Cash";
    $.each($(".paymentMode option:selected"), function(){  
            isCash=$(this).val();
            if($(this).val()=='Cheque' || $(this).val() =='DD')
            {
                $('input[name="totalPaid"]').val(parseInt($('input[name="amount"]').val()));
                if(parseInt($('input[name="totalPaid"]').val()) != parseInt($('input[name="amount"]').val()))
                {
                    alert("Amount cannot be less or more than payable amount");
                }
            }
        });
        
    feeheaders = [];
    $("input:checkbox[name='selectedHeaders[]']:checked").each(function () {
            feeheaders.push($(this).val());
    });
    if(feeheaders.length>1 && parseInt($('input[name="totalPaid"]').val()) < parseInt($('input[type=text].payableAmount').val()) && isCash=="Cash")
    {
        alert("Amount cannot be less than payable amount");
    }else{
        
    $.ajaxSetup({
        header:$('meta[name="_token"]').attr('content')
    });
 var formData =  new FormData($('#feesubmission')[0]);
 $("#submit-btn").prop('disabled', true);
    $.ajax({
        type:"POST",
        url: "{{url('school/busfees') }}",
        processData: false,
        contentType: false,
        data:formData,
        dataType: 'json',
        success:function(data){
            if( data[Object.keys(data)[0]] === 'SUCCESS' ){
                $("#submit-btn").prop('disabled', true);
                window.location = "{{url('school/busfees/')}}" + '/'+ {{$stdtransport->idStdTransport}} +'/details';
            }
            else {                  //False Case: With error msg
            $("#msg").html(data);   //$msg is the id of empty msg
            }

        },

        error: function(data){
                    if( data.status === 422 ) {
                        $("#submit-btn").prop('disabled', false);
                        var errors = data.responseJSON.errors;
                        var errorHtml = '<div class="alert alert-danger"><ul>';
                           $('#formerrors').html(errorHtml);
                                if(errors['totalPaid']=== undefined){
                                    $( '#totalerror' ).empty();
                                }else{
                                   errorname = '<span class="help-block"><strong>'+errors['totalPaid']+'</strong></span>';
                                   $( '#totalerror' ).html( errorname );
                                }
                                if(errors['idBank']=== undefined){
                                    $( '#bankerror' ).empty();
                                }else{
                                   errorname = '<span class="help-block"><strong>'+errors['idBank']+'</strong></span>';
                                   $( '#bankerror' ).html( errorname );
                                }
                                if(errors['chequeNo']=== undefined){
                                    $( '#chequenoerror' ).empty();
                                }else{
                                   errorname = '<span class="help-block"><strong>'+errors['chequeNo']+'</strong></span>';
                                   $( '#chequenoerror' ).html( errorname );
                                }
                                if(errors['chequeDate']=== undefined){
                                    $( '#chequedateerror' ).empty();
                                }else{
                                   errorname = '<span class="help-block"><strong>'+errors['chequeDate']+'</strong></span>';
                                   $( '#chequedateerror' ).html( errorname );
                                }
                                if(errors['chequeDate']=== undefined){
                                    $( '#chequedateerror' ).empty();
                                }else{
                                   errorname = '<span class="help-block"><strong>'+errors['chequeDate']+'</strong></span>';
                                   $( '#chequedateerror' ).html( errorname );
                                }
                                if(errors['amount']=== undefined){
                                    $( '#amounterror' ).empty();
                                }else{
                                   errorname = '<span class="help-block"><strong>'+errors['amount']+'</strong></span>';
                                   $( '#amounterror' ).html( errorname );
                                }
                                if(errors['cardNo']=== undefined){
                                    $( '#cardnoerror' ).empty();
                                }else{
                                   errorname = '<span class="help-block"><strong>'+errors['cardNo']+'</strong></span>';
                                   $( '#cardnoerror' ).html( errorname );
                                }
                                
                    }
            }
    });
  }
    return false;
});
@endif
$(document).ready(function(){
 @if(isset($isPending))
 @if($isPending == 1)
 alert("Fees from previous financial year is pending.");
 @endif
 @endif
 $('.otherpaymode').hide(); 
 $('.cardpayment').hide();
 $('#paymode').change(function() {
        var val = $(this).val();
        if((val == 'Cheque')){
           $('.cardpayment').hide();
           $('.otherpaymode').show();
        }else if(val == 'DD'){
           $('.cardpayment').hide();
           $('.otherpaymode').show();
        }else if(val == 'Card'){
           $('.cardpayment').show();
           $('.otherpaymode').hide();
        }else{
            $('.otherpaymode').hide();
            $('.cardpayment').hide();
        }
    });
});
var feeheaderIds = [];
$('.feeclass').change(function() {
    feeheaderIds = [];
    var outstanding = 0;
    if ($("input:checkbox[name='outstanding']").is(':checked')){
        outstanding = $("input:checkbox[name='outstanding']").val();
    }
    $("input:checkbox[name='selectedHeaders[]']:checked").each(function () {
            feeheaderIds.push($(this).val());
    });
    if(feeheaderIds.length > 0)
    $.ajax({
            url: "{{url('/school/busfeeheaders') }}"+'/' +feeheaderIds + "/students/"+{{$student->idStudent}}+"?payday="+$("#payment_date").val()+"&outstanding="+outstanding,
            type: "GET",
            dataType: "json",
                success:function(data) {
                     $('input[type=text].payableAmount').val(data);
                }
            });
    else if(outstanding > 0)
    $.ajax({
            url: "{{url('/school/busfeeheaders/none/students') }}/"+{{$student->idStudent}}+"?payday="+$("#payment_date").val()+"&outstanding="+outstanding,
            type: "GET",
            dataType: "json",
                success:function(data) {
                     $('input[type=text].payableAmount').val(data);
                }
            });
    else $('input[type=text].payableAmount').val(" ");      
});
var sum = 0;
var discount = 0;
var fine = 0;
// iterate through each td based on class and add the values
$(".amt").each(function() {

    var value = $(this).text();
    // add only if the value is number
    if(!isNaN(value) && value.length != 0) {
        sum += parseFloat(value);
    }
    $('#total_fee').text(sum.toFixed(2));
    
});

$(".discount").each(function() {

    var value = Number($(this).text());
    // add only if the value is number
    if(!isNaN(value) && value.length != 0) {
        discount += parseFloat(value);
    }
   $('#total_discount').text(discount.toFixed(2));
});
$(".fine").each(function() {

    var value = Number($(this).text());
    // add only if the value is number
    if(!isNaN(value) && value.length != 0) {
        fine += parseFloat(value);
    }
    $('#total_fine').text(fine.toFixed(2));
});
 var ftotal = parseFloat($('#total_fee').text()); 
 var tdiscount = parseFloat($('#total_discount').text());
 var tfine = parseFloat($('#total_fine').text());
 var paidtot = parseFloat($('#total_paid').text());
 var fbalance = parseFloat(ftotal+paidtot);
 $('#total_balance').text(fbalance.toFixed(2));
 var feetotal = parseFloat(ftotal);
 $('#feetotal').val(feetotal.toFixed(2));
 
 var distotal = parseFloat($('#total_discount').text()); 
 $('#discounttotal').val(distotal.toFixed(2));

 var tf = parseFloat($('#total_fine').text()); 
 $('#finetotal').val(tf.toFixed(2));
 
 var baltotal = parseFloat(ftotal+tfine-tdiscount);
 
 $('#balance_total').text(baltotal.toFixed(2));
 
 function calculatePenalty(){
        var penaltyAmt = parseFloat($('#penalty').val());
        console.log(penaltyAmt);
        $('#penaltyAmt').text(penaltyAmt.toFixed(2));
       
        var tb = parseFloat($('#balance_total').text());
        var ptb = parseFloat(tb+penaltyAmt);
        console.log(ptb);
        $('#balance_total').text(ptb.toFixed(2));
}
</script>
@stop

Copyright © 2021 - 2025 IMMREX7