 <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="col-lg-3 col-md-6 col-sm-12">
                      <div class="form-group">
                            <label class="form-label">Machine:</label>
                            <select class="form-control product_id"   name="product_id" required="required" id="product_id">
                                <option>Select  Machine #</option>
                                <?php foreach ($get_production_job as $get_production_machines) { ?>
                                  <option value="<?php echo $get_production_machines['machine']; ?>"><?php echo machine_name($get_production_machines['machine']); ?></option>

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

                    <div class="col-lg-12 col-md-12 col-sm-12" id="show_data"></div>

                 
                   


                  <?php form_close();?>
                <button type="submit" id="dis_submit" class="btn btn-primary">Save <i class="icon-arrow-right14 position-right"></i></button>


      <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_id").chosen();
        
        $(".product_id").chosen();


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

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

                $.ajax({
                            type:'POST',
                            url:'<?php echo base_url('Stock/get_material_job_production'); ?>',
                            data:{product_id:product_id},
                            dataType:'json',
                            success:function(data){
                                    

                                     
                                       $('#show_data').show().html(data.html);
                                        //$('#show_data').val(data.machine);
                                   /* $('#material_id').val(data.material_id);*/
                                    
                                  //  $('#wast_stock').val(data.wast_stock);
                                    
                            },
                            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();
         var inout = $('#inout').val();
           var total_qty = parseInt($("#total_qty").val());
            var qty = parseInt($("#qty").val());
           
           // if (total_qty < qty) {
               // alert("Quantity Greater Then  Quantity..!");
               
           // }else{



      if(inout==0){
              if (confirm('Are you sure you want to Add Stock Out.?')) {
            $.ajax({
                type:'POST',
                url:'<?php echo base_url('Stock/out_stock_production'); ?>',
                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(' Stock added Successfully');
                       setTimeout(function(){location.href="<?php echo base_url('Stock/fg_stock/'); ?>"} , 2000);
                    }else{
                        console.log('third'+data);          
                    }
                },
                error:function(data){console.log(data.responseText);}
            });

        }
        }
      //}
    });

    
  </script>