<?php
ob_start();

// 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');
$pdf = new FPDF('L', 'mm', array(215,330));
 
// asline //$pdf->SetMargins(7,8,0,0);
$pdf->SetMargins(20,15,10,10);
$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 . "";
}

 //Fungsi konversi tanggal bulan dan tahun ke dalam bahasa indonesia
 function tgl_indo($tgl){
   $tanggal = substr($tgl,8,2);
   $bulan = getBulan(substr($tgl,5,2));
   $tahun = substr($tgl,0,4);
   return $tanggal.' '.$bulan.' '.$tahun;  
 } 
 //Fungsi konversi nama bulan ke dalam bahasa indonesia
 function getBulan($bln){
    switch ($bln){
     case 1:
      return "Januari";
      break;
     case 2:
      return "Februari";
      break;
     case 3:
      return "Maret";
      break;
     case 4:
      return "April";
      break;
     case 5:
      return "Mei";
      break;
     case 6:
      return "Juni";
      break;
     case 7:
      return "Juli";
      break;
     case 8:
      return "Agustus";
      break;
     case 9:
      return "September";
      break;
     case 10:
      return "Oktober";
      break;
     case 11:
      return "November";
      break;
     case 12:
      return "Desember";
      break;
    }
   }
   
$daftar_hari = array(
 'Sunday' => 'Minggu',
 'Monday' => 'Senin',
 'Tuesday' => 'Selasa',
 'Wednesday' => 'Rabu',
 'Thursday' => 'Kamis',
 'Friday' => 'Jumat',
 'Saturday' => 'Sabtu'
);

            //////////////////////////////////////////////////////////////////////////// 
        $kdc   =$_SESSION['kdc'];    
        $oleh = $_GET['toleh'];
        $tabel_tujuan = "nawal_".$oleh;
        $tabel_asal = "nawal";

        $tgl_d = $_GET['xtgl_d'];
        $tgl_s = $_GET['xtgl_s'];

        $tgl_ke_1 = date('2025-01-01');
        $tgl_p = strtotime("$tgl_d");
        $tgl_lalu = date('Y-m-d', strtotime("-1 day", $tgl_p));

        $kanca = $_SESSION['kanca'];
        $now = date('Y-m-d H:i:s');
            //////////////////////////////////////////////////////////////////////////// 

            //////////////////////////////////////////////////////////////////////////// 
$kdkanca = mysqli_query($koneksi,"select * from kdkanca where kd='$kdc'");
$kc = mysqli_fetch_assoc($kdkanca);
$logo_kop=$kc['gambar'] ;

$gambar='../gambar/'.$logo_kop.'';

$pdf->Image(‘foto/’ . $gambar,20,10,90);

//$pdf->Image($gambar, 20, 5, 90, 20); // atur ukuran dan posisi gambar secara manual

$pdf->SetFont('Times','B',15);
$pdf->Cell(10,20,' ',0,1);

$pdf->Cell(10,12,'','0',1,'C');
$pdf->Cell(290,8,'LAPORAN PERUBAHAN EKUITAS',0,1,'C');

$pdf->SetFont('Arial','B',12);
$pdf->Cell(290,5,'Antara Tgl : '.date('d-m-Y', strtotime($tgl_d)).' s/d '.date('d-m-Y', strtotime($tgl_s)).'',0,0,'C');
$pdf->Cell(2,5,'',0,0,'C');
$pdf->Cell(10,5,'',0,1);

// Atur warna latar belakang sel
$pdf->SetFillColor(220, 220, 220); // Warna abu-abu

// Atur warna teks
$pdf->SetTextColor(0, 0, 0); // Warna hitam

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

// Baris pertama
$pdf->Cell(80, 20, 'Keterangan', 1, 0, 'C', true);
$pdf->Cell(60, 10, 'Modal', 1, 0, 'C', true);
$pdf->Cell(60, 10, 'Cadangan', 1, 0, 'C', true);
$pdf->Cell(30, 20, 'Ekuitas Lain', 1, 0, 'C', true);
$pdf->Cell(30, 20, 'SHU', 1, 0, 'C', true);
$pdf->Cell(30, 20, 'TOTAL', 1, 0, 'C', true);
$pdf->Ln(10);

