<?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";

//print $dcode;
if (!empty($dcode) || $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 != '011' and grpcode != '012' ORDER BY name") or die(mysqli_error($conn));
    $flag = "";
}

$ctr = 0;
echo "<br>";
echo '<table id="detail" class="table table-bordered table-responsive " border="" width="100%" style="margin-bottom: 2px;" height="auto" align="left">';
echo "<tr>";
echo "<td border='0px' class='right' style='width: 30%'></td>";
echo "<td border='0px' class='right' style='width: 10%'></td>";
echo "<td border='0px' class='right' style='width: 20%'></td>";
echo '<td align="right" style="width:20%"><font color="Green" size="3px">Debit</font><input type="text" size="10" style="text-align: right" id="totdebit" name="totdebit" class="form-control right" readonly></td>';
echo '<td align="right" style="width:20%"><font color="red" size="3px">Credit</font><input type="text" size="10" style="text-align: right" id="totcredit" name="totcredit" class="form-control right" readonly></td>';
echo '</tr>';
echo '</table>';

echo '<table id="openbal" class="table table-bordered table-responsive " border="" width="100%" height="auto" style="" align="center">';
echo "<tr style='background-color: #8F4131'>";
echo "<th><label class='control-label col-lg-4 right'>Name $flag</label></th>";
echo "<th><label class='control-label col-lg-4 right'>Initial</label></th>";
echo "<th><label class='control-label right'>Bank Initial</label></th>";
echo "<th align='right'><label class='control-label col-lg-4 right'>Debit</label></th>";
echo "<th align='right'><label class='control-label col-lg-4 right'>Credit</label></th>";
echo '</tr>';
while ($row = mysqli_fetch_array($result)) {
    $dc = $row['dc'];
    echo "<tr>";
    echo '<td align="center" style="width: 30%"><input type="hidden" name="accode_' . $ctr . '" value="' . $row["accode"] . '">
             <input type="text" size="40"  maxlength="4"  name="acname_' . $ctr . '"  value="' . $row["name"] . '" class="acname form-control " readonly/></td>';
    echo '<td align="center" style="width: 10%">
         <input type="text" size="4" maxlength="6" style="text-align: left;" name="init_' . $ctr . '" value="' . $row["init"] . '" class="init form-control right"  readonly/></td>';
    echo '<td align="left" style="width: 20%"><input type="text" size="4"  maxlength="4" name="bankinit_' . $ctr . '" value="' . $row["bankinit"] . '" class="bankinit form-control right" style="text-align:left; padding-left: 5px;"  readonly/></td>';
    if ($dc=='D') {
        echo '<td align="left" style="width: 20%"><input type="text" style="text-align: right" name="debit_' . $ctr . '" value="' . $row["openbal"] . '" class="cal form-control right" autofocus/></td>';
        echo '<td align="center" style="width: 20%"><input type="text" style="text-align: right" name="credit_' . $ctr . '"  value="" class="cal2 form-control right" /></td>';
    } else {
       echo '<td align="left" style="width: 20%"><input type="text" style="text-align: right" name="debit_' . $ctr . '" value="" class="cal form-control right" autofocus/></td>';
       echo '<td align="center" style="width: 20%"><input type="text" style="text-align: right" name="credit_' . $ctr . '" value="' . $row["openbal"] . '" class="cal2 form-control right" /></td>';
    }
    echo '</tr>';
    $ctr++;
}

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

?>