<?php
require_once __DIR__ . '/../../includes/bootstrap.php';
require_login();

$pageTitle = 'Stock Ledger';

if (file_exists(__DIR__ . '/../../includes/permission_check.php')) {
    require_once __DIR__ . '/../../includes/permission_check.php';
    if (function_exists('require_permission')) {
        require_permission($pdo, 'stock_movements', 'view');
    }
}

if (!function_exists('h')) {
    function h($v): string { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); }
}
if (!function_exists('money_fmt')) {
    function money_fmt($v): string { return number_format((float)$v, 2); }
}
if (!function_exists('qty_fmt')) {
    function qty_fmt($v): string { return number_format((float)$v, 4); }
}
if (!function_exists('sl_table_exists')) {
    function sl_table_exists(PDO $pdo, string $table): bool {
        $stmt = $pdo->prepare("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name=:t");
        $stmt->execute([':t' => $table]);
        return (int)$stmt->fetchColumn() > 0;
    }
}
if (!function_exists('sl_col_exists')) {
    function sl_col_exists(PDO $pdo, string $table, string $column): bool {
        $stmt = $pdo->prepare("SELECT COUNT(*) FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name=:t AND column_name=:c");
        $stmt->execute([':t' => $table, ':c' => $column]);
        return (int)$stmt->fetchColumn() > 0;
    }
}

$errors = [];

