
<?php
$img_path =  WWW_ROOT . 'reports' . DS. 'report.jpg' ;
$bank_details = Account_Title.', IBAN: '. IBAN.', BIC: '.SWIFT_BIC.', Account No: '. Account_No.', Sort Code '.Sort_Code;

?>
<?= $this->Form->create($Student, ['id' => 'student_offer_letter_form', 'class'=> 'input-form-section']) ?>

<div class="container-fluid box box-primary" >
    <input type="hidden" name="step" value="<?php echo (FORM_SEQUENCE)[4]?>">

    <div class="row form-group">

        <div class="col-md-4 mb-1">
            <label for="letter_type" class="control-label">Letter Type<span
                        class="text-danger">*</span></label>
            <select required name="letter_type" id="letter_type" class="form-control">
                <option selected="" disabled="" value="">Select One</option>
                <?php foreach (OFFER_LETTER_TYPE as $key => $value): ?>
                    <option value="<?= h($key) ?>" <?= $Student->registration_payment->letter_type == $key ? 'selected' : '' ?>><?= h($value) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    </div>

    <div class="row form-group">

        <div class="col-md-4 mb-1">
            <label for="registration_fee" class="control-label">Registration Fee<span
                    class="text-danger">*</span></label>
            <input required type="text" name="registration_fee" id="registration_fee"
                   class="form-control" placeholder="registration fee" value="<?php echo $Student->registration_payment->registration_fee ?>">
        </div>
        <div class="col-md-4 mb-1">
            <label for="tuition_fees" class="control-label">Tuition Fees<span
                        class="text-danger">*</span></label>
            <input required type="text" name="tuition_fees" id="tuition_fees"
                   class="form-control" placeholder="tuition fees" value="<?php echo $Student->registration_payment->tuition_fees ?>">
        </div>
    </div>

    <div class="row form-group">

        <div class="col-md-4 mb-1">
            <label for="total_fees" class="control-label">Total Fees<span
                        class="text-danger">*</span></label>
            <input required type="text" name="total_fees" id="total_fees"
                   class="form-control" placeholder="total fees" value="<?php echo $Student->registration_payment->total_fees ?>">
        </div>
        <div class="col-md-4 mb-1">
            <label for="total_fees_paid" class="control-label">Paid Fees<span
                        class="text-danger">*</span></label>
            <input required type="text" name="total_fees_paid" id="total_fees_paid"
                   class="form-control" placeholder="Total Paid Fees" value="<?php echo $Student->registration_payment->total_fees_paid ?>">
        </div>
    </div>

    <div class="row form-group">

        <div class="col-md-4 mb-1">
            <label for="outstanding_fees" class="control-label">Outstanding Fees<span
                        class="text-danger">*</span></label>
            <input required type="text" name="outstanding_fees" id="outstanding_fees"
                   class="form-control" placeholder="tuition fees" value="<?php echo $Student->registration_payment->outstanding_fees ?>">
        </div>
    </div>

    <div class="row form-group">

        <div class="col-md-10 mb-1">
            <label for="bank_details" class="control-label">Bank Details<span
                    class="text-danger">*</span></label>
            <input required type="text" name="bank_details" id="bank_details"
                   class="form-control" placeholder="bank details" value="<?php echo $bank_details ?>">
        </div>

    </div>

    <div class="row form-group">

        <div class="col-lg-9 center-block">
            <?= $this->Form->button(__('Next'), ['class' => 'btn btn-success tab3Save pull-left btn-grid btn-flat','id'=>'submit']) ?>

        </div>
    </div>
</div>
<?= $this->Form->end() ?>

<style type="text/css">

    .error-message {
        color: #ff0000;
    }


</style>

<script>
    $('#registration_fee').on('input', function() {
        this.value = decimalChecking(this.value);
        let tuition_fees = parseFloat($('#tuition_fees').val());
        $('#total_fees').val(parseFloat(this.value)+tuition_fees);
        $('#total_fees_paid').val(parseFloat(this.value)+tuition_fees);

    });
    $('#tuition_fees').on('input', function() {

        this.value = decimalChecking(this.value);
        let registration_fee = parseFloat($('#registration_fee').val());
        $('#total_fees').val(parseFloat(this.value)+registration_fee);
        $('#total_fees_paid').val(parseFloat(this.value)+registration_fee);

    });
    $('#total_fees').on('input', function() {

        this.value = decimalChecking(this.value);

    });
    $('#total_fees_paid').on('input', function() {

        this.value = decimalChecking(this.value);
        let total_fees = parseFloat($('#total_fees').val());
        $('#outstanding_fees').val(total_fees - parseFloat(this.value));

    });
    $('#outstanding_fees').on('input', function() {

        this.value = decimalChecking(this.value);

    });
    function decimalChecking(value){
        let sanitized = value.replace(/[^0-9.]/g, '');
        sanitized = sanitized.replace(/(\..*?)\..*/g, '$1');
        return sanitized;
    }
    $('#student_offer_letter_form').validate({
        rules:{
            'registration_fee' :'required',
            'tuition_fees' :'required',
            'total_fees_paid' :'required',
            'total_fees' :'required',
            'letter_type' : 'required'
        },
        messages: {
            'registration_fee':{
                required: "Please enter registration_fee"
            },
            'tuition_fees':{
                required: "Please enter tuition_fees"
            },
            'total_fees_paid':{
                required: "Please enter total_fees_paid"
            },
            'total_fees':{
                required: "Please enter total_fees"
            },
            'letter_type':{
                required: "Please enter letter_type"
            },




        },
        highlight: function(element) {
            $(element).parent().addClass("has-error");
        },
        submitHandler: function(form) {
            form.submit();
        }
    });


</script>


