
<style>
     #payment_form .col-md-6{
        display:grid;
    }
</style>
<div class="modal fade" id="collection_modal" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <div class="modal-header text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="text-left bold "><?php echo CommonLanguage::getMessage('collection'); ?></h5>
            </div>
            <div class="modal-body form-group">
                <form id="payment_form" method="POST" onsubmit="return false">
                    <input type="hidden" name="pay_detail_id" id="pay_detail_id" />
                    <input type="hidden" name="collection_id" id="collection_id" />
                    <input type="hidden" name="pay_acc_id" id="pay_acc_id" />

                    <div class="row">
                        <?php echo Forms::AlertDiv('payment_alert'); ?>
                    </div>
                    <div class="row ">
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('Date'); ?> <span class="red-star">*</span></label>
                            <input type="text" id="collection_date" name="collection_date" value="<?php echo $today; ?>" class="form-control " autocomplete="off" required>
                        </div>
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('account'); ?><span class="red-star">*</span></label>
                            <input type="hidden" id="account_id" name="account_id"  autocomplete="off" required>
                        </div>
                    </div>
                    <div class="row ">
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('amount'); ?><span class="red-star">*</span></label>

                            <input type="number" min="0" step="any" id="pay_amount" name="pay_amount" class="form-control " autocomplete="off" required>
                        </div>
                         <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('Currency'); ?> <span class="red-star">*</span></label>
                            <select class="full-width " id="currency_id" disabled data-init-plugin="select2">
                                <option value="0"><?php echo CommonLanguage::getMessage('select'); ?></option>
                                <?php foreach ($currency_list as $currency): ?>
                                    <option mysymbol="<?php echo $currency['Currency_Symbol']; ?>"  value="<?php echo $currency['Currency_ID']; ?>" ><?php echo $currency['Currency_Name'] . " - " . $currency['Currency_Code']; ?></option>
                                <?php endforeach; ?>
                            </select>                       
                        </div>
                     
                    </div>
                   
                    <div class="row ">
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('exchange_rate') . ' (' . smc_session()['local_currency_symbol'] . ')'; ?></label>
                            <input type="text" id="current_rate" name="current_rate" class="form-control " autocomplete="off" >
                        </div>
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('exchange_rate') . '(' . smc_session()['second_currency']['symbol'] . ')'; ?></label>
                            <input type="text" id="second_currency_rate" name="second_currency_rate" class="form-control " autocomplete="off" >
                        </div>
                    </div>
                     <div class="row ">
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('commission_amount'); ?></label>
                            <input type="number" min="0" step="any" id="commission_amount" name="commission_amount" class="form-control " autocomplete="off" >
                        </div>
                            <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('commession_account'); ?></label>
                            <input type="hidden" id="commission_acc_id" name="commission_acc_id"  autocomplete="off" >
                        </div>
                       
                    </div>
                    <div class="row ">
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('branch'); ?></label>
                            <input type="text" id="branch_id" name="branch_id"  autocomplete="off" >
                        </div>
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('project'); ?></label>
                            <input type="text" id="project_id" name="project_id"  autocomplete="off" >
                        </div>
                    </div>
                    <div class="row ">
                        <div class="col-md-6">
                            <label><?php print CommonLanguage::getMessage('job'); ?></label>
                            <input type="text" id="job_id" name="job_id"  autocomplete="off" >
                        </div>

                    </div>
                    <div class="row ">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('note'); ?></label>
                            <textarea id="note" name="note" class="form-control " autocomplete="off" ></textarea>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-complete" id="submit_payment"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('paymentLoader'); ?>
        </div>
    </div>
</div>
<script>
    $(function(){
               build_select2($("#account_id"), ("xhr/accIDSearch?type=Payment"))
        build_select2($("#commission_acc_id"), ("xhr/accIDSearch?type=Payment"))
        build_select2($("#branch_id"), "xhr/CommonSearch?col_id=branch_id&col_name=branch_name&table=tbl_organization_branches")
        build_select2($("#job_id"), "ACCAjax/JobSearch")
        build_select2($("#project_id"), "ACCAjax/projectSearch")
         $("#submit_payment").on("click", function () {
            if (!$("#payment_form").valid())
                return;
            var Data = new FormData(document.getElementById("payment_form"));
            Data.append('is_actual', is_actual);
            Data.append('currency_id', $("#currency_id").val());
            $("#paymentLoader").removeClass('hidden');
            $.ajax({
                url: "ACCAjax/submit_collection",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success' && jqXHR.responseJSON == 'ok') {
                        $("#payment_alert").attr("class", "alert alert-success").html('<?php echo CommonLanguage::getMessage('Submitted_Successfully')?>')
                        setTimeout(function () {
                            $("#payment_alert").addClass("hidden")
                            $("#collection_modal").modal("hide")
                        }, 1500)
                    } else {
                        $("#payment_alert").attr("class", "alert alert-danger").html('<?php echo CommonLanguage::getMessage('Failed_Submit')?>')

                    }
                    $("#paymentLoader").addClass('hidden');
                }
            })
        })
    })
</script>