<?php
// HTML HEADER & STYLES
$this->data = "<!DOCTYPE html><html><head><style>".
"html,body{font-family:sans-serif}#invoice{max-width:800px;margin:0 auto}#company,#billship{margin-bottom:30px}#billship{border:1px solid #9a9a9a}#billship td{border:1px solid #9a9a9a;border-bottom:none;} #billship td{border-bottom:1px solid #9a9a9a}#billship,#company,#items{width:100%;border-collapse:collapse}#company td,#billship td,#items td,#items th{padding:10px}#company td{vertical-align:top}#bigi{margin-bottom:20px;font-size:28px;font-weight:700;color:#296103}#co-addr{font-size:.95em;color:#477f21}#co-right img{max-width:180px;height:auto}#billship td{width:33%}#items th{text-align:left;background: #d8f5c4;padding:20px 10px}#items td{background:#fbfbfb;}.idesc{color:#80592d}#items tr.ttl td{ color: #ffffff;background:#9e866b;border-bottom:none;font-weight:700}.right{text-align:right}#notes{background:#d8f5c4;padding:10px;margin-top:30px}#act-image{margin: 0 auto;max-height:180px;}#items tr{height:auto;}#act-image img{max-width:180px;height:auto}.zero-padding-margin{padding-top:0px!important; margin-top:0px!important;padding-bottom:0px!important; margin-bottom:0px!important}.border-dark{border-bottom:1px solid #c8d2d7}.margin-left-3{margin-left:8px;}.sign-img{float:right;margin-top:15px;margin-bottom:130px}.invoice-mess{font-weight:bolder;margin-bottom:1px}.invoice-mess-div{}.comp-name{font-size:17}.comp-add{font-size:13}".
"</style></head><body><div id='invoice'>";
//
// COMPANY LOGO + INFORMATION
$this->data .= "<table id='company'><tr><td id='co-left'><div id='bigi'>INVOICE</div><div id='co-addr'>";
for ($i=2;$i<count($this->company);$i++) {
	$this->data .= $this->company[$i]."<br>";
}
$this->data .= "</div></td><td id='co-right' class='right'><img src='".$this->company[0]."'/></td></table>";

// BILL TO
$this->data .= "<table id='billship'><tr><td><strong>CLIENT INFORMATION:</strong><hr>";
foreach ($this->billto as $b) { $this->data .= $b."<br>"; }

// SHIP TO
$this->data .= "<br><br></td><td  style = 'border-bottom: #9a9a9a'><strong>SERVICE ADDRESS:</strong><hr>";
foreach ($this->shipto as $s) { $this->data .= $s."<br>"; }

// INVOICE INFO

$this->data .= "<br><br></td><td  style = 'border-bottom: #9a9a9a'><strong>INVOICE DETAILS:</strong><hr>";
foreach ($this->invoice as $i) {
	$this->data .= "<strong>$i[0]:</strong> $i[1]<br>";
} 
$is_set_name = "";
foreach ($this->items as $i) {
$is_set_name = $i[31];
}
if($is_set_name == 'set'){
	$this->data .= "<br><br>";
}

$this->data .= "</td></tr></table>";

