chore: add mvtart column diag to /api/diag, remove unused diag-mvtart

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Sonnet 4.6 committed 2026-04-01 09:36:21 +02:00
1 parent 3e4b320cbe
commit 63641e9de9
2 files changed
+28 -44

No files matched your search

-44
View File
@@ -1,44 +0,0 @@
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 });
}
}
+28
View File
@@ -151,6 +151,33 @@ export async function GET(req: NextRequest) {
ventesProduitsDiag = { error: String(e) };
}
// Diagnostic mvtart : colonnes + totaux mars 2025 + sample vente
let mvtartDiag: unknown;
try {
const cols = await db.execute(sql`
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'mvtart'
ORDER BY ordinal_position
`);
const totaux = await db.execute(sql`
SELECT site,
ABS(SUM(mntmvtttc))::float AS sum_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
`);
const sampleVente = await db.execute(sql`
SELECT * FROM mvtart WHERE genremvt = 3 AND site = '292' LIMIT 1
`);
mvtartDiag = { columns: cols.rows, totaux_202503: totaux.rows, sample: sampleVente.rows };
} catch (e) {
mvtartDiag = { error: String(e) };
}
return NextResponse.json({
timestamp: new Date().toISOString(),
dateRange: { dateDebut, dateFin },
@@ -170,5 +197,6 @@ export async function GET(req: NextRequest) {
},
postgresql,
ventesProduitsDiag,
mvtartDiag,
});
}