

<?php $__env->startSection('content'); ?>


<?php $__env->startPush('styles'); ?>
<link rel="stylesheet" href="<?php echo e(asset('admin/css/loansettings.css')); ?>">
<?php $__env->stopPush(); ?>

<div class="ls-page">

<div class="ls-wrap">




<a
    href="<?php echo e(route('admin.loans')); ?>"
    class="ls-back"
>
    ← Back to Loan Management
</a>




<div class="ls-head">

    <div>

        <h1>
            Loan Settings
        </h1>

        <p>
            Configure the rules used when clients calculate and apply for loans.
        </p>

    </div>

</div>




<?php if(session('success')): ?>

    <div class="ls-alert ls-success">
        <?php echo e(session('success')); ?>

    </div>

<?php endif; ?>




<?php if($errors->any()): ?>

    <div class="ls-alert ls-error">

        <strong>
            Please check the following:
        </strong>

        <ul style="margin:7px 0 0 17px;padding:0">

            <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                <li>
                    <?php echo e($error); ?>

                </li>

            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        </ul>

    </div>

<?php endif; ?>


<form
    method="POST"
    action="<?php echo e(route('admin.loan-settings.update')); ?>"
>

<?php echo csrf_field(); ?>

<?php echo method_field('PUT'); ?>




<div class="ls-card">

    <div class="ls-card-head">

        <h2>
            Loan System
        </h2>

        <span>
            General availability
        </span>

    </div>


    <div class="ls-body">

        <div class="ls-toggle">

            <div>

                <div class="ls-toggle-title">
                    Accept new loan applications
                </div>

                <div class="ls-toggle-sub">
                    Turn this off to temporarily stop clients from submitting new loan applications.
                </div>

            </div>


            <label class="switch">

                <input
                    type="checkbox"
                    name="enabled"
                    value="1"
                    <?php if(
                        old(
                            'enabled',
                            $settings->enabled
                        )
                    ): echo 'checked'; endif; ?>
                >

                <span class="slider"></span>

            </label>

        </div>

    </div>

</div>




