<?php

$this->row = $this->pageHeight - $this->topMargin;

$upper = $this->row - 2 * $this->lineHeight;
$lower = $this->bottomMargin + 13 * $this->lineHeight;
$iline1 = $upper - 7.5 * $this->lineHeight;
$iline2 = $iline1 - 4 * $this->lineHeight;
$iline5 = $iline2 - 1 * $this->lineHeight;
$iline6 = $iline5 - 1.5 * $this->lineHeight;
$iline7 = $lower;
$iline8 = $iline7 - 5 * $this->lineHeight;
$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;
$cols = count($this->cols);

$this->lineHeight = 20;
$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);
for($i = $iline6;$i > $iline7;$i -= $this->lineHeight){
    $this->Line($i);
}
$this->lineHeight = 12;

$Totalline = $iline7 + (5 * $this->lineHeight);
$Signline = $iline7 - (9 * $this->lineHeight);
$Signline1 = $iline7 - (13 * $this->lineHeight);
$col = $this->leftMargin;

$this->LineTo($this->leftMargin, $iline5, $this->leftMargin, $iline7);


$this->Font('bold');
$this->TextWrap($this->leftMargin + 2, $iline8 + (2 * $this->lineHeight), 0, "(*) Example abbreviations: DG - Damaged Goods / DO - Duplicate Order / IG - Incorrect Goods, etc");
$this->TextWrap($this->leftMargin + 2, $iline8 - $this->lineHeight, 0, "Requested By: ");
$this->Font();
$this->fontSize += 2;
$this->TextWrap($this->leftMargin + 70, $iline8 - $this->lineHeight, 0, $this->formData['requestedby']);
$this->fontSize -= 2;
$this->Font('bold');
$this->TextWrap($this->leftMargin + 2, $Signline, 0, "Approved By:___________________________________________");

$this->Font();
$this->TextWrap($this->cols[3], $iline8 - $this->lineHeight, 0, "Date :".date('M d, Y',strtotime($this->formData['date'])));
$this->TextWrap($this->cols[3], $Signline, 0, "Date :".date('M d, Y', strtotime($this->formData['date'])));

$this->Font('bold');
$this->TextWrap($this->cols[5], $iline8 - $this->lineHeight, 0, "Signature:___________________________");
$this->TextWrap($this->cols[5], $Signline, 0, "Signature:___________________________");
$this->Font();

$this->LineTo($this->cols[6] - 5, $iline5, $this->cols[6] - 5, $iline7);
$this->LineTo($this->cols[5] - 5, $iline5, $this->cols[5] - 5, $iline7);
$this->LineTo($this->cols[4] - 5, $iline5, $this->cols[4] - 5, $iline7);
$this->LineTo($this->cols[3] - 5, $iline5, $this->cols[3] - 5, $iline7);
$this->LineTo($this->cols[2] - 5, $iline5, $this->cols[2] - 5, $iline7);
$this->LineTo($this->cols[1] - 5, $iline5, $this->cols[1] - 5, $iline7);
$this->LineTo($right, $iline5, $right, $iline7);

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

// Company data
$this->TextWrapLines($ccol, $icol, $this->company['postal_address']);
$this->Font('italic');


$this->lineHeight = 17;

$this->NewLine();
//$this->fontSize += 2;
//$this->Font('bold');
$this->Text($ccol, "Customer Code", $icol);
$this->Font();
$this->Text($ccol + 70, ": ".$this->formData['debtor_no']);
//$this->fontSize -= 2;

$this->NewLine();
//$this->fontSize += 2;
//$this->Font('bold');
$this->Text($ccol, "Customer Name", $icol);
$this->Font();
$this->Text($ccol + 70, ": ".$this->formData['debtor_name']);
//$this->fontSize -= 2;

$this->NewLine();
//$this->fontSize += 2;
//$this->Font('bold');
$this->Text($ccol, "Address", $icol);
$this->Font();
$this->Text($ccol + 70, ": ");
//$this->fontSize -= 2;

$this->NewLine();
//$this->fontSize += 2;
//$this->Font('bold');
$this->Text($ccol, "Telephone", $icol);
$this->Font();
$this->Text($ccol + 70, ": ");
//$this->fontSize -= 2;

$this->NewLine();
//$this->fontSize += 2;
//$this->Font('bold');
$this->Text($ccol, "Contact Person:", $icol);
$this->Font();
$this->Text($ccol + 70, ": ");
//$this->fontSize -= 2;


$this->Font();
$this->row = $adrline ;
$this->NewLine(2);
$this->Text($mcol + 100, _("Date:"));
$this->Text($mcol + 180, sql2date($this->formData['date']));

$this->NewLine();
$this->Text($mcol + 100, "Serial #:");
$this->Text($mcol + 180, sprintf( '%06d',$this->formData['no']));
$this->NewLine(2);

$this->lineHeight = 12;

if ($this->pageNumber > 1)
    $this->Text($mcol + 180, _("Page") . ' ' . $this->pageNumber);
//$this->row = $iline1 - $this->lineHeight;



// 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;
