<?php


// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file = K_PATH_IMAGES.'logo_example.jpg';
        $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        // Page number
        $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}

// create new PDF document
$pdf = new TCPDF(PPDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);    

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Kikin Kusumah');
$pdf->SetTitle($title);
$pdf->SetSubject('');
$pdf->SetKeywords('TCPDF, PDF, Kikinsoft');

// remove default header/footer
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));


// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(10,50,10,20);
$pdf->SetHeaderMargin(35);
$pdf->SetFooterMargin(10);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 10);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

//echo dirname(dirname(dirname(dirname(__FILE__)))).'/libraries/tcpdf_barcodes_1d_includek.php';
require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/libraries/tcpdf_barcodes_1d_includek.php');

// set the barcode content and type
// $barcodeobj = new TCPDFBarcode('http://www.tcpdf.org', 'C128');


// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 8);

$filename = '';
$total = $rtot[0]->total;
// die($total);
for ($i= 0; $i <= $total; $i=$i+45)
{
$page = $i;
$no = 0;
if($no >= $page){
	$totals = $rtot[0]->total;
	// die($totals);
		for ($j= 0; $j <= $totals; $j=$j+45)
	{

// add a page
$pdf->AddPage('P','A4');
//$pdf->Cell(0, 1, 'Nama', 1, 0, 'L','','','','','','T');
// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)
$html="";
// create some HTML content
$Fmatout_date= $rhdr->Fmatout_date;
$Fmatout_date = str_replace("/","-","$Fmatout_date");
$Fmatout_date= date("F m, Y", strtotime($Fmatout_date));
$Fetd= $rhdr->Fetd;
$Fetd = str_replace("/","-","$Fetd");
$Fetd= date("F d, Y", strtotime($Fetd));
$Feta= $rhdr->Feta;
$Feta = str_replace("/","-","$Feta");
$Feta= date("F d, Y", strtotime($Feta));
$html .=
'
<style type="text/css">
  h1 {
    font-family: "Arial";
    font-size:30px;
  }
  
</style>
<style type="text/css">
  h1 {
    font-family: "Arial";
    font-size:30px;
  }
  
</style>

<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>
        <tr>
        <td class="block" style="width: 60%; "></td>		
        <td class="block" style="width: 40%;"><h1>PACKING LIST</h1></td>
        </tr>
        <tr>
			<td class="block" style="width: 20%">Messers :</td>				
            <td class="block" style="width: 40%;">'.$rhdr->NmPrshn.'<br/>'.$rhdr->AlmtPrshn.'</td>
			<td class="block" style="width: 20%" border="1">INVOICE NO. <br/>'.$rhdr->cust_inv.'</td>
            <td class="block" style="width: 20%" border="1">Date <br/>'.$Fmatout_date.'</td>
        </tr>
        <tr>
            <td class="block" style="width: 20%"></td>						
            <td class="block" style="width: 20%">PHONE: '.$rhdr->tlp.'</td>
			<td class="block" style="width: 20%">FAX: '.$rhdr->fax.'</td>
            <td class="block" style="width: 40%;" border="1">PAYMENT TERMS <br/></td>						
        </tr>
        </tbody>
        </table>
        <table style="table-layout: auto; width: 100%;" border="1">
        <tbody>
        <tr>
            <td class="block" style="width: 20%">PORT OF DISPACTH <br/>'.$rhdr->port_odispacth.'</td>
            <td class="block" style="width: 20%">PORT OF DISCHARGE <br/>'.$rhdr->port_odischarge.'</td>
            <td class="block" style="width: 20%">FINAL OF DESTINATION <br/>'.$rhdr->final_odestination.'</td>
            <td class="block" style="width: 40%">B/L NO./AWB NO.</td>
        </tr> 
        </tbody>
        </table>
        <table style="table-layout: auto; width: 100%;" border="1">
        <tbody>
        <tr>
        <td class="block" style="width:55%;">Feder Name<br/>'.$rhdr->feder_name.'</td>
        <td class="block" style="width:25%;">ETD<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$Fetd.'</td>
        <td class="block" style="width:20%;">ETA<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$Feta.'</td>
        </tr> 
        </tbody>
</table>
<br/><br/>
<table style="table-layout: auto; width: 100%; bt=20; border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;" >
    <thead>
        <tr>
            <td class="block" style="text-align: center; width:10%; border:1px solid black">Pallets</td>
            <td class="block" style="text-align: center; width:15%; border:1px solid black">Carton No.</td>
            <td class="block" style="text-align: center; width:35%; border:1px solid black">Description of Goods<br></td>
            <td class="block" style="text-align: center; width:10%; border:1px solid black">Quantity</td>
            <td class="block" style="text-align: center; width:10%; border:1px solid black">Net.Weight</td>
            <td class="block" style="text-align: center; width:10%; border:1px solid black">Gross Weight</td>
            <td class="block" style="text-align: center; width:10%; border:1px solid black">Meas.</td>
        </tr>
          <tr>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;"></td>
        <td class="block" style="text-align: center; width:15%; border-left:1px solid black;"></td>
        <td class="block" style="text-align: ; width:35%; border-left:1px solid black;"><u>STEEL NUTS FUJILOCKNUTS</u><br></td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;">(PCS)</td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;">(KGM)</td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;">(KGM)</td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;">(IM3)</td>
        </tr>
        <tr>
        <td class="block" style="text-align: center; width:10%;"></td>
        <td class="block" style="text-align: ; width:15%;border-left:1px solid black;"><u><br></u></td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;"><u>Part No.</u></td>
        <td class="block" style="text-align: center; width:25%; "><u>Size</u></td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;"><u></u></td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;"></td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;"></td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;"></td>
        </tr>
		</thead>
    <tbody border="0">';
    $no_prev=$no;
    $no=0;
    foreach($rdet as $r){
        $no++;
        if($no <= $no_prev) continue;
        else {
      $Fqty = $r->Fqty;
      $Fqty = str_replace(".00","","$Fqty");
    $html.= 
    '		

        <tr>
        <td class="block" style="text-align: center; width:10%;"></td>
        <td class="block" style="text-align: ; width:15%;border-left:1px solid black;"></td>
        <td class="block" style="text-align: center; width:10%;border-left:1px solid black;">'.$r->mat_id.'</td>
        <td class="block" style="text-align: center; width:25%;">'.$r->PartNo.'</td>
        <td class="block" style="text-align: center; width:10%; border-left:1px solid black;">'.$Fqty.'</td>
        <td class="block" style="text-align: center; width:10%;border-left:1px solid black;">'.$r->Netto.'</td>
        <td class="block" style="text-align: center; width:10%;border-left:1px solid black;">'.$r->Bruto.'</td>
        <td class="block" style="text-align: center; width:10%;border-left:1px solid black;"></td>
        </tr>
';
    $no_break = $j+45;
    // var_dump($no_break);
    if($no == $no_break){
        $html .=
            '<p style="text-align: center;">*************************To Be Continue*************************</p> ';
    break;
        }
        }

    $totalQty += $r->qty;
    $total_format1 = number_format("$totalQty",0,",",",");
    //$Netto += $rhdr->Netto;
    //$Total_Netto = number_format("$Netto",0,",",",");
    //$Bruto += $rhdr->Bruto;
    //$Total_Bruto = number_format("$Bruto",0,",",",");
    }

    $total = $rtot[0]->total;
    if($no >= $total){
$html.= 
'
    </tbody>
    <tfoot>
            <tr>
            <td class="block" style="text-align: center; width:10%;border-top:1px solid black;"></td>
            <td class="block" style="text-align: ; width:15%;border-left:1px solid black; border-top:1px solid black;"></td>
            <td class="block" style="text-align: center; width:10%;border-left:1px solid black;border-top:1px solid black;"></td>
            <td class="block" style="text-align: center; width:25%; border-top:1px solid black;">Total</td>
            <td class="block" style="text-align: center; width:10%; border-left:1px solid black;border-top:1px solid black;">'.$total_format1.'</td>
            <td class="block" style="text-align: center; width:10%;border-left:1px solid black;border-top:1px solid black;"></td>
            <td class="block" style="text-align: center; width:10%;border-left:1px solid black;border-top:1px solid black;"></td>
            <td class="block" style="text-align: center; width:10%;border-left:1px solid black;border-top:1px solid black;"></td>
    </tr>
        
    </tfoot>
</table>

<br/>
<br/>
<font size="-1">
<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>
    <tr>
    <td class="block" style="width: 20%;"></td>
    <td class="block" style="width: 4%; ">**</td>
    <td class="block" style="width: 20%; ">NINTEEN (19) PALLETS ONLY</td>
    <td class="block" style="width: 48%; "></td>
    </tr>
    
    <tr>
    <td class="block" style="width: 20%;"></td>
    <td class="block" style="width: 4%; "></td>
    <td class="block" style="width: 20%; ">FREIGHT</td>
    <td class="block" style="width: 4%; ">:</td>
    <td class="block" style="width: 48%; ">PREPAID</td>
    </tr>
    <tr>
    <td class="block" style="width: 20%;"></td>
    <td class="block" style="width: 4%; ">**</td>
    <td class="block" style="width: 20%; ">COUNTRY OF ORIGIN</td>
    <td class="block" style="width: 4%; ">:</td>
    <td class="block" style="width: 48%; ">INDONESIA</td>
    </tr>
    <br>

        <tr>
			<td class="block" style="width: 20%;">SHIPPING MARK</td>
            <td class="block" style="width: 4%; ">:</td>
            <td class="block" style="width: 68%; ">FSJ</td>
        </tr>
        <tr>
        <td class="block" style="width: 20%;"></td>
        <td class="block" style="width: 4%; "></td>
        <td class="block" style="width: 68%; ">'.$rhdr->Prov.'</td>
        </tr>
        <tr>
        <td class="block" style="width: 20%;"></td>
        <td class="block" style="width: 4%; "></td>
        <td class="block" style="width: 68%; ">P/NO. 1-</td>
        </tr>
        <tr>
        <td class="block" style="width: 20%;"></td>
        <td class="block" style="width: 4%; "></td>
        <td class="block" style="width: 68%; ">MADE IN INDONESIA</td>
        </tr><br/>
        <tr>
        <td class="block" style= "text-align: center; font-size:12px; width: 50%; " border="0" ></td>
        <td class="block" style="width: 10%;"></td>
        <td class="block" style="width: 40%; "><h3>PT. FUJI SEIMITSU INDONESIA</h3></td>
        </tr><br/>
        <tr>
        <td class="block" style= "text-align: ; font-size:12px; width: 50%; " border="0"></td>
        <td class="block" style="width: 10%;"></td>
        <td class="block" style="width: 40%;"><br/><br/><br/><br/>
        <h3><u>SUKAMOTO YUKI</u></h3><br/>VICE PRESIDENT DIRECTOR</td>
        </tr>
        <tr>
            <td colspan="9"></td>
        </tr>
        <tr>
            <td colspan="9"></td>
        </tr>
    </tbody>';
        }
        $html.='
</table>
</font>
';
    

$filename = $rhdr->po_no;
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// ---------------------------------------------------------    
    }
}
}
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
// $pdf->Output($rs[$j]->po_no.'.pdf', 'I');
$pdf->Output($filename.'.pdf', 'I');

?>        