// Baris kedua
$pdf->Cell(80, 10, '', 0, 0, 'C');
$pdf->Cell(30, 10, 'Simp Pokok', 1, 0, 'C', true);
$pdf->Cell(30, 10, 'Simp Wajib', 1, 0, 'C', true);
$pdf->Cell(30, 10, 'Umum', 1, 0, 'C', true);
$pdf->Cell(30, 10, 'Resiko', 1, 0, 'C', true);
$pdf->Ln();

$pdf->SetFont('Arial','',10);
$pdf->SetTextColor(0, 0, 0); // Warna hitam

                $sqlxp = mysqli_query($koneksi, "SELECT sum(awalk) AS so_awal_pokok FROM $tabel_tujuan WHERE noperk='31101' limit 1 ");
                list($so_awal_pokok) = mysqli_fetch_array($sqlxp);
                $sqlxw = mysqli_query($koneksi, "SELECT sum(awalk) AS so_awal_wajib FROM $tabel_tujuan WHERE noperk='31102' limit 1 ");
                list($so_awal_wajib) = mysqli_fetch_array($sqlxw);
                $sqlxc1 = mysqli_query($koneksi, "SELECT sum(awalk) AS so_awal_c1 FROM $tabel_tujuan WHERE noperk='31201' limit 1 ");
                list($so_awal_c1) = mysqli_fetch_array($sqlxc1);
                $sqlxc2 = mysqli_query($koneksi, "SELECT sum(awalk) AS so_awal_c2 FROM $tabel_tujuan WHERE noperk='31202' limit 1 ");
                list($so_awal_c2) = mysqli_fetch_array($sqlxc2);
                $sqlxel = mysqli_query($koneksi, "SELECT sum(awalk) AS so_awal_el FROM $tabel_tujuan WHERE noperk='31103' limit 1 ");
                list($so_awal_el) = mysqli_fetch_array($sqlxel);
                $sqlxel2 = mysqli_query($koneksi, "SELECT sum(awalk) AS so_awal_el2 FROM $tabel_tujuan WHERE noperk='32101' limit 1 ");
                list($so_awal_el2) = mysqli_fetch_array($sqlxel2);
                	$so_awal_elain=$so_awal_el+$so_awal_el2 ;
                $sqlxshu = mysqli_query($koneksi, "SELECT sum(awalk) AS so_awal_shu FROM $tabel_tujuan WHERE noperk>='33101' and noperk<='39101'");
                list($so_awal_shu) = mysqli_fetch_array($sqlxshu);
                $total_awal=$so_awal_pokok+$so_awal_wajib+$so_awal_c1+$so_awal_c2+$so_awal_el+$so_awal_shu ;

