<?php
require_once "core/koneksi.php";
require_once 'core/paramx.php';
require_once 'pdf/fpdf.php';


$pdf = new FPDF('l','cm',array(46.0,49.0));

// membuat halaman baru
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(19.5,0.5,'CV ABRINDO SEJAHTERA ',0,'L');
$pdf->SetX(4);
$pdf->ln(1.5);
$pdf->SetFont('Arial','B',30);
$pdf->MultiCell(47.5,0.5,'LAPORAN BUKU BESAR',0,'C');
$pdf->ln(2);
$pdf->SetFont('Arial','B',17);
$pdf->Cell(10.2,0.3,"Periode :".$date_from." s/d ".$date_end."",0,0,'C');
$pdf->ln(1.5);


$no=1;
$temp = '';
$tempOld = '1';
$credittot = 0;
$saldoCount = 0;
unset($_SESSION['temp']);
$debittot  = $lihat['fcdebit'];

while($lihat = mysqli_fetch_assoc($result)){

    //Mengubah Stok Awal Menjadi 0
    if ($lihat['ftDescription']  == 'Saldo Awal') {
        $lihat['fcsaldo'] = 0;
    }

      $saldoCount = $saldoCount + $lihat['fcdebit'] - $lihat['fccredit'];
      $debittot   = $debittot + $lihat['fcdebit'];
      $temp       = $lihat['ftcoa_code'];

    if ($tempOld != $temp) {
      if ($_SESSION['temp'] == 'true') {
      $pdf->SetFont('Arial','B',16);
      $pdf->Cell(47, 0.8, '______________________________________________________________________________________________________________________________________________________' , 0, 0, 'C');
      $pdf->ln(1);
      $pdf->Cell(1, 0.8, '' , 0, 0, 'C');
      $pdf->Cell(3, 0.8,'', 0, 0, 'C');
      $pdf->Cell(5, 0.8,'', 0, 0, 'C');
      $pdf->Cell(14, 0.8,'', 0, 0, 'L');
      $pdf->Cell(6, 0.8,'TOTAL :', 0, 0, 'R');
      $pdf->Cell(6, 0.8,rupiah($debittot), 0, 0, 'R');
      $pdf->Cell(6, 0.8,rupiah($credittot), 0, 0, 'R');
      $pdf->Cell(6, 0.8,'', 0, 0, 'R');
      $pdf->ln(0.8);
      }
    }

  if ($temp != $tempOld) {

    $no=1;
    $saldoCount = $lihat['fcsaldo'];
    $debittot   = $lihat['fcdebit'];
    $credittot =  $lihat['fccredit'];
    $credittot  = $credittot - $credittot;

    $pdf->ln(1);
    $pdf->SetFont('Arial','B',18);
    $pdf->MultiCell(50.2,0.3,$lihat['ftcoa_code']."-".$lihat['ftcoa_name'],0,'L');
    $pdf->ln(1);
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(1, 0.8, 'No', 1, 0, 'C');
    $pdf->Cell(3, 0.8, 'Tanggal', 1, 0, 'C');
    $pdf->Cell(5, 0.8, 'No. Transaksi', 1, 0, 'C');
    $pdf->Cell(14, 0.8, 'Keterangan', 1, 0, 'C');
    $pdf->Cell(6, 0.8, 'Jumlah (Non IDR)', 1, 0, 'C');
    $pdf->Cell(6, 0.8, 'Debit (IDR)', 1, 0, 'C');
    $pdf->Cell(6, 0.8, 'Kredit (IDR)', 1, 0, 'C');
    $pdf->Cell(6, 0.8, 'Saldo (IDR)', 1, 0, 'C');
    $pdf->ln(1);

  }

    $_SESSION['temp'] = 'true';
    $tempOld = $temp;

 if ($lihat['ftDescription']  != 'Saldo Awal') {
    $pdf->SetFont('Arial','',15);
    $pdf->Cell(1, 0.8, $no, 0, 0, 'C');
    $pdf->Cell(3, 0.8,$lihat['fdtrans_date'], 0, 0, 'C');
    $pdf->Cell(5, 0.8,$lihat['ftdocument_no'], 0, 0, 'C');
    $pdf->Cell(14, 0.8,$lihat['ftDescription'], 0, 0, 'L');
    $pdf->Cell(6, 0.8,'', 0, 0, 'C');
    $pdf->Cell(6, 0.8,rupiah($lihat['fcdebit']), 0, 0, 'R');
    $pdf->Cell(6, 0.8,rupiah($lihat['fccredit']), 0, 0, 'R');
    $pdf->Cell(6, 0.8,rupiah($saldoCount), 0, 0, 'R');
    $pdf->ln(0.8);
    $credittot  = $credittot + $lihat['fccredit'];
    $no++;
  }
}// for loop

$pdf->Output("laporan_buku_besar.pdf","I");
$pdf->ln(5);
?>
