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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];

$maindb = 'invmain';
$trandb = 'invtran';
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$zroot = $_SESSION["zdbroot"];

if (isset($_POST["view"])) {
    $formname = 'Bill Report';

    $frmvouch = $_POST["frmvouch"];
    $tovouch = $_POST["tovouch"];
    $section = $_POST["section"];
    $session = $_POST["session"];
    $exam = $_POST["exam"];

    if (!empty($exam)) {
        $examcond = " AND `examcode` = '$exam' ";
    }

    if (!empty($session)) {
        $sessioncond = " AND `session` = '$session' ";
    }

    if (!empty($section)) {
        $sectioncond = " AND `section` = '$section' ";
    }

    if (!empty($voucher)) {
        $vouchnocond = " AND `vouchno` = '$voucher' ";
    }

    if (!empty($frmvouch)) {
        $rangecond = "and demdvouch between $frmvouch and $tovouch ";
    }

    $gmain = mysqli_query($conn, "SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt  FROM `$maindb` WHERE `vouchno`!='' $rangecond $sectioncond 
                          $sessioncond $examcond") or die(mysqli_error($conn));

    $getno = mysqli_num_rows($gmain);

    if ($getno == 0) {
        browse("No Record Found");
        echo "<script>window.close()</script>";
    }

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

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

    <style>

        body{
            font-size: 10px;

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

        td,th,.t4{
            padding:5px;
            font-size:10px;
            font-size:10px;
        }
        .padd{
            padding:3px;
        }
        table{
            width:100%;
        }
        hr { 
            border-style: inset;
            border-width: 1px;
        } 
        .page {
            width: 210mm;
            min-height: 237mm;
            padding: 1mm;
            margin: 10mm auto;
            border: 1px #D3D3D3 solid;
            border-radius: 5px;
            background: white;

        }
        .subpage {
            padding-right: 0.5cm;
            padding-left: 0.5cm;
            /* padding: 0cm; */
            /* border: 1px solid; */
            height: 100%;
            outline: 2cm #ffffff solid;
        }

    </style>
    </head>
    <body>    
        <?php
        $ctr = 0;
        while ($pmain = mysqli_fetch_array($gmain)) {

            $gexam = mysqli_query($conn, "SELECT * FROM `exam` WHERE `code` = $pmain[examcode]");
            $shexam = mysqli_fetch_array($gexam);

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

            if ($pmain['section'] == 'P') {
                $ssection = "Primary";
            } elseif ($pmain['section'] == 'S') {
                $ssection = "Secondary";
            } elseif ($pmain['section'] == 'M') {
                $ssection = "Prelims";
            }

            $ctr++;
//
//            if ($ctr >= $getno ) {
//            }else{

            Echo '<div class="page">';
            Echo '<div class="subpage">';
            ?>
            <table width="100%" style="padding:5px; ">
                <tr>
                    <td style="font-size:17px;padding:3px;font-family: verdana"><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;" . "&nbsp;" . "Tel. -" . ' ' . $zcomp['tel']; ?></center></td>
        </tr>
        </table>

        <hr style="margin:0px;border:1px solid black">       
        <h4 class='text-center'><b>INVOICE</b></h4>
        <?php
        echo "<h5 class='text-center'><b>$ssection Section</b></h5>";
        ?>

        <table style="width:100%">
            <tr>
                <td style="width:12%"><b>BILL NO.&nbsp;&nbsp;&nbsp;&nbsp;:</b></td>
                <td style="width:53%; text-align:left" ><b><?php echo $pmain['vouchno']; ?></b></td>
                <td style="width:15%"><b>REF. NO.<span style="padding-right:44px;"></span>:</b></td>
                <td style="width:20%"><b><?php echo $sschool['custcode']; ?></b></td>
            </tr>

            <tr>
                <td style="width:12%"></td>
                <td style="width:53%"></td>
                <td style="width:15%"><b>DATE<span style="padding-right:65px;"></span>:</b></td>
                <td style="width:20%"><b><?php echo $pmain['mydt'] ?></b></td>
            </tr>

            <tr>
                <td style="width:12%"></td>
                <td style="width:53%"></td>
                <td style="width:15%"><b>EXAMINATION<span style="padding-right:8px "></span>:</b></td>
                <td style="width:20%"><b><?php echo $shexam['name'] ?></b></td>
            </tr>
        </table>               

        <table>
            <tr>
                <td style="width:50% ; padding:0px">TO,</td>
                <td style="width:50%"></td>
            </tr>

            <tr>
                <td style="width:50%;padding:0px">THE HEAD MASTER / HEAD MISTRESS</td>
                <td style="width:50%"></td>
            </tr>

            <tr>
                <td style="width:50%;padding:0px"><b><?php echo $sschool['name']; ?></b></td>
                <td style="width:50%"></td>
            </tr>

            <tr>
                <td style="width:50% ;padding:0px"><?php echo $sschool['add1']; ?></td>
                <td style="width:50%"></td>
            </tr>

            <tr>
                <td style="width:50%;padding:0px"><?php echo $sschool['add2']; ?></td>
                <td style="width:50%"></td>
            </tr>

            <tr>
                <td style="width:50%;padding:0px"><?php echo $sschool['add3']; ?></td>
                <td style="width:50%"></td>
            </tr>

            <tr>
                <td style="width:50%;padding:0px"><?php echo $sschool['city'] . " " . $sschool['pin']; ?></td>
                <td style="width:50%"></td>
            </tr>
        </table>

        <br>

        <table>
            <tr>
                <td>SIR / MADAM</td>
            </tr>

            <tr>
                <td><span style="padding-right:80px; "></span>Please refer your letter/indent for question papers.
                    Kindly arrange to remit the amount as shown below by 
                    CASH/CHEQUE/DEMAND DRAFT at an early date.
                </td>
            </tr>

        </table>

        <table class=" mtable">
            <?php
            if ($pmain['section'] == 'S') {
                ?> 
                <tr>
                    <td class="mtable padd" style="width:25%"><b>Subject</b></td>
                    <td class="mtd padd" style="width:9%"><b>V</b></td>
                    <td class="mtd padd" style="width:10%"><b>VI</b></td>
                    <td class="mtd padd" style="width:10%"><b>VII</b></td>
                    <td class="mtd padd" style="width:10%"><b>VIII</b></td>
                    <td class="mtd padd" style="width:10%"><b>IX</b></td>
                    <td class="mtd padd" style="width:10%"><b>X</b></td>
                    <td class="mtd padd" style="width:11%"><b>Amount</b></td>
                </tr>
                <?php
                $totamt = $ctrs = $ctr1 = 0;
                $gtran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno` = '$pmain[vouchno]' ") or die(mysqli_error($conn));
                $tranno = mysqli_num_rows($gtran);

//            if ($tranno > 18) {
                while ($tran = mysqli_fetch_array($gtran)) {

                    $srno2 = $tran['srno'];
                    $pq5 = $tran['pq5'];
                    $pq6 = $tran['pq6'];
                    $pq7 = $tran['pq7'];
                    $pq8 = $tran['pq8'];
                    $pq9 = $tran['pq9'];
                    $pq10 = $tran['pq10'];
                    $rt5 = $tran['rt5'];
                    $rt6 = $tran['rt6'];
                    $rt7 = $tran['rt7'];
                    $rt8 = $tran['rt8'];
                    $rt9 = $tran['rt9'];
                    $rt10 = $tran['rt10'];
                    $totpq2 = $pq5 + $pq6 + $pq7 + $pq8 + $pq9 + $pq10;

                    if ($totpq2 > 1) {
                        $ctrs++;
                        $ctr1++;
                        echo "<tr>";
                        echo "<td class='mtable'>$tran[subjname]</td>";
                        if ($pq5 > 1) {
                            echo "<td class='mtd'>$pq5 " . ' x ' . $rt5 . "</td>";
                        } else {
                            echo "<td class='mtd'></td>";
                        }
                        if ($pq6 > 1) {
                            echo "<td class='mtd'>$pq6 " . ' x ' . $rt6 . "</td>";
                        } else {
                            echo "<td class='mtd'></td>";
                        }
                        if ($pq7 > 1) {
                            echo "<td class='mtd'>$pq7 " . ' x ' . $rt7 . "</td>";
                        } else {
                            echo "<td class='mtd'></td>";
                        }
                        if ($pq8 > 1) {
                            echo "<td class='mtd'>$pq8 " . ' x ' . $rt8 . "</td>";
                        } else {
                            echo "<td class='mtd'></td>";
                        }
                        if ($pq9 > 1) {
                            echo "<td class='mtd'>$pq9 " . ' x ' . $rt9 . "</td>";
                        } else {
                            echo "<td class='mtd'></td>";
                        }
                        if ($pq10 > 1) {
                            echo "<td class='mtd'>$pq10 " . ' x ' . $rt10 . "</td>";
                        } else {
                            echo "<td class='mtd'></td>";
                        }
                        echo "<td class='mtd'>$tran[amount]</td>";
                        echo "</tr>";
                    }
//                    
                    $totamt = $totamt + $tran['amount'];
                }
                if ($ctr1 > 14) {
                    Echo "</table>";
                    ?>

                </div>
                </div>
                <br>

                ?>
                <div class="page">
                    <div class="subpage">

                        <table width="100%" style="padding:5px; ">
                            <tr>
                                <td style="font-size:17px;padding:3px;font-family: verdana"><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;" . "&nbsp;" . "Tel. -" . ' ' . $zcomp['tel']; ?></center></td>
                            </tr>
                        </table>
                        <hr style="margin:0px;border:1px solid black">
                        <h4 class='text-center'><b>INVOICE</b></h4>
                        <?php
                        echo "<h5 class='text-center'><b>$ssection Section</b></h5>";
                        ?>

                        <table style="width:100%">
                            <tr>
                                <td style="width:12%"><b>BILL NO.&nbsp;&nbsp;&nbsp;&nbsp;:</b></td>
                                <td style="width:53%; text-align:left" ><b><?php echo $pmain['vouchno']; ?></b></td>
                                <td style="width:15%"><b>REF. NO.<span style="padding-right:44px;"></span>:</b></td>
                                <td style="width:20%"><b><?php echo $sschool['custcode']; ?></b></td>
                            </tr>

                            <tr>
                                <td style="width:12%"></td>
                                <td style="width:53%"></td>
                                <td style="width:15%"><b>DATE<span style="padding-right:65px;"></span>:</b></td>
                                <td style="width:20%"><b><?php echo $pmain['mydt'] ?></b></td>
                            </tr>

                            <tr>
                                <td style="width:12%"></td>
                                <td style="width:53%"></td>
                                <td style="width:15%"><b>EXAMINATION<span style="padding-right:8px "></span>:</b></td>
                                <td style="width:20%"><b><?php echo $shexam['name'] ?></b></td>
                            </tr>
                        </table>               

                        <table>
                            <tr>
                                <td style="width:50% ; padding:0px">TO,</td>
                                <td style="width:50%"></td>
                            </tr>

                            <tr>
                                <td style="width:50%;padding:0px">THE HEAD MASTER / HEAD MISTRESS</td>
                                <td style="width:50%"></td>
                            </tr>

                            <tr>
                                <td style="width:50%;padding:0px"><b><?php echo $sschool['name']; ?></b></td>
                                <td style="width:50%"></td>
                            </tr>

                            <tr>
                                <td style="width:50% ;padding:0px"><?php echo $sschool['add1']; ?></td>
                                <td style="width:50%"></td>
                            </tr>

                            <tr>
                                <td style="width:50%;padding:0px"><?php echo $sschool['add2']; ?></td>
                                <td style="width:50%"></td>
                            </tr>

                            <tr>
                                <td style="width:50%;padding:0px"><?php echo $sschool['add3']; ?></td>
                                <td style="width:50%"></td>
                            </tr>

                            <tr>
                                <td style="width:50%;padding:0px"><?php echo $sschool['city'] . " " . $sschool['pin']; ?></td>
                                <td style="width:50%"></td>
                            </tr>
                        </table>
                        <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>                        
                        <?php
                    }
                } elseif ($pmain['section'] == 'P') {
                    ?> 
                    <tr>
                        <td class="mtable" style="width:24%"><b>Subject</b></td>
                        <td class="mtd" style="width:14%"><b>I</b></td>
                        <td class="mtd" style="width:14%"><b>II</b></td>
                        <td class="mtd" style="width:14%"><b>III</b></td>
                        <td class="mtd" style="width:14%"><b>IV</b></td>
                        <td class="mtd" style="width:15%"><b>Amount</b></td>
                    </tr>
                    <?php
                    $totamt = $ctrp = 0;
                    $gtran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno` = '$pmain[vouchno]' ") or die(mysqli_error($conn));
                    while ($tran = mysqli_fetch_array($gtran)) {


                        $srno = $tran['srno'];
                        $pq1 = $tran['pq1'];
                        $pq2 = $tran['pq2'];
                        $pq3 = $tran['pq3'];
                        $pq4 = $tran['pq4'];
                        $rt1 = $tran['rt1'];
                        $rt2 = $tran['rt2'];
                        $rt3 = $tran['rt3'];
                        $rt4 = $tran['rt4'];
                        $totpq = $pq1 + $pq2 + $pq3 + $pq4;

                        if ($totpq > 1) {
                            $ctrp++;

                            echo "<tr>";
                            echo "<td class='mtable'>$tran[subjname]</td>";
                            if ($pq1 > 1) {
                                echo "<td class='mtd'>$pq1 " . ' x ' . $rt1 . "</td>";
                            } else {
                                echo "<td class='mtd'></td>";
                            }
                            if ($pq2 > 1) {
                                echo "<td class='mtd'>$pq2 " . ' x ' . $rt2 . "</td>";
                            } else {
                                echo "<td class='mtd'></td>";
                            }
                            if ($pq3 > 1) {
                                echo "<td class='mtd'>$pq3 " . ' x ' . $rt3 . "</td>";
                            } else {
                                echo "<td class='mtd'></td>";
                            }
                            if ($pq4 > 1) {
                                echo "<td class='mtd'>$pq4 " . ' x ' . $rt4 . "</td>";
                            } else {
                                echo "<td class='mtd'></td>";
                            }
                            echo "<td class='mtd'>$tran[amount]</td>";
                            echo "</tr>";
                        }
                        $totamt = $totamt + $tran[amount];
                    }
                } elseif ($pmain['section'] == 'M') {
                    ?> 
                    <tr>
                        <td class="mtable" style="width:50%"><b>Subject</b></td>
                        <td class="mtd" style="width:15%"><b>Prelims</b></td>
                        <td class="mtd" style="width:15%"><b>Price Per Copy</b></td>
                        <td class="mtd" style="width:15%"><b>Amount</b></td>
                    </tr>
                    <?php
                    $totamt = $ctrm = 0;
                    $gtran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno` = '$pmain[vouchno]' ") or die(mysqli_error($conn));
                    while ($tran = mysqli_fetch_array($gtran)) {


                        $srno3 = $tran3['srno'];
                        $pqrelm = $tran['pqrelm'];
                        if ($pqrelm > 1) {
                            echo "<tr>";
                            echo "<td class='mtable'>$tran[subjname]</td>";
                            echo "<td class='mtd'>$pqrelm</td>";
                            echo "<td class='mtd'>$tran[rtprelm]</td>";
                            echo "<td class='mtd'>$tran[amount]</td>";
                            echo "</tr>";
                            $ctr++;
                        }
                        $totamt = $totamt + $tran['amount'];
                    }
                }
                ?>
                </table>

                <table class="mtable">
                    <tr>
                        <td  class="mtable"style="width:85%"></td>
                        <td class="mtd" style="width:15%"><b><?php echo number_format($totamt, 2, ".", ''); ?></b></td>
                    </tr>

                    <tr>
                        <td  class="mtable"style="width:85%">PACKET CHARGES FOR
                            <span style="padding-right:100px;"></span>
                            <?php echo $pmain['nopack']; ?>&nbsp;&nbsp;Packets@ 
                            <span style="padding-right:20px;"></span><i class="fa fa-inr"></i><?php echo $pmain['packrate'] ?> 
                            <span style="padding-right:20px;"></span>Per Packet
                        </td>
                        <td class="mtd" style="width:15%"><b><?php echo $pmain['packamt']; ?></b></td>
                    </tr>

                    <tr>
                        <td  class="mtable"style="width:85%">S.T PARCEL NO.- &nbsp;&nbsp;&nbsp;<?php echo $pmain['parcno'] ?></td>
                        <td class="mtd" style="width:15%"><b><?php echo $pmain['stamt']; ?></b></td>
                    </tr>

                    <tr>
                        <td  class="mtable"style="width:85%">OTHER CHARGES -&nbsp;&nbsp;&nbsp;<?php echo $pmain['other'] ?></td>
                        <td class="mtd" style="width:15%"><b><?php echo $pmain['otheramt']; ?></b></td>
                    </tr>
                    <?php
                    $tdtotamt = 0;
                    $tdtotamt = $tdtotamt + $totamt + $pmain['packamt'] + $pmain['stamt'] + $pmain['otheramt'];
                    ?>
                    <tr>
                        <td  class="mtable"style="width:85%">E.& O.E
                            <span style="padding-right:420px;"></span>Total(After Rounding)
                        </td>
                        <td class="mtd" style="width:15%"><b><i class="fa fa-inr"></i>&nbsp;<?php echo number_format($tdtotamt, 2, ".", ''); ?></b></td>
                    </tr>

                </table>

                <table>
                    <tr>
                        <td class="mtable">Rupees&nbsp;<?php echo rsword($tdtotamt); ?> Only</td>
                    </tr>
                </table>

                <table>
                    <tr>
                        <td style="width:50%; padding:3px; "></td>
                        <td style="width:50%; padding:3px;"><b>For MAHARASHTRA BHARATEEYA SHIKSHAN MANDAL
                            </b></td>
                    </tr>
                </table>

                <table>
                    <tr>
                        <td style="width:80%; padding:1px;"><i>NOTE:- PLEASE PAY YOUR DUES WITHIN 15 DAYS.
                            </i></td>
                        <td style="width:20%; padding:1px;"></td>
                    </tr>

                    <tr>
                        <td style="width:80%; padding:1px;"><span style="padding-right:40px"></span><i>
                                CHEQUE/PAY ORDER/DEMAND DRAFTS PAYMENT IN FAVOUR OF
                            </i></td>
                        <td style="width:20%; padding:1px;"></td>
                    </tr>

                    <tr>
                        <td style="width:80%; padding:1px;"><span style="padding-right:40px"></span>
                            "MAHARASHTRA BHARATEEYA SHIKSHAN MANDAL"
                        </td>
                        <td style="width:20%; padding:1px;"></td>
                    </tr>

                    <tr>
                        <td style="width:80%; padding:1px;"><span style="padding-right:40px"></span><i>
                                STRICTLY DEMAND DRAFT PAYMENT FOR SCHOOLS OUT OF MUMBAI AND THANE
                            </i></td>
                        <td style="width:20%; padding:1px;"></td>
                    </tr>
                    <tr>
                        <td style="width:80%; padding:1px;"><span style="padding-right:40px"></span><i>
                                COMPUTER GENERATED DOCUMENT SIGNATURE DENIED
                            </i></td>
                        <td style="width:20%; padding:1px;"></td>
                    </tr>
                </table>
            </div>
        </div>
        <br>
    <?php }
     include('includes/linksfoot.php'); 
     ?>
    </body>
    </html>
<?php }
?>