
<script src="<?php echo base_url();?>assets/choosen.js"></script>
<link rel="stylesheet" href="<?php echo base_url();?>assets/style.css">
  
<?php if($id==1) {?>

 <div class="row">
                                  
                                      
                                            
                                                   
                                                    <input type="hidden" name="created" id="created" value="<?php echo date('Y-m-d H:i:s'); ?>" class="form-control required">
                                               

                                            
                                                   
                                                    <input type="hidden" value="<?php echo date('Y-m-d H:i:s'); ?>" name="modified" id="modified" class="form-control required">
                                                
                                          
                                            <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Component:</label>
                                                     <select data-live-search="true" name="material_id" id="material_id" class="form-control material_id">

                                                        <option value="">Select Material</option>
                                                      <?php foreach ($get_materials as $get_material) { ?>
                                                                
                                                     <option value="<?php echo $get_material['id']; ?>"><?php echo $get_material['name']; ?></option>

                                                        <?php } ?>
                                                  </select>

                                                   <span id="link"></span>
                                                 </div>

                                                </div>

                                              <!--   <div class="col-lg-2 col-md-6 col-sm-12">
                                                 <div class="form-group">
                                                    <label class="form-label">Grade/Remarks:</label>
                                                    <input type="text"  readonly="readonly"   class="form-control grade">
                                                 </div>
                                                </div> -->
                                                  

                                                 <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Item Code:</label>
                                                    <input type="text" readonly="readonly"  class="form-control code_m_p">
                                                 </div>
                                                </div>
                                                

                                                  <!-- <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Weight/Qty:</label>
                                                      <input type="text" name="weight"  id="weight"  class="form-control weight">
                                                 </div>
                                                </div> -->


                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label"> Order Qty:</label>
                                                      <input type="text" name="order_qty"  id="order_qty"  class="form-control order_qty" onkeypress="return isNumberKey(event)">
                                                 </div>
                                                </div>

                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                  <div class="form-group">
                                                    <label class="form-label">Unit:</label>
                                                    <!--  <input type="text" readonly="readonly"   class="form-control unit"> -->
                                                      <select name="unit" id="unit" class="form-control">
                                                            <option value="">Select Unit</option>
                                                            <?php foreach ($get_units as $get_units) { ?>
                                                                
                                                                 <option value="<?php echo $get_units['id']; ?>"><?php echo $get_units['names']; ?></option>

                                                            <?php } ?>
                                                           
                                                            
                                                            </select>


                                                      <!-- <input type="hidden" name="unit"  id="unit"  class="form-control units_value"> -->
                                                       </div>

                                                </div>

                                                 <div class="col-lg-2 col-md-6 col-sm-12">
                                                   <div class="form-group">
                                                    <label class="form-label">Rate:</label>
                                                      <input type="text" name="rate" id="rate"  class="form-control" required="required" onkeypress="return isNumberKey(event)">
                                                 </div>
                                                </div>
                                 </div>
                           
                            <?php }else if($id==2){?>


                                    <div class="row">
                                                   
                                                    <input type="hidden" name="created" id="created" value="<?php echo date('Y-m-d H:i:s'); ?>" class="form-control required">
                                                
                                                   
                                                    <input type="hidden" value="<?php echo date('Y-m-d H:i:s'); ?>" name="modified" id="modified" class="form-control required">
                                                
                                          
                                            <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label"> Component:</label>
                                               
                                                        <select data-live-search="true" name="product_id" id="product_id" class="form-control product_id">
                                                        <option value="">Select Product</option>
                                                      <?php foreach ($get_products as $get_product) { ?>
                                                                
                                                     <option value="<?php echo $get_product['id']; ?>"><?php echo $get_product['name']; ?></option>

                                                        <?php } ?>
                                                  </select>
                                                 </div>
                                                </div>

                                               <!--  <div class="col-lg-2 col-md-6 col-sm-12">
                                                 <div class="form-group">
                                                    <label class="form-label">Grade/Remarks:</label>
                                                    <input type="text"  readonly="readonly"   class="form-control grade">
                                                 </div>
                                                </div> -->


                                                 <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Item Code:</label>
                                                    <input type="text"  readonly="readonly"  class="form-control code_m_p">
                                                 </div>
                                                </div>
                                                

              

                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label"> Order Qty:</label>
                                                      <input type="text" name="order_qty" id="order_qty"  class="form-control order_qty" onkeypress="return isNumberKey(event)">
                                                 </div>
                                                </div>

                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                  <div class="form-group">
                                                    <label class="form-label">Unit:</label>
                                                        <!-- <input type="text" name="unit"  class="form-control unit"> -->

                                                        <!-- <input type="hidden" name="unit" readonly="readonly" id="unit"  class="form-control units_value"> -->

                                                         <select name="unit" id="unit" class="form-control">
                                                            <option value="">Select Unit</option>
                                                            <?php foreach ($get_units as $get_units) { ?>
                                                                
                                                                 <option value="<?php echo $get_units['id']; ?>"><?php echo $get_units['names']; ?></option>

                                                            <?php } ?>
                                                           
                                                            
                                                            </select>
                                                       </div>

                                                </div>

                                                 <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Rate:</label>
                                                      <input type="text" name="rate" id="rate" readonly="readonly"  class="form-control rate" required onkeypress="return isNumberKey(event)">


                                                       

                                                 </div>
                                                </div>
                                       </div> 
                                     

                                <?php } ?>


      <SCRIPT language=Javascript>
       <!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
       //-->
    </SCRIPT>

<script type='text/javascript'>


    $(".product_id").chosen();

    $(".material_id").chosen();
    
        

            $("#material_id").change(function() {

                $( "#link" ).empty();
                    var material =  this.value;
                    
                    $("#link").append("<div> <a target=\"_blank\" href=\"<?php echo base_url('Purchase_order/material_logs/'); ?>"+material+"\">Show Material Logs</a> </div>")

                    $.ajax({
                                type:'POST',
                                url:'<?php echo base_url('Purchase_order/get_materils_details'); ?>',
                                data:{material:material},
                                dataType:'json',
                                success:function(data){
                                    //console.log(data);
                                   // $('.grade').val(data.grade);
                                    $('.code_m_p').val(data.codes);
                                    //$('.weight').val(data.total);
                                    //$('.unit').val(data.unit);
                                    //$('.units_value').val(data.units_value);
                                    
                                },
                                error:function(data){console.log(data.responseText);}
                            });

                });






             $("#product_id").change(function() {

                
    
                var product_id =  this.value;
                //alert(id);

                $.ajax({
                            type:'POST',
                            url:'<?php echo base_url('Purchase_order/get_product_details'); ?>',
                            data:{product_id:product_id},
                            dataType:'json',
                            success:function(data){
                                //console.log(data[0].material_code);
                                   //$('.grade').val(data.grade);
                                    $('.code_m_p').val(data.codes);
                                    $('.rate').val(data.rates);
                                    //$('.unit').val(data.unit);
                                   // $('.units_value').val(data.units_value);
                                    // $('.order_qty').val(data.order_qty);           
                               //$('.weight').val(data[0].weight);
                               
                            },
                            error:function(data){console.log(data.responseText);}
                        });

    });


             

</script>