<?php require "_header.php";

include "Numbers/Words.php"; ?>

<div id="main-report" align="center">



<?php 



ini_set('memory_limit', '256M');

/*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();

	

	$agencyid = $_SESSION["cCompany_id"];

	

	$headerflag=$_REQUEST['headerflag'];

	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(invoice_date as Date) >= '$startdate' ";  
		 $cond.= " AND CAST(invoice_date as DATE) <=  '$enddate' ";  
	}

	$qry = " SELECT * from csc_customer as cm,lms_customersupport as cs
			where 1= 1 and cm.customer_id = cs.customer_id ";
 $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>VoucherType</th>
		<th>VoucherNumber</th>
		<th>Date</th>
		<th>Ref No</th>
		<th>Ref Date</th>
		<th>Party Name</th>
		<th>State</th>
		<th>GST No</th>
		<th>Payment Terms</th>
		<th>Terms of Delivery</th>
		<th>Dispatch Through</th>
		<th>Docket No</th>
		<th>Destination/State</th>
		<th>Sales Ledger</th>
		<th>Nature Of Transaction</th>
		<th>ITEM Name</th>
		<th>Qty</th>
		<th>Rate</th>
		<th>Discount</th>
		<th>Amount</th>
		<th>Item Desc1</th>
		<th>Item Desc2</th>
		<th>Item Desc3</th>
		<th>Tax Name(CGST)</th>
		<th>Tax Rate</th>
		<th>Tax Amount</th>
		<th>Tax Name(SGST)</th>
		<th>Tax Rate</th>
		<th>Tax Amount</th>
		<th>Tax Name(IGST)</th>
		<th>Tax Rate</th>
		<th>Tax Amount</th>
		<th>Tax Name4</th>
		<th>Tax Rate4</th>
		<th>Tax Amount4</th>
		<th>Tax Name5</th>
		<th>Tax Rate5</th>
		<th>Tax Amount5</th>
		<th>Total Amount</th>
		<th>Consignee Name</th>
		<th>Consignee Address</th>
		<th>Consignee GST No</th>
		<th>Consignee State</th>
		<th>Buyer Name</th>
		<th>Buyer Address</th>
		<th>Buyer Country</th>
		<th>Buyer State</th>
		<th>Buyer State of Supply</th>
		<th>Buyer Reg Type</th>
		<th>Buyer GSTNO</th>
		<th>CSC ID</th>

	</tr>

	<?php

	while($row = dbArray($rs))
	{
		$support_id = $row['support_id'];
		$amount = round(($row['mrp']*100)/118,2);
		$tamount= round(($row['mrp']));
		$totalamount = $row['quantity'] * $amount;	
			$gst = round(($totalamount*18)/100,2);
			$ttotalamount = $row['quantity'] * $tamount;
		$sql = "select group_concat(distinct cost) as cost,expenses from lms_supportexpenses where support_id='$support_id' GROUP by expenses";
		$rs1 = dbQuery($sql);
		while($row1 = dbArray($rs1))
		{
	?>	
	<tr>
	<td><?php echo $sno++; ?>
	<td>
	<?php if($row['gst_no'] != '')
	{
	echo "Tax Sales Invoice - AICG";
	}
	else
	{
	echo "Retail Sales - AICG";
	}

	?>

	</td>

	<td>

	<?php 

		if($row['gst_no'] != '')

		{

		$len = strlen($row['invoice_no']);

		if($len == 1)

		{

		echo 'AICG/2627/T0000'.$row['invoice_no'] ;	

		}

		else if($len == 2)

		{

		echo 'AICG/2627/T000'.$row['invoice_no'] ;	

		}

		else if($len == 3)

		{

		echo 'AICG/2627/T00'.$row['invoice_no'] ;	

		}

		else if($len == 4)

		{

		echo 'AICG/2627/T0'.$row['invoice_no'] ;	

		}

		else if($len == 5)

		{

		echo 'AICG/2627/T'.$row['invoice_no'] ;	

		}

		}

		else

		{

			

		$len = strlen($row['invoice_no']);

		if($len == 1)

		{

		echo 'AICG/2627/R0000'.$row['invoice_no'] ;	

		}

		else if($len == 2)

		{

		echo 'AICG/2627/R000'.$row['invoice_no'] ;	

		}

		else if($len == 3)

		{

		echo 'AICG/2627/R00'.$row['invoice_no'] ;	

		}

		else if($len == 4)

		{

		echo 'AICG/2627/R0'.$row['invoice_no'] ;	

		}

		else if($len == 5)

		{

		echo 'AICG/2627/R'.$row['invoice_no'] ;	

		}

		}

		?>

		</td>

		<td><?php echo date("d-m-Y",strtotime($row['invoice_date']));?></td>

		<td><?php echo $row['order_no'];?></td>

		<td><?php echo date("d-m-Y",strtotime($row['order_date']));;?></td>

		<td><?php echo $row['estore_name'];?></td>

		<td><?php echo $row['state'];?></td>

		<td><?php echo $row['gst_no'];?></td>

		<td>Advance</td>

		<td>&nbsp;</td>

		<td><?php echo $row['courier_company'];?></td>

		<td><?php echo $row['courier_no'];?></td>

		<td><?php echo $row['state'];?></td>

		<?php 

		if($row1['expenses'] == 'MFS100V54')

		{

		?>

		<td>Sales of Finger Print Scanner CSC Gramin</td>

		<?php 

		}

		else if($row1['expenses'] == 'MFS110 L1')

		{

		?>

		<td>Sales of Finger Print Scanner CSC Gramin</td>

		<?php

		}

		else if($row1['expenses'] == 'MIS100V2')

		{

		?>

		<td>Sales of IRIS Scanner CSC Gramin</td>

		<?php

		}

		?>

		<td><?php

			if($row['state'] == 'Gujarat')

			{

				echo 'Sales Taxable';

			}

			else

			{

				echo 'Interstate Sales Taxable';

			}

			?></td>

			<td><?php echo $row1['expenses'];?></td>

			<td><?php echo $row['quantity'];?></td>

			<?php

			if(($row['product_name'] == 'Combo (IRIS Scanner and Finger Print) Pack' || $row['product_name'] == 'Combo (IRIS Scanner and Finger Print) 1 Pack'|| $row['product_name'] == 'COMBO (IRISScanner and FingerPrint) 1 pcs'|| $row['product_name'] == 'COMBO_MFS110_IRIS100V2 1 Pack')  && $row1['expenses'] == 'MFS100V54'||$row1['expenses'] == 'MFS110 L1')

			{

			?>

				<td>2541.53</td>

			<?php

			}

			else if(($row['product_name'] == 'Combo (IRIS Scanner and Finger Print) Pack' || $row['product_name'] == 'Combo (IRIS Scanner and Finger Print) 1 Pack'|| $row['product_name'] == 'COMBO (IRISScanner and FingerPrint) 1 pcs'|| $row['product_name'] == 'COMBO_MFS110_IRIS100V2 1 Pack') && $row1['expenses'] == 'MIS100V2')

			{

			?>

				<td>2728.81</td>

			<?php

			}

			else
			{
			?>
			<td><?php echo $amount;?></td>
			<?php
			}
			?>
			<td>0%</td>
			<?php

			if(($row['product_name'] == 'Combo (IRIS Scanner and Finger Print) Pack'|| $row['product_name'] == 'Combo (IRIS Scanner and Finger Print) 1 Pack'|| $row['product_name'] == 'COMBO (IRISScanner and FingerPrint) 1 pcs'|| $row['product_name'] == 'COMBO_MFS110_IRIS100V2 1 Pack') && $row1['expenses'] == 'MFS100V54'||$row1['expenses'] == 'MFS110 L1')
			{
			?>
				<td><?php echo round(($row['quantity'] * 2541.53),2) ?></td>
			<?php
			}

			else if(($row['product_name'] == 'Combo (IRIS Scanner and Finger Print) Pack'|| $row['product_name'] == 'Combo (IRIS Scanner and Finger Print) 1 Pack'|| $row['product_name'] == 'COMBO (IRISScanner and FingerPrint) 1 pcs'|| $row['product_name'] == 'COMBO_MFS110_IRIS100V2 1 Pack') && $row1['expenses'] == 'MIS100V2')

			{

			?>

				<td><?php echo round(($row['quantity'] * 2728.81),2) ?></td>

			<?php

			}

			else

			{

			?>

			<td><?php echo round(($row['quantity'] * $amount),2) ?></td>

			

			<?php

			}

			?>

			<td><?php echo 'SR No. '.$row1['cost'];?></td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			

			<?php if($row['state'] == 'Gujarat')

			{

			?>

			<td>CGST</td>

			<td>9</td>

			<td><?php echo round(($gst/2),2);?></td>

			<td>SGST</td>

			<td>9</td>

			<td><?php echo round(($gst/2),2);?></td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<?php

			}

			else

			{

			?>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>IGST</td>

			<td>18</td>

			<td><?php echo round($gst,2);?></td>

			<?php

			}

			?>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			<td>&nbsp;</td>

			

			

			

			

			<td><?php echo round(($ttotalamount));?></td>

			

			

			

			

			

			<td><?php echo $row['estore_name'];?></td>

			<td><?php echo $row['address'];?></td>

			<td><?php echo $row['gst_no'];?></td>

			<td><?php echo $row['state'];?></td>

			<td><?php echo $row['estore_name'];?></td>

			<td><?php echo $row['address'];?></td>

			<td>India</td>

			<td><?php echo $row['state'];?></td>

			<td><?php echo $row['district'];?></td>

			<td><?php if($row['gst_no'] != '')

			{

				echo "Regular";

			}

			else

			{

			echo "Unregistered/Consumer";

			}

			?></td>

			<td><?php echo $row['gst_no'];?></td>

			<td><?php echo $row['csc_id'];?></td>

		

	</tr>
<?php

	}	

	}  

		

	   ?>

</table> 



          

	   

<?php

	   $HtmlCode= ob_get_contents();

			ob_end_flush();

			$HtmlUrl 	=	"inventory-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('EXCEL');

			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";?>