<?php session_start();
ob_start();
error_reporting(E_ERROR | E_PARSE);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

?>

<?php

	if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  
  	include("configi.php");


  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($conn, $theValue) : mysqli_escape_string($conn, $theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

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


	include("configi.php");


//echo "Search option is " . $search_option;


//echo $_GET['suppid'];
$suppid =  2;

//695

$ac = 0;

$job_compid = 1;
$reportcompname = "hello";

$msg = "";


$sales_id =  $_GET['sales_id'];

$ac = 0;



	include("configi.php");


		$query_pag_data = "select * from " . $_COOKIE["phxcrmclient_id"] . "_st where st_id = " . $sales_id;

//	echo $query_pag_data;

$result_pag_data = mysqli_query($conn, $query_pag_data);
while ($row = mysqli_fetch_array($result_pag_data)) {
$sales_id 			= $row["st_id"];
$client_id 			= $row["uid_client"];
//echo "client id is " . $client_id;

$booking_status 	= $row["status"];
$comments 			= $row["comments"];
$total_tax 			= $row["total_tax"];
$total_sale 		= $row["total_sale"];
$total_paid 		= $row["total_paid"];
$sales_date 		= $row["sales_date"];	
$sales_staff 		= $row["sales_staff"];
$sales_comments 	= $row["sales_comments"];
$sales_status 		= $row["status"];

$job_uid_contact 	= $row["job_uid_contact"];

$event_name 		= $row["event_name"];
$event_venue 		= $row["event_venue"];

$s_credterms 		= $row["s_credterms"];

if ($event_venue == "novalue"){
	$event_venue = "";
}

$p_sales_status_date		= $row["p_status_date"];

$job_sales_person_name		= $row["job_sales_person_name"];

$job_sales_manager_name		= $row["job_sales_manager_name"];
$job_rep_person_name		= $row["job_rep_person_name"];
$job_tech1_person_name		= $row["job_tech1_person_name"];

$a_postline1	 		= $row["a_postline1"];
$a_postline2	 		= $row["a_postline2"];
$a_postline3	 		= $row["a_postline3"];
$a_postline4	 		= $row["a_postline4"];
$a_postline5	 		= $row["a_postline5"];

$s_postline1	 		= $row["s_postline1"];
$s_postline2	 		= $row["s_postline2"];
$s_postline3	 		= $row["s_postline3"];
$s_postline4	 		= $row["s_postline4"];
$s_postline5	 		= $row["s_postline5"];

$job_descr				= GetSQLValueString($row["job_descr"], "text2");
$jobsheet_comments		= GetSQLValueString($row["jobsheet_comments"], "text2");
$client_order_no		= $row["client_order_no"];

$job_compid      		= $row["job_compid"];

$reference_no      		= $row["reference_no"];

$job_date_start    		= $row["job_date_start"];

$job_time_start    		= $row["job_time_start"];

$job_date_end    		= $row["job_date_end"];

$job_time_end    		= $row["job_time_end"];

//$ttl_quote 				= $rowt["ttl_quote"];
//$ttl_quote_xgst 			= $rowt["ttl_quote_xgst"];
//$ttl_quote_gst 				= $rowt["ttl_quote_gst"];
$ttl_cost 				= $row["ttl_quote_cost"];

$job_ttl_quote_xgst			= $row["job_ttl_quote_xgst"];
$job_ttl_quote_gst			= $row["job_ttl_quote_gst"];
$job_ttl_quote				= $row["job_ttl_quote"];

$job_ttl_quote_cost_xgst	= $row["job_ttl_quote_cost_xgst"];
$job_ttl_quote_cost_gst		= $row["job_ttl_quote_cost_gst"];
$job_ttl_quote_cost			= $row["job_ttl_quote_cost"];


}


	include("configi.php");
  
$query="select * from phx_userid_outlet where client_id =  " . $_COOKIE['phxcrmclient_id'] . " and outlet_id = " . $job_compid;

$result_pag_data2 = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($result_pag_data2)) {
$outlet_name 			= $row["outlet_name"];
$address1 				= $row["address1"];
$address2 				= $row["address2"];
$address3 				= $row["address3"];
$address4 				= $row["address4"];
$address5 				= $row["address5"];

$phys_address1 			= $row["phys_address1"];
$phys_address2 			= $row["phys_address2"];
$phys_address3 			= $row["phys_address3"];
$phys_address4 			= $row["phys_address4"];
$phys_address5 			= $row["phys_address5"];

$quote_text1 			= $row["quote_text1"];
$quote_text2 			= $row["quote_text2"];
$quote_text3 			= $row["quote_text3"];
$quote_text4 			= $row["quote_text4"];
$quote_text5 			= $row["quote_text5"];

$office_phone 			= $row["office_phone"];
$office_fax 			= $row["office_fax"];
$office_mobile 			= $row["office_mobile"];
$gst_number 			= $row["gst_number"];
$website 				= $row["website"];
$outlet_email			= $row["outlet_email"];

}


	
	include("configi.php");

