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

$formname = 'Manual Rent Receipt (Residental)Print';
$maindb = 'invmainres';
$file = 'manrecprin_.php';
//$source = "BS";
$admin = $_SESSION["admin_" . $dbname];
$zroot = $_SESSION["zdir"];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$mht = 'height:20px;';


$party = $_POST["party"];
$partycond = "";
if (!empty($party)) {
    $partycond = "AND `name` = '$party'";
}

$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];

$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS mydt ,DATE_FORMAT(`fromdate`, '%d-%M-%Y') AS fromdate,DATE_FORMAT(`todate`, '%d-%M-%Y') AS todate
                  FROM `$maindb` WHERE vouchno='$vouchno' $partycond") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry);
$monno = $getmdata['monthno'];
$monthname = monthname($monno);
$gcomp = mysqli_query($conn, "SELECT `compname`, `hoadd1`, `hoadd2`, `hoadd2`,
                              `hoadd3`, `hocity`, `hopin`, `hocountry`, `htel`, `email`,
                              `code` FROM $zroot.`company`
                               WHERE `code` !='' ")or die(mysqli_error($conn));
$fcomp = mysqli_fetch_array($gcomp);

$company = $fcomp['compname'];
$add1 = $fcomp['hoadd1'];
$add2 = $fcomp['hoadd2'];
$add3 = $fcomp['hoadd3'];
$city = $fcomp['hocity'];
$pin = $fcomp['hopin'];
$country = $fcomp['hocountry'];
$tel = $fcomp['hotel'];
$email = $fcomp['hoemail'];
?>

<!DOCTYPE HTML>
<html lang="en-US">


</head>
<style>
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        /*background-color: #FAFAFA;*/
        font: 12pt "Verdana";
    }
    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }
    .page {
        width: 210mm;
        min-height: 140mm;
        padding: 4mm;
        margin: 10mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 5px;
        /*background: white;*/

    }
    .subpage {
        padding: 0cm;
        /*        border: 1px solid;*/
        height: 288mm;
        outline: 2cm #ffffff solid;
    }

    @page {
        size: A4;
        margin: 0;
    }
    @media print {
        html, body {
            width: 210mm;
            height: 297mm;        
        }
        .page {
            margin: 0;
            border: initial;
            border-radius: initial;
            width: initial;
            min-height: initial;
            box-shadow: initial;
            background: initial;
            page-break-after: always;
        }


    }
    .border{
        border: 1px solid;
    }
    tr td{
        padding:5px;
    }
