Skip to content

Commit a359af1

Browse files
committed
fix: improve variable naming
1 parent cfa5272 commit a359af1

File tree

2 files changed

+46
-34
lines changed

2 files changed

+46
-34
lines changed

src/pages/Dashboard/Cashflow.vue

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -83,38 +83,44 @@ export default defineComponent({
8383
customPeriod: { type: String, default: 'This Year' },
8484
},
8585
data: () => ({
86-
data: [] as { inflow: number; outflow: number; yearmonth: string }[],
86+
cashflowRecords: [] as {
87+
inflow: number;
88+
outflow: number;
89+
yearmonth: string;
90+
}[],
8791
periodList: [],
8892
periodOptions: ['This Year', 'This Quarter', 'YTD', 'Custom'],
8993
hasData: false,
9094
}),
9195
computed: {
9296
chartData() {
93-
let data = this.data;
97+
let records = this.cashflowRecords;
9498
let colors = [
9599
uicolors.blue[this.darkMode ? '600' : '500'],
96100
uicolors.pink[this.darkMode ? '600' : '500'],
97101
];
98102
if (!this.hasData) {
99-
data = dummyData;
103+
records = dummyData;
100104
colors = [
101105
this.darkMode ? uicolors.gray['700'] : uicolors.gray['200'],
102106
this.darkMode ? uicolors.gray['800'] : uicolors.gray['100'],
103107
];
104108
}
105109
106-
const xLabels = data.map((cf) => cf.yearmonth);
107-
const points = (['inflow', 'outflow'] as const).map((k) =>
108-
data.map((d) => d[k])
110+
const xLabels = records.map((cf) => cf.yearmonth);
111+
const points = (['inflow', 'outflow'] as const).map((flowType) =>
112+
records.map((entry) => entry[flowType])
109113
);
110114
111-
const format = (value: number) => fyo.format(value ?? 0, 'Currency');
115+
const formatCurrency = (value: number) =>
116+
fyo.format(value ?? 0, 'Currency');
112117
const yMax = getYMax(points);
118+
113119
return {
114120
points,
115121
xLabels,
116122
colors,
117-
format,
123+
format: formatCurrency,
118124
yMax,
119125
formatX: formatXLabels,
120126
gridColor: this.darkMode ? 'rgba(200, 200, 200, 0.2)' : undefined,
@@ -137,7 +143,7 @@ export default defineComponent({
137143
async setData() {
138144
let fromDate: DateTime;
139145
let toDate: DateTime;
140-
let periodList: DateTime[] = [];
146+
let generatedPeriods: DateTime[] = [];
141147
142148
if (this.period === 'Custom') {
143149
const parseDate = (date: string | Date) =>
@@ -148,32 +154,35 @@ export default defineComponent({
148154
fromDate = parseDate(this.fromDate);
149155
toDate = parseDate(this.toDate);
150156
151-
let current = fromDate.startOf('month');
152-
157+
let monthPointer = fromDate.startOf('month');
153158
const toMonthStart = toDate.startOf('month');
154159
155-
while (current <= toMonthStart) {
156-
periodList.push(current);
157-
current = current.plus({ months: 1 });
160+
while (monthPointer <= toMonthStart) {
161+
generatedPeriods.push(monthPointer);
162+
monthPointer = monthPointer.plus({ months: 1 });
158163
}
159164
160-
periodList.push(fromDate.startOf('month'));
165+
generatedPeriods.push(fromDate.startOf('month'));
161166
} else {
162-
const result = getDatesAndPeriodList(this.period);
163-
fromDate = result.fromDate;
164-
toDate = result.toDate;
165-
periodList = result.periodList;
167+
const dateRange = getDatesAndPeriodList(this.period);
168+
fromDate = dateRange.fromDate;
169+
toDate = dateRange.toDate;
170+
generatedPeriods = dateRange.periodList;
166171
}
167172
168-
const data = await fyo.db.getCashflow(fromDate.toISO(), toDate.toISO());
169-
const dataMap = getMapFromList(data, 'yearmonth');
173+
const cashflowData = await fyo.db.getCashflow(
174+
fromDate.toISO(),
175+
toDate.toISO()
176+
);
177+
const cashflowMap = getMapFromList(cashflowData, 'yearmonth');
178+
170179
this.period = this.commonPeriod;
171-
this.data = periodList.map((p) => {
172-
const key = p.toFormat('yyyy-MM');
173-
const item = dataMap[key];
180+
this.cashflowRecords = generatedPeriods.map((periodDate) => {
181+
const key = periodDate.toFormat('yyyy-MM');
182+
const entry = cashflowMap[key];
174183
175184
return (
176-
item ?? {
185+
entry ?? {
177186
inflow: 0,
178187
outflow: 0,
179188
yearmonth: key,
@@ -187,11 +196,14 @@ export default defineComponent({
187196
accountType: ['in', [AccountTypeEnum.Cash, AccountTypeEnum.Bank]],
188197
},
189198
});
190-
const accountNames = accounts.map((a) => a.name as string);
191-
const count = await fyo.db.count(ModelNameEnum.AccountingLedgerEntry, {
192-
filters: { account: ['in', accountNames] },
193-
});
194-
this.hasData = count > 0;
199+
const accountNames = accounts.map((account) => account.name as string);
200+
const ledgerEntryCount = await fyo.db.count(
201+
ModelNameEnum.AccountingLedgerEntry,
202+
{
203+
filters: { account: ['in', accountNames] },
204+
}
205+
);
206+
this.hasData = ledgerEntryCount > 0;
195207
},
196208
},
197209
});

src/utils/dashboardDateUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export function getDashboardDates(
3232
current = current.plus({ months: 1 });
3333
}
3434
} else {
35-
const result = getDatesAndPeriodList(period as PeriodKey);
36-
fromDateResult = result.fromDate;
37-
toDateResult = result.toDate;
38-
periodList = result.periodList;
35+
const dateRange = getDatesAndPeriodList(period as PeriodKey);
36+
fromDateResult = dateRange.fromDate;
37+
toDateResult = dateRange.toDate;
38+
periodList = dateRange.periodList;
3939
}
4040

4141
return {

0 commit comments

Comments
 (0)