<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
	print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
	return;
}
	include("../opendb1.php");
	include('mysqli_table.php');
	$brqry="select brname from branch where brcode='$brcode'";
	$brrs=mysqli_query($db,$brqry);
	$brrw=mysqli_fetch_array($brrs);
	$brnchnm=$brrw[0];
	$fromdt=$_REQUEST['dfrom'];
	$fromdt=implode("-",array_reverse(explode("-",$fromdt)));
	$todt=$_REQUEST['dto'];
	$todt=implode("-",array_reverse(explode("-",$todt)));
	$type=$_REQUEST['type'];
	$redtype=$_REQUEST['redtype'];
	$qry=mysqli_query($db,"select gname,invdate,sum(total),sum(mba),sum(strbtnml),sum(strbtspl),sum(redct),sum(befrtx),sum(taxamt),sum(nettot),min(invno),max(invno) from prod_invoice where invdate between '$fromdt' and '$todt' and brcode='$brcode' and gname='$type' group by gname");
	$row=mysqli_fetch_row($qry);
	$qry1=mysqli_query($db,"select brname from branch where brcode = '$brcode'");
	$row1=mysqli_fetch_row($qry1);
	$qry3=mysqli_query($db,"select gname,invdate,sum(total),sum(mba),sum(strbtnml),sum(strbtspl),sum(redct),sum(befrtx),sum(taxamt),sum(nettot),min(invno),max(invno) from salesretn where invdate between '$fromdt' and '$todt' and brcode='$brcode' and gname='$type' group by gname");
	$row3=mysqli_fetch_row($qry3);
	$mtot_total3 = $row3[2];
	if(($redtype=='mda')or ($redtype=='MDA'))
	{
		$mtot_rebt3 = $row3[3];
	}
	if(($redtype=='strbtnml')or ($redtype=='State Rebate Normal'))
	{
		$mtot_rebt3 = $row3[4];
	}
	if(($redtype=='strbtspl')or ($redtype=='State Rebate Special'))
	{
		$mtot_rebt3 = $row3[5];
	}
	$brname = $row1[0];
	$mtot_total = $row[2];
	if(($redtype=='mda')or ($redtype=='MDA'))
	{
		$mtot_rebt = $row[3];
	}
	if(($redtype=='strbtnml')or ($redtype=='State Rebate Normal'))
	{
		$mtot_rebt = $row[4];
	}
	if(($redtype=='strbtspl')or ($redtype=='State Rebate Special'))
	{
		$mtot_rebt = $row[5];
	}


	
	$pdf = new FPDF('P','mm','A4');
	$pdf->AddPage();
	$pdf->SetFont('Arial','B',10);
	$pdf->SetFont('','B');
	$dedres1=mysqli_query($db,"select brname from branch where brcode='$brcode'") or die("er5:".mysqli_error($db));
	$br_1=mysqli_fetch_array($dedres1);
	$pdf->SetFont('','BU');	
	$pdf->SetFont('Arial','',9);
	$brnchnm=strtoupper($brnchnm);			
        $pdf->SetFont('Arial','',9);     
	$pdf->Cell(35,10,'Total Sales :','');$pdf->Cell(20,10,$mtot_total,'');$pdf->Cell(80,10,'','');
	$pdf->Cell(30,10,'Rebate :','');$pdf->Cell(20,10,$mtot_rebt,'');
	$pdf->Ln(5);
 	$pdf->Cell(35,10,'Sales Returned :','');$pdf->Cell(20,10,$mtot_total3,'');$pdf->Cell(80,10,'','');$pdf->Cell(30,10,'Rebates :','');
	$pdf->Cell(20,10,$mtot_rebt3,'');
	$pdf->Ln(5);	
	$netsls=$mtot_total-$mtot_total3;
	$netrebts=$mtot_rebt-$mtot_rebt3;
	$pdf->Cell(35,10,'Net Sales :','');$pdf->Cell(20,10,$netsls,'');$pdf->Cell(80,10,'','');$pdf->Cell(30,10,'Net Rebates :','');
	$pdf->Cell(20,10,$netrebts,'');
	$pdf->Ln(9);
	
	$pdf->SetFont('Arial','',10);
	$pdf->Cell(190,10,'CERTIFICATE',0,1,'C'); 
	$pdf->Ln(5);
	$pdf->SetFont('Arial','',9);   
	$pdf->Cell('',10,'Certified that the duplicate copies of the cash memos mentioned in the centers statements enclosed with the claim are kept in','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'record with use and will be made available to the staff of the commission or the officers of the Goverment audit department for','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'checking whenever demanded.','');
	$pdf->Ln(5);
	$pdf->Ln(4);
	$pdf->Cell('',10,'Certified that the sales for which the rebate has been claimed do not included the wholesales
of sales or goods returned or','');
	$pdf->Ln(5);	
	$pdf->Cell('',10,'sales or goods on which rebate is not admissible or sales of government 
departments.','');
	$pdf->Ln(5);
	$pdf->Ln(4);
	$pdf->Cell('',10,'Certified that all the centres for which claims have been made in this statement are approved 
branches of this institution.','');
	$pdf->Ln(5);
	$pdf->Ln(4);
	$pdf->Cell('',10,'Certified that claims are made strictly according to the books of account of this institution 
and that the amount of the claim has','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'not been claimed and received previously and that in the event 
of any discrepency found during inspection or audit, this','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'institution will be liable to repay such amount to the commission promptly and rebates subsidy claimed above have been','');	
	$pdf->Ln(5);
	$pdf->Cell('',10,'paid at the rates and 
according to the scales and conditions prescribed in the sanctions of the each scheme.','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'','');
	$pdf->Ln(5);					
	$pdf->Cell(15,10,'Place :','');$pdf->Cell(35,10,$brname,'');
	$pdf->Ln(5);
	$pdf->Cell(15,10,'Date :','');$pdf->Cell(35,10,date('d-m-Y'),'');
	$pdf->Ln(5);
	$pdf->Ln(4);	     
	$pdf->Cell(60,10,'','');$pdf->Cell(35,10,'(Rubber stamp of the institution)','');
	$pdf->Ln(5);
	$pdf->Cell(130,10,'','');$pdf->Cell(35,10,'Signature of Manager','');
	$pdf->Ln(5);
	$pdf->Ln(4);		
	$pdf->Cell(35,10,'*(Strike which is not applicable)','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'Net Rebate amount for payment Rs. .................................. Entered in the Ledger Folio No.','');
	$pdf->Ln(5);
	$pdf->Ln(4);
	$pdf->Cell('',10,'                     CHECKING CLERK','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'Superintendent','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'Khadi & VI Commission','');
	$pdf->Ln(5);
	$pdf->Cell('',10,'Trivandum','');
	$pdf->Ln(9);
	
	







		$pdf->Output();	
?>
