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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$maindb = 'demdmain';
$trandb = 'demdtran';
$zroot = $_SESSION["zdbroot"];
$formname = 'Pending Bill Register';
$file = 'rgbillpend_fr.php';
$zroot = $_SESSION['zdir'];

if (isset($_POST["view"])) {
    $code = $_POST["custcode"];
    $school = $_POST["name"];
    $medium = $_POST["medmcode"];
    $exam = $_POST["exam"];
    $section = $_POST["section"];
    $session = $_POST["session"];
    $dtye = $_POST["dtype"];

    if (!empty($code)) {
        $codecond = " AND `custcode` = '$code' ";
    }
    if (!empty($school)) {
        $schoolcond = " AND `accode` = '$school' ";
    }
    if (!empty($medium)) {
        $mediumcond = " AND `medmcode` = '$medium '";
    }
    if (!empty($exam)) {
        $examcond = " AND `examcode` = '$exam' ";
    }
    if (!empty($section)) {
        $sectioncond = " AND `section` = '$section'";
    }
    if (!empty($session)) {
        $sessioncond = " AND `session` = '$session'";
    }
    if (!empty($dtype)) {
        $dtypecond = " AND `dtype`='$dtype' ";
    }
    if (empty($_POST["frmdt"])) {
        browse("From Date Cannot Be Empty");
        header("refresh:1; saleitemgrp.php");
    }
    if (empty($_POST["todt"])) {
        browse("To Date Cannot Be Empty");
        header("refresh:1; saleitemgrp.php");
    }

    $mfrmdate = trim($_POST["frmdt"]);
    $mtodate = trim($_POST["todt"]);

    $mfdt = date("d-m-Y", strtotime($mfrmdate));
    $mtdt = date("d-m-Y", strtotime($mtodate));

    $getpmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM `$maindb` WHERE `vouchdt` >= '$mfrmdate' 
                            AND `vouchdt` <= '$mtodate' AND concat(custcode, section , examcode ,medmcode , session)
                            not in(select concat(custcode, section , examcode ,medmcode , session) from invmain )
                            $codecond $schoolcond $mediumcond $examcond $sectioncond $sessioncond ")or die(mysqli_error($conn));

    $get = mysqli_num_rows($getpmain);

    $gexam = mysqli_query($conn, "SELECT `code`,`name` FROM `exam` WHERE `code`= '$exam' ")or die(mysqli_error($conn));
    $dexam = mysqli_fetch_array($gexam);

    include("includes/linkshead.php");
    ?>
    <style type="text/css">
        #tabital{
            font-style: italic;
        }
        #font1{
            font-style: italic;
        }
        #boldfont{
            font-weight: bold; 
        }
        th{
            background: #6082BF;
        }
    </style>
    </head>
    <body>
        <div class="container">
            <?php include("includes/head_rep.php"); ?>
            <div class="row">
                <div class="col-lg-12 pad">
                    <table style="background: white;width: 100%" class="table table-bordered table-condensed table-hover">
                        <thead class="mySearchTr">
                            <tr>
                                <th style="width:5%">Sr</th>
                                <th style="width:7%">Date</th>
                                <th style="width:7%">Bill.No</th>
                                <th style="width:8%">Code</th>
                                <th style="width:25%">School Name</th>
                                <th style="width:11%">Section</th>
                                <th style="width:11%">Session</th>
                                <th style="width:11%">Medium</th>
                                <th style="width:15%">Exam</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $ctr = 0;

                            while ($pmain = mysqli_fetch_array($getpmain)) {

                                $gschool = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$pmain[accode]' ")or die(mysqli_error($conn));
                                $sschool = mysqli_fetch_array($gschool);

                                $gmedm = mysqli_query($conn, "SELECT `code`,`name` FROM `medium` WHERE `code`= '$pmain[medmcode]' ")or die(mysqli_error($conn));
                                $smedm = mysqli_fetch_array($gmedm);

                                $gexam = mysqli_query($conn, "SELECT `code`,`name` FROM `exam` WHERE `code`= '$pmain[examcode]' ")or die(mysqli_error($conn));
                                $fexam = mysqli_fetch_array($gexam);

                                $ctr++;
                                Echo "<tr id='boldfont'>";
                                Echo "<td>$ctr</td>";
                                Echo "<td>$pmain[mydt]</td>";
                                Echo "<td>$pmain[vouchno]</td>";
                                Echo "<td>$pmain[custcode]</td>";
                                Echo "<td>$sschool[name]</td>";

                                if ($pmain['section'] == 'P') {
                                    $sectn = 'Primary';
                                } elseif ($pmain['section'] == 'S') {
                                    $sectn = 'Secondry';
                                } else {
                                    $sectn = 'Prelims';
                                }
                                Echo "<td>$sectn</td>";
                                if ($pmain['session'] == 'M') {
                                    $sessn = 'Morning';
                                } else {
                                    $sessn = 'Afternoon';
                                }
                                Echo "<td>$sessn</td>";
                                Echo "<td>$smedm[name]</td>";
                                Echo "<td>$fexam[name]</td>";
                                Echo "</tr>";

                                if ($pmain['section'] == 'P') {
                                    if ($_POST["dtype"] == 2) {

                                        Echo "<tr style='height:10px;'>";
                                        Echo "<td colspan='25'>";
                                        Echo "<table style='width:100%;' id='tabital' class='table table-condensed table-hover table-bordered'>";
                                        Echo "<th style='background: #007DFF;;width:10%;'>Sr</th>";
                                        Echo "<th style='background-color: #007DFF;width:30%;'>Subject</th>";
                                        Echo "<th style='background-color: #007DFF;width:15%;' class='text-right'>First</th>";
                                        Echo "<th style='background-color: #007DFF;width:15%;' class='text-right'>Second</th>";
                                        Echo "<th style='background-color: #007DFF;width:15%;' class='text-right'>Third</th>";
                                        Echo "<th style='background-color: #007DFF;width:15%;' class='text-right'>Fourth</th>";
                                        Echo "<tr>";

                                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                                        $ctr2 = 0;
                                        while ($tran = mysqli_fetch_array($gettran)) {

                                            $ctr2++;
                                            Echo "<tr>";
                                            Echo "<td>$ctr2</td>";
                                            Echo "<td class=''>$tran[subjname]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq1]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq2]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq3]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq4]</td>";
                                            Echo "</tr>";
                                        }
                                        Echo "</table>";
                                        Echo "</td>";
                                    }
                                } elseif ($pmain['section'] == 'S') {
                                    if ($_POST["dtype"] == 2) {
                                        Echo "<tr style='height:10px;'>";
                                        Echo "<td colspan='25'>";
                                        Echo "<table style='width:100%;' id='tabital' class='table table-condensed table-hover table-bordered'>";
                                        Echo "<th style='background: #007DFF;;width:10%;'>Sr</th>";
                                        Echo "<th style='background-color: #007DFF;width:30%;'>Subject</th>";
                                        Echo "<th style='background-color: #007DFF;width:10%;' class='text-right'>Fifth</th>";
                                        Echo "<th style='background-color: #007DFF;width:10%;' class='text-right'>Sixth</th>";
                                        Echo "<th style='background-color: #007DFF;width:10%;' class='text-right'>Seventh</th>";
                                        Echo "<th style='background-color: #007DFF;width:10%;' class='text-right'>Eight</th>";
                                        Echo "<th style='background-color: #007DFF;width:10%;' class='text-right'>Ninth</th>";
                                        Echo "<th style='background-color: #007DFF;width:10%;' class='text-right'>Tenth</th>";
                                        Echo "<tr>";

                                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                                        $ctr2 = 0;
                                        while ($tran = mysqli_fetch_array($gettran)) {

                                            $ctr2++;
                                            Echo "<tr>";
                                            Echo "<td>$ctr2</td>";
                                            Echo "<td class=''>$tran[subjname]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq5]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq6]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq7]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq8]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq9]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pq10]</td>";
                                            Echo "</tr>";
                                        }
                                        Echo "</table>";
                                        Echo "</td>";
                                    }
                                } elseif ($pmain['section'] == 'M') {
                                    if ($_POST["dtype"] == 2) {
                                        Echo "<tr style='height:10px;'>";
                                        Echo "<td colspan='25'>";
                                        Echo "<table style='width:100%;' id='tabital' class='table table-condensed table-hover table-bordered'>";
                                        Echo "<th style='background: #007DFF;;width:10%;'>Sr</th>";
                                        Echo "<th style='background-color: #007DFF;width:50%;'>Subject</th>";
                                        Echo "<th style='background-color: #007DFF;width:40%;' class='text-right'>Prelim</th>";
                                        Echo "<tr>";


                                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                                        $ctr2 = 0;
                                        while ($tran = mysqli_fetch_array($gettran)) {

                                            $ctr2++;
                                            Echo "<tr>";
                                            Echo "<td>$ctr2</td>";
                                            Echo "<td class=''>$tran[subjname]</td>";
                                            Echo "<td class='numeric' 'text-right'>$tran[pqrelm]</td>";
                                            Echo "</tr>";
                                        }
                                        Echo "</table>";
                                        Echo "</td>";
                                    }
                                }
                            }
                            ?>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <?php include("includes/linksfoot.php");
        ?>
    </body>
    </html>
    <?php
}
if (isset($_POST["excel"])) {

    $code = $_POST["custcode"];
    $school = $_POST["name"];
    $medium = $_POST["medmcode"];
    $exam = $_POST["exam"];
    $section = $_POST["section"];
    $session = $_POST["session"];
    $dtye = $_POST["dtype"];

    if (!empty($code)) {
        $codecond = " AND `custcode` = '$code' ";
    }
    if (!empty($school)) {
        $schoolcond = " AND `accode` = '$school' ";
    }
    if (!empty($medium)) {
        $mediumcond = " AND `medmcode` = '$medium '";
    }
    if (!empty($exam)) {
        $examcond = " AND `examcode` = '$exam' ";
    }
    if (!empty($section)) {
        $sectioncond = " AND `section` = '$section'";
    }
    if (!empty($session)) {
        $sessioncond = " AND `session` = '$session'";
    }
    if (!empty($dtype)) {
        $dtypecond = " AND `dtype`= '$dtype' ";
    }

    if (empty($_POST["frmdt"])) {
        browse("From Date Cannot Be Empty");
        header("refresh:1; saleitemgrp.php");
    }
    if (empty($_POST["todt"])) {
        browse("To Date Cannot Be Empty");
        header("refresh:1; saleitemgrp.php");
    }

    $mfrmdate = trim($_POST["frmdt"]);
    $mtodate = trim($_POST["todt"]);

    $mfdt = date("d-m-Y", strtotime($mfrmdate));
    $mtdt = date("d-m-Y", strtotime($mtodate));

    $getpmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM `$maindb` WHERE `vouchdt` >= '$mfrmdate' 
                            AND `vouchdt` <= '$mtodate' AND concat(custcode, section , examcode ,medmcode , session)
                            not in(select concat(custcode, section , examcode ,medmcode , session) from invmain )
                            $codecond $schoolcond $mediumcond $examcond $sectioncond $sessioncond ")or die(mysqli_error($conn));

    $get = mysqli_num_rows($getpmain);

    $gexam = mysqli_query($conn, "SELECT `code`,`name` FROM `exam` WHERE `code`= '$exam' ")or die(mysqli_error($conn));
    $dexam = mysqli_fetch_array($gexam);


    $comp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
    $zcomp = mysqli_fetch_assoc($comp);

    $contents .= "Sr.,Date,Bill.No,Code,School Name,Section,Session,Medium,Exam,\n";

    $ctr = 0;

    while ($pmain = mysqli_fetch_array($getpmain)) {

        $gschool = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$pmain[accode]' ")or die(mysqli_error($conn));
        $sschool = mysqli_fetch_array($gschool);

        $gmedm = mysqli_query($conn, "SELECT `code`,`name` FROM `medium` WHERE `code`= '$pmain[medmcode]' ")or die(mysqli_error($conn));
        $smedm = mysqli_fetch_array($gmedm);

        $gexam = mysqli_query($conn, "SELECT `code`,`name` FROM `exam` WHERE `code`= '$pmain[examcode]' ")or die(mysqli_error($conn));
        $fexam = mysqli_fetch_array($gexam);

        $ctr++;

        $contents .= $ctr . ",";
        $contents .= $pmain['mydt'] . ",";
        $contents .= $pmain['vouchno'] . ",";
        $contents .= $pmain['custcode'] . ",";
        $contents .= $sschool['name'] . ",";

        if ($pmain['section'] == 'P') {
            $sectn = Primary;
        } elseif ($pmain['section'] == 'S') {
            $sectn = Secondry;
        } else {
            $sectn = Prelims;
        }
        $contents .= $sectn . ",";

        if ($pmain['session'] == 'M') {
            $sessn = Morning;
        } else {
            $sessn = Afternoon;
        }

        $contents .= $sessn . ",";
        $contents .= $smedm['name'] . ",";
        $contents .= $fexam['name'] . "\n";

        if ($pmain[section] == 'P') {
            if ($_POST["dtype"] == 2) {

                $contents .= "Sr.,Subject,First,Second,Third,Fourth\n";

                $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                $ctr2 = 0;
                while ($tran = mysqli_fetch_array($gettran)) {

                    $ctr2++;
                    $contents .= $ctr . ",";
                    $contents .= $tran['subjname'] . ",";
                    $contents .= $tran['pq1'] . ",";
                    $contents .= $tran['pq2'] . ",";
                    $contents .= $tran['pq3'] . ",";
                    $contents .= $tran['pq4'] . "\n";
                }
            }
        } elseif ($pmain[section] == 'S') {
            if ($_POST["dtype"] == 2) {

                $contents .= "Sr.,Subect,Fifth,Sixth,Seventh,Eight,Ninth,Tenth\n";


                $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                $ctr2 = 0;
                while ($tran = mysqli_fetch_array($gettran)) {

                    $ctr2++;
                    $contents .= $ctr2 . ",";
                    $contents .= $tran['subjname'] . ",";
                    $contents .= $tran['pq5'] . ",";
                    $contents .= $tran['pq6'] . ",";
                    $contents .= $tran['pq7'] . ",";
                    $contents .= $tran['pq8'] . ",";
                    $contents .= $tran['pq9'] . ",";
                    $contents .= $tran['pq10'] . "\n";
                }
            }
        } elseif ($pmain['section'] == 'M') {
            if ($_POST["dtype"] == 2) {

                $contents .= "Sr.,Subject,Prelims\n";

                $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                $ctr2 = 0;
                while ($tran = mysqli_fetch_array($gettran)) {

                    $ctr2++;
                    $contents .= $ctr2 . ",";
                    $contents .= $tran['subjname'] . ",";
                    $contents .= $tran['pqrelm'] . "\n";
                }
            }
        }
    }

    $contents = strip_tags($contents);

    if ($_POST["dtype"] == 1) {
        header("Content-Disposition: attachment; filename=$formname" . "_Summary" . date('d-m-Y') . ".csv");
        print $contents;
    } else {
        header("Content-Disposition: attachment; filename=$formname" . "_Detail" . date('d-m-Y') . ".csv");
        print $contents;
    }
}
if (isset($_POST["subpdf"])) {
    $code = $_POST["custcode"];
    $school = $_POST["name"];
    $medium = $_POST["medmcode"];
    $exam = $_POST["exam"];
    $section = $_POST["section"];
    $session = $_POST["session"];
    $dtye = $_POST["dtype"];

    if (!empty($code)) {
        $codecond = " AND `custcode` = '$code' ";
    }
    if (!empty($school)) {
        $schoolcond = " AND `accode` = '$school' ";
    }
    if (!empty($medium)) {
        $mediumcond = " AND `medmcode` = '$medium '";
    }
    if (!empty($exam)) {
        $examcond = " AND `examcode` = '$exam' ";
    }
    if (!empty($section)) {
        $sectioncond = " AND `section` = '$section'";
    }
    if (!empty($session)) {
        $sessioncond = " AND `session` = '$session'";
    }
    if (!empty($dtype)) {
        $dtypecond = " AND `dtype`='$dtype' ";
    }
    if (empty($_POST["frmdt"])) {
        browse("From Date Cannot Be Empty");
        header("refresh:1; saleitemgrp.php");
    }
    if (empty($_POST["todt"])) {
        browse("To Date Cannot Be Empty");
        header("refresh:1; saleitemgrp.php");
    }

    $mfrmdate = trim($_POST["frmdt"]);
    $mtodate = trim($_POST["todt"]);

    $mfdt = date("d-m-Y", strtotime($mfrmdate));
    $mtdt = date("d-m-Y", strtotime($mtodate));

    $getpmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM `$maindb` WHERE `vouchdt` >= '$mfrmdate' 
                            AND `vouchdt` <= '$mtodate' AND concat(custcode, section , examcode ,medmcode , session)
                            not in(select concat(custcode, section , examcode ,medmcode , session) from invmain )
                            $codecond $schoolcond $mediumcond $examcond $sectioncond $sessioncond ")or die(mysqli_error($conn));

    $get = mysqli_num_rows($getpmain);

    $gexam = mysqli_query($conn, "SELECT `code`,`name` FROM `exam` WHERE `code`= '$exam' ")or die(mysqli_error($conn));
    $dexam = mysqli_fetch_array($gexam);

    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('L', 'mm', 'A4');

    $pdf->AliasNbPages();

    $pdf->AddPage();
    $pdf->SetFont('Arial', 'I', 10);
    $pdf->SetTextColor(255, 255, 255);
    $pdf->SetFillColor(96, 130, 191);
    $pdf->Cell(8, 7, "Sr.", 1, 0, '', 1);
    $pdf->Cell(20, 7, "Date", 1, 0, '', 1);
    $pdf->Cell(20, 7, "Bill. No.", 1, 0, '', 1);
    $pdf->Cell(20, 7, "Code", 1, 0, '', 1);
    $pdf->Cell(90, 7, "School Name", 1, 0, '', 1);
    $pdf->Cell(30, 7, "Section", 1, 0, '', 1);
    $pdf->Cell(30, 7, "Session", 1, 0, '', 1);
    $pdf->Cell(30, 7, "Medium", 1, 0, '', 1);
    $pdf->Cell(30, 7, "Exam", 1, 0, '', 1);
    $pdf->SetFont('Arial', '', 1, 0);

    $pdf->SetTextColor(0, 0, 0);
    $pdf->Ln();
    $ctr = 0;

    while ($pmain = mysqli_fetch_array($getpmain)) {

        $gschool = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$pmain[accode]' ")or die(mysqli_error($conn));
        $sschool = mysqli_fetch_array($gschool);

        $gmedm = mysqli_query($conn, "SELECT `code`,`name` FROM `medium` WHERE `code`= '$pmain[medmcode]' ")or die(mysqli_error($conn));
        $smedm = mysqli_fetch_array($gmedm);

        $gexam = mysqli_query($conn, "SELECT `code`,`name` FROM `exam` WHERE `code`= '$pmain[examcode]' ")or die(mysqli_error($conn));
        $fexam = mysqli_fetch_array($gexam);

        $ctr++;
        $pdf->SetFont('Arial', '', 8);
        $pdf->Cell(8, 7, "$ctr", 1);
        $pdf->Cell(20, 7, "$pmain[mydt]", 1);
        $pdf->Cell(20, 7, "$pmain[vouchno]", 1);
        $pdf->Cell(20, 7, "$pmain[custcode]", 1);
        $pdf->Cell(90, 7, "$sschool[name]", 1);
        if ($pmain['section'] == 'P') {
            $sectn = 'Primary';
        } elseif ($pmain['section'] == 'S') {
            $sectn = 'Secondry';
        } else {
            $sectn = 'Prelims';
        }
        $pdf->Cell(30, 7, "$sectn", 1);
        if ($pmain['session'] == 'M') {
            $sessn = 'Morning';
        } else {
            $sessn = 'Afternoon';
        }
        $pdf->Cell(30, 7, "$sessn", 1);
        $pdf->Cell(30, 7, "$smedm[name]", 1);
        $pdf->Cell(30, 7, "$fexam[name]", 1);
        $pdf->Ln();

        if ($pmain['section'] == 'P') {
            if ($_POST["dtype"] == 2) {

                $pdf->SetFont('Arial', 'I', 10);
                $pdf->SetTextColor(255, 255, 255);
                $pdf->SetFillColor(96, 130, 191);
                $pdf->Cell(8, 7, "Sr.", 1, 0, '', 1);
                $pdf->Cell(54, 7, "Subject", 1, 0, '', 1);
                $pdf->Cell(54, 7, "First", 1, 0, '', 1);
                $pdf->Cell(54, 7, "Second", 1, 0, '', 1);
                $pdf->Cell(54, 7, "Third", 1, 0, '', 1);
                $pdf->Cell(54, 7, "Fourth", 1, 0, '', 1);
                $pdf->SetFont('Arial', '', 1, 0);

                $pdf->SetTextColor(0, 0, 0);
                $pdf->Ln();

                $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                $ctr2 = 0;
                while ($tran = mysqli_fetch_array($gettran)) {

                    $ctr2++;
                    $pdf->SetFont('Arial', '', 8);
                    $pdf->Cell(8, 7, "$ctr2", 1);
                    $pdf->Cell(54, 7, "$tran[subjname]", 1);
                    $pdf->Cell(54, 7, "$tran[pq1]", 1);
                    $pdf->Cell(54, 7, "$tran[pq2]", 1);
                    $pdf->Cell(54, 7, "$tran[pq3]", 1);
                    $pdf->Cell(54, 7, "$tran[pq4]", 1);
                    $pdf->Ln();
                }
            }
        } elseif ($pmain['section'] == 'S') {
            if ($_POST["dtype"] == 2) {
                $pdf->SetFont('Arial', 'I', 10);
                $pdf->SetTextColor(255, 255, 255);
                $pdf->SetFillColor(96, 130, 191);
                $pdf->Cell(8, 7, "Sr.", 1, 0, '', 1);
                $pdf->Cell(42, 7, "Subject", 1, 0, '', 1);
                $pdf->Cell(38, 7, "Fifth", 1, 0, '', 1);
                $pdf->Cell(38, 7, "Sixth", 1, 0, '', 1);
                $pdf->Cell(38, 7, "Seventh", 1, 0, '', 1);
                $pdf->Cell(38, 7, "Eight", 1, 0, '', 1);
                $pdf->Cell(38, 7, "Ninth", 1, 0, '', 1);
                $pdf->Cell(38, 7, "Tenth", 1, 0, '', 1);
                $pdf->SetFont('Arial', '', 1, 0);

                $pdf->SetTextColor(0, 0, 0);
                $pdf->Ln();


                $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                $ctr2 = 0;
                while ($tran = mysqli_fetch_array($gettran)) {

                    $ctr2++;
                    $pdf->SetFont('Arial', '', 8);
                    $pdf->Cell(8, 7, "$ctr2", 1);
                    $pdf->Cell(42, 7, "$tran[subjname]", 1);
                    $pdf->Cell(38, 7, "$tran[pq5]", 1);
                    $pdf->Cell(38, 7, "$tran[pq6]", 1);
                    $pdf->Cell(38, 7, "$tran[pq7]", 1);
                    $pdf->Cell(38, 7, "$tran[pq8]", 1);
                    $pdf->Cell(38, 7, "$tran[pq9]", 1);
                    $pdf->Cell(38, 7, "$tran[pq10]", 1);
                    $pdf->Ln();
                }
            }
        } elseif ($pmain['section'] == 'M') {
            if ($_POST["dtype"] == 2) {
                $pdf->SetFont('Arial', 'I', 10);
                $pdf->SetTextColor(255, 255, 255);
                $pdf->SetFillColor(96, 130, 191);
                $pdf->Cell(8, 7, "Sr.", 1, 0, '', 1);
                $pdf->Cell(135, 7, "Subject", 1, 0, '', 1);
                $pdf->Cell(135, 7, "Prelim", 1, 0, '', 1);
                $pdf->SetFont('Arial', '', 1, 0);

                $pdf->SetTextColor(0, 0, 0);
                $pdf->Ln();

                $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$pmain[vouchno]'")or die(mysqli_error($conn));
                $ctr2 = 0;
                while ($tran = mysqli_fetch_array($gettran)) {

                    $ctr2++;
                    $pdf->SetFont('Arial', '', 8);
                    $pdf->Cell(8, 7, "$ctr2", 1);
                    $pdf->Cell(135, 7, "$tran[subjname]", 1);
                    $pdf->Cell(135, 7, "$tran[pqrelm]", 1);
                    $pdf->Ln();
                }
            }
        }
    }
    $pdf->Output("Pending Bills.pdf", "D");
}
?>
