<?php
/**********************************************************************
***********************************************************************/

/**
	Document blueprint use following parameters set in doctext.inc:

	$Addr1,	$Addr2 - address info
	$Payment_Terms - payment terms line
	$Footer - footer texts
	$this->company - company info
	$this->title - report title
	$this->formData - some other info
***/
                $print_invoice_no = 0;
		$this->row = $this->pageHeight - $this->topMargin;

		$upper = $this->row - 2 * $this->lineHeight;
		$lower = $this->bottomMargin + 15 * $this->lineHeight;
		$iline1 = $upper - 4.0 * $this->lineHeight;
		$iline2 = $iline1 - 7 * $this->lineHeight;
		$iline3 = $iline2 ;//- 1.5 * $this->lineHeight;
		$iline4 = $iline3 ;//- 1.5 * $this->lineHeight;
		$iline5 = $iline4 ;//- 3 * $this->lineHeight;
		$iline6 = $iline5 - 1.5 * $this->lineHeight;
		$iline7 = $lower;
		$right = $this->pageWidth - $this->rightMargin;
		$width = ($right - $this->leftMargin) / 5;
		$icol = $this->pageWidth / 2;
		$ccol = $this->cols[0] + 4;
		$c2col = $ccol + 60;
		$ccol2 = $icol / 2;
		$mcol = $icol + 8;
		$mcol2 = $this->pageWidth - $ccol2;
                
        $header_col1 = 100;
        $header_col2 = 380;
                
		$cols = count($this->cols);
		
		//$this->rectangle($this->leftMargin, $iline2, $right - $this->leftMargin, $iline2 - $iline3, "F", null, array(222, 231, 236));   
//		$this->Line($iline2);
//		$this->Line($iline3);
//		$this->Line($iline4);
		//$this->rectangle($this->leftMargin, $iline5, $right - $this->leftMargin, $iline5 - $iline6, "F", null, array(222, 231, 236));   
		$this->Line($iline5);
		$this->Line($iline6);
		$this->Line($iline7);
		//$this->LineTo($this->leftMargin, $iline2 ,$this->leftMargin, $iline4);
		$col = $this->leftMargin;
//		for ($i = 0; $i < 5; $i++)
//		{
//			$this->LineTo($col += $width, $iline2,$col, $iline4);
//		}
		//$this->LineTo($right, $iline2 ,$right, $iline4);
        
        
		$this->LineTo($this->leftMargin, $iline5 ,$this->leftMargin, $iline7);
                $this->LineTo($this->cols[$cols - 9] - 4, $iline5   ,$this->cols[$cols - 9] - 4, $iline7);
                $this->LineTo($this->cols[$cols - 8] - 4, $iline5   ,$this->cols[$cols - 8] - 4, $iline7);
                $this->LineTo($this->cols[$cols - 7]- 4 , $iline5  ,$this->cols[$cols - 7] - 4 , $iline7);
//                $this->LineTo($this->cols[$cols - 6] -4 , $iline5  ,$this->cols[$cols - 6] - 4, $iline7);
                 $this->LineTo($this->cols[$cols - 5] -4 , $iline5  ,$this->cols[$cols - 5] - 4, $iline7);
                $this->LineTo($this->cols[$cols - 4] - 3, $iline5  ,$this->cols[$cols - 4] - 3, $iline7);
                $this->LineTo($this->cols[$cols - 3] , $iline5  ,$this->cols[$cols - 3], $iline7);
		$this->LineTo($this->cols[$cols - 2] , $iline5  ,$this->cols[$cols - 2], $iline7);
		$this->LineTo($right, $iline5 ,$right, $iline7);
                 $this->formData['document_name'] =_("Order No.");
			$this->formData['document_date'] = $this->formData['ord_date'];
			$this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference'])
				//? $this->formData['reference'] : $this->formData['order_no'];
                                ? $this->formData['order_no'] : $this->formData['order_no'];
			$this->formData['document_amount'] = $this->formData['order_no'];

		// Company Logo
		//$this->NewLine();
		$logo = company_path() . "/images/" . $this->company['coy_logo'];
		if ($this->company['coy_logo'] != '' && file_exists($logo))
		{
			$this->AddImage($logo, 20, $this->row - 55, 0, 70);
		}
		else
		{
			$this->fontSize += 4;
			$this->Font('bold');
			$this->Text($ccol, $this->company['coy_name'], $icol);
			$this->Font();
			$this->fontSize -= 4;
		}
                
		// Document title
		$this->SetTextColor(0, 0, 0);
		$this->fontSize += 4;
		$this->Font('bold');
                $this->TextWrap($header_col1, $this->row, $this->pageWidth - $this->rightMargin - $mcol - 20, $this->company['coy_name']);
		$this->fontSize += 3;
                $this->SetTextColor(0, 0, 0);
                $this->TextWrap($header_col2, $this->row - 4, $this->pageWidth - $this->rightMargin - $mcol - 10, $this->title);
		$this->Font();
		$this->fontSize -= 7;
		$this->NewLine();
		$this->SetTextColor(0, 0, 0);
		$adrline = $this->row;

		// Company data
		//$this->TextWrapLines(170, 100, $this->company['postal_address']);
                $this->Text($header_col1, $this->company['postal_address'], $header_col1 + 250);
                $this->NewLine();
                //$this->NewLine();
                
		$this->Font('italic');
		if (@$this->company['phone'])
		{
			$this->Text($header_col1, _("Phone:"), $header_col1 + 50);
			$this->Text($header_col1 + 40, $this->company['phone'], $mcol);
			$this->NewLine();
		}
                                
		if (@$this->company['fax'])
		{
			$this->Text($header_col1 + 140, _("Fax:"), $header_col1 + 50);
			$this->Text($header_col1 + 160, $this->company['fax'], $header_col1 + 250);
			$this->NewLine();
		}
		if (@$this->company['email'])
		{
			$this->Text($header_col1, _("Email:"), $header_col1 + 50);

			$url = "mailto:" . $this->company['email'];
			$this->SetTextColor(0, 0, 255);
			$this->Text($header_col1 + 40, $this->company['email'], $mcol);
			$this->SetTextColor(0, 0, 0);
			$this->addLink($url, $c2col, $this->row, $mcol, $this->row + $this->lineHeight);

			$this->NewLine();
		}
                
                $this->Text($header_col1, _("Website:"), $header_col1 + 50);

               $url = get_sys_prefs_parameter_value("website");
                
                $this->SetTextColor(0, 0, 255);
                $this->Text($header_col1 + 40, $url, $header_col1 + 220);
