<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();

function callvalue($sale_no,$val)
{
   $sql_viewtmp="select sum(qty*unit_price) as taxvalue from view_sales_mstrdet where  sale_no='$sale_no' and cgst='$val' group by client_id";
				$res_viewtmp=mysql_query($sql_viewtmp);
				$rsw=mysql_fetch_array($res_viewtmp);
				if(isset($rsw["taxvalue"]))
				{
				$showamt=$rsw["taxvalue"];
				}
				else
				{
				 $showamt=0;
				}
				 
				return $showamt;
}

function callvaluetotal($s_date,$end_date,$client_id,$val)
{
   $sql_viewtmp="select sum(qty*unit_price) as taxvalue from view_sales_mstrdet where  stampdate>='$s_date' and stampdate<='$end_date' and client_id='$client_id' and cgst='$val' group by client_id";
				$res_viewtmp=mysql_query($sql_viewtmp);
				$rsw=mysql_fetch_array($res_viewtmp);
				if(isset($rsw["taxvalue"]))
				{
				$showamt=$rsw["taxvalue"];
				}
				else
				{
				 $showamt=0;
				}
				 
				return $showamt;
}


?>


	<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>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

		
	
		 <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>
</head>
<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>

<body>

<div class="span11" style=" width:83%;">



<div class="12" style=" margin-left:0px; ">



<br />
<br />
<br />

<div class="12" style=" margin-left:0px;">

<div class="panel" style="border:<?php echo THEMECOLOR?> solid 1px; border-radius:0px;">
<div class="entry-head" >
<h4>View GSTR 3-B Report</div>
<p>&nbsp;</p>
<form name="form1" id="form1" method="post">
  <table  width="100%" border="0" align="center">
  <tr>
  <td width="24%"><div align="right">Month</div></td>
      <td width="12%">
	    <div align="center">
	      <select name="month" id="month" style="width:100px;"  class="required">
	        <option value="" style="display:none">-Select-</option>
	        <option value="01" <?php if($_POST["month"]=='01'){ ?> selected="selected" <?php }?>>Jan</option>
			<option value="02" <?php if($_POST["month"]=='02'){ ?> selected="selected" <?php }?>>Feb</option>
			<option value="03" <?php if($_POST["month"]=='03'){ ?> selected="selected" <?php }?>>Mar</option>
			<option value="04" <?php if($_POST["month"]=='04'){ ?> selected="selected" <?php }?>>Apr</option>
			<option value="05" <?php if($_POST["month"]=='05'){ ?> selected="selected" <?php }?>>May</option>
			<option value="06" <?php if($_POST["month"]=='06'){ ?> selected="selected" <?php }?>>Jun</option>
			<option value="07" <?php if($_POST["month"]=='07'){ ?> selected="selected" <?php }?>>Jul</option>
			<option value="08" <?php if($_POST["month"]=='08'){ ?> selected="selected" <?php }?>>Aug</option>
			<option value="09" <?php if($_POST["month"]=='09'){ ?> selected="selected" <?php }?>>Sept</option>
			<option value="10" <?php if($_POST["month"]=='10'){ ?> selected="selected" <?php }?>>Oct</option>
			<option value="11" <?php if($_POST["month"]=='11'){ ?> selected="selected" <?php }?>>Nov</option>
	      	<option value="12" <?php if($_POST["month"]=='12'){ ?> selected="selected" <?php }?>>Dec</option>
            </select>
        </div></td>
		<td width="7%"><div align="right">Year</div></td>
      <td width="8%">
	    <div align="center">
	      <select name="yyear" id="yyear" style="width:100px;"  class="required">
	        <option value="" style="display:none">-Select-</option>
			<?php for($yy=2017;$yy<=date('Y');$yy++)
			{?>
	        <option value="<?=$yy?>" <?php if($_POST["yyear"]==$yy){ ?> selected="selected" <?php }?>><?=$yy?></option>	
			<?php }?>		
            </select>
        </div></td>
	<td width="49%"><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"]);