<div class="ls-card">

    <div class="ls-card-head">

        <h2>
            Interest & Processing Fee
        </h2>

        <span>
            Current loan pricing
        </span>

    </div>


    <div class="ls-body">


        

        <div class="ls-toggle">

            <div>

                <div class="ls-toggle-title">
                    Enable Interest
                </div>

                <div class="ls-toggle-sub">
                    Turn this on to apply interest rates based on loan type.
                    Keep it off for 0% interest loans.
                </div>

            </div>


            <label class="switch">

                <input
                    type="checkbox"
                    name="interest_enabled"
                    value="1"
                    id="interest_enabled"
                    <?php if(
                        old(
                            'interest_enabled',
                            $settings->interest_enabled ?? false
                        )
                    ): echo 'checked'; endif; ?>
                >

                <span class="slider"></span>

            </label>

        </div>


        

        <div
            id="interestStatus"
            style="margin-top:15px;"
        >

            <div class="zero-box">

                <div>

                    <strong id="interestStatusTitle">
                        <?php if(
                            old(
                                'interest_enabled',
                                $settings->interest_enabled ?? false
                            )
                        ): ?>
                            Interest Enabled
                        <?php else: ?>
                            0% Interest Loan
                        <?php endif; ?>
                    </strong>

                    <div
                        id="interestStatusText"
                        style="margin-top:3px"
                    >

                        <?php if(
                            old(
                                'interest_enabled',
                                $settings->interest_enabled ?? false
                            )
                        ): ?>

                            Loan interest will be calculated according to the selected loan type.

                        <?php else: ?>

                            Clients pay no interest on the principal amount.

                        <?php endif; ?>

                    </div>

                </div>


                <span id="interestStatusBadge">

                    <?php if(
                        old(
                            'interest_enabled',
                            $settings->interest_enabled ?? false
                        )
                    ): ?>

                        Interest is ON

                    <?php else: ?>

                        Interest is OFF

                    <?php endif; ?>

                </span>

            </div>

        </div>


        

        <div
            id="loanTypeInterestSection"
            class="loan-type-interest"
            style="
                display:
                <?php echo e(old(
                        'interest_enabled',
                        $settings->interest_enabled ?? false
                    )
                    ? 'block'
                    : 'none'); ?>;
            "
        >

            <div class="loan-type-interest-head">

                <div>

                    <div class="loan-type-interest-title">
                        Loan Type-wise Interest Rate
                    </div>

                    <div class="loan-type-interest-sub">
                        Set the annual interest rate for each active loan type.
                    </div>

                </div>

            </div>


            <?php if(isset($loanTypes) && $loanTypes->count()): ?>

                <div class="loan-type-list">

                    <?php $__currentLoopData = $loanTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $loanType): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                        <div class="loan-type-row">

                            <div class="loan-type-info">

                                <div class="loan-type-name">
                                    <?php echo e($loanType->name); ?>

                                </div>

                                <?php if($loanType->code): ?>

                                    <div class="loan-type-code">
                                        <?php echo e($loanType->code); ?>

                                    </div>

                                <?php endif; ?>

                            </div>


                            <div class="loan-type-rate">

                                <input
                                    type="number"
                                    name="loan_type_interest_rates[<?php echo e($loanType->id); ?>]"
                                    value="<?php echo e(old(
                                        'loan_type_interest_rates.' . $loanType->id,
                                        $loanType->interest_rate ?? 0
                                    )); ?>"
                                    min="0"
                                    max="100"
                                    step="0.01"
                                    inputmode="decimal"
                                    aria-label="<?php echo e($loanType->name); ?> interest rate"
                                >

                                <span class="loan-type-percent">
                                    %
                                </span>

                            </div>

                        </div>

                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                </div>


                <div class="interest-disabled-note">

                    <strong style="color:#233a55;font-size:10px">
                        Interest calculation
                    </strong>

                    <br>

                    When Interest is ON, the above rate will be used according
                    to the selected loan type.

                    When Interest is OFF, all active loan types will be saved
                    automatically at <strong>0%</strong>.

                </div>

            <?php else: ?>

                <div class="interest-disabled-note">

                    No active loan types found.

                </div>

            <?php endif; ?>

        </div>


        

        <input
            type="hidden"
            name="interest_rate"
            value="<?php echo e(old(
                'interest_rate',
                $settings->interest_rate ?? 0
            )); ?>"
        >


        

        <div
            class="ls-grid"
            style="margin-top:15px"
        >

            <div class="ls-field">

                <label for="processing_fee_type">
                    Processing Fee Type
                </label>

                <select
                    name="processing_fee_type"
                    id="processing_fee_type"
                >

                    <option
                        value="fixed"
                        <?php if(
                            old(
                                'processing_fee_type',
                                $settings->processing_fee_type
                            ) === 'fixed'
                        ): echo 'selected'; endif; ?>
                    >
                        Fixed Amount
                    </option>

                    <option
                        value="percentage"
                        <?php if(
                            old(
                                'processing_fee_type',
                                $settings->processing_fee_type
                            ) === 'percentage'
                        ): echo 'selected'; endif; ?>
                    >
                        Percentage of Loan
                    </option>

                </select>

                <div class="ls-help">
                    Choose whether the fee is a fixed amount or a percentage of the loan amount.
                </div>

            </div>


            <div class="ls-field">

                <label for="processing_fee">
                    Processing Fee
                </label>

                <input
                    type="number"
                    id="processing_fee"
                    name="processing_fee"
                    min="0"
                    step="0.01"
                    value="<?php echo e(old(
                        'processing_fee',
                        $settings->processing_fee
                    )); ?>"
                    required
                >

                <div
                    class="ls-help"
                    id="feeHelp"
                >
                    For fixed fee, enter the amount in rupees.
                </div>

                <?php $__errorArgs = ['processing_fee'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>

                    <div class="ls-errors">
                        <?php echo e($message); ?>

                    </div>

                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

            </div>

        </div>


        <div class="fee-note">

            Example: Fixed ₹999 means every eligible loan has a ₹999 processing fee.

            Percentage 2% means a ₹50,000 loan has a ₹1,000 processing fee.

        </div>

    </div>

</div>




<div class="ls-card">

    <div class="ls-card-head">

        <h2>
            EMI Card Unlock
        </h2>

        <span>
            Card activation payment
        </span>

    </div>


    <div class="ls-body">

        <div class="ls-grid">


            <div class="ls-field">

                <label for="card_unlock_amount">
                    Card Unlock Amount
                </label>

                <input
                    type="number"
                    id="card_unlock_amount"
                    name="card_unlock_amount"
                    min="0"
                    step="0.01"
                    value="<?php echo e(old(
                        'card_unlock_amount',
                        $settings->card_unlock_amount ?? 199
                    )); ?>"
                    required
                >

                <div class="ls-help">
                    This amount will be used for the “Unlock Card” payment on both the client and admin side.
                </div>

                <?php $__errorArgs = ['card_unlock_amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>

                    <div class="ls-errors">
                        <?php echo e($message); ?>

                    </div>

                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

            </div>


            <div
                class="ls-field"
                style="display:flex;align-items:center"
            >

                <div
                    class="fee-note"
                    style="margin:0;width:100%"
                >

                    <strong
                        style="
                            color:#233a55;
                            font-size:11px;
                        "
                    >
                        Example
                    </strong>

                    <br>

                    Set ₹199 here →
                    Client shows
                    <strong>
                        Unlock Card ₹199
                    </strong>
                    and Admin shows the same amount.

                </div>

            </div>

        </div>

    </div>

</div>




<div class="ls-card">

    <div class="ls-card-head">

        <h2>
            Loan Amount Limits
        </h2>

        <span>
            Client application limits
        </span>

    </div>


    <div class="ls-body">

        <div class="ls-grid">


            <div class="ls-field">

                <label for="minimum_loan_amount">
                    Minimum Loan Amount
                </label>

                <input
                    type="number"
                    id="minimum_loan_amount"
                    name="minimum_loan_amount"
                    min="1"
                    step="0.01"
                    value="<?php echo e(old(
                        'minimum_loan_amount',
                        $settings->minimum_loan_amount
                    )); ?>"
                    required
                >

                <div class="ls-help">
                    Clients cannot apply below this amount.
                </div>

            </div>


            <div class="ls-field">

                <label for="maximum_loan_amount">
                    Maximum Loan Amount
                </label>

                <input
                    type="number"
                    id="maximum_loan_amount"
                    name="maximum_loan_amount"
                    min="1"
                    step="0.01"
                    value="<?php echo e(old(
                        'maximum_loan_amount',
                        $settings->maximum_loan_amount
                    )); ?>"
                    required
                >

                <div class="ls-help">
                    This is also limited by the client's available EMI card limit.
                </div>

            </div>

        </div>

    </div>

