<?php session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Unrealized &amp; Unpresented Cheques</title>
        <style type="text/css">
            <!--
            .companyname {
                color: #0000FF;
                font-weight: bold;
                font-size: 24px;
            }

            .com_address {
                color: #000000;
                font-weight: bold;
                font-size: 18px;
            }

            .heading {
                color: #000000;
                font-weight: bold;
                font-size: 16px;
            }

            body {
                color: #000000;
                font-size: 14px;
            }


            -->
        </style>
    </head>

    <body><center>
            <?php
            include('connection_un_rp.php');

            $sql_com = "select comcode from bankmaster where bm_code = '" . $_GET['txtBankCode'] . "'";
            $result_com = mysqli_query($GLOBALS['dbacc'],$sql_com);
            $row_com = mysqli_fetch_array($result_com);

            $sql_rsBANKMASTER = "select * from bankmaster where  bm_code='" . trim($_GET["txtBankCode"]) . "'";
            $result_rsBANKMASTER = mysqli_query($GLOBALS['dbacc'],$sql_rsBANKMASTER);
            if ($row_rsBANKMASTER = mysqli_fetch_array($result_rsBANKMASTER)) {
                $txtBank = "  " . $row_rsBANKMASTER["bm_code"] . ", " . $row_rsBANKMASTER["bm_bank"];
                $txtbrnach = " : " . $row_rsBANKMASTER["bm_branch"];
                $txtaccno = " : " . trim($row_rsBANKMASTER["bm_accno"]);
            }
            ?>
            <tr>
                <td width="208"><span class="heading"><?php echo $txtBank . ' as at ' . $_GET['dtpDate'] ?></span></td>
            </tr>
            <?php
            echo "<table width=\"904\" height=\"81\" border=\"0\" cellspacing=\"0\">
		<tr >
        <th colspan=4 align=left>Un-Realised Cheques</th>
		</tr>
      	<tr  bgcolor=\"#999999\">
        <th width=\"70\" height=\"23\">Date</th>
        <th width=\"100\">Chq. No</th>
        <th width=\"445\">Description</th>
        <th width=\"100\" >Amount</th>
        </tr>";
            /////
            /////
            $sql_rsPrInv = "Select * from op_cheq where (recdate='0' )  and flag='DEB'  and code='" . trim($_GET["txtBankCode"]) . "' order by sdate";
            //echo $sql_rsPrInv;
            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv);
            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . date("Y-m-d", strtotime($row_rsPrInv["sdate"])) . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>
			<td>&nbsp;</td>
			<td align=right>" . number_format($row_rsPrInv["amount"], 2, ".", ",") . "</td>
			</tr>";

                $DEB_amt = $DEB_amt + $row_rsPrInv["amount"];
            }
            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_a);
            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . date("Y-m-d", strtotime($row_rsPrInv["sdate"])) . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>
			<td>&nbsp;</td>
			<td align=right>" . number_format($row_rsPrInv["amount"], 2, ".", ",") . "</td>
			</tr>";

                $DEB_amt = $DEB_amt + $row_rsPrInv["amount"];
            }
            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_b);
            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . date("Y-m-d", strtotime($row_rsPrInv["sdate"])) . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>
			<td>&nbsp;</td>
			<td align=right>" . number_format($row_rsPrInv["amount"], 2, ".", ",") . "</td>
			</tr>";

                $DEB_amt = $DEB_amt + $row_rsPrInv["amount"];
            }
            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_d);
            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . date("Y-m-d", strtotime($row_rsPrInv["sdate"])) . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>
			<td>&nbsp;</td>
			<td align=right>" . number_format($row_rsPrInv["amount"], 2, ".", ",") . "</td>
			</tr>";

                $DEB_amt = $DEB_amt + $row_rsPrInv["amount"];
            }
            /////
            /////
            echo "<tr><td colspan=3>&nbsp;</td>
			<td align=right><b>" . number_format($DEB_amt, 2, ".", ",") . "</b></td>
			</tr>";


            ////
            /////
            $sql_rsPrInv = "select * from ledger where  (l_flag != 'opb') and l_code='" . trim($_GET["txtBankCode"]) . "'   and (l_flag2 = '0' or tmprecdate > '" . $_GET["dtpDate"] . "')  and l_date <= '" . $_GET["dtpDate"] . "' and l_flag1='DEB' order by l_date ";

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv);

            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . $row_rsPrInv["l_date"] . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>";

                $sql_rspaymas = "select heading from bankdepmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas);

                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    //$descrip=$row_rspaymas["heading"];
                }

                $sql_rspaymas = "select heading from bankentmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas);

                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);

                    //$descrip=$row_rspaymas["heading"];
                }

                echo "<td>" . " C " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " " . $descrip . "</td>
			<td align=right>" . number_format($row_rsPrInv["l_amount"], 2, ".", ",") . "</td>
			</tr>";

                $DEB_amt = $DEB_amt + $row_rsPrInv["l_amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_a);

            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . $row_rsPrInv["l_date"] . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>";

                $sql_rspaymas = "select heading from bankdepmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_a);

                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    //$descrip=$row_rspaymas["heading"];
                }

                $sql_rspaymas = "select heading from bankentmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_a);

                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);

                    //$descrip=$row_rspaymas["heading"];
                }

                echo "<td>" . " A " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " " . $descrip . "</td>
			<td align=right>" . number_format($row_rsPrInv["l_amount"], 2, ".", ",") . "</td>
			</tr>";

                $DEB_amt = $DEB_amt + $row_rsPrInv["l_amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_b);

            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . $row_rsPrInv["l_date"] . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>";

                $sql_rspaymas = "select heading from bankdepmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_b);

                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    //$descrip=$row_rspaymas["heading"];
                }

                $sql_rspaymas = "select heading from bankentmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_b);

                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);

                    //$descrip=$row_rspaymas["heading"];
                }

                echo "<td>" . " B " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " " . $descrip . "</td>
			<td align=right>" . number_format($row_rsPrInv["l_amount"], 2, ".", ",") . "</td>
			</tr>";

                $DEB_amt = $DEB_amt + $row_rsPrInv["l_amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_d);

            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . $row_rsPrInv["l_date"] . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>";

                $sql_rspaymas = "select heading from bankdepmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_d);

                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    //$descrip=$row_rspaymas["heading"];
                }

                $sql_rspaymas = "select heading from bankentmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_d);

                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);

                    //$descrip=$row_rspaymas["heading"];
                }

                echo "<td>" . " R " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " " . $descrip . "</td>
			<td align=right>" . number_format($row_rsPrInv["l_amount"], 2, ".", ",") . "</td>
			</tr>";

                $DEB_amt = $DEB_amt + $row_rsPrInv["l_amount"];
            }

            //////////
            /////////
            echo "<tr><td colspan=3>&nbsp;</td>
			<td align=right><b>" . number_format($DEB_amt, 2, ".", ",") . "</b></td>
			</tr></table>";

            echo "<br>";

            echo "<table width=\"904\" height=\"81\" border=\"0\" cellspacing=\"0\">
		<tr >
        <th colspan=4 align=left>Un-Presented Cheques</th>
		</tr>
      	<tr  bgcolor=\"#999999\">
        <th width=\"70\" height=\"23\">Date</th>
        <th width=\"100\">Chq. No</th>
        <th width=\"445\">Description</th>
        <th width=\"100\">Amount</th>
        </tr>";

            /////////
            ////////
            $sql_rsPrInv = "Select * from op_cheq where (recdate='0'  )  and flag='CRE'  and code='" . trim($_GET["txtBankCode"]) . "' order by sdate";
            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv);

            //echo $sql_rsPrInv;
            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . date("Y-m-d", strtotime($row_rsPrInv["sdate"])) . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>
			<td>&nbsp;</td>
			<td align=right>" . number_format($row_rsPrInv["amount"], 2, ".", ",") . "</td>
			</tr>";

                $CRE_amt = $CRE_amt + $row_rsPrInv["amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_a);

            //echo $sql_rsPrInv;
            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . date("Y-m-d", strtotime($row_rsPrInv["sdate"])) . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>
			<td>&nbsp;</td>
			<td align=right>" . number_format($row_rsPrInv["amount"], 2, ".", ",") . "</td>
			</tr>";

                $CRE_amt = $CRE_amt + $row_rsPrInv["amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_b);

            //echo $sql_rsPrInv;
            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . date("Y-m-d", strtotime($row_rsPrInv["sdate"])) . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>
			<td>&nbsp;</td>
			<td align=right>" . number_format($row_rsPrInv["amount"], 2, ".", ",") . "</td>
			</tr>";

                $CRE_amt = $CRE_amt + $row_rsPrInv["amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_d);

            //echo $sql_rsPrInv;
            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . date("Y-m-d", strtotime($row_rsPrInv["sdate"])) . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>
			<td>&nbsp;</td>
			<td align=right>" . number_format($row_rsPrInv["amount"], 2, ".", ",") . "</td>
			</tr>";

                $CRE_amt = $CRE_amt + $row_rsPrInv["amount"];
            }

            //////
            //////
            /*
              echo "<tr><td colspan=3>&nbsp;</td>
              <td align=right><b>" . number_format($DEB_amt, 2, ".", ",") . "</b></td>
              </tr>";
             */
            ///////
            //////
            $sql_rsPrInv = "select * from ledger where  (l_flag != 'opb') and l_code='" . trim($_GET["txtBankCode"]) . "'   and (l_flag2 = '0' or tmprecdate > '" . $_GET["dtpDate"] . "')  and l_date <= '" . $_GET["dtpDate"] . "' and l_flag1='CRE' order by l_date ";

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv);

            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . $row_rsPrInv["l_date"] . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>";

                $descrip_cre = "";
                $sql_rspaymas = "select barer from paymas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas);


                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["barer"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    $descrip_cre = " C " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " - " . $descrip;
                }

                $sql_rspaymas = "select heading from bankentmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas);


                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    $descrip_cre = " C " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " - " . $descrip;
                }

                echo "<td>" . $descrip_cre . "</td>
			<td  align=right>" . number_format($row_rsPrInv["l_amount"], 2, ".", ",") . "</td>
			</tr>";

                $CRE_amt = $CRE_amt + $row_rsPrInv["l_amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_a);

            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . $row_rsPrInv["l_date"] . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>";

                $descrip_cre = "";
                $sql_rspaymas = "select barer from paymas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_a);


                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["barer"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    $descrip_cre = " A " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " - " . $descrip;
                }

                $sql_rspaymas = "select heading from bankentmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_a);


                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    $descrip_cre = " A " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " - " . $descrip;
                }

                echo "<td>" . $descrip_cre . "</td>
			<td  align=right>" . number_format($row_rsPrInv["l_amount"], 2, ".", ",") . "</td>
			</tr>";

                $CRE_amt = $CRE_amt + $row_rsPrInv["l_amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_b);

            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . $row_rsPrInv["l_date"] . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>";

                $descrip_cre = "";
                $sql_rspaymas = "select barer from paymas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_b);


                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["barer"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    $descrip_cre = " B " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " - " . $descrip;
                }

                $sql_rspaymas = "select heading from bankentmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_b);


                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    $descrip_cre = " B " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " - " . $descrip;
                }

                echo "<td>" . $descrip_cre . "</td>
			<td  align=right>" . number_format($row_rsPrInv["l_amount"], 2, ".", ",") . "</td>
			</tr>";

                $CRE_amt = $CRE_amt + $row_rsPrInv["l_amount"];
            }

            $result_rsPrInv = mysqli_query($GLOBALS['dbacc'],$sql_rsPrInv_d);

            while ($row_rsPrInv = mysqli_fetch_array($result_rsPrInv)) {
                echo "<tr><td>" . $row_rsPrInv["l_date"] . "</td>
			<td>" . $row_rsPrInv["chno"] . "</td>";

                $descrip_cre = "";
                $sql_rspaymas = "select barer from paymas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_d);


                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["barer"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    $descrip_cre = " B " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " - " . $descrip;
                }

                $sql_rspaymas = "select heading from bankentmas where refno='" . $row_rsPrInv["l_refno"] . "'";
                //echo $sql_rspaymas;
                $result_rspaymas = mysqli_query($GLOBALS['dbacc'],$sql_rspaymas_d);


                if ($row_rspaymas = mysqli_fetch_array($result_rspaymas)) {

                    // $ResponseXML .=  " <td>".$row_rspaymas["barer"]."</td>";
                    $descrip = str_replace("~", "&", $row_rspaymas["heading"]);
                    $descrip = str_replace("&nbsp;", " ", $descrip);
                    $descrip_cre = " R " . $row_rsPrInv["id"] . " " . $row_rsPrInv["l_refno"] . " - " . $descrip;
                }

                echo "<td>" . $descrip_cre . "</td>
			<td  align=right>" . number_format($row_rsPrInv["l_amount"], 2, ".", ",") . "</td>
			</tr>";

                $CRE_amt = $CRE_amt + $row_rsPrInv["l_amount"];
            }

            //////
            //////
            echo "<tr><td colspan=3>&nbsp;</td>
			<td align=right><b>" . number_format($CRE_amt, 2, ".", ",") . "</b></td>
			</tr></table>";
            ?> 
        </center></body>