<?php
// memanggil library FPDF
require('../library/fpdf185/fpdf.php');

    include '../koneksi.php';


// intance object dan memberikan pengaturan halaman PDF
// asline // $pdf=new FPDF('L','mm', array(200,104));
// $pdf=new FPDF('P','mm', 'A6');

$pdf=new FPDF('P','mm','A4');
 

// asline //$pdf->SetMargins(7,8,0,0);
$pdf->SetMargins(17,17,0,0);
$pdf->AddPage();
function penyebut($nilai) {
  $nilai = abs($nilai);
  $huruf = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
  $temp = "";
  if ($nilai < 12) {
    $temp = "". $huruf[$nilai];
  } else if ($nilai <20) {
    $temp = penyebut($nilai - 10). " belas ";
  } else if ($nilai < 100) {
    $temp = penyebut($nilai/10)." puluh ". penyebut($nilai % 10);
  } else if ($nilai < 200) {
    $temp = " seratus " . penyebut($nilai - 100);
  } else if ($nilai < 1000) {
    $temp = penyebut($nilai/100) . " ratus " . penyebut($nilai % 100);
  } else if ($nilai < 2000) {
    $temp = " seribu " . penyebut($nilai - 1000);
  } else if ($nilai < 1000000) {
    $temp = penyebut($nilai/1000) . " ribu " . penyebut($nilai % 1000);
  } else if ($nilai < 1000000000) {
    $temp = penyebut($nilai/1000000) . " juta " . penyebut($nilai % 1000000);
  } else if ($nilai < 1000000000000) {
    $temp = penyebut($nilai/1000000000) . " milyar " . penyebut(fmod($nilai,1000000000));
  } else if ($nilai < 1000000000000000) {
    $temp = penyebut($nilai/1000000000000) . " trilyun " . penyebut(fmod($nilai,1000000000000));
  }     
  return $temp;
}

function terbilang($nilai) {
  if($nilai<0) {
    $hasil = "minus ". trim(penyebut($nilai));
  } else {
    $hasil = trim(penyebut($nilai));
  }         
  return $hasil . " rupiah";
}

$notrans = $_GET['notrans'];
$kar= 5 ;

$pinj_angs = mysqli_query($koneksi,"select * from pinjaman where notrans='$notrans'");
$s = mysqli_fetch_assoc($pinj_angs);
    $ajumlah    =$s['pokok'] ;
    $jml_angs   =($s['pokok']+$s['bungarp'])/$s['jkw'] ;
    $tgl_jt     ='';
    $jkw        =$s['jkw'] ;
                // date_diff adalah fungsi php dalam menghitung hari
    $tgl_jth_tmp    = date('Y-m-d', strtotime("+$jkw month", strtotime( $s['tanggal'] )));
    $tanggal_3      = date_create($tgl_jth_tmp);
                
$anggota = mysqli_query($koneksi,"select * from anggota where angg_no=$s[angg_no]");
$a = mysqli_fetch_assoc($anggota);

$karyawan = mysqli_query($koneksi,"select * from karyawan where id='$kar'");
$k = mysqli_fetch_assoc($karyawan);

$karyawan = mysqli_query($koneksi,"select * from karyawan where id='$s[kdm]'");
$aok = mysqli_fetch_assoc($karyawan);

$karyawan = mysqli_query($koneksi,"select * from karyawan where jabatan='Supervisor'");
$sup = mysqli_fetch_assoc($karyawan);

$kdkanca = mysqli_query($koneksi,"select * from kdkanca where id='1'");
$kc = mysqli_fetch_assoc($kdkanca);

$pdf->SetFont('Arial','B',15);

$pdf->Cell(120,10,'BUKTI PINJAMAN',1,0,'C');
$pdf->SetFont('Arial','',9);
$pdf->Cell(20,5,'Tanggal','TB',0,'C');
$pdf->Cell(2,5,'','TB',0,'C');
$pdf->Cell(44,5, date('d/m/Y', strtotime($s['tanggal'])) ,1,1,'');

$pdf->Cell(120,5,'' ,0,0,'C');
$pdf->Cell(20,5,'Nomor','TB',0,'C');
$pdf->Cell(2,5,'','TB',0,'C');
$pdf->Cell(44,5, 'KK - '.$s['notrans'] ,1,1,'');

$pdf->Cell(20,5,'','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(33,5,'Yg Menerima',1,0,'C');
$pdf->Cell(33,5,'Yg Menyerahkan',1,1,'C');

$pdf->Cell(20,5,'','LR',0,'C');
$pdf->Cell(30,5,'Diterima dari ',0,0,'L');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(66,5, 'Kasir '.$kc['kanca'] ,1,0,'');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(33,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',1,'C');

$pdf->Cell(20,5,'P','LR',0,'C');
$pdf->Cell(30,5,'',0,0,'C');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(66,5, $kc['alamat'] ,1,0,'');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(33,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',1,'C');

$pdf->Cell(20,5,'T','LR',0,'C');
$pdf->Cell(30,5,'Guna membayar',0,0,'L');
$pdf->Cell(2,5,'',0,0,'C');


$ket='Realisasi pinjaman kpd '.$a['nama'].', '.$a['alamat'].', '.$a['kec'].' '.$a['kab'].' No.Rekg : '.$s['norek'].' dg angsuran Rp. '.number_format($jml_angs).',- per-bln, selama '.number_format($s['jkw']).' bln, atau selambatnya s/d tgl '.date('d/m/Y', strtotime($s['tgl_jt'])).'. ';
$current_y = $pdf->GetY();
$current_x = $pdf->GetX();

$pdf->MultiCell(66,5, $ket,1);


$current_x+5;
$pdf->SetXY($current_x, $current_y);



$pdf->Cell(66,5,'',0,0,'C');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(33,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',1,'C');

$pdf->Cell(20,5,'','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',1,'C');


$pdf->Cell(20,5,'','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(33,5,$s['nama'],1,0,'C');
$pdf->Cell(33,5,$k['nama'],1,1,'C');

$pdf->Cell(20,5,'','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(66,5,'',1,1,'C');

$pdf->Cell(20,5,'S','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(33,5,'AO Kredit',1,0,'C');
$pdf->Cell(33,5,'Supervisor',1,1,'C');

$pdf->Cell(20,5,'D','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',1,'C');

$pdf->Cell(20,5,'B','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',1,'C');

$pdf->Cell(20,5,'','LR',0,'C');
$pdf->Cell(30,5,'Jumlah Uang',0,0,'L');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(66,5, "Rp.  " . number_format($ajumlah) . " ,-" ,1,0,'');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(33,5,'','LR',0,'C');
$pdf->Cell(33,5,'','LR',1,'C');

$pdf->Cell(20,5,'','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(33,5,$aok['nama'],1,0,'C');
$pdf->Cell(33,5,$sup['nama'],1,1,'C');


$pdf->Cell(20,5,'Terbilang','LTB',0,'C');
$pdf->Cell(2,5,':','TB',0,'C');
$pdf->Cell(164,5, strtoupper(terbilang($ajumlah)),'TBR',1,'');












$pdf->Output();

?>