<!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>Pending Supply Payment</title>
        <link rel="stylesheet" href="css/table_min.css" type="text/css"/>	
    </head>

    <body>
        <div class="CSSTableGenerator" id="chq_table1" >
            <?php
            include('connectioni.php');

            echo "<center><span class=\"style1\">Pending Supply Payment : " . $_GET['txt_bea'] ." (". $_GET['txtcuscode'] . ")</span></center><br>";
            $sql = "Select * from vendor where CODE='" . $_GET['txtcuscode'] . "'";
            $result = mysqli_query($GLOBALS['dbinv'],$sql);
            if ($row = mysqli_fetch_array($result)) {

                echo "<table width=\"1000\" border=\"0\">
              <tr>
                <td width=\"150\">Date</td>
                <td width=\"150\">Ref No</td>
                <td width=\"150\">Inv No</td>
                <td width=\"150\">Value</td>
                <td width=\"150\">Paid</td>
                <td width=\"150\">To Pay</td>
              </tr>";

                $i = 1;
                $sql1 = "Select * from s_purmas where SUP_CODE='" . $_GET['txtcuscode'] . "' and AMOUNT-PAID_AMT>0";
                $result1 = mysqli_query($GLOBALS['dbinv'],$sql1);
                $totAmount = 0;
                $totPaidAmount = 0;
                $totBalance = 0;
                while ($row1 = mysqli_fetch_array($result1)) {

                    $sql2 = "Select * from c_bal where REFNO='" . $row1["REFNO"] . "' and BALANCE>10";
                    $result2 = mysqli_query($GLOBALS['dbinv'],$sql2);
                    if ($row2 = mysqli_fetch_array($result2)) {

                        $REFNO = "REFNO" . $i;
                        $to_pay = "to_pay" . $i;
                        $txtpay = "txtpay" . $i;
                        $bal = "bal" . $i;
                        $disc = "disc" . $i;
                        $pi_no = "pi_no" . $i;

                        $date1 = date("Y-m-d", strtotime($row1["SDATE"]));
                        $date2 = date("Y-m-d");

                        $diff = abs(strtotime($date2) - strtotime($date1));
                        $days = floor($diff / (60 * 60 * 24));
                        if ($row1["SDATE"] == "") {
                            $days = "";
                        }

                        echo "<tr>
                		<td>" . $row1["SDATE"] . "</td>
                		<td>" . $row1["REFNO"] . "</td>";

                        if ((trim($row1["pi_no"]) == "") or ( strlen(trim($row1["pi_no"])) == 1)) {
                            echo "<td>" . $row1["LCNO"] . "</td>";
                        } else {
                            echo "<td>" . $row1["pi_no"] . "</td>";
                        }
                        $totAmount += $row1["AMOUNT"];
                        $totPaidAmount += $row1["PAID_AMT"];
                        $totBalance += ($row1["AMOUNT"]-$row1["PAID_AMT"]);
                        echo "<td>" . number_format($row1["AMOUNT"], 2, ".", ",") . "</td>
                		<td>" . number_format($row1["PAID_AMT"], 2, ".", ",") . "</td>
                		<td>" . ($row1["AMOUNT"] - $row1["PAID_AMT"]) . "</td>
              			</tr>";
                        $i = $i + 1;
                    }
                }
                                    echo "<tr><td colspan='3'></td><td><b>". number_format($totAmount, 2, ".", ",") ."</b></td><td><b>".number_format($totPaidAmount, 2, ".", ",")."</b></td><td><b>".number_format($totBalance, 2, ".", ",")."</b></td></tr>";
                echo "</table>";
            }
            ?>
        </div>
    </body>
</html>
