<?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',20,10,15);

//$pdf->Image('profile/iso1.jpg',205,10,14);
//$pdf->Image('profile/iso2.jpg',225,10,15);
//$pdf->Image('profile/iso3.jpg',245,10,15);



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

$pdf->Cell(200,5,'PERMINTAAN DANA CASH',0,1,'C');
$pdf->SetFont('Arial','',10);


$timezone = time() + (60 * 60 * 1);
date_default_timezone_set('Asia/Jakarta');
$pdf->Cell(200,6,'Balikpapan,  '.date('d / M / yy / 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 advance='1'";
$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,'Address            : ' .$rowi['alamat'],1,0,'c');
$pdf->SetFont('Arial','',8);
$pdf->Cell(90 , 20, 'Kepada Yth,         ',1,1,'c');

$pdf->Cell(90 , 5, 'Departemen            :   Purchasing',1,1,'c');
$pdf->Cell(90 , 5, 'Signature                :   By system',1,1,'c');



$pdf->SetFont('Arial','B',8);
$pdf->Cell(100 , 5,'PR Number*          :   '.$row['pr_no'],1,0,'c');
$pdf->SetFont('Arial','',8);
if ($row['type_of_material'] == 1)
{
	$pdf->Cell(90 , 5, 'Type of Material*                    :   Consumable',1,1,'c');
}
if ($row['type_of_material'] == 2)
{
	$pdf->Cell(90 , 5, 'Type of Material*                    :   Non - Consumable',1,1,'c');
}


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

if ($row['pr_date'] == 1)
{
	$pdf->Cell(90 , 5, 'Purchase Request Type*       :   Normal',1,1,'c');
}
if ($row['type_of_material'] == 2)
{
	$pdf->Cell(90 , 5, 'Purchase Request Type*       :   Urgent',1,1,'c');
}
if ($row['type_of_material'] == 3)
{
	$pdf->Cell(90 , 5, 'Purchase Request Type*       :   Top Urgent',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(30,6,'Matr. Master',1,0,'C');
$pdf->Cell(80,6,'Description',1,0,'C');
$pdf->Cell(15,6,'Part No.',1,0,'C');
$pdf->Cell(15,6,'Qty',1,0,'C');
//$pdf->Cell(30,6,'User',1,0,'C');
$pdf->Cell(15,6,'Unit',1,0,'C');
$pdf->Cell(50,6,'Justification',1,0,'C');
$pdf->Cell(40,6,'Date Time',1,0,'C');
$pdf->Ln(2);
$no = 0;

//$idcuti = mysqli_real_escape_string($conn, $_GET["id"]);
$sql ="select * from data_purchasing_requisition where advance ='1'";
$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(30,4,$data['matr_master'],1,0,'C');
	$pdf->Cell(80,4,$data['description'],1,0,'C');
	$pdf->Cell(15,4,$data['part_no'],1,0,'C');
	//$pdf->Cell(30,4,$user,1,0,'C');
	$pdf->Cell(15,4,$data['quantity'],1,0,'C');
	$pdf->Cell(15,4,$data['unit'],1,0,'C');
	$pdf->Cell(50,4,$data['justification'],1,0,'C');
	$pdf->Cell(40,4,$data['acc_code'],1,0,'C');
	
}

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



$pdf->Ln(8);
$pdf->Cell(20 , 2, '',0,1,'c');//supaya bisa tulisan masuk ke kolom
$pdf->SetFont('Arial','B',12);
$pdf->Cell(40 , 2, 'Note                :    '.$row['note'],0,0,'c');//kolom top


$pdf->Cell(20 , 2, '',0,1,'c');//supaya bisa tulisan masuk ke kolom
$pdf->SetFont('Arial','',8);
$pdf->Ln(2);


$pdf->SetFont('Arial','',8);



$pdf->Ln(20);

$pdf->SetFont('Arial','B',8);
$pdf->Cell(70 , 20, '                 Request by,',0,0,'c');
$pdf->Cell(65 , 20, '                 Acknowledged by,',0,0,'c');
$pdf->Cell(60 , 20, '                 Reviewed by,',0,0,'c');
$pdf->Cell(20 , 20, '                 Approved by,',0,1,'c');

$pdf->SetFont('Arial','',8);
$pdf->Cell(59 , 5, '            (Acc By System)',0,0,'c');
$pdf->Cell(59 , 5, '                                 (Acc By System)',0,0,'c');
$pdf->Cell(59 , 5, '                                     (Acc By System)',0,0,'c');
$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');

$b = "SELECT * FROM data_karyawan WHERE nik=" .$row['user_request'];
$resb = mysqli_query($conn,$b);
$rowb = mysqli_fetch_array($resb);

$pdf->SetFont('Arial','B',8);
$pdf->Cell(89 , 10, '      '.$rowb['nama_karyawan'].', '.$rowb['departement'],0,0,'c');
$pdf->Cell(60 , 5, 'SPV'.', '.$rowb['departement'],0,0,'c');
//$pdf->Cell(20 , 5,$rowi['nama_suplier'],0,1,'c');

$pdf->Cell(50 , 5, '    Manager,',0,0,'c');
$pdf->Cell(63 , 5, '    Lukito Prasetyo, 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();


?>