
<div  style="overflow: scroll;">
    <div class="btn-group" id="credit_score_both" data-toggle="buttons">
        <label class="btn btn-default btn-on active foir_selection">
            <input type="radio" value="1" checked="checked">Show Applicant FOIR</label>
        <label class="btn btn-default btn-off foir_selection">
            <input type="radio" value="2">Show Co-Applicant FOIR</label>
        <label class="btn btn-default btn-off foir_selection">
            <input type="radio" value="0">Show Both Applicant FOIR</label>
    </div>
    <table class="table show_ratio">
        <h6 class="foir_formula" style="margin-bottom:15px">FOIR = [(Total EMIs + CF EMI + 5% Total Active Credit Card Current Balance) / (Income<?php $categoryName = _env('APP_CONNECTION') ? 24 : 6; if(isset($consumer_applications->purpose) && $consumer_applications->purpose == $categoryName) { echo " + Power Savings";} ?>)] x 100 </h6>
        <h6 class="cf_foir_formula" style="margin-bottom:15px">CF FOIR = (CF EMI / (Income<?php $categoryName = _env('APP_CONNECTION') ? 24 : 6; if(isset($consumer_applications->purpose) && $consumer_applications->purpose == $categoryName) { echo " + Power Savings";} ?>)) x 100 </h6>
        <h6 class="residual_foir_formula" style="margin-bottom:15px">Residual FOIR(%) = Max cap(75% currently) - (Existing FOIR(%))</h6>

        <tr>
            <td style="color: #4e5858;" colspan="3"><code>Active Credit Card</code></td>
        </tr>
        <tr>
            <td style="font-weight: 600;">AccountType</td>
            <td style="font-weight: 600;">Credit Card Current Balance Amount</td>
            <td style="font-weight: 600;text-align:center" colspan="2">Action</td>
            @if(\Illuminate\Support\Facades\Session::has('Edit_Trade_Line|-60'))
            <td style="font-weight: 600;">Reason</td>
            @endif
        </tr>
        <?php $balance_amount = 0; ?>
        @if(isset($consumer_applications->foir))
            @foreach($consumer_applications->foir as $foir)
                @if($foir->cc_loan == 0 && $foir->isOpened == 1)
                    <?php $balance_amount += (int)$foir->Balance; ?>
                    <tr class="foir new_foir_details foir_date_row_{!! $foir->id !!}" style="<?php echo ($foir->applicant_type == 2) ? 'display:none;': ''; ?>" 
                        data-credit-id="{!! $foir->credit_id !!}" data-is-include="@if($foir->applicant_type == 1) 1 @else 0 @endif" data-applicant-type="{!! $foir->applicant_type !!}" 
                        data-id="{!! $foir->id !!}" data-type="credit" data-account-type="{!! $foir->AccountType !!}">
                        <td>{!! $foir->AccountType !!}</td>
                        <td>
                            <input type="text" value="{!! $foir->Balance !!}" placeholder="Credit Card Current Balance" class="form-control @if($foir->Balance > 0) hide_in_foir @endif" @if($foir->Balance > 0) readonly @endif name="balance_amount" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')"/>
                        </td>
                        @if($foir->created_by && \Illuminate\Support\Facades\Session::has('delete_trade_line|-4'))
                            <td class="delete-foir-row" data-id="{!! $foir->id !!}" style="text-align:end"><i class="fa fa-trash" style="cursor:pointer"></i></td>
                        @else
                        <td> </td>
                        @endif
                        @if(\Illuminate\Support\Facades\Session::has('Edit_Trade_Line|-60'))
                            <td class="edit-foir-row" data-id="{!! $foir->id !!}"><i class="la la-edit" style="cursor:pointer"></i></td>
                            <td>
                                <input type="text" placeholder="Reason to change credit card current balance" value="{!! $foir->reason_info !!}" name="reason_info" class="form-control hide_in_foir" readonly>
                            </td>
                        @endif
                    </tr>
                @endif
            @endforeach
        @endif
        <tr>
            <td style="font-weight: 600;" class="total_credit_limit">Total Active Credit Card Current Balance</td>
            <td colspan="4">{!! $balance_amount !!}</td>
        </tr>
        <tr>
            <td style="font-weight: 600;" class="five_percent_total_credit_limit">5% of Total Credit Card limit</td>
            <td colspan="4">{!! $balance_amount*5/100 !!}</td>
        </tr>
    </table>
    @if(\Illuminate\Support\Facades\Session::has('Add_Trade_Line|-16'))
        <div class="btn btn-primary add_more_foir" data-type="credit">Add More</div>
    @endif
    <table class="table km_dhw_sg">
        <tr>
            <td colspan="3"><code>Existing EMI</code></td>
        </tr>
        <tr>
            <td style="font-weight: 600;">AccountType</td>
            <td style="font-weight: 600;">InstallmentAmount</td>
            <td style="font-weight: 600;text-align:center" colspan="2">Action</td>
            @if(\Illuminate\Support\Facades\Session::has('Edit_Trade_Line|-60'))
            <td style="font-weight: 600;">Reason</td>
            @endif
        </tr>
        <?php $amount = 0; $is_credit_fair_set = 0; $jointLoans = []; $inc_foir = 1; ?>
        @if(isset($consumer_applications->foir))
            @foreach($consumer_applications->foir as $foir)
                @if($foir->AccountType == 'Credit Fair EMI') <?php $is_credit_fair_set = 1; ?> @endif
                <?php if($foir->applicant_type == 2 && $foir->OwnershipType == 'Joint Account' && in_array($foir->AccountType, $jointLoans)){$inc_foir = 0;} ?>
                @if($foir->OwnershipType != 'Guarantor' && ($foir->cc_loan == 1 && $foir->isOpened == 1 && ($foir->Balance > 0 || $foir->created_by > 0)) && $inc_foir)
                    <?php $amount += $foir->InstallmentAmount; if($foir->applicant_type == 1){ $jointLoans[] = $foir->AccountType;} ?>
                    <tr class="foir new_foir_details foir_date_row_{!! $foir->id !!}" style="<?php echo ($foir->applicant_type == 2) ? 'display:none;': ''; ?>" data-credit-id="{!! $foir->credit_id !!}" data-is-include="@if($foir->applicant_type == 1) 1 @else 0 @endif" data-applicant-type="{!! $foir->applicant_type !!}" data-id="{!! $foir->id !!}" data-type="loan" data-account-type="{!! $foir->AccountType !!}">
                        <td @if($foir->AccountType == 'Credit Fair EMI') class="select_plan_edit_td" @endif> {!! $foir->AccountType !!} @if($foir->AccountType == 'Credit Fair EMI') <span class="select_plan_edit">(Select Other EMI Plan)</span> @endif</td>
                        <td><input type="text" value="{!! $foir->InstallmentAmount !!}" placeholder="Installment Amount" class="form-control @if($foir->InstallmentAmount > 0) hide_in_foir @endif" @if($foir->InstallmentAmount > 0) readonly @endif name="installment_amount" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')"/></td>
                        @if($foir->created_by && \Illuminate\Support\Facades\Session::has('delete_trade_line|-4'))
                            <td class="delete-foir-row" data-id="{!! $foir->id !!}" style="text-align:end"><i class="fa fa-trash" style="cursor:pointer"></i></td>
                        @else
                        <td></td>
                        @endif
                        @if($foir->AccountType != 'Credit Fair EMI' && \Illuminate\Support\Facades\Session::has('Edit_Trade_Line|-60'))
                            <td class="edit-foir-row" data-id="{!! $foir->id !!}"><i class="la la-edit" style="cursor:pointer"></i></td>
                            <td><input type="text" placeholder="Reason to change installment amount" value="{!! $foir->reason_info !!}" name="reason_info" class="form-control hide_in_foir" readonly></td>
                        @endif
                    </tr>
                @endif
            @endforeach
        @endif
        @if($is_credit_fair_set == 0)
            <tr class="new_foir_details" data-is-include="1" data-applicant-type="1" data-type="loan" data-account-type="Credit Fair EMI">
                <td class="select_plan_edit_td">Credit Fair EMI  <span class="select_plan_edit">(Select Other EMI Plan)</span></td>
                <td colspan="4"><input type="text" value="" placeholder="Installment Amount" class="form-control hide_in_foir" readonly name="installment_amount"/></td>
            </tr>
        @endif
        <tr class="emi-default-hide">
            <td colspan="5">
                <div class="emi-calculation-summary m-section__content">

                </div>
            </td>
        </tr>
        <tr>
            <td style="font-weight: 600;" class="total_existing_emi">Total Existing EMI</td>
            <td colspan="4">{!! $amount !!}</td>
        </tr>
    </table>
    @if(\Illuminate\Support\Facades\Session::has('Add_Trade_Line|-16'))
        <div class="btn btn-primary add_more_foir" data-type="loan">Add More</div>
    @endif
    <table class="table">
        <tr>
            <td colspan="3"><code>Guarantor Loans</code></td>
        </tr>
        <tr>
            <td style="font-weight: 600;">Account Type</td>
            <td style="font-weight: 600;">Sanction Amount</td>
        </tr>
        @if(isset($consumer_applications->foir))
            @foreach($consumer_applications->foir as $foir)
                @if($foir->OwnershipType == 'Guarantor' && ($foir->cc_loan == 1 && $foir->isOpened == 1 && ($foir->Balance > 0 || $foir->created_by > 0)))
                    <tr>
                        <td>{!! $foir->AccountType !!}</td>
                        <td style="@if($foir->PastDueAmount > 0) color:red; @endif">{!! $foir->ApprovedAmount !!} @if($foir->PastDueAmount > 0) <span style="font-size: 12px;">(Past Due Amount {!! $foir->PastDueAmount !!})</span> @endif</td>
                    </tr>
                @endif
            @endforeach
        @endif
    </table>
    <input type="hidden" name="foir_changed" id="foir_changed" value="old">
    <div class="btn btn-success calculate_foir_btn" onclick="document.getElementById('foir_changed').value='new'">Calculate FOIR</div>
    <h4><code>Edited FOIR/Installment value wont be saved in System after cases is approved</code></h4>
</div>