$mm=$_POST["month"];
$yy=$_POST["yyear"];

$s_date=$objIms->DateToInt('01-'.$mm.'-'.$yy);
$end_date=$objIms->DateToInt(date("t-m-Y",$objIms->DateToInt('01-'.$mm.'-'.$yy)));
 $month=date("F",$s_date);	
 ?>
 <input type="hidden" name="rahul" id="rahul" value="<?='3-B for '.$month.' '.$yy?>" /> 
<?php 				
							$sql_viewtmp="select sum(qty*unit_price) as taxvalue,cgst,sgst from view_sales_mstrdet where stampdate>='$s_date' and stampdate<='$end_date' and cancel_status=0 and cgst>0 group by cgst,sgst";
							$res_viewtmp=mysql_query($sql_viewtmp);
							$saletaxval=0;
							$salecgst=0;
							$salesgst=0;
							while($rws=mysql_fetch_array($res_viewtmp))
							{
							if($rws["taxvalue"]<>''){$sval=$rws["taxvalue"];}else{$sval=0;}
							$saletaxval+=$sval;
							$scgst=($rws["cgst"]/100)*$sval;$salecgst+=$scgst;
							$ssgst=($rws["sgst"]/100)*$sval; $salesgst+=$ssgst;
							
							}
							
							
							$sql_intertmp="select sum(qty*unit_price) as taxvalue,igst from view_sales_mstrdet where stampdate>='$s_date' and stampdate<='$end_date' and cancel_status=0 and igst>0 group by igst";
							$res_intertmp=mysql_query($sql_intertmp);
							$saletaxvalinter=0;
							$saleigstinter=0;
							while($rwsinter=mysql_fetch_array($res_intertmp))
							{
							if($rwsinter["taxvalue"]<>''){$svalinter=$rwsinter["taxvalue"];}else{$svalinter=0;}$saletaxvalinter+=$svalinter;
							$sigstinter=($rwsinter["igst"]/100)*$svalinter;$saleigstinter+=$sigstinter;
							}
							
							$sql_viewpur="select sum(pur_qty*pur_price) as taxvalue,cgst,sgst from view_pur_masdet where purchase_date>='$s_date' and purchase_date<='$end_date' and cgst>0 group by cgst,sgst";
							$res_viewpur=mysql_query($sql_viewpur);
							$rwspur=mysql_fetch_array($res_viewpur);
							if($rwspur["taxvalue"]<>''){$purtaxval=$rwspur["taxvalue"];}else{$purtaxval=0;}
							$purcgst=($rwspur["cgst"]/100)*$purtaxval;
							$pursgst=($rwspur["sgst"]/100)*$purtaxval;
							
							
							$sql_interpur="select sum(pur_qty*pur_price) as taxvalue,igst from view_pur_masdet where purchase_date>='$s_date' and purchase_date<='$end_date' and igst>0 group by igst";
							$res_interpur=mysql_query($sql_interpur);
							$rwsinterpur=mysql_fetch_array($res_interpur);
							if($rwsinterpur["taxvalue"]<>''){$purtaxvalinter=$rwsinterpur["taxvalue"];}else{$purtaxvalinter=0;}
							$purigstinter=($rwsinterpur["igst"]/100)*$purtaxvalinter;
							

