<?php
include "koneksi.php";
if (!isset($_SESSION["UserID"])) {
	header("location:login.php?p=3");
}

// memanggil library FPDF
require('fpdf/fpdf.php');
// intance object dan memberikan pengaturan halaman PDF
$pdf = new FPDF('p','mm','A4');
// membuat halaman baru
$pdf->AddPage();
// setting jenis font yang akan digunakan
$pdf->SetFont('Arial','B',18);
// mencetak string 

$pdf->Image('images/mhb.jpeg',18,8,15);

$pdf->Image('profile/iso1.jpg',165,10,11);
$pdf->Image('profile/iso2.jpg',178,10,11);
$pdf->Image('profile/iso3.jpg',190,10,11);


$pdf->Cell(180,5,'PT.MULTI HIDRACHROME BALIKPAPAN',0,1,'C');
$pdf->SetFont('Arial','',10);
$pdf->Cell(180,4,'HYDRAULIC MANUFACTURE & HARDCHROME PLATING SERVICES',0,1,'C');
$pdf->Cell(180,5,'JL. Mulawarman RT.038 No.26A Manggar, Balikpapan 76116 Kalimantan Timur',0,1,'C');
$pdf->Cell(180,5,'Telp. (0542) 771768, 771836, 747074, Fax. (0542) 743276',0,1,'C');
$pdf->Cell(180,5,'Website : www.mhb-hydraulic.com, Email : adm_marketing@mhb-hydraulic.com, accounting1@mhb-hydraulic.com',0,1,'C');
$pdf->SetFont('Arial','B',10);

$pdf->Cell(180,5,'PURCHASE ORDER',0,1,'C');
$pdf->Cell(180,5,'Document No. : MHB-FR-PRC-001-02',0,1,'C');


$timezone = time() + (60 * 60 * 1);
date_default_timezone_set('Asia/Jakarta');
$pdf->Cell(180,6,'Balikpapan,  '.date('d / M / Y / H:i:s a',$timezone),0,1,'C');
$pdf->SetFont('Arial','B',10);



$idcuti = mysqli_real_escape_string($conn, $_GET["id"]);
$q = "SELECT * FROM data_purchasing_requisition WHERE id=".$idcuti;
$res = mysqli_query($conn, $q);
$row = mysqli_fetch_array($res);
$harga_setelah_diskon = $row['harga_discont'];
$harga_total = $row['harga_total_pcs'];

$diskon = $harga_total - $harga_setelah_diskon;

$id_suplier = $row['id_suplier'];
$s = "SELECT * FROM data_suplier WHERE id=" .$row['id_suplier'];
$resi = mysqli_query($conn,$s);
$rowi = mysqli_fetch_array($resi);
$top = $rowi["top"];

$id_user = $_SESSION['UserID'];
$a = "SELECT * FROM user WHERE id=" .$id_user;
$resa = mysqli_query($conn,$a);
$rowa = mysqli_fetch_array($resa);

