chore: add diag-mvtart to inspect columns and CA totals

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Sonnet 4.6 committed 2026-04-01 09:28:53 +02:00
1 parent c5fbc85c6c
commit 3e4b320cbe
1 file changed
+44
+44
View File
@@ -0,0 +1,44 @@
import { NextResponse } from "next/server";
import { db } from "@/db";
import { sql } from "drizzle-orm";
export async function GET() {
try {
// Colonnes de mvtart
const cols = await db.execute(sql`
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'mvtart'
ORDER BY ordinal_position
`);
// 5 ventes récentes avec tous les montants visibles
const sample = await db.execute(sql`
SELECT *
FROM mvtart
WHERE genremvt = 3 AND site IN ('292', '579')
ORDER BY datmvt DESC
LIMIT 5
`);
// CA mars 2025 par site via mntmvtttc — pour comparer avec le cube
const totaux = await db.execute(sql`
SELECT site,
ABS(SUM(mntmvtttc))::float AS ca_mntmvtttc,
COUNT(*) AS nb_lignes
FROM mvtart
WHERE genremvt = 3
AND TO_CHAR(datmvt, 'YYYY-MM') = '2025-03'
AND site IN ('292', '579')
GROUP BY site
`);
return NextResponse.json({
columns: cols.rows,
sample_ventes: sample.rows,
totaux_202503: totaux.rows,
});
} catch (e) {
return NextResponse.json({ error: String(e) }, { status: 500 });
}
}