<?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 ;

$kas = mysqli_query($koneksi,"select * from kas where notrans='$notrans'");
$k = mysqli_fetch_assoc($kas);
    $ajumlah=$k['jumlah'] ;
$tanggal = $k['tanggal']; // ambil tanggal dari kolom anggota_trans.tanggal
$bulan = array(
    '01' => 'Januari',
    '02' => 'Februari',
    '03' => 'Maret',
    '04' => 'April',
    '05' => 'Mei',
    '06' => 'Juni',
    '07' => 'Juli',
    '08' => 'Agustus',
    '09' => 'September',
    '10' => 'Oktober',
    '11' => 'November',
    '12' => 'Desember'
);
$tanggal_array = explode('-', $tanggal);
$tanggal_format = $tanggal_array[2] . ' ' . $bulan[$tanggal_array[1]] . ' ' . $tanggal_array[0];
    
$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'");
$ky = 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);

$logo_kop=$kc['gambar'] ;
$gambar='../gambar/'.$logo_kop.'';

$pdf->Image(‘foto/’ . $gambar,15,5,120);

$pdf->Cell(33,10,'','',1,'C');
$pdf->SetFont('Arial','B',15);

$pdf->Cell(120,10,'BUKTI PENERIMAAN KAS / BANK',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, $tanggal_format ,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, 'KM - '.$k['oleh'].'.'.$k['notrans'] ,1,1,'');

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

$pdf->Cell(20,5,'','LR',0,'C');
$pdf->Cell(30,5,'Diterima oleh ',0,0,'L');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(66,5, 'Takmir '.$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,' ','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,' ','LR',0,'C');
$pdf->Cell(30,5,'Guna membayar',0,0,'L');
$pdf->Cell(2,5,'',0,0,'C');


$ket=''.$k['keterangan'].'.';
$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,$k['nami'],1,0,'C');
$pdf->Cell(33,5,$kc['kasir'],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,' ','LR',0,'C');
$pdf->Cell(100,5,'','LR',0,'C');
$pdf->Cell(33,5,$kc['ttd_1'],1,0,'C');
$pdf->Cell(33,5,$kc['ttd_2'],1,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(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,'','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,$kc['nama_ttd_1'],1,0,'C');
$pdf->Cell(33,5,$kc['nama_ttd_2'],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();

?>