$pdf->SetFont('Arial','',12);
$pdf->Cell(80, 10, '1. Saldo Awal Per : '.date('d-m-Y', strtotime($tgl_d)).'', 1, 0, 'L');
$pdf->Cell(30, 10, '' . number_format($so_awal_pokok).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_awal_wajib).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_awal_c1).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_awal_c2).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_awal_elain).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_awal_shu).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($total_awal).'', 1, 0, 'R');
$pdf->Ln();

                $sqlxp = mysqli_query($koneksi, "SELECT sum(mutasik) AS so_mt_pokok FROM $tabel_tujuan WHERE noperk='31101' limit 1 ");
                list($so_mt_pokok) = mysqli_fetch_array($sqlxp);
                $sqlxw = mysqli_query($koneksi, "SELECT sum(mutasik) AS so_mt_wajib FROM $tabel_tujuan WHERE noperk='31102' limit 1 ");
                list($so_mt_wajib) = mysqli_fetch_array($sqlxw);
                $sqlxc1 = mysqli_query($koneksi, "SELECT sum(mutasik) AS so_mt_c1 FROM $tabel_tujuan WHERE noperk='31201' limit 1 ");
                list($so_mt_c1) = mysqli_fetch_array($sqlxc1);
                $sqlxc2 = mysqli_query($koneksi, "SELECT sum(mutasik) AS so_mt_c2 FROM $tabel_tujuan WHERE noperk='31202' limit 1 ");
                list($so_mt_c2) = mysqli_fetch_array($sqlxc2);
                $sqlxel = mysqli_query($koneksi, "SELECT sum(mutasik) AS so_mt_el FROM $tabel_tujuan WHERE noperk='31103' limit 1 ");
                list($so_mt_el) = mysqli_fetch_array($sqlxel);
                $sqlxel2 = mysqli_query($koneksi, "SELECT sum(mutasik) AS so_mt_el2 FROM $tabel_tujuan WHERE noperk='32101' limit 1 ");
                list($so_mt_el2) = mysqli_fetch_array($sqlxel2);
                	$so_mt_elain=$so_mt_el+$so_mt_el2 ;
                $sqlxshu = mysqli_query($koneksi, "SELECT sum(mutasik) AS so_mt_shu FROM $tabel_tujuan WHERE noperk>='33101' and noperk<='39101'");
                list($so_mt_shu) = mysqli_fetch_array($sqlxshu);
                $total_mt=$so_mt_pokok+$so_mt_wajib+$so_mt_c1+$so_mt_c2+$so_mt_el+$so_mt_shu ;

$pdf->Cell(80, 10, '2. P e n a m b a h a n', 1, 0, 'L');
$pdf->Cell(30, 10, '' . number_format($so_mt_pokok).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mt_wajib).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mt_c1).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mt_c2).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mt_elain).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mt_shu).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($total_mt).'', 1, 0, 'R');
$pdf->Ln();

                $so_jm_pokok=$so_awal_pokok+$so_mt_pokok;
                $so_jm_wajib=$so_awal_wajib+$so_mt_wajib;
                $so_jm_c1=$so_awal_c1+$so_mt_c1;
                $so_jm_c2=$so_awal_c2+$so_mt_c2;
                $so_jm_elain=$so_awal_elain+$so_mt_elain;
                $so_jm_shu=$so_awal_shu+$so_mt_shu;
                $total_jm=$total_awal+$total_mt ;

$pdf->SetFont('Arial','BI',12);
$pdf->Cell(80, 10, 'J u m l a h ', 1, 0, 'C');
$pdf->Cell(30, 10, '' . number_format($so_jm_pokok).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_jm_wajib).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_jm_c1).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_jm_c2).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_jm_elain).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_jm_shu).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($total_jm).'', 1, 0, 'R');
$pdf->Ln();

                $sqlxp = mysqli_query($koneksi, "SELECT sum(mutasid) AS so_mk_pokok FROM $tabel_tujuan WHERE noperk='31101' limit 1 ");
                list($so_mk_pokok) = mysqli_fetch_array($sqlxp);
                $sqlxw = mysqli_query($koneksi, "SELECT sum(mutasid) AS so_mk_wajib FROM $tabel_tujuan WHERE noperk='31102' limit 1 ");
                list($so_mk_wajib) = mysqli_fetch_array($sqlxw);
                $sqlxc1 = mysqli_query($koneksi, "SELECT sum(mutasid) AS so_mk_c1 FROM $tabel_tujuan WHERE noperk='31201' limit 1 ");
                list($so_mk_c1) = mysqli_fetch_array($sqlxc1);
                $sqlxc2 = mysqli_query($koneksi, "SELECT sum(mutasid) AS so_mk_c2 FROM $tabel_tujuan WHERE noperk='31202' limit 1 ");
                list($so_mk_c2) = mysqli_fetch_array($sqlxc2);
                $sqlxel = mysqli_query($koneksi, "SELECT sum(mutasid) AS so_mk_el FROM $tabel_tujuan WHERE noperk='31103' limit 1 ");
                list($so_mk_el) = mysqli_fetch_array($sqlxel);
                $sqlxel2 = mysqli_query($koneksi, "SELECT sum(mutasid) AS so_mk_el2 FROM $tabel_tujuan WHERE noperk='32101' limit 1 ");
                list($so_mk_el2) = mysqli_fetch_array($sqlxel2);
                	$so_mk_elain=$so_mk_el+$so_mk_el2 ;
                $sqlxshu = mysqli_query($koneksi, "SELECT sum(mutasid) AS so_mt_shu FROM $tabel_tujuan WHERE noperk>='32101' and noperk<='32901' limit 1 ");
                list($so_mt_shu) = mysqli_fetch_array($sqlxshu);
                $total_mk=$so_mk_pokok+$so_mk_wajib+$so_mk_c1+$so_mk_c2+$so_mk_el+$so_mk_shu ;

