               <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_multipart(base_url(''),array('class'=>"form-horizontal add_clear", 'id'=>"add_clear")); ?>
        

                      <?php if($this->session->flashdata('product_success')){ ?>
                            <div class="alert alert-success solid" style='text-align:center;'><?php echo $this->session->flashdata('product_success'); ?></div>
                        <?php } ?>           

                         <div class="col-xl-12 col-xxl-12 col-sm-12">
                            <div class="card">
                                
                                <div class="card-body">
                                    <div id='product_success' class='alert alert-success solid' style='display:none;'></div>
                                        <div class="row">
                                            <input type="hidden" name="printing_id" value="<?php echo $get_details_printing[0]['id']; ?>">


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

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


                                       <div class="col-lg-6 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Total Qty:</label>
                                                      <input type="text" disabled="disabled" value="<?php echo $get_details_printing[0]['qty']; ?>" required="required" id="total"  class="form-control ">
                                                 </div>
                                                </div>
                                        
                                                <div class="col-lg-6 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Printing Qty:</label>
                                                      <input type="text" name="qty" required="required" id="qty"  class="form-control ">
                                                 </div>
                                                </div>

                                              
                                                 <div class="col-lg-6 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Printing Qty Remaining:</label>
                                                    <?php

                                                         $printing = total_printing($get_details_printing[0]['id']);
                                                         $printing_log =  total_printing_log($get_details_printing[0]['id']);
                                                         $total = $printing-$printing_log;
                                                     ?>
                                                      <input type="text" readonly="readonly" value="<?php echo $total; ?>" name="remaining" required="required" id="remaining"  class="form-control ">
                                                 </div>
                                                </div> 

                                            
                                           
                                             <div class="col-lg-6 col-md-6 col-sm-12" id="carton_div">
                                                <div class="form-group">
                                                    <label class="form-label">Remarks</label>
                                                       <textarea name="remarks" class="form-control" id="remarks"> </textarea>
                                                </div>
                                            </div>
                                       
                        
                                    <div class="modal-footer">
                                
                                <button type="submit" id="dis_submit" class="btn btn-primary">Submit <i class="icon-arrow-right14 position-right"></i></button>
                            </div>  
                                </div>
                            </div>
                        </div>
                         
                     <?php form_close();?>
                           

    <!-- Required vendors -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

    <script type='text/javascript'>
    $(".machine").chosen();

  var clear = $('#add_clear');   
    
    clear.on('submit',function(e){

       var qty = parseInt($("#qty").val());
        var remaining = parseInt($("#remaining").val());
        e.preventDefault();
        
        var cleardata = clear.serialize();

       if(qty > remaining || remaining == 0){

             alert("Stock Not Available..!");

          }else{



        if (confirm('Are you sure you want to Add Details.?')) {

      
            $.ajax({
                type:'POST',
                url:'<?php echo base_url('Requisition/update_printing_data'); ?>',
                data:cleardata,
                dataType:'json',
                success:function(data){
                    console.log('first'+data.status);
                    if(data.status === 'true'){
                        console.log('second'+data.status);
                        $('#product_success').show().html('Added Successfully');
                       setTimeout(function(){location.href="<?php echo base_url('Stock/printing_line'); ?>"} , 3000);
                    }else{
                        console.log('third'+data);          
                    }
                },
                error:function(data){console.log(data.responseText);}
            });
        }
    }
    });

    </script>   
    