<?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];
mysqli_select_db($conn, $zdb);

$dcode = mysqli_real_escape_string($conn, $_GET["code"]);
$colorcode = "#FF8C00";

if (!empty($dcode)) {
    $result = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `grpcode`='$dcode' ORDER BY name") or die(mysqli_error($conn));
    $flag = "";
} else {
    $result = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `grpcode` BETWEEN 001 AND 051 ORDER BY name") or die(mysqli_error($conn));
    $flag = "";
}

$ctr = 0;
echo '<table id="detail" border="1" width="40%" align="right">';
echo "<tr>";
echo '<th>
    </th>';
echo '<th align="right"><font color="Green" size="3px">Debit  </font><input type="text" size="10" id="totdebit" name="totdebit" class="form-control" readonly></th>';
echo '<th align="right"><font color="red" size="3px">Credit  </font><input type="text" size="10" id="totcredit" name="totcredit" class="form-control" readonly></th>';
echo '</tr>';
echo '</table>';
echo '<table id="openbal" border="1" width="100%" align="center">';
echo "<tr>";
echo "<th><label class='control-label col-lg-4'>Name $flag</label></th>";
echo "<th><label class='control-label col-lg-4'>Init</label></th>";
echo "<th><label class='control-label'>Bank Init</label></th>";
echo "<th align='right'><label class='control-label col-lg-4'>Debit</label></th>";
echo "<th align='right'><label class='control-label col-lg-4'>Credit</label></th>";
echo '</tr>';
while ($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo '<td align="center"><input type="hidden" name="accode_' . $ctr . '" value="' . $row["accode"] . '">
             <input type="text" size="40"  maxlength="4"  name="acname_' . $ctr . '"  value="' . $row["name"] . '" class="form-control" readonly/></td>';
    echo '<td align="center">
              <input type="text" size="4" maxlength="6" style="text-align: left;" name="init_' . $ctr . '" value="' . $row["init"] . '" class="form-control"  readonly/></td>';
    echo '<td align="left"><input type="text" size="4"  maxlength="4" name="bankinit_' . $ctr . '" value="' . $row["bankinit"] . '" class="qty form-control" style="text-align:left; padding-left: 5px;"  readonly/></td>';
    echo '<td align="center "><input type="text" size="10" maxlength="6" name="debit_' . $ctr . '" value="'.$row["openbal"].'" class="cal form-control" autofocus/></td>';
    echo '<td align="center"><input type="text" size="10" maxlength="6" name="credit_' . $ctr . '" value="" class="cal2 qty form-control" /></td>';
    echo '</tr>';
    $ctr++;
}

echo "<input type='hidden' name='count' value='$ctr'>";
echo "</table>";
?>

