<?php

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

$formname = 'Receipt (Items On Rent)';
$maindb = 'rentmain';
$trandb = 'renttran';
$file = 'rentitem_pdf.php';
$source = "";
$zcomp = $_SESSION["comp_" . $dbname];
$fseries = $_SESSION["series_" . $dbname];

$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);

$mht = 'height:20px;';
$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];

$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt,DATE_FORMAT(`retdate`, '%d-%m-%Y') AS retndate  FROM `$maindb` WHERE `vouchno`='$vouchno' ORDER BY `vouchno`") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry) or die(mysqli_error($conn));

$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company` where code ='$zcomp'")or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);


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');
    }

}

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

$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 18);
$pdf->SetTextColor(0, 0, 0);

if ($fseries == 'MJ') {

    $pdf->Cell(193, 6, "", 0, 0, 'C');
    $pdf->Ln(7);

    $pdf->SetFont('Arial', 'B', 15);
    $pdf->Cell(193, 6, "SORATHIYA MUSLIM GHANCHI JAMAT TRUST (MUMBAI)", 0, 0, 'C');
    $pdf->Ln();
    $pdf->SetFont('Arial', 'B', 12);
    $pdf->Cell(193, 6, "Regd. 1950 No. B.1184 Dt. 9-4-1970", 0, 0, 'C');
    $pdf->Ln();
    $pdf->SetFont('Arial', '', 12);
    $pdf->Cell(193, 6, "131, Zakaria Masjid Street, Mumbai - 400 001. Phone: 022-23456741", 0, 0, 'C');
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(0, 6, "", 0, 0, 'C');
    $pdf->Ln();
    $pdf->Cell(0, 6, "", 0, 0, 'C');
    $pdf->Ln();

    $pdf->Ln(8);
} elseif ($fseries == 'MAD') {

    $pdf->SetFont('Arial', 'B', 16);
    $pdf->Cell(193, 6, "MADNI BAUG", 0, 0, 'C');
    $pdf->Ln(7);

    $pdf->SetFont('Arial', 'B', 12);
    $pdf->Cell(193, 6, "SORATHIYA MUSLIM GHANCHI JAMAT TRUST (MUMBAI)", 0, 0, 'C');
    $pdf->Ln();
    $pdf->Cell(193, 6, "Regd. 1950 No. B.1184 Dt. 9-4-1970", 0, 0, 'C');
    $pdf->Ln();
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(0, 6, "502/2, Vaishali Nagar, Amrut Nagar Corner, Rubi Hospital Lane Off S. V. Road,", 0, 0, 'C');
    $pdf->Ln();
    $pdf->Cell(0, 6, "Jogeshwari (West), Mumbai - 400 102. Phone: 022-26794479 ", 0, 0, 'C');
    $pdf->Ln();
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(28, 6, "", 0, 0, 'C');
    $pdf->Cell(23, 6, "Head Office : ", 0, 0, 'L');
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(142, 6, "131, Zakaria Masjid Street, Mumbai - 400 001. Phone: 022-23456741", 0, 0, 'L');

    $pdf->Ln(8);
    
} elseif ($fseries == 'TAI') {
    
    $pdf->SetFont('Arial', 'B', 16);
    $pdf->Cell(193, 6, "TAIBA HALL", 0, 0, 'C');
    $pdf->Ln(7);

    $pdf->SetFont('Arial', 'B', 12);
    $pdf->Cell(193, 6, "SORATHIYA MUSLIM GHANCHI JAMAT TRUST (MUMBAI)", 0, 0, 'C');
    $pdf->Ln();
    $pdf->Cell(193, 6, "Regd. 1950 No. B.1184 Dt. 9-4-1970", 0, 0, 'C');
    $pdf->Ln();
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(0, 6, "Porbunder Wala Estate, Off. L.B.S Road", 0, 0, 'C');
    $pdf->Ln();
    $pdf->Cell(0, 6, "Chirag Nagar, Ghatkopar (W), Mumbai - 400 070", 0, 0, 'C');
    $pdf->Ln();
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(28, 6, "", 0, 0, 'C');
    $pdf->Cell(23, 6, "Head Office : ", 0, 0, 'L');
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(142, 6, "131, Zakaria Masjid Street, Mumbai - 400 001. Phone: 022-23456741", 0, 0, 'L');

    $pdf->Ln(8);
}
//if ($fseries == 'MAD') {
//include ('includes/header_madni.php');
//} else{
//include ('includes/header_MJ.php');
//}


$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(193, 7, "$formname", 0, 0, 'C');
$pdf->Ln(10);
$pdf->Line(10, 48, 203, 48);

$pdf->SetFont('Arial', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(25, 2, "Receipt No.  :", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(110, 2, "$getmdata[vouchno]", 0, 0);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(20, 1, "From Date : ", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, 1, "$getmdata[vouchdt]", 0, 0);
$pdf->Ln(7);

$pdf->SetFont('Arial', '', 12);
$pdf->SetTextColor(0, 0, 0);

$pdf->SetDrawColor(206, 169, 98);
$pdf->SetFont('Arial', '', 10);
$pdf->SetDrawColor(0, 0, 0);

$pdf->Cell(20, 1, "Name", 0, 0);
$pdf->Cell(4, 1, ":", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(110, 1, " $getmdata[name]", 0, 0);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(20, 5, "To Date :", 0, 0, 'R');
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, 5, "$getmdata[retndate]", 0, 0);

$pdf->Ln(7);

$pdf->SetFont('Arial', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(20, 0, "Address", 0, 0);
$pdf->Cell(5, 0, ":", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(110, 0, "$getmdata[add1]", 0, 0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(20, 5, "No. Of Days :", 0, 0, 'R');
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, 5, "$getmdata[days]", 0, 0);
$pdf->Ln(5);

$pdf->Cell(20, 0, "", 0, 0);
$pdf->Cell(5, 0, "", 0, 0);
$pdf->Cell(165, 0, "$getmdata[add2]", 0, 0);
$pdf->Ln(5);

$pdf->Cell(20, 0, "", 0, 0);
$pdf->Cell(5, 0, "", 0, 0);
$pdf->Cell(165, 0, "$getmdata[add3]", 0, 0);
$pdf->Ln(5);

$pdf->SetFont('Arial', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(20, 2, "Mobile", 0, 0);
$pdf->Cell(4, 2, ":", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(115, 2, " $getmdata[mob1]", 0, 0);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(17, 1, "Mobile 2 :", 0, 0);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, 1, "$getmdata[mob2]", 0, 0);
$pdf->Ln(7);

$pdf->SetFont('Arial', 'B', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFillColor(169, 185, 124);
$cl = 8;

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

$pdf->Cell(10, $cl, 'Sr.', 1, 0, 'C', 1);
$pdf->Cell(115, $cl, 'Itemname', 1, 0, 'C', 1);
$pdf->Cell(20, $cl, 'Qty.', 1, 0, 'C', 1);
$pdf->Cell(20, $cl, 'Rate', 1, 0, 'C', 1);
$pdf->Cell(25, $cl, 'Amount', 1, 0, 'C', 1);
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(0, 0, 0);
$gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$vouchno' order by srno")or die(mysqli_error($conn));
while ($row = mysqli_fetch_array($gettran)) {

    $gitem = mysqli_query($conn, "SELECT code,name FROM `item` where `code`='$row[item]' ") or die(mysqli_error($conn));
$fitem = mysqli_fetch_array($gitem);
    $item = $fitem['name'];
    $qty = $row['qty'];
    $rate = $row['rate'];
    $amount = $row['amount'];
    $ctr++;

    $pdf->Cell(10, $cl, "$ctr", 1, 0, 'R', 1);
    $pdf->Cell(115, $cl, "$item", 1, 0, 'C', 1);
    $pdf->Cell(20, $cl, "$qty", 1, 0, 'R', 1);
    $pdf->Cell(20, $cl, "$rate", 1, 0, 'R', 1);
    $pdf->Cell(25, $cl, "$amount", 1, 0, 'R', 1);
    $pdf->Ln();
    $ctab = $ctab + 1;
}
$pdf->Ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(165, $cl, "Daily Amount", 1, 0, 'R', 1);
$pdf->Cell(25, $cl, $getmdata['totamt'], 1, 0, 'R', 1);
$pdf->ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(165, $cl, "Total Amount", 1, 0, 'R', 1);
$pdf->Cell(25, $cl, $getmdata['billamt'], 1, 0, 'R', 1);
$pdf->ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(165, $cl, "Advance", 1, 0, 'R', 1);
$pdf->Cell(25, $cl, $getmdata['advance'], 1, 0, 'R', 1);
$pdf->ln();

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(165, $cl, "Balance", 1, 0, 'R', 1);
$pdf->Cell(25, $cl, $getmdata['bal'], 1, 0, 'R', 1);
$pdf->ln();

$rupees = rsword(round($getmdata['billamt']));

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(190, $cl, "Rupees in words :" . $rupees, 1, 0, 'L', 1);
$pdf->Ln(10);

$pdf->Cell(145, $cl, "For", 0, 0, 'R', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(45, $cl, "S.M.G.J. Trust (Mumbai)", 0, 0, 'R', 1);
$pdf->Ln(50);

$pdf->Line(20, 220, 100, 220);

$pdf->Line(110, 220, 193, 220);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(140, 6, "", '', 0, 'R', 1);
$pdf->Cell(45, 6, "Sign. of Authorise Person", 'T', 0, 'R', 1);

$pdf->Ln(10);
$y_aqui2 = $pdf->Gety();

ob_end_clean();
$pdf->Output("$formname - $lparty[name]-" . $getmdata['vouchno'] . ".pdf", "I");
?>