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

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

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

$maindb = 'demdmain';
$trandb = 'demdtran';

$zroot = $_SESSION["zdbroot"];
$formname = 'Demand Form Print';
$root = 'apps4rea_epi_root';
$vouchno = $_GET['vouchno'];
$para = $_GET['para'];

##############################Print Start Here##################################
    
$qmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt FROM $maindb  WHERE vouchno='$vouchno' order by vouchno") or die(mysqli_error($conn));
$fmain = mysqli_fetch_array($qmain);

if ($fmain['section'] == 'P') {
    $section = "Primary";
} elseif ($fmain['section'] == 'S') {
    $section = "Secondary";
} elseif ($fmain['section'] == 'M') {
    $section = "Prelim";
}

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

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

$gschl = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `grpcode` = '010' and `accode` = '$fmain[accode]'") or die(mysqli_error($conn));
$fschl = mysqli_fetch_array($gschl);

$gcent = mysqli_query($conn, "SELECT * FROM `center` WHERE `centcode` = '$fschl[centcode]'") or die(mysqli_error($conn));
$fcent = mysqli_fetch_array($gcent);

$vouch = $get['increvouch'];
if ($vouch == 0) {
    $vouch = $vouchno;
}

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

include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>

    body{
        font-size: 15px;

    }
    .mtable{
        border:1px solid black;
        boder-collapse:collapse;
    }
    .mtd{
        border:1px solid black;
        boder-collapse:collapse;
        text-align:right;
    }

    .fsize{
        font-size:15px;
    }

    td,th{
        padding:0px;
        font-size:15px;
    }

    .padd{
        padding:15px;
    }

    .padd2{
        padding:4px;
    }

    .padd3{
        padding:7px;
    }

    .padd4{
        bottom-padding:7px;
    }

    .border{
        border-top-style:solid;
        border-right-style:solid;
        border-left-style:solid;
        border-bottom-style:none;
        border-width:1px;
    }
    .border2{
        border-top-style:none;
        border-right-style:solid;
        border-left-style:solid;
        border-bottom-style:solid;
        border-width:1px;
    }

    table{
        width:100%;
        /*border : 1px solid black;*/
    }


</style>
</head>
<body>    
    <div class="page">
        <div class="col-lg-11"></div>
        <div class="col-lg-1">
            <a  class="btn btn-primary goback"  onclick="window.close()">Go Back</a>
        </div>

        <div class="subpage" style="margin-top:5px;width:100%;">
            <div class="row">
                <table width="100%" style="border-bottom: 1px solid black;padding:5px">
                    <tr>
                        <td style="font-size:17px;padding:3px;font-family: serif"><b><center><?php echo $zcomp['compname']; ?></center></b></td>
                    </tr>
                    <tr>
                        <td style="font-size:12px"><center>
                        REG.NO. BOMOBAY P.T.ACT 1950/F 17203 PUNE /SOCIETY'S REG.ACT 1860 MAHARASHTRA/ 330 - 2000/ PUNE
                    </center></td>
                    </tr>
                    <tr>
                        <td style="font-size:13px;font-family: serif;padding-top: 5px"><center><?php echo $zcomp['add1'] . $zcomp['add2']; ?></center></td>
                    </tr>
                    <tr>
                        <td style="font-size:13px;font-family: serif"><center><?php echo $zcomp['add3'] . "&nbsp;" . "&nbsp;" . "&nbsp;" . $zcomp['tel']; ?></center></td>
                    </tr>
                </table>
            </div>

            <table style="width:100%">
                <tr>
                    <td style ="width:33%"></td>
                    <td style ="width:33%;" class="fsize padd"><b><?php echo $section; ?>&nbsp;Section</b></td>
                    <td style ="width:34%; font-size:24px;padding-left: 80px" class="padd"><b><?php echo $fmain['custcode']; ?></b></td>
                </tr>
            </table>
            <table style="width:100%">
                <tr>
                    <td style="padding-left:105px;width:60%"><b>Voucher No.<span style="padding-right:5px"></span> :&nbsp; <?php echo $vouch; ?></b></td>
                    <td style ="width:40%"><b>Date<span style="padding-right:10px"></span> : <?php echo $fmain['mydt']; ?></b></td>
                </tr>
                <tr>
                    <td style="padding-left:105px;"colspan="2"><b>Ref.No<span style="padding-right:37px"></span> :&nbsp; <?php echo $fmain['custcode'] . ' -  ' . $fschl['name']; ?></b></td>
                </tr>
            </table>

            <table style="width:100%">
                <tr>
                    <td style="width:26%"></td>
                    <td style="width:74%"><?php echo $fschl['add1'] . ' ' .  $fschl['add2'] ; ?></td>
                </tr>
                <tr>
                    <td style="width:26%"></td>
                    <td style="width:74%"><?php echo $fschl['add3'] . ' ' . $fschl['city'] . '  ' . $fschl['pin']; ?></td>
                </tr>
                <tr>
                    <td style="width:26%"></td>
                    <td style="width:74%"><?php
                        if (!empty($fschl['tel'])) {
                            echo $fschl['tel'] . " / ";
                        }
                        ?>  <?= $fschl['mobile'] ?></td>
                </tr>
            </table>

            <table>
