<?php
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');


require("library/fpdf/fpdf.php");

class pdf extends fpdf
{
    function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('Arial', 'I', 8);
    }
}

class PDF_Dash extends FPDF
{
    function SetDash($black = false, $white = false)
    {
        if ($black && $white) {
            $s = sprintf('[%.3f %.3f] 0 d', $black, $white);
        } else {
            $s = '[] 0 d'; // Solid line
        }
        $this->_out($s);
    }
}

$pdf = new PDF_Dash('P', 'mm', 'A4');
$pdf->AddPage();
$font = 'Arial';
$cellWidth = 97;
$ht = 8;

$pdf->SetDrawColor(220, 220, 220); // white border

$pdf->SetFont($font, 'B', 15);
$pdf->SetTextColor(255, 255, 255); // White text
$pdf->SetFillColor(141, 153, 174); // Background color

$pdf->SetFont($font, 'B', 12);
$pdf->Cell($cellWidth, $ht, "Received", 1, 0, 'L', 1);
$pdf->Cell($cellWidth, $ht, "Paid", 1, 1, 'L', 1);
$pdf->Ln(1);

$pdf->SetFont($font, 'B', 10);
$pdf->SetFillColor(64, 145, 108);  // Green header
$pdf->SetTextColor(255, 255, 255); // White text

$pdf->Cell(20, $ht, 'Date', 1, 0, 'L', 1);
$pdf->Cell(15, $ht, 'Source', 1, 0, 'L', 1);
$pdf->Cell(16, $ht, 'Voucher', 1, 0, 'L', 1);
$pdf->Cell(31, $ht, 'Description', 1, 0, 'L', 1);
$pdf->Cell(15, $ht, 'Amount', 1, 0, 'R', 1);

// Header Row under Paid
$pdf->Cell(20, $ht, 'Date', 1, 0, 'L', 1);
$pdf->Cell(15, $ht, 'Source', 1, 0, 'C', 1);
$pdf->Cell(16, $ht, 'Voucher', 1, 0, 'C', 1);
$pdf->Cell(31, $ht, 'Description', 1, 0, 'C', 1);
$pdf->Cell(15, $ht, 'Amount', 1, 1, 'C', 1);
$pdf->Ln(0);

// Received side data
$pdf->SetFont($font, '', 10);
$pdf->SetTextColor(0);
$pdf->Cell(20, $ht, '', 1, 0, 'L');
$pdf->Cell(15, $ht, '', 1, 0, 'L');
$pdf->Cell(16, $ht, '', 1, 0, 'L');
$pdf->Cell(31, $ht, '', 1, 0, 'L');
$pdf->Cell(15, $ht, number_format(1, 0), 1, 0, 'R');

// Paid side empty
$pdf->Cell(20, $ht, '', 1, 0, 'L');
$pdf->Cell(15, $ht, '', 1, 0, 'L');
$pdf->Cell(16, $ht, '', 1, 0, 'L');
$pdf->Cell(31, $ht, '', 1, 0, 'L');
$pdf->Cell(15, $ht, '', 1, 1, 'R');
$pdf->Ln(0);

$pdf->SetFont($font, '', 10);
$pdf->SetTextColor(0);
$pdf->SetFillColor(224, 255, 234); // light green

$pdf->Cell(20+15+16+31, $ht, 'Total', 1, 0, 'R', 1);
$pdf->Cell(15, $ht, number_format(1, 0), 1, 0, 'R', 1);

$pdf->Cell(20+15+16+31, $ht, 'Total', 1, 0, 'R', 1);
$pdf->Cell(15, $ht, '0', 1, 1, 'R', 1);
$pdf->Ln(0);

// Closing row
$pdf->SetFillColor(64, 145, 108);  // Green
$pdf->SetTextColor(255);
$pdf->Cell(20+15+16+31, $ht, '', 1, 0, 'R', 1); // blank on left
$pdf->Cell(15, $ht, '', 1, 0, 'R', 1); // blank amount

$pdf->Cell(20+15+16+31, $ht, 'Closing', 1, 0, 'R', 1);
$pdf->Cell(15, $ht, number_format(1, 0), 1, 1, 'R', 1);
$pdf->Ln(0);


$pdf->SetFont($font, 'B', 10);
$pdf->SetTextColor(255, 255, 255);
$pdf->SetFillColor(141, 153, 174);

// while ($pmain = mysqli_fetch_array($getpmain)) {
    
//     $pdf->SetTextColor(0, 0, 0);


//     $ctr++;
   
// }


$pdf->Output(".pdf", "I");
