              <?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>Total Qty</th>
                                                <th>Remaining Qty</th>
                                               <th>Unit</th>
                                               <th>Date</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php if(!empty($get_invoice_data1)) {?>
                                                <?php //foreach ($get_invoice_data1 as $all_get_po) {
                                                   
                                                 ?>
                                            <tr> 
                                                <td><strong><?php echo  $get_invoice_data1[0]['po_no']; ?></strong></td>
                                              
                                                    <?php if($get_invoice_data1[0]['product_id']!=0){ ?>
                                                    <td><strong><?php echo product_name($get_invoice_data1[0]['product_id']); ?></strong></td>
                                                  <?php }else{ ?>
                                                    <td><strong><?php echo material_name($get_invoice_data1[0]['material_id']); ?></strong></td>
                                                  <?php } ?>
                                                  <td><?php echo $get_invoice_data1[0]['order_qty']; ?></td>

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

                                                <td><strong><?php echo $get_invoice_data1[0]['order_qty'];?></strong></td>
                                                <td><strong><?php echo get_unit_name($get_invoice_data1[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_data1[0]['unit']); ?></strong></td>
                                                <?php } ?>

                                                <td><?php  echo date("d-m-Y", strtotime($get_invoice_data1[0]['po_date']) ); ?></td>
                                            </tr>
                                        <?php }
                                              // }
                                         ?>
                                          
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <?php 
                        $dc_qty = $get_dc_qty[0]['qty'];
                         $mat_qty = $get_invoice_data1[0]['order_qty'];
                        $total = $mat_qty-$dc_qty;

                        if($total == 0){

                          echo "";
                        }//else

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

                  <input type="hidden" name="tqty" id="tqty"  value="<?php echo $get_invoice_data1[0]['order_qty']; ?>"/> 
                        <?php 
                          $dc_qty = $get_dc_qty[0]['qty'];
                          $mat_qty = $get_invoice_data1[0]['order_qty'];
                          $total_condition =  $mat_qty-$dc_qty;  
                           ?>
                    <input type="hidden" name="total" id="total"  value="<?php echo  $total_condition; ?>"/> 



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

                        <input type="hidden" name="gst"  id="gst" value="<?php echo $get_invoice_data1[0]['gst']; ?>">
                           
                            <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" readonly="readonly" value="<?php echo $dc_no; ?>" id="dc_no"  class="form-control required"> -->

                                     <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" onkeypress="return isNumberKey(event)">
                        </div>
                    </div>

                    <div class="col-lg-4 col-md-4 col-sm-8">
                        <div class="form-group">
                            <label class="form-label">Lot No</label>
                            <input type="text" name="lot_no" id="lot_no" required="required" placeholder="Lot Number" class="form-control">
                        </div>
                    </div>

                    <div class="col-lg-4 col-md-4 col-sm-8">
                        <div class="form-group">
                            <label class="form-label">Qc Release #</label>
                            <input type="text" name="release_no" id="release_no" value="<?php echo $codes; ?>" required="required" readonly="readonly" class="form-control" onkeypress="return isNumberKey(event)">
                        </div>
                    </div>

                     <div class="col-lg-4 col-md-4 col-sm-8">
                        <div class="form-group">
                            <label class="form-label">Remarks</label>
                            <textarea name="remarks" id="remarks"  placeholder="Remarks" class="form-control "></textarea>
                        </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="grn_no" id="grn_no" value="<?php echo $grn_code; ?>">
                       <input type="hidden" name="po_id" id="po_id" value="<?php echo $get_invoice_data1[0]['pur_id']; ?>">
                        <input type="hidden" name="date_challan" id="date_challan" value="<?php echo date('Y-m-d'); ?>">
                </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">
                 
              function isNumberKey(evt)
                   {
                      var charCode = (evt.which) ? evt.which : evt.keyCode;
                      if (charCode != 46 && charCode > 31 
                        && (charCode < 48 || charCode > 57))
                         return false;
            
                      return true;
                   }

                           var dc = $('#add_dc');   
    
                                dc.on('submit',function(e){
                                 
       
                                    e.preventDefault();
                                    
                                    var dcdata = dc.serialize();
                                    //var tqty = parseInt($("#tqty").val());
                                     var total = parseInt($("#total").val());
                                        var qty = parseInt($("#qty").val());
                                      

                                        /*if (total < qty) {
                                            alert("Quantity Greater Then PO Quantity..!");
                                           
                                        }else{*/
                                    $("#dc_dis").attr('disabled', true);
                                        $.ajax({
                                            type:'POST',
                                            url:'<?php echo base_url('Purchase_order/pending_orders1'); ?>',
                                            data:dcdata,
                                            dataType:'json',
                                            success:function(data){
                                                console.log('first'+data.id);
                                               // alert(data);
                                                if(data.status !=''){
                                                    console.log(data);
                                                    $('#add_dc_success').show().html('Dc added Successfully');
                                                   setTimeout(function(){location.href="<?php echo base_url('Purchase_order/qurantine_print/'); ?>"+data} , 3000);
                                                }else{
                                                    console.log('third'+data);          
                                                }
                                            },
                                            error:function(data){console.log(data.responseText);}
                                        });
                                    //}
                                });

                       /* }

                      });
                    });*/

                    /* $( document ).ready(function() {

                
    
               // var id = $('#type').val();

                   $.ajax({
                            type:'POST',
                            url:'<?php echo base_url('Sales_order/dc_code'); ?>',
                           // data:{id:id},
                            dataType:'json',
                            success:function(data){
                                console.log(data);
                                $('#dc_no').val(data);
                                //alert(data);
                                
                            },
                            error:function(data){console.log(data.responseText);}
                        });

    });*/
             </script>