<!--                <tr>
                    <td  style="width:50%;padding-left: 112px" >&nbsp;</td>
                    <td  style="width:50%"><span style="padding-right:40px">&nbsp;</td>
                </tr>-->
                <tr>
                    <td  style="width:50%;padding-left: 112px" ><b>Medium</b><span style="padding-right:25px"></span>:&nbsp;&nbsp;<?php echo $fmedm['name']; ?></td>
                    <td  style="width:50%"><span style="padding-right:69px"></span><b>Exam</b>
                        <span style="padding-right:11px"></span>:&nbsp;&nbsp;<?php echo $fexam['name']; ?></td>
                </tr>
                <tr>
                    <td style="width:50%;padding-left: 112px"><b>Section</b><span style="padding-right:28px"></span>:&nbsp;&nbsp;<?php echo $section; ?></td>
                    <td class="padd3"><span style="padding-right:50px"></span><b>Session</b><span style="padding-right:12px"></span> :&nbsp;&nbsp;<?php echo $session; ?></td>
                </tr>
                <tr>
                    <td class="padd3"></td>
                    <td class="padd3"></td>
                </tr>
            </table>

            <?php if ($fmain[section] == "P") { ?>
                <table style="width:56%;" align="center" >

                    <tr>
                        <!--<td style="width:3%" class="mtable padd2"><b>Sr.No</b></td>-->
                        <td style="width:24%; text-align:left;" class="mtable padd2"><b>Subject</b></td>
                        <td style="width:7%; text-align:right; " class="mtable padd2"><b>I</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>II</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>III</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>IV</b></td>
                    </tr>

                    <?php
                    $ctr = 0;
                    $gtran = mysqli_query($conn, "SELECT * FROM $trandb where `vouchno` = '$fmain[vouchno]'") or die(mysqli_error($conn));
                    while ($ftran = mysqli_fetch_array($gtran)) {
                        $ctr++;

                        echo "<tr>";
//                        echo "<td style='' class='mtable padd2'>$ctr</td>";
                        echo "<td style='text-align:left' class='mtable padd2'>$ftran[subjname]</td>";
                        if ($ftran['pq1'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq1]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        if ($ftran['pq2'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq2]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        if ($ftran['pq3'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq3]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        if ($ftran['pq4'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq4]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        echo "</tr>";
                    }
                    ?>
                </table>

                <table style="width:56%;" align="center">
                    <tr class="border">
                        <td style="width:16%" class="padd2"><b>No Pack:</b></td>
                        <td style="width:40%" class="padd2"><b><?php echo $fmain['nopack']; ?></b></td>
                    </tr>
                    <tr class="border2">
                        <td style="width:16%" class=" padd2"><b>Center:</b></td>
                        <td style="width:40%" class="padd2"><b><?php echo $fcent['name']; ?></b></td>
                    </tr>
                </table>
            <?php } elseif ($fmain['section'] == "S") { ?>

                <table style="width:70%;" align="center">

                    <tr>
                        <!--<td style="width:3%" class="mtable padd2"><b>Sr.No</b></td>-->
                        <td style="width:25%; text-align:left;" class="mtable padd2"><b>Subject</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>V</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>VI</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>VII</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>VIII</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>IX</b></td>
                        <td style="width:7%; text-align:right;" class="mtable padd2"><b>X</b></td>
                    </tr>

                    <?php
                    $ctr = 0;
                    $gtran = mysqli_query($conn, "SELECT * FROM $trandb where `vouchno` = '$fmain[vouchno]'") or die(mysqli_error($conn));
                    while ($ftran = mysqli_fetch_array($gtran)) {
                        $ctr++;


                        echo "<tr>";
//                        echo "<td style='' class='mtable padd2'>$ctr</td>";
                        echo "<td style='text-align:left' class='mtable padd2'>$ftran[subjname]</td>";
                        if ($ftran['pq5'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq5]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'></td>";
                        }
                        if ($ftran['pq6'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq6]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        if ($ftran['pq7'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq7]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        if ($ftran['pq8'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq8]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        if ($ftran['pq9'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq9]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        if ($ftran['pq10'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pq10]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        echo "</tr>";
                    }
                    ?>
                </table>

                <table style="width:70%;" align="center">
                    <tr class="border">
                        <td style="width:10%;" class="padd2"><b>No Pack:</b></td>
                        <td style="width:60%; text-align:left;" class="padd2"><b><?php echo $fmain['nopack']; ?></b></td>
                    </tr>
                    <tr class="border2">
                        <td style="width:10%;" class="padd2"><b>Center</b></td>
                        <td style="width:60%; text-align:left;" class="padd2"><b><?php echo $fcent['name']; ?></b></td>
                    </tr>
                </table>
            <?php } elseif ($fmain['section'] == "M") { ?>

                <table style="width:53%;" align="center">

                    <tr>
                        <!--<td style="width:3%" class="mtable padd2"><b>Sr.No</b></td>-->
                        <td style="width:42%; text-align:left;" class="mtable padd2"><b>Subject</b></td>
                        <td style="width:11%; text-align:right;" class="mtable padd2"><b>Prelim</b></td>
                    </tr>

                    <?php
                    $ctr = 0;
                    $gtran = mysqli_query($conn, "SELECT * FROM $trandb where `vouchno` = '$fmain[vouchno]'") or die(mysqli_error($conn));
                    while ($ftran = mysqli_fetch_array($gtran)) {
                        $ctr++;


                        echo "<tr>";
//                        echo "<td style='' class='mtable padd2'>$ctr</td>";
                        echo "<td style='text-align:left' class='mtable padd2'>$ftran[subjname]</td>";
                        if ($ftran['pqrelm'] > 1) {
                            echo "<td style='text-align:right' class='mtable padd2 fsize'>$ftran[pqrelm]</td>";
                        } else {
                            echo "<td style='text-align:right' class='mtable padd2'></td>";
                        }
                        echo "</tr>";
                    }
                    ?>
                    
                </table>

            <table style="width:53%;border:1px solid black" align="center">
                    <tr>
                        <td style="font-size:14px" colspan="2" class="padd2"><b>No Pack&nbsp;:&nbsp;</b><?php echo $fmain['nopack']; ?></td>
                    </tr>
                    <tr>
                        <td style="font-size:14px" colspan="2" class="padd2"><b>Centre&nbsp;:&nbsp;</b><?php echo $fcent['name']; ?></td>
                    </tr>
                </table>
            <?php } ?>

        </div>
    </div>