$pdf->SetFont('Arial','',12);
$pdf->Cell(80, 10, '3. P e n g u r a n g a n ', 1, 0, 'L');
$pdf->Cell(30, 10, '' . number_format($so_mk_pokok).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mk_wajib).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mk_c1).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mk_c2).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mk_elain).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_mk_shu).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($total_mk).'', 1, 0, 'R');
$pdf->Ln();

                $so_ak_pokok=$so_jm_pokok-$so_mk_pokok;
                $so_ak_wajib=$so_jm_wajib-$so_mk_wajib;
                $so_ak_c1=$so_jm_c1-$so_mk_c1;
                $so_jm_c2-$so_mk_c2;
                $so_ak_elain=$so_jm_elain-$so_mk_elain;
                $so_ak_shu=$so_jm_shu-$so_mk_shu;
                $total_ak=$total_jm-$total_mk ;

$pdf->SetFont('Arial','BI',12);
$pdf->Cell(80, 10, '4. Saldo Akhir Per : '.date('d-m-Y', strtotime($tgl_s)).'', 1, 0, 'L');
$pdf->Cell(30, 10, '' . number_format($so_ak_pokok).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_ak_wajib).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_ak_c1).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_ak_c2).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_ak_elain).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($so_ak_shu).'', 1, 0, 'R');
$pdf->Cell(30, 10, '' . number_format($total_ak).'', 1, 0, 'R');
$pdf->Ln();


































date_default_timezone_set('Asia/Jakarta');

$bulan = array(
  1 => 'Januari',
  'Februari',
  'Maret',
  'April',
  'Mei',
  'Juni',
  'Juli',
  'Agustus',
  'September',
  'Oktober',
  'November',
  'Desember'
);

$tgl = date('d');
$bln = date('n');
$thn = date('Y');
//echo $tgl . ' ' . $bulan[$bln] . ' ' . $thn;

$pdf->SetFont('Arial','',9);
$pdf->Cell(60,3,'',0,0,'C');
$pdf->Cell(10,3,'',0,1);  

$pdf->Cell(170,5,'',0,0,'C');
$pdf->Cell(80,5,''.$kc['kota'].',  '.$tgl . ' ' . $bulan[$bln] . ' ' . $thn.'',0,0,'R');
$pdf->Cell(27,5,'',0,0,'C');
$pdf->Cell(10,5,'',0,1);  

$pdf->Cell(190,5,'',0,0,'C');
$pdf->Cell(40,5,$kc['ttd_1'],0,0,'C');
$pdf->Cell(40,5,$kc['ttd_2'],0,0,'C');
$pdf->Cell(27,5,'',0,1,'C');

$pdf->Cell(60,17,'',0,0,'C');
$pdf->Cell(10,17,'',0,1);  

$pdf->Cell(190,5,'',0,0,'C');
$pdf->Cell(40,5,$kc['nama_ttd_1'],0,0,'C');
$pdf->Cell(40,5,$kc['nama_ttd_2'],0,0,'C');
$pdf->Cell(27,5,'',0,1,'C');

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="dokumen.pdf"');
$pdf->Output();
?>