$sql="SELECT " . $_COOKIE["phxcrmclient_id"] . "_client.* FROM " . $_COOKIE["phxcrmclient_id"] . "_client where " . $_COOKIE["phxcrmclient_id"] . "_client.uid_client = " . $client_id;

//echo $sql;

$result = mysqli_query($conn, $sql);

$intcounter = 0;

while ($row = mysqli_fetch_array($result)) {


$ccomp_name				= $row["comp_name"];
$ccont_name 			= $row["cont_name"];
$ccell_phone 			= $row["cell_phone"];
$cwork_phone 			= $row["work_phone"];
$chome_phone 			= $row["home_phone"];
$cemail		 			= $row["email"];
$cwebsite		 		= $row["website"];



	$intcounter = $intcounter + 1;
	
	}
	
	
	
	//check multi contacts
	
	
	

if ($job_uid_contact == 0){
}else{
						
					$sqlcontact = "SELECT * FROM ". $_COOKIE["phxcrmclient_id"]."_client_contacts where uid_client = ".$client_id ." and con_uid = ". $job_uid_contact;
		//	echo $sqlcontact;

					$resultcontact = $conn->query($sqlcontact);


					// output data of each row
					while($rowcontact = $resultcontact->fetch_assoc()) {

						$ccont_name 		= $rowcontact["contact_name"];
						$cwork_phone 		= $rowcontact["contact_work_phone"];					
						$ccell_phone 		= $rowcontact["contact_mobile"];	
						$a_postline5 		= $rowcontact["contact_name"];	

					}

}
	
	
	

	$address1_len = strlen($a_postline1);
	$address2_len = strlen($a_postline2);
	$address3_len = strlen($a_postline3);
	$address4_len = strlen($a_postline4);
	$address5_len = strlen($a_postline5);

    $address5p_len = strlen($a_postline5);

	
  if ($address5p_len > 1) {

        $a_postline51dear = "Dear " . $a_postline5 . ",<br>";
        $a_postline5 = " Attn: " . $a_postline5;


    }else{
	        $a_postline51dear = "";
	}
	

$sql="SELECT sum(qtl_incl_price) as suminclprice from " . $_COOKIE["phxcrmclient_id"] . "_qtl where st_id = " . $sales_id;
$countqtlinclprice = 0;
$result_pag_data = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result_pag_data)) {
$countqtlinclprice			= $row["suminclprice"];
}
if ($countqtlinclprice == 0){
	$showprice = "No";
}else{
	$showprice = "Yes";
}

//echo "showprice" . $countqtlinclprice;


$report2='<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            height: 23px;
            text-align: left;
        }
                .auto-style22 {
            height: 23px;
            text-align: right;
        }
        .auto-style3 {
            width: 33%;
            height: 23px;
        }

        .auto-style24 {
            width: 149px;
            height: 90px;
        }
        .auto-style25 {
            width: 199px;
        }
        .auto-style26 {
            width: 60px;
        }
        .auto-style27 {
            width: 33%;
            height: 23px;
            text-align: left;
            font-size: large;
        }
		p {
    margin-top: 0px;
}
        .auto-style28 {
            height: 23px;
            text-align: left;
            font-size: large;
        }
        .auto-style29 {
            width: 57px;
        }
        .auto-style30 {
            width: 126px;
        }
        .auto-style31 {
            width: 386px;
        }
        .auto-style32 {
            width: 386px;
            font-weight: bold;
        }
        .auto-style33 {
            width: 126px;
            font-weight: bold;
        }
        .auto-style34 {
            width: 57px;
            font-weight: bold;
        }
    </style>
