<script src="<?php echo base_url();?>assets/choosen.js"></script>
<link rel="stylesheet" href="<?php echo base_url();?>assets/style.css">
  
 <?php echo form_open(base_url(''),array('class'=>"form-horizontal add_fg_stock", 'id'=>"add_fg_stock")); ?>
                                    
                <?php if($this->session->flashdata('fg_stock_success')){ ?>
        <div class="alert alert-success solid" style='text-align:center;'><?php echo $this->session->flashdata('fg_stock_success'); ?></div>
    <?php } ?> 

     <div id='fg_stock_success' class='alert alert-success solid' style='display:none;'></div>   
<div class="row">
         <div class="col-lg-6 col-md-6 col-sm-12">
            <div class="form-group">
               
                <input type="hidden" name="created" id="created" value="<?php echo date('Y-m-d H:i:s'); ?>" class="form-control required">
            </div>
        </div>

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


          <input type="hidden" name="user_id" id="user_id" value="<?php echo $this->session->userdata('id');?>">

          			 <div class="col-lg-3 col-md-6 col-sm-12">
                       <div class="form-group">
                            <label class="form-label">Machine:</label>
                             <select class="form-control machine"name="machine" required="required" id="machine">
                                <option>Select Option</option>
                                <?php  if(!empty($get_machine_data)){   ?>

                                    <?php foreach($get_machine_data as $get_machine){ ?>

                                    <option value="<?php echo $get_machine['machine']; ?>"><?php echo machine_name($get_machine['machine']); ?></option>

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

                     <div class="col-lg-3 col-md-6 col-sm-12">
                       <div class="form-group">
                        <label class="form-label">Item:</label>
                       <input type="text" id="product_name" name="product_name" readonly="readonly"  placeholder="Product Name" required="required"  class="form-control product_name">
                     </div>
                    </div>

                    <div class="col-lg-3 col-md-6 col-sm-12">
                       <div class="form-group">
                        <label class="form-label">Job #:</label>
                       <input type="text" id="job" readonly="readonly" name="job" placeholder="JOB NO" required="required"  class="form-control job">
                     </div>
                    </div>


                     <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Date</label>
                             <input type="date" id="date" name="date"  required="required"  class="form-control heater4">
                        </div>
                    </div>

                     <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Time</label>
                             <input type="time" id="time" name="time"  required="required"  class="form-control heater4">
                        </div>
                    </div>

        		  <div class="col-lg-3 col-md-6 col-sm-12">
                               <div class="form-group">
                                    <label class="form-label">Machine Cooling</label>
                                    <select class="form-control" required="required" name="machine_cooling" id="machine_cooling">
                                     <option>Select Option</option>
                                     <option value="Cool">Cool</option>
                                     <option value="Normal">Normal</option>
                                     <option value="Hot">Hot</option>
                                        
                            </select>
                         </div>
                        </div>

                        


                        <div class="col-lg-3 col-md-6 col-sm-12">
                               <div class="form-group">
                                    <label class="form-label">Die Cooling</label>
                                    <select class="form-control" required="required" name="die_cooling" id="die_cooling">
                                     <option>Select Option</option>
                                     <option value="Cool">Cool</option>
                                     <option value="Normal">Normal</option>
                                     <option value="Hot">Hot</option>
                                        
                            </select>
                         </div>
                        </div>
                         
                         <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Heater Reading 1</label>
                             <input type="text" id="heater1" name="heater1" placeholder="Heater Reading" required="required"  class="form-control heater1">
                        </div>
                    </div>

                          
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Heater Reading 2</label>
                             <input type="text" id="heater2" name="heater2" placeholder="Heater Reading" required="required"  class="form-control heater2">
                        </div>
                    </div>


                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Heater Reading 3</label>
                             <input type="text" id="heater1" name="heater3" placeholder="Heater Reading" required="required"  class="form-control heater3">
                        </div>
                    </div>



                     <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Heater Reading 4</label>
                             <input type="text" id="heater4" name="heater4" placeholder="Heater Reading" required="required"  class="form-control heater4">
                        </div>
                    </div>

                          
                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Heater Reading 5</label>
                             <input type="text" id="heater5" name="heater5" placeholder="Heater Reading" required="required"  class="form-control heater5">
                        </div>
                    </div>


                    <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Heater Reading 6</label>
                             <input type="text" id="heater6" name="heater6" placeholder="Heater Reading" required="required"  class="form-control heater6">
                        </div>
                    </div>
                           
                           <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">Timers Readeing1:</label>
                                  <input type="text" id="timers_reading1" name="timers_reading1" required="required"  class="form-control timers_reading1">
                             </div> 
                             
                           </div>


                           <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">Timers Readeing2:</label>
                                  <input type="text" id="timers_reading2" name="timers_reading2" required="required"  class="form-control timers_reading2">
                             </div> 
                             
                           </div>

                           <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">Timers Readeing3:</label>
                                  <input type="text" id="timers_reading3" name="timers_reading3" required="required"  class="form-control timers_reading3">
                             </div> 
                             
                           </div>

                           <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">Timers Readeing4:</label>
                                  <input type="text" id="timers_reading4" name="timers_reading4" required="required"  class="form-control timers_reading4">
                             </div> 
                             
                           </div>

                           <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">Timers Readeing5:</label>
                                  <input type="text" id="timers_reading5" name="timers_reading5" required="required"  class="form-control timers_reading5">
                             </div> 
                             
                           </div>


                            <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">Timers Readeing6:</label>
                                  <input type="text" id="timers_reading6" name="timers_reading6" required="required"  class="form-control timers_reading6">
                             </div> 
                             
                           </div>



                        <div class="col-lg-3 col-md-6 col-sm-12">
                               <div class="form-group">
                                    <label class="form-label">Pcs Condition</label>
                                    <select class="form-control" required="required" name="pcs_codition" id="pcs_codition">
                                     <option>Select Option</option>
                                     <option value="Good">Good</option>
                                     <option value="Normal">Normal</option>
                                     <option value="Bad">Bad</option>
                                        
                            </select>
                         </div>
                        </div>


                        <div class="col-lg-3 col-md-6 col-sm-12">
                               <div class="form-group">
                                    <label class="form-label">Machine Condition</label>
                                    <select class="form-control" required="required" name="machine_condition" id="machine_condition">
                                     <option>Select Option</option>
                                     <option value="Good">Good</option>
                                     <option value="Normal">Normal</option>
                                     <option value="Bad">Bad</option>
                                        
                            </select>
                         </div>
                        </div>


                        <div class="col-lg-3 col-md-6 col-sm-12">
                               <div class="form-group">
                                    <label class="form-label">Compressor Service</label>
                                    <select class="form-control" required="required" name="compressor_service" id="compressor_service">
                                     <option>Select Option</option>
                                     <option value="Oil">Oil</option>
                                     <option value="Water">Water</option>
                                     <option value="Cleaning">Cleaning</option>
                                        
                            </select>
                         </div>
                        </div>
                          

                        <div class="col-lg-6 col-md-6 col-sm-12">
                            <div class="form-group">
                                <label class="form-label">Remarks:</label>
                                <textarea  class="form-control remarks" name="remarks" id="remarks"></textarea>  
                             </div>
                         </div>

                 </div>

                  <?php form_close();?>
               <button type="submit" id="dis_submit" class="btn btn-primary">Save <i class="icon-arrow-right14 position-right"></i></button>
                <div class="col-12">
					<div class="card">
						    <div class="card-body">
                                <button type="button" class="btn btn-rounded btn-success" onclick="btnExport_monthly();"><span class="btn-icon-left text-success"><i class="fa fa-download color-success"></i>
                                    </span>Download</button>
                               <br/><br/><br/>
                                <div class="table-responsive">

                                    <table  id="example" class="table table-striped table-bordered" style="font-size:11px;">
                                        <thead>
                                            <tr>
                                                
                                                <th>Machine</th>
                                                <th>Item</th>
                                                <th>Job#</th>
                                                <th>Machine Cooling</th>
                                                <th>Die Cooling</th>
                                                <th>Heater 1</th>
                                                <th>Heater 2</th>
                                                <th>Heater 3</th>
                                                <th>Heater 4</th>
                                                <th>Heater 5</th>
                                                <th>Heater 6</th>
                                                <th>Timers 1</th>
                                                <th>Timers 2</th>
                                                <th>Timers 3</th>
                                                <th>Timers 4</th>
                                                <th>Timers 5</th>
                                                <th>Timers 6</th>
                                                <th>Pcs Condition</th>
                                                <th>Machine Condition</th>
                                                <th>Compressor</th>
                                                <th>Date/Time</th>
                                                <th>Remarks</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                          
                                        </tbody>
                                        <tbody>
                                        <?php
                                        if(!empty($get_supervisor_data)){
                                         foreach($get_supervisor_data as $get_supervisor_datas){ ?>
                                        
                                      <tr>
                                        <td><strong><?php 
                                        //$machine =  machine_from_production($get_supervisor_datas['machine']); 
                                        echo machine_name($get_supervisor_datas['machine']);

                                    ?></strong></td>
                                        <td><strong><?php echo $get_supervisor_datas['product_name']; ?></strong></td>      
                                        <td><?php echo $get_supervisor_datas['job']; ?></td>
                                        <td><?php echo $get_supervisor_datas['machine_cooling']; ?></td>
                                        <td><?php echo $get_supervisor_datas['die_cooling']; ?></td>
                                        <td><?php echo $get_supervisor_datas['heater1']; ?></td>
                                        <td><?php echo $get_supervisor_datas['heater2']; ?></td>
                                        <td><?php echo $get_supervisor_datas['heater3']; ?></td>
                                        <td><?php echo $get_supervisor_datas['heater4']; ?></td>
                                        <td><?php echo $get_supervisor_datas['heater5']; ?></td>
                                        <td><?php echo $get_supervisor_datas['heater6']; ?></td>
                                        <td><?php echo $get_supervisor_datas['timers_reading1']; ?></td>
                                        <td><?php echo $get_supervisor_datas['timers_reading2']; ?></td>
                                        <td><?php echo $get_supervisor_datas['timers_reading3']; ?></td>
                                        <td><?php echo $get_supervisor_datas['timers_reading4']; ?></td>
                                        <td><?php echo $get_supervisor_datas['timers_reading5']; ?></td>
                                        <td><?php echo $get_supervisor_datas['timers_reading6']; ?></td>
                                        <td><?php echo $get_supervisor_datas['pcs_codition']; ?></td>
                                        <td><?php echo $get_supervisor_datas['machine_condition']; ?></td>
                                        <td><?php echo $get_supervisor_datas['compressor_service']; ?></td>
                                       
                                        <td><?php echo $get_supervisor_datas['insert_date']; ?></td>
                                        <td><?php echo $get_supervisor_datas['remarks']; ?></td>
                                        <td><a href="<?php echo base_url('Order_qc/edit_qc_timings/'.$get_supervisor_datas['id']); ?>" class="btn btn-sm btn-primary"><i class="la la-pencil"></i></a></td>
                                      </tr>
                                      <?php } } ?>
                                        </tbody>
                                    </table>
                                </div>
                                
                            </div>
                            </div>
                            </div>



      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <style>
        .redborder{
            border:1px solid red;
        }
        </style>

        <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'>


          $(".machine").chosen();


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

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

                $.ajax({
                            type:'POST',
                            url:'<?php echo base_url('Order_qc/get_item_production'); ?>',
                            data:{machine:machine},
                            dataType:'json',
                            success:function(data){
                            
                                    $('#product_name').val(data.product_name);
                                    $('#job').val(data.job);
                                    /*$('#total_qty').val(data.total_qty);*/
                                      
                                  
                            },
                            error:function(data){console.log(data.responseText);}
                        });

    });


        
    var add_fg_stocks = $('#add_fg_stock');   
    
    add_fg_stocks.on('submit',function(e){
  //$("#dis_submit").attr('disabled', true);
        e.preventDefault();
        
        var add_fg = add_fg_stocks.serialize();
         
     
          if (confirm('Are you sure you want to Add.?')) {
            $.ajax({
                type:'POST',
                url:'<?php echo base_url('Order_qc/supervisormachine_qc'); ?>',
                data:add_fg,
                dataType:'json',
                success:function(data){
                
                    console.log('first'+data.status);
                    if(data.status === 'true'){
                        console.log('second'+data.status);
                        $('#fg_stock_success').show().html('Added Successfully');
                       setTimeout(function(){location.href="<?php echo base_url('Order_qc/qc_production_on_machine/'); ?>"} , 2000);
                    }else{
                        console.log('third'+data);          
                    }
                },
                error:function(data){console.log(data.responseText);}
            });
        }
        
    });

    
  </script>