<?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('P', '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";
            //////////////////////////////////////////////////////////////////////////// 
                $sql0 = mysqli_query($koneksi, "SELECT tgl_htg,tgl_sd FROM $tabel_tujuan WHERE mutasid>=1 limit 1 ");
                list($tgl_htg,$tgl_sd) = mysqli_fetch_array($sql0);            
              $tgl_d    = $tgl_htg;
              $tgl_s    = $tgl_sd;
              
              $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,105);

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

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

$pdf->Cell(10,12,'','0',1,'C');
$pdf->Cell(180,8,'PROFIL KOPERASI',0,1,'C');

$pdf->SetFont('Arial','B',12);
//$pdf->Cell(180,5,'Dari Tgl : '.date('d-m-Y', strtotime($tgl_s)).' s/d '.date('d-m-Y', strtotime($tgl_d)).'',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',11);
$pdf->Cell(180,9,'A. Identitas Koperasi :',1,0,'L', true);
$pdf->Cell(5,9,'',0,1);

            $no=1;
            $nol=0;
            //
            $data = mysqli_query($koneksi,"SELECT * FROM n_profil WHERE kd>'10' and kd<'20' order by kd ASC ");
            while($p = mysqli_fetch_array($data)){
            	$kdp=$p['kd'];
				$sql_11 = mysqli_query($koneksi, "SELECT kota AS p_kota FROM kdkanca WHERE kd='$kdc' ");
                	list($p_kota) = mysqli_fetch_array($sql_11);
				$sql_12 = mysqli_query($koneksi, "SELECT kanca AS p_kanca,nama_singkat AS p_nama_singkat FROM kdkanca WHERE kd='$kdc' ");
                	list($p_kanca,$p_nama_singkat) = mysqli_fetch_array($sql_12);
				$sql_13 = mysqli_query($koneksi, "SELECT no_bh AS p_no_bh FROM kdkanca WHERE kd='$kdc' ");
                	list($p_no_bh) = mysqli_fetch_array($sql_13);  
                $sql_14 = mysqli_query($koneksi, "SELECT no_nik AS p_no_nik,npwp AS no_npwp FROM kdkanca WHERE kd='$kdc' ");
                	list($p_no_nik,$no_npwp) = mysqli_fetch_array($sql_14);
                $sql_16 = mysqli_query($koneksi, "SELECT no_nib AS p_no_nib FROM kdkanca WHERE kd='$kdc' ");
                	list($p_no_nib) = mysqli_fetch_array($sql_16);                	
                $sql_15 = mysqli_query($koneksi, "SELECT alamat,kelurahan,kecamatan,kota FROM kdkanca WHERE kd='$kdc' ");
                	list($alamat,$kelurahan,$kecamatan,$kota) = mysqli_fetch_array($sql_15);                	
                	
                	if ($kdp=='11')	{
                		$jawab=$p_kota;	
                	} else if ($kdp=='12') {
                		$jawab=''.$p_kanca.' ('.$p_nama_singkat.')';
                	} else if ($kdp=='13') {
                		$jawab=$p_no_bh;
                	} else if ($kdp=='14') {
                		$jawab=$p_no_nik;
                	} else if ($kdp=='15') {
                		$jawab=$p_no_nib; 
                	} else if ($kdp=='151') {
                		$jawab=$no_npwp;                 		
                	} else if ($kdp=='16') {
                		$jawab=$alamat ;
                	} else if ($kdp=='17') {
                		$jawab=$kelurahan ;
                	} else if ($kdp=='18') {
                		$jawab=$kecamatan ;                		
                	} else {
                		$jawab='' ;
                	}                	
                	
$pdf->SetFont('Arial','',10);
$pdf->Cell(10,7,$no++,1,0,'C');
$pdf->Cell(45,7,$p['nama'],1,0,'L');
$pdf->SetFont('Arial','B',11);
$pdf->Cell(125,7,$jawab,1,0,'L');
$pdf->Cell(5,7,'',0,1);
}