</head>
<body>

    <table class="auto-style1">
        <tr>
            <td style="width: 280px;  vertical-align: bottom;">
                <img alt="" style="width: 250px" src="../../images/hotprintsmall.png" />
				</td>
				<td valign="bottom" style="align: left;   vertical-align: bottom;">
				<span style="font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;"><strong>8 Waring Taylor Street | Wellington Central | Aotearoa</strong></span><br>
				<span  style="font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;"><strong>Ph: 04 499 6588 | E: info@hotprint.nz</strong></span>
				</td>
				
        </tr>
		
	</table>
	<br>
		  <table class="auto-style1"   style="font-size: 11px; font-family: \'Helvetica\', \'Arial\', sans-serif;">

        <tr>
            <td style="width: 33%" class="auto-style23"><strong><span style="font-size: 18px; font-family: \'Helvetica\', \'Arial\', sans-serif;">#*job_date*#</span></strong></td>
            <td style="width: 33%; text-align: center;" class="auto-style23"></td>
            <td style="width: 33%; text-align: right;"><strong><span  style="font-size: 18px; text-align: right font-family: \'Helvetica\', \'Arial\', sans-serif;"><strong><span style="font-size: 18px; font-family: \'Helvetica\', \'Arial\', sans-serif;">QUOTE</span></strong> ID: #*ff1_st_id*#</span></strong></td>
        </tr>
				  </table>
				  <table class="auto-style1"  style="font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;">
        <tr>
            <td class="auto-style3"></td>
            <td colspan="2" class="auto-style3"></td>
            <td class="auto-style3"></td>
        </tr>
        <tr>
            <td class="auto-style2" style="vertical-align: top;">
                <table  class="auto-style1">
                    <tr>
                        <td><strong>#*company_name*#</strong></td>
                    </tr>
                    <tr>
                        <td>#*company_addr1*#</td>
                    </tr>
                    <tr>
                        <td>#*company_addr2*#</td>
                    </tr>
                    <tr>
                        <td>#*company_addr3*#</td>
                    </tr>
                    <tr>
                        <td>#*company_addr4*#</td>
                    </tr>
       <tr>
	   <td>
                #*company_addr5*#</td>
				         </table>
            <td colspan="4" class="auto-style22">
                <table style="font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;" class="auto-style1">
                    <tr>
                        <td style="width: 80px">&nbsp;</td>
                        <td style="width: 100px">&nbsp;</td>

                        <td style="width: 100px"  class="auto-style25">Job Number:</td>
                        <td style="width: 200px">#*ff1_st_id*#</td>
                    </tr>
                    <tr>
   <td style="width:80px">&nbsp;</td>

   <td style="width: 100px">&nbsp;</td>
                     
					 <td style="width: 100px"  class="auto-style25">Customer Ref:</td>
                        <td style="width: 200px">#*cust_ref*#</td>
                    </tr>
                    <tr>
   <td style="width:80px">&nbsp;</td>

   <td style="width: 100px">&nbsp;</td>

                        <td   style="width: 100px" class="auto-style25">Contact Name:</td>
                        <td  style="width: 200px">#*contact_name*#</td>
                    </tr>
                    <tr>
   <td style="width:50px">&nbsp;</td>

   <td style="width: 100px">&nbsp;</td>
                        <td style="width: 100px" class="auto-style25">Work Phone:</td>
                        <td style="width: 200px">#*contact_work_phone*#</td>
                    </tr>
                    <tr>
                 <td style="width:80px">&nbsp;</td>

   <td style="width: 100px">&nbsp;</td>
                        <td  style="width: 100px" class="auto-style25">Cellphone:</td>
                        <td style="width: 200px">#*contact_cell_phone*#</td>
                    </tr>
										                    <tr>
                     <td style="width:80px">&nbsp;</td>

   <td style="width: 100px">&nbsp;</td>
                        <td  style="width: 100px"  class="auto-style25">Quoted by:</td>
                        <td>#*salesmanagername*#</td>
                    </tr>
					                </table>
            </td>
        </tr>
        <tr>
            <td colspan="4" class="auto-style27" style="vertical-align: top;">
             ' . $a_postline51dear . ' </td>
		   </tr>
		   <tr>
		   <td colspan="4" class="auto-style27" style="vertical-align: top;">
		   Thank you for the opportunity to quote for your printing needs, please find details as follows:
		   <hr size=1> 
		   </td>
        </tr>
        <tr>
            <td colspan="4" class="auto-style27" style="vertical-align: top;">
                <strong>Job Description:</strong></td>
        </tr>

        <tr>
            <td class="auto-style2" style="vertical-align: top;" colspan="4">
                <div width="100%" border="0" style="width: 100%; outline: none; overflow: none; border: none; margin-right:50px; background-color: transparent;">#*job_descr*#</div></td>
     		</tr>
        <tr>
            <td class="auto-style27" style="vertical-align: top;">
                <br><strong>Quoted Items:</strong><br></td>
            <td colspan="3" class="auto-style22">
                </td>
        </tr>
        <tr>
            <td class="auto-style2" style="vertical-align: top;" colspan="4">
                #*quote_txn_line*#</td>
        </tr>

        <tr>
            <td class="auto-style2" style="vertical-align: top;" colspan="4">
                &nbsp;</td>
        </tr>

