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

$para     = isset($_GET['para']) ? trim($_GET['para']) : 'R';   // R=Receivable, P=Payable
$formname = ($para == 'P') ? 'Outstanding Payable' : 'Outstanding Receivable';
$action   = 'osbill_fr.php';

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

// ── Lookup list ───────────────────────────────────────────────────────────
$grpcode  = ($para == 'P') ? '009' : '010';
$acctList = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='$grpcode' ORDER BY `name`") or die(mysqli_error($conn));

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; gap:0; }
    .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;
        transition:border-color .15s, background .15s, box-shadow .15s;
        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); }

    .fl .select2-container { flex:1; }
    .fl .select2-container .select2-selection--single {
        height:34px; border:1px solid #e2e8f0; border-radius:6px; background:#f8fafc;
        display:flex; align-items:center;
    }
    .fl .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height:normal; font-size:12.5px; color:#1e293b; padding-left:11px;
    }
    .fl .select2-container--default .select2-selection--single .select2-selection__arrow { height:32px; right:6px; }
    .fl .select2-container--default.select2-container--focus .select2-selection--single,
    .fl .select2-container--default.select2-container--open .select2-selection--single {
        border-color:#3b82f6; box-shadow:0 0 0 3px rgba(59,130,246,.12);
    }

    .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">
<input type="hidden" name="para" value="<?php echo htmlspecialchars($para); ?>">
<div class="sim-card">

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

    <div class="sim-body">

        <div class="fr">
            <span class="lbl"><?php echo ($para == 'P') ? 'Supplier' : 'Customer'; ?></span>
            <select name="acname" class="finp select2" style="width:100%;">
                <option value="">-- All <?php echo ($para == 'P') ? 'Suppliers' : 'Customers'; ?> --</option>
                <?php mysqli_data_seek($acctList, 0); while ($a = mysqli_fetch_assoc($acctList)): ?>
                <option value="<?php echo (int)$a['accode']; ?>"><?php echo htmlspecialchars($a['name']); ?></option>
                <?php endwhile; ?>
            </select>
        </div>

        <div class="fr">
            <span class="lbl">As On Date</span>
            <input type="text" name="asondate" class="finp datepick" placeholder="dd-mm-yyyy" value="<?php echo date('d-m-Y'); ?>">
        </div>

        <div class="fr">
            <span class="lbl">Report Type</span>
            <select name="dtype" class="finp select2" style="width:100%;">
                <option value="1">Summary</option>
                <option value="2">Detail</option>
            </select>
        </div>

        <div class="fr">
            <span class="lbl">More Than Days</span>
            <input type="text" name="days" class="finp" style="text-align:right;" placeholder="e.g. 30">
        </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>
