<?php
	//require_once("../begin_gzip.php");
	$curdir = "../";
	require_once("../include/config.php");
	require_once(GLOBAL_INCLUDE_PATH."include/startup.php");
	require_once("header1.html");
	require_once("leftnav.html");
	 error_reporting(0);

	

	$csv = (isset($_POST['csv_output'])?'1':'0');
	if ($csv=='1')
		{
			header("Content-type: application/octet-stream");
			header("Content-Disposition: attachment; filename=\"my-data.csv\"");
			
			$paymentlist = str_replace('\\"','"',$_POST['csv_output']);
			echo $paymentlist;
			exit();
		}
	
	// rcmc new issue monthwise 
	$CurFinancialYrDates = FinancialYrStartEndDates(date("m d Y"),0);
	$LastFinancialYrDates = FinancialYrStartEndDates(date("m d Y"),-1);
	
	$CurFinDates = explode('|',$CurFinancialYrDates);
	$LastFinDates = explode('|',$LastFinancialYrDates);
	
	$CurFinStartDate = $CurFinDates[0];
	$CurFinEndDate = $CurFinDates[1];
	
	$LastFinStartDate = $LastFinDates[0];
	$LastFinStartDate = $LastFinDates[1];
	
	// return various types of financial years or dates from basic function  FinancialYrStartEndDates()
	function getFinancialDates($type='',$datetouse)
	{
		//2011-2012
		$datearray = explode('-',$datetouse);
		$date = '3-31-'.$datearray[1];
		$CurFinancialYrDates = FinancialYrStartEndDates($date);	
		$CurFinDates = explode('|',$CurFinancialYrDates);
		$CurFinStartDate = $CurFinDates[0];
		$CurFinEndDate = $CurFinDates[1];
		
		switch ($type){
			case 'subperiodfull':
				$retval = formatdate($CurFinStartDate,"jS F Y")." to ".formatdate($CurFinEndDate,"jS F Y");
				break;
			case 'yearfrom':
				$retval = formatdate($CurFinStartDate,"Y");
				break;
			case 'yearto':
				$retval = formatdate($CurFinEndDate,"Y");
				break;
			case 'subperiodshort':
				$retval = formatdate($CurFinStartDate,"Y")."-".formatdate($CurFinEndDate,"Y");
				break;
			case 'subperiodlastyear':
				$datearray = explode('-',$datetouse);
				$date = '4-1-'.$datearray[0];
				$LastFinancialYrDates = FinancialYrStartEndDates($date,-1);
				$LastFinDates = explode('|',$LastFinancialYrDates);
				$LastFinStartDate = $LastFinDates[0];
				$LastFinEndDate = $LastFinDates[1];
				$retval = formatdate($LastFinStartDate,"Y")."-".formatdate($LastFinEndDate,"Y");
				break;
		}
	return $retval;	
	}
	
	$CurFinFromYear = formatdate($CurFinStartDate,"Y");
	$CurFinToYear	= formatdate($CurFinEndDate,"Y");	
	
	$fromdate = (isset($_REQUEST['from'])?$_REQUEST['from']:$CurFinStartDate);
	$todate = (isset($_REQUEST['to'])?$_REQUEST['to']:$CurFinEndDate);
	
	
	if ($_GET['csv']=='1')
	{
		$csv ='1';
		$lables = '0';
	}
	else
	{
		$csv ='0';
		$lables = '1';
	}
	
	$yearfrom = getFinancialDates('yearfrom',date("Y"));
	$yearto	= getFinancialDates('yearto',$invoiceyear);
	/* with state query
	$sqlText = "SELECT invoicesrno,invoicedate,invoiceno,membername, companytype,region, GROUP_CONCAT( DISTINCT (membershipforyear)) as membershipforyear,
				 		membershiptypenew, for_manufacturer, isManufacturer,chequeno,chequedate,
				 		chequeamount,bankname,branch, InvoiceTotalAmount,packagename,package_amount 
				 		FROM trninvoicetomember a,
					 	trninvoicetomemberdetails b,
					 	mstmember c ,
					 	mststate d,
					 	membership_packages e ,
					 	member_payment_detail f 
					 	where invoicesrno > 0 and a.memberinvoicesid=b.memberinvoicesid 
					 	and a.memberid=c.memberid 
					 	and c.StateName=d.StateName 
					 	and b.membershippackageid = e.packageid 
					 	and a.memberinvoicesid=f.memberinvoicesid 
					 	and invoicedate >= '2016-04-01' 
					 	and invoicedate <= '2017-03-31' 
					 	group by invoicesrno,chequeno,membername order by invoicesrno, package_entryfee desc";
	
		*/
		
	// without state query given below
		/*$sqlText = "SELECT invoicesrno,invoicedate,igst_amount,sgst_amount,invoiceno,membername, companytype, GROUP_CONCAT( DISTINCT (membershipforyear)) as membershipforyear,
					 membershiptypenew, for_manufacturer, isManufacturer,chequeno,chequedate,
					 chequeamount,bankname,branch, InvoiceTotalAmount,packagename,package_amount 
					 FROM trninvoicetomember a 
					 inner join trninvoicetomemberdetails b on a.memberinvoicesid=b.memberinvoicesid 
					 inner join mstmember c on a.memberid=c.memberid 
					 inner join membership_packages e on b.membershippackageid = e.packageid 
					 inner join member_payment_detail f on a.memberinvoicesid=f.memberinvoicesid
					 left join mststate d on c.head_StateName=d.StateName 
					where invoicesrno > 0   
					 and invoicedate >= '2019-04-01' 
					 and invoicedate <= '2020-03-31' 
					 group by invoicesrno,chequeno,membername order by invoicesrno, package_entryfee desc";*/
	$sqlText = " SELECT a.invoicesrno,invoicedate,igst_amount,sgst_amount,invoiceno,membername, companytype, GROUP_CONCAT( DISTINCT (membershipforyear)) as membershipforyear,
					 membershiptypenew, for_manufacturer, isManufacturer,chequeno,chequedate,
					 chequeamount,bankname,branch, InvoiceTotalAmount,packagename,package_amount 
					 FROM trninvoicetomember a 
					 inner join trninvoicetomemberdetails b on a.memberinvoicesid=b.memberinvoicesid 
					 inner join mstmember c on a.memberid=c.memberid 
					 inner join membership_packages e on b.membershippackageid = e.packageid 
					 inner join member_payment_detail f on a.memberinvoicesid=f.memberinvoicesid
					 left join mststate d on c.head_StateName=d.StateName 
                      where invoicesrno > 0   
					 and invoicedate >= '2012-04-31' 
					 and invoicedate <= '2012-05-23' 
					
					 group by invoicesrno,chequeno,membername order by invoicesrno, package_entryfee desc";
		
			
	//echo $sqlText;
	$reportheader = 'Receipt List';
	
		$products1 = new Products();
		 $productlist = $products1-> getProducts("",$sqlText);
	
		if ($productlist){$rowcount_adv = count($productlist);}else{$rowcount_adv=0;}
	
		   $maxrows = $rowcount_adv;
			$searchresultCSV = '"Sr. no.","Vch Type","Vch Date","Bank Ledger Cr","Narration","Party Ledger Dr","Party Category","Party Costcenter","Party Narration","Party Amount","Transaction Type","Cheque Amt","Instu no","Instru Date","Bank Date","Bank Name","Bank Branch","Ref Type 1","Ref Number 1","Ref Amount 1"'."\n";

			//$searchresultCSV = '"Vch No.","Vch Type","Date","Reference","Ledger Name","Amount","Cost Category","Cost Center","Dr/Cr","Bill Type","Bill Name","Narration"'."\n";
			
			//$firstLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">Membership Subscripion</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".
			//'<td width="3%">'.$invoiceno.'</td>'."\n".'<td width="9%">'.$membername.'</td>'."\n".'<td width="5%">'.$InvoiceTotalAmount.'</td>'."\n".
			//'<td width="5%">Primary Cost Category</td>'."\n".'<td width="3%">'.$region.' Region</td>'."\n".'<td width="1%">Dr</td>'."\n".'<td width="2%">New Ref</td>'."\n".
			//'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td>Membership for the Year '.$membershipforyear.'</td>'."\n".'</tr>';
		
			$searchresult1 ='<table class="table table-bordered table-striped">';
			$searchresult1 .='<thead>';
			$searchresult1 .='<tr>';
			$searchresult1 .='<th>Vch No</th>';
			$searchresult1 .='<th>Vch Type</th>';
			$searchresult1 .='<th>Date</th>';
			$searchresult1 .='<th>Reference</th>';
			$searchresult1 .='<th>Ledger Name</th>';
			$searchresult1 .='<th>Amount</th>';
			$searchresult1 .='<th>Cost Category</th>';
			$searchresult1 .='<th>Cost Center</th>';
			$searchresult1 .='<th>Dr/Cr</th>';
			$searchresult1 .='<th>Bill Type</th>';
			$searchresult1 .='<th">Bill Name</th>';
			$searchresult1 .='<th>Narration</th>';
			
			$searchresult1 .='</tr>';
			$searchresult1 .='</thead>';
				$searchresult1 .='<tbody>';
	
		
			for ($i=0;$i<$maxrows;$i++)
			{
				$invoicesrnoval = $productlist[$i]['invoicesrno'];
				if ($invoicesrno != $invoicesrnoval)
				{
					if ($adminChargesLine !='')
					{
						echo $adminChargesLine = str_replace("[adminCharges]",$adminCharges,$adminChargesLine);
					
					}
					if ($adminChargesLineCSV!='')
					{
						echo $adminChargesLineCSV = str_replace("[adminCharges]",$adminCharges,$adminChargesLineCSV);
					}
					
					//$searchresult1 .= $firstLine.$membershipSubscriptionLine.$adminChargesLine.$ServiceTaxLine;
					//$searchresultCSV .= $firstLineCSV.$membershipSubscriptionLineCSV.$adminChargesLineCSV.$ServiceTaxLineCSV;
					$searchresult1 .= $firstLine.$membershipSubscriptionLine.$adminChargesLine.$igstLine.$sgstLine;
					$searchresultCSV .= $firstLineCSV.$membershipSubscriptionLineCSV.$adminChargesLineCSV.$ServiceTaxLineCSV;
					
					$firstLine = '';
					$membershipSubscriptionLine = '';
					$adminChargesLine = '';
					$ServiceTaxLine = '';
					
					$firstLineCSV = '';
					$membershipSubscriptionLineCSV = '';
					$adminChargesLineCSV = '';
					$ServiceTaxLineCSV = '';
					$package_entryfee ='';
					$paymentType = 'Cheque/DD';

					$invoicesrno = $productlist[$i]['invoicesrno']; 
					$invoicedate = $productlist[$i]['invoicedate']; 
					$invoiceno = $productlist[$i]['invoiceno']; 
					$membername = $productlist[$i]['membername']; 
					//$InvoiceServiceTaxAmount = $productlist[$i]['InvoiceServiceTaxAmount']; 
					//$InvoiceEducationCessOnServiceTaxAmount = $productlist[$i]['InvoiceEducationCessOnServiceTaxAmount']; 
				//	$InvoiceCessOnServiceTaxAmount = $productlist[$i]['InvoiceCessOnServiceTaxAmount']; 
					$TotalTaxAmount = $InvoiceServiceTaxAmount + $InvoiceEducationCessOnServiceTaxAmount + $InvoiceCessOnServiceTaxAmount;
					$InvoiceBaseAmount = $productlist[$i]['InvoiceBaseAmount']; 
					$InvoiceTotalAmount = $productlist[$i]['InvoiceTotalAmount'];
					$chequeno			= $productlist[$i]['chequeno'];
					$chequedate			= $productlist[$i]['chequedate'];
					$chequeamount		= $productlist[$i]['chequeamount'];
					$bankname			= $productlist[$i]['bankname'];
					$branch				= $productlist[$i]['branch'];
					$igst = $productlist[$i]['igst_amount']; 
					$sgst = $productlist[$i]['sgst_amount'];
					
					$companytype = $productlist[$i]['companytype'];
					/*if($productlist[$i]['region'] == '') 
					{						
						$region = '';
					}
					else 
					{
						$region = $productlist[$i]['region'].'ern Region';
					}	*/					
					$package_entryfee = $productlist[$i]['package_entryfee']; 
					$package_amount = $productlist[$i]['package_amount'];
					$administration_charges = $productlist[$i]['administration_charges'];
					$editing_charges = $productlist[$i]['editing_charges']; 
					$membershipforyear = $productlist[$i]['membershipforyear'];
					$packagename 		= $productlist[$i]['packagename'];
					
					if ($productlist[$i]['for_manufacturer']=='1'){
						$for_manufacturer =  strtoupper('Manufacturer Exporter');
					}	
					else if ($productlist[$i]['for_manufacturer']=='0')
					{	$for_manufacturer =  strtoupper('Merchant Exporter'); }
					else if ($productlist[$i]['isManufacturer']=='1')
					{
						$for_manufacturer =  strtoupper('Manufacturer Exporter');
					}
					else if ($productlist[$i]['isManufacturer']=='0')
					{
						$for_manufacturer =  strtoupper('Merchant Exporter');
					}
					else
					{	
						$for_manufacturer =  strtoupper('Both'); 
					}
						
					if ($package_amount > 1000)
					{
						$firstLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">Membership Subscripion</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">'.$invoiceno.'</td>'."\n".'<td width="9%">'.$membername.'</td>'."\n".'<td width="5%">'.$InvoiceTotalAmount.'</td>'."\n".'<td width="5%">Primary Cost Category</td>'."\n".'<td width="3%">'.$region.'</td>'."\n".'<td width="1%">Dr</td>'."\n".'<td width="2%">New Ref</td>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td>Membership for the Year '.$membershipforyear.'</td>'."\n".'</tr>';
					//$searchresultCSV = '"Sr. no.","Vch Type","Vch Date","Bank Ledger Cr","Narration","Party Ledger Dr","Party Category","Party Costcenter","Party Narration","Party Amount","Transaction Type","Cheque Amt","Instu no","Instru Date","Bank Date","Bank Name","Bank Branch","Ref Type 1","Ref Number 1","Ref Amount 1"'."\n";
							
						$firstLineCSV = '"'.($i + 1).'","Bank Receipt -ICICI -Admn","'.formatdate($invoicedate,'d.m.Y').'","ICICI Bank Ltd. - 000405030150","Membership for the Year '.$membershipforyear.'","'.$membername.'","Primary Cost Category","'.$region.'","Membership for the Year '.$membershipforyear.'","'.$chequeamount.'","'.$paymentType.'","'.$chequeamount.'","'.$chequeno.'","'.formatdate($chequedate,'d.m.Y').'","","'.$bankname.'","'.$branch.'","Agst Ref","'.$invoiceno.'","'.$InvoiceTotalAmount.'"'."\n";
						
						$membershipSubscriptionLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">Membership Subscripion</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">&nbsp;</td>'."\n".'<td width="9%">Membership Subscription '.$membershipforyear.'</td>'."\n".'<td width="5%">'.$package_amount.'</td>'."\n".'<td width="5%">'.$for_manufacturer.'</td>'."\n".'<td width="3%">'.$membername.'</td>'."\n".'<td width="1%">Cr</td>'."\n".'<td width="2%"></td>'."\n".'<td width="2%"></td>'."\n".'<td></td>'."\n".'</tr>';
					}
					else if (($package_amount > 0)&& ($package_amount < 1000))
					{
						$firstLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">'.$packagename.'</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">'.$invoiceno.'</td>'."\n".'<td width="9%">'.$membername.'</td>'."\n".'<td width="5%">'.$InvoiceTotalAmount.'</td>'."\n".'<td width="5%">Primary Cost Category</td>'."\n".'<td width="3%">'.$region.'</td>'."\n".'<td width="1%">Dr</td>'."\n".'<td width="2%">New Ref</td>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td>'.$packagename.'</td>'."\n".'</tr>';
					//$searchresultCSV = '"Sr. no.","Vch Type","Vch Date","Bank Ledger Cr","Narration","Party Ledger Dr","Party Category","Party Costcenter","Party Narration","Party Amount","Transaction Type","Cheque Amt","Instu no","Instru Date","Bank Date","Bank Name","Bank Branch","Ref Type 1","Ref Number 1","Ref Amount 1"'."\n";
							
						$firstLineCSV = '"'.($i + 1).'","Bank Receipt -ICICI -Admn","'.formatdate($invoicedate,'d.m.Y').'","ICICI Bank Ltd. - 000405030150","'.$packagename.'","'.$membername.'","Primary Cost Category","'.$region.'","'.$packagename.'","'.$chequeamount.'","'.$paymentType.'","'.$chequeamount.'","'.$chequeno.'","'.formatdate($chequedate,'d.m.Y').'","","'.$bankname.'","'.$branch.'","Agst Ref","'.$invoiceno.'","'.$InvoiceTotalAmount.'"'."\n";
						
						$membershipSubscriptionLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">'.$packagename.'</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">&nbsp;</td>'."\n".'<td width="9%">'.$packagename.'</td>'."\n".'<td width="5%">'.$package_amount.'</td>'."\n".'<td width="5%">'.$for_manufacturer.'</td>'."\n".'<td width="3%">'.$membername.'</td>'."\n".'<td width="1%">Cr</td>'."\n".'<td width="2%"></td>'."\n".'<td width="2%"></td>'."\n".'<td></td>'."\n".'</tr>';
					}
					$adminCharges = $administration_charges;
					$adminChargesLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">Membership Subscripion</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">&nbsp;</td>'."\n".'<td width="9%">Administrative Charges - Membership</td>'."\n".'<td width="5%">[adminCharges]</td>'."\n".'<td width="5%">'.$for_manufacturer.'</td>'."\n".'<td width="3%">'.$membername.'</td>'."\n".'<td width="1%">Cr</td>'."\n".'<td width="2%"></td>'."\n".'<td width="2%"></td>'."\n".'<td></td>'."\n".'</tr>';
					//$ServiceTaxLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">Membership Subscripion</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">&nbsp;</td>'."\n".'<td width="9%">Output Service Tax on Membership</td>'."\n".'<td width="5%">'.$TotalTaxAmount.'</td>'."\n".'<td width="5%">'.$for_manufacturer.'</td>'."\n".'<td width="3%">'.$membername.'</td>'."\n".'<td width="1%">Cr</td>'."\n".'<td width="2%"></td>'."\n".'<td width="2%"></td>'."\n".'<td></td>'."\n".'</tr>';
					$igstLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">Membership Subscripion</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">&nbsp;</td>'."\n".'<td width="9%">IGST on Membership</td>'."\n".'<td width="5%">'.$igst.'</td>'."\n".'<td width="5%">'.$for_manufacturer.'</td>'."\n".'<td width="3%">'.$membername.'</td>'."\n".'<td width="1%">Cr</td>'."\n".'<td width="2%"></td>'."\n".'<td width="2%"></td>'."\n".'<td></td>'."\n".'</tr>';
					$sgstLine = '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">Membership Subscripion</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">&nbsp;</td>'."\n".'<td width="9%">SGST on Membership</td>'."\n".'<td width="5%">'.$sgst.'</td>'."\n".'<td width="5%">'.$for_manufacturer.'</td>'."\n".'<td width="3%">'.$membername.'</td>'."\n".'<td width="1%">Cr</td>'."\n".'<td width="2%"></td>'."\n".'<td width="2%"></td>'."\n".'<td></td>'."\n".'</tr>';

				}
				else
				{
					$paymentType = 'Cheque/DD';

					$invoicesrno = $productlist[$i]['invoicesrno']; 
					$invoicedate = $productlist[$i]['invoicedate']; 
					$invoiceno = $productlist[$i]['invoiceno']; 
					$membername = $productlist[$i]['membername']; 
					//$InvoiceServiceTaxAmount = $productlist[$i]['InvoiceServiceTaxAmount']; 
				//	$InvoiceEducationCessOnServiceTaxAmount = $productlist[$i]['InvoiceEducationCessOnServiceTaxAmount']; 
				//	$InvoiceCessOnServiceTaxAmount = $productlist[$i]['InvoiceCessOnServiceTaxAmount']; 
					//$TotalTaxAmount = $InvoiceServiceTaxAmount + $InvoiceEducationCessOnServiceTaxAmount + $InvoiceCessOnServiceTaxAmount;
				//	$InvoiceBaseAmount = $productlist[$i]['InvoiceBaseAmount']; 
					$InvoiceTotalAmount = $productlist[$i]['InvoiceTotalAmount'];
					$chequeno			= $productlist[$i]['chequeno'];
					$chequedate			= $productlist[$i]['chequedate'];
					$chequeamount		= $productlist[$i]['chequeamount'];
					$bankname			= ucwords(strtolower($productlist[$i]['bankname']));
					$branch				= ucwords(strtolower($productlist[$i]['branch']));
					
					$companytype = $productlist[$i]['companytype']; 
					/*if($productlist[$i]['region'] == '') 
					{						
						$region = ''; 
					}
					else 
					{
						$region = $productlist[$i]['region'].'ern Region';
					} */
					$package_entryfee = $productlist[$i]['package_entryfee']; 
					$package_amount = $productlist[$i]['package_amount'];
					$administration_charges = $productlist[$i]['administration_charges'];
					$editing_charges = $productlist[$i]['editing_charges']; 
					$membershipforyear = $productlist[$i]['membershipforyear'];
					$packagename 		= $productlist[$i]['packagename'];
					
					if ($productlist[$i]['for_manufacturer']=='1'){
						$for_manufacturer =  strtoupper('Manufacturer Exporter');

					}	
					else if ($productlist[$i]['for_manufacturer']=='0')
					{	$for_manufacturer =  strtoupper('Merchant Exporter'); }
					else
					{	$for_manufacturer =  strtoupper('Both'); }
					
					if ($package_amount > 1000)
					{
						$membershipSubscriptionLine .= '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">Membership Subscripion</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">&nbsp;</td>'."\n".'<td width="9%">Membership Subscription '.$membershipforyear.'</td>'."\n".'<td width="5%">'.$package_amount.'</td>'."\n".'<td width="5%">'.$for_manufacturer.'</td>'."\n".'<td width="3%">'.$membername.'</td>'."\n".'<td width="1%">Cr</td>'."\n".'<td width="2%"></td>'."\n".'<td width="2%"></td>'."\n".'<td></td>'."\n".'</tr>';
					
						$membershipSubscriptionLineCSV .= '"'.($i + 1).'"'.($i + 1).'","Bank Receipt -ICICI -Admn","'.formatdate($invoicedate,'d.m.Y').'","ICICI Bank Ltd. - 000405030150","Membership for the Year '.$membershipforyear.'","'.$membername.'","Primary Cost Category","'.$region.'","Membership for the Year '.$membershipforyear.'","'.$chequeamount.'","'.$paymentType.'","'.$chequeamount.'","'.$chequeno.'","'.formatdate($chequedate,'d.m.Y').'","","'.$bankname.'","'.$branch.'","Agst Ref","'.$invoiceno.'","'.$InvoiceTotalAmount.'"'."\n";
					}
					else if (($package_amount > 0)&& ($package_amount < 1000))
					{
						$membershipSubscriptionLine .= '<tr>'."\n".'<td width="2%">'.$invoicesrno.'</td>'."\n".'<td width="3%">'.$packagename.'</td>'."\n".'<td width="3%">'.$invoicedate.'</td>'."\n".'<td width="3%">&nbsp;</td>'."\n".'<td width="9%">'.$packagename.'</td>'."\n".'<td width="5%">'.$package_amount.'</td>'."\n".'<td width="5%">'.$for_manufacturer.'</td>'."\n".'<td width="3%">'.$membername.'</td>'."\n".'<td width="1%">Cr</td>'."\n".'<td width="2%"></td>'."\n".'<td width="2%"></td>'."\n".'<td></td>'."\n".'</tr>';
					
						$membershipSubscriptionLineCSV .= '"'.($i + 1).'"'.($i + 1).'","Bank Receipt -ICICI -Admn","'.formatdate($invoicedate,'d.m.Y').'","ICICI Bank Ltd. - 000405030150","'.$packagename.'","'.$membername.'","Primary Cost Category","'.$region.'","'.$packagename.'","'.$chequeamount.'","'.$paymentType.'","'.$chequeamount.'","'.$chequeno.'","'.formatdate($chequedate,'d.m.Y').'","","'.$bankname.'","'.$branch.'","Agst Ref","'.$invoiceno.'","'.$InvoiceTotalAmount.'"'."\n";
					}
				}
				
			}
			//viewpayments.php?csv=1&from=2012-07-30&to=2012-08-07&chequedepositeddate=1
			if ($adminChargesLine !='')
					{
						$adminChargesLine = str_replace("[adminCharges]",$adminCharges,$adminChargesLine);
					
					}
					if ($adminChargesLineCSV!='')
					{
						$adminChargesLineCSV = str_replace("[adminCharges]",$adminCharges,$adminChargesLineCSV);
					}
			//$searchresult1 .= $firstLine.$membershipSubscriptionLine.$adminChargesLine.$ServiceTaxLine;
			//$searchresultCSV .= $firstLineCSV.$membershipSubscriptionLineCSV.$adminChargesLineCSV.$ServiceTaxLineCSV;
			$searchresult1 .= $firstLine.$membershipSubscriptionLine.$adminChargesLine.$igstLine.$sgstLine;
			$searchresultCSV .= $firstLineCSV.$membershipSubscriptionLineCSV.$adminChargesLineCSV.$ServiceTaxLineCSV;
			$searchresult1 .= '</tbody></table>';
		
		if (isset($_GET['csv']))
		{
			header("Content-type: application/octet-stream");
			header("Content-Disposition: attachment; filename=\"receipt_export_to_tally.csv\"");		
			echo trim($searchresultCSV);
			exit();
		}
			else
		{
		require_once("receipt_export_to_Tally1.html");
		require_once("footer1.html");
		}	


	
?>