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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$zyear = right($zdb, 4);
$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');
mysqli_select_db($conn, $zdb);
$zroot = $_SESSION['zdir'];

$maindb = "billmain";
$trandb = "billtran";

$file = "bill_print.php";
$society = $_SESSION["society_" . $dbname];
$usertype = $_SESSION["usertype_" . $dbname];

$pzero = $_POST["pzero"];

if (empty($society)) {
    browse("Invalid Society Credentials Forced Logout.");
    print '<script type="text/javascript">';
    print " top.window.location = 'index.php'";
    print '</script>';
}

$getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `code` = '$society'") or die(mysqli_error($conn));
$company = mysqli_fetch_array($getcomp);
$latefeesname = $company['latefeesname'];

$ptype = $company['ptype'];
$registno = $company['gstno'];
$acinterest = $company['acinterest'];

$getacint = mysqli_query($conn, "SELECT name FROM `accmast` WHERE `series`='$society' and `accode` = '$acinterest' ");
$acinit = mysqli_fetch_array($getacint);

$billcycle = $company['billcycle'];

switch ($billcycle) {

    case 'M':
        $byname = 'MONTHLY';
        break;
    case 'BM':
        $byname = 'BI - MONTHLY';
        break;
    case 'Q':
        $byname = 'QUARTERLY';
        break;
    case 'H':
        $byname = 'HALF YEARLY';
        break;
    default:
        $byname = '';
}


$memb = $_POST["member"];
$flatno = $_POST["flatno"];
$yearno = $_POST["yearno"];
$pgtype = $_POST["pgtype"];

$fdate = $_GET['fdt'];
$vouchno = $_GET['mvouch'];

if ($_POST["billcode"] != '') {
    $billcode = $_POST["billcode"];
} else {
    $m = date_parse_from_format("Y-m-d", $fdate);
    $billcode = $m['month'];
}

//    switch ($billcycle) {
//        case 'M':
//            if ($billcode < 4) {
//                $cdate = strtotime($mtodate);
//            } else {
//                $cdate = strtotime($mfrdate);
//            }
//
//            $chkdate = date("Y", $cdate);
////            browse($chkdate);
//
//            break;
//        case 'BM':
//            if ($billcode == 6) {
//                $cdate = strtotime($mtodate);
//            } else {
//                $cdate = strtotime($mfrdate);
//            }
//
//            $chkdate = date("Y", $cdate);
//            break;
//        case 'Q':
//            if ($billcode == 4) {
//                $cdate = strtotime($mtodate);
//            } else {
//                $cdate = strtotime($mfrdate);
//            }
//
//            $chkdate = date("Y", $cdate);
//            break;
//        case 'H':
//            if ($billcode == 2) {
//                $cdate = strtotime($mtodate);
//            } else {
//                $cdate = strtotime($mfrdate);
//            }
//            $chkdate = date("Y", $cdate);
//            break;
//        default:
//            $chkdate = '';
//    }

$memcond = '';
$billcond = '';
$accond = '';
$accond2 = '';
$accond1 = '';

if (!empty($vouchno)) {
    $vouchcond = "and `vouchno` = '$vouchno'";
}

if ($usertype == 1) {

    if (!empty($_POST['flatno'])) {

        foreach ($_POST['flatno'] as $cucheck2) {
            $ccheckoth[$ccountoth++] .= "OR `accode` = '" . $cucheck2 . "' ";
        }

        foreach ($ccheckoth as $g => $valuesoth) {
            $cuscheckoth .= $valuesoth;
        }

        $accond1 = " AND (`accode` = '' " . $cuscheckoth . " )";
    }

    if (!empty($_POST['acname'])) {

        foreach ($_POST['acname'] as $cucheck2) {
            $ccheckoth[$ccountoth++] .= "OR `accode` = '" . $cucheck2 . "' ";
        }

        foreach ($ccheckoth as $g => $valuesoth) {
            $cuscheckoth .= $valuesoth;
        }

        $accond2 = " AND (`accode` = '' " . $cuscheckoth . " )";
    }
} else {
    if (!empty($memb)) {
        $memcond = "and `accode` = '$memb'";
    }
    if (!empty($flatno)) {
        $accond = "and `accode` = '$flatno'";
    }
}


if (!empty($billcode)) {
    $billcond = "and `billcode` = '$billcode'";
}
if (!empty($yearno)) {
    $yearcond = "and `yearno` = '$yearno'";
}


