
<div class="container-fluid container-fixed-lg bg-white">
    <?php echo Forms::ModalLoader('MedicalLocationLoader') ?>
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <input type='hidden' id="IS_Edit" value="<?php echo $IsEdit ? 1 : 0?>"/>
            <h5 class="bold"> <?php print CommonLanguage::getMessage('medical_location'); ?></h5>
            <div id="Medical_Location_Alert" ></div>


            <div class='col-md-12 p-b-15'>
                <div class='col-md-4'>
                    <label><?php print CommonLanguage::getMessage('medical_name') ?></label><span class="red-star">*</span>
                    <input type='text' class='form-control medical_location_name' value='<?php echo $IsEdit ? $data[0]['mdcl_place_name']:""?>' id='medical_location_name' placeholder="<?php print CommonLanguage::getMessage('medical_name') ?>" />
                </div>
            </div>



            <div class="col-md-12 p-b-15" id='MedicalLocation'>

                <?php foreach ($Medical_Type as $item) { ?>
                    <div class="col-md-12 medical_place p-t-5">
                        <div class="col-md-2 " >
                            <input type='text' data-id='<?php echo $item['mdcl_type_id'] ?>' value='<?php echo $item['mdcl_type_name'] ?>' class='form-control medical_type_name' readonly />
                        </div>
                        <div class="col-md-1 p-l-10">
                            
                            <input type='number' min='0' max='100'  value='<?php echo (isset($data['place_dtls'][$item['mdcl_type_id']]['mdcl_place_details_percent'])?$data['place_dtls'][$item['mdcl_type_id']]['mdcl_place_details_percent']:$item['mdcl_type_percent']); ?>' class='form-control medical_type_percent'  /> 
                                                        

                        </div>
                        <div class="col-md-1 p-r-0"  >
                            <span class='red-star'>*</span>
                            %
                        </div>
                    </div>
                <?php } ?>
            </div>
            <div class="col-md-12 p-b-10">
                <button class="btn btn-success pull-left" id='SubmitMedicalLocation'><?php print CommonLanguage::getMessage('Save') ?></button>
            </div>
        </div>
    </div>
</div>
<script>

    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Required_Fields_Percnt = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields_Percnt')); ?>,
               id = <?php echo json_encode($id)?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>;
    $(function () {
        $('#SubmitMedicalLocation').on('click', function () {
            var is_empty = false;
            var Data = {
                mdcl_place_name: $('#medical_location_name').val(),
                mdcl_place_details: [],
                Is_Edit : $('#IS_Edit').val()
            };
            $("#MedicalLocation > .medical_place").each(function (i, v) {

                var me = $(this);
                var prcnt_val = parseFloat(me.find('.medical_type_percent').val());
                if (!isNaN(prcnt_val) && prcnt_val>= 0 && prcnt_val <= 100) {
                    Data.mdcl_place_details.push({
                        mdcl_type_id: me.find('.medical_type_name').attr('data-id'),
                        mdcl_place_details_percent: me.find('.medical_type_percent').val()
                    });
                    me.find('.medical_type_percent').removeClass('error');
                }
                else{
                    is_empty = true;
                    me.find('.medical_type_percent').addClass('error');
                }
            })
            if (Data.mdcl_place_name == '') {
                is_empty = true;
            }
            if (is_empty) {
                $('#Medical_Location_Alert').attr('class', ' alert alert-danger').html(Required_Fields_Percnt)
                return false;
            }
             if(Data.Is_Edit == 1){
                
                Data.mdcl_place_id = id
            }

          
            
           
            $.ajax({
                url: 'HRMAjax/MedicalPlaceRequest',
                data: Data,
                type: 'POST',
                complete: function (v, v1) {
                    if (v1 == 'success' && v.responseText == 'ok') {

                        $('#Medical_Location_Alert').attr('class', ' alert alert-success').html(Submitted_Successfully)

                        setTimeout(function () {
                            $("#Medical_Location_Alert").addClass("hidden")
                        }, 800);
                    } else {
                        $('#Medical_Location_Alert').attr('class', ' alert alert-danger').html(Failed_Submit)
                    }

                }
            })

        })
















    })

</script>   