

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

session_start();
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(19,10,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";
}
            //////////////////////////////////////////////////////////////////////////// 
            $kdc   =$_SESSION['kdc'];
            $oleh  =$_GET['toleh'];
            //////////////////////////////////////////////////////////////////////////// 
            $oleh   =$_SESSION['id_kar'];
            $xx     = $oleh ;
            $tabel_tujuan   = "nawal_".$xx; 
            $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));
            ////////////////////////////////////////////////////////////////////////////        
            
$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,120);

$pdf->SetFont('Arial','B',12);
$pdf->Cell(10,10,' ',0,1);

$pdf->Cell(20,15,'','0',1,'C');
$pdf->Cell(200,8,'Laporan Kenaikan (Penurunan) Aset Bersih',0,1,'C');

$pdf->SetFont('Arial','I',10);
$pdf->Cell(200,5,'S/d Tanggal '.date('d-m-Y', strtotime($tgl_s)).' dan s/d tanggal '.date('d-m-Y', strtotime($tgl_lalu)).'',0,1,'C');

$pdf->SetFont('Arial','',9);
$pdf->Cell(60,4,'',0,0,'C');
$pdf->Cell(10,4,'',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',11);
$pdf->Cell(10,9,'No.',1,0,'C', true);
$pdf->Cell(100,9,'Keterangan',1,0,'C', true);
$pdf->Cell(35,9,'Per '.date('d-m-Y', strtotime($tgl_s)).' ',1,0,'C', true);
$pdf->Cell(35,9,'Per '.date('d-m-Y', strtotime($tgl_lalu)).' ',1,0,'C', true);
$pdf->Cell(5,9,'',0,1);
$pdf->SetFont('Arial','',8);
$pdf->SetTextColor(0, 0, 0); // Warna hitam

                $kd4='4';
                $sqlx = mysqli_query($koneksi, "SELECT nama FROM n_kode_1 WHERE kd1='$kd4' limit 1 ");
                list($nama) = mysqli_fetch_array($sqlx);
                
$pdf->SetFont('Arial','',10);
$pdf->Cell(10,9,'A.',1,0,'C');
$pdf->Cell(100,9,''.$nama.'',1,0,'L');
$pdf->Cell(35,9,'',1,0,'C');
$pdf->Cell(35,9,'',1,0,'C');
$pdf->Cell(5,9,'',0,1);

$no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM $tabel_tujuan WHERE nosub='411' and kt<>'X' and (awald+awalk+akhird+akhirk)<>0 order by noperk ASC ");
            while($d = mysqli_fetch_array($data)){
              $antara=$w['akhirk']-$w['awalk'];
    
  $pdf->Cell(10,7, $no++,1,0,'C');
  $pdf->Cell(100,7,$d['noperk'].' - '.$d['perk'],1,0,'L');
  $pdf->Cell(35,7,'' . number_format($d['akhirk']).'',1,0,'R'); 
  $pdf->Cell(35,7,'' . number_format($d['awalk']).'',1,0,'R');
  $pdf->Cell(5,7,'',0,1);  
}

                $sql2 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk,sum(mutasid) AS tmutd,sum(mutasik) AS tmutk,sum(akhird) AS takhird,sum(akhirk) AS takhirk FROM $tabel_tujuan WHERE kt<>'X' and nosub='411' ");
                list($awald,$awalk,$tmutd,$tmutk,$takhird,$takhirk) = mysqli_fetch_array($sql2);
                  $phu_4_ak=($takhirk);
                  $phu_4_aw=($awalk);
                  $jantara=$takhirk-$awalk;
    
$pdf->SetFillColor(220, 220, 220); // Warna abu-abu

$pdf->SetFont('Arial','B',10);
$pdf->Cell(110,7,'TOTAL '.$nama.'',1,0,'L', true);
$pdf->Cell(35,7,'' . number_format($phu_4_ak).'',1,0,'R', true);
$pdf->Cell(35,7,'' . number_format($phu_4_aw).'',1,0,'R', true);
$pdf->Cell(5,7,'',0,1);  
  
                $kd5='5';
                $sqlx = mysqli_query($koneksi, "SELECT nama FROM n_kode_1 WHERE kd1='$kd5' limit 1 ");
                list($nama) = mysqli_fetch_array($sqlx);
                
$pdf->SetFont('Arial','',10);
$pdf->Cell(10,9,'B.',1,0,'C');
$pdf->Cell(100,9,''.$nama.'',1,0,'L');
$pdf->Cell(35,9,'',1,0,'C');
$pdf->Cell(35,9,'',1,0,'C');
$pdf->Cell(5,9,'',0,1);

$no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM $tabel_tujuan WHERE nosub='511' and kt<>'X' and (awald+awalk+akhird+akhirk)<>0 order by noperk ASC ");
            while($d = mysqli_fetch_array($data)){
              
  $pdf->Cell(10,7, $no++,1,0,'C');
  $pdf->Cell(100,7,$d['noperk'].' - '.$d['perk'],1,0,'L');
  $pdf->Cell(35,7,'' . number_format($d['akhird']).'',1,0,'R'); 
  $pdf->Cell(35,7,'' . number_format($d['awald']).'',1,0,'R');
  $pdf->Cell(5,7,'',0,1);  
}
                $sql2 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk,sum(mutasid) AS tmutd,sum(mutasik) AS tmutk,sum(akhird) AS takhird,sum(akhirk) AS takhirk FROM $tabel_tujuan WHERE kt<>'X' and nosub='511' ");
                list($awald,$awalk,$tmutd,$tmutk,$takhird,$takhirk) = mysqli_fetch_array($sql2);
                  $phu_5_ak=($takhird);
                  $phu_5_aw=($awald);
    
$pdf->SetFillColor(220, 220, 220); // Warna abu-abu

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

$pdf->Cell(110,7,'TOTAL '.$nama.'',1,0,'L', true);
$pdf->Cell(35,7,'' . number_format($phu_5_ak).'',1,0,'R', true);
$pdf->Cell(35,7,'' . number_format($phu_5_aw).'',1,0,'R', true);
$pdf->Cell(5,7,'',0,1);  

                  $phu_ktr_ak=($phu_4_ak-$phu_5_ak);
                  $phu_ktr_aw=($phu_4_aw-$phu_5_aw);  
                  
$pdf->SetFillColor(220, 220, 220); // Warna abu-abu

$pdf->SetFont('Arial','B',10);
$pdf->Cell(110,7,'Kenaikan (Penurunan) Aset Bruto ',1,0,'C');
$pdf->Cell(35,7,'' . number_format($phu_ktr_ak).'',1,0,'R');
$pdf->Cell(35,7,'' . number_format($phu_ktr_aw).'',1,0,'R');
$pdf->Cell(5,7,'',0,1);  





                $kd6='6';
                $sqlx = mysqli_query($koneksi, "SELECT nama FROM n_kode_1 WHERE kd1='$kd6' limit 1 ");
                list($nama) = mysqli_fetch_array($sqlx);
                
$pdf->SetFont('Arial','',10);
$pdf->Cell(10,9,'B.',1,0,'C');
$pdf->Cell(100,9,''.$nama.'',1,0,'L');
$pdf->Cell(35,9,'',1,0,'C');
$pdf->Cell(35,9,'',1,0,'C');
$pdf->Cell(5,9,'',0,1);

$no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM $tabel_tujuan WHERE noperk>'40000' and nosub<>'511' and nosub<>'411' and kt<>'X' and (awald+awalk+akhird+akhirk)<>0 order by noperk ASC ");
            while($d = mysqli_fetch_array($data)){
              $jumlah_aw=$d[awalk]-$d[awald];
              $jumlah_ak=$d[akhirk]-$d[akhird];

$nilai=$jumlah_aw;
if ($nilai < 0) {
    $xnilai= '(' . number_format($nilai*-1).')';
} else {
    $xnilai= '' . number_format($nilai).'';
}

$nilai_a=$jumlah_ak;
if ($nilai_a < 0) {
    $xnilai_a= '(' . number_format($nilai_a*-1).')';
} else {
    $xnilai_a= '' . number_format($nilai_a).'';
}              
  $pdf->Cell(10,7, $no++,1,0,'C');
  $pdf->Cell(100,7,$d['noperk'].' - '.$d['perk'],1,0,'L');
  $pdf->Cell(35,7,''.$xnilai_a.'',1,0,'R'); 
  $pdf->Cell(35,7,''.$xnilai.'',1,0,'R'); 
  $pdf->Cell(5,7,'',0,1);  
}
                $sql2 = mysqli_query($koneksi, "SELECT sum(awalk-awald) AS tawal,sum(akhirk-akhird) AS takhir FROM $tabel_tujuan WHERE noperk>'40000' and nosub<>'511' and nosub<>'411' and kt<>'X' ");
                list($tawal,$takhir) = mysqli_fetch_array($sql2);
$nilai=$tawal;
if ($nilai < 0) {
    $xnilai= '(' . number_format($nilai*-1).')';
} else {
    $xnilai= '' . number_format($nilai).'';
}

$nilai_a=$takhir;
if ($nilai_a < 0) {
    $xnilai_a= '(' . number_format($nilai_a*-1).')';
} else {
    $xnilai_a= '' . number_format($nilai_a).'';
}                     
                
    
$pdf->SetFillColor(220, 220, 220); // Warna abu-abu

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

$pdf->Cell(110,7,'TOTAL '.$nama.'',1,0,'L', true);
$pdf->Cell(35,7,'' .$xnilai_a.'',1,0,'R', true);
$pdf->Cell(35,7,'' .$xnilai.'',1,0,'R', true);
$pdf->Cell(5,7,'',0,1);  

                $sql2a = mysqli_query($koneksi, "SELECT sum(awalk-awald) AS ttawal,sum(akhirk-akhird) AS ttakhir FROM $tabel_tujuan WHERE kt<>'X' and noperk>'40000' ");
                list($ttawal,$ttakhir) = mysqli_fetch_array($sql2a);

$nilai=$ttawal;
if ($nilai < 0) {
    $xnilai= '(' . number_format($nilai*-1).')';
} else {
    $xnilai= '' . number_format($nilai).'';
}

$nilai_a=$ttakhir;
if ($nilai_a < 0) {
    $xnilai_a= '(' . number_format($nilai_a*-1).')';
} else {
    $xnilai_a= '' . number_format($nilai_a).'';
}      

$warna=$_SESSION['warna_bag'];
$pdf->SetFillColor(240, 248, 254); // Warna abu-abu

$pdf->SetFont('Arial','B',10);
$pdf->Cell(110,7,'Kenaikan (Penurunan) Aset Bersih ',1,0,'C', true);
$pdf->Cell(35,7,'' .$xnilai_a.'',1,0,'R', true);
$pdf->Cell(35,7,'' .$xnilai.'',1,0,'R', true);
$pdf->Cell(5,7,'',0,1);  



















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(70,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(90,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(90,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();
?>