<html>
  <head>
    
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Rizwan </title>
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="<?php echo base_url();?>assets/images/favicon.png">
    <link rel="stylesheet" href="<?php echo base_url();?>assets/vendor/bootstrap-select/dist/css/bootstrap-select.min.css">
    <link rel="stylesheet" href="<?php echo base_url();?>assets/css/style.css">
    <!-- Pick date -->
    <link rel="stylesheet" href="<?php echo base_url();?>assets/vendor/pickadate/themes/default.css">
    <link rel="stylesheet" href="<?php echo base_url();?>assets/vendor/pickadate/themes/default.date.css">
     <link href="<?php echo base_url();?>assets/vendor/datatables/css/jquery.dataTables.min.css" rel="stylesheet">
    <!-- Custom Stylesheet -->
     

</head>
<body>
 

  <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>
                                   <button class="btn btn-warning" onclick="printData1();">Print me</button> 
                     
<?php 

$TotalNoOfRecords = count($get_products_semi);
//print_r($TotalNoOfRecords);
$Count = 0;
 ?>

<div id="container">
  <div class="card-header">
                             <img src="<?php echo base_url();?>assets/logo.png" style="width:105px;"/><br/>
                                <span class="float-right">
                                    <strong>Semi Finish Good Report -:</strong><?php echo date('d-m-Y') ?><br/>
                                   
                                      <strong> </strong></span>
                                </div>
  <table id="example5" class="" border="1" width="600px" style=" font-size: 13px;">
    
  <thead>
                                            <tr>
                                                <th>Product Name</th>
                                                <th>Last Balance</th>
                                                <th>Qty Receive</th>
                                                <th>Qty Deliver</th>
                                                <th>Balance</th> 
                                                <!-- <th>Action</th> -->
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php if(!empty($get_products_semi)){
     
                                foreach ($get_products_semi as $value) {  ?>
                                            <tr>
                                                <td><?php  echo product_name($value['product_id']); ?></td>
                                                    <td><?php

                                                     echo get_last_all($value['product_id'])-get_out_all($value['product_id']);
                                                     
                                                  
                                                    ?></td>
                                                             
                                                    <td><?php 
                                                    $get_log_stock = get_last($value['product_id']); 
                                                    $get_log_stock_date = get_last_created_date($value['product_id']);
                                                    $newDate_in = date("Y-m-d", strtotime($get_log_stock_date)); 
                                                    $today_in = date('Y-m-d');

                                                    if($get_log_stock !="" && $newDate_in == $today_in){

                                                        echo get_last($value['product_id']);
                                                    }else{
                                                       echo get_last($value['product_id']);
                                                    }
                                                     ?></td>
                                                   
                                                    
                                                    <td><?php
                                                    $get_out_stock_date = get_last_created_date_out($value['product_id']);
                                                    $newDate_out = date("Y-m-d", strtotime($get_out_stock_date)); 
                                                    $today_out = date('Y-m-d');
                                                     if($get_out_stock_date !="" && $newDate_out == $today_out){
                                                         echo get_out($value['product_id']);
                                                        }else {
                                                            echo get_out($value['product_id']);
                                                        }
                                                     ?></td>
                                                            
                                                    <td><?php 

                                                    echo get_in_balance($value['product_id'])-get_out_balance($value['product_id']); 
                                                   

                                                    ?></td> 
                                                                                             
                                            </tr>

                                            <?php }} ?>
                                           
                                        </tbody>
    
  </table>
</div>

</body>
</html>
<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,"Generation_School_Report");
    }  
    else                 //other browser not tested on IE 11
        sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));  

    return (sa);
}
</script>