<?php 
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
$svgImg = $_GET['img'];
$blender = $_GET["blender"];
$intsaved = $_GET["intsaved"];
$client   = $_GET["client"];
$date = $_GET["date"];
// standard loan 
$la = $_GET["la"]; //loan amount
$lt = $_GET["lt"]; //loan term
$lir = $_GET["lir"]; // loan interest rate
$repayment = $_GET["repayment"]; // loan repayment
$oip  = $_GET["oip"]; //Orignal interest paid
$otlr = $_GET["otlr"]; // orignal total loan repayment 
// Lender 1
$l1n = $_GET["l1n"]; // lender 1 name
$l1ir = $_GET["l1ir"]; // lender 1 interest rate
$l1repay = $_GET["l1repay"]; //lender 1 repayment
$l1totalpi = $_GET["l1totalpi"];// lender 1 total P & I
$l1totali  = $_GET["l1totali"]; // lender 1 toal Interest
$l1cup = $_GET["l1cup"];//lender 1 commission up front
$l1ct  = $_GET["l1ct"];//lender 1 commission trail 
$l1totcom = $_GET["l1totcom"]; // lender 1 total commission
// Lender 2
$l2n = $_GET["l2n"]; // lender 2 name
$l2ir = $_GET["l2ir"]; // lender 2 interest rate
$l2repay = $_GET["l2repay"]; //lender 2 repayment
$l2totalpi = $_GET["l2totalpi"];// lender 2 total P & I
$l2totali  = $_GET["l2totali"]; // lender 2 toal Interest
$l2cup = $_GET["l2cup"];//lender 2 commission up front
$l2ct  = $_GET["l2ct"];//lender 2 commission trail
$l2totcom = $_GET["l2totcom"]; // lender 2 total commission
// Lender 3
$l3n = $_GET["l3n"]; // lender 3 name
$l3ir = $_GET["l3ir"]; // lender 3 interest rate
$l3repay = $_GET["l3repay"]; //lender 3 repayment
$l3totalpi = $_GET["l3totalpi"];// lender 3 total P & I
$l3totali  = $_GET["l3totali"]; // lender 3 toal Interest
$l3cup = $_GET["l3cup"];//lender 3 commission up front
$l3ct  = $_GET["l3ct"];//lender 3 commission trail
$l3totcom = $_GET["l3totcom"]; // lender 3 total commission


// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Fintrack Pty Ltd');
$pdf->SetTitle('LOAN ASSESSMENT WITH CASH BACK');
$pdf->SetSubject('Fintrack Pty Ltd - LOAN ASSESSMENT WITH CASH BACK');
$pdf->SetKeywords('LOAN ASSESSMENT WITH CASH BACK');

// set default header data
$pdf->SetHeaderData("fint-logo.jpg", PDF_HEADER_LOGO_WIDTH, 'LOAN ASSESSMENT WITH CASH BACK', '');

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 10);

// add a page
$pdf->AddPage();