</div>




<div class="ls-card">

    <div class="ls-card-head">

        <h2>
            Allowed Tenures
        </h2>

        <span>
            Select one or more
        </span>

    </div>


    <div class="ls-body">

        <?php

            $selectedTenures =
                old(
                    'allowed_tenures',
                    $settings->allowed_tenures ?? []
                );

            $availableTenures = [
                3,
                6,
                9,
                12,
                18,
                24,
                36,
                48
            ];

        ?>


        <div class="tenures">

            <?php $__currentLoopData = $availableTenures; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $months): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                <div class="tenure">

                    <input
                        type="checkbox"
                        name="allowed_tenures[]"
                        id="tenure<?php echo e($months); ?>"
                        value="<?php echo e($months); ?>"
                        <?php if(
                            in_array(
                                $months,
                                $selectedTenures
                            )
                        ): echo 'checked'; endif; ?>
                    >

                    <label
                        for="tenure<?php echo e($months); ?>"
                    >
                        <?php echo e($months); ?> Months
                    </label>

                </div>

            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        </div>


        <div
            class="ls-help"
            style="margin-top:10px"
        >
            Only selected tenures will be available on the client loan application page.
        </div>

    </div>

</div>




<div class="ls-card">

    <div class="ls-card-head">

        <h2>
            Overdue Fine
        </h2>

        <span>
            Late EMI payment charges
        </span>

    </div>


    <div class="ls-body">

        <div class="ls-grid">


            

            <div class="ls-field">

                <label for="overdue_fine_type">
                    Fine Type
                </label>

                <select
                    name="overdue_fine_type"
                    id="overdue_fine_type"
                >

                    <option
                        value="fixed"
                        <?php if(
                            old(
                                'overdue_fine_type',
                                $settings->overdue_fine_type ?? 'fixed'
                            ) === 'fixed'
                        ): echo 'selected'; endif; ?>
                    >
                        Fixed Amount
                    </option>

                    <option
                        value="percentage"
                        <?php if(
                            old(
                                'overdue_fine_type',
                                $settings->overdue_fine_type ?? 'fixed'
                            ) === 'percentage'
                        ): echo 'selected'; endif; ?>
                    >
                        Percentage
                    </option>

                </select>

                <div class="ls-help">
                    Choose how the overdue fine should be calculated.
                </div>

                <?php $__errorArgs = ['overdue_fine_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>

                    <div class="ls-errors">
                        <?php echo e($message); ?>

                    </div>

                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

            </div>


            

            <div class="ls-field">

                <label for="overdue_fine_amount">
                    Fine Amount
                </label>

                <input
                    type="number"
                    id="overdue_fine_amount"
                    name="overdue_fine_amount"
                    min="0"
                    step="0.01"
                    value="<?php echo e(old(
                        'overdue_fine_amount',
                        $settings->overdue_fine_amount ?? 0
                    )); ?>"
                    required
                >

                <div
                    class="ls-help"
                    id="overdueFineHelp"
                >
                    Fixed amount charged for overdue EMI.
                </div>

                <?php $__errorArgs = ['overdue_fine_amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>

                    <div class="ls-errors">
                        <?php echo e($message); ?>

                    </div>

                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

            </div>


            

            <div class="ls-field">

                <label for="overdue_grace_days">
                    Grace Period
                </label>

                <input
                    type="number"
                    id="overdue_grace_days"
                    name="overdue_grace_days"
                    min="0"
                    max="365"
                    step="1"
                    value="<?php echo e(old(
                        'overdue_grace_days',
                        $settings->overdue_grace_days ?? 0
                    )); ?>"
                    required
                >

                <div class="ls-help">
                    Fine will start after this many days from the EMI due date.
                </div>

                <?php $__errorArgs = ['overdue_grace_days'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>

                    <div class="ls-errors">
                        <?php echo e($message); ?>

                    </div>

                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

            </div>


            

            <div class="ls-field">

                <label for="overdue_max_fine">
                    Maximum Fine
                </label>

                <input
                    type="number"
                    id="overdue_max_fine"
                    name="overdue_max_fine"
                    min="0"
                    step="0.01"
                    value="<?php echo e(old(
                        'overdue_max_fine',
                        $settings->overdue_max_fine ?? 0
                    )); ?>"
                    required
                >

                <div class="ls-help">
                    Maximum fine allowed. Enter 0 for no maximum limit.
                </div>

                <?php $__errorArgs = ['overdue_max_fine'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>

                    <div class="ls-errors">
                        <?php echo e($message); ?>

                    </div>

                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

            </div>

        </div>


        <div class="fee-note">

            <strong
                style="
                    color:#233a55;
                    font-size:11px;
                "
            >
                Example
            </strong>

            <br>

            Fixed ₹50 → ₹50 fine for an overdue EMI.

            <br>

            Percentage 2% → 2% of the overdue EMI amount.

            <br>

            Grace Period 3 days → Fine starts after 3 days overdue.

            <br>

            Maximum Fine ₹1,000 → Fine cannot exceed ₹1,000.

        </div>

    </div>

</div>




<div class="ls-card">

    <div class="ls-body">

        <div class="ls-actions">

            <a
                href="<?php echo e(route('admin.loans')); ?>"
                class="ls-btn ls-btn-light"
            >
                Cancel
            </a>

            <button
                type="submit"
                class="ls-btn ls-btn-blue"
            >
                Save Loan Settings
            </button>

        </div>

    </div>

</div>


</form>

</div>

</div>




<script>

(function(){

    const type =
        document.getElementById(
            'processing_fee_type'
        );

    const help =
        document.getElementById(
            'feeHelp'
        );


    if (!type || !help) {
        return;
    }


    function updateFeeHelp()
    {

        if (
            type.value === 'percentage'
        ) {

            help.textContent =
                'Enter a percentage. Example: 2 means 2% of the loan amount.';

        } else {

            help.textContent =
                'Enter the fixed processing fee amount in rupees.';

        }

    }


    type.addEventListener(
        'change',
        updateFeeHelp
    );


    updateFeeHelp();

})();

</script>




<script>

(function(){

    const type =
        document.getElementById(
            'overdue_fine_type'
        );

    const help =
        document.getElementById(
            'overdueFineHelp'
        );


    if (!type || !help) {
        return;
    }


    function updateOverdueFineHelp()
    {

        if (
            type.value === 'percentage'
        ) {

            help.textContent =
                'Enter a percentage. Example: 2 means 2% of the overdue EMI amount.';

        } else {

            help.textContent =
                'Enter the fixed fine amount for an overdue EMI.';

        }

    }


    type.addEventListener(
        'change',
        updateOverdueFineHelp
    );


    updateOverdueFineHelp();

})();

</script>




<script>

(function(){

    const interestToggle =
        document.getElementById(
            'interest_enabled'
        );

    const title =
        document.getElementById(
            'interestStatusTitle'
        );

    const text =
        document.getElementById(
            'interestStatusText'
        );

    const badge =
        document.getElementById(
            'interestStatusBadge'
        );

    const loanTypeSection =
        document.getElementById(
            'loanTypeInterestSection'
        );


    if (
        !interestToggle ||
        !title ||
        !text ||
        !badge ||
        !loanTypeSection
    ) {
        return;
    }


    function updateInterestStatus()
    {

        if (
            interestToggle.checked
        ) {

            title.textContent =
                'Interest Enabled';

            text.textContent =
                'Loan interest will be calculated according to the selected loan type.';

            badge.textContent =
                'Interest is ON';

            loanTypeSection.style.display =
                'block';

        } else {

            title.textContent =
                '0% Interest Loan';

            text.textContent =
                'Clients pay no interest on the principal amount.';

            badge.textContent =
                'Interest is OFF';

            loanTypeSection.style.display =
                'none';

        }

    }


    interestToggle.addEventListener(
        'change',
        updateInterestStatus
    );


    updateInterestStatus();

})();

</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\emi-card\resources\views/admin/loan-settings/edit.blade.php ENDPATH**/ ?>