<link href="<?php echo base_url(); ?>assets/vendor/datatables/css/jquery.dataTables.min.css" rel="stylesheet">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/style.css">
   
<!-- <button class="btn btn-warning" onclick="printData1();">Print me</button> -->
<div class="row">
<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>
<div class="col-12">
 <div class="card">
<div class="card-body">
<div class="table-responsive">
<div class="table-responsive" id="container">
            <h3></h3>
                <table id="example5" class="table table-striped table-bordered dataTable no-footer" style="min-width: 775px">
                    <thead>
                <tr>
                    <th>Company </th>
                    <th>S.O #</th>
                    <th>Product</th>
                    <th>Qty</th>
                    <th>Unit Price</th>
                    <th>Excluding Tax</th>
                    <th>Including Taxes</th>
                    <th>Term</th>
                    <th>DC</th>
                    <th>Action</th>
                    </tr>
            </thead>
            <tbody>
                <?php
                if(!empty($filter_data)){
                foreach ($filter_data as $value) {  ?>
                <tr>
                <td><?php echo party_name($value['party_id']); ?></td>
                <td><?php echo $value['so_no']; ?></td>
                <td><?php $product =  sale_order_pro($value['id']); 
                    echo product_name($product);
                ?></td>
                <td><?php  echo $qty = get_qty_complete_bill($value['id']); ?></td>
                <td><?php 
                $product = sale_order_pro($value['id']); 
                $rates = get_fg_rates($product);
                echo $rates; ?></td>
                <td><?php 
                    $total_with_sale_tax = $rates*$qty;
                    echo number_format($total_with_sale_tax);
                  ?></td>
                <td>
                    <?php
                          $gstRate = 0.18;
                        $totalValueWithGST = $rates * $qty *$gstRate;
                         $totalValue = $rates*$qty+$totalValueWithGST;
                         echo number_format($totalValue);
                        ?></td>
                <td><?php echo $value['pay_term']; ?></td>
                <td><?php $check_condition = check_multiple($value['id']); ?>
                    <?php if($check_condition == 'single') {?>
                    <span class="badge badge-success">Single</span>
                    <?php }else if($check_condition == 'multiple'){ ?>
                    <span class="badge badge-warning">Multiple</span>
                    <?php } ?>
                <td>
                <a href="<?php echo base_url('Sales_order/view_filter_sales_tax_bill/'.$value['id']);?> " target="_blank"  class="badge badge-primary">Sales Tax</a>                           
                <a href="<?php echo base_url('Sales_order/view_filter_sales_bill/'.$value['id']);?>" target="_blank"  class="badge badge-success">Bill</a>
                </td>
                </tr>
                <?php } ?>
            </tbody>
        </table> 
          </div>  
</div>
</div>
 </div>
</div>
                </div>    
        <?php } ?>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script type="text/javascript">
  $(document).ready(function() {
    $('#example5').DataTable();
  });
</script>
  <script type="text/javascript">
function printData1()
{
    var divToPrint=document.getElementById("container");
    newWin= window.open("");
    newWin.document.write(divToPrint.outerHTML);
    newWin.print();
    newWin.close();
}

          

function btnExport_monthly()
{
    
    var tab_text="<table border='2px'><tr bgcolor='#ebebeb'>";
    var textRange; var j=0;
    tab = document.getElementById('example5'); // id of table

    for(j = 0 ; j < tab.rows.length ; j++) 
    {     
        tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
        //tab_text=tab_text+"</tr>";
    }

    tab_text=tab_text+"</table>";
    tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
    tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
    tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params


    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE "); 

    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
    {
        txtArea2.document.open("txt/html","replace");
        txtArea2.document.write(tab_text);
        txtArea2.document.close();
        txtArea2.focus(); 
        sa=txtArea2.document.execCommand("SaveAs",true,"Banking");
    }  
    else                 //other browser not tested on IE 11
        sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));  

    return (sa);
}
        </script>
        