$AfterImage='<table width="100%" border="0">
		<tr><td>
		 &nbsp;&nbsp;'.$client.' ('.$date.')
		</td></tr>
		<tr><td height="20">
		</td></tr>		
		<tr><td>
		<table width="98%" border="0" height="20" align="center" bordercolor="#999999;">
		<tr><td width="1%"></td><td width="55%">
		<table width="100%" border="1" align="center" bordercolor="#999999;">
		<tr><td colspan="2" align="left">
		&nbsp;Best Loan Scenario
		</td>
		</tr>
		<tr>
		<td align="left" width="30%">&nbsp;Lender Name</td>
		<td align="left" width="70%">&nbsp;'.$blender.'</td>
		</tr>
		<tr>
		<td align="left">&nbsp;Interest Saved</td>
		<td align="left">&nbsp;'.$intsaved.'</td>
		</tr>
		</table>
		</td>
		<td>&nbsp;</td>
		</tr>
		</table>
		</td></tr>
		<tr><td height="20">
		</td></tr>
		<tr><td align="left">
        <table width="98%" border="1"  align="left" bordercolor="#999999;" >
       <tr>
		    <td width="20%"  align="left" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;LOAN DETAILS</td>
			<td width="20%" align="left" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Standard Loan</td>	
		    <td width="20%" align="left" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Lender 1</td>
		    <td width="20%" align="left" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Lender 2</td>
			<td width="20%" align="left" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Lender 3</td>	
       </tr>
       <tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Lender Name</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;</td>	
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l1n.'</td>
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l2n.'</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l3n.'</td>	
       </tr>
		<tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Loan Amount</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;$'.$la .'</td>		
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;$'.$la .'</td>
		    <td align="left" style="font-size:10px;font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;$'.$la .'</td>
			<td align="left" style="font-size:10px;font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;$'.$la .'</td>	
       </tr>
		<tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Loan Term</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$lt.' Years</td>		
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$lt.' Years</td>
		    <td align="left" style="font-size:10px;font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$lt.' Years</td>
			<td align="left" style="font-size:10px;font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$lt.' Years</td>	
       </tr>						
	   <tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Interest Rate</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'. $lir .'%</td>		
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l1ir.'%</td>
		    <td align="left" style="font-size:10px;font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l2ir.'%</td>
			<td align="left" style="font-size:10px;font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l3ir.'%</td>	
       </tr>	
		 <tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Repayment</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;$'. $repayment.'</td>		
		    <td align="left" style=" font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l1repay.'</td>
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l2repay.'</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l3repay.'</td>	
       </tr>
		 <tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Total P&I</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$otlr.'</td>		
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l1totalpi.'</td>
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l2totalpi.'</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l3totalpi.'</td>	
       </tr>					
		 <tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Total Interest</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$oip.'</td>		
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l1totali.'</td>
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l2totali.'</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l3totali.'</td>	
       </tr>		
		</table>		
		</td></tr>
		<tr><td height="20px">
		&nbsp;
        </td>
        </tr>
		<tr><td align="center">&nbsp;
		 <table width="98%" border="1"  align="left" bordercolor="#999999;">
         <tr>
		    <td width="20%"  align="left" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;COMMISSION<br> CASHBACK</td>
			<td width="20%" align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;</td>		
		    <td width="20%" align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;</td>
		    <td width="20%" align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;</td>
			<td width="20%" align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;</td>	
         </tr>
		 <tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Commission Upfront</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;$0</td>		
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l1cup.'</td>
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l2cup.'</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l3cup.'</td>	
         </tr>	
		   <tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Commission Trail</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;$0</td>		
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l1ct.'</td>
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l2ct.'</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l3ct.'</td>	
         </tr>	
		  <tr>
		    <td align="left" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;Estimated Commission</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;$0</td>		
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l1totcom.'</td>
		    <td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l2totcom.'</td>
			<td align="left" style="font-size:10px; font-family:Arial, Helvetica, sans-serif; font-weight:600">&nbsp;'.$l3totcom.'</td>	
         </tr>	
		</table>		
        </td>
        </tr>
		<tr><td height="20px">
		&nbsp;
        </td>
        </tr>
		<tr><td>
		   <span style="margin-left:6px; padding:0px; font-family:Arial, Helvetica, sans-serif; color:#000000; font-size:14px; text-align:left; font-weight:600">Disclaimer:-</span>			
	       <p style="text-align:justify; font-family:Arial, Helvetica, sans-serif; font-size:8px;">
				This is an illustration of potential interest savings only and assumes average levels of commission payments available from our Lenders as they advise from time to time. Interest costs have been rounded to the nearest whole dollar. Your individual interest savings may be more or less than the results shown here. The modeled outcomes are valid only for the inputs shown and assume interest rates remain constant and that you maintain your loan in good standing and pay minimum scheduled payments. No attempt has been made to analyse costs associated with switching Lenders including discharge fees, applications fees, or Lender&#39;s Mortgage Insurance. This is not a recommendation or offer of finance. You should not make a decision to refinance any loan or to engage our services based purely on this illustrated calculation. Should detail of your particular situation be wrong or have changed please contact us so that we may reassess and provide a more accurate illustration.
		   </p>
		  <p>Fintrack Pty Ltd Australian Credit Licence XXXXXX</p>
     </td></tr>									
		</table>			
		';
//die($AfterImage);
$file='../../export/' .$svgImg;

$pdf->ImageSVG($file, $x=15, $y=25, $w='170', $h='80', $link='http://www.fintrack.com.au', $align='', $palign='', $border=1, $fitonpage=false);

$pdf->setY(110);
$pdf->setX(15);
//$pdf->ImageSVG($file='images/tux.svg', $x=30, $y=100, $w='', $h=100, $link='', $align='', $palign='', $border=0, $fitonpage=false);
$pdf->writeHTML($AfterImage, true, false, true, false, '');
// ---------------------------------------------------------
//Close and output PDF document

$to = "hemant@antheminfotech.com";
//$to = "richard@fintrack.com.au";
$from = "info@fintrack.com.au";
$subject = "Loan Enquiry Calculation Cashback - " . $client;
$message = "Please find attached Loan Enquiry Calculation Cashback statement for ".$client."."  ;


// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// $eol = "\r\n";
// attachment name
$filename = $subject.".pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output('LECC'.$separator.'.pdf', 'S');
$attachment = chunk_split(base64_encode($pdfdoc));

// encode data (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Enconding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;

// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charsrt=\"iso-8859-1\"".$eol;
$headers .= $message.$eol.$eol;

// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
//$headers .= "Content-Type: application/zip; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";

// send message
if(@mail($to, $subject, $message, $headers))
{

	echo "<script type='text/javascript'> alert('mail sent');window.close();</script>";
	
}

else{
	echo "<script type='text/javascript'>alert('mail not sent');window.close();</script>";
}
?>

<script type="text/javascript">

</script>