<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();
?>
		 <style>
			select.error { background-color:#ffa8a8; border: 1px dotted red;  }
			input.error{ background-color:#ffa8a8;   }
			textarea.error{ background-color:#ffa8a8; border: 1px dotted red;  }
         </style>
		 
        


<style type="text/css">
<!--
.table_bg{ border:#CCCCCC solid 1px; border-radius:5px; height:auto; width:auto; padding:20px; margin-bottom:10px;}


-->
</style>

<script type="text/javascript">
 
function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

</script>
<script type="text/javascript">
	$(document).ready(function() {                
	$("#form1").validate({
	rules: {
	
	client_name: "required",
	
	
	},
	messages: {
	
	client_name:"",
	
	},
	});                
	});
	</script>
<!-- Page wrapper  -->
        <div class="page-wrapper">
          
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
              <h4>GST BC Report<span style="float:right"><button onclick="goBack()" class="btn btn-info btn-sm">Go Back</button><script>
function goBack() {
  window.history.back();
}
</script></span></h4>
							<hr />
<form name="form1" id="form1" method="post">
  <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
    <tr>
      <td width="6%" height="49" ><strong>From Date </strong></td>
      <td width="1%"><strong>:</strong></td>
      <td width="15%"><input name="s_date" type="date" class="tcal form-control" id="s_date"  value="<?=date('d-m-Y')?>"/></td>
      <td width="7%"><strong>To Date </strong></td>
      <td width="1%"><strong>:</strong></td>
      <td width="23%"><input name="end_date" type="date" class="tcal form-control" id="end_date" value="<?=date('d-m-Y')?>" /></td>
      <td width="1%">GST</td>
      <td width="1%"><select name="gstper" id="gstper" style="width:200px;"  class="required form-control">
      <option value="">---Please Select---</option>
      <?php 
							$sqlc="SELECT distinct cgst FROM tbl_sales_detail where session_login_id = '".$_SESSION['login_id']."' order by cgst";
							//echo $sqlc;
							$c=mysql_query($sqlc);
							if(mysql_num_rows($c)>0){
							while($cs=mysql_fetch_array($c))
							{?>
      <option value="<?=$cs["cgst"];?>" <?php if(($cs["cgst"])==$_POST["gstper"]){ ?> selected="selected" <?php }?>>
      <?=$cs["cgst"];?>
      </option>
      <?php }}?>
    </select></td>
      <td width="22%"><input type="submit" name="Search" value="Search" class="btn btn-info" /></td>
      </tr>
  </table>
</form>
<br />

<?php 
if(isset($_POST["Search"]))
{
/*$s_date=$objIms->DateToInt($_POST["s_date"]);
$end_date=$objIms->DateToInt($_POST["end_date"]);*/
$sdt = date('d-m-y', strtotime($_POST["s_date"]));
$s_date=$objIms->DateToInt($sdt);
$edt = date('d-m-y', strtotime($_POST["end_date"]));
$end_date=$objIms->DateToInt($edt);
$gstper=$_POST["gstper"];

?>
    <input type="hidden" name="rahul" id="rahul" value="<?='BC for '.$gstper?>" />   
            
		
            <?php 
				    $sql_viewtmp="select * from view_sales_mstrdet where session_login_id = '".$_SESSION['login_id']."' and   stampdate>='$s_date' and stampdate<='$end_date' and cgst='$gstper' and cancel_status=0";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					$sums=0;
					$tottaxval=0;
					$totcgst=0;
					$totsgst=0;
					$totigst=0;
					?>
					<div id="table_wrapper">
					<div id="printableArea">
					<div class="panel">
					<div class="panel-heading">Gst Item Report of <?=$gstper?> percent From <?php echo $_POST["s_date"];?> To <?php echo $_POST["end_date"];?></div>
					<p>&nbsp;</p>
                    <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                     <tr height="32" align="left">
            <th>Si No</th>
            <th >Sale Date </th>
            <th >Sale No </th>
            
            
            <th >Item Name</th>
           <th >HSN</th>
           
            <th>Unit Price </th>
            <th >Qty</th>
            <th >Taxable Value </th>
            
            <th >Cgst Value </th>
            
            <th >Sgst Value </th>
            
                     </tr>
            <?php
				while($rows=mysql_fetch_assoc($res_viewtmp))
					{
					$item_id=$rows["item_id"];	
					$unit_id=$rows["unit_id"];
					$client_id=$rows["client_id"];	
						
					$sql_it="select * from tbl_item where id='$item_id' and session_login_id = '".$_SESSION['login_id']."'";
				$res_it=mysql_query($sql_it);
				$rsit=mysql_fetch_array($res_it);
					
					$sql_ut="select * from tbl_unit where id='$unit_id' and session_login_id = '".$_SESSION['login_id']."'";
				$res_ut=mysql_query($sql_ut);
				$rsut=mysql_fetch_array($res_ut);
				
					
			?>
           
            <tr>
            <td ><?php echo $i++;?></td>
           
		    <td ><?php echo $objIms->IntToDate($rows["stampdate"]);?></td>
		    
		    <td ><?php echo $rows["sale_no"];?></td>		    
            
            <td ><?php echo $rsit["item_name"];?></td>
            <td ><?php echo $rsit["hsn_code"];?></td>
            <td  width="17%"><?php echo $rows["unit_price"];?></td>
            <td ><?php echo $rows["qty"];?></td>
            <td ><?php echo $taxval=round(($rows["qty"]*$rows["unit_price"])-($rows["qty"]*$rows["unit_price"]*$rows["discount"]/100),2);$tottaxval+=$taxval;?></td>
            
            <td ><?php echo $cgstval=round(($rows["cgst"]*$taxval)/100,2);$totcgst+=$cgstval;?></td>
            
            <td ><?php echo $sgstval=round(($rows["sgst"]*$taxval)/100,2); $totsgst+=$sgstval;?></td>
            
            
            </tr>
            
            <?php }?>
			<tr height="32">
              <td colspan="7" ><div align="right"><strong>Total : </strong></div></td>
              <td ><strong><?php echo $tottaxval;?></strong></td>
              
              <td ><strong><?php echo $totcgst;?></strong></td>
              
              <td ><strong><?php echo $totsgst;?></strong></td>
              
              
            </tr>   
           </table>
		   </div>
		   </div>
		   </div>
    <?php }
	else
	{
	echo '<span style="color:#FF0000">No Data Found</span>';
	}
	}?>
	
		

   
<p></p>
		<br />
        


</div>
<br />

<div align="center"><span class="btn btn-info" onClick="printDiv('printableArea')">Print</span> &nbsp;&nbsp;<button id="btnExport" class="btn btn-success">Export to Excel</button></div>
 </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
<?php include 'footer.php' ?>

  <script>
  $(document).ready(function() {
  $("#btnExport").click(function(e) {
    e.preventDefault();

    //getting data from our table
    var data_type = 'data:application/vnd.ms-excel';
    var table_div = document.getElementById('table_wrapper');
    var table_html = table_div.outerHTML.replace(/ /g, '%20');

    var a = document.createElement('a');
    a.href = data_type + ', ' + table_html;
    a.download = document.getElementById('rahul').value + '.xls';
    a.click();
  });
});
</script>

 <script src="../js/lib/datatables/datatables.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
    <script src="../js/lib/datatables/cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>
    <script src="../js/lib/datatables/datatables-init.js"></script>