
<div class="container-fluid container-fixed-lg bg-white">
    <?php echo Forms::ModalLoader('MedicalEmployeeLoader') ?>
    <div class="panel panel-transparent">
        <div class="panel-heading">

            <h5 class="bold"> <?php print CommonLanguage::getMessage('medical_employee'); ?></h5>
            <div id="Medical_Employee_Alert" ></div>
            <div class="col-md-12 p-b-10">
                <div class="col-md-3">

                    <label><?php echo CommonLanguage::getMessage('employee') ?></label><span class="red-star">*</span>
                    <input type="hidden" class="full-width Employee_ID" required name="Employee_ID" id="Employee_ID" value="<?= $IsEdit ? $data[0]['Employee_ID'] : '' ?>"  data-select-name=<?= json_encode($IsEdit ? $data[0]['Employee_Name'] : "") ?>/>

                </div>
                <div class="col-md-3">

                    <label><?php echo CommonLanguage::getMessage('Date') ?></label><span class="red-star">*</span>
                    <input type="text" class="full-width form-control mdcl_employee_date" value="<?php echo $IsEdit ? $data[0]['mdcl_employee_date'] : $today; ?>" id="mdcl_employee_date" required />

                </div>
            </div>

            <div class="col-md-12 mdcl_employee p-b-10" id="mdcl_employee">
                <?php foreach ($Medical_Type as $item) { ?>
                    <div class="col-md-12 mdcl_employee_data p-b-10">
                        <div class="col-md-4">
                            <label><?php echo CommonLanguage::getMessage('medical_type_name') ?></label>
                            <input type='text' data-id='<?php echo $item['mdcl_type_id'] ?>' value='<?php echo $item['mdcl_type_name'] ?>' class='form-control medical_type_id' readonly />
                        </div>
                        <div class="col-md-4">
                            <label><?php echo CommonLanguage::getMessage('medical_name') ?></label><span class="red-star">*</span>
                            <input type="hidden" class=" full-width mdcl_place_id" value='<?php echo (isset($data['mdcl_emp_dtls'][$item['mdcl_type_id']]['mdcl_place_id']) ? $data['mdcl_emp_dtls'][$item['mdcl_type_id']]['mdcl_place_id'] : '') ?>' data-select-name='<?= (isset($data['mdcl_emp_dtls'][$item['mdcl_type_id']]['mdcl_place_name']) ? $data['mdcl_emp_dtls'][$item['mdcl_type_id']]['mdcl_place_name'] : '') ?>' id="mdcl_place_id"   name="mdcl_place_id"/>

                        </div>
                        <div class="col-md-3">
                            <label><?php echo CommonLanguage::getMessage('amount') ?></label><span class="red-star">*</span>
                            <input type="number" min="0" class="form-control mdcl_total_iswa" value='<?php echo (isset($data['mdcl_emp_dtls'][$item['mdcl_type_id']]['mdcl_emp_dtl_total']) ? $data['mdcl_emp_dtls'][$item['mdcl_type_id']]['mdcl_emp_dtl_total'] : '') ?>' id="mdcl_total_iswa"  required/>
                            
                        </div>
                        
                   
                    </div>

                <?php } ?>
            </div>
            <div class="col-md-12">
                <div class="form-group">
                    <label><?php echo CommonLanguage::getMessage('note') ?></label>
                    <textarea class="mdcl_employee_note form-control" id="mdcl_employee_note"><?php echo $IsEdit ? $data[0]['mdcl_employee_note'] : "" ?></textarea>

                </div>
            </div>



            <div class="col-md-12 p-b-10 ">
                <button class="btn btn-success pull-right" id='SubmitMedicalEmployee'><?php print CommonLanguage::getMessage('Save') ?></button>
            </div>
        </div>
    </div>
</div>
<script>

    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
            IsEdit = <?php echo json_encode($IsEdit); ?>,
            id = <?php echo json_encode($id); ?>,
            is_actual = <?php echo json_encode($is_actual); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>;
    var is_empty = false;
    $(function () {
        build_select2($('.Employee_ID'), 'xhr/employeeSearch?is_actual='+is_actual);
        build_select2($('.mdcl_place_id'), 'xhr/medicalPlaceSearch');
        $('#mdcl_employee_date').datetimepicker({format: 'YYYY-MM-DD', useCurrent: false, extraFormats: ['DD-MM-YYYY']});
        $("#SubmitMedicalEmployee").on("click", function () {
            var Data = {
                Employee_ID: $('#Employee_ID').val(),
                mdcl_employee_date: $('#mdcl_employee_date').val(),
                mdcl_employee_note: $('#mdcl_employee_note').val(),
                mdcl_employee_data: []
            };
            $('#mdcl_employee > .mdcl_employee_data').each(function () {
                var me = $(this);
                var mdcl_place_id = me.find('#mdcl_place_id').val(),
                        mdcl_total_iswa = parseFloat(me.find('.mdcl_total_iswa').val());
                if (mdcl_place_id != "" && mdcl_total_iswa != "") {
                    Data.mdcl_employee_data.push({
                        mdcl_type_id: me.find('.medical_type_id').attr('data-id'),
                        mdcl_place_id: mdcl_place_id,
                        mdcl_emp_dtl_total: mdcl_total_iswa
                    });
                }
            });
            if (Data.Employee_ID == '' || Data.mdcl_employee_data.length == 0) {
                is_empty = true;
                $('#Medical_Employee_Alert').attr('class', ' alert alert-danger').empty().html(Required_Fields)
                return;
            }
            if (IsEdit) {
                Data.mdcl_employee_id = id;
            }
            $.ajax({
                url: 'HRMAjax/medicalEmployeeRequest',
                data: Data,
                type: 'POST',
                complete: function (v, v1) {
                    if (v1 == 'success' && v.responseText == 'ok') {

                        $('#Medical_Employee_Alert').attr('class', ' alert alert-success').empty().html(Submitted_Successfully)
                        $('#SubmitMedicalEmployee').attr('disabled', 'disabled')
                    } else {

                        $('#Medical_Employee_Alert').attr('class', ' alert alert-danger').empty().html(Failed_Submit)
                    }
                }
            });
        });
    });

</script>   