// ITEMS
$this->data .= "<table id='items'><tr><th>ITEM</th><th>DESCRIPTION</th><th>QUANTITY</th><th>UNIT PRICE</th><th>AMOUNT</th></tr>";
foreach ($this->items as $i) {
	$this->data .= "<tr><td style = 'border-bottom: #e4eff5'><div><b>".$i[0]."</b></div></td>";	
	
	$this->data .= "<td  style = 'text-align:justify;border-bottom: #e4eff5' align='justify' >".($i[1]==""?"":"<small class='idesc'>$i[1]<br></small>")."</td>";
	
	if($i[9]== 0 || $i[9]== 1 || $i[9]== 5 || $i[9]== 6 || $i[9]== 7 || $i[9]== 8){
		$item_quant = $i[2];
	}else{
		$item_quant = "";
	}	
	
	if($i[9]== 2){
		$item_quant1 = "<b>".$i[18].":</b> ".$i[20]."<br><br><b>".$i[19].": </b>".$i[21];
	}elseif($i[9]== 4){
		$item_quant1 = "<b>".$i[10].": </b>".$i[14]."<br><br><b>".$i[11].": </b>".$i[15]."<br><br><b>".$i[12].": </b>".$i[16]."<br><br><b>".$i[13].": </b>".$i[17];
	}else{
		$item_quant1 = "";
	}

	$this->data .= "<td style = 'border-bottom: #e4eff5;' class = 'center-quant'><p><span style='font-size:.75em;'>".$item_quant."</span></td>";


	if($i[9]== 0){
		$item_amount =$i[3];
    }elseif($i[9]== 2 || $i[9]== 1 || $i[9]== 5 || $i[9]== 6 || $i[9]== 7 || $i[9]== 8){
		$item_amount =$i[3];
    }else{
		$item_amount = '';
	}
	$this->data .= "<td style = 'border-bottom: #e4eff5'>".$item_amount."</td>";
	
	$this->data .= "<td style = 'border-bottom: #e4eff5'>".$i[4]."</td></tr>";

	if(strlen($item_quant1)>0){
		$this->data .= "<tr>
	<td style = 'padding:0px; margin:0px' class='".($i[22] != 'set'?'':'')."zero-padding-margin'></td><td style = 'padding:0px; margin:0px' class='".($i[22] != 'set'?'':'')."zero-padding-margin'><span style='font-size:.75em;'>$item_quant1</span></td><td style = 'padding:0px; margin:0px' class='".($i[22] == 'set'?'':'')."zero-padding-margin'></td><td style = 'padding:0px; margin:0px' class='".($i[22] == 'set'?'':'')."zero-padding-margin'></td><td style = 'padding:0px; margin:0px' class='".($i[22] == 'set'?'':'')."zero-padding-margin'></td></tr>";
	}
	
	
	if($i[22] == 'set'){
		$this->data .= "<tr>
		<td style = '".($i[23] == 'set'?'border-bottom: #e4eff5;':'')."' class='zero-padding-margin".($i[23] == 'set'?'':'')."'><b>".$i[24]. "</b></td><td style='".($i[23] == 'set'?'border-bottom: #e4eff5;':'')."padding:0px; margin:0px' class='zero-padding-margin".($i[23] == 'set'?'':'')."'><small class='idesc'>". $i[25] ."</small></td><td style = '".($i[23] == 'set'?'border-bottom: #e4eff5;':'')."' class='zero-padding-margin".($i[23] == 'set'?'':'')."'></td><td style = '".($i[23] == 'set'?'border-bottom: #e4eff5;':'')."' class='zero-padding-margin".($i[23] == 'set'?'':'')."'>". $i[26]. "</td><td style = '".($i[23] == 'set'?'border-bottom: #e4eff5;':'')."' class='zero-padding-margin".($i[23] == 'set'?'':'')."'></td>
		
		</tr>";
	
	}
	
	if($i[23] == 'set'){
		$this->data .= "<tr>
		<td class='zero-padding-margin'><b>".$i[27]. "</b></td><td style='padding:0px; margin:0px' class='zero-padding-margin'><small class='idesc'>". $i[28] ."</small></td><td class='zero-padding-margin'></td><td class='zero-padding-margin'>". $i[29]. "</td><td class='zero-padding-margin'></td>
		
		</tr>";
		
	}
		if(strlen($i[32]) > 0){
			$this->data .= "<tr><td style = 'border-bottom: #e4eff5; padding:0px; margin:0px'  class='zero-padding-margin' colspan='5'>".($i[32]==""?"":"<img src='$i[32]' style='height:120px; width:120px;display:block;float:left; margin-left:10px' />").($i[33]==""?"":"<img src='$i[33]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[34]==""?"":"<img src='$i[34]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[35]==""?"":"<img src='$i[35]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[36]==""?"":"<img src='$i[36]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>")."</td></tr>";
		}
		
		if(strlen($i[37]) > 0){
			$this->data .= "<tr><td style = 'border-bottom: #e4eff5; padding:0px; margin:0px'  class='zero-padding-margin' colspan='5'>".($i[37]==""?"":"<img src='$i[37]' style='height:120px; width:120px;display:block;float:left; margin-left:10px' />").($i[38]==""?"":"<img src='$i[38]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[39]==""?"":"<img src='$i[39]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[40]==""?"":"<img src='$i[40]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[41]==""?"":"<img src='$i[41]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>")."</td></tr>";
		}	
	
		if(strlen($i[42]) > 0){
			$this->data .= "<tr><td style = 'border-bottom: #e4eff5; padding:0px; margin:0px'  class='zero-padding-margin' colspan='5'>".($i[42]==""?"":"<img src='$i[42]' style='height:120px; width:120px;display:block;float:left; margin-left:10px' />").($i[43]==""?"":"<img src='$i[43]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[44]==""?"":"<img src='$i[44]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[45]==""?"":"<img src='$i[45]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[46]==""?"":"<img src='$i[46]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>")."</td></tr>";
		}	
	
		if(strlen($i[47]) > 0){
			$this->data .= "<tr><td style = 'border-bottom: #e4eff5; padding:0px; margin:0px'  class='zero-padding-margin' colspan='5'>".($i[47]==""?"":"<img src='$i[47]' style='height:120px; width:120px;display:block;float:left; margin-left:10px' />").($i[48]==""?"":"<img src='$i[48]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[49]==""?"":"<img src='$i[49]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[50]==""?"":"<img src='$i[50]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[51]==""?"":"<img src='$i[51]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>")."</td></tr>";
		}	
	
		if(strlen($i[52]) > 0){
			$this->data .= "<tr><td style = 'border-bottom: #e4eff5; padding:0px; margin:0px'  class='zero-padding-margin' colspan='5'>".($i[52]==""?"":"<img src='$i[52]' style='height:120px; width:120px;display:block;float:left; margin-left:10px' />").($i[53]==""?"":"<img src='$i[53]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[54]==""?"":"<img src='$i[54]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[55]==""?"":"<img src='$i[55]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[56]==""?"":"<img src='$i[56]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>")."</td></tr>";
		}	
	
		if(strlen($i[57]) > 0){
			$this->data .= "<tr><td style = 'border-bottom: #e4eff5; padding:0px; margin:0px'  class='zero-padding-margin' colspan='5'>".($i[57]==""?"":"<img src='$i[57]' style='height:120px; width:120px;display:block;float:left; margin-left:10px' />").($i[58]==""?"":"<img src='$i[58]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[59]==""?"":"<img src='$i[59]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[60]==""?"":"<img src='$i[60]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>").($i[61]==""?"":"<img src='$i[61]' style='height:120px; width:120px;display:block;float:left; margin-left:10px'/>")."</td></tr>";
		}
		
	$this->data .= "<tr>
		<td class='border-dark zero-padding-margin' colspan='5'></td>
		
		</tr>";
}

$bid_message_set = '';
if (count($this->totals)>0) { foreach ($this->totals as $t) {
	$bid_question_string1 = '';
	$bid_question_string2 = '';
	$bid_question_string3 = '';
	if($t[2] == 'yes'){
		$bid_message_set = 'y';
		$bid_question_string1 = "Bid Created: Yes";
		$bid_question_string2 = "Bid#: $t[4]";
		$bid_question_string3 = "Bid Amount: $$t[3]";
	}
	$this->data .= "<tr class='ttl'><td class='right' colspan='3'><b>$t[0]</b></td><td class='right' colspan='2'><b>$t[1]</b></td></tr>";
}}
$this->data .= "</table>";


// NOTES
if (count($this->notes)>0) {
	if($bid_message_set == 'y'){
		$this->data .= "<div id='notes'> <strong>$bid_question_string1</strong>  <br><br><strong>$bid_question_string2</strong><br><br> 	<strong>$bid_question_string3</strong> <br> <br>";
	}else{
		$this->data .= "<div id='notes'>	<br>";
	}
	
	foreach ($this->notes as $n) {
		$this->data .= $n."<br>";
	}
	$this->data .= "</div>";
}
$this->data .= "</div>";
// CLOSE
/* $this->data .= $sign_pathx; */
$this->data .= "</div></body></html>";
$mpdf->WriteHTML($this->data);
?>