<?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>INVOICE</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 cellspacing="0" style="table-layout: auto; width: 100%; 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:60%; 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">Price</td>
            <td class="block" style="text-align: center; width:20%; border:1px solid black">Amount</td>
        </tr>
      	<tr>
        <td class="block" style="text-align: ; width:60%;"><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;">(JPY)</td>
        <td class="block" style="text-align: center; width:20%; border-left:1px solid black;">(JPY)</td>
        </tr>
        <tr>
        <td class="block" style="text-align: center; width:5%;"></td>
        <td class="block" style="text-align: ; width:15%;"><u>Order No.<br></u></td>
        <td class="block" style="text-align: center; width:10%;"><u>Part No.</u></td>
        <td class="block" style="text-align: center; width:30%;"><u>Size</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:20%; 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 {
      $amount = $r->amount;
      $amount = str_replace(".00","","$amount");
      $Fqty = $r->Fqty;
      $Fqty = str_replace(".00","","$Fqty");
      $Fprice = $r->Fprice;
      $Fprice = number_format("$Fprice",2,".",".");
      $Netto = $rhdr->Netto;
      $Netto = number_format("$Netto",0,",",",");
      $Bruto = $rhdr->Bruto;
      $Bruto = number_format("$Bruto",0,",",",");
      
    $html.= 
            '		
            <tr>
            <td class="block" style="text-align: center; width:5%;">'.$no.'</td>
            <td class="block" style="text-align: ; width:15%;"><br>'.$r->npo_id.'</td>
            <td class="block" style="text-align: center; width:10%;">'.$r->mat_id.'</td>
            <td class="block" style="text-align: center; width:30%;">'.$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;">'.$Fprice.'</td>
            <td class="block" style="text-align: center; width:20%;border-left:1px solid black;">'.$amount.'</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,",",",");
        $tot_amount = $rhdr->tot_amount;
        $total_format = number_format("$tot_amount",0,",",",");

    }
    $total = $rtot[0]->total;
    if($no >= $total){

        //$total_format = number_format("$rhdr->tot_amount",0,",",",");
        $html .= 
        '
        </tbody>
            <tfoot>
            <tr>

                <td class="block" style="text-align:; width:60%; "><br><br><br><br><br><br><strong>
                TOTAL</strong><br/>
                ** &nbsp;&nbsp;&nbsp;&nbsp; NINETEEN (19) PALLETS ONLY <br/>
                ** &nbsp;&nbsp;&nbsp;&nbsp; NET WEIGHT &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 
                '.$Netto.' KGS ** MEANSUREMENT 12,25 M3<br/>
                ** &nbsp;&nbsp;&nbsp;&nbsp; GROS WEIGHT &nbsp;&nbsp;: 
                '.$Bruto.' KGS<br/>
                ** &nbsp;&nbsp;&nbsp;&nbsp; FREIGHT     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
                 PREPAID<br/>
                ** &nbsp;&nbsp; &nbsp;&nbsp;COUNTRY OF ORIGIN  &nbsp;&nbsp;: 
                INDONESIA<br></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:20%; border-left:1px solid black;"></td>
            </tr>
    
            <tr>
                <td class="block" style="text-align: right; width: 60%; border-right:1px solid black; border-bottom:1px solid black;" >Total Quantity </td>
                <td class="block" style="width: 10%; border-right:1px solid black; border-bottom:1px solid black;" >'.$total_format1.'</td>
                <td class="block" style="width: 10%; border-right:1px solid black; border-bottom:1px solid black;" ></td>
                <td class="block" style="text-align: center; width: 20%; border-bottom:1px solid black;"></td>
            </tr>
                <tr>
                <td class="block" style="width: 60%;" ></td>
                <td class="block" style="width: 20%;" >CIF '.$rhdr->Negara.' </td>
                <td class="block" style="text-align: center; width: 20%; border-right:1px solid black; border-left:1px solid black;">'.$total_format.'</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: 30%;">SHIPPING MARK</td>
            <td class="block" style="width: 2%; ">:</td>
            <td class="block" style="width: 68%; ">FSJ</td>
            </tr>
            <tr>
            <td class="block" style="width: 30%;"></td>
            <td class="block" style="width: 2%; "></td>
            <td class="block" style="width: 68%; ">'.$rhdr->Prov.'</td>
            </tr>
            <tr>
            <td class="block" style="width: 30%;"></td>
            <td class="block" style="width: 2%; "></td>
            <td class="block" style="width: 68%; ">'.$rhdr->insured.'</td>
            </tr>
            <tr>
            <td class="block" style="width: 30%;"></td>
            <td class="block" style="width: 2%; "></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="1" >
            Original for the purpose of Insurance Claim</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="1">
            '.$rhdr->insured.'</td>
            <td class="block" style="width: 10%;"></td>
            <td class="block" style="width: 40%;"><br/><br/><br/><br/>
            <h3><u>'.$rhdr->vpd.'</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->matout_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('INVOICE-'.$filename.'.pdf', 'I');

?>        