@fullqueso/mcp-bc-gastos 1.11.0 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,16 @@ export const COGS_ACCOUNTS = {
25
25
  57020: { name: 'Costos Diversos', nameEn: 'Diverse Costs' },
26
26
  };
27
27
 
28
+ // Income group labels for breakdown (by 100-prefix: 40110 → 40100)
29
+ export const INCOME_GROUP_LABELS = {
30
+ 40100: '40100_ingreso_ventas',
31
+ 40300: '40300_facturacion_directa',
32
+ 40400: '40400_ingreso_servicios',
33
+ 40500: '40500_otros_ingresos',
34
+ 40600: '40600_ingreso_alquiler',
35
+ 40900: '40900_extraordinarios',
36
+ };
37
+
28
38
  // Ranges
29
39
  export const REVENUE_RANGE = { min: 40000, max: 49999 };
30
40
  export const COGS_RANGE = { min: 50000, max: 59999 };
package/lib/bc-client.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { logger } from '../utils/logger.js';
2
2
  import { getExpenseCategory } from '../config/expense-accounts.js';
3
+ import { INCOME_GROUP_LABELS } from '../config/income-accounts.js';
3
4
  import { resolveStores } from '../config/company-config.js';
4
5
 
5
6
  export class BCClient {
@@ -308,6 +309,26 @@ export class BCClient {
308
309
  0
309
310
  );
310
311
 
312
+ // Income breakdown by account group (401xx, 405xx, etc.)
313
+ const groupTotals = {};
314
+ for (const e of revenueEntries) {
315
+ const prefix = Math.floor(parseInt(e.accountNumber, 10) / 100) * 100;
316
+ groupTotals[prefix] = (groupTotals[prefix] || 0) + ((e.creditAmount || 0) - (e.debitAmount || 0));
317
+ }
318
+ const incomeBreakdown = {};
319
+ let breakdownSum = 0;
320
+ for (const [prefix, amount] of Object.entries(groupTotals)) {
321
+ const label = INCOME_GROUP_LABELS[prefix] || `${prefix}_other`;
322
+ incomeBreakdown[label] = Math.round(amount * 100) / 100;
323
+ breakdownSum += amount;
324
+ }
325
+ // Catch rounding drift vs totalRevenue
326
+ const drift = Math.round((totalRevenue - breakdownSum) * 100) / 100;
327
+ if (Math.abs(drift) > 0.005) {
328
+ incomeBreakdown.unclassified = drift;
329
+ }
330
+ incomeBreakdown.total = Math.round(totalRevenue * 100) / 100;
331
+
311
332
  // COGS (50000-59999): debit balance accounts, cost = debit - credit
312
333
  const totalCOGS = cogsEntries.reduce(
313
334
  (sum, e) => sum + ((e.debitAmount || 0) - (e.creditAmount || 0)),
@@ -341,6 +362,7 @@ export class BCClient {
341
362
  period: { start: startDate, end: endDate },
342
363
  expenses: categorizedExpenses,
343
364
  totalRevenue,
365
+ incomeBreakdown,
344
366
  totalCOGS,
345
367
  grossMargin,
346
368
  grossMarginPct,
@@ -85,6 +85,7 @@ export function analyzeExpenses(storeData) {
85
85
  store_code: storeData.storeCode,
86
86
  period: storeData.period,
87
87
  total_revenue: round2(totalRevenue || totalIncome),
88
+ income_breakdown: storeData.incomeBreakdown || null,
88
89
  total_cogs: round2(totalCOGS || 0),
89
90
  gross_margin: round2(grossMargin || totalIncome),
90
91
  gross_margin_pct: round2(grossMarginPct || 0),
@@ -90,6 +90,7 @@ export function calculateRatios(storeData) {
90
90
  store_code: storeData.storeCode,
91
91
  period: storeData.period,
92
92
  total_income: round2(totalIncome),
93
+ income_breakdown: storeData.incomeBreakdown || null,
93
94
  total_expenses: round2(totalExpenses),
94
95
  main_ratios: ratios,
95
96
  key_ratios: keyRatios,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullqueso/mcp-bc-gastos",
3
- "version": "1.11.0",
3
+ "version": "1.11.1",
4
4
  "description": "MCP server for Business Central operational expense analysis, bank reconciliation, POS reconciliation, accounts receivable/payable, and multi-payment draft visibility - Full Queso franchise stores",
5
5
  "main": "server.js",
6
6
  "bin": {