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

$formname = "Closing Stock";
$file     = "closstk.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb   = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

$result = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='23' ") or die(mysqli_error($conn));
$get    = mysqli_fetch_array($result);

if (isset($_POST["submit"])) {
    $curbal = $_POST["curbal"];
    $curdc  = $_POST["curdc"];

    mysqli_query($conn, "UPDATE `accmast` SET `currbal`='" . mysqli_real_escape_string($conn, $curbal) . "',
        `currdc` = '" . mysqli_real_escape_string($conn, $curdc) . "'  WHERE `accode`= '23' ") or die(mysqli_error($conn));
    updmess($file);
    exit;
}

include("includes/linkshead.php");
?>
<style>
    body { background:#f0f2f5; margin:0; padding:10px 14px; }

    .sim-card { background:#fff; border-radius:10px; max-width:520px; margin:0 auto;
        box-shadow:0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06); overflow:hidden; }
    .sim-card-header { background:#fff; border-bottom:2px solid #f1f5f9; padding:12px 20px;
        display:flex; align-items:center; justify-content:space-between; }
    .sim-card-header h2 { font-size:15px; font-weight:700; color:#1e293b; margin:0; }
    .sim-body { padding:20px; }

    .fr { display:flex; align-items:center; gap:10px; margin-bottom:11px; }
    .lbl { font-size:12px; font-weight:500; color:#64748b; white-space:nowrap; text-align:right;
        padding-right:2px; min-width:130px; flex-shrink:0; }
    .finp { flex:1; padding:7px 11px; background:#f8fafc; border:1px solid #e2e8f0; border-radius:6px;
        font-size:13px; color:#1e293b; outline:none; width:100%; box-sizing:border-box; font-family:inherit; }
    .finp:focus { background:#fff; border-color:#3b82f6; box-shadow:0 0 0 3px rgba(59,130,246,.12); }
    .dcsel { width:80px; flex:0 0 80px; }

    .btn-bar { display:flex; justify-content:center; align-items:center; gap:8px;
        padding:16px 20px; border-top:1px solid #f1f5f9; background:#fafafa; }
    .abtn { width:auto; padding:0 22px; height:42px; border-radius:8px; border:none; cursor:pointer;
        font-size:12.5px; font-weight:600; color:#fff; display:inline-flex; align-items:center;
        gap:6px; text-decoration:none; transition:transform .12s,box-shadow .12s,filter .12s; }
    .abtn:hover { transform:translateY(-2px); box-shadow:0 5px 14px rgba(0,0,0,.22); filter:brightness(1.06); }
    .abtn-save { background:#16a34a; }
    .abtn-exit { background:#64748b; }
</style>
</head>
<body>
    <form id="form" method="post" action="">
    <div class="sim-card">

        <div class="sim-card-header">
            <h2><i class="fa fa-boxes-stacked" style="color:#f59e0b;margin-right:8px;font-size:14px;"></i><?php echo $formname; ?></h2>
        </div>

        <div class="sim-body">
            <div class="fr">
                <span class="lbl">Closing Stock</span>
                <input type="number" step="any" name="curbal" value="<?php echo htmlspecialchars($get['currbal']); ?>" class="finp">
                <select class="finp dcsel" name="curdc">
                    <option value="D" <?php echo ($get['currdc'] == 'D') ? "selected" : ""; ?>>D</option>
                    <option value="C" <?php echo ($get['currdc'] == 'C') ? "selected" : ""; ?>>C</option>
                </select>
            </div>
        </div>

        <div class="btn-bar">
            <button id="submit" type="submit" name="submit" class="abtn abtn-save">
                <i class="fa fa-check"></i> Save
            </button>
            <button id="exit" type="button" class="abtn abtn-exit" onclick="window.location.href='default.php'">
                <i class="fa fa-power-off"></i> Exit
            </button>
        </div>

    </div>
    </form>

<?php include("includes/linksfoot.php"); ?>
</body>
</html>
