<?php

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

$formname = 'Cash Receipt';
$maindb = 'cashrecp';
$accdb = 'actran';
$billdb = 'billsett';
$file = 'cashrecp_pdf.php';
$source = "CR";
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';

$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];
//browse('hey');
$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt FROM `$maindb` WHERE vouchno='$vouchno'") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry);

$getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company`")or die(mysqli_error($conn));
$comp = mysqli_fetch_array($getcomp);
//if (isset($_POST["subpdf"])) {
//browse('idar');
//ini_set("session.auto_start", 0);
require("library/fpdf/fpdf.php");

class pdf extends fpdf {

    function Footer() {

//Position at 1.5 cm from bottom
        $this->SetY(-15);

//Arial italic 8
        $this->SetFont('Arial', 'I', 8);
//Page number
        $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
    }

}

//browse('udar');

$pdf = new pdf('P', 'mm', 'A4');

$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 14);
$pdf->SetTextColor(0, 0, 0);
$pdf->Rect(5, 5, 200, 140, 'D');
$pdf->Cell(0,10, $comp['compname'],0,0,'C');
$pdf->Ln();
//$pdf->SetFont('Arial', '', 10);
//$pdf->Cell(0, 5, "$comp[hoadd1]", 0, 0,'C');
//$pdf->Ln();
//$pdf->Cell(0, 5, "$comp[hoadd2]", 0, 0,'C');
//$pdf->Ln();
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(190, 7, "$formname", 0, 0, 'C');
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial', '', 14);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(30, 5, "Receipt No. :", 0, 0);
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(80, 5, "$getmdata[vouchno]", 0, 0);
$pdf->SetFont('Arial', '', 14);
$pdf->Cell(39, 5, "Date :", 0, 0, "R");
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(30, 5, "$getmdata[vouchdt]", 0, 0);
$pdf->Ln(10);
$pdf->SetFont('Arial', '', 14);
$pdf->SetTextColor(0, 0, 0);
mysqli_select_db($conn, $zdb);

$gcust = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$getmdata[party]'") or die(mysqli_error($conn));
$cust = mysqli_fetch_array($gcust);


$pdf->Line(5, 30, 205, 30);
//$pdf->SetFillColor(96, 130, 191);
$pdf->Cell(68, 5, "Received With Thanks From :", 0, 0);
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(62, 5, "$cust[name]", 0, 0);
$pdf->Ln(15);

$pdf->SetFont('Arial', '', 14);
$pdf->SetTextColor(0, 0, 0);
//$pdf->SetFillColor(96, 130, 191);

$rps = rsword(round($getmdata["amount"]));
$pdf->Cell(42, 5, "An Amount Of  Rs.", 0, 0);
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(68, 5, "$getmdata[amount] ", 0, 0);
$pdf->Ln(10);
$rps = rsword(round($getmdata["amount"]));
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(128, 5, "( $rps )", 0, 0);
$pdf->Ln(15);

$pdf->Ln(20);
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(130, 7, "____________________", 0, 0, 'L' );
$pdf->Cell(30, 7, "____________________", 0, 0, 'L' );
$pdf->Ln();
$pdf->SetFont ('Arial','B',12);
$pdf->Cell(125, 7, '   Authorised Signatory ', 0,0, 'L');
$pdf->Cell(30, 7, 'Received By/Account Holder ', 0,0, 'L');
ob_end_clean();
$pdf->Output("Cash Reciept-".$getmdata['vouchno'].".pdf", "I");
//}
?>