?>
     
            
		
					<div id="table_wrapper">
					<div id="printableArea">
					<div class="panel">
					<div class="panel-heading">GSTR1 3-B Report For <?php echo $month;?> <?php echo $_POST["yyear"];?></div>
					<p>&nbsp;</p>
                     <table width="100%" border="0">
  <tr>
    <td width="23%"><strong>Sale Summary(Intra State) :- </strong></td>
    <td width="11%">&nbsp;</td>
    <td width="22%"><strong>Sale Summary(Inter State) :- </strong></td>
    <td width="13%">&nbsp;</td>
    <td width="20%"><strong>Total Sale Summary :- </strong></td>
    <td width="11%">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Taxable Value : </td>
    <td><?=round($saletaxval,2)?></td>
    <td>Taxable Value : </td>
    <td><?=round($saletaxvalinter,2)?></td>
    <td>Total Taxable Value : </td>
    <td><?=round(($saletaxval+$saletaxvalinter),2)?></td>
  </tr>
  <tr>
    <td>Central Tax : </td>
    <td><?=round($salecgst,2)?></td>
    <td>Integrated Tax : </td>
    <td><?=round($saleigstinter,2)?></td>
    <td>Central Tax :</td>
    <td><?=round($salecgst,2)?></td>
  </tr>
  <tr>
    <td>State Tax : </td>
    <td><?=round($salesgst,2)?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>State Tax :</td>
    <td><?=round($salesgst,2)?></td>
  </tr>
  <tr>
    <td>Cess : </td>
    <td><?=0?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Integrated Tax :</td>
    <td><?=round($saleigstinter,2)?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Cess :</td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td><strong>Sales Return Summary(Intra State) :- </strong></td>
    <td>&nbsp;</td>
    <td><strong>Sales Return Summary(Inter State) :- </strong></td>
    <td>&nbsp;</td>
    <td><strong>Total Sales Return Summary :- </strong></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Taxable Value : </td>
    <td><?=0?></td>
    <td>Taxable Value : </td>
    <td><?=0?></td>
    <td>Total Taxable Value : </td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td>Central Tax : </td>
    <td><?=0?></td>
    <td>Integrated Tax : </td>
    <td><?=0?></td>
    <td>Central Tax :</td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td>State Tax : </td>
    <td><?=0?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>State Tax :</td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td>Cess : </td>
    <td><?=0?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Integrated Tax :</td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Cess :</td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td><strong>Purchase Summary(Intra State) :- </strong></td>
    <td>&nbsp;</td>
    <td><strong>Purchase Summary(Inter State) :-</strong></td>
    <td>&nbsp;</td>
    <td><strong>Total Purchase Summary :-</strong></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Taxable Value : </td>
    <td><?=round($purtaxval,2)?></td>
    <td>Taxable Value : </td>
    <td><?=round($purtaxvalinter,2)?></td>
    <td>Total Taxable Value : </td>
    <td><?=round(($purtaxval+$purtaxvalinter),2)?></td>
  </tr>
  <tr>
    <td>Central Tax : </td>
    <td><?=round($purcgst,2)?></td>
    <td>Integrated Tax : </td>
    <td><?=round($purigstinter,2)?></td>
    <td>Central Tax :</td>
    <td><?=round($purcgst,2)?></td>
  </tr>
  <tr>
    <td>State Tax : </td>
    <td><?=round($pursgst,2)?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>State Tax :</td>
    <td><?=round($pursgst,2)?></td>
  </tr>
  <tr>
    <td>Cess : </td>
    <td><?=0?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Integrated Tax :</td>
    <td><?=round($purigstinter,2)?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Cess :</td>
    <td><?=0?></td>
  </tr>
  
  <tr>
    <td><strong>Purchase Return Summary(Intra State) :- </strong></td>
    <td>&nbsp;</td>
    <td><strong>Purchase Return Summary(Inter State) :- </strong></td>
    <td>&nbsp;</td>
    <td><strong>Total Purchase Return Summary :- </strong></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Taxable Value : </td>
    <td><?=0?></td>
    <td>Taxable Value : </td>
    <td><?=0?></td>
    <td>Total Taxable Value : </td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td>Central Tax : </td>
    <td><?=0?></td>
    <td>Integrated Tax : </td>
    <td><?=0?></td>
    <td>Central Tax :</td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td>State Tax : </td>
    <td><?=0?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>State Tax :</td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td>Cess : </td>
    <td><?=0?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Integrated Tax :</td>
    <td><?=0?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Cess :</td>
    <td><?=0?></td>
  </tr>
</table>

		   </div>
		   </div>
		   </div>
    <?php 
	}?>
	
		

   
<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>
</body>
</html>
