              <?php if($this->session->flashdata('add_dc_success')){ ?>
                            <div class="alert alert-success solid" style='text-align:center;'><?php echo $this->session->flashdata('add_dc_success'); ?></div>
                        <?php } ?>
                                    <div id='add_dc_success' class='alert alert-success solid' style="display: none;">
                                      
                                    </div>    
            <div class="welcome-text">
                            <h4>DC Challan Receving</h4>
                        </div>
                <div class="col-lg-12">
                        <div class="card">
                           
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-hover table-responsive-sm">
                                        <thead>
                                            <tr>
                                               <th>P.O No</th>
                                                <th>Items</th>
                                                <th>Qty</th>
                                               <th>Unit</th>
                                               <th>Date</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php if(!empty($get_invoice_data)) {?>
                                                <?php //foreach ($get_invoice_data as $all_get_po) {
                                                   
                                                 ?>
                                            <tr> 
                                                <td><strong><?php echo po_number( $get_invoice_data[0]['po_id']); ?></strong></td>
                                              <?php if($get_invoice_data[0]['material_id'] !=0){ ?>
                                                <td><strong><?php echo material_name($get_invoice_data[0]['material_id']); ?></strong></td>
                                                 <?php }else{?>

                                                    <td><strong><?php echo product_name($get_invoice_data[0]['product_id']); ?></strong></td>

                                               <?php  } ?>

                                                <?php  
                                                
                                                    $dc_qty = $get_dc_qty[0]['qty'];
                                                    $mat_qty = $get_invoice_data[0]['order_qty'];
                                                    $total_condition =  $mat_qty-$dc_qty;                                        
                                                if($dc_qty ==""){ ?>                                                 
                                                 <td><strong><?php  echo $get_invoice_data[0]['order_qty']; ?></strong></td>
                                                 <td><strong><?php  echo get_unit_name($get_invoice_data[0]['unit']); ?></strong></td>
                                                <?php }else if($total_condition == 0){?>

                                                <td><strong><?php echo $get_invoice_data[0]['order_qty'];?></strong></td>
                                                <td><strong><?php  echo get_unit_name($get_invoice_data[0]['unit']); ?></strong></td>
                                                
                                               <?php }else{ ?>
                                                    <td><strong><?php  echo $mat_qty-$dc_qty; ?></strong></td>

                                                    <td><strong><?php  echo get_unit_name($get_invoice_data[0]['unit']); ?></strong></td>
                                                <?php } ?>

                                                <td><?php echo date('d/m/Y'); ?></td>
                                            </tr>
                                        <?php }
                                              // }
                                         ?>
                                          
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <?php 


                        $total = $mat_qty-$dc_qty;
                        if($total == 0){

                          echo "";
                        }//else

                        if($get_dc_qty[0]['qc_status']!=1){
                         ?>
                        

                  <input type="hidden" name="tqty" id="tqty"  value="<?php echo $total;?>"/> 

                <?php echo form_open(base_url(''),array('class'=>"form-horizontal add_dc", 'id'=>"add_dc")); ?>
                 <div class="row">

                            <input type="hidden" name="grn_no" id="grn_no" value="<?php echo $grn_code; ?>">
                            <div class="col-lg-4 col-md-4 col-sm-8">
                                <div class="form-group">
                                    <label class="form-label">Challan No</label>
                                    <input type="text" placeholder="Challan No" name="dc_no"  id="dc_no"  class="form-control required">
                                </div>
                            </div>

                      <div class="col-lg-4 col-md-4 col-sm-8">
                        <div class="form-group">
                            <label class="form-label">Qty</label>
                            <input type="text" name="qty" id="qty" required="required" placeholder="Quantity" class="form-control ">
                        </div>
                    </div>


                      <div class="col-lg-4 col-md-4 col-sm-8">
                        <div class="form-group">
                            <label class="form-label">Status:</label>
                            <select class="form-control required" required="required" name="status" id="status" tabindex="-98">
                                <!-- <option value="">Select Status</option> -->
                                
                                <option value="1">Recived</option>
                                <!-- <option value="2">Rejected</option> -->
                                </select>
                            </div>
                        </div>
                  
                    
                     <input type="hidden" name="created" id="created" value="<?php echo date('Y-m-d H:i:s'); ?>" class="form-control required">
                      <input type="hidden" value="<?php echo date('Y-m-d H:i:s'); ?>" name="modified" id="modified" class="form-control required">
                       <input type="hidden" name="user_id" id="user_id" value="<?php echo $this->session->userdata('id');?>">

                       <input type="hidden" name="po_id" id="po_id" value="<?php echo $get_invoice_data[0]['po_id']; ?>">
                </div>

                  <?php form_close();?>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="submit" id="dc_dis" class="btn btn-primary">Submit <i class="icon-arrow-right14 position-right"></i></button>
                    </div>
                  <?php } ?>

                  
             </div>


            
             <script type="text/javascript">
                 
             

                           var dc = $('#add_dc');   
    
                                dc.on('submit',function(e){
                                   $("#dc_dis").attr('disabled', true);
       
                                    e.preventDefault();
                                    
                                    var dcdata = dc.serialize();
                                    var tqty = parseInt($("#tqty").val());
                                        var qty = parseInt($("#qty").val());
                                       
                                        if (tqty < qty) {
                                            alert("Quantity Greater Then PO Quantity..!");
                                           
                                        }else{
                                  
                                        $.ajax({
                                            type:'POST',
                                            url:'<?php echo base_url('order_qc/pending_orders'); ?>',
                                            data:dcdata,
                                            dataType:'json',
                                            success:function(data){
                                                console.log('first'+data.id);
                                               // alert(data);
                                                if(data.status !=''){
                                                    console.log('second'+data.id);
                                                    $('#add_dc_success').show().html('Dc added Successfully');
                                                   setTimeout(function(){location.href="<?php echo base_url('order_qc/qurantine_print/'); ?>"+data} , 3000);
                                                }else{
                                                    console.log('third'+data);          
                                                }
                                            },
                                            error:function(data){console.log(data.responseText);}
                                        });
                                    }
                                });

                       /* }

                      });
                    });*/
             </script>