<div class="modal fade" id="add-edit-rent-type-modal" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label h-labels text-left bold hidden"><?php echo CommonLanguage::getMessage('add_rent_type'); ?></h5>
                <h5 class="edit-label h-labels text-left bold hidden"><?php echo CommonLanguage::getMessage('edit_rent_type'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="rent_type_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='rent_type_id' id='rent_type_id'/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('rent_type_alert'); ?>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('rent_type_name'); ?></label>
                            <span class="red-star">*</span>
                            <input class="line_name form-control" id="rent_type_name" name="rent_type_name" type="text" required  />
                        </div>
                    </div> 
                    <div class="row form-group">
                        <div class="col-md-12 ">
                            <label><?php print CommonLanguage::getMessage('Price'); ?></label>
                            <span class="red-star">*</span>
                            <input class="form-control" id="rent_type_price" name="rent_type_price" type="number" min="0" required />
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12 ">
                            <label><?php print CommonLanguage::getMessage('currency'); ?></label>
                            <span class="red-star">*</span>
                            <input class="full-width" id="currency_id" name="currency_id" type="hidden" required />
                        </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-bg-success-darker text-white" id="submit_rent_type"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('rentTypeLoader'); ?>
        </div>
    </div>
</div>
<script>
    $(function(){
        $('#currency_id').val(<?php echo smc_session()['local_currency']; ?>).attr('data-select-name','<?php echo smc_session()['local_currency_name']; ?>'+' '+'<?php echo smc_session()['local_currency_symbol']; ?>')
        build_select2($("#currency_id"), "xhr/CommonSearch?col_name=concat_ws(' ',Currency_Name,Currency_Symbol)&col_id=Currency_ID&table=tbl_common_currency");
        $("#tableWithSearch").on("click", ".edit_rent_type", function () {
            var rent_type_id = $(this).attr('data-id');
            $("#rent_type_id").val(rent_type_id);
            $("#add-edit-rent-type-modal .edit-label").removeClass('hidden');
            CommonViewById('GarageAjax/getRentTypeData', {rent_type_id: rent_type_id},
                           '#rentTypeLoader', function (response) {
                $('#rent_type_name').val(response[0].rent_type_name)
                $('#rent_type_price').val(response[0].rent_type_price)
                $('#currency_id').val(response[0].currency_id).attr('data-select-name',response[0].Currency_Name+' '+response[0].Currency_Symbol)
                build_select2($("#currency_id"), "xhr/CommonSearch?col_name=concat_ws(' ',Currency_Name,Currency_Symbol)&col_id=Currency_ID&table=tbl_common_currency");
            });
        });
        $("#new_rent_type").on("click", function () {
            $("#rent_type_id").val(0);
            $("#add-edit-rent-type-modal .add-label").removeClass('hidden');
        });
        $("#submit_rent_type").on("click", function () {
            if (!$("#rent_type_form").valid())
                return;
            var Data = new FormData(document.getElementById("rent_type_form"));
            $("#rentTypeLoader").removeClass('hidden');
            $.ajax({
                url: "GarageAjax/submitRentType",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            hideModalAlert('add-edit-rent-type-modal', 'rent_type_alert');
                            RebuildDataTable($('.panel-heading .panel-title').html(), [0,1], 'GarageAjax/getRentType');
                        }
                        AddAlert("#rent_type_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#rentTypeLoader").addClass('hidden');
                }
            });
        });  
    });
</script>