<?php
include_once "invoice_includes.php";

if(!empty($_REQUEST['id'])){
$id=$_REQUEST['id'];
}

//$due1=date("l F j, Y",strtotime($due));
//$dated1=date("l F j, Y",strtotime($dated));

$case="1";

$client_id=strtoupper(db_ref(table,id_col,$id,lead_ref));

$dated1=db_ref(table,id_col,$id,dated1);
$dated2=db_ref(table,id_col,$id,dated2);
$charges=db_ref(table,id_col,$id,charges);
$charges=number_format($charges);
$charges="PKR ".$charges;
$discount=db_ref(table,id_col,$id,discount);
$tracking_ref=strtoupper(db_ref(table,id_col,$id,tracking_ref));
$invoice_title=strtoupper(db_ref(table,id_col,$id,invoice_title));


$person_name=strtoupper(db_ref(table,id_col,$client_id,owner_name));
$company_name=strtoupper(db_ref(table,id_col,$client_id,company_name));
$add1=strtoupper(db_ref(table,id_col,$client_id,address));
$city_id=strtoupper(db_ref(table,id_col,$client_id,city_type));
$city_name=strtoupper(db_ref(sub_table2,id_col,$city_id,sub_table_title));


$domain1=db_ref(table,id_col,$id,dot_com);

$package_id=strtoupper(db_ref(table,id_col,$id,package_ref));

$package_name=strtoupper(db_ref(table,id_col,$package_id,package_name));
$package_details=db_ref(table,id_col,$package_id,package_details);




//$package="Social Starter Plan";
//$dated1=date("l F j, Y");
//$refno="5D-PK-100-".$id;
//$domain_package="Social Media Content Design / Animation";
//$amount="12,000";

require_once('tcpdf_include.php');


// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

	//Page header
	public function Header() {
		// Logo
		if (count($this->pages) === 1) {
		$image_file = K_PATH_IMAGES.'2014.jpg';
		$this->Image($image_file, 10, 10, 190, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
		// Set font
		$this->SetFont('helvetica', 'B', 20);
		// Title
		}
		if (count($this->pages) === 2) {
		$img_file = K_PATH_IMAGES.'cheque2018.jpg';
        $this->Image($img_file, 0, 25, 210, 0, 'JPG', '', 'T', false, 300, 'C', false, false, 0);
		}
	
	}

	// Page footer
	public function Footer() {
if (count($this->pages) === 1) {
	// Position at 15 mm from bottom
		$this->SetY(-15);
		
		// Set font
		$this->SetFont('helvetica', 'I', 8);
		// Page number
		$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
		$image_file = K_PATH_IMAGES.'2015.jpg';
		$this->Image($image_file, 10, 250, 190, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
		
	}}
	
	
}

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

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('i2d Technologies');
$pdf->SetTitle('Service Invoice');
$pdf->SetSubject('Invoice');
$pdf->SetKeywords('i2d,i2d Technologies');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// 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', '', 9);

// add a page

$pdf->AddPage();


// create some HTML content



//////////////////////////////
//////////////////////////////
//////////////////////////////




$html = '<p>&nbsp;</p><p>&nbsp;</p>

<table width="660" border="0" align="center" cellpadding="2" cellspacing="2">
  <tr>
    <td colspan="2" align="right"></td>
  </tr>
  <tr>
    <td width="412" rowspan="3"><p align="left"><br /><br /><br />ATTN : <br />
      '. $person_name .'<br />
      '. $company_name .'<br />
      '. $add1 .',<br />
      '. $city_name .',<br />	  
	  </p></td>
    <td width="252" align="right">
	<h1>'. $invoice_title .'</h1>
	<br />
	<h4>Tracking / Ref: '. $tracking_ref .'</h4></td>
  </tr>
  <tr>
    <td align="right">Invoice Dated :  '. $dated1 .'<br /><span style="color:red;">
	Due Date :  '. $dated2 .'</span>
	</td>
  </tr>
</table>


<table width="660" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" color="#111111">
  <tr>
  

    <td align="center"><br /><br /><br />
    <h2>'. $domain1 .'</h2><b>(*available for purchase on '. $dated1 .')</b></td>
  </tr>
	 <tr>
     <td align="left">&nbsp;</td>
    </tr>
</table>


<table width="660" border="0" align="center" cellpadding="5" cellspacing="0">
  <tr>
  <td colspan="2" align="center"></td>
  </tr>
  <tr>
    <td align="left" bgcolor="#000000"><p style="color:white;"><strong>Package Details</strong></p></td>
    <td align="center" bgcolor="#000000"><p style="color:white;"><strong>Price</strong></p></td>
  </tr>
  <tr>
    <td align="left"><br />
	
	'. $package_details .'
	
    <p></p></td>
    <td align="center" style="border-top: 1px solid black; border-left: 1px solid black;">
	<p>&nbsp;</p>
	<p>&nbsp;</p>
	<p>&nbsp;</p>
	
	'. $charges .'</td>
  </tr>
  
    <tr>
    <td align="center" style="border-top: 1px solid black; border-bottom: 1px solid black;"><h4>&nbsp;&nbsp;&nbsp;Total Charges :</h4></td>
    <td align="center" style="border-top: 1px solid black; border-bottom: 1px solid black;"><h4>PKR : 9,500  + 5 % GST</h4></td>
  </tr>
  <tr>
      <td align="left"><b>*IMPORTANT NOTE : Domain Availability is subject to International Market Purchases & Global Company Name Competition</b></td>
      <td align="left"></td>
  </tr>
  <tr>
    <td align="left"><img src="images/i2dbar.png"></td>
    <td align="right"><h4><i>Prepared By :</i><br/>
      i2d Billing & Accounts<br />
      billing@i2dtechnologies.com</h4></td>
  </tr>
</table>

<!--HEY-->
';


//$pdf->Image('images/2gb.jpg', 15, 140, 75, 113, 'JPG', '', '', true, 150, '', false, false, false, false, false);



// output the HTML content
$pdf->writeHTML($html, true, 0, true, 0);

$pdf->AddPage();
   

// reset pointer to the last page
$pdf->lastPage();

$file="i2d_invoice"."-".$tracking_ref.".pdf";

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

if($case=="1"){//Close and output PDF document
$pdf->Output($file , 'I');}

if($case=="2"){
	// force print dialog
$js = 'print(true);';

// set javascript
$pdf->IncludeJS($js);

//Close and output PDF document
$pdf->Output($file , 'I');
	
}



//============================================================+
// END OF FILE
//============================================================+

