@pfm-platform/budgets-feature 0.2.0 → 0.2.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.
package/dist/index.cjs CHANGED
@@ -5,10 +5,10 @@ var budgetsDataAccess = require('@pfm-platform/budgets-data-access');
5
5
 
6
6
  // src/hooks/useBudgetProgress.ts
7
7
  function useBudgetProgress(options) {
8
- const { userId, start_date, end_date } = options;
8
+ const { userId, month, year } = options;
9
9
  const { data } = budgetsDataAccess.useBudgets({
10
10
  userId,
11
- filters: { start_date, end_date }
11
+ filters: { month, year }
12
12
  });
13
13
  return react.useMemo(() => {
14
14
  if (!data?.budgets || data.budgets.length === 0) {
@@ -40,10 +40,10 @@ function useBudgetProgress(options) {
40
40
  }, [data]);
41
41
  }
42
42
  function useBudgetSummary(options) {
43
- const { userId, start_date, end_date } = options;
43
+ const { userId, month, year } = options;
44
44
  const { data } = budgetsDataAccess.useBudgets({
45
45
  userId,
46
- filters: { start_date, end_date }
46
+ filters: { month, year }
47
47
  });
48
48
  return react.useMemo(() => {
49
49
  if (!data?.budgets) {
@@ -79,10 +79,10 @@ function useBudgetSummary(options) {
79
79
  }, [data]);
80
80
  }
81
81
  function useBudgetsByMonth(options) {
82
- const { userId, start_date, end_date } = options;
82
+ const { userId, month, year } = options;
83
83
  const { data } = budgetsDataAccess.useBudgets({
84
84
  userId,
85
- filters: { start_date, end_date }
85
+ filters: { month, year }
86
86
  });
87
87
  return react.useMemo(() => {
88
88
  if (!data?.budgets || data.budgets.length === 0) {
@@ -99,16 +99,16 @@ function useBudgetsByMonth(options) {
99
99
  budgetCount: 0
100
100
  };
101
101
  }
102
- const month = grouped[monthKey];
103
- month.totalBudget += budget.budget_amount || 0;
104
- month.totalSpent += budget.spent || 0;
105
- month.budgetCount += 1;
106
- if (month.totalSpent > month.totalBudget) {
107
- month.state = "over";
108
- } else if (month.totalSpent < month.totalBudget) {
109
- month.state = "under";
102
+ const mo = grouped[monthKey];
103
+ mo.totalBudget += budget.budget_amount || 0;
104
+ mo.totalSpent += budget.spent || 0;
105
+ mo.budgetCount += 1;
106
+ if (mo.totalSpent > mo.totalBudget) {
107
+ mo.state = "over";
108
+ } else if (mo.totalSpent < mo.totalBudget) {
109
+ mo.state = "under";
110
110
  } else {
111
- month.state = "risk";
111
+ mo.state = "risk";
112
112
  }
113
113
  });
114
114
  return grouped;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/useBudgetProgress.ts","../src/hooks/useBudgetSummary.ts","../src/hooks/useBudgetsByMonth.ts"],"names":["useBudgets","useMemo"],"mappings":";;;;;;AAuBO,SAAS,kBAAkB,OAAA,EAAkD;AAClF,EAAA,MAAM,EAAE,MAAA,EAAQ,UAAA,EAAY,QAAA,EAAS,GAAI,OAAA;AAEzC,EAAA,MAAM,EAAE,IAAA,EAAK,GAAIA,4BAAA,CAAW;AAAA,IAC1B,MAAA;AAAA,IACA,OAAA,EAAS,EAAE,UAAA,EAAY,QAAA;AAAS,GACjC,CAAA;AAED,EAAA,OAAOC,cAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,IAAA,EAAM,OAAA,IAAW,IAAA,CAAK,OAAA,CAAQ,WAAW,CAAA,EAAG;AAC/C,MAAA,OAAO,EAAC;AAAA,IACV;AAEA,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW;AAClC,MAAA,MAAM,KAAA,GAAQ,OAAO,KAAA,IAAS,CAAA;AAC9B,MAAA,MAAM,YAAA,GAAe,OAAO,aAAA,IAAiB,CAAA;AAC7C,MAAA,MAAM,YAAY,YAAA,GAAe,KAAA;AACjC,MAAA,MAAM,YAAA,GAAe,YAAA,GAAe,CAAA,GAAK,KAAA,GAAQ,eAAgB,GAAA,GAAM,CAAA;AAEvE,MAAA,IAAI,KAAA;AACJ,MAAA,IAAI,QAAQ,YAAA,EAAc;AACxB,QAAA,KAAA,GAAQ,MAAA;AAAA,MACV,CAAA,MAAA,IAA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AA,GAAI;AAAA,UAClB,WAAA,EAAa,CAAA;AAAA,UACb,UAAA,EAAY,CAAA;AAAA,UACZ,KAAA,EAAO,OAAA;AAAA,UACP,WAAA,EAAa;AAAA,SACf;AAAA,MACF;AAEA,MAAA,MAAM,KAAA,GAAQ,QAAQ,QAAQ,CAAA;AAC9B,MAAA,KAAA,CAAM,WAAA,IAAe,OAAO,aAAA,IAAiB,CAAA;AAC7C,MAAA,KAAA,CAAM,UAAA,IAAc,OAAO,KAAA,IAAS,CAAA;AACpC,MAAA,KAAA,CAAM,WAAA,IAAe,CAAA;AAGrB,MAAA,IAAI,KAAA,CAAM,UAAA,GAAa,KAAA,CAAM,WAAA,EAAa;AACxC,QAAA,KAAA,CAAM,KAAA,GAAQ,MAAA;AAAA,MAChB,CAAA,MAAA,IAAW,KAAA,CAAM,UAAA,GAAa,KAAA,CAAM,WAAA,EAAa;AAC/C,QAAA,KAAA,CAAM,KAAA,GAAQ,OAAA;AAAA,MAChB,CAAA,MAAO;AACL,QAAA,KAAA,CAAM,KAAA,GAAQ,MAAA;AAAA,MAChB;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAO,OAAA;AAAA,EACT,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AACX","file":"index.cjs","sourcesContent":["import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface BudgetProgress {\n id: number;\n name: string;\n budgetAmount: number;\n spent: number;\n remaining: number;\n percentSpent: number;\n state: 'under' | 'risk' | 'over';\n}\n\nexport interface BudgetProgressOptions {\n userId: string;\n start_date?: string;\n end_date?: string;\n}\n\n/**\n * Calculate progress for each budget (spent vs budget amount)\n * Replaces: budgetsStore/List.js listByMonth computed property\n */\nexport function useBudgetProgress(options: BudgetProgressOptions): BudgetProgress[] {\n const { userId, start_date, end_date } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { start_date, end_date },\n });\n\n return useMemo(() => {\n if (!data?.budgets || data.budgets.length === 0) {\n return [];\n }\n\n return data.budgets.map((budget) => {\n const spent = budget.spent || 0;\n const budgetAmount = budget.budget_amount || 0;\n const remaining = budgetAmount - spent;\n const percentSpent = budgetAmount > 0 ? (spent / budgetAmount) * 100 : 0;\n\n let state: 'under' | 'risk' | 'over';\n if (spent > budgetAmount) {\n state = 'over';\n } else if (spent < budgetAmount) {\n state = 'under';\n } else {\n state = 'risk';\n }\n\n return {\n id: budget.id,\n name: budget.name,\n budgetAmount,\n spent,\n remaining,\n percentSpent,\n state,\n };\n });\n }, [data]);\n}\n","import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface BudgetSummary {\n totalBudgets: number;\n totalBudget: number;\n totalSpent: number;\n totalRemaining: number;\n percentSpent: number;\n state: 'under' | 'risk' | 'over';\n hasBudgets: boolean;\n}\n\nexport interface BudgetSummaryOptions {\n userId: string;\n start_date?: string;\n end_date?: string;\n}\n\n/**\n * Calculate budget summary totals across all budgets\n * Replaces: budgetsStore.meta and budgetsStore.hasBudgets computed properties\n */\nexport function useBudgetSummary(\n options: BudgetSummaryOptions\n): BudgetSummary | null {\n const { userId, start_date, end_date } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { start_date, end_date },\n });\n\n return useMemo(() => {\n if (!data?.budgets) {\n return null;\n }\n\n const totalBudget = data.budgets.reduce(\n (sum, budget) => sum + (budget.budget_amount || 0),\n 0\n );\n const totalSpent = data.budgets.reduce(\n (sum, budget) => sum + (budget.spent || 0),\n 0\n );\n const totalRemaining = totalBudget - totalSpent;\n const percentSpent = totalBudget > 0 ? (totalSpent / totalBudget) * 100 : 0;\n\n let state: 'under' | 'risk' | 'over';\n if (totalSpent > totalBudget) {\n state = 'over';\n } else if (totalSpent < totalBudget) {\n state = 'under';\n } else {\n state = 'risk';\n }\n\n return {\n totalBudgets: data.budgets.length,\n totalBudget,\n totalSpent,\n totalRemaining,\n percentSpent,\n state,\n hasBudgets: data.budgets.length > 0,\n };\n }, [data]);\n}\n","import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface MonthBudgetSummary {\n totalBudget: number;\n totalSpent: number;\n state: 'under' | 'risk' | 'over';\n budgetCount: number;\n}\n\nexport interface BudgetsByMonthOptions {\n userId: string;\n start_date?: string;\n end_date?: string;\n}\n\n/**\n * Group budgets by month with summary statistics\n * Replaces: budgetsStore/List.js listByMonth computed property\n *\n * Returns a map of month keys (YYYY-MM format) to budget summaries\n */\nexport function useBudgetsByMonth(\n options: BudgetsByMonthOptions\n): Record<string, MonthBudgetSummary> {\n const { userId, start_date, end_date } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { start_date, end_date },\n });\n\n return useMemo(() => {\n if (!data?.budgets || data.budgets.length === 0) {\n return {};\n }\n\n const grouped: Record<string, MonthBudgetSummary> = {};\n\n data.budgets.forEach((budget) => {\n // Create month key in YYYY-MM format\n const monthKey = `${budget.year}-${String(budget.month).padStart(2, '0')}`;\n\n if (!grouped[monthKey]) {\n grouped[monthKey] = {\n totalBudget: 0,\n totalSpent: 0,\n state: 'under',\n budgetCount: 0,\n };\n }\n\n const month = grouped[monthKey];\n month.totalBudget += budget.budget_amount || 0;\n month.totalSpent += budget.spent || 0;\n month.budgetCount += 1;\n\n // Determine state\n if (month.totalSpent > month.totalBudget) {\n month.state = 'over';\n } else if (month.totalSpent < month.totalBudget) {\n month.state = 'under';\n } else {\n month.state = 'risk';\n }\n });\n\n return grouped;\n }, [data]);\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/useBudgetProgress.ts","../src/hooks/useBudgetSummary.ts","../src/hooks/useBudgetsByMonth.ts"],"names":["useBudgets","useMemo"],"mappings":";;;;;;AAuBO,SAAS,kBAAkB,OAAA,EAAkD;AAClF,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAO,IAAA,EAAK,GAAI,OAAA;AAEhC,EAAA,MAAM,EAAE,IAAA,EAAK,GAAIA,4BAAA,CAAW;AAAA,IAC1B,MAAA;AAAA,IACA,OAAA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,OAAA;AAAA,MACb,CAAA,MAAO;AACL,QAAA,EAAA,CAAG,KAAA,GAAQ,MAAA;AAAA,MACb;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAO,OAAA;AAAA,EACT,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AACX","file":"index.cjs","sourcesContent":["import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface BudgetProgress {\n id: string;\n name: string;\n budgetAmount: number;\n spent: number;\n remaining: number;\n percentSpent: number;\n state: 'under' | 'risk' | 'over';\n}\n\nexport interface BudgetProgressOptions {\n userId: string;\n month?: number;\n year?: number;\n}\n\n/**\n * Calculate progress for each budget (spent vs budget amount)\n * Replaces: budgetsStore/List.js listByMonth computed property\n */\nexport function useBudgetProgress(options: BudgetProgressOptions): BudgetProgress[] {\n const { userId, month, year } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { month, year },\n });\n\n return useMemo(() => {\n if (!data?.budgets || data.budgets.length === 0) {\n return [];\n }\n\n return data.budgets.map((budget) => {\n const spent = budget.spent || 0;\n const budgetAmount = budget.budget_amount || 0;\n const remaining = budgetAmount - spent;\n const percentSpent = budgetAmount > 0 ? (spent / budgetAmount) * 100 : 0;\n\n let state: 'under' | 'risk' | 'over';\n if (spent > budgetAmount) {\n state = 'over';\n } else if (spent < budgetAmount) {\n state = 'under';\n } else {\n state = 'risk';\n }\n\n return {\n id: budget.id,\n name: budget.name,\n budgetAmount,\n spent,\n remaining,\n percentSpent,\n state,\n };\n });\n }, [data]);\n}\n","import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface BudgetSummary {\n totalBudgets: number;\n totalBudget: number;\n totalSpent: number;\n totalRemaining: number;\n percentSpent: number;\n state: 'under' | 'risk' | 'over';\n hasBudgets: boolean;\n}\n\nexport interface BudgetSummaryOptions {\n userId: string;\n month?: number;\n year?: number;\n}\n\n/**\n * Calculate budget summary totals across all budgets\n * Replaces: budgetsStore.meta and budgetsStore.hasBudgets computed properties\n */\nexport function useBudgetSummary(\n options: BudgetSummaryOptions\n): BudgetSummary | null {\n const { userId, month, year } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { month, year },\n });\n\n return useMemo(() => {\n if (!data?.budgets) {\n return null;\n }\n\n const totalBudget = data.budgets.reduce(\n (sum, budget) => sum + (budget.budget_amount || 0),\n 0\n );\n const totalSpent = data.budgets.reduce(\n (sum, budget) => sum + (budget.spent || 0),\n 0\n );\n const totalRemaining = totalBudget - totalSpent;\n const percentSpent = totalBudget > 0 ? (totalSpent / totalBudget) * 100 : 0;\n\n let state: 'under' | 'risk' | 'over';\n if (totalSpent > totalBudget) {\n state = 'over';\n } else if (totalSpent < totalBudget) {\n state = 'under';\n } else {\n state = 'risk';\n }\n\n return {\n totalBudgets: data.budgets.length,\n totalBudget,\n totalSpent,\n totalRemaining,\n percentSpent,\n state,\n hasBudgets: data.budgets.length > 0,\n };\n }, [data]);\n}\n","import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface MonthBudgetSummary {\n totalBudget: number;\n totalSpent: number;\n state: 'under' | 'risk' | 'over';\n budgetCount: number;\n}\n\nexport interface BudgetsByMonthOptions {\n userId: string;\n month?: number;\n year?: number;\n}\n\n/**\n * Group budgets by month with summary statistics\n * Replaces: budgetsStore/List.js listByMonth computed property\n *\n * Returns a map of month keys (YYYY-MM format) to budget summaries\n */\nexport function useBudgetsByMonth(\n options: BudgetsByMonthOptions\n): Record<string, MonthBudgetSummary> {\n const { userId, month, year } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { month, year },\n });\n\n return useMemo(() => {\n if (!data?.budgets || data.budgets.length === 0) {\n return {};\n }\n\n const grouped: Record<string, MonthBudgetSummary> = {};\n\n data.budgets.forEach((budget) => {\n // Create month key in YYYY-MM format\n const monthKey = `${budget.year}-${String(budget.month).padStart(2, '0')}`;\n\n if (!grouped[monthKey]) {\n grouped[monthKey] = {\n totalBudget: 0,\n totalSpent: 0,\n state: 'under',\n budgetCount: 0,\n };\n }\n\n const mo = grouped[monthKey];\n mo.totalBudget += budget.budget_amount || 0;\n mo.totalSpent += budget.spent || 0;\n mo.budgetCount += 1;\n\n // Determine state\n if (mo.totalSpent > mo.totalBudget) {\n mo.state = 'over';\n } else if (mo.totalSpent < mo.totalBudget) {\n mo.state = 'under';\n } else {\n mo.state = 'risk';\n }\n });\n\n return grouped;\n }, [data]);\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  interface BudgetProgress {
2
- id: number;
2
+ id: string;
3
3
  name: string;
4
4
  budgetAmount: number;
5
5
  spent: number;
@@ -9,8 +9,8 @@ interface BudgetProgress {
9
9
  }
10
10
  interface BudgetProgressOptions {
11
11
  userId: string;
12
- start_date?: string;
13
- end_date?: string;
12
+ month?: number;
13
+ year?: number;
14
14
  }
15
15
  /**
16
16
  * Calculate progress for each budget (spent vs budget amount)
@@ -29,8 +29,8 @@ interface BudgetSummary {
29
29
  }
30
30
  interface BudgetSummaryOptions {
31
31
  userId: string;
32
- start_date?: string;
33
- end_date?: string;
32
+ month?: number;
33
+ year?: number;
34
34
  }
35
35
  /**
36
36
  * Calculate budget summary totals across all budgets
@@ -46,8 +46,8 @@ interface MonthBudgetSummary {
46
46
  }
47
47
  interface BudgetsByMonthOptions {
48
48
  userId: string;
49
- start_date?: string;
50
- end_date?: string;
49
+ month?: number;
50
+ year?: number;
51
51
  }
52
52
  /**
53
53
  * Group budgets by month with summary statistics
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  interface BudgetProgress {
2
- id: number;
2
+ id: string;
3
3
  name: string;
4
4
  budgetAmount: number;
5
5
  spent: number;
@@ -9,8 +9,8 @@ interface BudgetProgress {
9
9
  }
10
10
  interface BudgetProgressOptions {
11
11
  userId: string;
12
- start_date?: string;
13
- end_date?: string;
12
+ month?: number;
13
+ year?: number;
14
14
  }
15
15
  /**
16
16
  * Calculate progress for each budget (spent vs budget amount)
@@ -29,8 +29,8 @@ interface BudgetSummary {
29
29
  }
30
30
  interface BudgetSummaryOptions {
31
31
  userId: string;
32
- start_date?: string;
33
- end_date?: string;
32
+ month?: number;
33
+ year?: number;
34
34
  }
35
35
  /**
36
36
  * Calculate budget summary totals across all budgets
@@ -46,8 +46,8 @@ interface MonthBudgetSummary {
46
46
  }
47
47
  interface BudgetsByMonthOptions {
48
48
  userId: string;
49
- start_date?: string;
50
- end_date?: string;
49
+ month?: number;
50
+ year?: number;
51
51
  }
52
52
  /**
53
53
  * Group budgets by month with summary statistics
package/dist/index.js CHANGED
@@ -3,10 +3,10 @@ import { useBudgets } from '@pfm-platform/budgets-data-access';
3
3
 
4
4
  // src/hooks/useBudgetProgress.ts
5
5
  function useBudgetProgress(options) {
6
- const { userId, start_date, end_date } = options;
6
+ const { userId, month, year } = options;
7
7
  const { data } = useBudgets({
8
8
  userId,
9
- filters: { start_date, end_date }
9
+ filters: { month, year }
10
10
  });
11
11
  return useMemo(() => {
12
12
  if (!data?.budgets || data.budgets.length === 0) {
@@ -38,10 +38,10 @@ function useBudgetProgress(options) {
38
38
  }, [data]);
39
39
  }
40
40
  function useBudgetSummary(options) {
41
- const { userId, start_date, end_date } = options;
41
+ const { userId, month, year } = options;
42
42
  const { data } = useBudgets({
43
43
  userId,
44
- filters: { start_date, end_date }
44
+ filters: { month, year }
45
45
  });
46
46
  return useMemo(() => {
47
47
  if (!data?.budgets) {
@@ -77,10 +77,10 @@ function useBudgetSummary(options) {
77
77
  }, [data]);
78
78
  }
79
79
  function useBudgetsByMonth(options) {
80
- const { userId, start_date, end_date } = options;
80
+ const { userId, month, year } = options;
81
81
  const { data } = useBudgets({
82
82
  userId,
83
- filters: { start_date, end_date }
83
+ filters: { month, year }
84
84
  });
85
85
  return useMemo(() => {
86
86
  if (!data?.budgets || data.budgets.length === 0) {
@@ -97,16 +97,16 @@ function useBudgetsByMonth(options) {
97
97
  budgetCount: 0
98
98
  };
99
99
  }
100
- const month = grouped[monthKey];
101
- month.totalBudget += budget.budget_amount || 0;
102
- month.totalSpent += budget.spent || 0;
103
- month.budgetCount += 1;
104
- if (month.totalSpent > month.totalBudget) {
105
- month.state = "over";
106
- } else if (month.totalSpent < month.totalBudget) {
107
- month.state = "under";
100
+ const mo = grouped[monthKey];
101
+ mo.totalBudget += budget.budget_amount || 0;
102
+ mo.totalSpent += budget.spent || 0;
103
+ mo.budgetCount += 1;
104
+ if (mo.totalSpent > mo.totalBudget) {
105
+ mo.state = "over";
106
+ } else if (mo.totalSpent < mo.totalBudget) {
107
+ mo.state = "under";
108
108
  } else {
109
- month.state = "risk";
109
+ mo.state = "risk";
110
110
  }
111
111
  });
112
112
  return grouped;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/useBudgetProgress.ts","../src/hooks/useBudgetSummary.ts","../src/hooks/useBudgetsByMonth.ts"],"names":["useBudgets","useMemo"],"mappings":";;;;AAuBO,SAAS,kBAAkB,OAAA,EAAkD;AAClF,EAAA,MAAM,EAAE,MAAA,EAAQ,UAAA,EAAY,QAAA,EAAS,GAAI,OAAA;AAEzC,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,UAAA,CAAW;AAAA,IAC1B,MAAA;AAAA,IACA,OAAA,EAAS,EAAE,UAAA,EAAY,QAAA;AAAS,GACjC,CAAA;AAED,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,IAAA,EAAM,OAAA,IAAW,IAAA,CAAK,OAAA,CAAQ,WAAW,CAAA,EAAG;AAC/C,MAAA,OAAO,EAAC;AAAA,IACV;AAEA,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW;AAClC,MAAA,MAAM,KAAA,GAAQ,OAAO,KAAA,IAAS,CAAA;AAC9B,MAAA,MAAM,YAAA,GAAe,OAAO,aAAA,IAAiB,CAAA;AAC7C,MAAA,MAAM,YAAY,YAAA,GAAe,KAAA;AACjC,MAA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I,CAAA,CAAA,EAAI,MAAA,CAAO,MAAA,CAAO,KAAK,CAAA,CAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAA;AAExE,MAAA,IAAI,CAAC,OAAA,CAAQ,QAAQ,CAAA,EAAG;AACtB,QAAA,OAAA,CAAQ,QAAQ,CAAA,GAAI;AAAA,UAClB,WAAA,EAAa,CAAA;AAAA,UACb,UAAA,EAAY,CAAA;AAAA,UACZ,KAAA,EAAO,OAAA;AAAA,UACP,WAAA,EAAa;AAAA,SACf;AAAA,MACF;AAEA,MAAA,MAAM,KAAA,GAAQ,QAAQ,QAAQ,CAAA;AAC9B,MAAA,KAAA,CAAM,WAAA,IAAe,OAAO,aAAA,IAAiB,CAAA;AAC7C,MAAA,KAAA,CAAM,UAAA,IAAc,OAAO,KAAA,IAAS,CAAA;AACpC,MAAA,KAAA,CAAM,WAAA,IAAe,CAAA;AAGrB,MAAA,IAAI,KAAA,CAAM,UAAA,GAAa,KAAA,CAAM,WAAA,EAAa;AACxC,QAAA,KAAA,CAAM,KAAA,GAAQ,MAAA;AAAA,MAChB,CAAA,MAAA,IAAW,KAAA,CAAM,UAAA,GAAa,KAAA,CAAM,WAAA,EAAa;AAC/C,QAAA,KAAA,CAAM,KAAA,GAAQ,OAAA;AAAA,MAChB,CAAA,MAAO;AACL,QAAA,KAAA,CAAM,KAAA,GAAQ,MAAA;AAAA,MAChB;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAO,OAAA;AAAA,EACT,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AACX","file":"index.js","sourcesContent":["import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface BudgetProgress {\n id: number;\n name: string;\n budgetAmount: number;\n spent: number;\n remaining: number;\n percentSpent: number;\n state: 'under' | 'risk' | 'over';\n}\n\nexport interface BudgetProgressOptions {\n userId: string;\n start_date?: string;\n end_date?: string;\n}\n\n/**\n * Calculate progress for each budget (spent vs budget amount)\n * Replaces: budgetsStore/List.js listByMonth computed property\n */\nexport function useBudgetProgress(options: BudgetProgressOptions): BudgetProgress[] {\n const { userId, start_date, end_date } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { start_date, end_date },\n });\n\n return useMemo(() => {\n if (!data?.budgets || data.budgets.length === 0) {\n return [];\n }\n\n return data.budgets.map((budget) => {\n const spent = budget.spent || 0;\n const budgetAmount = budget.budget_amount || 0;\n const remaining = budgetAmount - spent;\n const percentSpent = budgetAmount > 0 ? (spent / budgetAmount) * 100 : 0;\n\n let state: 'under' | 'risk' | 'over';\n if (spent > budgetAmount) {\n state = 'over';\n } else if (spent < budgetAmount) {\n state = 'under';\n } else {\n state = 'risk';\n }\n\n return {\n id: budget.id,\n name: budget.name,\n budgetAmount,\n spent,\n remaining,\n percentSpent,\n state,\n };\n });\n }, [data]);\n}\n","import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface BudgetSummary {\n totalBudgets: number;\n totalBudget: number;\n totalSpent: number;\n totalRemaining: number;\n percentSpent: number;\n state: 'under' | 'risk' | 'over';\n hasBudgets: boolean;\n}\n\nexport interface BudgetSummaryOptions {\n userId: string;\n start_date?: string;\n end_date?: string;\n}\n\n/**\n * Calculate budget summary totals across all budgets\n * Replaces: budgetsStore.meta and budgetsStore.hasBudgets computed properties\n */\nexport function useBudgetSummary(\n options: BudgetSummaryOptions\n): BudgetSummary | null {\n const { userId, start_date, end_date } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { start_date, end_date },\n });\n\n return useMemo(() => {\n if (!data?.budgets) {\n return null;\n }\n\n const totalBudget = data.budgets.reduce(\n (sum, budget) => sum + (budget.budget_amount || 0),\n 0\n );\n const totalSpent = data.budgets.reduce(\n (sum, budget) => sum + (budget.spent || 0),\n 0\n );\n const totalRemaining = totalBudget - totalSpent;\n const percentSpent = totalBudget > 0 ? (totalSpent / totalBudget) * 100 : 0;\n\n let state: 'under' | 'risk' | 'over';\n if (totalSpent > totalBudget) {\n state = 'over';\n } else if (totalSpent < totalBudget) {\n state = 'under';\n } else {\n state = 'risk';\n }\n\n return {\n totalBudgets: data.budgets.length,\n totalBudget,\n totalSpent,\n totalRemaining,\n percentSpent,\n state,\n hasBudgets: data.budgets.length > 0,\n };\n }, [data]);\n}\n","import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface MonthBudgetSummary {\n totalBudget: number;\n totalSpent: number;\n state: 'under' | 'risk' | 'over';\n budgetCount: number;\n}\n\nexport interface BudgetsByMonthOptions {\n userId: string;\n start_date?: string;\n end_date?: string;\n}\n\n/**\n * Group budgets by month with summary statistics\n * Replaces: budgetsStore/List.js listByMonth computed property\n *\n * Returns a map of month keys (YYYY-MM format) to budget summaries\n */\nexport function useBudgetsByMonth(\n options: BudgetsByMonthOptions\n): Record<string, MonthBudgetSummary> {\n const { userId, start_date, end_date } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { start_date, end_date },\n });\n\n return useMemo(() => {\n if (!data?.budgets || data.budgets.length === 0) {\n return {};\n }\n\n const grouped: Record<string, MonthBudgetSummary> = {};\n\n data.budgets.forEach((budget) => {\n // Create month key in YYYY-MM format\n const monthKey = `${budget.year}-${String(budget.month).padStart(2, '0')}`;\n\n if (!grouped[monthKey]) {\n grouped[monthKey] = {\n totalBudget: 0,\n totalSpent: 0,\n state: 'under',\n budgetCount: 0,\n };\n }\n\n const month = grouped[monthKey];\n month.totalBudget += budget.budget_amount || 0;\n month.totalSpent += budget.spent || 0;\n month.budgetCount += 1;\n\n // Determine state\n if (month.totalSpent > month.totalBudget) {\n month.state = 'over';\n } else if (month.totalSpent < month.totalBudget) {\n month.state = 'under';\n } else {\n month.state = 'risk';\n }\n });\n\n return grouped;\n }, [data]);\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/useBudgetProgress.ts","../src/hooks/useBudgetSummary.ts","../src/hooks/useBudgetsByMonth.ts"],"names":["useBudgets","useMemo"],"mappings":";;;;AAu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,UAAA,GAAa,EAAA,CAAG,WAAA,EAAa;AAClC,QAAA,EAAA,CAAG,KAAA,GAAQ,MAAA;AAAA,MACb,CAAA,MAAA,IAAW,EAAA,CAAG,UAAA,GAAa,EAAA,CAAG,WAAA,EAAa;AACzC,QAAA,EAAA,CAAG,KAAA,GAAQ,OAAA;AAAA,MACb,CAAA,MAAO;AACL,QAAA,EAAA,CAAG,KAAA,GAAQ,MAAA;AAAA,MACb;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAO,OAAA;AAAA,EACT,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AACX","file":"index.js","sourcesContent":["import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface BudgetProgress {\n id: string;\n name: string;\n budgetAmount: number;\n spent: number;\n remaining: number;\n percentSpent: number;\n state: 'under' | 'risk' | 'over';\n}\n\nexport interface BudgetProgressOptions {\n userId: string;\n month?: number;\n year?: number;\n}\n\n/**\n * Calculate progress for each budget (spent vs budget amount)\n * Replaces: budgetsStore/List.js listByMonth computed property\n */\nexport function useBudgetProgress(options: BudgetProgressOptions): BudgetProgress[] {\n const { userId, month, year } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { month, year },\n });\n\n return useMemo(() => {\n if (!data?.budgets || data.budgets.length === 0) {\n return [];\n }\n\n return data.budgets.map((budget) => {\n const spent = budget.spent || 0;\n const budgetAmount = budget.budget_amount || 0;\n const remaining = budgetAmount - spent;\n const percentSpent = budgetAmount > 0 ? (spent / budgetAmount) * 100 : 0;\n\n let state: 'under' | 'risk' | 'over';\n if (spent > budgetAmount) {\n state = 'over';\n } else if (spent < budgetAmount) {\n state = 'under';\n } else {\n state = 'risk';\n }\n\n return {\n id: budget.id,\n name: budget.name,\n budgetAmount,\n spent,\n remaining,\n percentSpent,\n state,\n };\n });\n }, [data]);\n}\n","import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface BudgetSummary {\n totalBudgets: number;\n totalBudget: number;\n totalSpent: number;\n totalRemaining: number;\n percentSpent: number;\n state: 'under' | 'risk' | 'over';\n hasBudgets: boolean;\n}\n\nexport interface BudgetSummaryOptions {\n userId: string;\n month?: number;\n year?: number;\n}\n\n/**\n * Calculate budget summary totals across all budgets\n * Replaces: budgetsStore.meta and budgetsStore.hasBudgets computed properties\n */\nexport function useBudgetSummary(\n options: BudgetSummaryOptions\n): BudgetSummary | null {\n const { userId, month, year } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { month, year },\n });\n\n return useMemo(() => {\n if (!data?.budgets) {\n return null;\n }\n\n const totalBudget = data.budgets.reduce(\n (sum, budget) => sum + (budget.budget_amount || 0),\n 0\n );\n const totalSpent = data.budgets.reduce(\n (sum, budget) => sum + (budget.spent || 0),\n 0\n );\n const totalRemaining = totalBudget - totalSpent;\n const percentSpent = totalBudget > 0 ? (totalSpent / totalBudget) * 100 : 0;\n\n let state: 'under' | 'risk' | 'over';\n if (totalSpent > totalBudget) {\n state = 'over';\n } else if (totalSpent < totalBudget) {\n state = 'under';\n } else {\n state = 'risk';\n }\n\n return {\n totalBudgets: data.budgets.length,\n totalBudget,\n totalSpent,\n totalRemaining,\n percentSpent,\n state,\n hasBudgets: data.budgets.length > 0,\n };\n }, [data]);\n}\n","import { useMemo } from 'react';\nimport { useBudgets } from '@pfm-platform/budgets-data-access';\n\nexport interface MonthBudgetSummary {\n totalBudget: number;\n totalSpent: number;\n state: 'under' | 'risk' | 'over';\n budgetCount: number;\n}\n\nexport interface BudgetsByMonthOptions {\n userId: string;\n month?: number;\n year?: number;\n}\n\n/**\n * Group budgets by month with summary statistics\n * Replaces: budgetsStore/List.js listByMonth computed property\n *\n * Returns a map of month keys (YYYY-MM format) to budget summaries\n */\nexport function useBudgetsByMonth(\n options: BudgetsByMonthOptions\n): Record<string, MonthBudgetSummary> {\n const { userId, month, year } = options;\n\n const { data } = useBudgets({\n userId,\n filters: { month, year },\n });\n\n return useMemo(() => {\n if (!data?.budgets || data.budgets.length === 0) {\n return {};\n }\n\n const grouped: Record<string, MonthBudgetSummary> = {};\n\n data.budgets.forEach((budget) => {\n // Create month key in YYYY-MM format\n const monthKey = `${budget.year}-${String(budget.month).padStart(2, '0')}`;\n\n if (!grouped[monthKey]) {\n grouped[monthKey] = {\n totalBudget: 0,\n totalSpent: 0,\n state: 'under',\n budgetCount: 0,\n };\n }\n\n const mo = grouped[monthKey];\n mo.totalBudget += budget.budget_amount || 0;\n mo.totalSpent += budget.spent || 0;\n mo.budgetCount += 1;\n\n // Determine state\n if (mo.totalSpent > mo.totalBudget) {\n mo.state = 'over';\n } else if (mo.totalSpent < mo.totalBudget) {\n mo.state = 'under';\n } else {\n mo.state = 'risk';\n }\n });\n\n return grouped;\n }, [data]);\n}\n"]}
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@pfm-platform/budgets-feature",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "dependencies": {
8
- "react": "19.2.0",
9
- "@pfm-platform/budgets-data-access": "0.2.0",
10
- "@pfm-platform/shared": "0.1.0"
8
+ "react": "19.2.4",
9
+ "@pfm-platform/budgets-data-access": "0.2.1",
10
+ "@pfm-platform/shared": "0.2.1"
11
11
  },
12
12
  "devDependencies": {
13
- "@tanstack/react-query": "5.90.9",
14
- "@testing-library/react": "^16.3.0",
13
+ "@tanstack/react-query": "5.90.21",
14
+ "@testing-library/react": "^16.3.2",
15
15
  "@testing-library/user-event": "^14.6.1",
16
- "@types/react": "^19.2.5",
17
- "@vitejs/plugin-react": "^5.1.1",
18
- "@vitest/coverage-v8": "^4.0.9",
16
+ "@types/react": "^19.2.14",
17
+ "@vitejs/plugin-react": "^5.1.4",
18
+ "@vitest/coverage-v8": "^4.0.18",
19
19
  "jsdom": "^27.2.0",
20
- "react-dom": "19.2.0",
20
+ "react-dom": "19.2.4",
21
21
  "typescript": "5.9.3",
22
- "vitest": "4.0.9"
22
+ "vitest": "4.0.18"
23
23
  },
24
24
  "module": "./dist/index.js",
25
25
  "exports": {