$getdata = mysqli_query($conn, "SELECT *, DATE_FORMAT(`billdate`, '%d-%m-%Y') as mydt FROM `$maindb` WHERE `society`='$society'
                           $billcond $accond1 $accond2 $memcond $vouchcond $accond $yearcond ORDER BY `newbill`") or die(mysqli_error($conn));
//print table($getdata);
//die();
//    return ;
//    $getacint = mysqli_query($conn, "SELECT accode,name FROM $zdb.`accmast` WHERE  `series`='$getvouch' and `init` = 'INT'  and grpcode='011' ");
//    $acinit = mysqli_fetch_array($getacint);

if (mysqli_num_rows($getdata) <= 0) {
    browse("No Records Found");
    echo "<script>"
    . "window.close();"
    . "</script>";
}
if (isset($_POST["view"]) || ($_GET['view'])) {

    include("includes/linkshead.php");
    ?>
    <link href="styles/inv_format.css" rel="stylesheet">
    <style>
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            /*background-color: #FAFAFA;*/
            font: 12pt "Tahoma";
        }

        * {
            box-sizing: border-box;
            -moz-box-sizing: border-box;
        }

        .padd {
            padding: 2px;
        }

        .page {
            width: 210mm;
            min-height: 113mm;
            padding: 2mm;
            margin: 6mm auto;
            border-radius: 2px;

        }

        .subpage {
            padding: 0cm;
            height: 150mm;
        }

        table {
            width: 100%;

        }

        .border {
            border: 1px solid;
        }

        hr {
            border: 1px dotted black;
            margin-top: 35px;
            margin-bottom: 35px;
        }

        .f10 {
            font-size: 10px;
        }

        .f9 {
            font-size: 9px;
        }

        .f8 {
            font-size: 8px;
        }
    </style>
    </head>
    <?php
    if ($pzero != "Y") {
        if ($getmdata['total'] > 0) {
            $a = 1;
        }
    }


    $ctr = 0;
    $pctr = 2;
    $intamt = 0;

    while ($getmdata = mysqli_fetch_array($getdata)) {
        $intamt = $getmdata['intamt'];
        $billdate = $getmdata['billdate'];
        $billpaym = $getmdata['billpaym'];
        $billpayd = $getmdata['billpayd'];
        $pctr++;
        $a = 1;

        if ($pzero != "Y") {
            if ($getmdata['total'] <= 0) {
                $a = 0;
            }
        }

        
        $bcode = mysqli_query($conn, "SELECT `code`,`descrip` FROM $zroot.`billingcycle` where `code` = '$getmdata[billcode]' 
                              and `billcycle`='$billcycle' ") or die(mysqli_error($conn));
        $scode = mysqli_fetch_array($bcode);
        $descrip = $scode['descrip'];
        
        
        $getmember = mysqli_query($conn, "SELECT `accode`,`name`, `name2`, `block`, `wing`,`flatno`,`add1`,`add2`,`add3`, openbal, dc,
                                 `area`,`unit`, `shop` FROM `accmast` WHERE `grpcode`='010' AND `accode`= '$getmdata[accode]'
                                  AND `series` ='$society'") or die(mysqli_error($conn));
        $member = mysqli_fetch_array($getmember);
        if ($member['unit'] == 'F') {
            $unit = 'Sq. Ft. ';
        } elseif ($member == 'M') {
            $unit = 'Sq. Mtr.';
        }

        $openbal = $member['openbal'];
        $opendc = $member['dc'];
        
//        browse($openbal) ;
//        browse($opendc) ;

        if ($opendc == 'D') {
            $open = $openbal * -1;
        } else {
            $open = $openbal;
        }


        $qrycode = mysqli_query($conn, "SELECT sum(amount) as openamt FROM actran where `accode` = '$getmdata[accode]' and date < '$billdate' ") or die(mysqli_error($conn));
        $fetcode = mysqli_fetch_array($qrycode);
        $openamt = $fetcode['openamt'];

        $openbal = $openamt + $open;
//        browse($openamt);
//        browse($open);
//        browse($openbal);

        $advance = 0;
        $arrears = 0;

        if ($openbal > 0) {
            $advance = $openbal;
        } else {
            $arrears = abs($openbal);
        }

        $totlamt = $getmdata['billamt'] + $arrears - $advance ;

        if ($billpaym == 'S') {
            //            $ddate = strtotime("+$billpayd days", strtotime($billdate));
            $ddate = strtotime($billdate);
            $month = date("m", $ddate);
            $year = date("Y", $ddate);
            $day = date('t', strtotime($billdate));
//            $day = cal_days_in_month(CAL_GREGORIAN, $month, $zyear);
            $duedate = $day . '-' . $month . '-' . $year;
            //                        $duedate = date('d-m-Y', $ddate);
        } else {
            $ddate = strtotime("+1 month $billpayd days", strtotime($billdate));
            $duedate = date('d-m-Y', $ddate);
        }

        if ($a > 0) {
            $ctr++;
            if ($pgtype == 1) {
                echo '<body id="main_container">';
                echo '<div class="book">';
                echo "<div class = 'page' style = ''>";
            } else {
                if ($ctr % 2 != 0) {
                    echo '<body id="main_container">';
                    echo '<div class="book">';
                    echo "<div class = 'page' style = ''>";
                }
                if ($ctr % 2 == 0) {
                    echo "<hr>";
                }
            }
            ?>

            <div style="border:1px solid black;">
                <table class="">
                    <tr>
                        <td class="text-center">
                            <h4 style="margin-top: 5px;margin-bottom: 5px"><strong><?php echo $company['compname'] ?></strong></h4>
                        </td>
                    </tr>
                    <tr>
                        <td class="text-center">
                            <?php echo $registno ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="text-center">
                            <?php echo $company['hoadd1'] ?>
                            <?php echo $company['hoadd2'] ?>
                            <?php echo $company['hoadd3'] ?>
                        </td>
                    </tr>
                </table>

                <table class="" align='center' style="height:35%;width:90%;">
                    <tr>
                        <td width="32%" class="text-left">
                            <b>Bill No. <span style='padding-right: 22px'></span>
                                :</b>&nbsp;<?php echo $getmdata['newbill']; ?>
                        </td>
                        <td width="69%" class="text-center"><span style='padding-right: 263px'></span>
                            <b>Date :</b>
                            <?php echo $getmdata['mydt']; ?>
                        </td>
                    </tr>
                </table>

                <!--<br>-->

                <table class="" align='center' style="height:35%;width:90%;">

                    <tr>
                        <td width="10%" class="text-left">
                            <label><strong>Name<span style="padding-left:33px"></span>:</strong></label>
                        </td>
                        <td width="62%" class="text-left">
                            <label style="text-transform: uppercase"><?php echo $member['name']; ?></label>
                        </td>
                        <td width="28%" class="text-left"><span style="padding-left:33px"></span>
                            <label><strong>Area&nbsp;:</strong>&nbsp;<?php echo $member['area'] . " " . $unit; ?></label>
                        </td>
                    </tr>
                    <tr>
                        <td width="11%" class="text-left">
                        </td>
                        <td width="59%" class="text-left">
                            <label style="text-transform: uppercase"><?php echo $member['name2']; ?></label>
                        </td>
                        <td width="30%" class="text-left"><span style="padding-left:33px"></span>
                        </td>
                    </tr>

                    <tr>
                        <td class="text-left">
                            <?php if ($member["shop"] == '1') { ?>
                                <label><strong>Shop No<span style="padding-left:25px"></span>:</strong></label>
                            <? } else { ?>
                                <label><strong>Flat No<span style="padding-left:25px"></span>:</strong></label>
                            <?php } ?>
                        </td>
                        <td class="text-left"><span style="padding-left:5px"></span>
                            <label><?php echo $member['flatno']; ?></label>
                        </td>
                        <td class="text-left"><span style="padding-left:5px"></span>
                            <label><b>Due Date :&nbsp;</b><?php echo $duedate ?></label>
                        </td>
                    </tr>

                    <tr>
                        <td class="text-center" colspan="3">
                            <label><strong>Bill For the Month of <?php echo $descrip; ?> - <?= $getmdata['yearno'] ?></strong></label>
                        </td>
                    </tr>

                </table>
                <?php
                $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `billno`='$getmdata[billno]' and `society`='$getmdata[society]' and
                                    amount > 0 order by srno") or die(mysqli_error($conn));
                $tran2 = mysqli_num_rows($gettran);

                if ($tran2 <= 7) {
                    ?>
                    <table class="" align='center' style="height:35%;width:90%;border:1px solid black;">
                        <tr style="border:1px solid black; background-color: #EFE4B0;">
                            <td style="width:10%;border-right:1px solid black;font-size: 15px; " class="padd"><strong>Sr.</strong></td>
                            <td style="width:50%;border-right:1px solid black;font-size: 15px;" class="padd"><strong>Description</strong></td>
                            <td style="width:20%;text-align: right;border-right:1px solid black;font-size: 15px;" class="padd"><strong>Amount</strong></td>
                        </tr>

                        <?php
                        $ctr2 = 0;
                        $extra = 0;
                        while ($tran = mysqli_fetch_array($gettran)) {

                            $gmaintype = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`='$tran[maintcode]' and `active`='1'") or die(mysqli_error($conn));
                            $smaintype = mysqli_fetch_array($gmaintype);
                            ?>
                            <?php
                            if ($tran['amount'] > 0) {
                                $ctr2++;

                                echo '<tr style="height:24px; border:1px solid black;">';
                                echo "<td class='padd' align='center' style='border-right:1px solid black;'>$ctr2</td>";
                                echo "<td class='padd' align='left' style='border-right:1px solid black;'>$smaintype[name]</td>";
                                echo "<td class='padd' align='right' style='border-right:1px solid black;'>$tran[amount]</td>";
                                echo "</tr>";
                                $extra = $extra + 1;
                            }
                        }
                        if ($intamt > 0) {
                            $mctr = $ctr2 + 1;
                            echo '<tr style="height:24px; border:1px solid black;">';
                            echo "<td class='padd' align='center' style='border-right:1px solid black;'>$mctr</td>";
//                        echo "<td class='padd' align='left' style='border-right:1px solid black;'>$acinit[name]</td>";
                            echo "<td class='padd' align='left' style='border-right:1px solid black;'>$latefeesname</td>";
                            echo "<td class='padd' align='right' style='border-right:1px solid black;'>$intamt</td>";
                            echo "</tr>";
                            $extra = $extra + 1;
                        }

                        if ($extra < 6) {
                            for ($i = $extra; $i < 6; $i++) {

                                echo '<tr style="height:24px; border:1px solid black;">';
                                echo "<td style='border-right:1px solid black;'></td>";
                                echo "<td style='border-right:1px solid black;'></td>";
                                echo "<td style='border-right:1px solid black;'></td>";
                                echo '</tr>';
                            }
                        }
                        ?>
                        <tr style="border-bottom: 1px solid black">
                            <td width="" class='' style=""></td>
                            <td width="" class='ttotclr text-right padd' style="border-right:1px solid black;">Bill Amount</td>
                            <td width="" class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo number_format($getmdata['billamt'], 2) . "<br>"; ?></td>
                        </tr>
                        <?php if ($advance > 0) { ?>
                            <tr style="border-bottom: 1px solid black">
                                <td class='' style=""></td>
                                <td class='ttotclr text-right padd' style="border-right: 1px solid black;">Advance</td>
                                <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo number_format($adv,2) ; ?></td>
                            </tr>
                            <?php
                        } else {
                            if ($arrears != 0) {
                                ?>
                                <tr style="border-bottom: 1px solid black">
                                    <td class='' style=""></td>
                                    <td class='ttotclr text-right padd' style="border-right: 1px solid black;">Arrears</td>
                                    <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo number_format($arrears,2) ; ?></td>
                                </tr>
                            <?php } else {
                                ?>
                                <tr style="border-bottom: 1px solid black">
                                    <td class='' style=""></td>
                                    <td class='ttotclr text-right padd' style="border-right: 1px solid black;"></td>
                                    <td class='ttotclr text-right padd'><i class=""></i> &nbsp;</td>
                                </tr>
                                <?
                            }
                        }

                        if ($getmdata['intprev'] > 0) {
                            ?>
                            <tr style="border-bottom: 1px solid black">
                                <td class='' style=""></td>
                                <td class='ttotclr text-right padd' style="border-right: 1px solid black;"><?php echo $acinit['name'] ?></td>
                                <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo number_format("$getmdata[intprev]", 2) . "<br>" ?></td>
                            </tr>
                        <? } else { ?>
                            <tr style="border-bottom: 1px solid black">
                                <td class='' style=""></td>
                                <td class='ttotclr text-right padd' style="border-right: 1px solid black;"></td>
                                <td class='ttotclr text-right padd'>&nbsp;</td>
                            </tr>
                        <? } ?>
                        <tr style="border-bottom: 1px solid black">
                            <td class='' style=""></td>
                            <td class='ttotclr text-right padd' style="border-right: 1px solid black;">Total</td>
                            <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo number_format("$totlamt", 2) . "<br>" ?></td>
                        </tr>
                    </table>

                <?php } else { ?>

                    <?php
                    $ctr1 = 0;
                    $ctr2 = 0;

                    while ($tran3 = mysqli_fetch_array($gettran)) {

                        if ($ctr1 == 0) {
                            if ($ctr2 == 0) {
                                ?>
                                <table class='' style='height:35%;width:45%;display: inline-block;margin-left: 38px;border-collapse: collapse;'>
                                <?php } else { ?>
                                    <table class='' style='height:35%;width:45%;display: inline-block;margin-left: 1px;border-collapse: collapse;'>
                                    <?php } ?>
                                    <tr style='border:1px solid black; background-color: #EFE4B0;'>
                                        <td style='width:5%;border-right:1px solid black;font-size: 15px; ' class='padd'><strong>Sr.</strong></td>
                                        <td style='width:25%;border-right:1px solid black;font-size: 15px;' class='padd'><strong>Description</strong></td>
                                        <td style='width:10%;text-align: right;border-right:1px solid black;font-size: 15px;' class='padd'><strong>Amount</strong></td>
                                    </tr>
                                    <?php
                                }

                                $tamt = $tran3['amount'];
                                $gmaintype = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`='$tran3[maintcode]' and `active`='1'") or die(mysqli_error($conn));
                                $smaintype = mysqli_fetch_array($gmaintype);
                                $ctr1++;
                                $ctr2++;

                                if ($tamt > 0) {

                                    echo '<tr style="height:24px; border:1px solid black;">';
                                    echo "<td class='padd' align='center' style='border-right:1px solid black;'>$ctr2</td>";
                                    echo "<td class='padd' align='left' style='border-right:1px solid black;'>$smaintype[name]</td>";
                                    echo "<td class='padd' align='right' style='border-right:1px solid black;'>$tran3[amount]</td>";
                                    echo "</tr>";
                                }
                                if ($ctr1 == 4) {
                                    $ctr1 = 0;
                                    $ctab = 0;
                                }
                                $ctab++;
                            }

                            if ($intamt > 0) {
                                $ctr2++;
                                $ctab = $ctab + 1;
                                echo '<tr style="height:24px; border:1px solid black;">';
                                echo "<td class='padd' align='center' style='border-right:1px solid black;'>$ctr2</td>";
                                echo "<td class='padd' align='left' style='border-right:1px solid black;'>INTEREST ON ARREARS</td>";
                                echo "<td class='padd' align='right' style='border-right:1px solid black;'>$intamt</td>";
                                echo "</tr>";
                            }
                            if ($ctab < 4) {
                                for ($i = $ctab; $i <= 4; $i++) {
                                    $ctab = $ctab + 1;

                                    if ($tamt > 0) {
                                        echo '<tr style="height:24px; border:1px solid black;">';
                                        echo "<td class='padd' align='center' style='border-right:1px solid black;'></td>";
                                        echo "<td class='padd' align='left' style='border-right:1px solid black;'></td>";
                                        echo "<td class='padd' align='right' style='border-right:1px solid black;'></td>";
                                        echo "</tr>";
                                    }
                                }
                            }
                            ?>
                        </table>

                        <table align='center' border="1" style="width:90%;">
                            <tr style="border-bottom: 1px solid black">
                                <td width="76%" class='ttotclr text-right padd' style="">Bill Amount</td>
                                <td width="14%" class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo number_format($getmdata['billamt'] + $intamt, 2) . "<br>"; ?></td>
                            </tr>
                            <?php if ($getmdata[advance] > 0) { ?>
                                <tr style="border-bottom: 1px solid black">
                                    <td class='ttotclr text-right padd' style="">Advance</td>
                                    <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo $adv; ?></td>
                                </tr>
                                <?php
                            } else {
                                if ($getmdata['arrears'] != 0) {
                                    ?>
                                    <tr style="border-bottom: 1px solid black">
                                        <td class='ttotclr text-right padd' style="">Arrears</td>
                                        <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo $getmdata['arrears']; ?></td>
                                    </tr>
                                <?php } else {
                                    ?>
                                    <tr style="border-bottom: 1px solid black">
                                        <td class='ttotclr text-right padd' style=""></td>
                                        <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;</td>
                                    </tr>   
                                    <?
                                }
                            }
                            if ($getmdata['intprev'] > 0) {
                                ?>
                                <tr style="border-bottom: 1px solid black">
                                    <td class='ttotclr text-right padd' style="border-right: 1px solid black;">Previous Interest</td>
                                    <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo number_format("$getmdata[intprev]", 2) . "<br>" ?></td>
                                </tr>
                            <? } else { ?>
                                <tr style="border-bottom: 1px solid black">
                                    <td class='ttotclr text-right padd' style="border-right: 1px solid black;"></td>
                                    <td class='ttotclr text-right padd'>&nbsp;</td>
                                </tr>
                            <? } ?>
                            <tr style="border-bottom: 1px solid black">
                                <td class='ttotclr text-right padd' style="">Total</td>
                                <td class='ttotclr text-right padd'><i class="fa fa-inr"></i> &nbsp;<?php echo number_format("$totlamt", 2) . "<br>" ?></td>
                            </tr>
                        </table>
                    <?php } ?>
                    <table class="" align='center' style="height:35%;width:90%;border:1px solid black;">
                        <tr>
                            <td width="17%">Amount In Rupees :</td>
                            <td width="80%" class='padd' style="border-right: 1px solid black;">
                                <?php
                                $total = abs($getmdata["total"]);
                                $mamt = $getmdata['billamt'] + $intamt;

                                echo rsword(round(abs($totlamt))) . " " . "Only";
                                ?></td>

                        </tr>
                    </table>

                    <table class="" align='center' style="height:35%;width:90%;">
                        <tr>
                            <td style="width:42%"><b> E. & O.E Subject to Mumbai Jurisdiction</b></td>
                            <td  class="text-right" style="font-size: 15px;width:57%">
                                <strong>For&nbsp;<?php echo $company['compname'] ?></strong>
                            </td>
                        </tr>

                        <tr>
                            <?php if ($company['note1'] != '') { ?>
                                <td class="f9">Note&nbsp;:- &nbsp;<?php echo $company['note1'] ?></td>
                                <td>&nbsp;</td>
                            </tr>
                            <?php
                        }
                        if ($company['note2'] != '') {
                            ?>
                            <tr width="50%">
                                <td class="f9"> <?php echo $company['note2'] ?></td>
                                <td>&nbsp;</td>
                            </tr>
                            <?php
                        }
                        if ($company['note3'] != '') {
                            ?>
                            <tr width="50%">
                                <td class="f9"><?php echo $company['note3'] ?></td>
                                <td>&nbsp;</td>
                            </tr>
                            <?php
                        }
                        if ($company['note4'] != '') {
                            ?>
                            <tr width="50%">
                                <td class="f9"> <?php echo $company['note4'] ?></td>
                                <td class="text-right" style="font-size: 15px"></td>
                            </tr>
                            <?php
                        }
                        if ($company['note5'] != '') {
                            ?>
                            <tr width="50%">
                                <td class="f9"> <?php echo $company['note5'] ?></td>
                                <td class="text-right" style="font-size: 15px">
                                    <strong> <?php
                                        if (!empty($company['sigdesi'])) {
                                            echo $company['sigdesi'];
                                        } else {
                                            echo "authorised signatory";
                                        }
                                        ?></strong>
                                </td>
                            </tr>
                        <?php } else { ?>
                            <table>
                                <br>
                                <br>
                                <tr width="50%">
                                    <td></td>
                                    <td class="text-right" style="font-size: 13px;padding-right: 50px">
                                        <strong> <?php
                                            if (!empty($company['sigdesi'])) {
                                                echo $company['sigdesi'];
                                            } else {
                                                echo "Authorised Signatory";
                                            }
                                            ?></strong>
                                    </td>
                                </tr>
                            </table>
                        <?php } ?>
                    </table>
            </div>
            </body>
            <?php
            if ($pgtype == 2) {
                if ($ctr % 2 == 0) {
                    echo "</div>";
                    echo "</div>";
                }
            } else {
                echo "</div>";
                echo "</div>";
            }
        }
    }
    include('includes/linksfoot.php');
//}else{
//    
//}
}


if (isset($_POST["subpdf"])) {

    while ($getmdata = mysqli_fetch_array($getdata)) {
        $iaccode = $getmdata['accode'];
        ?>
        <script>
            $(document).ready(function () {
                window.open("bill_print_multipdf.php?accode=<?= $iaccode ?>&billcode=<?= $billcode ?>");
            });
        </script>
        <?php
    }
    die();
    echo "<script>window.close()</script>";
}
?>