</style>
<?php
$getten = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode` = '$getmdata[accode]' ") or die(mysqli_error($conn));
$ftget = mysqli_fetch_array($getten);


$room = $ftget['flatno'];
$address = $ftget['add1'];
?>

<body id="main_container">
    <div class="container">
        <div class="page" style='border:1px solid black'>
            <!-- <div class="subpage">    -->
            <!--   ************Header************  -->
            <div class="col-md-12" >

                <b><center><?php echo $company; ?></center></b>
                <center><?php echo $add1 . " " . $add2 . " " . $add3 . " " . $city . " - " . $pin ?></center>

                <h5><center><?php echo $formname; ?></center></h5>

            </div>
            <hr style="border-top: dotted 1px;" />

            <table width="100%">
                <tr>
                    <td style="text-align: left;" colspan="3">
                        Bill No.&nbsp;<b><?php echo $getmdata['vouchno']; ?></b> 
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left; width: 50%;"  >
                        Name of Tenant :
                        <b> <?php echo $ftget['name']; ?> </b>
                    </td>
                    <td style="text-align: center;">
                        <b>Date :</b>
                        <?php echo $getmdata['mydt']; ?> 
                    </td>                                
                </tr>

                <tr>
                    <td style="text-align: left;" colspan="3">
<!--                        Rent for the Month of <b><?php echo $monthname . " " . date("Y"); ?></b>. -->
                        Rent for the Period of <b><?php echo $getmdata['fromdate'] . " to  " . $getmdata['todate']; ?></b>. 
                    </td>
                </tr>

                <tr>                      
                    <td style="text-align: left;" colspan="3">
                        Of the Property Godown/Shop/Room No.<b><?php echo $room; ?></b>
                        <?php // echo rsword(round($getmdata["amount"]));     ?>
                    </td>
                </tr>    
                <tr>                      
                    <td style="text-align: left;">
                        Situated At <b><?php echo $address; ?> </b>
                    </td>
                    <td style="text-align: left;">
                        <!--Date <b><?php // echo $getmdata['chqdate'];        ?> </b>-->
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left;" colspan="3">
                      Rent Rs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><?php echo $getmdata['rent']; ?> </b>&nbsp;&nbsp;p.m. with/without Municipal Taxes  
                    </td>
                </tr>
                <?php
                if ($getmdata['proptax'] > 0) {
                    $propdesc = "and Property Tax :  $getmdata[proptax]";
                }
                if ($getmdata['othertax'] > 0) {
                    $othdesc = "Other :  $getmdata[othertax]";
                }
                if ($getmdata['repairtax'] > 0) {
                    $repdesc = "Repair Cess :  $getmdata[repairtax]";
                }
                ?>
                <tr>                      
                    <td style="text-align: left;" colspan="3">
                        <?php echo $propdesc; ?>
                    </td>
                </tr> 

                <tr>                      
                    <td style="text-align: left;" colspan="3">
                        <?php echo $repdesc; ?>

                    </td>
                </tr> 
                <tr>                      
                    <td style="text-align: left;" colspan="3">
                        <?php echo $othdesc; ?>

                    </td>
                </tr> 
                <tr>                      
                    <td style="text-align: left; " colspan="3">
                        <hr   align="left" style="border: 1px solid black; width:30%"/>
                        Total <b> &nbsp;&nbsp;&nbsp;<?php echo $getmdata['rent'] . " (Rupees " . rsword($getmdata['rent']) . ")"; ?> </b>
                    </td>
                </tr> 
                <tr>                      
                    <td style="text-align: left;" colspan="3">
                        E.&.O.E
                    </td>
                </tr> 
                <tr>                      
                    <td style="text-align: left;"  colspan="3">
                        <?php
                        $count = mysqli_num_rows($result2);
                        IF ($count > 0) {
                            $billstr = 'Bill No. ';
                        } ELSE {
                            $billstr = '';
                        }
                        $no = 1;
                        while ($row2 = mysqli_fetch_array($result2)) {
                            $billstr = $billstr . $row2['billno'] . ",&nbsp;";
                        }
                        IF ($count > 0) {
                            $billstr = $billstr . $row2['billno'] . ".&nbsp;";
                        } ELSE {
                            $billstr = $billstr;
                        }
                        if ($get['remark2'] != '') {
                            $billstr = $get['remark2'];
                        } else {
                            $billstr = $billstr;
                        }
//                        echo $billstr;
                        $bilrem = $billstr;
                        $bilrem1 = substr($bilrem, 0, 80);
                        $bilrem2 = substr($bilrem, 81, 150);

                        echo $bilrem1 . "<br>" . $bilrem2;
                        ?> 

                    </td>
                </tr> 
            </table>
            <table>
                <tr>
                    <td colspan="3" height="30px"></td>
                </tr>
                <tr>
                    <td style="text-align: left; width:10%;">
                        <b>Trustees</b>
                    </td>
                    <td style="text-align: center; width:50%;font-size:13px">
                        <b><?php echo $cust['staff']; ?> </b><br>
                        <b>(Please see conditions on the reverse)</b>
                    </td>
                    <td style="text-align: right; width:35%;">
                        <hr align="right" style="border: 1px solid black; width:50%;"/>
                        <b>Received By/Account Holder</b>
                    </td>
                </tr>                    
            </table>
            <br>
            <?php
            if ($getmdata['for'] == 'P') {
                $dtldb = 'purinvmain';
                $vdt = 'invdate';
            } else {
                $dtldb = 'courmain';
                $vdt = 'vouchdt';
            }
            $getdtl = mysqli_query("SELECT * FROM `billsett` WHERE source = 'BP' and bnkvouch = '$vouchno'") or die(mysqli_error());
            $countdtl = mysqli_num_rows($getdtl);
            if ($countdtl > 0) {
                ?>
                <table style="width:100%;" class="table table-bordered table-condensed sortableTable responsive-table report">
                    <tr style="height:10px;" class="mySearchTr">
                        <th align="left" width="15%">Date</th>
                        <th align="left" width="15%">Bill No.</th>
                        <th align="left" width="15%">Invoice Date</th>
                        <th align="right" width="15%" style="text-align:right;">Bill Amount</th>
                        <th align="right" width="15%" style="text-align:right;">Paid Amount</th>
                    </tr>
                    <?php
                    $totamount = 0;
                    $totpaidamt = 0;
                    while ($rmain = mysqli_fetch_object($mainqry)) {

                        echo "<tr>";
                        echo "<td style=\"text-align:left;\" scope=\"col\" width=\"300\">$rmain[vouchno]</td>";
                        echo "<td style=\"text-align:left;\" scope=\"col\" width=\"100\">$qbill</td>";
                        echo "<td style=\"text-align:left;\" scope=\"col\" width=\"100\">$invdate</td>";
                        echo "<td style=\"text-align:right;\" scope=\"col\" width=\"300\">$total</td>";
                        echo "<td style=\"text-align:right;\" scope=\"col\" width=\"200\">$msetoff</td>";
                        echo "</tr>";
                    }
                    ?>
                    <tr style="height:10px;" class="mySearchTr">
                        <td align="left" width="15%"></td>
                        <td align="left" width="15%"></td>
                        <td align="left" width="15%"><b>Total</b></td>
                        <td align="right" width="15%" style="text-align:right;"><b><?= $totamount ?></b></td>
                        <td align="right" width="15%" style="text-align:right;"><b><?= $totpaidamt ?></b></td>
                    </tr>
                </table>
                <?php
            }
            ?>
        </div>        
    </div>

    <!-- <hr style="border-top: dotted 1px;" /> -->
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>
