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

$formname = "Balance Sheet";
$action   = "balsheet_fr.php";

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

// ── Default As-On Date = current fiscal year end ────────────────────────────
// See trbal.php for why this can't just be getzdates($zyear,'E') —
// getzdates() takes no args and returns [start, end] as 'd-m-Y' strings.
$zdates  = getzdates();
$mtodate = !empty($zdates[1]) ? implode('-', array_reverse(explode('-', $zdates[1]))) : date('Y-m-d');

include("includes/linkshead.php");
?>
<style>
    body { background:#f0f2f5; margin:0; padding:10px 14px; }
    .sim-card { background:#fff; border-radius:10px; max-width:560px; 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; margin-bottom:11px; }
    .lbl { font-size:12px; font-weight:500; color:#64748b; white-space:nowrap; text-align:right;
        padding-right:12px; min-width:130px; flex-shrink:0; }
    .finp { flex:1; padding:7px 11px; background:#f8fafc; border:1px solid #e2e8f0; border-radius:6px;
        font-size:12.5px; 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); }
    @media (max-width:480px) {
        .fr { flex-wrap:wrap; }
        .lbl { text-align:left; width:100%; padding-right:0; margin-bottom:5px; min-width:0; }
    }
    .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-view   { background:#2563eb; }
    .abtn-cancel { background:#64748b; }
</style>

<body>
<form method="POST" action="<?php echo $action; ?>" target="_blank">
<div class="sim-card">

    <div class="sim-card-header">
        <h2><i class="fa fa-file-invoice-dollar" style="color:#2563eb;margin-right:8px;font-size:14px;"></i><?php echo $formname; ?></h2>
    </div>

    <div class="sim-body">

        <div class="fr">
            <span class="lbl">As On Date</span>
            <input type="date" name="todt" class="finp" value="<?php echo $mtodate; ?>">
        </div>

    </div>

    <div class="btn-bar">
        <button type="submit" name="view" value="1" class="abtn abtn-view">
            <i class="fa fa-television"></i> View
        </button>
        <button type="button" class="abtn abtn-cancel" onclick="window.close()">
            <i class="fa fa-power-off"></i> Cancel
        </button>
    </div>

</div>
</form>

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