</table>
<table style="width: 100%" style="font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;">



												<tr>
			<td style="width: 5%" valign="top">
			1.
			</td>
			<td style="width: 95%" valign="top">
			Payment Terms: ' . $s_credterms . '
			</td>
			</tr>
			<tr>
			<td style="width: 5%"  valign="top">
			2.
			</td>
			<td style="width: 95%" valign="top">
			The prices in this quotation are valid for 30 days, based on the files being supplied to <b>HOTPRINT</b> specifications.
			</td>
			</tr>
			<tr>
						<td style="width: 5%"  valign="top">
			3.
			</td>
			<td style="width: 95%" valign="top">
						Prices exclude GST.

			</td>
			</tr>
			<tr>
						<td style="width: 5%"  valign="top">
			4.
			</td>
			<td style="width: 95%" valign="top">
			Any author’s corrections will incur a minimum fee of $25.00.
			</td>
			</tr>
			<tr>
						<td style="width: 5%"  valign="top">
			5.
			</td>
			<td style="width: 95%" valign="top">
			Prices do not include freight unless otherwise stated.
			</td>
			</tr>
			</table>
	
	<br>

				Thank you once again for considering our quote. 
</strong>				
			</td>
			<td style="width: 500px;"  valign="top">
			<table valign="top">
				<tr>
						<td>
									</td>
									<td align="right">
<div style="display: inline; width: 150px; border:none; font-size: large; border-style:none; outline:none; border-width:0px; border-color: transparent; text-align: right;"></div>
			</td>
			</tr>
				<tr>
						<td>
						<span style="font-size: large"></span>
			</td>
									<td align="right">
<div style="display: inline; width: 150px; border:none; font-size: large; border-style:none; outline:none; border-width:0px; border-color: transparent; text-align: right; font-size: large"></div>
			</td>
			</tr>
			
			
			</table>
			</td>
			</tr>
			</table>

                &nbsp;</td>
				<table>
				<tr>
				<td>
				If you have any questions regarding this quote, please do not hesitate to call me.
				</td>
				</tr>
				</table>
        </tr>
		</table>
		<table>
				<tr>
						<td width="50%">
						<span style="font-size: 18px;"><strong>
						Yours Sincerely<br>
						<img alt="" width="200px"  src="../../images/91_'.$_COOKIE["phxcrmuserid"].'_signature.jpg" /><br>
						'. $_COOKIE["current_username"] .'<br>
						Director
						</strong></span>
			</td>
									<td align="right" width="700px">
<img alt=""  src="../../images/91signoff.jpg" />
			</td>
			</tr>

        </table>

</body>

</html>';

$qtl = '<table  cellspacing="0" style="border: none;font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;">
                    <tbody>
					<tr bgcolor="lightgrey" border="none">
	                        <td style="width: 500px; text-align: centre;font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;"><strong>Description</strong></td>
                        <td style="width: 100px; text-align: centre;font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;"><strong>Quantity</strong></td>';
						if ($showprice == "Yes"){
						$qtl = $qtl .'
							<td style="width: 120px;  text-align: right;font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;"><strong>Sell Price</strong></td>
						<td style="width: 120px;   text-align: right;"><strong>Total</strong></td>';
                    }
					
					$qtl = $qtl . '</tr>';
                
				
