<div class="modal fade stick-up " data-backdrop="static" id="add_vehicle_checkup" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog " style="width:50%;">
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold"><?php print CommonLanguage::getMessage('checkup'); ?></h5>
                <div id="addchecupAlert"></div>
            </div>
            <div class="modal-body">
                <form id="add_vehicle_checkupForm" method="POST" onsubmit="return false">
                    <input type="hidden" class="Is_Edit" id="IS_Edit" value="0"/> 
                    <div class="row ">
                        <div class="col-md-12 form-group" >
                            <div class="col-md-6">
                                <label><?php echo CommonLanguage::getMessage('vehicle') ?></label><span class="red-star">*</span>
                                <input type="hidden" class="full-width vehicle_id" id="vehicle_id" />
                            </div>
                            <div class="col-md-6">
                                <label><?php echo CommonLanguage::getMessage('Date') ?></label><span class="red-star">*</span>
                                <input type="text" class="form-control checkup_date" id="checkup_date" value="<?php echo $today ?>"/>
                            </div>

                        </div>
                    </div>
                    <div class="row ">
                        <div class="col-md-12 form-group" >
                            <div class="col-md-6">
                                <label><?php echo CommonLanguage::getMessage('milage') ?></label><span class="red-star">*</span>
                                <input type="number" min="0" class="form-control  vehicle_milage" id="vehicle_milage" />
                            </div>
                            <div class="col-md-6">
                                <label><?php echo CommonLanguage::getMessage('Action') ?></label><span class="red-star">*</span>
                                <div class="radio radio-success " id="vehicle_action">
                                    <input type="radio" value="0"  name="vehicle_action"  id="checkup">
                                    <label for="checkup"><?php print CommonLanguage::getMessage('checkup'); ?></label>
                                    <input type="radio"  value="1" name="vehicle_action"  id="change_oil">
                                    <label for="change_oil"><?php print CommonLanguage::getMessage('oil_exchange'); ?></label>
                                    <input type="radio"  value="2" name="vehicle_action"  id="maintenance">
                                    <label for="maintenance"><?php print CommonLanguage::getMessage('maintenance'); ?></label>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="row ">
                        <div class="col-md-12 form-group" >

                            <label><?php echo CommonLanguage::getMessage('note') ?></label>
                            <textarea class="form-control checkup_note" id="checkup_note" style="resize:none"></textarea>

                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" id="CloseCheckup" data-dismiss="modal"   > <?php print CommonLanguage::getMessage('Close'); ?> </button>
                <button class="btn btn-bg-success-darker" id="SubmitCheckup"  > <?php print CommonLanguage::getMessage('Save'); ?>   </button>
            </div>
        </div>
    </div>
</div>


<script>
    var Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
        Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>;
            var vehicle_checkup_id;
    $(function () {
        //    build_select2($('#vehicle_id'), 'xhr/CommonSearch?col_id=Vehicle_ID&col_name=concat(Vehicle_Code,"-",Vehicle_Registration_Number)&table=tbl_garage_vehicle');
        build_select2($('#vehicle_id'), 'xhr/truckSearch');
        $('#checkup_date').datepicker({autoclose: true});
        $('#SubmitCheckup').on('click', function () {
            var Data = {
                vehicle_id: $('#vehicle_id').val(),
                checkup_date: $('#checkup_date').val(),
                vehicle_milage: $('#vehicle_milage').val(),
                vehicle_action: $('input[name=vehicle_action]:checked').val(),
                checkup_note: $('#checkup_note').val()
            };
            if (Data.vehicle_id == '' || Data.checkup_date == '' || Data.vehicle_milage == '' || Data.vehicle_action == undefined) {
                $('#addchecupAlert').attr('class', 'alert alert-danger').empty().html(Required_Fields);
                return false;
            }

            if ($('#IS_Edit').val() == 1) {
                Data.vehicle_checkup_id = vehicle_checkup_id;
            }
            $.ajax({
                url: "GarageAjax/addVehicleCheckupRequest",
                data: Data,
                dataType: 'JSON',
                type: 'post',
                complete: function (v, v2) {
                    if (v2 == 'success') {
                        if (v.responseJSON[0] == 'ok') {
                            $('#addchecupAlert').attr('class', 'alert alert-success').empty().html(Submitted_Successfully);
                            RebuildDataTable(title, [0, 1, 2, 3], 'GarageAjax/vehiclecheckupListRequest');
                            setTimeout(function () {
                                $('#addchecupAlert').addClass('hidden');
                                $('#add_vehicle_checkup').modal('hide');
                                $('#IS_Edit').val('0');
                            }, 800);
                        } else {
                            $('#addchecupAlert').attr('class', 'alert alert-danger').empty().html(v.responseJSON[1]);
                        }
                    } else {
                        $('#addchecupAlert').attr('class', 'alert alert-danger').empty().html(Failed_Submit);
                    }
                }
            });
        });

        $('#CloseCheckup').on('click', function () {
            $('#IS_Edit').val('0');
        });
    });
</script>  