mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-20 13:38:08 +02:00
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:
1 parent
3e4b320cbe
commit
63641e9de9
2 files changed
+28
-44
No files matched your search
@@ -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 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -151,6 +151,33 @@ export async function GET(req: NextRequest) {
|
|||||||
ventesProduitsDiag = { error: String(e) };
|
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({
|
return NextResponse.json({
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
dateRange: { dateDebut, dateFin },
|
dateRange: { dateDebut, dateFin },
|
||||||
@@ -170,5 +197,6 @@ export async function GET(req: NextRequest) {
|
|||||||
},
|
},
|
||||||
postgresql,
|
postgresql,
|
||||||
ventesProduitsDiag,
|
ventesProduitsDiag,
|
||||||
|
mvtartDiag,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user