//$sql="SELECT " . $_COOKIE["phxcrmclient_id"] . "_qtl.*, " . $_COOKIE["phxcrmclient_id"] . "_qtl.qtl_catname as prod_catname,"  . $_COOKIE["phxcrmclient_id"] . "_prodserv.prod_catname," . $_COOKIE["phxcrmclient_id"] . "_qtl.qtl_title AS line_desc, " . $_COOKIE["phxcrmclient_id"] . "_cat_sort.level, If(level>=1,level,99) AS sort, concat(If(level>=1,level,99), " . $_COOKIE["phxcrmclient_id"] . "_qtl.qtl_catname) AS sort_cat FROM (" . $_COOKIE["phxcrmclient_id"] . "_qtl LEFT JOIN " . $_COOKIE["phxcrmclient_id"] . "_prodserv ON " . $_COOKIE["phxcrmclient_id"] . "_qtl.prodserv_uid = " . $_COOKIE["phxcrmclient_id"] . "_prodserv.uid) LEFT JOIN " . $_COOKIE["phxcrmclient_id"] . "_cat_sort ON " . $_COOKIE["phxcrmclient_id"] . "_qtl.qtl_catname = " . $_COOKIE["phxcrmclient_id"] . "_cat_sort.category  where st_id = " . $sales_id . " ORDER BY sort_cat, id_stl;";

//$sql="SELECT " . $_COOKIE["phxcrmclient_id"] . "_qtl.*, " . $_COOKIE["phxcrmclient_id"] . "_qtl.qtl_catname as prod_catname,"  . $_COOKIE["phxcrmclient_id"] . "_prodserv.prod_catname," . $_COOKIE["phxcrmclient_id"] . "_qtl.qtl_title AS line_desc, " . $_COOKIE["phxcrmclient_id"] . "_catcode.lu_level, If(lu_level>=1,lu_level,99) AS sort, IFNULL(concat(If(lu_level>=1,lu_level,99), " . $_COOKIE["phxcrmclient_id"] . "_qtl.qtl_catname),999) AS sort_cat FROM (" . $_COOKIE["phxcrmclient_id"] . "_qtl LEFT JOIN " . $_COOKIE["phxcrmclient_id"] . "_prodserv ON " . $_COOKIE["phxcrmclient_id"] . "_qtl.prodserv_uid = " . $_COOKIE["phxcrmclient_id"] . "_prodserv.uid) LEFT JOIN " . $_COOKIE["phxcrmclient_id"] . "_catcode ON " . $_COOKIE["phxcrmclient_id"] . "_qtl.qtl_catname = " . $_COOKIE["phxcrmclient_id"] . "_catcode.lu_code_descr where st_id = " . $sales_id . " ORDER BY sort_cat, id_stl;";

//$sql="SELECT qtl.*, prodserv.prod_catname, qtl.qtl_title AS line_desc, catcode.lu_level, If(lu_level>=1,lu_level,99) AS sort, IFNULL(concat(If(lu_level>=1,lu_level,99), qtl.qtl_catname),999) AS sort_cat FROM (" . $_COOKIE["phxcrmclient_id"] . "_qtl as qtl LEFT JOIN " . $_COOKIE["phxcrmclient_id"] . "_prodserv as prodserv ON qtl.prodserv_uid = prodserv.uid) LEFT JOIN " . $_COOKIE["phxcrmclient_id"] . "_catcode as catcode ON qtl.qtl_catname = catcode.lu_code_descr where st_id = " . $sales_id . " ORDER BY sort_cat, id_stl;";

$sql="SELECT qtl.*, prodserv.prod_catname, qtl.qtl_title AS line_desc, catcode.lu_level, If(lu_level>=1,lu_level,99) AS sort, IFNULL(If(lu_level>=1,lu_level,99),999) AS sort_cat FROM (" . $_COOKIE["phxcrmclient_id"] . "_qtl as qtl LEFT JOIN " . $_COOKIE["phxcrmclient_id"] . "_prodserv as prodserv ON qtl.prodserv_uid = prodserv.uid) LEFT JOIN " . $_COOKIE["phxcrmclient_id"] . "_catcode as catcode ON prodserv.prod_catname = catcode.lu_code_descr where st_id = " . $sales_id . " ORDER BY sort_cat, id_stl;";

//echo $sql;

$qtl = $qtl . '<tr>';
 $ttl_quote_net = 0;
 $currcat = "";
 $lastcat = "";
$i2 = 1;
 $qtlcount = 0;