$pdf->Cell(20 , 5, '',0,1,'c');
$pdf->Cell(20 , 5, '',0,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(100 , 5, 'ORDER TO      :  ' .$rowi['kode_suplier']. ' ( '.$rowi['nama_suplier'].' )',1,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(90 , 5, 'SHIP TO                 :  '.' PT.MULTI HIDRACHROME BALIKPAPAN',1,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(100 , 5,'Address            : ' .$rowi['alamat'],1,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(90 , 5, 'Requested by         :  Purchasing Dept.' .$rowa['nama'],1,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(100 , 5, 'Attention           :  ' .$rowi['contact_person'],1,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(90 , 5, 'Departemen           :  Purchasing',1,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(100 , 5,'Phone               : ' .$rowi['tlp'],1,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(90 , 5, 'Tax Number           : 02.724.421.9-721.000',1,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(100 , 5,'Fax                    : ',1,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(90 , 5, 'PR Number             : ' .$row['pr_no'],1,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(100 , 5,'',1,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(90 , 5, 'PR Date                  : ' .$row['pr_date'],1,1,'c');



$pdf->Cell(20 , 5, '',0,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(100 , 5, 'In confirmity with quotation we hereby order and request delivery for the following gods/services listed below      :',0,1,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(100 , 5,'QUOTE No.      : ' .$row['quote'],1,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(90 , 5, 'PO NO   :  ' .$row['no_po'],1,1,'c');


$pdf->SetFont('Arial','',11);//mulai isi
$pdf->Cell(20 , 5, '',0,1,'c');


$pdf->cell(10 , 6, 'NO.' ,1,0,'c');
$pdf->cell(70,6,'Description',1,0,'C');
$pdf->cell(15,6,'QTY',1,0,'C');
$pdf->cell(15,6,'UNIT',1,0,'C');
$pdf->cell(30,6,'Unit Price',1,0,'C');
$pdf->cell(50,6,'Total Rp.',1,1,'C');

$pdf->cell(10 , 50, '1.' ,1,0,'C');
$pdf->cell(70,50,''.$row['description'],1,0,'L');
$pdf->cell(15,50,''.$row['quantity'],1,0,'C');
$pdf->cell(15,50,''.$row['unit'],1,0,'C');
$pdf->cell(30,50,'Rp. '.number_format($row['harga'], 0, ".", "."),1,0,'C');
$pdf->cell(50,50,'Rp. '.number_format($row['harga_total_pcs'], 0, ".", "."),1,1,'C');

$pdf->cell(110 , 20, '' ,1,0,'c');
$pdf->cell(30,20,'',1,0,'L');
$pdf->cell(50,20,'',1,0,'C');



$pdf->Cell(20 , 2, '',0,1,'c');//supaya bisa tulisan masuk ke kolom
$pdf->SetFont('Arial','',8);
$pdf->Cell(40 , 2, 'TERMS OF PAYMENT : ',0,0,'c');//kolom top
$pdf->Cell(70 , 2,''.$top.'  Days After are gods Deliverd',0,0,'c');
$pdf->SetFont('Arial','B',8);
$pdf->Cell( 28, 2, '      SUB TOTAL       ',0,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell( 20, 2, '      Rp.       '.number_format($row['harga_total_pcs'], 0, ".", "."),0,1,'c');

$pdf->Cell(20 , 2, '',0,1,'c');//supaya bisa tulisan masuk ke kolom
$pdf->SetFont('Arial','',8);
$pdf->Cell(40 , 2, 'PRICE                           : ',0,0,'c');//kolom top
$pdf->Cell(70 , 2, 'FRANCO BPP ',0,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell( 43, 2, '      Discont  '.$row['besar_discont'].' %',0,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell( 20, 2,''.number_format($diskon, 0, ".", "."),0,1,'c');

$pdf->Cell(20 , 2, '',0,1,'c');//supaya bisa tulisan masuk ke kolom
$pdf->SetFont('Arial','',8);
$pdf->Cell(40 , 2, 'CUREENCY                  : ',0,0,'c');//kolom top
$pdf->Cell(70 , 2, 'Rp. (IDR)  ',0,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell( 31, 2, '      PPN 10%       ',0,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell( 20, 2, '  Rp.        '.number_format($row['harga_ppn'], 0, ".", "."),0,1,'c');

$pdf->Cell(20 , 2, '',0,1,'c');//supaya bisa tulisan masuk ke kolom
$pdf->SetFont('Arial','',8);
$pdf->Cell(40 , 2, 'DELIVERY TIME           :            '.$row['delivery_po_date'],0,0,'c');//kolom top
$pdf->Cell(70 , 2, '  ',0,0,'c');
$pdf->SetFont('Arial','B',8);
$pdf->Cell( 31, 6, '      NET PRICE       ',0,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell( 20, 6, '  Rp.        '.number_format($row['harga_akhir'], 0, ".", "."),0,1,'c');
	

$pdf->SetFont('Arial','B',8);
$pdf->cell(110 , 25, '' ,0,0,'c');
$pdf->cell(80,10,'      TOTAL '.'                       Rp.        '.number_format($row['harga_akhir'], 0, ".", "."),1,1,'L');


$pdf->Cell(20 , 5, '',0,1,'c');
$pdf->Cell(20 , 5, '',0,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(35 , 5, '* Please deliver material to our receiving departement enclosed with all related documents',0,1,'c');
$pdf->Cell(35 , 5, '* Please state PO Number on all documents',0,1,'c');
$pdf->Cell(35 , 5, '* PT.MHB is only responsible for delivered good as we received',0,1,'c');
$pdf->Cell(35 , 5, '* Goods / material received must be in accordance to PT MHB specification required. No varations will be accepted without prior notice',0,1,'c');





$pdf->SetFont('Arial','B',8);
$pdf->Cell(70 , 20, '                 Issued by,',0,0,'c');
$pdf->Cell(65 , 20, '                 Approved by,',0,0,'c');
$pdf->Cell(20 , 20, '                 Supplier,',0,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(59 , 5, '            (Acc By System)',0,0,'c');
$pdf->Cell(50 , 5, '         (Acc By System) '.$row['tgl_disetujui_direktur'],0,0,'c');
$pdf->Cell(20 , 5, '               ',0,1,'c');

$pdf->SetFont('Arial','B',8);
$pdf->Cell(74 , 5, '             Hary Prasetya,',0,0,'c');
$pdf->Cell(70 , 5, '         Lukito Prasetyo,',0,0,'c');
$pdf->Cell(20 , 5, '    ',0,1,'c');

$pdf->Cell(74 , 5, '               Purchasing,',0,0,'c');
$pdf->Cell(68 , 5, '           Opr. Director,',0,0,'c');
$pdf->Cell(20 , 5,$rowi['nama_suplier'],0,1,'c');




$no = 1;
$pdf->Ln();
while ($row = mysqli_fetch_array($res)){
	//$pdf->SetFont('Arial','B',10);
	//$pdf->SetFillColor(255,255,255);
	//$pdf->Cell(15,6,$no++,1,0,'C',true);
	//$pdf->Cell(40,6,$row['nik'],1,0,'C');
	//$pdf->Cell(85,6,$row['nama_karyawan'],1,0,'L');
	//$pdf->Cell(47,6,"",1,0,'C');
	//$pdf->Ln();
}

$pdf->Output();


?>