<!-- DEBUG-VIEW START 1 APPPATH/Views/login.php -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?= $pageTitle; ?> | <?= PROJECT_NAME; ?></title>
    <link rel="icon" type="image/x-icon" href="<?= base_url('assets/payonline'); ?>/images/favicon.png">
    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<?= base_url('assets/payonline'); ?>/css/all.min.css">
    <!-- icheck bootstrap -->
    <link rel="stylesheet" href="<?= base_url('assets/payonline'); ?>/css/icheck-bootstrap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<?= base_url('assets/payonline'); ?>/css/adminlte.min.css">
    <!-- SweetAlert2 -->


    <!-- sweet alert -->
    <script src="https://common.olemiss.edu/_js/sweet-alert/sweet-alert.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://common.olemiss.edu/_js/sweet-alert/sweet-alert.css">


    <!-- country_code links -->
    <link rel="stylesheet" type="text/css" href="<?= base_url('assets/css/intlTelInput.css?1549804213570'); ?>">
    <!-- country_code links -->

    <!-- <script src='https://www.google.com/recaptcha/api.js'></script> -->
    <style>
        .login-box-msg,
        .register-box-msg {
            padding: 0;
        }

        .submitbutton {
            background-color: #7E4555;
        }

        .submitbutton:hover {
            background-color: #EE4D23;
        }

        /*body .modal-dialog { margin-left: 0; }*/

        .iti {
            /*position: relative;*/
            display: -webkit-box !important;
        }


        #signupModal {
            display: none;
        }

        .inSignup {
            display: none;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="<?= base_url('assets/css/ldld.min.css'); ?>">
    <script type="text/javascript" charset="utf8" src="<?= base_url('assets/js/ldld.min.js'); ?>"></script>
</head>

<body class="hold-transition login-page" style="display:grid!important;justify-items: center!important;">

    <!--- popup --->



    <?php
    if ($this->session->userdata('logged_in') == 1) {

        $current_user = getUserDetails()->data[0];
        $fgh = getFullPaymentSettings();


        $dsbj = $fgh['result']['data'][0]['paymentGatewayoffon'];

        foreach ($dsbj as $key => $dd) {
            if ($dd['source'] == 'WEBSITE') {
                $paymentSeverOn = $dd['isenable'];
                $paymentSeverText = $dd['desc'];
            }
        }


        $paymentSetting = @getPaymentGatewaySettings();

        $getclientInfoById = @getclientInfoById()['data'][0];

        $CAW_MerchantId = @$getclientInfoById['ChargeAnywhereMerchantId'];
        $CAW_TerminalId = @$getclientInfoById['ChargeAnywhereTerminalId'];

        $GeneralSettings = GeneralSettings();
        $currencySymbol = getCurrencySymbol();


    ?>
        <?php

        $facilitySettings = SettingsApi()['result']['data'][0]['facilitySettings'];
        $facilityAdvance = isset($facilitySettings['facilityAdvance']) ? $facilitySettings['facilityAdvance'] : 0;
        $facilityAdvanceType = isset($facilitySettings['Type']) ? $facilitySettings['Type'] : '';
        ?>
        <div class="login-box my-4">
            <div class="card card-outline card-danger">
                <div class="card-header text-center">
                    <div class="login-box-msg parent">
                        <div class="center fill-remaining-space">
                            <h4>CHECKOUT</h4>
                        </div>
                    </div>
                </div>

                <div class="card-body login-card-body">
                    <div class="card-body">
                        <div style="padding:0px">
                            <img src="<?= ApiBaseUrl()['url'] . $header_data[0]['leftImage'] ?>" class="img-fluid mb-4"
                                height="100px" width="100px" style="display: block; margin-left: auto; margin-right: auto;">
                            <div class="row d-flex justify-content-center align-items-center">
                                <form action="#" method="post" onsubmit="return SignupUser('<?= base_url('signup') ?>')" style="width: 100%;">
                                    <div class="col-xl-12">
                                        <div class="row g-0">
                                            <div class="col-xl-12">
                                                <?php
                                                // var_dump($paymentDetails['_id']);
                                                if ($paymentDetails['paymentStatus'] == 'PARTIALLY_COMPLETED' || (isset($paymentDetails['advanceAmount']) && $paymentDetails['advanceAmount'] > 0)) {
                                                ?>
                                                    <div class="row">
                                                        <div class="col-md-12 mb-4">
                                                            <table class="table table-responsive table-bordered text-center">
                                                                <thead>
                                                                    <tr>
                                                                        <th style="width: 165px !important;">
                                                                            <h5
                                                                                style="font-size:16px; font-family: 'Open Sans', sans-serif!important; font-weight: 800; color: #B02135;">
                                                                                Facility</h5>
                                                                        </th>
                                                                        <th style="width: 165px !important;">
                                                                            <h5
                                                                                style="font-size:16px; font-family: 'Open Sans', sans-serif!important; font-weight: 800; color: #B02135;">
                                                                                Amount</h5>
                                                                        </th>
                                                                    </tr>
                                                                </thead>
                                                                <tbody>
                                                                    <?php

                                                                    $totalAmount = 0;
                                                                    $paymentId = $paymentDetails['_id'];
                                                                    foreach ($paymentDetails['paymentsData'] as $key => $services) {
                                                                        // $paymentId = $servicesDetail[$key]['paymentId'];
                                                                        $totalAmount += $services['serviceAmount'];
                                                                    ?>
                                                                        <tr>
                                                                            <td><span id="serviceName"
                                                                                    class="serviceName"><?= @$services['ServiceSetup']; ?></span>
                                                                            </td>
                                                                            <td>
                                                                                <h4 id="servicePrice">
                                                                                    $<?= sprintf("%.2f", @$services['serviceAmount']); ?>
                                                                                </h4>
                                                                            </td>
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['serviceAmount']; ?>"
                                                                                id="serviceAmt">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['serviceCategoryTypes']; ?>"
                                                                                id="serviceCategoryTypes">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['serviceTypes']; ?>"
                                                                                id="serviceTypes">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['bookingTypes']; ?>"
                                                                                id="dayTypes">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['serviceDate']; ?>"
                                                                                id="startDate">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['startTime']; ?>"
                                                                                id="startTime">
                                                                        </tr>
                                                                    <?php
                                                                    }
                                                                    ?>

                                                                    <!-- <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                                                                    <tr>
                                                                        <td>General Donations($)</td>
                                                                        <td><input type="number" name="general_donation"
                                                                                placeholder="<?= $currencySymbol ?> 0.00"
                                                                                class="form-control form-control-sm"
                                                                                id="general-donation-input"></td>
                                                                    </tr>
                                                                <?php } ?>


                                                                <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                                                                    <tr>
                                                                        <td>Acharya Sambhavana($)</td>
                                                                        <td> <input type="number" name="acharya_sambhavana"
                                                                                placeholder="<?= $currencySymbol ?> 0.00"
                                                                                class="form-control form-control-sm"
                                                                                id="acharya-sambhavana-input"></td>
                                                                    </tr>
                                                                <?php } ?> -->



                                                                </tbody>
                                                            </table>


                                                            <hr>
                                                            <div class="row">
                                                                <div class="col-sm-6">
                                                                    <span
                                                                        style="font-weight: 600; color: #b02135; padding-left: 10px;font-size: 20px;">Sub
                                                                        Total</span>
                                                                </div>
                                                                <div class="col-sm-6">
                                                                    <span id="sub-total"
                                                                        style="float: right; font-weight: 600; color: #b02135; padding-right: 10px;font-size: 20px;">$<?= sprintf("%.2f", $totalAmount); ?></span>
                                                                </div>
                                                            </div>


                                                            <hr>
                                                            <div class="row">
                                                                <div class="col-sm-6">
                                                                    <span
                                                                        style="font-weight: 600; color: #544c4d; padding-left: 10px;font-size: 16px;">Advance
                                                                        Paid Amount</span>
                                                                </div>
                                                                <div class="col-sm-6">

                                                                    <span id="sub-total1"
                                                                        style="float: right; font-weight: 600; color: #544c4d; padding-right: 10px;font-size: 20px;">$&nbsp;<?= sprintf("%.2f", $paymentDetails['advanceAmount']) ?></span>
                                                                </div>
                                                            </div>
                                                            <hr>
                                                            <div class="row">
                                                                <div class="col-sm-6">
                                                                    <span
                                                                        style="font-weight: 600; color: #b02135; padding-left: 10px;font-size: 20px;">Pending Amount</span>
                                                                </div>
                                                                <div class="col-sm-6">
                                                                    <?php
                                                                    $advanceFacilityAmt = $paymentDetails['pendingAmount'];
                                                                    $advanceUpdateAmt = sprintf("%.2f", $paymentDetails['pendingAmount'] + $paymentDetails['advanceAmount']);
                                                                    ?>

                                                                    <span id="sub-total1"
                                                                        style="float: right; font-weight: 600; color: #b02135;font-size: 20px;">$&nbsp;<input type="number" style="width: 100px;color: #b02135;font-weight: 600;" min="<?= $advanceFacilityAmt ?>" max="<?= sprintf("%.2f", $totalAmount) ?>" value="<?= sprintf("%.2f", $advanceFacilityAmt) ?>" readonly step="0.1" onchange="validateMinimumPay(this)" id="advanceAmt" name="advanceAmt"></span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <!-- <button onclick="chargeanywhere()">response</button> -->
                                                    </div>
                                                <?php
                                                } else {
                                                    // var_dump($servicesDetail[0]);
                                                    // var_dump($paymentDetails);
                                                ?>
                                                    <div class="row">
                                                        <div class="col-md-12 mb-4">
                                                            <table class="table table-responsive table-bordered text-center">
                                                                <thead>
                                                                    <tr>
                                                                        <th style="width: 165px !important;">
                                                                            <h5
                                                                                style="font-size:16px; font-family: 'Open Sans', sans-serif!important; font-weight: 800; color: #B02135;">
                                                                                Facility</h5>
                                                                        </th>
                                                                        <th style="width: 165px !important;">
                                                                            <h5
                                                                                style="font-size:16px; font-family: 'Open Sans', sans-serif!important; font-weight: 800; color: #B02135;">
                                                                                Amount</h5>
                                                                        </th>
                                                                    </tr>
                                                                </thead>
                                                                <tbody>
                                                                    <?php

                                                                    $totalAmount = 0;
                                                                    $paymentId = $paymentDetails['_id'];

                                                                    foreach ($paymentDetails['paymentsData'] as $key => $services) {
                                                                        // var_dump($services);
                                                                        // $paymentId = $servicesDetail[$key]['paymentId'];
                                                                        $totalAmount += $services['serviceAmount'];
                                                                    ?>
                                                                        <tr>
                                                                            <td><span id="serviceName"
                                                                                    class="serviceName"><?= @$services['ServiceSetup']; ?></span>
                                                                            </td>
                                                                            <td>
                                                                                <h4 id="servicePrice">
                                                                                    $<?= sprintf("%.2f", @$services['serviceAmount']); ?>
                                                                                </h4>
                                                                            </td>
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['serviceAmount']; ?>"
                                                                                id="serviceAmt">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['serviceCategoryTypes']; ?>"
                                                                                id="serviceCategoryTypes">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['serviceTypes']; ?>"
                                                                                id="serviceTypes">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['bookingTypes']; ?>"
                                                                                id="dayTypes">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['serviceDate']; ?>"
                                                                                id="startDate">
                                                                            <input type="hidden" name=""
                                                                                value="<?= @$services['startTime']; ?>"
                                                                                id="startTime">
                                                                        </tr>
                                                                    <?php
                                                                    }
                                                                    ?>

                                                                    <!-- <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                                                                    <tr>
                                                                        <td>General Donations($)</td>
                                                                        <td><input type="number" name="general_donation"
                                                                                placeholder="<?= $currencySymbol ?> 0.00"
                                                                                class="form-control form-control-sm"
                                                                                id="general-donation-input"></td>
                                                                    </tr>
                                                                <?php } ?>


                                                                <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                                                                    <tr>
                                                                        <td>Acharya Sambhavana($)</td>
                                                                        <td> <input type="number" name="acharya_sambhavana"
                                                                                placeholder="<?= $currencySymbol ?> 0.00"
                                                                                class="form-control form-control-sm"
                                                                                id="acharya-sambhavana-input"></td>
                                                                    </tr>
                                                                <?php } ?> -->



                                                                </tbody>
                                                            </table>


                                                            <hr>
                                                            <div class="row">
                                                                <div class="col-sm-6">
                                                                    <span
                                                                        style="font-weight: 600; color: #b02135; padding-left: 10px;font-size: 20px;">Sub
                                                                        Total</span>
                                                                </div>
                                                                <div class="col-sm-6">
                                                                    <span id="sub-total"
                                                                        style="float: right; font-weight: 600; color: #b02135; padding-right: 10px;font-size: 20px;">$<?= sprintf("%.2f", $totalAmount); ?></span>
                                                                </div>
                                                            </div>


                                                            <hr>
                                                            <div class="row">
                                                                <div class="col-sm-6">
                                                                    <span
                                                                        style="font-weight: 600; color: #b02135; padding-left: 10px;font-size: 20px;">Advance
                                                                        Amount</span>
                                                                </div>
                                                                <div class="col-sm-6">
                                                                    <?php
                                                                    if ($facilityAdvance > 0 && !empty($facilityAdvanceType)) {
                                                                        if ($facilityAdvanceType == 'PERCENT') {
                                                                            // $advanceAmt = $totalAmount - ($totalAmount * $facilityAdvance) / 100;
                                                                            $advanceAmt = ($totalAmount * $facilityAdvance) / 100;
                                                                        } else {
                                                                            // $advanceAmt = $totalAmount - $facilityAdvance;
                                                                            $advanceAmt = $facilityAdvance;
                                                                        }

                                                                        $advanceFacilityAmt = sprintf("%.2f", $advanceAmt);
                                                                    } else {
                                                                        $advanceFacilityAmt = sprintf("%.2f", $totalAmount);
                                                                    }
                                                                    $advanceUpdateAmt = 0;

                                                                    ?>
                                                                    <span id="sub-total1"
                                                                        style="float: right; font-weight: 600; color: #b02135; padding-right: 10px;font-size: 20px;">$&nbsp;<input type="number" style="width: 70px;" min="<?= $advanceFacilityAmt ?>" max="<?= sprintf("%.2f", $totalAmount) ?>" value="<?= $advanceFacilityAmt ?>" step="0.1" onchange="validateMinimumPay(this)" id="advanceAmt" name="advanceAmt"></span>

                                                                </div>
                                                            </div>
                                                        </div>
                                                        <!-- <button onclick="chargeanywhere()">response</button> -->
                                                    </div>
                                                <?php
                                                }
                                                ?>


                                                <div class="d-flex justify-content-center text-center">
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <button type="button"
                                                                class="btn PaymentClosebtn btn-danger ms-2"
                                                                hidden>CLOSE</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>

                                <?php
                                if ($paymentSeverOn == 1) {
                                    // $paymentSetting = 'MPI';
                                    if (isset($paymentSetting) && ($paymentSetting == 'MPI' || $paymentSetting == 'MPITEST')) { ?>
                                        <link rel="stylesheet" type="text/css" href="<?= base_url('assets/css/mpi.css'); ?>">
                                        <form id="paymentForm" action="https://www.bridgepaynetsecuretx.com/WebSecurity/echo.aspx"
                                            method="post" style="max-width: 500px; margin: auto;">
                                            <div class="row px-0">
                                                <div class="col-md-12 px-0">
                                                    <h6 class="text-center">Card Details</h6>
                                                    <div id="card" class="mx-0" style="width: 100%!important; height: 150px;"></div>
                                                    <div id="errorMessage" style="margin-bottom: 10px; color: #c0392b;"></div>
                                                </div>
                                                <div class="col-md-12 px-0">
                                                    <!-- <h6 class="text-center">Billing Address</h6> -->
                                                    <p for="fname" style="text-align: justify;margin-bottom: 0px;font-weight: 600;">Name on Card <span class="text-danger">*</span></p>
                                                    <input type="text" class="form-control" id="fname" name="firstname"
                                                        placeholder="Enter Your Full Name*" required
                                                        style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px; padding-top: 12px!important;"
                                                        value="<?= @$current_user->refDataName; ?>">
                                                    <input type="email" id="email" class="form-control d-none" name="email"
                                                        placeholder="Enter Your Email Address"
                                                        style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px; padding-top: 12px!important;"
                                                        value="<?= base64_decode(@$current_user->email); ?>"  oninput="this.value = this.value.toLowerCase();">
                                                    <input type="text" class="form-control d-none" id="address" name="address"
                                                        placeholder="Enter Your Street Address"
                                                        style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px; padding-top: 12px!important;"
                                                        value="<?= @$current_user->addressLine1; ?>">
                                                    <input type="number" class="form-control" id="zipcode" name="zipcode"
                                                        placeholder="Enter Your Zipcode" required onKeyPress="if(this.value.length==5) return false;"
                                                        style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px; padding-top: 12px!important;"
                                                        value="<?= @$current_user->zip; ?>">
                                                    <div class="row m-0 p-0 d-none">
                                                        <div class="col-md-12 px-0">
                                                            <input type="text" id="state" name="state" placeholder="State*"
                                                                style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px; padding-top: 12px!important;"
                                                                value="<?= @$current_user->stateTypes; ?>">
                                                        </div>
                                                        <div class="col-md-12 px-0">
                                                            <input type="text" id="city" name="city" placeholder="City*"
                                                                style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px; padding-top: 12px!important;"
                                                                value="<?= @$current_user->cityTypes; ?>">
                                                        </div>
                                                    </div>
                                                    <center>
                                                        <button type="submit" id="paynowbtn" class="btn btn-success"
                                                            style="max-width: 500px; margin: auto; border-radius: 4px!important; font-weight: 800; padding: 8px 24px; background: #e78b00; border: 0; text-shadow: 1px 1px 0px black;">PAY
                                                            NOW</button>
                                                    </center>
                                                </div>
                                            </div>
                                        </form>
                                    <?php } else if (isset($paymentSetting) && $paymentSetting == 'CHARGEANYWHERE') { ?>
                                        <iframe id="paymentIframe" title="Payment Page" width="100%" height="300px"></iframe>
                                    <?php } else { ?>
                                        <div id="paypal-button-container"></div>
                                    <?php }
                                } else { ?>
                                    <span class="alert mt-5 alert-danger text-center fw-bold"><i
                                            class="fa fa-warning fw-bold"></i> <?= $paymentSeverText; ?></span>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


    <?php } else {
    ?>

        <div class="login-box my-4">
            <div class="login-logo">
            </div>
            <div class="card card-outline card-danger">
                <div class=" card-header text-center">
                    <div class="login-box-msg parent">
                        <div class="center fill-remaining-space">
                            <h4>LOGIN IN </h4>
                        </div>
                    </div>
                </div>

                <div class="card-body login-card-body">
                    <!-- <p class="login-box-msg">Sign in to start your session</p> -->

                    <div class="row">

                        <!-- SIGNUP BOX -->
                        <div class="col-md-12" id="signupModal">

                            <form action="#" method="post" onsubmit="return SignupUser('<?= base_url('signup') ?>')">

                                <div class="modal-body p-0">
                                    <div class="container">
                                        <img src="<?= ApiBaseUrl()['url'] . $header_data[0]['leftImage']; ?>"
                                            class="img-fluid my-1" height="120px" width="120px"
                                            style="display: block;margin-left: auto;margin-right: auto;">
                                        <div class="row" style="text-align:center;">
                                            <div class="col-md-12">
                                                <span id="signup-error-flashmsg" class="text-center"
                                                    style="color: red;"></span>
                                                <span id="signup-success-flashmsg" class="text-center"
                                                    style="color: green;"></span>
                                            </div>
                                        </div>
                                        <div class="row d-flex justify-content-center align-items-center">
                                            <div class="col-xl-12">
                                                <div class="row g-0">
                                                    <div class="col-xl-12">
                                                        <div class="row">
                                                            <div class="col-md-6 mb-2">
                                                                <div class="form-outline">
                                                                    <label class="form-label" for="fname">First name</label>
                                                                    <input type="text" id="fname" name="fname"
                                                                        class="form-control" required />
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6 mb-2">
                                                                <div class="form-outline">
                                                                    <label class="form-label" for="lname">Last name</label>
                                                                    <input type="text" id="lname" name="lname"
                                                                        class="form-control" />
                                                                </div>
                                                            </div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-12 mb-2">
                                                                <div class="form-outline">
                                                                    <label class="form-label"
                                                                        for="signupEmail">Email</label>
                                                                    <input type="email" id="signupEmail" name="email"
                                                                        class="form-control" required  oninput="this.value = this.value.toLowerCase();"/>
                                                                </div>
                                                            </div>
                                                        </div>


                                                        <div class="row">
                                                            <div class="col-md-12 mb-2">
                                                                <div class="form-outline">
                                                                    <label class="form-label" for="signupPhoneNumber">Phone
                                                                        Number</label>
                                                                    <input type="tel" placeholder="Ex. +1 (702) 123-4567"
                                                                        minlength="10" maxlength="15" id="signupPhoneNumber"
                                                                        name="phone"
                                                                        class="phone-with-country-code form-control"
                                                                        value=""
                                                                        onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57 || event.charCode==43 ))"
                                                                        oninput="nonEditCuntryCode1(this);" value="+1">
                                                                </div>
                                                            </div>
                                                        </div>



                                                        <div class="row">
                                                            <div class="col-md-12 p-3">
                                                                <center>
                                                                    <button type="submit" class="btn btn-info ms-2"
                                                                        id="signupBtn">SIGN UP</button>
                                                                </center>
                                                            </div>
                                                        </div>



                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="d-flex justify-content-center modal-footer">
                                    <!--   <div class="row mx-auto d-block">
                <div class="col-md-12">
                 <button type="submit" class="btn btn-warning ms-2" id="signupBtn">SIGN UP</button>
                 <button type="button" class="signupBtnClose btnClose btn btn-danger ms-2" data-dismiss="modal" hidden>CLOSE</button> 
               </div>

             </div> -->
                                </div>
                            </form>


                        </div>


                        <!-- LOGIN BOX -->
                        <div class="col-md-12" id="loginModal">
                            <form action="#" method="post" id="phonemyForm"
                                onsubmit="return LoginUser('<?= base_url('signin') ?>')">
                                <div class="modal-body p-0">
                                    <div class="container">
                                        <img src="<?= ApiBaseUrl()['url'] . $header_data[0]['leftImage']; ?>"
                                            class="img-fluid my-3" height="120px" width="120px"
                                            style="display: block;margin-left: auto;margin-right: auto;">


                                        <div class="row g-0">
                                            <div class="col-xl-12">
                                                <div class="row" style="text-align:center;">
                                                    <div class="col-md-12">
                                                        <span id="login-error-flashmsg" class="text-center"
                                                            style="color: red;"></span>
                                                        <span id="login-success-flashmsg" class="text-center"
                                                            style="color: green;"></span>

                                                    </div>
                                                </div>
                                            </div>
                                        </div>


                                        <div class="row d-flex justify-content-center align-items-center">
                                            <div class="col-xl-12">
                                                <div class="row">
                                                    <div class="col-xl-12">


                                                        <span class="email_section ">
                                                            <div class="row ">
                                                                <div class="col-md-12 mb-2">
                                                                    <input type="email" id="loginEmail"
                                                                        placeholder="Enter your email Id." name="email"
                                                                        class="form-control"  oninput="this.value = this.value.toLowerCase();"/>
                                                                    <span class="otpsendmsg"
                                                                        style="color: green; font-size: 13px;"></span>
                                                                </div>
                                                            </div>

                                                            <div class="row" id="otptoggle" style="display:none;">
                                                                <div class="col-md-8 mb-2">
                                                                    <input type="number" id="emailotp" name="emailotp"
                                                                        placeholder="Please enter OTP to continue."
                                                                        class="form-control" required />
                                                                </div>
                                                                <div class="col-md-4 mb-2">
                                                                    <button id="emailotpverifybtn"
                                                                        class="btn btn-success verifyBtn"
                                                                        onclick="verifyEmailOtp('<?= base_url('email-otp-verification') ?>')">VERIFY</button>
                                                                </div>
                                                            </div>
                                                        </span>

                                                        <span class="mobile_section">
                                                            <div class="text-center mb-2">--OR--</div>
                                                            <div class="row">
                                                                <div class="col-md-12 mb-0 ">
                                                                    <input type="tel" placeholder="Ex. +1 (702) 123-4567"
                                                                        id="loginPhoneNumber" name="phone"
                                                                        class="phone-with-country-code form-control"
                                                                        value="+1" minlength="10" maxlength="15"
                                                                        onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57 || event.charCode==43 ))"
                                                                        oninput="nonEditCuntryCode(this);">
                                                                    <span class="otpsendmsg_number"
                                                                        style="color: green; font-size: 18px;margin-left: 12px;"></span>
                                                                </div>

                                                                <div class="col-md-12 mb-4">
                                                                    <center>
                                                                        <button id="emailotpntn" class="btn btn-success"
                                                                            onclick="sendEmailOtp('<?= base_url('send-email-otp') ?>')">Login</button>
                                                                    </center>
                                                                </div>
                                                            </div>
                                                        </span>

                                                        <div class="row mobile-section otpmobilebox" id="mobiletoggle"
                                                            style="display:none;">
                                                            <div class="col-md-8 mb-4">
                                                                <input type="number" id="mobileotp" name="mobileotp"
                                                                    placeholder="Please enter OTP to continue."
                                                                    class="form-control" />
                                                                <span class="otpsendmsg_number_error"
                                                                    style="color: red; font-size: 18px;margin-left: 12px;"></span>
                                                            </div>
                                                            <div class="col-md-4 mb-4">
                                                                <button id="mobileotpverifybtn"
                                                                    class="btn btn-success verifyBtn"
                                                                    onclick="submitPhoneNumberAuthCode()">VERIFY</button>
                                                            </div>
                                                        </div>
                                                        <div id="recaptcha-container"></div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="d-flex justify-content-center text-center modal-footer">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <button type="submit" class="btn btn-warning" id="loginBtn">LOGIN</button>
                                            <button type="button" class="loginBtnClose btnClose btn btn-danger ms-2"
                                                data-dismiss="modal" hidden>CLOSE</button>
                                        </div>
                                    </div>
                                </div>

                            </form>
                        </div>

                        <div class="row">
                            <div class="col-12 ml-4 mb-2" style="padding-right: 3.5rem;">

                                <a href="javaScript:void(0);" onclick="openBoxlog('signup')" class="inLogin"
                                    style="float: left;color:#EE4D23">New User? Sign Up</a>
                                <a href="javaScript:void(0);" onclick="openBoxlog('forgot')" class="inLogin"
                                    style="float: right;color:#EE4D23">Forgot password ?</a>
                                <a href="javaScript:void(0);" onclick="openBoxlog('login')" class="inSignup">Already
                                    registered? Login</a>
                            </div>
                        </div>
                    </div>


                </div>
            </div>
        </div>


        <!-- Payment Modal -->
        <div class="modal fade" id="paymentModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle"
            aria-hidden="true" data-keyboard="false" data-backdrop="static">
            <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg" role="document">
                <div class="modal-content">


                    <form action="#" method="post" onsubmit="return SignupUser('<?= base_url('signup') ?>')">
                        <div class="modal-header text-center">
                            <h5 class="modal-title bottomborder modatTitle">CHECKOUT</h5>



                            <button type="button" class="btn-close modalCloseBtn" data-bs-dismiss="modal"
                                aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <div class="container">
                                <img src="<?= ApiBaseUrl()['url'] . $header_data[0]['leftImage'] ?>" class="img-fluid mb-4"
                                    height="100px" width="100px"
                                    style="display: block;margin-left: auto;margin-right: auto;">
                                <div class="row d-flex justify-content-center align-items-center">
                                    <div class="col-xl-12">
                                        <div class="row g-0">
                                            <div class="col-xl-12">
                                                <div class="row">
                                                    <div class="col-md-12 mb-4">
                                                        <table class="table table-responsive table-bordered text-center">
                                                            <thead>
                                                                <tr>
                                                                    <th>
                                                                        <h5
                                                                            style="font-size:20px;font-family: 'Open Sans', sans-serif!important;font-weight: 800;color: #DB9619;">
                                                                            SERVICE TYPE</h5>
                                                                    </th>
                                                                    <th>
                                                                        <h5
                                                                            style="font-size:20px;font-family: 'Open Sans', sans-serif!important;font-weight: 800;color: #DB9619;">
                                                                            TOTAL AMOUNT TO PAY</h5>
                                                                    </th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <tr>
                                                                    <td><span id="serviceName" class="serviceName"></span>
                                                                    </td>
                                                                    <td>
                                                                        <h4 id="servicePrice"></h4>
                                                                    </td>
                                                                    <input type="hidden" name="" id="serviceAmt">

                                                                    <input type="hidden" name="" id="serviceCategoryTypes">
                                                                    <input type="hidden" name="" id="serviceTypes">
                                                                    <input type="hidden" name="" id="dayTypes">
                                                                    <input type="hidden" name="" id="startDate">
                                                                    <input type="hidden" name="" id="startTime">
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>

                                                <div class="d-flex justify-content-center text-center modal-footer">
                                                    <div class="row">

                                                        <div class="col-md-12">
                                                            <div id="paypal-button-container"></div>
                                                            <button type="button"
                                                                class="btn PaymentClosebtn btn-danger ms-2"
                                                                data-dismiss="modal" hidden>CLOSE</button>
                                                        </div>


                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- End Registration Modal -->




        <div class="modal fade" id="exampleModal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-md" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"
                            style="position:absolute;z-index: 999">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h5 class="col-12 modal-title text-center" id="exampleModalLabel">Welcome</h5>
                    </div>
                    <div class="modal-body" style="text-align: justify">

                        <a class="" href="#"><img style="width:95%" alt="Devotee Portal"
                                src="<?= base_url('assets/payonline'); ?>/images/devotee_portal.jpeg" /></a>

                        <div class="row p1">
                            <div class="col-sm-12 p-1 text-left">

                                <ul class="list-group">
                                    <li class="list-group-item">Click on Create Account</li>
                                    <li class="list-group-item"></i>Enter your Name, Email and Phone number and click on
                                        register</li>
                                    <li class="list-group-item">Check your email for the activation or password reset link
                                        (check your spam folder)</li>
                                    <li class="list-group-item">If you see message, "Your email is already registered...",
                                        click on Reset Password link to generate a new password</li>
                                </ul>

                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>



    <?php } ?>
    <!-- END HARE LOGIN CHECK -->

    <div class="ldld full" style="z-index: 9999;"></div>


    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="<?= base_url('assets/js/intlTelInput.js?1549804213570'); ?>"></script>
    <script type="text/javascript">
        var loader = new ldLoader({
            root: ".ldld.full"
        });
    </script>
    <!-- <script>
  $('#email').popover();