$result_pag_data = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result_pag_data)) {

$prodserv_uid			= $row["prodserv_uid"];
$qtl_title				= $row["qtl_title"];
$qtl_qty				= $row["qty"];
$qtl_days				= $row["qtl_days"];
$qtl_rrp_price			= $row["rrp_price"];
$qtl_rrp_price_format	= number_format($qtl_rrp_price, 2, '.', ',');

$qtl_line_disc			= $row["line_disc"];
$qtl_item_amount		= $row["item_amount"];
$qtl_item_amount_format	= number_format($qtl_item_amount, 2, '.', ',');
$qtl_line_amount		= $row["line_amount"];
$qtl_line_amount_format	= number_format($qtl_line_amount, 2, '.', ',');
$ttl_quote_net = $ttl_quote_net + $qtl_line_amount;
$qtl_incl_price			= $row["qtl_incl_price"];
 
$currcat				= $row["qtl_catname"];
 
 
 if ($currcat == $lastcat){
 
 }else{

	$qtl = $qtl . '<tr>
					<td>
					<span style="font-size: 12px; font-family: \'Helvetica\', \'Arial\', sans-serif;"><b>' . $currcat . '</b></span>
					</td>
					</tr>';
	$lastcat = $currcat;
			$qtlcount = $qtlcount + 1;		
	
 }


 $qtl = $qtl . '<tr>
   <td style="width: 500px; border: none;">' . $qtl_title . '</td>';

   $qtl = $qtl . '<td align="center" style="width: 100px; border: none; text-align: right;">' . floatval($qtl_qty) . '</td>';
						if ($showprice == "Yes"){

   $qtl = $qtl . '<td style="width: 120px; border: none; text-align:right;">';
   if ($qtl_incl_price == "1"){
	$qtl = $qtl . '$ ' . $qtl_item_amount_format;
   }
   $qtl = $qtl . '</td>
 <td style="width: 120px; border: none; text-align:right;">'; 
    if ($qtl_incl_price == "1"){
	$qtl = $qtl . '$ ' . $qtl_line_amount_format;
   }
  $qtl = $qtl . '</td>';
}
 $qtl = $qtl . '</tr>';

   $qtlcount = $qtlcount + 1;
  
  }

   $qtl = $qtl . '<tr>
   <td style="width: 500px; border: none;"></td>
     <td align="center" style="width: 70px; border: none; text-align: centre;"><br></td>
 <td style="width: 90px; border: none; text-align:right;"></td>
 <td style="width: 90px; border: none; text-align:right;"></td>
 </tr>
   <tr>
   <td style="width: 500px; border: none;" align="right"><span style="font-size: large"><strong>Total:</strong> &nbsp;&nbsp;</td>
     <td colspan="3" align="left" style="width: 70px; border: none; text-align: left;"><div style="display: inline; width: 150px; border:none; font-size: large; border-style:none; outline:none; border-width:0px; border-color: transparent; text-align: right;"><strong>$ #*ttl_quote_net*#</strong></div></td>
 </tr>';
 
    if ($qtlcount < 6){
	 
	 $qtlcount2 = $qtlcount;
	 
	 while($qtlcount2 < 6) {
		 $qtl = $qtl . '</tr><tr><td>&nbsp;</td></tr>';
		 $qtlcount2 = $qtlcount2 + 1;
	 }
		 
	 
 }
 
  $qtl = $qtl.'</tbody></table>';

						
	$ttl_quote_gst = ($ttl_quote_net/100)*15;

	$ttl_quote = ($ttl_quote_net+$ttl_quote_gst);
	

$report2 = str_replace("#*company_name*#",$ccomp_name,$report2);

$report2 = str_replace("#*company_addr1*#",$a_postline1,$report2);

$report2 = str_replace("#*company_addr2*#",$a_postline2,$report2);

$report2 = str_replace("#*company_addr3*#",$a_postline3,$report2);

$report2 = str_replace("#*company_addr4*#",$a_postline4,$report2);

$report2 = str_replace("#*company_addr5*#",$a_postline5,$report2);

$report2 = str_replace("#*ff1_st_id*#",$sales_id,$report2);

$report2 = str_replace("#*job_descr*#",$job_descr,$report2);

$report2 = str_replace("#*event_name*#",$event_name,$report2);
$report2 = str_replace("#*event_venue*#",$event_venue,$report2);

$report2 = str_replace("#*jobsheet_comments*#",$jobsheet_comments,$report2);

