File manager - Edit - /home/webtrixia/mynetronix.webtrixia.com/admin/invoices.php
Back
<?php require_once __DIR__ . '/../includes/config.php'; require_once __DIR__ . '/../includes/db.php'; require_once __DIR__ . '/../includes/auth.php'; require_once __DIR__ . '/../includes/layout.php'; require_admin(); $msg = $err = ''; $filter_client = (int)($_GET['client_id'] ?? 0); // DELETE if (isset($_GET['delete']) && is_numeric($_GET['delete'])) { db()->prepare("DELETE FROM invoices WHERE id=?")->execute([(int)$_GET['delete']]); $msg = 'Фактурата е изтрита.'; } // MARK PAID if (isset($_GET['mark_paid']) && is_numeric($_GET['mark_paid'])) { db()->prepare("UPDATE invoices SET paid=1 WHERE id=?")->execute([(int)$_GET['mark_paid']]); $msg = 'Фактурата е маркирана като платена.'; } // ADD INVOICE if ($_SERVER['REQUEST_METHOD'] === 'POST') { $client_id = (int)($_POST['client_id'] ?? 0); $period = trim($_POST['period'] ?? ''); $amount = (float)($_POST['amount_bgn'] ?? 0); $due_days = (int)($_POST['due_days'] ?? 10); if (!$client_id || !$amount) { $err = 'Клиент и сума са задължителни.'; } else { $eur = round($amount / BGN_EUR, 2); $number = 'INV-' . date('Y') . '-' . str_pad(db()->query("SELECT COUNT(*)+1 FROM invoices")->fetchColumn(), 5, '0', STR_PAD_LEFT); $issued = date('Y-m-d'); $due = date('Y-m-d', strtotime("+{$due_days} days")); db()->prepare("INSERT INTO invoices (client_id, number, period, amount_bgn, amount_eur, issued_at, due_at) VALUES (?,?,?,?,?,?,?)") ->execute([$client_id, $number, $period, $amount, $eur, $issued, $due]); $msg = "Фактура {$number} е създадена."; } } // ALL CLIENTS for dropdown $all_clients = db()->query("SELECT id, client_number, name FROM clients WHERE status='active' ORDER BY name")->fetchAll(); // LIST if ($filter_client) { $st = db()->prepare("SELECT i.*, c.name, c.client_number FROM invoices i JOIN clients c ON c.id=i.client_id WHERE i.client_id=? ORDER BY i.issued_at DESC"); $st->execute([$filter_client]); } else { $st = db()->query("SELECT i.*, c.name, c.client_number FROM invoices i JOIN clients c ON c.id=i.client_id ORDER BY i.issued_at DESC"); } $invoices = $st->fetchAll(); page_header('Фактури', true); ?> <div class="page-title">🧾 Фактури</div> <?php if ($msg): ?><div class="alert alert-success"><?= htmlspecialchars($msg) ?></div><?php endif; ?> <?php if ($err): ?><div class="alert alert-danger"><?= htmlspecialchars($err) ?></div><?php endif; ?> <div class="card"> <div class="card-header">➕ Издай фактура</div> <div class="card-body"> <form method="POST"> <div class="form-row"> <div class="form-group"> <label>Клиент *</label> <select name="client_id" required> <option value="">— Изберете клиент —</option> <?php foreach ($all_clients as $c): ?> <option value="<?= $c['id'] ?>" <?= $filter_client===$c['id']?'selected':'' ?>> <?= htmlspecialchars($c['client_number'] . ' — ' . $c['name']) ?> </option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label>Период (напр. 01.2026)</label> <input type="text" name="period" placeholder="01.2026" value="<?= date('m.Y') ?>"> </div> </div> <div class="form-row"> <div class="form-group"> <label>Сума (лв.) *</label> <input type="number" step="0.01" name="amount_bgn" placeholder="21.00" required> </div> <div class="form-group"> <label>Срок за плащане (дни)</label> <input type="number" name="due_days" value="10"> </div> </div> <button type="submit" class="btn btn-primary">🧾 Издай фактура</button> </form> </div> </div> <div class="card"> <div class="card-header dark"> 📋 Фактури <?= $filter_client ? '— филтрирано по клиент ' : '' ?>(<?= count($invoices) ?>) <?php if ($filter_client): ?> <a href="<?= SITE_URL ?>/admin/invoices.php" class="btn btn-sm btn-outline" style="margin-left:auto">✖ Покажи всички</a> <?php endif; ?> </div> <div class="card-body" style="padding:0"> <?php if ($invoices): ?> <table class="tbl"> <thead> <tr><th>№</th><th>Клиент</th><th>Период</th><th>Сума</th><th>Издадена</th><th>Краен срок</th><th>Статус</th><th>Действия</th></tr> </thead> <tbody> <?php foreach ($invoices as $inv): ?> <tr> <td><strong><?= htmlspecialchars($inv['number']) ?></strong></td> <td> <?= htmlspecialchars($inv['name']) ?><br> <small style="color:#888"><?= $inv['client_number'] ?></small> </td> <td><?= htmlspecialchars($inv['period'] ?: '—') ?></td> <td> <strong><?= number_format($inv['amount_eur'],2) ?> €</strong><br> <small><?= number_format($inv['amount_bgn'],2) ?> лв.</small> </td> <td style="font-size:12px"><?= $inv['issued_at'] ?></td> <td style="font-size:12px"><?= $inv['due_at'] ?></td> <td> <?php if ($inv['paid']): ?> <span class="badge badge-paid">✅ Платена</span> <?php elseif ($inv['due_at'] < date('Y-m-d')): ?> <span class="badge badge-denied">⚠️ Просрочена</span> <?php else: ?> <span class="badge badge-pending">⏳ Чакаща</span> <?php endif; ?> </td> <td style="white-space:nowrap"> <?php if (!$inv['paid']): ?> <a href="?mark_paid=<?= $inv['id'] ?><?= $filter_client?"&client_id=$filter_client":'' ?>" class="btn btn-sm btn-success" onclick="return confirm('Маркирай като платена?')">✅</a> <?php endif; ?> <a href="?delete=<?= $inv['id'] ?><?= $filter_client?"&client_id=$filter_client":'' ?>" class="btn btn-sm btn-danger" onclick="return confirm('Изтрий фактура?')">🗑</a> </td> </tr> <?php endforeach; ?> </tbody> </table> <?php else: ?> <div class="empty-state"><div class="empty-icon">🧾</div><p>Няма фактури</p></div> <?php endif; ?> </div> </div> <?php page_footer(); ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.31 | Generation time: 0.05 |
proxy
|
phpinfo
|
Settings