$pdf->SetFont('Arial','B',11);
$pdf->Cell(180,9,'B. Keanggotaan :',1,0,'L', true);
$pdf->Cell(5,9,'',0,1);

            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM n_profil WHERE kd>'20' and kd<'30' order by kd ASC ");
            while($p = mysqli_fetch_array($data)){
            	$kdp=$p['kd'];
				$sql_11 = mysqli_query($koneksi, "SELECT count(angg_no) AS p_jangg_no FROM anggota WHERE hapus<>'HAPUS' ");
                	list($p_jangg_no) = mysqli_fetch_array($sql_11);

                $sql_21 = mysqli_query($koneksi, "SELECT COUNT(DISTINCT a.angg_no) AS jumlah_anggota_aktif 
                                                  FROM anggota a 
                                                  WHERE a.angg_no IN (SELECT kd FROM brg_mts_r) 
                                                  OR a.angg_no IN (SELECT angg_no FROM pinjaman)");
                list($jumlah_anggota_aktif) = mysqli_fetch_array($sql_21);

				$sql_10 = mysqli_query($koneksi, "SELECT sp AS k_sp FROM kdkanca WHERE kd='$kdc' ");
                	list($k_sp) = mysqli_fetch_array($sql_10);   
                	
				$sql_14 = mysqli_query($koneksi, "SELECT sum(awalk) AS tpk_awal,sum(mutasik) AS tpk_masuk,sum(mutasid) AS tpk_keluar,sum(akhirk) AS tpk_akhir FROM $tabel_tujuan WHERE noperk='31101' ");
                	list($tpk_awal) = mysqli_fetch_array($sql_14);  
                	$or_tpk_awal=$tpk_awal/$k_sp ;
                	
$sql_22 = mysqli_query($koneksi, "
  SELECT 
    COUNT(CASE WHEN total_setor >= sp_besar THEN angg_no END) AS sudah_lunas,
    COUNT(CASE WHEN total_setor < sp_besar AND total_setor > 0 THEN angg_no END) AS belum_lunas,
    COUNT(CASE WHEN total_setor = 0 THEN angg_no END) AS belum_bayar
  FROM (
    SELECT 
      a.angg_no,
      COALESCE(SUM(ast.setor) - SUM(ast.tarik), 0) AS total_setor,
      k.sp AS sp_besar
    FROM 
      anggota a
    LEFT JOIN 
      angg_simp_trans ast ON a.angg_no = ast.angg_no AND ast.kdj = '01'
    CROSS JOIN 
      (SELECT sp FROM kdkanca WHERE kd = '$kdc') k
    WHERE 
      a.hapus <> 'HAPUS'
    GROUP BY 
      a.angg_no, k.sp
  ) subquery
");
list($sudah_lunas, $belum_lunas, $belum_bayar) = mysqli_fetch_array($sql_22);

            $sql_41 = mysqli_query($koneksi, "
              SELECT COUNT(DISTINCT a.angg_no) AS p_jangg_no_w
              FROM anggota a
              JOIN (
                SELECT angg_no, SUM(setor) - SUM(tarik) AS saldo
                FROM angg_simp_trans WHERE kdj='02'
                GROUP BY angg_no
                HAVING SUM(setor) - SUM(tarik) > 1
              ) b ON a.angg_no = b.angg_no
              WHERE a.hapus <> 'HAPUS'
            ");
            list($p_jangg_no_w) = mysqli_fetch_array($sql_41);
            $belum_bayar_sw=$p_jangg_no-$p_jangg_no_w ;

				$sql_20 = mysqli_query($koneksi, "SELECT count(angg_no) AS j_jekel_laki FROM anggota WHERE jekel='1' and hapus<>'HAPUS' ");
                	list($j_jekel_laki) = mysqli_fetch_array($sql_20);
				$sql_21 = mysqli_query($koneksi, "SELECT count(angg_no) AS j_jekel_wnt FROM anggota WHERE jekel<>'1' and hapus<>'HAPUS' ");
                	list($j_jekel_wnt) = mysqli_fetch_array($sql_21);                	
                	
                	if ($kdp=='21')	{
                		$jawab=''.$p_jangg_no.' orang' ;	
                	} else if ($kdp=='22') {
                		$jawab=''.$jumlah_anggota_aktif.' orang';
                	} else if ($kdp=='23') {
                		$jawab=''.$sudah_lunas.' org' ;
                	} else if ($kdp=='24') {
                		$jawab=''.$belum_lunas.' org' ;
                	} else if ($kdp=='25') {
                		$jawab=''.$belum_bayar.' org' ; 
                	} else if ($kdp=='26') {
                		$jawab=''.$p_jangg_no_w.' org' ;
                	} else if ($kdp=='27') {
                		$jawab='Laki-Laki : '.$j_jekel_laki.' org & Perempuan : '.$j_jekel_wnt.' org' ;	
                	} else {
                		$jawab='' ;
                	}                	
                	
$pdf->SetFont('Arial','',10);
$pdf->Cell(10,6,$no++,1,0,'C');
$pdf->Cell(45,6,$p['nama'],1,0,'L');
$pdf->Cell(125,6,$jawab,1,0,'L');
$pdf->Cell(5,6,'',0,1);
}



$pdf->SetFont('Arial','B',11);
$pdf->Cell(180,9,'C. Struktur Organisasi :',1,0,'L', true);
$pdf->Cell(5,9,'',0,1);

$pdf->SetFont('Arial','B',11);
$pdf->Cell(10,6,'a).',1,0,'C');
$pdf->Cell(45,6,'P E N G U R U S  :',1,0,'L');
$pdf->Cell(125,6,'',1,0,'L');
$pdf->Cell(5,6,'',0,1);

$no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM n_profil WHERE kd>'30' and kd<'40' order by kd ASC ");
            while($p = mysqli_fetch_array($data)){
                $kdp=$p['kd'];
				$sql_k01 = mysqli_query($koneksi, "SELECT angg_no AS t_angg_01 FROM karyawan WHERE jabatan='01' ");
                	list($t_angg_01) = mysqli_fetch_array($sql_k01);                
				$sql_a01 = mysqli_query($koneksi, "SELECT nama AS nama_01 FROM anggota WHERE angg_no='$t_angg_01' ");
                	list($nama_01) = mysqli_fetch_array($sql_a01);
				$sql_k04 = mysqli_query($koneksi, "SELECT angg_no AS t_angg_04 FROM karyawan WHERE jabatan='04' ");
                	list($t_angg_04) = mysqli_fetch_array($sql_k04);                
				$sql_a04 = mysqli_query($koneksi, "SELECT nama AS nama_04 FROM anggota WHERE angg_no='$t_angg_04' ");
                	list($nama_04) = mysqli_fetch_array($sql_a04);
				$sql_k07 = mysqli_query($koneksi, "SELECT angg_no AS t_angg_07 FROM karyawan WHERE jabatan='07' ");
                	list($t_angg_07) = mysqli_fetch_array($sql_k07);                
				$sql_a07 = mysqli_query($koneksi, "SELECT nama AS nama_04 FROM anggota WHERE angg_no='$t_angg_07' ");
                	list($nama_07) = mysqli_fetch_array($sql_a07);
                	
                	if ($kdp=='31')	{
                		$jawab=$nama_01 ;	
                	} else if ($kdp=='32') {
                		$jawab=$nama_04 ;
                	} else if ($kdp=='33') {
                		$jawab=$nama_07 ;
                	} else {
                		$jawab='' ;
                	}                     	
                	
$pdf->SetFont('Arial','',10);
$pdf->Cell(10,6,$no++,1,0,'C');
$pdf->Cell(45,6,$p['nama'],1,0,'L');
$pdf->Cell(125,6,$jawab,1,0,'L');
$pdf->Cell(5,6,'',0,1);
}

$pdf->SetFont('Arial','B',11);
$pdf->Cell(10,6,'b).',1,0,'C');
$pdf->Cell(45,6,'P E N G A W A S  :',1,0,'L');
$pdf->Cell(125,6,'',1,0,'L');
$pdf->Cell(5,6,'',0,1);

            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM n_profil WHERE kd>'40' and kd<'50' order by kd ASC ");
            while($p = mysqli_fetch_array($data)){
                $kdp=$p['kd'];
				$sql_k10 = mysqli_query($koneksi, "SELECT angg_no AS t_angg_10 FROM karyawan WHERE jabatan='10' ");
                	list($t_angg_10) = mysqli_fetch_array($sql_k10);                
				$sql_a10 = mysqli_query($koneksi, "SELECT nama AS nama_10 FROM anggota WHERE angg_no='$t_angg_10' ");
                	list($nama_10) = mysqli_fetch_array($sql_a10);
				$sql_k11 = mysqli_query($koneksi, "SELECT angg_no AS t_angg_11 FROM karyawan WHERE jabatan='11' ");
                	list($t_angg_11) = mysqli_fetch_array($sql_k11);                
				$sql_a11 = mysqli_query($koneksi, "SELECT nama AS nama_11 FROM anggota WHERE angg_no='$t_angg_11' ");
                	list($nama_11) = mysqli_fetch_array($sql_a11);
				$sql_k12 = mysqli_query($koneksi, "SELECT angg_no AS t_angg_12 FROM karyawan WHERE jabatan='12' ");
                	list($t_angg_12) = mysqli_fetch_array($sql_k12);                
				$sql_a12 = mysqli_query($koneksi, "SELECT nama AS nama_12 FROM anggota WHERE angg_no='$t_angg_12' ");
                	list($nama_12) = mysqli_fetch_array($sql_a12);                	
                	
                	if ($kdp=='41')	{
                		$jawab=$nama_10 ;	
                	} else if ($kdp=='42') {
                		$jawab=$nama_11 ;
                	} else if ($kdp=='43') {
                		$jawab=$nama_12 ;
                	} else {
                		$jawab='' ;
                	}                
                	
$pdf->SetFont('Arial','',10);
$pdf->Cell(10,6,$no++,1,0,'C');
$pdf->Cell(45,6,$p['nama'],1,0,'L');
$pdf->Cell(125,6,$jawab,1,0,'L');
$pdf->Cell(5,6,'',0,1);
}

$pdf->SetFont('Arial','B',11);
$pdf->Cell(10,6,'c).',1,0,'C');
$pdf->Cell(45,6,'P E N G E L O L A  :',1,0,'L');
$pdf->Cell(125,6,'',1,0,'L');
$pdf->Cell(5,6,'',0,1);

            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM n_profil WHERE kd>'50' and kd<'60' order by kd ASC ");
            while($p = mysqli_fetch_array($data)){
                $kdp=$p['kd'];
				$sql_k50 = mysqli_query($koneksi, "SELECT nama AS t_nama_manager FROM karyawan WHERE jabatan='Manager' ");
                	list($t_nama_manager) = mysqli_fetch_array($sql_k50);      
				$sql_k10 = mysqli_query($koneksi, "SELECT count(nama) AS j_nama_kar FROM karyawan WHERE ket<>'PP' and jabatan<>'Manager'");
                	list($j_nama_kar) = mysqli_fetch_array($sql_k10);
                	
                	if ($kdp=='51')	{
                		$jawab=$t_nama_manager ;	
                	} else if ($kdp=='52') {
                		$jawab=''.$j_nama_kar.' org Karyawan' ;
                	} else {
                		$jawab='' ;
                	}           
                	
$pdf->SetFont('Arial','',10);
$pdf->Cell(10,6,$no++,1,0,'C');
$pdf->Cell(45,6,$p['nama'],1,0,'L');
$pdf->Cell(125,6,$jawab,1,0,'L');
$pdf->Cell(5,6,'',0,1);
}


$pdf->SetFont('Arial','B',11);
$pdf->Cell(180,9,'D. Kegiatan Usaha :',1,0,'L', true);
$pdf->Cell(5,9,'',0,1);

            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM n_profil WHERE kd>'60' and kd<'70' order by kd ASC ");
            while($p = mysqli_fetch_array($data)){
                $kdp=$p['kd'];
				$sql_k02 = mysqli_query($koneksi, "SELECT keterangan AS t_ket_02 FROM kd_unit WHERE kd='02' ");
                	list($t_ket_02) = mysqli_fetch_array($sql_k02);                
				$sql_k03 = mysqli_query($koneksi, "SELECT keterangan AS t_ket_03 FROM kd_unit WHERE kd='03' ");
                	list($t_ket_03) = mysqli_fetch_array($sql_k03);
				$sql_k04 = mysqli_query($koneksi, "SELECT keterangan AS t_ket_04 FROM kd_unit WHERE kd='04' ");
                	list($t_ket_04) = mysqli_fetch_array($sql_k04);
                	
                	if ($kdp=='61')	{
                		$jawab=$t_ket_02 ;	
                	} else if ($kdp=='62') {
                		$jawab=$t_ket_03 ;	
                	} else if ($kdp=='63') {
                		$jawab=$t_ket_04 ;	
                	} else {
                		$jawab='' ;
                	}                

$pdf->SetFont('Arial','',10);
$pdf->Cell(10,5,$no++,1,0,'C');
$pdf->Cell(45,5,$p['nama'],1,0,'L');
$pdf->MultiCell(125,5,$jawab,1,'L');
$pdf->Ln(); // untuk membuat baris baru
}

$pdf->SetFont('Arial','B',11);
$pdf->Cell(180,9,'E. Keuangan Perusahaan :',1,0,'L', true);
$pdf->Cell(5,9,'',0,1);

            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM n_profil WHERE kd>'70' and kd<'75' order by kd ASC ");
            while($p = mysqli_fetch_array($data)){
                $kdp=$p['kd'];

                	if ($kdp=='71')	{
                		$jawab='Ada - terlampir' ;	
                	} else if ($kdp=='72') {
                		$jawab='Ada - terlampir' ;	
                	} else if ($kdp=='73') {
                		$jawab='Ada - terlampir' ;	
                	} else if ($kdp=='74') {
                		$jawab='Ada - terlampir' ;
                	} else {
                		$jawab='' ;
                	}                        

$pdf->SetFont('Arial','',10);
$pdf->Cell(10,6,$no++,1,0,'C');
$pdf->Cell(55,6,$p['nama'],1,0,'L');
$pdf->Cell(115,6,$jawab,1,0,'L');
$pdf->Cell(5,6,'',0,1);
}

$pdf->Cell(10,6,'',1,0,'C');
$pdf->Cell(55,6,'Keterangan',1,0,'C', true);
$pdf->Cell(55,6,''.date('d-m-Y', strtotime($tgl_s)).'',1,0,'C', true);
$pdf->Cell(60,6,''.date('d-m-Y', strtotime($tgl_d)).'',1,0,'C', true);
$pdf->Cell(5,6,'',0,1);

            $data = mysqli_query($koneksi,"SELECT * FROM n_profil WHERE kd>='75' and kd<'90' order by kd ASC ");
            while($p = mysqli_fetch_array($data)){
                $kdp=$p['kd'];
				$sql_74 = mysqli_query($koneksi, "SELECT sum(awald) AS tas_awal,sum(akhird) AS tas_akhir FROM $tabel_tujuan WHERE noperk<'20000' ");
                	list($tas_awal,$tas_akhir) = mysqli_fetch_array($sql_74);  
				$sql_75 = mysqli_query($koneksi, "SELECT sum(awalk) AS tmds_awal,sum(akhirk) AS tmds_akhir FROM $tabel_tujuan WHERE left(noperk,1)='3' and ry<>'xx' ");
                	list($tmds_awal,$tmds_akhir) = mysqli_fetch_array($sql_75); 
				$sql_76 = mysqli_query($koneksi, "SELECT sum(awalk) AS thtg_awal,sum(akhirk) AS thtg_akhir FROM $tabel_tujuan WHERE left(noperk,1)='2' and ry<>'xx' ");
                	list($thtg_awal,$thtg_akhir) = mysqli_fetch_array($sql_76); 
				$sql_77 = mysqli_query($koneksi, "SELECT sum(awalk) AS tshu_awal,sum(akhirk) AS tshu_akhir FROM $tabel_tujuan WHERE left(noperk,1)='3' and ry='xx' ");
                	list($tshu_awal,$tshu_akhir) = mysqli_fetch_array($sql_77);                 	
				$sql_78 = mysqli_query($koneksi, "SELECT sum(awalk) AS toms_awal,sum(akhirk) AS toms_akhir FROM $tabel_tujuan WHERE left(noperk,1)='4' ");
                	list($toms_awal,$toms_akhir) = mysqli_fetch_array($sql_78);      
                	
                	if ($kdp=='75')	{
                		$jawab_a="Rp. " . number_format("$tas_akhir", 0, ",", ".") ;
                		$jawab_b="Rp. " . number_format("$tas_awal", 0, ",", ".") ;
                	} else if ($kdp=='76') {
                		$jawab_a="Rp. " . number_format("$tmds_akhir", 0, ",", ".") ;
                		$jawab_b="Rp. " . number_format("$tmds_awal", 0, ",", ".") ;
                	} else if ($kdp=='77') {
                		$jawab_a="Rp. " . number_format("$thtg_akhir", 0, ",", ".") ;
                		$jawab_b="Rp. " . number_format("$thtg_awal", 0, ",", ".") ;
                	} else if ($kdp=='78') {
                        $jawab_a="Rp. " . number_format("$tshu_akhir", 0, ",", ".") ;
                		$jawab_b="Rp. " . number_format("$tshu_awal", 0, ",", ".") ;
                	} else if ($kdp=='79') {
                        $jawab_a="Rp. " . number_format("$toms_akhir", 0, ",", ".") ;
                		$jawab_b="Rp. " . number_format("$toms_awal", 0, ",", ".") ;
                	} else {
                		$jawab_a='' ;
                		$jawab_b='' ;
                	}                        

$pdf->SetFont('Arial','',10);
$pdf->Cell(10,6,$no++,1,0,'C');
$pdf->Cell(55,6,$p['nama'],1,0,'L');
$pdf->Cell(55,6,$jawab_a,1,0,'L');
$pdf->Cell(60,6,$jawab_b,1,0,'L');
$pdf->Cell(5,6,'',0,1);
}

$pdf->SetFont('Arial','B',11);
$pdf->Cell(180,9,'F. Keterangan Tambahan :',1,0,'L', true);
$pdf->Cell(5,9,'',0,1);

$pdf->SetFont('Arial','',10);
$pdf->Cell(180,6,'Sementara jalan baik dan lancar.',1,0,'L');
$pdf->Cell(5,10,'',0,1);

$ket2='Demikian profil dan laporan '.trim($kc['kanca']).', Kecamatan '.trim($kc['kecamatan']).', Kabupaten '.trim($kc['kota']).', kami buat dengan sebenar-benarnya. Kemudian atas perhatiannya kami haturkan ucapan terimakasih.';
$current_y = $pdf->GetY();
$current_x = $pdf->GetX();
$pdf->MultiCell(180,5, $ket2,0);
$current_x+5;
$pdf->SetXY($current_x, $current_y);
$pdf->Cell(5,16,'',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();
?>