$report2 = str_replace("#*quote_txn_line*#",$qtl,$report2);

$report2 = str_replace("#*yourcompany_name*#",$outlet_name,$report2);

$report2 = str_replace("#*yourcompany_addr1*#",$phys_address1,$report2);

$report2 = str_replace("#*yourcompany_addr2*#",$phys_address2,$report2);

$report2 = str_replace("#*yourcompany_addr3*#",$phys_address3,$report2);

$report2 = str_replace("#*yourcompany_phone*#","Office Phone: ".$office_phone,$report2);


$report2 = str_replace("#*cust_ref*#",$client_order_no,$report2);
$report2 = str_replace("#*contact_name*#",$ccont_name,$report2);
$report2 = str_replace("#*contact_work_phone*#",$cwork_phone,$report2);
$report2 = str_replace("#*contact_cell_phone*#",$ccell_phone,$report2);
$sdate   =strtotime($sales_date);
$report2 = str_replace("#*job_date*#",date("d-M-Y",$sdate),$report2);
$jsd		=	strtotime($job_date_start);
$jed		=	strtotime($job_date_end);
$report2 = str_replace("#*job_start_date*#",date("d-m-y",$jsd),$report2);
$report2 = str_replace("#*job_end_date*#",date("d-m-y",$jed),$report2);

$dispdates = date("d-m-Y",$jsd) . " to " . date("d-m-Y",$jed);

$report2 = str_replace("#*event_dates*#",$dispdates,$report2);

$jst = date ('h:i a',strtotime($job_time_start));
$jet = date ('h:i a',strtotime($job_time_end));

$report2 = str_replace("#*job_start_time*#",$jst,$report2);
$report2 = str_replace("#*job_end_time*#",$jet,$report2);


$report2 = str_replace("#*job_outlet_compid*#",$_COOKIE['phxcrmclient_id'],$report2);
$report2 = str_replace("#*job_outlet_id*#",$job_compid,$report2);

$report2 = str_replace("#*yourcompany_fax*#","Office Fax: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$office_fax,$report2);
$report2 = str_replace("#*yourcompany_mobile*#","Office Mobile: ".$office_mobile,$report2);
$report2 = str_replace("#*yourcompany_gst_number*#","GST Number: ".$gst_number,$report2);
$report2 = str_replace("#*yourcompany_email*#","EMAIL: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=mailto:" . $outlet_email . ">" . $outlet_email . "</a>",$report2);
$report2 = str_replace("#*yourcompany_website*#","Website: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=http://" . $website . ">" . $website . "</a>",$report2);

$report2 = str_replace("#*salesmanagername*#",$job_sales_person_name,$report2);

$report2 = str_replace("#*quotetext1*#",$quote_text1,$report2);
$report2 = str_replace("#*quotetext2*#",$quote_text2,$report2);
$report2 = str_replace("#*quotetext3*#",$quote_text3,$report2);
$report2 = str_replace("#*quotetext4*#",$quote_text4,$report2);
$report2 = str_replace("#*quotetext5*#",$quote_text5,$report2);




$report2 = str_replace("#*ttl_quote_net*#",number_format($job_ttl_quote_xgst, 2, '.', ','),$report2);
$report2 = str_replace("#*ttl_quote_gst*#",number_format($job_ttl_quote_gst, 2, '.', ','),$report2);
$report2 = str_replace("#*ttl_quote_total*#",number_format($job_ttl_quote, 2, '.', ','),$report2);


//echo $report2;

//exit;


include("mpdflatest/mpdf.php");

//$mpdf=new mPDF('','A4', 12, 'Verdana,sans-serif', 20, 20, 20, 10, 20, 5, 'P');
$mpdf=new mPDF('','A4', 10, 'Helvetica', 20, 15, 15, 5, 5, 5, 'P');

//$mpdf=new mPDF('c','A4', 20, 'arial', 15, 15, 5, 5, 5, 5, 'P');

$mpdf->SetDisplayMode('fullpage');

$mpdf->WriteHTML($report2);	// Separate Paragraphs  defined by font

//$content = $mpdf->Output('', 'S');


	$file_name = "quote_".$sales_id.".pdf";

//$file_name = 'yourFileName.pdf';
$mpdf->Output($file_name, 'D');
//$content = $mpdf->Output($filename, 'F');
// You can now optionally also send it to the browser
//$mpdf->Output();
exit;


?>