<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" 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">Job:</label>
                             <input type="text" id="job"  placeholder="JOB NO" name="job" readonly="readonly" 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">Product:</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">Material:</label>
                             <input type="text" id="material"   placeholder="Material Name" readonly="readonly" required="required"  class="form-control ">
                         </div>
                        </div>

                        <input type="hidden" id="material_id" name="material"  required="required"  class="form-control">

          			 <div class="col-lg-3 col-md-6 col-sm-12">
                       <div class="form-group">
                            <label class="form-label">Time In:</label>
                           <input type="text" readonly="readonly" id="time_in" value="<?php echo date('H:i:A'); ?>" name="time_in" placeholder="Time In" required="required"  class="form-control time_in">
                         </div>
                        </div>

                    
        		   <div class="col-lg-3 col-md-6 col-sm-12">
         				  <div class="form-group">
        	                    <label class="form-label">Total Cavities:</label>
                             <input type="text" id="total_cavities" name="total_cavities" placeholder="Total Cavities" required="required"  class="form-control total_cavities">
                         </div>
                        </div>
                         
                         <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Production Cavities</label>
                             <input type="text" id="production_cavities"  name="production_cavities" placeholder="Production Cavities" required="required"  class="form-control production_cavities">
                        </div>
                    </div>

                           <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">Operator</label>
                            <select class="form-control operator" name="operator" required="required" id="operator">
		                             <option>Select Option</option>
	                                 <?php foreach($get_machine_data_production_operator as $get_machine_data_production_operators){ ?>
	                                 <option value="<?php echo $get_machine_data_production_operators['id']; ?>"><?php echo $get_machine_data_production_operators['fullname']; ?></option>
	                                <?php } ?>                       
                            </select>
                        </div>
                    </div>

                           
                           <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">10 M-D-R:</label> 
                                  <input type="text" id="short_pcs" name="short_pcs" placeholder="10 M-D-R" required="required"  class="form-control short_pcs">
                             </div> 
                             
                           </div>


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

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


                            <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">Pcs Weight Range:</label> 
                                  <input type="text" id="pcs_weight_range" name="pcs_weight_range" placeholder="Pcs Weight Range" required="required"  class="form-control pcs_weight_range">
                             </div> 
                           </div>

                            <div class="col-lg-3 col-md-6 col-sm-12">
		                       <div class="form-group">
		                            <label class="form-label">Check Pcs:</label>
		                            <select class="form-control" name="check_pcs" required="required" id="check_pcs">
		                             <option>Select Option</option>
	                                 <option value="OK">OK</option>
	                                 <option value="Not OK">Not OK</option>
	                               
                            </select>
                         </div>
                        </div>
                          

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


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

                        <div class="col-lg-3 col-md-6 col-sm-12">
                               <div class="form-group">
                                    <label class="form-label">Shift:</label>
                                    <select class="form-control" name="shift" required="required" id="shift">
                                     <option>Select Option</option>
                                     <option value="1">Day</option>
                                     <option value="2">Night</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">
                                    <div id='party_danger' class='alert alert-danger solid' style='display:none;width: 25%;'></div>

                                    <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>Material</th>
                                                <th>Time In</th>
                                                <th>Total Cavities</th>
                                                <th>Production Cavities</th>
                                                <th>Operator</th>
                                                <th>10M-D-R</th>
                                                <th>Engraving</th>
                                                <th>Fitting</th>
                                                <th>Pcs Range</th>
                                                <th>Check Pcs</th>
                                                <th>Time Out</th>
                                                <th>Remarks</th>
                                                <th>Date/Time</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                          
                                        </tbody>
                                        <tbody>
                                           <?php
                                           if(!empty($get_randomly_qc)){
                                         foreach($get_randomly_qc as $get_randomly_qcs){ ?>
                                      <tr>
                                        <td><strong><?php 
                                        //$machine =  machine_from_production($get_randomly_qcs['machine']); 
                                        echo machine_name($get_randomly_qcs['machine']);

                                    ?></strong></td>
                                        <td><strong><?php echo $get_randomly_qcs['product_name']; ?></strong></td>      
                                        <td><?php echo $get_randomly_qcs['job']; ?></td>
                                        <td><?php echo $get_randomly_qcs['material']; ?></td>
                                        <td><?php echo $get_randomly_qcs['time_in']; ?></td>
                                        <td><?php echo $get_randomly_qcs['total_cavities']; ?></td>
                                        <td><?php echo $get_randomly_qcs['production_cavities']; ?></td>
                                        <td><?php echo $get_randomly_qcs['operator']; ?></td>
                                        <td><?php echo $get_randomly_qcs['short_pcs']; ?></td>
                                        <td><?php echo $get_randomly_qcs['condition']; ?></td>
                                        <td><?php echo $get_randomly_qcs['fitting']; ?></td>
                                        <td><?php echo $get_randomly_qcs['pcs_weight_range']; ?></td>
                                        <td><?php echo $get_randomly_qcs['check_pcs']; ?></td>
                                        <td><?php echo $get_randomly_qcs['time_out']; ?></td>
                                        <td><?php echo $get_randomly_qcs['remarks']; ?></td>

                                        <td><?php echo $get_randomly_qcs['created']; ?></td>
                                        <td><!-- <a href="<?php echo base_url('Order_qc/edit_qc_timings/'.$get_randomly_qcs['id']); ?>" class="btn btn-sm btn-primary"><i class="la la-pencil"></i></a> -->
                                        <a href="javascript:void(0);" onclick="delete_data(<?php echo $get_randomly_qcs['id']; ?>)" class="btn btn-sm btn-danger"><i class="la la-trash-o"></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 type='text/javascript'>
    
    

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

           $(".operator").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);
                            $('#material').val(data.material);

                            $('#material_id').val(data.material_id);
                              
                          
                    },
                    error:function(data){console.log(data.responseText);}
                });

    });


        
    var add_fg_stocks = $('#add_fg_stock');   
    
    add_fg_stocks.on('submit',function(e){
 
        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/randomly_check'); ?>',
                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);}
            });
        }
        
    });


       function delete_data(id) { 
        var id = id;
        
         $.ajax({
                type:'POST',
                url:'<?php echo base_url('Order_qc/delete_randomlydelete/'); ?>'+id,
                data:id,
                dataType:'json',
                success:function(data){
                    console.log('first'+data.status);
                    
                        console.log('second'+data.status);
                        //debugger;
                        $('#party_danger').show().html('Deleted Successfully');
                       setTimeout(function(){location.href="<?php echo base_url('Order_qc/qc_production_on_machine/'); ?>"} , 3000);
                    
                },
                error:function(data){console.log(data.responseText);}
            });
        } 

    
  </script>