try {
    $pdo->exec("CREATE TABLE IF NOT EXISTS store_locations (
        id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
        location_code VARCHAR(50) NULL,
        location_name VARCHAR(150) NOT NULL,
        location_type ENUM('main_store','bar','restaurant','curio','kitchen','housekeeping','maintenance','other') NOT NULL DEFAULT 'main_store',
        is_pos_location TINYINT(1) NOT NULL DEFAULT 0,
        allow_room_charge TINYINT(1) NOT NULL DEFAULT 1,
        is_active TINYINT(1) NOT NULL DEFAULT 1,
        notes TEXT NULL,
        created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
        updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        UNIQUE KEY uq_store_location_code (location_code)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");

    $pdo->exec("CREATE TABLE IF NOT EXISTS inventory_units (
        id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
        unit_code VARCHAR(30) NOT NULL,
        unit_name VARCHAR(80) NOT NULL,
        is_active TINYINT(1) NOT NULL DEFAULT 1,
        created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
        UNIQUE KEY uq_inventory_unit_code (unit_code)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");

    $pdo->exec("CREATE TABLE IF NOT EXISTS inventory_items (
        id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
        item_code VARCHAR(60) NULL,
        item_name VARCHAR(180) NOT NULL,
        category_id INT UNSIGNED NULL,
        unit_id INT UNSIGNED NULL,
        supplier_id INT UNSIGNED NULL,
        item_type ENUM('stock','food','bar','curio','consumable','service','recipe','other') NOT NULL DEFAULT 'stock',
        barcode VARCHAR(100) NULL,
        description TEXT NULL,
        cost_price DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        avg_cost DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        selling_price DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        tax_rate DECIMAL(7,4) NOT NULL DEFAULT 0.0000,
        reorder_level DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        reorder_qty DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        is_stock_item TINYINT(1) NOT NULL DEFAULT 1,
        is_pos_item TINYINT(1) NOT NULL DEFAULT 0,
        allow_room_charge TINYINT(1) NOT NULL DEFAULT 1,
        track_expiry TINYINT(1) NOT NULL DEFAULT 0,
        is_active TINYINT(1) NOT NULL DEFAULT 1,
        created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
        updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        UNIQUE KEY uq_inventory_item_code (item_code),
        INDEX idx_inventory_item_name (item_name)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");

    $pdo->exec("CREATE TABLE IF NOT EXISTS stock_movements (
        id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
        item_id INT UNSIGNED NOT NULL,
        store_id INT UNSIGNED NOT NULL,
        movement_type ENUM('OPENING','GRN','ISSUE','SALE','TRANSFER_IN','TRANSFER_OUT','ADJUSTMENT_IN','ADJUSTMENT_OUT','WASTAGE','RETURN') NOT NULL,
        qty_in DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        qty_out DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        unit_cost DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        total_cost DECIMAL(14,4) NOT NULL DEFAULT 0.0000,
        reference_type VARCHAR(60) NULL,
        reference_id BIGINT UNSIGNED NULL,
        notes TEXT NULL,
        movement_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
        created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
        INDEX idx_stock_item_store (item_id, store_id),
        INDEX idx_stock_movement_date (movement_date),
        INDEX idx_stock_reference (reference_type, reference_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
} catch (Throwable $e) {
    $errors[] = 'Could not prepare stock ledger tables: ' . $e->getMessage();
}

$dateFrom = trim((string)($_GET['date_from'] ?? date('Y-m-01')));
$dateTo = trim((string)($_GET['date_to'] ?? date('Y-m-d')));
$storeId = (int)($_GET['store_id'] ?? 0);
$itemId = (int)($_GET['item_id'] ?? 0);
$movementType = trim((string)($_GET['movement_type'] ?? ''));
$search = trim((string)($_GET['q'] ?? ''));

if (strtotime($dateFrom) === false) $dateFrom = date('Y-m-01');
if (strtotime($dateTo) === false) $dateTo = date('Y-m-d');
if (strtotime($dateFrom) > strtotime($dateTo)) {
    $tmp = $dateFrom;
    $dateFrom = $dateTo;
    $dateTo = $tmp;
}

$stores = [];
$items = [];
$ledger = [];
$selectedItem = null;
$selectedStore = null;

$summary = [
    'opening_qty' => 0,
    'opening_value' => 0,
    'qty_in' => 0,
    'qty_out' => 0,
    'value_in' => 0,
    'value_out' => 0,
    'closing_qty' => 0,
    'closing_value' => 0,
    'movement_count' => 0,
];

try {
    $stores = $pdo->query("SELECT id, location_name FROM store_locations WHERE is_active=1 ORDER BY location_name ASC")->fetchAll(PDO::FETCH_ASSOC);

    $items = $pdo->query("
        SELECT ii.id, ii.item_code, ii.item_name, ii.item_type, ii.avg_cost, ii.cost_price, u.unit_code
        FROM inventory_items ii
        LEFT JOIN inventory_units u ON u.id=ii.unit_id
        WHERE ii.is_active=1
        ORDER BY ii.item_name ASC
    ")->fetchAll(PDO::FETCH_ASSOC);

    if ($itemId > 0) {
        $stmt = $pdo->prepare("
            SELECT ii.*, u.unit_code
            FROM inventory_items ii
            LEFT JOIN inventory_units u ON u.id=ii.unit_id
            WHERE ii.id=:id
            LIMIT 1
        ");
        $stmt->execute([':id' => $itemId]);
        $selectedItem = $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
    }

    if ($storeId > 0) {
        $stmt = $pdo->prepare("SELECT * FROM store_locations WHERE id=:id LIMIT 1");
        $stmt->execute([':id' => $storeId]);
        $selectedStore = $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
    }

    $openingWhere = "DATE(sm.movement_date) < :date_from";
    $openingParams = [':date_from' => $dateFrom];

    if ($storeId > 0) {
        $openingWhere .= " AND sm.store_id=:store_id";
        $openingParams[':store_id'] = $storeId;
    }
    if ($itemId > 0) {
        $openingWhere .= " AND sm.item_id=:item_id";
        $openingParams[':item_id'] = $itemId;
    }
    if ($movementType !== '') {
        $openingWhere .= " AND sm.movement_type=:movement_type";
        $openingParams[':movement_type'] = $movementType;
    }

    $stmt = $pdo->prepare("
        SELECT
            COALESCE(SUM(sm.qty_in - sm.qty_out),0) AS opening_qty,
            COALESCE(SUM(
                CASE 
                    WHEN sm.qty_in > 0 THEN sm.total_cost
                    WHEN sm.qty_out > 0 THEN -sm.total_cost
                    ELSE 0
                END
            ),0) AS opening_value
        FROM stock_movements sm
        LEFT JOIN inventory_items ii ON ii.id=sm.item_id
        LEFT JOIN store_locations sl ON sl.id=sm.store_id
        WHERE {$openingWhere}
    ");
    $stmt->execute($openingParams);
    $opening = $stmt->fetch(PDO::FETCH_ASSOC) ?: [];
    $summary['opening_qty'] = (float)($opening['opening_qty'] ?? 0);
    $summary['opening_value'] = (float)($opening['opening_value'] ?? 0);

    $where = "DATE(sm.movement_date) BETWEEN :date_from AND :date_to";
    $params = [
        ':date_from' => $dateFrom,
        ':date_to' => $dateTo,
    ];

    if ($storeId > 0) {
        $where .= " AND sm.store_id=:store_id";
        $params[':store_id'] = $storeId;
    }
    if ($itemId > 0) {
        $where .= " AND sm.item_id=:item_id";
        $params[':item_id'] = $itemId;
    }
    if ($movementType !== '') {
        $where .= " AND sm.movement_type=:movement_type";
        $params[':movement_type'] = $movementType;
    }
    if ($search !== '') {
        $where .= " AND (
            ii.item_name LIKE :q
            OR ii.item_code LIKE :q
            OR sl.location_name LIKE :q
            OR sm.notes LIKE :q
            OR sm.reference_type LIKE :q
            OR CAST(sm.reference_id AS CHAR) LIKE :q
        )";
        $params[':q'] = '%' . $search . '%';
    }

    $stmt = $pdo->prepare("
        SELECT
            sm.*,
            ii.item_name,
            ii.item_code,
            ii.item_type,
            COALESCE(u.unit_code,'') AS unit_code,
            sl.location_name
        FROM stock_movements sm
        LEFT JOIN inventory_items ii ON ii.id=sm.item_id
        LEFT JOIN inventory_units u ON u.id=ii.unit_id
        LEFT JOIN store_locations sl ON sl.id=sm.store_id
        WHERE {$where}
        ORDER BY sm.movement_date ASC, sm.id ASC
        LIMIT 3000
    ");
    $stmt->execute($params);
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

    $runningQty = $summary['opening_qty'];
    $runningValue = $summary['opening_value'];

    foreach ($rows as $row) {
        $qtyIn = (float)$row['qty_in'];
        $qtyOut = (float)$row['qty_out'];
        $totalCost = (float)$row['total_cost'];

        $runningQty += ($qtyIn - $qtyOut);
        if ($qtyIn > 0) {
            $runningValue += $totalCost;
            $summary['qty_in'] += $qtyIn;
            $summary['value_in'] += $totalCost;
        }
        if ($qtyOut > 0) {
            $runningValue -= $totalCost;
            $summary['qty_out'] += $qtyOut;
            $summary['value_out'] += $totalCost;
        }

        $row['running_qty'] = $runningQty;
        $row['running_value'] = $runningValue;
        $ledger[] = $row;
    }

    $summary['movement_count'] = count($ledger);
    $summary['closing_qty'] = $runningQty;
    $summary['closing_value'] = $runningValue;

} catch (Throwable $e) {
    $errors[] = 'Could not load stock ledger: ' . $e->getMessage();
}

require_once __DIR__ . '/../../includes/header.php';
?>

<div class="hero-band no-print">
    <div class="row g-4 align-items-center">
        <div class="col-lg-8">
            <div class="page-eyebrow text-white-50"><i class="bi bi-journal-text"></i> Inventory Ledger</div>
            <div class="hero-title mt-2">Stock Ledger</div>
            <div class="hero-subtitle mt-2">
                Item/store movement history with opening balance, running balance, quantities and values.
            </div>
        </div>
        <div class="col-lg-4 text-lg-end">
            <button onclick="window.print()" class="btn btn-light me-2">
                <i class="bi bi-printer me-2"></i>Print
            </button>
            <a href="stock_movements.php" class="btn btn-outline-light">
                <i class="bi bi-arrow-left-right me-2"></i>Movements
            </a>
        </div>
    </div>
</div>

<?php if ($errors): ?>
    <div class="alert alert-danger no-print">
        <div class="fw-bold mb-2">Please fix the following:</div>
        <ul class="mb-0"><?php foreach ($errors as $err): ?><li><?php echo h($err); ?></li><?php endforeach; ?></ul>
    </div>
<?php endif; ?>

<div class="card panel-card mb-4 no-print">
    <div class="card-body">
        <form method="get" class="row g-3 align-items-end">
            <div class="col-md-2">
                <label class="form-label">From</label>
                <input type="date" name="date_from" class="form-control" value="<?php echo h($dateFrom); ?>">
            </div>
            <div class="col-md-2">
                <label class="form-label">To</label>
                <input type="date" name="date_to" class="form-control" value="<?php echo h($dateTo); ?>">
            </div>
            <div class="col-md-2">
                <label class="form-label">Store</label>
                <select name="store_id" class="form-select">
                    <option value="0">All stores</option>
                    <?php foreach ($stores as $store): ?>
                        <option value="<?php echo (int)$store['id']; ?>" <?php echo $storeId === (int)$store['id'] ? 'selected' : ''; ?>>
                            <?php echo h($store['location_name']); ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-md-3">
                <label class="form-label">Item</label>
                <select name="item_id" class="form-select">
                    <option value="0">All items</option>
                    <?php foreach ($items as $item): ?>
                        <option value="<?php echo (int)$item['id']; ?>" <?php echo $itemId === (int)$item['id'] ? 'selected' : ''; ?>>
                            <?php echo h($item['item_name']); ?><?php echo !empty($item['item_code']) ? ' • ' . h($item['item_code']) : ''; ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-md-2">
                <label class="form-label">Movement</label>
                <select name="movement_type" class="form-select">
                    <option value="">All movements</option>
                    <?php foreach (['OPENING','GRN','ISSUE','SALE','TRANSFER_IN','TRANSFER_OUT','ADJUSTMENT_IN','ADJUSTMENT_OUT','WASTAGE','RETURN'] as $mt): ?>
                        <option value="<?php echo h($mt); ?>" <?php echo $movementType === $mt ? 'selected' : ''; ?>>
                            <?php echo h(str_replace('_',' ', $mt)); ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-md-1 d-grid">
                <button class="btn btn-primary"><i class="bi bi-funnel"></i></button>
            </div>
            <div class="col-md-12">
                <label class="form-label">Search</label>
                <input type="text" name="q" class="form-control" value="<?php echo h($search); ?>" placeholder="Item / store / reference / notes">
            </div>
        </form>
    </div>
</div>

<div class="print-title d-none d-print-block">
    <h2>Stock Ledger</h2>
    <p>
        Period: <?php echo h($dateFrom); ?> to <?php echo h($dateTo); ?>
        <?php if ($selectedStore): ?> | Store: <?php echo h($selectedStore['location_name']); ?><?php endif; ?>
        <?php if ($selectedItem): ?> | Item: <?php echo h($selectedItem['item_name']); ?><?php endif; ?>
    </p>
</div>

<div class="row g-4 mb-4">
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-secondary-subtle text-secondary"><i class="bi bi-box-arrow-in-down"></i></div>
            <div><div class="metric-label">Opening Qty</div><div class="metric-value small-value"><?php echo qty_fmt($summary['opening_qty']); ?></div></div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-success-subtle text-success"><i class="bi bi-arrow-down-circle"></i></div>
            <div><div class="metric-label">Qty In</div><div class="metric-value small-value"><?php echo qty_fmt($summary['qty_in']); ?></div></div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-danger-subtle text-danger"><i class="bi bi-arrow-up-circle"></i></div>
            <div><div class="metric-label">Qty Out</div><div class="metric-value small-value"><?php echo qty_fmt($summary['qty_out']); ?></div></div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-primary-subtle text-primary"><i class="bi bi-box-seam"></i></div>
            <div><div class="metric-label">Closing Qty</div><div class="metric-value small-value"><?php echo qty_fmt($summary['closing_qty']); ?></div></div>
        </div>
    </div>
</div>

<div class="row g-4 mb-4">
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-secondary-subtle text-secondary"><i class="bi bi-wallet2"></i></div>
            <div><div class="metric-label">Opening Value</div><div class="metric-value small-value"><?php echo money_fmt($summary['opening_value']); ?></div></div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-success-subtle text-success"><i class="bi bi-cash-stack"></i></div>
            <div><div class="metric-label">Value In</div><div class="metric-value small-value"><?php echo money_fmt($summary['value_in']); ?></div></div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-danger-subtle text-danger"><i class="bi bi-cash"></i></div>
            <div><div class="metric-label">Value Out</div><div class="metric-value small-value"><?php echo money_fmt($summary['value_out']); ?></div></div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-primary-subtle text-primary"><i class="bi bi-bank"></i></div>
            <div><div class="metric-label">Closing Value</div><div class="metric-value small-value"><?php echo money_fmt($summary['closing_value']); ?></div></div>
        </div>
    </div>
</div>

<div class="card panel-card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <div>
            <h5 class="mb-0">Ledger Movements</h5>
            <div class="small text-muted">
                <?php echo (int)$summary['movement_count']; ?> movements shown.
                <?php if ($selectedItem): ?> Item: <?php echo h($selectedItem['item_name']); ?><?php endif; ?>
                <?php if ($selectedStore): ?> • Store: <?php echo h($selectedStore['location_name']); ?><?php endif; ?>
            </div>
        </div>
        <span class="badge text-bg-light border no-print">Running balance enabled</span>
    </div>

    <div class="card-body p-0">
        <div class="table-responsive ledger-table-wrap">
            <table class="table table-modern align-middle mb-0">
                <thead>
                <tr>
                    <th>Date</th>
                    <th>Item</th>
                    <th>Store</th>
                    <th>Movement</th>
                    <th class="text-end">Qty In</th>
                    <th class="text-end">Qty Out</th>
                    <th class="text-end">Balance Qty</th>
                    <th class="text-end">Unit Cost</th>
                    <th class="text-end">Value</th>
                    <th class="text-end">Running Value</th>
                    <th>Reference</th>
                    <th>Notes</th>
                </tr>
                </thead>
                <tbody>
                <tr class="table-light">
                    <td><?php echo h($dateFrom); ?></td>
                    <td colspan="5"><strong>Opening Balance</strong></td>
                    <td class="text-end fw-bold"><?php echo qty_fmt($summary['opening_qty']); ?></td>
                    <td></td>
                    <td class="text-end"><?php echo money_fmt($summary['opening_value']); ?></td>
                    <td class="text-end fw-bold"><?php echo money_fmt($summary['opening_value']); ?></td>
                    <td colspan="2"></td>
                </tr>

                <?php if (!$ledger): ?>
                    <tr><td colspan="12" class="text-center text-muted py-4">No stock movements found.</td></tr>
                <?php else: foreach ($ledger as $row): ?>
                    <?php
                        $isIn = (float)$row['qty_in'] > 0;
                        $value = (float)$row['total_cost'];
                    ?>
                    <tr>
                        <td><?php echo h($row['movement_date']); ?></td>
                        <td>
                            <strong><?php echo h($row['item_name'] ?: 'Item'); ?></strong>
                            <div class="small text-muted"><?php echo h($row['item_code'] ?? ''); ?></div>
                        </td>
                        <td><?php echo h($row['location_name'] ?: 'Store'); ?></td>
                        <td>
                            <span class="badge <?php echo $isIn ? 'text-bg-success' : 'text-bg-warning'; ?>">
                                <?php echo h(str_replace('_',' ', $row['movement_type'])); ?>
                            </span>
                        </td>
                        <td class="text-end text-success"><?php echo qty_fmt($row['qty_in']); ?> <?php echo h($row['unit_code']); ?></td>
                        <td class="text-end text-danger"><?php echo qty_fmt($row['qty_out']); ?> <?php echo h($row['unit_code']); ?></td>
                        <td class="text-end fw-bold"><?php echo qty_fmt($row['running_qty']); ?> <?php echo h($row['unit_code']); ?></td>
                        <td class="text-end"><?php echo money_fmt($row['unit_cost']); ?></td>
                        <td class="text-end <?php echo $isIn ? 'text-success' : 'text-danger'; ?>">
                            <?php echo ($isIn ? '+' : '-'); ?><?php echo money_fmt($value); ?>
                        </td>
                        <td class="text-end fw-bold"><?php echo money_fmt($row['running_value']); ?></td>
                        <td>
                            <?php echo h($row['reference_type'] ?: '—'); ?>
                            <?php if (!empty($row['reference_id'])): ?>
                                <div class="small text-muted">#<?php echo (int)$row['reference_id']; ?></div>
                            <?php endif; ?>
                        </td>
                        <td class="small"><?php echo h(mb_strimwidth((string)$row['notes'], 0, 80, '...')); ?></td>
                    </tr>
                <?php endforeach; endif; ?>

                <tr class="table-light">
                    <td><?php echo h($dateTo); ?></td>
                    <td colspan="5"><strong>Closing Balance</strong></td>
                    <td class="text-end fw-bold"><?php echo qty_fmt($summary['closing_qty']); ?></td>
                    <td></td>
                    <td></td>
                    <td class="text-end fw-bold"><?php echo money_fmt($summary['closing_value']); ?></td>
                    <td colspan="2"></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

<style>
.small-value{font-size:1rem!important;letter-spacing:0!important}
.ledger-table-wrap{max-height:720px;overflow:auto}
.ledger-table-wrap thead th{position:sticky;top:0;z-index:2;background:#f8fafc}
.print-title{margin-bottom:18px}
@media print{
    .no-print,.sidebar,.enterprise-sidebar,.app-sidebar,.topbar,.navbar,.header,.footer{display:none!important}
    body{background:#fff!important}
    .panel-card,.card,.metric-card{box-shadow:none!important;border:1px solid #ddd!important}
    .ledger-table-wrap{max-height:none!important;overflow:visible!important}
    .ledger-table-wrap thead th{position:static!important}
    .table{font-size:11px}
}
</style>

<?php require_once __DIR__ . '/../../includes/footer.php'; ?>