//                $this->NewLine();
                $this->SetTextColor(0, 0, 0);
                $this->addLink($url, $c2col, $this->row, $mcol, $this->row + $this->lineHeight);

                $this->NewLine();  
                        
		if (@$this->company['gst_no'])
		{
			$this->Text($header_col1, _("VAT No.:"), $header_col1 + 50);
			$this->Text($header_col1 + 40, $this->company['gst_no'], $mcol);
			$this->NewLine();
		}
		if (@$this->formData['domicile'])
		{
			$this->Text($ccol, _("Domicile"), $c2col);
			$this->Text($c2col, $this->company['domicile'], $mcol);
			$this->NewLine();
		}
		$this->Font();
		$this->row = $adrline;
		$this->NewLine(1);
		$this->Text($header_col2, _("Date:"));
		$this->Text($header_col2 + 60, sql2date($this->formData['document_date']));

		$this->NewLine();
		$this->Text($header_col2, $this->formData['document_name'].":");
		$this->Text($header_col2 + 60, $this->formData['document_number']);
                
                $this->NewLine();
		$this->Text($header_col2, "Project Code".":");
		$this->Text($header_col2 + 60, $this->params['project_code'],-2);
                
                $this->NewLine();
		$this->Text($header_col2, "Department".":");
		$this->Text($header_col2 + 60, $this->params['dep'],-2);
//return;
		if ($this->pageNumber > 1){
                        $this->NewLine();
			$this->Text($this->endLine - 35, _("Page") . ' ' . $this->pageNumber);
        }
		
/*=========================End of header============================*/
        
//        $this->SetDrawColor(205, 205, 205);
		//$this->Line($iline1, 3);
//		$this->SetDrawColor(128, 128, 128);
		$this->Line($iline1);
                $this->row = $iline1 - $this->lineHeight;
                
                
        
               
//			$aux_info = array(
//				_("Customer's Reference") => $this->formData["customer_ref"],
//				_("Sales Person") => get_salesman_name($this->formData['salesman']),
//				_("Your VAT no.") => $this->formData['tax_id'],
//				_("Our Order No") => $this->formData['order_no'],
//				_("Delivery Date") => sql2date($this->formData['delivery_date']),
//			);
                
                        $this->Font('b');
		$this->Text($ccol, "Vendor".":", $icol);
		$this->Text($mcol,"Delivered To".":");
                $this->Font('');
                
                $temp = $this->row = $this->row - $this->lineHeight - 5;
		$this->Text($ccol, $this->formData['supp_name'], $icol);
		$this->NewLine();
		$this->TextWrapLines($ccol, $icol - $ccol, $this->formData['address']);
                
//                $id = $this->formData['terms'];
//		$sql = "SELECT terms FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($id);
//		$result = db_query($sql,"could not get paymentterms");
//		$row = db_fetch($result);
		$Payment_Terms = _("Payment Terms") . ': ' . $this->params['payment_term'];
                
                $this->row = $temp;
		$this->Text($mcol, $this->formData['location_name']);
		$this->NewLine();
		$this->TextWrapLines($mcol, $this->rightMargin - $mcol, $this->formData['delivery_address']);
		$col = $this->leftMargin;
                $this->row = $iline5 + 4;
		$this->Font('italic');
		$this->TextWrap($ccol, $this->row, $right-$ccol, $Payment_Terms);
		$this->Font();

		// Line headers
		$this->row = $iline5 - $this->lineHeight - 1;
		$this->Font('bold');
		$count = count($this->headers);
		$this->cols[$count] = $right - 3;
		for ($i = 0; $i < $count; $i++)
			$this->TextCol($i, $i + 1, $this->headers[$i], -2);
		$this->Font();

		// Footer
		$this->Font('italic');
		$this->row = $iline7 - $this->lineHeight - 6;

//		

		$this->Font();
		$temp = $iline6 - $this->lineHeight - 2;
                $this->row = $temp;
?>
