<?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->Image('profile/stempel.jpeg',100,245,31);


$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.ptmhb.com, Email : info@ptmhb.com, accounting1@ptmhb.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 gabung=".$idcuti;
$res = mysqli_query($conn, $q);
$row = mysqli_fetch_array($res);

$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);

$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, '',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');


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

$pdf->SetFont('Arial','B',7);
$pdf->Cell(8,6,'No.',1,0,'C');
$pdf->Cell(10,6,'No PR',1,0,'C');
$pdf->Cell(80,6,'Description',1,0,'C');
$pdf->Cell(10,6,'QTY',1,0,'C');
//$pdf->Cell(30,6,'User',1,0,'C');
$pdf->Cell(15,6,'Unit',1,0,'C');
$pdf->Cell(30,6,'Unit Price',1,0,'C');
$pdf->Cell(38,6,'Total Rp.',1,0,'C');
$pdf->Ln(2);
$no = 0;

$idcuti = mysqli_real_escape_string($conn, $_GET["id"]);
$sql ="select * from data_purchasing_requisition where gabung =".$idcuti;
$res = mysqli_query($conn, $sql);

while($data = mysqli_fetch_array($res))
{
	
	$harga_belum_diskon[] =$data['harga_total_pcs'];
	$discount=$data['discount_gabung'];
	$ppn=$data['ppn_gabung'];
	$delivery_po_date=$data['delivery_po_date'];
	$suplier = $data['id_suplier'];
	$tgl_acc = $data['tgl_disetujui_direktur'];
	$user_request = $data['user_request'];
	
	
	$no++;
	$pdf->Ln(4);
	$pdf->SetFont('Arial','',7);
	$pdf->Cell(8,4,$no.".",1,0,'C');
	$pdf->Cell(10,4,$data['pr_no'],1,0,'C');
	$pdf->Cell(80,4,$data['description'].' ('.$data['part_no'].' )',1,0,'C');
	$pdf->Cell(10,4,$data['quantity'],1,0,'C');
	//$pdf->Cell(30,4,$user,1,0,'C');
	$pdf->Cell(15,4,$data['unit'],1,0,'C');
	$pdf->Cell(30,4,'Rp. '.number_format($data['harga'], 0, ".", "."),1,0,'C');
	$pdf->Cell(38,4,'Rp. '.number_format($data['harga_total_pcs'], 0, ".", "."),1,0,'C');
	
}

//penghitungan
$total_harga_belum_diskon    =array_sum($harga_belum_diskon);
$diskon = is_numeric($total_harga_belum_diskon) * is_numeric($discount) / 100;
$total_diskon = $total_harga_belum_diskon - $diskon;
$totalPpn= 0;

//echo "diskon = ".$discount."<br>";
//echo "harga = ".$total_harga_belum_diskon."<br>";
//echo "harga setelah diskon = ".$diskon."<br>";

$o = "SELECT * FROM data_suplier WHERE id = '$suplier'";
							$reso = mysqli_query($conn, $o);
							$rowo = mysqli_fetch_assoc($reso);
							$top = $rowo["top"];
							
							

if ($ppn == 1)
{
	$total_ppn = round($total_harga_belum_diskon) * 0.1;
	$harga_total = $total_diskon + $total_ppn;
	//echo "ppn";
}
else
{
	$harga_total = $total_diskon;
	//echo "tidak ppn";
	$total_ppn = 0;
}
//echo "diskon = ".$discount;
//echo "ppn gabung = ".$ppn;

$pdf->Ln(8);
$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, ''.$rowi['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($total_harga_belum_diskon, 0, ".", "."),0,1,'c');

$pdf->Cell(20 , 2, '',0,1,'c');//supaya bisa tulisan masuk ke kolom
$pdf->SetFont('Arial','',8);
$pdf->Ln(2);
$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  '.$discount.' %',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->Ln(2);
$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($total_ppn, 0, ".", "."),0,1,'c');


$pdf->Cell(20 , 2, '',0,1,'c');//supaya bisa tulisan masuk ke kolom
$pdf->SetFont('Arial','',8);
$pdf->Ln(2);
$pdf->Cell(40 , 2, 'DELIVERY TIME           :            '.$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($total_harga_belum_diskon, 0, ".", "."),0,1,'c');
	


$pdf->SetFont('Arial','B',8);
$pdf->cell(110 , 25, '' ,0,0,'c');
$pdf->cell(80,10,'      TOTAL '.'                       Rp.        '.number_format($harga_total, 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 , 17, '                 Issued by,',0,0,'c');
$pdf->Cell(65 , 17, '                 Approved by,',0,0,'c');
$pdf->Cell(20 , 17, '                 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)'.$tgl_acc,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(76 , 5, '         Lukito Prasetyo,',0,0,'c');
$pdf->Cell(20 , 5,$rowi['nama_suplier'],0,1,'c');

$pdf->Cell(74 , 5, '               Purchasing,',0,0,'c');
$pdf->Cell(63 , 5, '               Director,',0,0,'c');
$pdf->Cell(20 , 5, '    ',0,1,'c');


//$rowi['kode_suplier']. ' ( '.$rowi['nama_suplier'].' )'

$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();


?>