store();
if ($action === 'update') $invoiceController->update();
if ($action === 'form') {
include __DIR__ . '/../app/Views/invoices/form.php';
exit;
}
if ($action === 'edit') {
$edit = $repository->find((int)($_GET['id'] ?? 0));
include __DIR__ . '/../app/Views/invoices/form.php';
exit;
}
if ($action === 'delete') $invoiceController->delete();
if ($action === 'tva') $invoiceController->selectedVat();
}
if ($action === 'pdf') {
$invoiceController->pdf();
exit;
}
if ($action === 'csv') {
// Filtres liste
$listYear = isset($_GET['year']) ? (int)$_GET['year'] : (int)date('Y');
$listPage = isset($_GET['page']) ? max(1,(int)$_GET['page']) : 1;
$listSort = isset($_GET['sort']) ? $_GET['sort'] : 'date_desc';
$listQuarter = isset($_GET['quarter']) ? trim($_GET['quarter']) : '';
$listQ = isset($_GET['q']) ? trim($_GET['q']) : '';
$perPage = 20;
$totalInv = $repository->countSearch($listYear, $listQuarter, $listQ);
$pages = max(1, (int)ceil($totalInv / $perPage));
if ($listPage > $pages) $listPage = $pages;
$invoices = $repository->search($listYear, $listPage, $perPage, $listSort, $listQuarter, $listQ);
$availYears = $repository->availableYears();
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="factures.csv"');
$out = fopen('php://output', 'w');
fputcsv($out, ['FACTURE', 'NUMERO', 'DATE', 'TRIMESTRE', 'ANNEE'], ';');
fputcsv($out, ['LIGNE', 'DESIGNATION', 'QTE', 'PU HT', 'TOTAL HT'], ';');
fputcsv($out, [], ';');
foreach ($invoices as $inv) {
fputcsv($out, ['FACTURE', $inv['invoice_number'], $inv['invoice_date'], $inv['quarter'], $inv['year']], ';');
$it = $pdo->prepare('SELECT * FROM invoice_items WHERE invoice_id=:id ORDER BY id ASC');
$it->execute(['id' => $inv['id']]);
foreach ($it->fetchAll() as $item) {
fputcsv($out, ['LIGNE', $item['description'], $item['quantity'], $item['unit_price_ht'], $item['line_total_ht']], ';');
}
fputcsv($out, ['TOTAL HT', $inv['total_ht']], ';');
fputcsv($out, ['TVA 20%', $inv['total_vat']], ';');
fputcsv($out, ['TOTAL TTC', $inv['total_ttc']], ';');
fputcsv($out, [], ';');
}
fclose($out);
exit;
}
if ($action === 'excel') {
$xid = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($xid > 0) {
ob_end_clean();
header('Location: /TV@/dlxls.php?id=' . $xid);
exit;
}
if (!empty($_POST['invoice_ids'])) {
ob_end_clean();
require_once dirname(__DIR__) . '/dlxls.php';
exit;
}
echo '
Selectionnez au moins une facture.
';
exit;
}
$invoices = $repository->all();
$selectedTotals = $_SESSION['selected_totals'] ?? null;
unset($_SESSION['selected_totals']);
$edit = null;
if ($action === 'edit') {
$edit = $repository->find((int)($_GET['id'] ?? 0));
}
$yearInvoices = array_values(array_filter($invoices, fn($inv) => (int)$inv['year'] === $dashboardYear));
$yearTotals = ['c' => count($yearInvoices), 'ht' => 0, 'vat' => 0, 'ttc' => 0];
foreach ($yearInvoices as $inv) {
$yearTotals['ht'] += (float)$inv['total_ht'];
$yearTotals['vat'] += (float)$inv['total_vat'];
$yearTotals['ttc'] += (float)$inv['total_ttc'];
}
$quarters = $repository->quarterSummary($dashboardYear);
$latest = array_slice($yearInvoices, 0, 10);
$nextNumber = $repository->nextNumber();
?>
Facturation TVA
Facturation TVA
Dashboard, factures, TVA, PDF, CSV, Excel
= e($_SESSION['success']); unset($_SESSION['success']); ?>
= e($_SESSION['error']); unset($_SESSION['error']); ?>
Dashboard = (int)$dashboardYear ?>
Factures = (int)$dashboardYear ?>
= (int)$yearTotals['c'] ?>
Total HT
= money($yearTotals['ht']) ?>
TVA
= money($yearTotals['vat']) ?>
TTC
= money($yearTotals['ttc']) ?>
| Trimestre | Factures | HT | TVA | TTC |
| = e($q['quarter']) ?> |
= (int)$q['c'] ?> |
= money($q['ht']) ?> |
= money($q['vat']) ?> |
= money($q['ttc']) ?> |
Dernières factures de l’année = (int)$dashboardYear ?>
| N° | Date | Trimestre | TVA | TTC |
| = e($inv['invoice_number']) ?> |
= e($inv['invoice_date']) ?> |
= e($inv['quarter']) ?> |
= money($inv['total_vat']) ?> |
= money($inv['total_ttc']) ?> |
countSearch($listYear, $listQuarter, $listQ);
$pages = max(1,(int)ceil($totalInv / $perPage));
if ($listPage > $pages) $listPage = $pages;
$invoices = $repository->search($listYear, $listPage, $perPage, $listSort, $listQuarter, $listQ);
$availYears = $repository->availableYears();
$baseParams = http_build_query(array_filter(["action"=>"list","year"=>$listYear,"sort"=>$listSort,"quarter"=>$listQuarter,"q"=>$listQ],fn($v)=>$v!==" "&&$v!==null&&$v!==0));
?>