<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">کس وجہ سے کم روکا:</label>
                             <input type="text" id="work_stop"  name="work_stop"  required="required"  class="form-control work_stop" >
                         </div>
                        </div>
                         
                         <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">پروڈکشن روکنے کا وقت</label>
                             <input type="time" id="production_time" name="production_time" required="required"  class="form-control production_time">
                        </div>
                    </div>

                           <div class="col-lg-3 col-md-6 col-sm-12">
                        <div class="form-group">
                            <label class="form-label">پروڈکشن شروع ہونے کا وقت   </label>
                             <input type="time" id="production_time_start" name="production_time_start"  required="required"  class="form-control production_time_start" >
                        </div>
                    </div>

                           
                           <div class="col-lg-3 col-md-6 col-sm-12">
                           <div class="form-group">
                                <label class="form-label">پروڈکشن روکنے کا دورانیہ:</label>
                                  <input type="text" id="production_stoping_time" readonly="readonly" name="production_stoping_time" required="required"  class="form-control production_stoping_time">
                             </div> 
                             
                           </div>


                           <div class="col-lg-3 col-md-6 col-sm-12">
                               <div class="form-group">
                                    <label class="form-label">کیا اب کم سہی ہوگیا ہے:</label>
                                    <select class="form-control" required="required" name="condition" id="condition">
                                     <option>Select Option</option>
                                     <option value="yes">ہان</option>
                                     <option value="no">نہیں</option>
                                     <option value="normal">پھیلے سے بہتر ہے</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>Job</th>
                                                 <th>Item</th>
                                                <th>Issue</th>
                                                <th>Stop</th>
                                                <th>Start</th>
                                                <th>Difference</th>
                                                <th>WorkFine</th>
                                                
                                                <th>Date/Time</th>
                                                <th>Remarks</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                          
                                        </tbody>
                                        <tbody>
                                        <?php
                                        if(!empty($get_qc_complain_hour)){
                                        foreach($get_qc_complain_hour as $get_qc_complain_hours){ ?>
                                      <tr>
                                        <td><strong><?php 
                                        //$machine =  machine_from_production($get_qc_complain_hours['machine']); 
                                        echo machine_name($get_qc_complain_hours['machine']);

                                    ?></strong></td>
                                         
                                        <td><?php echo $get_qc_complain_hours['job']; ?></td>
                                        <td><?php echo $get_qc_complain_hours['product_name']; ?></td>
                                        <td><?php echo $get_qc_complain_hours['work_stop']; ?></td>
                                        <td><?php echo $get_qc_complain_hours['production_time']; ?></td>
                                        <td><?php echo $get_qc_complain_hours['production_time_start']; ?></td>
                                        <td><?php echo $get_qc_complain_hours['production_stoping_time']; ?></td>
                                        <td><?php echo $get_qc_complain_hours['condition']; ?></td>
                                     
                                        
                                        <td><?php echo $get_qc_complain_hours['created']; ?></td>
                                        <td><?php echo $get_qc_complain_hours['remarks']; ?></td>
                                        <td><a href="<?php echo base_url('Order_qc/edit_qc_timings/'.$get_qc_complain_hours['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_qc_complain_hours['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 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'>

        




        $("#production_time_start").click(function(){

        valueStart = $("#production_time").val();
        valueStop = $("#production_time_start").val();

        var str0="01/01/1970 " + valueStart;
        var str1="01/01/1970 " + valueStop;

        var diff=(Date.parse(str1)-Date.parse(str0))/1000/60;
        var hours=String(100+Math.floor(diff/60)).substr(1);
        var mins=String(100+diff%60).substr(1);

        //alert(hours+':'+mins);
        var  productionmint = mins/60;
        var  productionhour = hours+productionmint;
        var output= productionhour.replace(/0/g, '');
          //var totals  = output.toFixed(2); 
        $('#production_stoping_time').val(output);

        });


        $("#production_time").click(function() {

  
          var production_time = $(".production_time").val();
          var production_time_start = $(".production_time_start").val();
          
          $('.production_stoping_time').text(TimeDiff(production_time, production_time_start)); 
        });


          $(".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/complain_hour'); ?>',
                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_complian/'); ?>'+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>