<?php
require_once(PATH_CODE . 'tcpdf/tcpdf.php');

class RequestPdf extends TCPDF {    
    public function Header() {
        $this->SetY(10);

        $columnSize = $this->sales_order_column_size;
        $this->SetFont($this->fontname, '', 9);
        $header_data = $this->sales_order_data;
        $tbl = '<table border="0" cellpadding="1.25" cellspacing="0">
        <thead>
        <tr >
            <td rowspan="6"  width="'.($columnSize["image_content"]). '" align="left"><div align="left"><img src="' . $header_data['logopath'] . '" width="290" height="90" border="0" align="top" style="line-height:-30%;"/></div></td>
            <td width="' . $columnSize["margin_header"] . '"><span ><b></b></span></td>
            <td width="'.($columnSize["header_content"]+10). '" align="left" height="30"> <span style="font-size:19px;"><b>G O O D S&nbsp; R E C E I V I N G</b></span></td>
        </tr>
        <tr>
            <td width="' . $columnSize["margin_header"] . '"><span ><b></b></span></td>
            <td width="'.$columnSize["header_content"].'" align="left" height="30"> <span ><b>'.$header_data['gst_label'] .'</b></span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["header_content_label"].'"><span ><b>GRN Number</b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b>:</b></span></td>
            <td width="'.$columnSize["header_content_value"].'"><span ><b>'.$header_data['order_number'] .'</b></span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["header_content_label"]. '"><span ><b>GRN Date</b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b>:</b></span></td>
            <td width="'.$columnSize["header_content_value"].'"><span ><b>'.$header_data['order_date'].'</b></span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["header_content_label"].'"><span ><b>Page.</b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b>:</b></span></td>
            <td width="'.$columnSize["header_content_value"].'"><span ><b>'.($this->getAliasNumPage()).'</b></span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["content_item"].'"><span ><b></b></span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_content_image_adjustment"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["bill_to"].'"><span ><b>Bill To :</b></span></td>
            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["ship_to"].'"><span ><b>Ship To:</b></span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_content_image_adjustment"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["bill_to"].'"><span ><b>'.$header_data['supplier_name'].'</b></span></td>
            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["ship_to"].'"><span ><b>'.$header_data['shipping_to'].'</b></span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_content_image_adjustment"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["bill_to"].'"><span >'.$header_data['supplier_address'].'</span></td>
            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["ship_to"].'"><span >'.$header_data['shipping_to_address'].'</span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["content"].'"><span ><b></b></span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_content_image_adjustment"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["bill_to_contact_label"].'"><span ><b>Name</b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b>:</b></span></td>
            <td width="'.$columnSize["bill_to_contact_value"].'"><span >'.$header_data['supplier_billing_contact'].'</span></td>
            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["ship_to_contact_label"].'"><span ><b>Name</b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b>:</b></span></td>
            <td width="'.$columnSize["ship_to_contact_value"].'"><span >'.$header_data['shipping_to_name'] .'</span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_content_image_adjustment"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["bill_to_contact_label"].'"><span ><b>Phone</b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b>:</b></span></td>
            <td width="'.$columnSize["bill_to_contact_value"].'"><span >'. $header_data['supplier_phone'] .'</span></td>

            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["ship_to_contact_label"].'"><span ><b>Phone</b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b>:</b></span></td>
            <td width="'.$columnSize["ship_to_contact_value"].'"><span >'.$header_data['shipping_to_phone'].'</span></td>
        </tr>
        <tr>
            <td width="'.$columnSize["margin_content_image_adjustment"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["bill_to_contact_label"].'"><span ><b>Email</b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b>:</b></span></td>
            <td width="'.$columnSize["bill_to_contact_value"].'"><span >'.$header_data['supplier_email'].'</span></td>
            <td width="'.$columnSize["margin_header_content"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["ship_to_contact_label"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["double_dot"].'"><span ><b></b></span></td>
            <td width="'.$columnSize["ship_to_contact_value"]. '"><span ></span></td>
        </tr>
        </thead>
        </table>';

        $this->writeHTML($tbl, true, false, false, false, '');

        // $this->setY($this->getY() - 0.8);

        $tbl_header = '<table border="0" cellpadding="0" cellspacing="0" >
        <thead>
            <tr>
                <th rowspan="2" width="' . ($columnSize["margin_content_image_adjustment"] + 10) . '"><span ><b></b></span></th>
                <th rowspan="2" width="35" align="left"><span class="item_header"><b>S/N</b></span></th>
                <th rowspan="2" width="360" align="left" ><span class="item_header"><b>Description</b></span></th>
                <th rowspan="2" width="100" align="center" ><span class="item_header"><b>Qty Ordered</b></span></th>
                <th rowspan="2" width="100" align="right" ><span class="item_header"><b>Qty Received</b></span></th>
                <th width="0" align="right" ><span class="item_header"><b></b></span></th>
            </tr>
            <tr >
                <th colspan="5" align="right" width="79"></th>
            </tr>
            <tr>
                <th width="' . ($columnSize["margin_content_image_adjustment"] - 2) . '"><span ><b></b></span></th>
                <th width="' . ($columnSize["margin_content_image_adjustment"] - 4) . '"></th>
                <th width="' . ($columnSize["content_item"] - 4) . '"><div align="left"><hr style="line-height:50%;"/></div></th>
            </tr>
        </thead>
        </table>';

        $this->writeHTML($tbl_header, true, false, false, false, '');

        $this->SetMargins(PDF_MARGIN_LEFT + 4, $this->getY() - 2 , PDF_MARGIN_RIGHT, true);
        //$this->setY($this->getY()  );
    }

    public function Footer() {
        // set font
        // $fontname = "garudabook";
        $fontname = "lomabook";
        // set color for background
        $this->SetFillColor(255, 255, 255);

        // set margins
        //$this->SetMargins(PDF_MARGIN_LEFT, 0, PDF_MARGIN_RIGHT);

        // Position at 15 mm from bottom
        $this->SetY(-15);

        // Set font
        $this->SetFont($fontname, 'B', 8);
        $this->MultiCell(0, 0, strtoupper($this->coy_name), '', 'C'           , 1, 1, PDF_MARGIN_RIGHT, '', true);

        // Set font
        $this->SetFont($fontname, '', 8);
        $this->MultiCell(0, 0, trim(preg_replace('/\s+/', ' ', $this->coy_address)), '', 'C'           , 0, 0, PDF_MARGIN_RIGHT, '', true);
    }

    public function AcceptPageBreak() {
        if (1 == $this->PageNo()) {
               //$this->SetMargins(PDF_MARGIN_LEFT, 90, PDF_MARGIN_RIGHT, true);

        }
       if ($this->num_columns > 1) {
           // multi column mode
           if ($this->current_column < ($this->num_columns - 1)) {
               // go to next column
               $this->selectColumn($this->current_column + 1);


           } elseif ($this->AutoPageBreak) {
               // add a new page

               $this->AddPage();

               // set first column
               $this->selectColumn(0);
           }
           // avoid page breaking from checkPageBreak()
           return false;
       }
       return $this->AutoPageBreak;
   }

}
