<script src="<?php echo THEME_PATH ?>js/jquery-barcode.js"></script>
<script src="<?php echo THEME_PATH ?>js/jQuery.print.js"></script>
<style>
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}
</style>
<div id="Barcode" ></div>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div id="barcodealert"></div>
            <div class="panel-title"> <?php print CommonLanguage::getMessage('print_barcodes'); ?></div>
        </div>
        <div class="panel-heading">
             <div class="panel-title"> 
                 <label class="switch">
                    <input id="check_bar" type="checkbox" checked>
                    <span class="slider round"></span>
                </label>
             </div>
        </div>
        <div class="panel-body">
        <form id="add_barcode_form" method="POST" onsubmit="return false">   
            <div class="row m-b-20 form-group">
                <div class="col-md-2">
                    <label><?php print CommonLanguage::getMessage('barcode'); ?></label> 
                    <input type="text"  id="myBarcode" name="myBarcode" class="form-control  myBarcode barcode_change">
                </div>
                <div class="col-md-2">
                    <label><?php print CommonLanguage::getMessage('item_name'); ?></label> 
                    <input type="text"  id="item_name" name="item_name" class="form-control">
                </div>
                <div class="col-md-2 ">
                    <label><?php print CommonLanguage::getMessage('text_right'); ?></label> 
                    <input type="text"  id="text_right" name="text_right" class="form-control  "/>
                </div>
                <div class="col-md-2 ">
                    <label><?php print CommonLanguage::getMessage('text_left'); ?></label> 
                    <input type="text"  id="text_left" name="text_left" class="form-control  "/>
                </div>
                <div class="col-md-2 ">
                    <label><?php print CommonLanguage::getMessage('text_right_bottom'); ?></label> 
                    <input type="text"  id="text_right_bo" name="text_right_bo" class="form-control  "/>
                </div>
                <div class="col-md-2 ">
                    <label><?php print CommonLanguage::getMessage('text_left_bottom'); ?></label> 
                    <input type="text"  id="text_left_bo" name="text_left_bo" class="form-control  "/>
                </div>
                <div hidden class="col-md-2 template_div">
                    <label><?php print CommonLanguage::getMessage('template'); ?></label> 
                    <input type="hidden" value="67" id="template_id" name="template_id" class="full-width"/>
                </div>
            </div>
        </form>
             
            
            <div class="row m-t-10">
                <div class="col-md-4 col-md-offset-4">                        
                    <button class=" btn btn-primary btn-cons  pull-right" id="printbtn" type="button" style="margin-top:24px;"><i class="pg-form"></i> <span class="bold"><?php print CommonLanguage::getMessage('print'); ?></span></button>
                </div>
            </div>
        </div>
    </div>
</div>
<iframe id="barcode_frame" name="ifrm" style="width:0;height:0;visibility: hidden;" ></iframe><br>
<select required id="Select_UOM" name="Select_UOM"  class="full-width Select_UOM hidden" data-init-plugin="select2">
    <?php foreach ($all_uom as $uom): ?>
        <option value="<?php echo $uom['UOM_ID']; ?>"><?php echo $uom['UOM_Name']; ?></option>
    <?php endforeach; ?>
</select>
<script>
             
    $(function () {
          
        $("#check_bar").on("change", function () {
        if(document.getElementById('check_bar').checked) {
            
            $("#s2id_myBarcode").remove();

            $(".barcode_change").attr("type", "text");
            $(".barcode_change").addClass('form-control');
            $(".barcode_change").removeClass('full-width');
            $(".barcode_change").css('display','block')
            $(".barcode_change").addClass("id", "barcode_change1");
            $(".barcode_change1").removeClass("id", "barcode_change");

        } else {

            $(".barcode_change1").attr("type", "hidden");
            $(".barcode_change1").addClass("id", "barcode_change");
            $(".barcode_change").removeClass("id", "barcode_change1");

            $(".barcode_change").attr("type", "hidden");
            $(".barcode_change").addClass('full-width');
            $(".barcode_change").removeClass('form-control');

            build_select2($("#myBarcode"), 'xhr/commonSearch?table=tbl_production_barcode&col_id=barcode&col_name=barcode');

        }
        });
         $("#myBarcode").on("change", function () {
            var myBarcode =$('#myBarcode').val();
            
            $.ajax({
              url: "InventoryAjax/get_production_barcode",
              data: {myBarcode:myBarcode},
              dataType: "JSON",
              complete: function(jqXHR, status) {
                  if (status == 'success') {
                      if (jqXHR.responseJSON[1] == "success") {
                          
                      }                 

                        $("#item_name").val(jqXHR.responseJSON['data'][0]['item']);
                        $("#text_right").val(jqXHR.responseJSON['data'][0]['text_right']);
                        $("#text_left").val(jqXHR.responseJSON['data'][0]['text_left']);
                        $("#text_left_bo").val(jqXHR.responseJSON['data'][0]['text_left_bo']);
                        $("#text_right_bo").val(jqXHR.responseJSON['data'][0]['text_right_bo']);

                    }
                   
              }
          });
        });
        $("#printbtn").on("click", function () {
            var bar_code = [];
//            if ($(".myBarcode").attr("data-code") == '') {
            if ($("#myBarcode").val() == '') {
                
                $("#barcodealert").attr("class", "alert alert-danger").html(Required_Fields);
                return false;
            }
             
            var data_param = { 
                Code: $("#myBarcode").val(),
                text_left: $("#text_left").val(),
                text_right: $("#text_right").val(),
                text_left_bo: $("#text_left_bo").val(),
                text_right_bo: $("#text_right_bo").val(),
                item_name: $("#item_name").val(),

                
                bar_code: bar_code,
                template_id: ($("#is_multi").is(":checked") || $('.AddRow').length == 1) ? $('#template_id').val() : ''
            };
             
                $('#barcode_frame').attr('src', "InventoryAjax/print_production_barcode?" + $.param(data_param));

            
            $('.template_div').removeClass('hidden')
             
               var Data = new FormData(document.getElementById("add_barcode_form"));
                $.ajax({
                    url: "InventoryAjax/submit_production_barcode",
                    method: "POST",
                    data: Data,
                    processData: false,
                    contentType: false,
                    dataType: "JSON",
                    complete: function (jqXHR, status) {
                        if (status == 'success') {
                            if (jqXHR.responseJSON[1] == "success") {
                             }
                         }
                     }
                });
            
         });
         
         
    });
  </script>
