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

$maindb = 'member';
$trandb = 'member';

$accode = $_GET["accode"];
$mvouch = $_REQUEST["mvouch"];

$getpmain = mysqli_query($conn, "SELECT * FROM member WHERE accode = '$accode' ")or die(mysqli_error($conn));

$pmain = mysqli_fetch_object($getpmain);
require("library/fpdf/fpdf.php");

class pdf extends fpdf {

    function Footer() {


        $this->SetY(-15);


        $this->SetFont('Arial', 'I', 8);


        $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
    }

}

$htt = 9;
$pdf = new pdf('L', 'mm', 'A4');

$pdf->AliasNbPages();

$pdf->AddPage();
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(168,184,124);
$pdf->SetFont('Arial', 'B', 15);
$pdf->Cell(280, -6, "SORATHIYA MUSLIM GHANCHI JAMAT TRUST (MUMBAI)", 0, 0, 'C');
$pdf->Ln(2);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial', 'I', 12);
$pdf->Cell(280, 12, "Family Head Details", 1, 0, 'C', 1);
$pdf->ln(12);

$surname = strtoupper($pmain->surname);
$name = strtoupper($pmain->name);
$name2 = strtoupper($pmain->name2);

$pdf->SetFont('Arial', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(30, $htt, "Surname", 'LT', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, $htt, ": $surname", 'T', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $htt, "Member No.", 'T', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25, $htt, ": $pmain->accode", 'T', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $htt, "Family ID", 'T', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(20, $htt, ": $pmain->familyid", 'T', 0, 'L', 1);
$pdf->Cell(125, 60, " ", 'TR', 0, 'L', 1);

$ht = 7;
$pdf->Ln($ht);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Name", 'L', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(200, $ht, ": $name", '', 0, 'L', 1);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Father/Husband", 'L', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(80, $ht, ": $name2", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "Birth Place", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25, $ht, ": $pmain->birthpl", '', 0, '', 1);
//$pdf->Cell(25, $ht, "Aadhaar No.", '', 0, 'L', 1);
//$pdf->Cell(145, $ht, ": $pmain->aadhaar", 'R', 0, '', 1);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Gender", 'L', 0, 'L', 1);
if ($pmain->gender == "M") {
    $gender = "Male";
} else {
    $gender = "Female";
}

$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, $ht, ": $gender", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "Date Of Birth", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25, $ht, ": $pmain->dob", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "Age", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, $ht, ": $pmain->age", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Married Status", '', 0, 'L', 1);
if ($pmain->mstatus == "M") {
    $mstatus = "Married";
} else if ($pmain->mstatus == "S") {
    $mstatus = "Single";
} else if ($pmain->mstatus == "D") {
    $mstatus = "Divorce";
} else if ($pmain->mstatus == "W") {
    $mstatus = "Widow";
}
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, $ht, ": $mstatus", '', 0, 'L', 1);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "State", 'L', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 8);
$pdf->Cell(30, $ht, ": $pmain->area", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "District", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 8);
$pdf->Cell(25, $ht, ": $pmain->district", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "Area", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, $ht, ": $pmain->taluka", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "City/Village", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(40, $ht, ": $pmain->village", '', 0, 'L', 1);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Address", 'L', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 9);
$pdf->Cell(250, $ht, ": $pmain->add1", 'R', 0, 'L', 1);
$pdf->Ln($ht);

if ($pmain->add2 != '') {
    $pdf->Cell(30, $ht, "", 'L', 0, 'L', 1);
    $pdf->Cell(250, $ht, "  $pmain->add2", 'R', 0, 'L', 1);
    $pdf->Ln($ht);
}

if ($pmain->add3 != '') {
    $pdf->Cell(30, $ht, "", 'L', 0, 'L', 1);
    $pdf->Cell(80, $ht, ": $pmain->add3", '', 0, 'L', 1);
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(25, $ht, "Pin", '', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(30, $ht, ": $pmain->pin", '', 0, 'L', 1);
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, $ht, "Native", '', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(85, $ht, ": $pmain->native", 'R', 0, 'L', 1);
    $pdf->Ln($ht);
} else {
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, $ht, "", 'L', 0, 'L', 1);
    $pdf->Cell(80, $ht, "", '', 0, 'L', 1);
    $pdf->Cell(25, $ht, "Pin", '', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(30, $ht, ": $pmain->pin", '', 0, 'L', 1);
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, $ht, "Native", '', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(85, $ht, ": $pmain->native", 'R', 0, 'L', 1);
    $pdf->Ln($ht);
}

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Mobile", 'L', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, $ht, ": $pmain->mobile", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "Whatsapp", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25, $ht, ": $pmain->whatsapp", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "Telephone", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(145, $ht, ": $pmain->tel", 'R', 0, 'L', 1);

$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Email", 'L', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(80, $ht, ": $pmain->email", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "Aadhaar", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(145, $ht, ": $pmain->aadhaar", 'R', 0, 'L', 1);
$pdf->Ln($ht);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Qualification", 'L', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, $ht, ": $pmain->qualification", '', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25, $ht, "Occupation", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(80, $ht, ": $pmain->occupation", '', 0, 'L', 1);
// $pdf->Ln($ht);
// $pdf->SetFont('Arial', '', 10);
// $pdf->Cell(25, $ht, "Profession", 'B', 0, 'L', 1);
// $pdf->SetFont('Arial', 'B', 10);
// $pdf->Cell(145, $ht, ": $pmain->profession", 'BR', 0, 'L', 1);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, $ht, "Profession", '', 0, 'L', 1);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(85, $ht, ": $pmain->profession", 'R', 0, 'L', 1);
$pdf->Ln($ht);

$occupation = $pmain->occupation;
if ($occupation == "Business") {
    $pdf->SetFillColor(226, 226, 226);
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, $ht, "Firm Name", 'L', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(250, $ht, ": $pmain->firmname", 'R', 0, 'L', 1);
    $pdf->Ln($ht);

    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, $ht, "State", 'L', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(30, $ht, ": $pmain->bsarea", '', 0, 'L', 1);
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(25, $ht, "District", '', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(25, $ht, ": $pmain->bsdistrict", '', 0, 'L', 1);
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(25, $ht, "Taluka", '', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(30, $ht, ": $pmain->bstaluka", '', 0, 'L', 1);
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, $ht, "City/Village", '', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(85, $ht, ": $pmain->bsvillage", 'R', 0, 'L', 1);
    $pdf->Ln($ht);


    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, $ht, "Address", 'L', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 9);
    $pdf->Cell(250, $ht, ": $pmain->bsadd1", 'R', 0, 'L', 1);
    $pdf->Ln($ht);

    if ($pmain->bsadd2 != '') {
        $pdf->Cell(30, $ht, "", 'L', 0, 'L', 1);
        $pdf->Cell(250, $ht, ": $pmain->bsadd2", 'R', 0, 'L', 1);
        $pdf->Ln($ht);
    }

    if ($pmain->bsadd3 != '') {
        $pdf->Cell(30, $ht, "B", 'L', 0, 'L', 1);
        $pdf->Cell(80, $ht, ": $pmain->bsadd3", 'B', 0, 'L', 1);
        $pdf->SetFont('Arial', '', 10);
        $pdf->Cell(25, $ht, "Pin", 'B', 0, 'L', 1);
        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(145, $ht, ": $pmain->bspin", 'BR', 0, 'L', 1);
        $pdf->Ln($ht);
    } else {
        $pdf->Cell(30, $ht, "", 'B', 0, 'L', 1);
        $pdf->Cell(80, $ht, "", 'B', 0, 'L', 1);
        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(25, $ht, "Pin", 'B', 0, 'L', 1);
        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(145, $ht, ": $pmain->bspin", 'BR', 0, 'L', 1);
        $pdf->Ln($ht);
    }
    $pdf->SetFillColor(255, 255, 255);
} else if ($occupation == "Govt Service") {

    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(30, $ht, "Department", 'BL', 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(250, $ht, ": $pmain->occudtl", 'RB', 0, 'L', 1);
    $pdf->Ln($ht);
    $pdf->SetFillColor(255, 255, 255);
}
$gettran = mysqli_query($conn, "SELECT *,DATE_FORMAT(`dob`, '%d-%m-%Y')as dob FROM  `$trandb` WHERE memcode = '$mvouch' and accode != '$mvouch' 
                                       order by accode")or die(mysqli_error($conn));
$trannum = mysqli_num_rows($gettran);

if ($trannum > 0) {
    $pdf->Cell(10, $ht, "M No.", 1, 0, 'L', 1);
    $pdf->Cell(23, $ht, "Name", 1, 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 7);
    $pdf->Cell(24, $ht, "Father/Husband", 1, 0, 'L', 1);
    $pdf->SetFont('Arial', 'B', 10);
    $pdf->Cell(15, $ht, "Gender", 1, 0, 'L', 1);
    $pdf->Cell(20, $ht, "DOB", 1, 0, 'L', 1);
    $pdf->Cell(10, $ht, "Age", 1, 0, 'L', 1);
    $pdf->Cell(28, $ht, "Aadhaar", 1, 0, 'L', 1);
    $pdf->Cell(15, $ht, "Status", 1, 0, 'L', 1);
    $pdf->Cell(25, $ht, "Mobile", 1, 0, 'L', 1);
    $pdf->Cell(30, $ht, "Relationship", 1, 0, 'L', 1);
    $pdf->Cell(30, $ht, "Qualification", 1, 0, 'L', 1);
    $pdf->Cell(30, $ht, "Profession", 1, 0, 'L', 1);
    $pdf->Cell(20, $ht, "Birth Place", 1, 0, 'L', 1);
    $pdf->Ln($ht);

    $ctr = 0;
    while ($ptran = mysqli_fetch_object($gettran)) {
        if ($ptran->gender == "M") {
            $tgender = "Male";
        } else {
            $tgender = "Female";
        }

        $trdob = $ptran->dob;
        $trage = $ptran->age;
        $tradr = $ptran->aadhaar;
        $mobile = $ptran->mobile;
        if ($ptran->mstatus == "M") {
            $trstatus = "Married";
        } else if ($ptran->mstatus == "S") {
            $trstatus = "Single";
        } else if ($ptran->mstatus == "D") {
            $trstatus = "Divorce";
        } else if ($ptran->mstatus == "W") {
            $trstatus = "Widow";
        }
        $relation = $ptran->relation;
        $qualification = $ptran->qualification;
        $profession = $ptran->profession;
        $birth = $ptran->birthpl;
        $tranmemid = $ptran->accode;
        $name = strtoupper($ptran->name);
        $name2 = strtoupper($ptran->name2);

        $ctr++;
        $pdf->SetFont('Arial', '', 10);
        $pdf->Cell(10, 7, "$tranmemid", 1);
        $pdf->SetFont('Arial', '', 6);
        $pdf->Cell(23, 7, "$name", 1);
        $pdf->Cell(24, 7, "$name2", 1);
        $pdf->SetFont('Arial', '', 10);
        $pdf->Cell(15, 7, "$tgender", 1);
        $pdf->Cell(20, 7, "$trdob", 1);
        $pdf->Cell(10, 7, "$trage", 1);
        $pdf->Cell(28, 7, "$tradr", 1);
        $pdf->Cell(15, 7, "$trstatus", 1);
        $pdf->Cell(25, 7, "$mobile", 1);
        $pdf->SetFont('Arial', '', 8);
        $pdf->Cell(30, 7, "$relation", 1);
        $pdf->SetFont('Arial', '', 6);
        $pdf->Cell(30, 7, "$qualification", 1);
        $pdf->Cell(30, 7, "$profession", 1);
        $pdf->Cell(20, 7, "$birth", 1);
        $pdf->Ln();
    }
}
$pdf->Output("Member.pdf", "I");
?>