<?php require "_header.php";
include "Numbers/Words.php"; ?>
<div id="main-report" align="center">

<?php 
/*echo "<pre>";
print_r($_SESSION);
exit;*/
if($_SESSION['cCompany_id']!="" && isset($_SESSION['cCompany_id'])) 
{
	$customer_id = Escape($_REQUEST["ID"]);
	$startdate = Escape($_REQUEST["startdate"]);
	$enddate= Escape($_REQUEST["enddate"]);
	
 $cond = "";
	$height=300;
	$nw = new Numbers_Words();
	
/*	 if($startdate !="From" && $startdate !="To")
	{
		
		 $startdate = DateConversion($startdate,"Y-m-d","d/m/Y");
		 $enddate = DateConversion($enddate,"Y-m-d","d/m/Y");
		  $cond.= " AND CAST(createdon as Date) >= '$startdate' ";  
		  $cond.= " AND CAST(createdon as DATE) <=  '$enddate' ";  
	}
*/	
	$agencyid = $_SESSION["cCompany_id"];
	
	$headerflag=$_REQUEST['headerflag'];
	
	$qry = "SELECT SUM(mrp*quantity) as total, state,quantity from csc_customer where 1=1 AND invoice_status='printed'  group by state";
			
	$qry .= $cond;
	 $qry .= ""; 
	

	$rs = dbQuery($qry);
	$count=dbRows($rs);
	
	$j=0;

	
	ob_start();
	$i=0;
	$sno=1;
?>
<table class="report" width="100%" align="center" border="1">
	<tr>
		<th>Sr No</th>
		<th>State Name</th>
		<th>Total Amount(Without GST)</th>
		<th>CGST</th>
		<th>SGST</th>
		<th>IGST</th>
		<th>Total Amount(With GST)</th>
		
	</tr>
	<?php
	while($row = dbArray($rs))
	{
		
	?>	
	<tr>
	<td><?php echo $sno++; ?>
		<td><?php echo $row['state'];?></td>
		<?php 
		$withoutcgst = round(($row['total']*100)/118,2);
		$cgst = 		round(($withoutcgst*9)/100,2);
		$sgst = 		round(($withoutcgst*9)/100,2);
		$igst = 		round(($withoutcgst*18)/100,2);
		
		if($row['state'] == 'Gujarat')
		{
		$withoutsgsttotal += $cgst;
		$withoutcgsttotal += $sgst;
		
		?>
		<td><?php echo $withoutcgst;?></td>
		<td><?php echo $cgst;?></td>
		<td><?php echo $sgst;?></td>
		<td>&nbsp;</td>
		<?php
		}
		else
		{
		$withoutigsttotal += $igst;
		?>
		<td><?php echo $withoutcgst;?></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td><?php echo $igst;?></td>
		<?php
		}
		?>
		<td><?php echo $row['total'];?></td>
		
		
		
	</tr>
	
<?php
		
	$total += $row['total'];
	$withouttotal += $withoutcgst;
	
	
	
	}	
  
		
	   ?>
	   <tr>
	   <th><b>Total</b></th>
	   <th>&nbsp;</th>
	   <td><b><?php echo $withouttotal;?><b></td>
	   <td><b><?php echo $withoutsgsttotal;?><b></td>
	   <td><b><?php echo $withoutcgsttotal;?><b></td>
	   <td><b><?php echo $withoutigsttotal;?><b></td>
	   <td><b><?php echo $total;?><b></td>
	   
</table> 

          
	   
<?php
	   $HtmlCode= ob_get_contents();
			ob_end_flush();
			$HtmlUrl 	=	"customerbill-report-". $_SESSION["eAgencyId"].".html";
			$HtmlPath 	=	"report/".$HtmlUrl;		
			createHTMLReportPage($header_row_string,$HtmlUrl,$HtmlPath,$HtmlCode,true); 		
		?>		
		<br />
<br /><br />
		<form name="frm" id="frm" action="" method="post">		
<input type="hidden" name="txtFile" id="txtFile" value="<?php echo $HtmlUrl ;?>" />
<input type="button" name="btnPdf" id="btnPdf" value="Print" onClick="SetPageAction('PRINT');"/>
<input type="button" name="btnPdf" id="btnPdf" value="Create PDF" onClick="SetPageAction('PDF');"/>
<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onClick="SetPageAction('HTML');"/>
<input type="button" name="btnWord" id="btnWord" value="Create WORD" onClick="SetPageAction('WORD');"/>
<input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onClick="SetPageAction('Excel');"/>
		</form>
		<script language="javascript" type="text/javascript">
			//SetPageAction('PRINT');
			function SetPageAction(varAction) {
				
				if(varAction=="PRINT"){			
                        document.frm.action="print/create-print.php";
                        document.frm.submit();
                    }
			   else if(varAction=="PDF"){			
					document.frm.action="convertpdf/create-pdf.php";
					document.frm.target = "_blank";
					document.frm.submit();
				}
				else if(varAction=="HTML"){
					document.frm.action="<?php echo $HtmlPath ;?>"; 
					document.frm.target = "_blank";
					document.frm.submit();
				}
				else if(varAction=="WORD"){
					document.frm.action="convertword/create-word.php";
					document.frm.target="_blank";
					document.frm.submit();
				}
				else if(varAction=="Excel"){
					document.frm.action="convertword/create-excel.php";
					document.frm.target="_blank";
					document.frm.submit();
				}
			}
		</script> 


		<?php }require "_footer.php";?>