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

$formname = 'Opening Balance ';
$maindb = 'openbal';
$file = 'openbal.php';
$zdb = $_SESSION["zdbyear_" . $dbname];
$series = $_SESSION["society_" . $dbname];
mysqli_select_db($conn, $zdb);

$dcode = mysqli_real_escape_string($conn, $_GET["code"]);
$stype = mysqli_real_escape_string($conn, $_GET["stype"]);

$sterm = mysqli_real_escape_string($conn, $_GET["sterm"]);

$termcond = '';
if (!empty($sterm)) {
    if ($stype == 1) {
        $termcond = " and name LIKE '%$sterm%'";
    } elseif ($stype == 2) {
        $termcond = " and flatno LIKE '%$sterm%'";
    } elseif ($stype == 3) {
        $termcond = " and wing = '%$sterm%'";
    }
}


$colorcode = "#FF8C00";



//print $dcode;
$cond = 'ORDER BY `flatno`,`wing`';
if ($dcode == 1) {
    $cond = 'ORDER BY `name`';
} else {
    $cond = 'ORDER BY `flatno`,`wing`';
}

$result = mysqli_query($conn, "SELECT accode,name,dc,openbal,flatno,wing,floor,prinamt,interest,advance,latefee FROM `accmast` WHERE `grpcode`='010' and
                      `active`='1' and `series`='$series' $termcond $cond") or die(mysqli_error($conn));
$flag = "";


$ctr = 0;
echo "<br>";
echo '<table id="openbal" class="table table-bordered table-responsive persist-area" border="" width="100%" height="auto" style="" align="center">';
echo "<tr class='mySearchTr persist-header'>";
echo "<th style='width:20.5%'><label class='control-label right'>Name </label></th>";
echo "<th style='width:11%'><label class='control-label right'>Wing</label></th>";
echo "<th  style='width:11%'><label class='control-label right'>Floor</label></th>";
echo "<th style='width:11%'><label class='control-label right'>Flat No.</label></th>";
echo "<th style='width:11%' align='right'>Principle Amt.</th>";

echo "<th style='width:11%' align='right'>Interest</th>";
echo "<th style='width:11%' align='right'>Advance</th>";
echo "<th style='width:13%' align='right'>Opening balance</th>";
echo '</tr>';
echo '</table>';
echo '<div style="max-height:450px;overflow: auto; border: 0px solid;">';
echo '<table id="openbal" class="table table-bordered table-responsive persist-area" border="" width="100%" height="auto" style="" align="center">';


while ($row = mysqli_fetch_array($result)) {
    $dc = $row[dc];
    echo "<tr>";
    echo '<td style="width:21%" align="center"  ><input type="hidden" name="accode_' . $ctr . '" value="' . $row["accode"] . '">
                                          <input type="text"  name="acname_' . $ctr . '"  value="' . $row["name"] . '" class="acname form-control " readonly/></td>';
    echo '<td style="width:11%" align="center"   ><input type="text" name="wing_' . $ctr . '" class=" form-control " value="' . $row["wing"] . '" readonly></td>';
    echo '<td style="width:11%" align="center"   ><input type="text" name="floor_' . $ctr . '" class=" form-control " value="' . $row["floor"] . '" readonly></td>';
    echo '<td style="width:11%" align="center"   ><input type="text" name="flatno_' . $ctr . '" class=" form-control " value="' . $row["flatno"] . '" readonly></td>';
    echo '<td style="width:11%" align="" ><input type="text" style="text-align: right"  name="prinamt_' . $ctr . '"  value="' . $row["prinamt"] . '" class="prinamt form-control right" /></td>';

    echo '<td style="width:11%" align="" ><input type="text" style="text-align: right"  name="interest_' . $ctr . '"  value="' . $row["interest"] . '" class="interest form-control right" /></td>';
    echo '<td style="width:11%" align="" ><input type="text" style="text-align: right"  name="advance_' . $ctr . '"  value="' . $row["advance"] . '" class="advance form-control right" /></td>';
    echo '<td style="width:13%" align="" ><input type="text" style="text-align: right;display:inline;width:75%;text-transform: uppercase;"  name="openbal_' . $ctr . '"  value="' . $row["openbal"] . '" class="openbal form-control right" readonly>
    <input type="text" style="text-align: right;display:inline;width:15%"  name="dc_' . $ctr . '"  value="' . $row["dc"] . '" class="dc form-control right" >'
        . '</td>';
    echo '</tr>';
    $ctr++;
}
echo "<input type='hidden' name='mcount' value='$ctr'>";
echo "</table>";
echo "</div>";