</script> -->

    <?php if ($this->session->userdata('logged_in') == 1) {

    ?>

        <?php if (isset($paymentSetting) && $paymentSetting == 'MPI') {  ?>

            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>


            <?php $TokenPay  = @getclientInfoById()['data'][0]['MPItokenPay'];
            $MpiPayUrl = base_url('MPI_Payments/Paynow');
            if (isset($TokenPay) && $TokenPay != '') {
                $TokenPay = $TokenPay;
            ?>
                <script type="text/javascript" src="https://www.bridgepaynetsecuretx.com/Bridgepay.WebSecurity/TokenPay/js/tokenPay.js"></script>
            <?php
            } else {
                $TokenPay = 'tokenpay10579api20211508121542285';
                $MpiPayUrl = base_url('MPI_Payments/PaynowTest');
            ?>
                <script type="text/javascript" src="https://www.bridgepaynetsecuretest.com/WebSecurity/TokenPay/js/tokenPay.js"></script>
            <?php
            }

            ?>
            <script>
                $(document).ready(function() {
                    var $totalPrice = $('#sub-total');


                    <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                        var $acharyaInput = $('#acharya-sambhavana-input');
                        $acharyaInput.on('input', updateTotalPrice);
                    <?php } ?>

                    <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                        var $generalInput = $('#general-donation-input');
                        $generalInput.on('input', updateTotalPrice);
                    <?php } ?>



                    // Function to update the total price based on the input values
                    function updateTotalPrice() {
                        // Get the input values
                        var acharyaValue = 0;
                        var generalValue = 0;
                        <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                            var acharyaValue = parseFloat($acharyaInput.val().replace(/[^\d.-]/g, '')) || 0;
                        <?php } ?>
                        <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                            var generalValue = parseFloat($generalInput.val().replace(/[^\d.-]/g, '')) || 0;
                        <?php } ?>



                        // Get the initial total price
                        var initialTotalPrice = parseFloat(<?= @$totalAmount; ?>) || 0;

                        // Calculate the new total price
                        var newTotalPrice = initialTotalPrice + acharyaValue + generalValue;

                        // alert(initialTotalPrice);
                        // alert(newTotalPrice);
                        // alert($totalPrice);

                        // Update the total price element
                        $totalPrice.text('<?= $currencySymbol ?> ' + newTotalPrice.toFixed(2));
                    }

                    // Call updateTotalPrice once to include the initial total price
                    updateTotalPrice();


                    <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                        // Disable arrow key inputs
                        $acharyaInput.on('keydown', function(e) {
                            if (e.which === 38 || e.which === 40) {
                                e.preventDefault();
                            }
                        });
                        // Add validation to prevent input of negative values
                        $acharyaInput.on('keydown', function(e) {
                            if (e.key === '-' || e.key === '+') {
                                e.preventDefault();
                            }
                        });

                        // Add validation to prevent input of "+" and "e" characters
                        $acharyaInput.on('input', function() {
                            $acharyaInput.val($acharyaInput.val().replace(/[+e]/gi, ''));
                        });
                    <?php } ?>
                    <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                        $generalInput.on('keydown', function(e) {
                            if (e.which === 38 || e.which === 40) {
                                e.preventDefault();
                            }
                        });

                        $generalInput.on('keydown', function(e) {
                            if (e.key === '-' || e.key === '+') {
                                e.preventDefault();
                            }
                        });

                        $generalInput.on('input', function() {
                            $generalInput.val($generalInput.val().replace(/[+e]/gi, ''));
                        });
                    <?php } ?>

                });



                var tokenpay = TokenPay('<?= $TokenPay ?>');
                tokenpay.initialize({
                    dataElement: '#card',
                    errorElement: '#errorMessage',
                    amountElement: '#amount',
                    useStyles: false,
                    useACH: false,
                    disableZip: true,
                    disableCvv: false
                });

                var form = document.getElementById('paymentForm');
                form.addEventListener('submit', function(event) {

                    loader.on();

                    event.preventDefault();

                    tokenpay.createToken(function(result) {


                        console.log(result);


                        // var totalPriceText = $("#servicePrice").text();
                        var totalPriceText = $("#sub-total").text();
                        var mpi_zipcode = $("#zipcode").val();
                        var mpi_fname = $("#fname").val();
                        var mpi_address = $("#address").val();


                        var numericValue = totalPriceText.replace(/[^0-9.]/g, '');
                        var numericAmount = parseFloat(numericValue);

                        var totolAmt = numericAmount;
                        var advanceAmt = parseFloat($("#advanceAmt").val());

                        <?php
                        if ($advanceUpdateAmt > 0) {
                        ?>
                            // var pendingAmount = 0;
                            var advanceUpdateAmt = parseFloat(<?= @$advanceUpdateAmt; ?>)
                        <?php } else {
                        ?>
                            // var pendingAmount = totolAmt - advanceAmt;
                            var advanceUpdateAmt = advanceAmt;
                        <?php
                        }
                        ?>

                        // alert(totolAmt);


                        if (result.status == 'auth_success') {

                            var cart_data = '';



                            var paymentSource = 'MPI';



                            totalPrice = parseFloat(totolAmt);


                            var serviceName = $("#serviceName").text();
                            var service_Id = $("#serviceId").val();
                            var serviceAmount = $("#serviceAmt").val();
                            var serviceCategoryTypes = $("#serviceCategoryTypes").val();
                            var serviceTypes = $("#serviceTypes").val();
                            var dayTypes = $("#dayTypes").val();
                            var startDate = $("#startDate").val();
                            var startTime = $("#startTime").val();





                            var cart_data = '<?= json_encode($servicesDetail, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) ?>';

                            var fromSource = 'Pay_later';
                            $.ajax({
                                url: "<?= $MpiPayUrl ?>",
                                type: "POST",
                                dataType: "json",
                                data: {
                                    'token': result.token,
                                    'totolAmt': advanceUpdateAmt,
                                    'name': mpi_fname,
                                    'address': mpi_address,
                                    'zipcode': mpi_zipcode
                                },
                                success: function(mpicardpayment_response) {

                                    console.log(mpicardpayment_response.data);
                                    var paymentSource = 'MPI';

                                    var status = 'TEMP';

                                    var totalPrice = totolAmt;
                                    var acharya_sambhavana = parseFloat($('#acharya-sambhavana-input')
                                        .val()) || 0;
                                    var general_donation = parseFloat($('#general-donation-input')
                                        .val()) || 0;



                                    console.log(mpicardpayment_response.data.responseCode == 00000);
                                    if (mpicardpayment_response.data.responseCode == 00000) {

                                        // $.ajax({
                                        //     url: "<?= base_url('Services/AddToCart') ?>",
                                        //     type: "POST",
                                        //     dataType: "json",
                                        //     data: {
                                        //         'status': status,
                                        //         'paymentSource': paymentSource,
                                        //         'totalPrice': totalPrice,
                                        //         'acharya_sambhavana': acharya_sambhavana,
                                        //         'general_donation': general_donation,
                                        //         'cart_data': cart_data,
                                        //         'fromSource': fromSource
                                        //     },
                                        //     success: function(addtocart_response) {
                                        //         if (addtocart_response.statusCode == 1) {
                                        var status = '';
                                        if (advanceUpdateAmt == totolAmt) {
                                            status = 'COMPLETED';
                                        } else {
                                            status = 'PARTIALLY_COMPLETED';
                                        }


                                        var trnxId = "Payment completed~" +
                                            mpicardpayment_response.data
                                            .ReferenceNumber + "~" +
                                            mpicardpayment_response.data
                                            .cardType + "~" +
                                            mpicardpayment_response.data
                                            .maskedAccountNumber;
                                        <?php
                                        if ($advanceUpdateAmt > 0) {
                                        ?>
                                            var pendingAmount = 0;
                                        <?php } else {
                                        ?>
                                            var pendingAmount = totolAmt - advanceAmt;
                                        <?php
                                        }
                                        ?>
                                        $.ajax({
                                            url: "<?= base_url('FacilityPayonline/updateFacilityTransactionStatus/') . @$paymentId  ?>",
                                            type: "POST",
                                            dataType: "json",
                                            data: {
                                                'status': status,
                                                'transaction_id': trnxId,
                                                'paymentDescription': mpicardpayment_response,
                                                'advanceAmount': advanceAmt,
                                                'pendingAmount': pendingAmount,
                                                'totalAmount': advanceUpdateAmt,
                                            },
                                            success: function(
                                                update_transactionstatus_response
                                            ) {
                                                console.log("okkkkkk");
                                                if (update_transactionstatus_response
                                                    .statusCode == 1
                                                ) {


                                                    swal({
                                                            html: true,
                                                            text: "Payment Successfully Processed!",
                                                            title: "<span style='font-weight: 600;margin:5px;padding:5px'>Receipt #:</span> " +
                                                                update_transactionstatus_response
                                                                .envoiceNo,
                                                            type: "success",
                                                            confirmButtonText: 'OK',
                                                            confirmButtonColor: 'var(--main-color-new-theme)',
                                                        },
                                                        function() {
                                                            // window
                                                            //     .location
                                                            //     .reload();
                                                            window.location.href = "<?= base_url() ?>";
                                                        });
                                                    loader.off();

                                                }

                                            }
                                        });

                                        //         }
                                        //     }
                                        // });

                                    } else {

                                        // $.ajax({
                                        //     url: "<?= base_url('Services/AddToCart') ?>",
                                        //     type: "POST",
                                        //     dataType: "json",
                                        //     data: {

                                        //         'status': status,
                                        //         'paymentSource': paymentSource,
                                        //         'totalPrice': totalPrice,
                                        //         'acharya_sambhavana': acharya_sambhavana,
                                        //         'general_donation': general_donation,
                                        //         'cart_data': cart_data,
                                        //         'fromSource': fromSource
                                        //     },
                                        //     success: function(addtocart_response) {

                                        // if (addtocart_response.statusCode == 1) {

                                        // var pendingAmount = <?= @$paymentDetails['pendingAmount'] ?>;
                                        // advanceAmt = <?= @$paymentDetails['advanceAmount'] ?>;
                                        <?php
                                        if (isset($paymentDetails['pendingAmount'])) {
                                        ?>
                                            var pendingAmount = <?= @$paymentDetails['pendingAmount'] ?>;
                                        <?php } else {
                                        ?>
                                            var pendingAmount = totolAmt;
                                        <?php
                                        }
                                        ?>
                                        <?php
                                        if (isset($paymentDetails['pendingAmount'])) {
                                        ?>
                                            advanceAmt = <?= @$paymentDetails['advanceAmount'] ?>;
                                        <?php } else {
                                        ?>
                                            advanceAmt = 0;
                                        <?php
                                        }
                                        ?>
                                        var status = 'FAILED';
                                        var trnxId = "Payment failed~0~" +
                                            mpicardpayment_response.message;

                                        $.ajax({
                                            url: "<?= base_url('FacilityPayonline/updateFacilityTransactionStatus/') . @$paymentId  ?>",
                                            type: "POST",
                                            dataType: "json",
                                            data: {

                                                'status': status,
                                                'transaction_id': trnxId,
                                                'paymentDescription': mpicardpayment_response,
                                                'advanceAmount': advanceAmt,
                                                'pendingAmount': pendingAmount,
                                                'totalAmount': advanceUpdateAmt,
                                            },
                                            success: function(
                                                update_transactionstatus_response
                                            ) {
                                                if (update_transactionstatus_response
                                                    .statusCode == 1
                                                ) {


                                                    var original_string =
                                                        update_transactionstatus_response
                                                        .message;
                                                    var substring_to_replace =
                                                        "Payment failed~0~"

                                                    var new_string =
                                                        original_string
                                                        .replace(
                                                            substring_to_replace,
                                                            "");


                                                    swal({
                                                            html: true,
                                                            title: "Failed!",
                                                            text: "<span>" +
                                                                new_string +
                                                                "!<span><br><span style='font-weight: 600;margin:5px;padding:5px'>Receipt #:</span> " +
                                                                update_transactionstatus_response
                                                                .envoiceNo,
                                                            type: "error",
                                                            confirmButtonText: 'OK',
                                                            confirmButtonColor: 'var(--main-color-new-theme)',
                                                        },
                                                        function() {
                                                            window
                                                                .location
                                                                .reload();
                                                        });

                                                    loader.off();
                                                }

                                            }
                                        });

                                        // }
                                        // }
                                        // });
                                    }

                                }
                            });
                        } else {
                            alert('Please enter valid details');
                        }

                    }, function(result) {

                        console.log("error@@@: " + result.token);
                    });
                });
            </script>

        <?php } ?>

        <?php if (isset($paymentSetting) && $paymentSetting == 'MPITEST') {  ?>

            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>


            <?php

            $TokenPay = 'tokenpay10579api20211508121542285';
            $MpiPayUrl = base_url('MPI_Payments/PaynowTest');
            ?>
            <script type="text/javascript" src="https://www.bridgepaynetsecuretest.com/WebSecurity/TokenPay/js/tokenPay.js"></script>

            <script>
                $(document).ready(function() {
                    var $totalPrice = $('#sub-total');


                    <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                        var $acharyaInput = $('#acharya-sambhavana-input');
                        $acharyaInput.on('input', updateTotalPrice);
                    <?php } ?>

                    <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                        var $generalInput = $('#general-donation-input');
                        $generalInput.on('input', updateTotalPrice);
                    <?php } ?>



                    // Function to update the total price based on the input values
                    function updateTotalPrice() {
                        // Get the input values
                        var acharyaValue = 0;
                        var generalValue = 0;
                        <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                            var acharyaValue = parseFloat($acharyaInput.val().replace(/[^\d.-]/g, '')) || 0;
                        <?php } ?>
                        <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                            var generalValue = parseFloat($generalInput.val().replace(/[^\d.-]/g, '')) || 0;
                        <?php } ?>



                        // Get the initial total price
                        var initialTotalPrice = parseFloat(<?= @$totalAmount; ?>) || 0;

                        // Calculate the new total price
                        var newTotalPrice = initialTotalPrice + acharyaValue + generalValue;

                        // alert(initialTotalPrice);
                        // alert(newTotalPrice);
                        // alert($totalPrice);

                        // Update the total price element
                        $totalPrice.text('<?= $currencySymbol ?> ' + newTotalPrice.toFixed(2));
                    }

                    // Call updateTotalPrice once to include the initial total price
                    updateTotalPrice();


                    <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                        // Disable arrow key inputs
                        $acharyaInput.on('keydown', function(e) {
                            if (e.which === 38 || e.which === 40) {
                                e.preventDefault();
                            }
                        });
                        // Add validation to prevent input of negative values
                        $acharyaInput.on('keydown', function(e) {
                            if (e.key === '-' || e.key === '+') {
                                e.preventDefault();
                            }
                        });

                        // Add validation to prevent input of "+" and "e" characters
                        $acharyaInput.on('input', function() {
                            $acharyaInput.val($acharyaInput.val().replace(/[+e]/gi, ''));
                        });
                    <?php } ?>
                    <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                        $generalInput.on('keydown', function(e) {
                            if (e.which === 38 || e.which === 40) {
                                e.preventDefault();
                            }
                        });

                        $generalInput.on('keydown', function(e) {
                            if (e.key === '-' || e.key === '+') {
                                e.preventDefault();
                            }
                        });

                        $generalInput.on('input', function() {
                            $generalInput.val($generalInput.val().replace(/[+e]/gi, ''));
                        });
                    <?php } ?>

                });



                var tokenpay = TokenPay('<?= $TokenPay ?>');
                tokenpay.initialize({
                    dataElement: '#card',
                    errorElement: '#errorMessage',
                    amountElement: '#amount',
                    useStyles: false,
                    useACH: false,
                    disableZip: true,
                    disableCvv: false
                });

                var form = document.getElementById('paymentForm');
                form.addEventListener('submit', function(event) {

                    loader.on();

                    event.preventDefault();

                    tokenpay.createToken(function(result) {


                        console.log(result);


                        // var totalPriceText = $("#servicePrice").text();
                        var totalPriceText = $("#sub-total").text();
                        var mpi_zipcode = $("#zipcode").val();
                        var mpi_fname = $("#fname").val();
                        var mpi_address = $("#address").val();


                        var numericValue = totalPriceText.replace(/[^0-9.]/g, '');
                        var numericAmount = parseFloat(numericValue);

                        var totolAmt = numericAmount;
                        var advanceAmt = parseFloat($("#advanceAmt").val());
                        // var pendingAmount = totolAmt - advanceAmt;
                        <?php
                        if ($advanceUpdateAmt > 0) {
                        ?>
                            // var pendingAmount = 0;
                            var advanceUpdateAmt = parseFloat(<?= @$advanceUpdateAmt; ?>)
                        <?php } else {
                        ?>
                            // var pendingAmount = totolAmt - advanceAmt;
                            var advanceUpdateAmt = advanceAmt;
                        <?php
                        }
                        ?>

                        // alert(totolAmt);


                        if (result.status == 'auth_success') {

                            var cart_data = '';



                            var paymentSource = 'MPI';



                            totalPrice = parseFloat(totolAmt);


                            var serviceName = $("#serviceName").text();
                            var service_Id = $("#serviceId").val();
                            var serviceAmount = $("#serviceAmt").val();
                            var serviceCategoryTypes = $("#serviceCategoryTypes").val();
                            var serviceTypes = $("#serviceTypes").val();
                            var dayTypes = $("#dayTypes").val();
                            var startDate = $("#startDate").val();
                            var startTime = $("#startTime").val();





                            var cart_data = '<?= json_encode($servicesDetail, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) ?>';

                            var fromSource = 'Pay_later';
                            $.ajax({
                                url: "<?= $MpiPayUrl ?>",
                                type: "POST",
                                dataType: "json",
                                data: {
                                    'token': result.token,
                                    'totolAmt': advanceUpdateAmt,
                                    'name': mpi_fname,
                                    'address': mpi_address,
                                    'zipcode': mpi_zipcode
                                },
                                success: function(mpicardpayment_response) {

                                    console.log(mpicardpayment_response.data);
                                    var paymentSource = 'MPI';

                                    var status = 'TEMP';

                                    var totalPrice = totolAmt;
                                    var acharya_sambhavana = parseFloat($('#acharya-sambhavana-input')
                                        .val()) || 0;
                                    var general_donation = parseFloat($('#general-donation-input')
                                        .val()) || 0;



                                    console.log(mpicardpayment_response.data.responseCode == 00000);
                                    if (mpicardpayment_response.data.responseCode == 00000) {

                                        // $.ajax({
                                        //     url: "<?= base_url('Services/AddToCart') ?>",
                                        //     type: "POST",
                                        //     dataType: "json",
                                        //     data: {
                                        //         'status': status,
                                        //         'paymentSource': paymentSource,
                                        //         'totalPrice': totalPrice,
                                        //         'acharya_sambhavana': acharya_sambhavana,
                                        //         'general_donation': general_donation,
                                        //         'cart_data': cart_data,
                                        //         'fromSource': fromSource
                                        //     },
                                        //     success: function(addtocart_response) {
                                        //         if (addtocart_response.statusCode == 1) {
                                        var status = '';
                                        if (advanceUpdateAmt == totolAmt) {
                                            status = 'COMPLETED';
                                        } else {
                                            status = 'PARTIALLY_COMPLETED';
                                        }


                                        var trnxId = "Payment completed~" +
                                            mpicardpayment_response.data
                                            .ReferenceNumber + "~" +
                                            mpicardpayment_response.data
                                            .cardType + "~" +
                                            mpicardpayment_response.data
                                            .maskedAccountNumber;

                                        <?php
                                        if ($advanceUpdateAmt > 0) {
                                        ?>
                                            var pendingAmount = 0;
                                        <?php } else {
                                        ?>
                                            var pendingAmount = totolAmt - advanceAmt;
                                        <?php
                                        }
                                        ?>


                                        $.ajax({
                                            url: "<?= base_url('FacilityPayonline/updateFacilityTransactionStatus/') . @$paymentId  ?>",
                                            type: "POST",
                                            dataType: "json",
                                            data: {
                                                'status': status,
                                                'transaction_id': trnxId,
                                                'paymentDescription': mpicardpayment_response,
                                                'advanceAmount': advanceAmt,
                                                'pendingAmount': pendingAmount,
                                                'totalAmount': advanceUpdateAmt,
                                            },
                                            success: function(
                                                update_transactionstatus_response
                                            ) {
                                                console.log("okkkkkk");
                                                if (update_transactionstatus_response
                                                    .statusCode == 1
                                                ) {


                                                    swal({
                                                            html: true,
                                                            text: "Payment Successfully Processed!",
                                                            title: "<span style='font-weight: 600;margin:5px;padding:5px'>Receipt #:</span> " +
                                                                update_transactionstatus_response
                                                                .envoiceNo,
                                                            type: "success",
                                                            confirmButtonText: 'OK',
                                                            confirmButtonColor: 'var(--main-color-new-theme)',
                                                        },
                                                        function() {
                                                            // window
                                                            //     .location
                                                            //     .reload();
                                                            window.location.href = "<?= base_url() ?>";
                                                        });
                                                    loader.off();

                                                }

                                            }
                                        });

                                        //         }
                                        //     }
                                        // });

                                    } else {

                                        // $.ajax({
                                        //     url: "<?= base_url('Services/AddToCart') ?>",
                                        //     type: "POST",
                                        //     dataType: "json",
                                        //     data: {

                                        //         'status': status,
                                        //         'paymentSource': paymentSource,
                                        //         'totalPrice': totalPrice,
                                        //         'acharya_sambhavana': acharya_sambhavana,
                                        //         'general_donation': general_donation,
                                        //         'cart_data': cart_data,
                                        //         'fromSource': fromSource
                                        //     },
                                        //     success: function(addtocart_response) {

                                        // if (addtocart_response.statusCode == 1) {
                                            <?php
                                        if (isset($paymentDetails['pendingAmount'])) {
                                        ?>
                                            var pendingAmount = <?= @$paymentDetails['pendingAmount'] ?>;
                                        <?php } else {
                                        ?>
                                            var pendingAmount = totolAmt;
                                        <?php
                                        }
                                        ?>
                                        <?php
                                        if (isset($paymentDetails['pendingAmount'])) {
                                        ?>
                                            advanceAmt = <?= @$paymentDetails['advanceAmount'] ?>;
                                        <?php } else {
                                        ?>
                                            advanceAmt = 0;
                                        <?php
                                        }
                                        ?>
                                        var status = 'FAILED';
                                        var trnxId = "Payment failed~0~" +
                                            mpicardpayment_response.message;

                                        $.ajax({
                                            url: "<?= base_url('FacilityPayonline/updateFacilityTransactionStatus/') . @$paymentId  ?>",
                                            type: "POST",
                                            dataType: "json",
                                            data: {

                                                'status': status,
                                                'transaction_id': trnxId,
                                                'paymentDescription': mpicardpayment_response,
                                                'advanceAmount': advanceAmt,
                                                'pendingAmount': pendingAmount,
                                                'totalAmount': advanceUpdateAmt,
                                            },
                                            success: function(
                                                update_transactionstatus_response
                                            ) {
                                                if (update_transactionstatus_response
                                                    .statusCode == 1
                                                ) {


                                                    var original_string =
                                                        update_transactionstatus_response
                                                        .message;
                                                    var substring_to_replace =
                                                        "Payment failed~0~"

                                                    var new_string =
                                                        original_string
                                                        .replace(
                                                            substring_to_replace,
                                                            "");


                                                    swal({
                                                            html: true,
                                                            title: "Failed!",
                                                            text: "<span>" +
                                                                new_string +
                                                                "!<span><br><span style='font-weight: 600;margin:5px;padding:5px'>Receipt #:</span> " +
                                                                update_transactionstatus_response
                                                                .envoiceNo,
                                                            type: "error",
                                                            confirmButtonText: 'OK',
                                                            confirmButtonColor: 'var(--main-color-new-theme)',
                                                        },
                                                        function() {
                                                            window
                                                                .location
                                                                .reload();
                                                        });
                                                    loader.off();

                                                }

                                            }
                                        });

                                        // }
                                        // }
                                        // });
                                    }

                                }
                            });
                        } else {
                            alert('Please enter valid details');
                        }

                    }, function(result) {

                        console.log("error@@@: " + result.token);
                    });
                });
            </script>

        <?php } ?>


        <?php

        if (isset($paymentSetting) && $paymentSetting == 'CHARGEANYWHERE' && $paymentSeverOn == 1) { ?>

            <script type="text/javascript">
                $(document).ready(function() {



                    amt = $("#serviceAmt").val()

                    var advanceAmt = parseFloat($("#advanceAmt").val());
                    var pendingAmount = amt - advanceAmt;


                    var iframe = document.getElementById('paymentIframe');
                    var url =
                        "https://www.chargeanywhere.com/APIs/PayOnline.aspx?Version=2.0&MerchantId=<?= $CAW_MerchantId ?>&TerminalId=<?= $CAW_TerminalId ?>&Amount=" +
                        advanceAmt + "&Mode=0";
                    iframe.src = url;




                    var $totalPrice = $('#sub-total');


                    <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                        var $acharyaInput = $('#acharya-sambhavana-input');
                        $acharyaInput.on('input', updateTotalPrice);
                    <?php } ?>

                    <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                        var $generalInput = $('#general-donation-input');
                        $generalInput.on('input', updateTotalPrice);
                    <?php } ?>



                    // Function to update the total price based on the input values
                    function updateTotalPrice() {
                        // Get the input values
                        var acharyaValue = 0;
                        var generalValue = 0;
                        <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                            var acharyaValue = parseFloat($acharyaInput.val().replace(/[^\d.-]/g, '')) || 0;
                        <?php } ?>
                        <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                            var generalValue = parseFloat($generalInput.val().replace(/[^\d.-]/g, '')) || 0;
                        <?php } ?>



                        // Get the initial total price
                        var initialTotalPrice = parseFloat(<?= @$totalAmount; ?>) || 0;

                        // Calculate the new total price
                        var newTotalPrice = initialTotalPrice + acharyaValue + generalValue;

                        // alert(initialTotalPrice);
                        // alert(newTotalPrice);
                        // alert($totalPrice);

                        // Update the total price element
                        $totalPrice.text('<?= $currencySymbol ?> ' + newTotalPrice.toFixed(2));
                    }

                    // Call updateTotalPrice once to include the initial total price
                    updateTotalPrice();


                    <?php if (@$GeneralSettings['AcharyaSambhavana'] == 1) { ?>
                        // Disable arrow key inputs
                        $acharyaInput.on('keydown', function(e) {
                            if (e.which === 38 || e.which === 40) {
                                e.preventDefault();
                            }
                        });
                        // Add validation to prevent input of negative values
                        $acharyaInput.on('keydown', function(e) {
                            if (e.key === '-' || e.key === '+') {
                                e.preventDefault();
                            }
                        });

                        // Add validation to prevent input of "+" and "e" characters
                        $acharyaInput.on('input', function() {
                            $acharyaInput.val($acharyaInput.val().replace(/[+e]/gi, ''));
                        });
                    <?php } ?>
                    <?php if (@$GeneralSettings['GeneralDonationAmount'] == 1) { ?>
                        $generalInput.on('keydown', function(e) {
                            if (e.which === 38 || e.which === 40) {
                                e.preventDefault();
                            }
                        });

                        $generalInput.on('keydown', function(e) {
                            if (e.key === '-' || e.key === '+') {
                                e.preventDefault();
                            }
                        });

                        $generalInput.on('input', function() {
                            $generalInput.val($generalInput.val().replace(/[+e]/gi, ''));
                        });
                    <?php } ?>




                });


                window.addEventListener('message', handleMessage, false);
                window.addEventListener('message', chargeanywhere, false);

                function handleMessage(event) {

                    if (event.origin != "https://www.chargeanywhere.com") {
                        return;
                    }

                    var customData = event.data;


                }



                function chargeanywhere(event) {
                    //  function chargeanywhere() {

                    // alert('ok');

                    if (event.origin != "https://www.chargeanywhere.com") {
                        return;
                    }

                    // console.log(event);

                    var customData = event.data;
                    // var customData = {
                    //     ResponseCode: '000',
                    //     ResponseText: 'APPROVED',
                    //     ApprovalCode: '07100C',
                    //     PaymentType: '2',
                    //     TransactionType: 'Sale',
                    //     AuthorizedAmount: "1.00",
                    //     CardNumber: "xxxx8230",
                    //     CardType: "1",
                    //     GrandTotal: "1.00",
                    //     ReferenceNumber: "000121225582",
                    //     ServiceFee: "0.00",
                    //     TokenNumber: "2105504356377893",
                    // }


                    console.log(customData);

                    // alert('ok');

                    var paymentSource = 'CAW';


                    var grand_totalPrice = customData.GrandTotal;


                    var cleanedPrice = grand_totalPrice.replace(/[,$\s]/g, '');


                    var totalPrice = parseFloat(cleanedPrice);


                    var serviceName = $("#serviceName").text();
                    var service_Id = $("#serviceId").val();
                    var serviceAmount = $("#serviceAmt").val();
                    var serviceCategoryTypes = $("#serviceCategoryTypes").val();
                    var serviceTypes = $("#serviceTypes").val();
                    var dayTypes = $("#dayTypes").val();
                    var startDate = $("#startDate").val();
                    var startTime = $("#startTime").val();



                    var cart_data = '<?= json_encode($servicesDetail, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) ?>';

                    // alert(cart_data);

                    if (customData.ResponseCode === "000") {



                        // $.ajax({
                        //   url: "<?= base_url('Services/AddToCart') ?>",
                        //   type: "POST",
                        //   dataType: "json",
                        //   data: {

                        //     'status': status,
                        //     'paymentSource': paymentSource,
                        //     'totalPrice': totalPrice,
                        //     'acharya_sambhavana': acharya_sambhavana,
                        //     'general_donation': general_donation,
                        //     'cart_data': JSON.stringify(cart_data)
                        //   },
                        //   success: function(addtocart_response) {

                        //     console.log(addtocart_response);



                        //     if (addtocart_response.statusCode == 1) {

                        var status = '';
                        if (advanceAmt == totolAmt) {
                            status = 'COMPLETED';
                        } else {
                            status = 'PARTIALLY_COMPLETED';
                        }


                        var cardTypeCode = customData.CardType;
                        var cardTypeName = getCardTypeName(cardTypeCode);


                        var trnxId = "Payment completed~" + customData.ReferenceNumber + "~" + customData.cardTypeName + "~" +
                            customData.CardNumber + "~" + customData.ApprovalCode + "~" + customData.ReferenceNumber;
                        // console.log("<?= $_GET['serviceId'] ?>");
                        // alert("trnxId");
                        $.ajax({
                            url: "<?= base_url('Services/updateFacilityTransactionStatus/' . @$servicesDetail['paymentId'] . '/' . @$servicesDetail['tokenNumber']) ?>",
                            type: "POST",
                            dataType: "json",
                            data: {

                                'status': status,
                                'transaction_id': trnxId,
                                'paymentDescription': customData,
                                'advanceAmount': advanceAmt,
                                'pendingAmount': pendingAmount
                            },
                            success: function(update_transactionstatus_response) {
                                // console.log(update_transactionstatus_response);
                                // alert("trnxId3");
                                // alert(update_transactionstatus_response.statusCode);
                                if (update_transactionstatus_response.statusCode == 1) {
                                    console.log(update_transactionstatus_response);
                                    // alert(update_transactionstatus_response.envoiceNo);

                                    swal({
                                            html: true,
                                            title: "Payment Successfully Processed!",
                                            text: "<span style='font-weight: 600;margin:5px;padding:5px'>Receipt #:</span> " +
                                                update_transactionstatus_response.envoiceNo,
                                            type: "success",
                                            confirmButtonText: 'OK',
                                            confirmButtonColor: 'var(--main-color-new-theme)',
                                        },
                                        function() {
                                            // window.location.reload();

                                            if (location.href.indexOf('Payonline') != -1) {
                                                window.location.href = "<?= base_url('logout'); ?>";
                                            } else if (location.href.indexOf('Reschedule') != -1) {

                                                window.location.href =
                                                    "<?= base_url('Reschedule/RescheduleProcess'); ?>";
                                            } else {
                                                window.location.reload();
                                            }


                                        });


                                }

                            }
                        });

                        //     }
                        //   }
                        // });



                    } else {

                        // $.ajax({
                        //   url: "<?= base_url('Services/AddToCart') ?>",
                        //   type: "POST",
                        //   dataType: "json",
                        //   data: {

                        //     'status': 'TEMP',
                        //     'paymentSource': paymentSource,
                        //     'totalPrice': totalPrice,
                        //     'acharya_sambhavana': acharya_sambhavana,
                        //     'general_donation': general_donation,
                        //     'cart_data': JSON.stringify(cart_data)
                        //   },
                        //   success: function(addtocart_response) {

                        //     if (addtocart_response.statusCode == 1) {
                        var status = 'FAILED';

                        var cardTypeCode = customData.CardType;
                        var cardTypeName = getCardTypeName(cardTypeCode);

                        var trnxId = "Payment failed~0~" + customData.ResponseText + "~" + customData.cardTypeName + "~" +
                            customData.CardNumber + "~" + customData.ApprovalCode + "~" + customData.ReferenceNumber;

                        $.ajax({
                            url: "<?= base_url('Services/updateFacilityTransactionStatus/' . @$servicesDetail['paymentId'] . '/' . @$servicesDetail['tokenNumber']) ?>",
                            type: "POST",
                            dataType: "json",
                            data: {

                                'status': status,
                                'transaction_id': trnxId,
                                'paymentDescription': customData,
                                'advanceAmount': advanceAmt,
                                'pendingAmount': pendingAmount
                            },
                            success: function(update_transactionstatus_response) {
                                if (update_transactionstatus_response.statusCode == 1) {

                                    var original_string = update_transactionstatus_response.message;
                                    var substring_to_replace = "Payment failed~0~"

                                    var new_string = original_string.replace(substring_to_replace, "");

                                    swal({
                                            html: true,
                                            title: "Failed!",
                                            text: "<span>" + new_string +
                                                "!<span><br><span style='font-weight: 600;margin:5px;padding:5px'>Receipt #:</span> " +
                                                update_transactionstatus_response.envoiceNo,
                                            type: "error",
                                            confirmButtonText: 'OK',
                                            confirmButtonColor: 'var(--main-color-new-theme)',
                                        },
                                        function() {
                                            window.location.reload();
                                        });


                                }

                            }
                        });

                        //     }
                        //   }
                        // });
                    }
                }

                function getCardTypeName(cardTypeCode) {
                    switch (cardTypeCode) {
                        case "1":
                            return "VISA";
                        case "2":
                            return "MASTERCARD";
                        case "3":
                            return "AMEX";
                        case "4":
                            return "DISCOVER";
                        case "5":
                            return "DINERS CLUB";
                        case "6":
                            return "JCB";
                        case "9":
                            return "DINERSCLUB";
                        case "10":
                            return "MAESTRO";
                        default:
                            return "Unknown";
                    }
                }
            </script>

        <?php } ?>
    <?php } ?>

    <script>
        function validateMinimumPay(inputElement) {
            // Get the current value, min, and max from the input element
            let value = parseFloat(inputElement.value);
            let minValue = parseFloat(inputElement.min);
            let maxValue = parseFloat(inputElement.max);

            // Ensure the value has 2 decimal places, but only if it's not NaN
            if (!isNaN(value)) {
                value = parseFloat(value).toFixed(2);
            }

            // Check if the value is valid (not blank, within min and max range)
            if (isNaN(value) || value < minValue || value > maxValue || inputElement.value === "") {
                alert("Please enter a valid value between " + minValue.toFixed(2) + " and " + maxValue.toFixed(2));
                inputElement.value = ""; // Clear the input if invalid
                document.getElementById('paynowbtn').disabled = true; // Disable button
            } else {
                inputElement.value = value; // Set the value back with 2 decimal places
                document.getElementById('paynowbtn').disabled = false; // Enable button
            }
        }
    </script>

    <?php $this->load->view('includes/scriptForPayonline.php') ?>