@layerfi/components 0.1.6 → 0.1.7
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/esm/index.js +711 -59
- package/dist/esm/index.js.map +4 -4
- package/dist/index.d.ts +92 -1
- package/dist/index.js +706 -61
- package/dist/index.js.map +4 -4
- package/dist/styles/index.css +241 -0
- package/dist/styles/index.css.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4047,7 +4047,7 @@ var MOCK_DATA = [
|
|
|
4047
4047
|
{
|
|
4048
4048
|
name: "Account",
|
|
4049
4049
|
account: "4321",
|
|
4050
|
-
amount:
|
|
4050
|
+
amount: 801.91
|
|
4051
4051
|
}
|
|
4052
4052
|
];
|
|
4053
4053
|
var useLinkedAccounts = () => {
|
|
@@ -4112,6 +4112,62 @@ var import_react55 = __toESM(require("react"));
|
|
|
4112
4112
|
|
|
4113
4113
|
// src/hooks/useProfitAndLoss/useProfitAndLoss.tsx
|
|
4114
4114
|
var import_react47 = require("react");
|
|
4115
|
+
|
|
4116
|
+
// src/utils/profitAndLossUtils.ts
|
|
4117
|
+
var doesLineItemQualifies = (item) => {
|
|
4118
|
+
return !(item.is_contra || item.value === void 0 || item.value === null || isNaN(item.value) || item.value === -Infinity || item.value === Infinity || item.value < 0);
|
|
4119
|
+
};
|
|
4120
|
+
var collectSubItems = (type, item) => {
|
|
4121
|
+
if (!item) {
|
|
4122
|
+
return [];
|
|
4123
|
+
}
|
|
4124
|
+
const items = [];
|
|
4125
|
+
item?.line_items?.forEach((item2) => {
|
|
4126
|
+
if (doesLineItemQualifies(item2)) {
|
|
4127
|
+
items.push({
|
|
4128
|
+
name: item2.name,
|
|
4129
|
+
display_name: item2.display_name,
|
|
4130
|
+
value: Math.abs(item2.value || 0),
|
|
4131
|
+
// @TODO - confirm that's safe to do this
|
|
4132
|
+
type
|
|
4133
|
+
});
|
|
4134
|
+
}
|
|
4135
|
+
});
|
|
4136
|
+
return items;
|
|
4137
|
+
};
|
|
4138
|
+
var collectExpensesItems = (data) => {
|
|
4139
|
+
const cogs = collectSubItems("Cost of Goods Sold", data.cost_of_goods_sold);
|
|
4140
|
+
const expenses = collectSubItems("Operating Expenses", data.expenses);
|
|
4141
|
+
const taxes = collectSubItems("Taxes & Licenses", data.taxes);
|
|
4142
|
+
return [].concat(cogs).concat(expenses).concat(taxes);
|
|
4143
|
+
};
|
|
4144
|
+
var collectRevenueItems = (data) => {
|
|
4145
|
+
const income = collectSubItems("Income", data.income);
|
|
4146
|
+
return [].concat(income);
|
|
4147
|
+
};
|
|
4148
|
+
var humanizeTitle = (sidebarView) => {
|
|
4149
|
+
switch (sidebarView) {
|
|
4150
|
+
case "expenses":
|
|
4151
|
+
return "Expenses";
|
|
4152
|
+
case "revenue":
|
|
4153
|
+
return "Revenue";
|
|
4154
|
+
default:
|
|
4155
|
+
return "Profit & Loss";
|
|
4156
|
+
}
|
|
4157
|
+
};
|
|
4158
|
+
var applyShare = (items, total) => {
|
|
4159
|
+
return items.map((item) => {
|
|
4160
|
+
if (total === 0) {
|
|
4161
|
+
return item;
|
|
4162
|
+
}
|
|
4163
|
+
return {
|
|
4164
|
+
...item,
|
|
4165
|
+
share: item.value / total
|
|
4166
|
+
};
|
|
4167
|
+
});
|
|
4168
|
+
};
|
|
4169
|
+
|
|
4170
|
+
// src/hooks/useProfitAndLoss/useProfitAndLoss.tsx
|
|
4115
4171
|
var import_date_fns10 = require("date-fns");
|
|
4116
4172
|
var import_swr4 = __toESM(require("swr"));
|
|
4117
4173
|
var useProfitAndLoss = ({
|
|
@@ -4130,6 +4186,11 @@ var useProfitAndLoss = ({
|
|
|
4130
4186
|
const [endDate, setEndDate] = (0, import_react47.useState)(
|
|
4131
4187
|
initialEndDate || (0, import_date_fns10.endOfMonth)(Date.now())
|
|
4132
4188
|
);
|
|
4189
|
+
const [filters, setFilters] = (0, import_react47.useState)({
|
|
4190
|
+
expenses: void 0,
|
|
4191
|
+
revenue: void 0
|
|
4192
|
+
});
|
|
4193
|
+
const [sidebarScope, setSidebarScope] = (0, import_react47.useState)("expenses");
|
|
4133
4194
|
const {
|
|
4134
4195
|
data: rawData,
|
|
4135
4196
|
isLoading,
|
|
@@ -4152,6 +4213,43 @@ var useProfitAndLoss = ({
|
|
|
4152
4213
|
})
|
|
4153
4214
|
);
|
|
4154
4215
|
const { data, error } = rawData || {};
|
|
4216
|
+
const { filteredData, filteredTotal } = (0, import_react47.useMemo)(() => {
|
|
4217
|
+
if (!data) {
|
|
4218
|
+
return { filteredData: [], filteredTotal: void 0 };
|
|
4219
|
+
}
|
|
4220
|
+
const items = sidebarScope === "revenue" ? collectRevenueItems(data) : collectExpensesItems(data);
|
|
4221
|
+
const filtered = items.map((x) => {
|
|
4222
|
+
if (sidebarScope && filters[sidebarScope]?.types && filters[sidebarScope].types.length > 0 && !filters[sidebarScope]?.types?.includes(x.type)) {
|
|
4223
|
+
return {
|
|
4224
|
+
...x,
|
|
4225
|
+
hidden: true
|
|
4226
|
+
};
|
|
4227
|
+
}
|
|
4228
|
+
return x;
|
|
4229
|
+
});
|
|
4230
|
+
const sorted = filtered.sort((a, b) => {
|
|
4231
|
+
switch (filters[sidebarScope ?? "expenses"]?.sortBy) {
|
|
4232
|
+
case "category":
|
|
4233
|
+
if (filters[sidebarScope ?? "expenses"]?.sortDirection === "asc") {
|
|
4234
|
+
return a.display_name.localeCompare(b.display_name);
|
|
4235
|
+
}
|
|
4236
|
+
return b.display_name.localeCompare(a.display_name);
|
|
4237
|
+
case "type":
|
|
4238
|
+
if (filters[sidebarScope ?? "expenses"]?.sortDirection === "asc") {
|
|
4239
|
+
return a.type.localeCompare(b.type);
|
|
4240
|
+
}
|
|
4241
|
+
return b.type.localeCompare(a.type);
|
|
4242
|
+
default:
|
|
4243
|
+
if (filters[sidebarScope ?? "expenses"]?.sortDirection === "asc") {
|
|
4244
|
+
return a.value - b.value;
|
|
4245
|
+
}
|
|
4246
|
+
return b.value - a.value;
|
|
4247
|
+
}
|
|
4248
|
+
});
|
|
4249
|
+
const total = sorted.filter((x) => !x.hidden).reduce((x, { value }) => x + value, 0);
|
|
4250
|
+
const withShare = applyShare(sorted, total);
|
|
4251
|
+
return { filteredData: withShare, filteredTotal: total };
|
|
4252
|
+
}, [data, startDate, filters, sidebarScope]);
|
|
4155
4253
|
const changeDateRange = ({
|
|
4156
4254
|
startDate: newStartDate,
|
|
4157
4255
|
endDate: newEndDate
|
|
@@ -4162,14 +4260,40 @@ var useProfitAndLoss = ({
|
|
|
4162
4260
|
const refetch = () => {
|
|
4163
4261
|
mutate();
|
|
4164
4262
|
};
|
|
4263
|
+
const sortBy = (scope, field, direction) => {
|
|
4264
|
+
setFilters({
|
|
4265
|
+
...filters,
|
|
4266
|
+
[scope]: {
|
|
4267
|
+
...filters[scope],
|
|
4268
|
+
sortBy: field,
|
|
4269
|
+
sortDirection: direction ?? filters[scope]?.sortDirection === "desc" ? "asc" : "desc"
|
|
4270
|
+
}
|
|
4271
|
+
});
|
|
4272
|
+
};
|
|
4273
|
+
const setFilterTypes = (scope, types) => {
|
|
4274
|
+
setFilters({
|
|
4275
|
+
...filters,
|
|
4276
|
+
[scope]: {
|
|
4277
|
+
...filters[scope],
|
|
4278
|
+
types
|
|
4279
|
+
}
|
|
4280
|
+
});
|
|
4281
|
+
};
|
|
4165
4282
|
return {
|
|
4166
4283
|
data,
|
|
4284
|
+
filteredData,
|
|
4285
|
+
filteredTotal,
|
|
4167
4286
|
isLoading,
|
|
4168
4287
|
isValidating,
|
|
4169
4288
|
error: error || rawError,
|
|
4170
4289
|
dateRange: { startDate, endDate },
|
|
4171
4290
|
refetch,
|
|
4172
|
-
changeDateRange
|
|
4291
|
+
changeDateRange,
|
|
4292
|
+
sidebarScope,
|
|
4293
|
+
setSidebarScope,
|
|
4294
|
+
sortBy,
|
|
4295
|
+
filters,
|
|
4296
|
+
setFilterTypes
|
|
4173
4297
|
};
|
|
4174
4298
|
};
|
|
4175
4299
|
|
|
@@ -4178,6 +4302,38 @@ var import_react49 = __toESM(require("react"));
|
|
|
4178
4302
|
|
|
4179
4303
|
// src/utils/format.ts
|
|
4180
4304
|
var capitalizeFirstLetter = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
4305
|
+
var formatPercent = (value, options) => {
|
|
4306
|
+
if (!value && value !== 0) {
|
|
4307
|
+
return;
|
|
4308
|
+
}
|
|
4309
|
+
const val = value * 100;
|
|
4310
|
+
let defaultOptions = {
|
|
4311
|
+
minimumFractionDigits: 0,
|
|
4312
|
+
maximumFractionDigits: 0
|
|
4313
|
+
};
|
|
4314
|
+
if (Math.abs(val) < 10) {
|
|
4315
|
+
defaultOptions = {
|
|
4316
|
+
minimumFractionDigits: 1,
|
|
4317
|
+
maximumFractionDigits: 1
|
|
4318
|
+
};
|
|
4319
|
+
}
|
|
4320
|
+
if (Math.abs(val) < 1) {
|
|
4321
|
+
defaultOptions = {
|
|
4322
|
+
minimumFractionDigits: 1,
|
|
4323
|
+
maximumFractionDigits: 1
|
|
4324
|
+
};
|
|
4325
|
+
}
|
|
4326
|
+
if (val === 0) {
|
|
4327
|
+
defaultOptions = {
|
|
4328
|
+
minimumFractionDigits: 0,
|
|
4329
|
+
maximumFractionDigits: 0
|
|
4330
|
+
};
|
|
4331
|
+
}
|
|
4332
|
+
return val.toLocaleString("en-US", {
|
|
4333
|
+
...defaultOptions,
|
|
4334
|
+
...options
|
|
4335
|
+
});
|
|
4336
|
+
};
|
|
4181
4337
|
|
|
4182
4338
|
// src/components/ProfitAndLossChart/Indicator.tsx
|
|
4183
4339
|
var import_react48 = __toESM(require("react"));
|
|
@@ -4525,34 +4681,64 @@ var SkeletonLoader = ({
|
|
|
4525
4681
|
};
|
|
4526
4682
|
|
|
4527
4683
|
// src/components/ProfitAndLossSummaries/ProfitAndLossSummaries.tsx
|
|
4684
|
+
var import_classnames23 = __toESM(require("classnames"));
|
|
4528
4685
|
var ProfitAndLossSummaries = ({
|
|
4529
4686
|
vertical,
|
|
4530
4687
|
revenueLabel = "Revenue"
|
|
4531
4688
|
}) => {
|
|
4532
|
-
const {
|
|
4689
|
+
const {
|
|
4690
|
+
data: storedData,
|
|
4691
|
+
isLoading,
|
|
4692
|
+
setSidebarScope,
|
|
4693
|
+
sidebarScope
|
|
4694
|
+
} = (0, import_react52.useContext)(ProfitAndLoss.Context);
|
|
4533
4695
|
const data = storedData ? storedData : { income: { value: NaN }, net_profit: NaN };
|
|
4534
|
-
const incomeDirectionClass = (data.income.value ?? NaN) < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--
|
|
4535
|
-
const expensesDirectionClass = (data?.income?.value ?? NaN) - data.net_profit < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--
|
|
4536
|
-
const netProfitDirectionClass = data.net_profit < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--
|
|
4696
|
+
const incomeDirectionClass = (data.income.value ?? NaN) < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--positive";
|
|
4697
|
+
const expensesDirectionClass = (data?.income?.value ?? NaN) - data.net_profit < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--positive";
|
|
4698
|
+
const netProfitDirectionClass = data.net_profit < 0 ? "Layer__profit-and-loss-summaries__amount--negative" : "Layer__profit-and-loss-summaries__amount--positive";
|
|
4537
4699
|
return /* @__PURE__ */ import_react52.default.createElement(
|
|
4538
4700
|
"div",
|
|
4539
4701
|
{
|
|
4540
4702
|
className: `Layer__profit-and-loss-summaries ${vertical ? "flex-col" : ""}`
|
|
4541
4703
|
},
|
|
4542
|
-
/* @__PURE__ */ import_react52.default.createElement(
|
|
4543
|
-
"
|
|
4704
|
+
/* @__PURE__ */ import_react52.default.createElement(
|
|
4705
|
+
"div",
|
|
4544
4706
|
{
|
|
4545
|
-
className:
|
|
4707
|
+
className: (0, import_classnames23.default)(
|
|
4708
|
+
"Layer__profit-and-loss-summaries__summary Layer__actionable",
|
|
4709
|
+
"Layer__profit-and-loss-summaries__summary--income",
|
|
4710
|
+
sidebarScope === "revenue" ? "active" : ""
|
|
4711
|
+
),
|
|
4712
|
+
onClick: () => setSidebarScope("revenue")
|
|
4546
4713
|
},
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4714
|
+
/* @__PURE__ */ import_react52.default.createElement("span", { className: "Layer__profit-and-loss-summaries__title" }, revenueLabel),
|
|
4715
|
+
isLoading || storedData === void 0 ? /* @__PURE__ */ import_react52.default.createElement("div", { className: "Layer__profit-and-loss-summaries__loader" }, /* @__PURE__ */ import_react52.default.createElement(SkeletonLoader, null)) : /* @__PURE__ */ import_react52.default.createElement(
|
|
4716
|
+
"span",
|
|
4717
|
+
{
|
|
4718
|
+
className: `Layer__profit-and-loss-summaries__amount ${incomeDirectionClass}`
|
|
4719
|
+
},
|
|
4720
|
+
centsToDollars(Math.abs(data?.income?.value ?? NaN))
|
|
4721
|
+
)
|
|
4722
|
+
),
|
|
4723
|
+
/* @__PURE__ */ import_react52.default.createElement(
|
|
4724
|
+
"div",
|
|
4551
4725
|
{
|
|
4552
|
-
className:
|
|
4726
|
+
className: (0, import_classnames23.default)(
|
|
4727
|
+
"Layer__profit-and-loss-summaries__summary Layer__actionable",
|
|
4728
|
+
"Layer__profit-and-loss-summaries__summary--expenses",
|
|
4729
|
+
sidebarScope === "expenses" ? "active" : ""
|
|
4730
|
+
),
|
|
4731
|
+
onClick: () => setSidebarScope("expenses")
|
|
4553
4732
|
},
|
|
4554
|
-
|
|
4555
|
-
|
|
4733
|
+
/* @__PURE__ */ import_react52.default.createElement("span", { className: "Layer__profit-and-loss-summaries__title" }, "Expenses"),
|
|
4734
|
+
isLoading || storedData === void 0 ? /* @__PURE__ */ import_react52.default.createElement("div", { className: "Layer__profit-and-loss-summaries__loader" }, /* @__PURE__ */ import_react52.default.createElement(SkeletonLoader, { className: "Layer__profit-and-loss-summaries__loader" })) : /* @__PURE__ */ import_react52.default.createElement(
|
|
4735
|
+
"span",
|
|
4736
|
+
{
|
|
4737
|
+
className: `Layer__profit-and-loss-summaries__amount ${expensesDirectionClass}`
|
|
4738
|
+
},
|
|
4739
|
+
centsToDollars(Math.abs((data.income.value ?? 0) - data.net_profit))
|
|
4740
|
+
)
|
|
4741
|
+
),
|
|
4556
4742
|
/* @__PURE__ */ import_react52.default.createElement("div", { className: "Layer__profit-and-loss-summaries__summary Layer__profit-and-loss-summaries__summary--net-profit" }, /* @__PURE__ */ import_react52.default.createElement("span", { className: "Layer__profit-and-loss-summaries__title" }, "Net Profit"), isLoading || storedData === void 0 ? /* @__PURE__ */ import_react52.default.createElement("div", { className: "Layer__profit-and-loss-summaries__loader" }, /* @__PURE__ */ import_react52.default.createElement(SkeletonLoader, { className: "Layer__profit-and-loss-summaries__loader" })) : /* @__PURE__ */ import_react52.default.createElement(
|
|
4557
4743
|
"span",
|
|
4558
4744
|
{
|
|
@@ -4774,6 +4960,8 @@ var ProfitAndLossTable = ({ lockExpanded }) => {
|
|
|
4774
4960
|
var import_date_fns13 = require("date-fns");
|
|
4775
4961
|
var PNLContext = (0, import_react55.createContext)({
|
|
4776
4962
|
data: void 0,
|
|
4963
|
+
filteredData: [],
|
|
4964
|
+
filteredTotal: void 0,
|
|
4777
4965
|
isLoading: true,
|
|
4778
4966
|
isValidating: false,
|
|
4779
4967
|
error: void 0,
|
|
@@ -4784,6 +4972,17 @@ var PNLContext = (0, import_react55.createContext)({
|
|
|
4784
4972
|
changeDateRange: () => {
|
|
4785
4973
|
},
|
|
4786
4974
|
refetch: () => {
|
|
4975
|
+
},
|
|
4976
|
+
sidebarScope: void 0,
|
|
4977
|
+
setSidebarScope: () => {
|
|
4978
|
+
},
|
|
4979
|
+
sortBy: () => {
|
|
4980
|
+
},
|
|
4981
|
+
setFilterTypes: () => {
|
|
4982
|
+
},
|
|
4983
|
+
filters: {
|
|
4984
|
+
expenses: void 0,
|
|
4985
|
+
revenue: void 0
|
|
4787
4986
|
}
|
|
4788
4987
|
});
|
|
4789
4988
|
var ProfitAndLoss = ({ children, tagFilter, reportingBasis }) => {
|
|
@@ -4797,20 +4996,466 @@ ProfitAndLoss.Summaries = ProfitAndLossSummaries;
|
|
|
4797
4996
|
ProfitAndLoss.Table = ProfitAndLossTable;
|
|
4798
4997
|
|
|
4799
4998
|
// src/components/ProfitAndLossView/ProfitAndLossView.tsx
|
|
4999
|
+
var import_react57 = __toESM(require("react"));
|
|
5000
|
+
|
|
5001
|
+
// src/components/ProfitAndLossDetailedCharts/ProfitAndLossDetailedCharts.tsx
|
|
4800
5002
|
var import_react56 = __toESM(require("react"));
|
|
5003
|
+
var import_react_select3 = __toESM(require("react-select"));
|
|
5004
|
+
|
|
5005
|
+
// src/icons/SortArrows.tsx
|
|
5006
|
+
var React66 = __toESM(require("react"));
|
|
5007
|
+
var SortArrows = ({ size = 13, ...props }) => /* @__PURE__ */ React66.createElement(
|
|
5008
|
+
"svg",
|
|
5009
|
+
{
|
|
5010
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
5011
|
+
viewBox: "0 0 12 13",
|
|
5012
|
+
fill: "none",
|
|
5013
|
+
...props,
|
|
5014
|
+
width: size,
|
|
5015
|
+
height: size
|
|
5016
|
+
},
|
|
5017
|
+
/* @__PURE__ */ React66.createElement("g", { "clip-path": "url(#clip0_1758_75388)" }, /* @__PURE__ */ React66.createElement(
|
|
5018
|
+
"path",
|
|
5019
|
+
{
|
|
5020
|
+
d: "M1.33325 8.5L3.99992 11.1667L6.66659 8.5",
|
|
5021
|
+
stroke: "currentColor",
|
|
5022
|
+
"stroke-linecap": "round",
|
|
5023
|
+
"stroke-linejoin": "round",
|
|
5024
|
+
className: "desc-arrow"
|
|
5025
|
+
}
|
|
5026
|
+
), /* @__PURE__ */ React66.createElement(
|
|
5027
|
+
"path",
|
|
5028
|
+
{
|
|
5029
|
+
d: "M4 2.5L4 11.1667",
|
|
5030
|
+
stroke: "currentColor",
|
|
5031
|
+
"stroke-linecap": "round",
|
|
5032
|
+
"stroke-linejoin": "round",
|
|
5033
|
+
className: "desc-arrow"
|
|
5034
|
+
}
|
|
5035
|
+
), /* @__PURE__ */ React66.createElement(
|
|
5036
|
+
"path",
|
|
5037
|
+
{
|
|
5038
|
+
d: "M5.99988 5.16602L8.66654 2.49935L11.3332 5.16602",
|
|
5039
|
+
stroke: "currentColor",
|
|
5040
|
+
"stroke-linecap": "round",
|
|
5041
|
+
"stroke-linejoin": "round",
|
|
5042
|
+
className: "asc-arrow"
|
|
5043
|
+
}
|
|
5044
|
+
), /* @__PURE__ */ React66.createElement(
|
|
5045
|
+
"path",
|
|
5046
|
+
{
|
|
5047
|
+
d: "M8.66663 11.166L8.66663 2.49935",
|
|
5048
|
+
stroke: "currentColor",
|
|
5049
|
+
"stroke-linecap": "round",
|
|
5050
|
+
"stroke-linejoin": "round",
|
|
5051
|
+
className: "asc-arrow"
|
|
5052
|
+
}
|
|
5053
|
+
)),
|
|
5054
|
+
/* @__PURE__ */ React66.createElement("defs", null, /* @__PURE__ */ React66.createElement("clipPath", { id: "clip0_1758_75388" }, /* @__PURE__ */ React66.createElement(
|
|
5055
|
+
"rect",
|
|
5056
|
+
{
|
|
5057
|
+
width: "12",
|
|
5058
|
+
height: "12",
|
|
5059
|
+
fill: "white",
|
|
5060
|
+
transform: "translate(0 0.5)"
|
|
5061
|
+
}
|
|
5062
|
+
)))
|
|
5063
|
+
);
|
|
5064
|
+
var SortArrows_default = SortArrows;
|
|
5065
|
+
|
|
5066
|
+
// src/icons/X.tsx
|
|
5067
|
+
var React67 = __toESM(require("react"));
|
|
5068
|
+
var X = ({ size = 18, ...props }) => /* @__PURE__ */ React67.createElement(
|
|
5069
|
+
"svg",
|
|
5070
|
+
{
|
|
5071
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
5072
|
+
viewBox: "0 0 18 18",
|
|
5073
|
+
fill: "none",
|
|
5074
|
+
...props,
|
|
5075
|
+
width: size,
|
|
5076
|
+
height: size
|
|
5077
|
+
},
|
|
5078
|
+
/* @__PURE__ */ React67.createElement(
|
|
5079
|
+
"path",
|
|
5080
|
+
{
|
|
5081
|
+
d: "M13.5 4.5L4.5 13.5",
|
|
5082
|
+
stroke: "currentColor",
|
|
5083
|
+
strokeLinecap: "round",
|
|
5084
|
+
strokeLinejoin: "round"
|
|
5085
|
+
}
|
|
5086
|
+
),
|
|
5087
|
+
/* @__PURE__ */ React67.createElement(
|
|
5088
|
+
"path",
|
|
5089
|
+
{
|
|
5090
|
+
d: "M4.5 4.5L13.5 13.5",
|
|
5091
|
+
stroke: "currentColor",
|
|
5092
|
+
strokeLinecap: "round",
|
|
5093
|
+
strokeLinejoin: "round"
|
|
5094
|
+
}
|
|
5095
|
+
)
|
|
5096
|
+
);
|
|
5097
|
+
var X_default = X;
|
|
5098
|
+
|
|
5099
|
+
// src/components/ProfitAndLossDetailedCharts/ProfitAndLossDetailedCharts.tsx
|
|
5100
|
+
var import_classnames24 = __toESM(require("classnames"));
|
|
5101
|
+
var import_date_fns14 = require("date-fns");
|
|
5102
|
+
var import_recharts2 = require("recharts");
|
|
5103
|
+
var INACTIVE_OPACITY_LEVELS = [0.85, 0.7, 0.66, 0.55, 0.4, 0.33, 0.25, 0.15];
|
|
5104
|
+
var DEFAULT_CHART_COLORS = [
|
|
5105
|
+
{
|
|
5106
|
+
color: "#7417B3",
|
|
5107
|
+
opacity: 1
|
|
5108
|
+
},
|
|
5109
|
+
{
|
|
5110
|
+
color: "#7417B3",
|
|
5111
|
+
opacity: 0.8
|
|
5112
|
+
},
|
|
5113
|
+
{
|
|
5114
|
+
color: "#7417B3",
|
|
5115
|
+
opacity: 0.6
|
|
5116
|
+
},
|
|
5117
|
+
{
|
|
5118
|
+
color: "#7417B3",
|
|
5119
|
+
opacity: 0.4
|
|
5120
|
+
},
|
|
5121
|
+
{
|
|
5122
|
+
color: "#7417B3",
|
|
5123
|
+
opacity: 0.2
|
|
5124
|
+
},
|
|
5125
|
+
{
|
|
5126
|
+
color: "#7417B3",
|
|
5127
|
+
opacity: 0.1
|
|
5128
|
+
},
|
|
5129
|
+
{
|
|
5130
|
+
color: "#006A80",
|
|
5131
|
+
opacity: 1
|
|
5132
|
+
},
|
|
5133
|
+
{
|
|
5134
|
+
color: "#006A80",
|
|
5135
|
+
opacity: 0.8
|
|
5136
|
+
},
|
|
5137
|
+
{
|
|
5138
|
+
color: "#006A80",
|
|
5139
|
+
opacity: 0.6
|
|
5140
|
+
},
|
|
5141
|
+
{
|
|
5142
|
+
color: "#006A80",
|
|
5143
|
+
opacity: 0.4
|
|
5144
|
+
},
|
|
5145
|
+
{
|
|
5146
|
+
color: "#006A80",
|
|
5147
|
+
opacity: 0.2
|
|
5148
|
+
},
|
|
5149
|
+
{
|
|
5150
|
+
color: "#006A80",
|
|
5151
|
+
opacity: 0.1
|
|
5152
|
+
},
|
|
5153
|
+
{
|
|
5154
|
+
color: "#009930",
|
|
5155
|
+
opacity: 1
|
|
5156
|
+
},
|
|
5157
|
+
{
|
|
5158
|
+
color: "#009930",
|
|
5159
|
+
opacity: 0.8
|
|
5160
|
+
},
|
|
5161
|
+
{
|
|
5162
|
+
color: "#009930",
|
|
5163
|
+
opacity: 0.6
|
|
5164
|
+
},
|
|
5165
|
+
{
|
|
5166
|
+
color: "#009930",
|
|
5167
|
+
opacity: 0.4
|
|
5168
|
+
},
|
|
5169
|
+
{
|
|
5170
|
+
color: "#009930",
|
|
5171
|
+
opacity: 0.2
|
|
5172
|
+
},
|
|
5173
|
+
{
|
|
5174
|
+
color: "#009930",
|
|
5175
|
+
opacity: 0.1
|
|
5176
|
+
}
|
|
5177
|
+
];
|
|
5178
|
+
var ProfitAndLossDetailedCharts = () => {
|
|
5179
|
+
const {
|
|
5180
|
+
data,
|
|
5181
|
+
filteredData,
|
|
5182
|
+
filteredTotal,
|
|
5183
|
+
sortBy,
|
|
5184
|
+
filters,
|
|
5185
|
+
isLoading,
|
|
5186
|
+
dateRange,
|
|
5187
|
+
sidebarScope,
|
|
5188
|
+
setSidebarScope,
|
|
5189
|
+
setFilterTypes
|
|
5190
|
+
} = (0, import_react56.useContext)(ProfitAndLoss.Context);
|
|
5191
|
+
const [hoveredItem, setHoveredItem] = (0, import_react56.useState)();
|
|
5192
|
+
const chartData = (0, import_react56.useMemo)(() => {
|
|
5193
|
+
if (!filteredData) {
|
|
5194
|
+
return [];
|
|
5195
|
+
}
|
|
5196
|
+
return filteredData.map((x) => {
|
|
5197
|
+
if (x.hidden) {
|
|
5198
|
+
return {
|
|
5199
|
+
name: x.display_name,
|
|
5200
|
+
value: 0
|
|
5201
|
+
};
|
|
5202
|
+
}
|
|
5203
|
+
return {
|
|
5204
|
+
name: x.display_name,
|
|
5205
|
+
value: x.value
|
|
5206
|
+
};
|
|
5207
|
+
});
|
|
5208
|
+
}, [filteredData]);
|
|
5209
|
+
const buildColClass = (column) => {
|
|
5210
|
+
return (0, import_classnames24.default)(
|
|
5211
|
+
"Layer__sortable-col",
|
|
5212
|
+
sidebarScope && filters[sidebarScope]?.sortBy === column ? `sort--${(sidebarScope && filters[sidebarScope]?.sortDirection) ?? "desc"}` : ""
|
|
5213
|
+
);
|
|
5214
|
+
};
|
|
5215
|
+
return /* @__PURE__ */ import_react56.default.createElement(
|
|
5216
|
+
"div",
|
|
5217
|
+
{
|
|
5218
|
+
className: (0, import_classnames24.default)(
|
|
5219
|
+
"Layer__profit-and-loss__side-panel",
|
|
5220
|
+
sidebarScope && "open"
|
|
5221
|
+
)
|
|
5222
|
+
},
|
|
5223
|
+
/* @__PURE__ */ import_react56.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts" }, /* @__PURE__ */ import_react56.default.createElement("header", null, /* @__PURE__ */ import_react56.default.createElement("div", { className: "Layer__profit-and-loss-detailed-charts__head" }, /* @__PURE__ */ import_react56.default.createElement(Text, { size: "lg" /* lg */, weight: "bold" /* bold */, className: "title" }, humanizeTitle(sidebarScope)), /* @__PURE__ */ import_react56.default.createElement(Text, { size: "sm" /* sm */, className: "date" }, (0, import_date_fns14.format)(dateRange.startDate, "LLLL, y"))), /* @__PURE__ */ import_react56.default.createElement(
|
|
5224
|
+
Button,
|
|
5225
|
+
{
|
|
5226
|
+
rightIcon: /* @__PURE__ */ import_react56.default.createElement(X_default, null),
|
|
5227
|
+
iconOnly: true,
|
|
5228
|
+
onClick: () => setSidebarScope(void 0),
|
|
5229
|
+
variant: "secondary" /* secondary */
|
|
5230
|
+
}
|
|
5231
|
+
)), /* @__PURE__ */ import_react56.default.createElement("div", { className: "chart-container" }, /* @__PURE__ */ import_react56.default.createElement(import_recharts2.ResponsiveContainer, null, /* @__PURE__ */ import_react56.default.createElement(import_recharts2.PieChart, null, /* @__PURE__ */ import_react56.default.createElement(
|
|
5232
|
+
import_recharts2.Pie,
|
|
5233
|
+
{
|
|
5234
|
+
data: chartData,
|
|
5235
|
+
dataKey: "value",
|
|
5236
|
+
nameKey: "name",
|
|
5237
|
+
cx: "50%",
|
|
5238
|
+
cy: "50%",
|
|
5239
|
+
innerRadius: 105,
|
|
5240
|
+
outerRadius: 120,
|
|
5241
|
+
paddingAngle: 0.5,
|
|
5242
|
+
fill: "#8884d8"
|
|
5243
|
+
},
|
|
5244
|
+
chartData.map((entry, index) => {
|
|
5245
|
+
const colorConfig = DEFAULT_CHART_COLORS[index % DEFAULT_CHART_COLORS.length];
|
|
5246
|
+
let fill = colorConfig.color;
|
|
5247
|
+
let opacity = colorConfig.opacity;
|
|
5248
|
+
let active = true;
|
|
5249
|
+
if (hoveredItem && entry.name !== hoveredItem) {
|
|
5250
|
+
active = false;
|
|
5251
|
+
fill = void 0;
|
|
5252
|
+
opacity = INACTIVE_OPACITY_LEVELS[index % INACTIVE_OPACITY_LEVELS.length];
|
|
5253
|
+
}
|
|
5254
|
+
return /* @__PURE__ */ import_react56.default.createElement(
|
|
5255
|
+
import_recharts2.Cell,
|
|
5256
|
+
{
|
|
5257
|
+
key: `cell-${index}`,
|
|
5258
|
+
className: `Layer__profit-and-loss-detailed-charts__pie ${hoveredItem && active ? "active" : "inactive"}`,
|
|
5259
|
+
style: { fill },
|
|
5260
|
+
opacity,
|
|
5261
|
+
onMouseEnter: () => setHoveredItem(entry.name),
|
|
5262
|
+
onMouseLeave: () => setHoveredItem(void 0)
|
|
5263
|
+
}
|
|
5264
|
+
);
|
|
5265
|
+
}),
|
|
5266
|
+
/* @__PURE__ */ import_react56.default.createElement(
|
|
5267
|
+
import_recharts2.Label,
|
|
5268
|
+
{
|
|
5269
|
+
position: "center",
|
|
5270
|
+
value: "Total",
|
|
5271
|
+
className: "pie-center-label-title",
|
|
5272
|
+
content: (props) => {
|
|
5273
|
+
const { cx, cy } = props.viewBox ?? {
|
|
5274
|
+
cx: 0,
|
|
5275
|
+
cy: 0
|
|
5276
|
+
};
|
|
5277
|
+
const positioningProps = {
|
|
5278
|
+
x: cx,
|
|
5279
|
+
y: (cy || 0) - 15,
|
|
5280
|
+
textAnchor: "middle",
|
|
5281
|
+
verticalAnchor: "middle"
|
|
5282
|
+
};
|
|
5283
|
+
let text = "Total";
|
|
5284
|
+
if (hoveredItem) {
|
|
5285
|
+
text = hoveredItem;
|
|
5286
|
+
}
|
|
5287
|
+
return /* @__PURE__ */ import_react56.default.createElement(
|
|
5288
|
+
import_recharts2.Text,
|
|
5289
|
+
{
|
|
5290
|
+
...positioningProps,
|
|
5291
|
+
className: "pie-center-label__title"
|
|
5292
|
+
},
|
|
5293
|
+
text
|
|
5294
|
+
);
|
|
5295
|
+
}
|
|
5296
|
+
}
|
|
5297
|
+
),
|
|
5298
|
+
/* @__PURE__ */ import_react56.default.createElement(
|
|
5299
|
+
import_recharts2.Label,
|
|
5300
|
+
{
|
|
5301
|
+
position: "center",
|
|
5302
|
+
value: "Total",
|
|
5303
|
+
className: "pie-center-label-title",
|
|
5304
|
+
content: (props) => {
|
|
5305
|
+
const { cx, cy } = props.viewBox ?? {
|
|
5306
|
+
cx: 0,
|
|
5307
|
+
cy: 0
|
|
5308
|
+
};
|
|
5309
|
+
const positioningProps = {
|
|
5310
|
+
x: cx,
|
|
5311
|
+
y: (cy || 0) + 5,
|
|
5312
|
+
textAnchor: "middle",
|
|
5313
|
+
verticalAnchor: "middle"
|
|
5314
|
+
};
|
|
5315
|
+
let value = filteredTotal;
|
|
5316
|
+
if (hoveredItem) {
|
|
5317
|
+
value = filteredData.find(
|
|
5318
|
+
(x) => x.display_name === hoveredItem
|
|
5319
|
+
)?.value;
|
|
5320
|
+
}
|
|
5321
|
+
return /* @__PURE__ */ import_react56.default.createElement(
|
|
5322
|
+
import_recharts2.Text,
|
|
5323
|
+
{
|
|
5324
|
+
...positioningProps,
|
|
5325
|
+
className: "pie-center-label__value"
|
|
5326
|
+
},
|
|
5327
|
+
`$${centsToDollars(value)}`
|
|
5328
|
+
);
|
|
5329
|
+
}
|
|
5330
|
+
}
|
|
5331
|
+
),
|
|
5332
|
+
/* @__PURE__ */ import_react56.default.createElement(
|
|
5333
|
+
import_recharts2.Label,
|
|
5334
|
+
{
|
|
5335
|
+
position: "center",
|
|
5336
|
+
value: "Total",
|
|
5337
|
+
className: "pie-center-label-title",
|
|
5338
|
+
content: (props) => {
|
|
5339
|
+
const { cx, cy } = props.viewBox ?? {
|
|
5340
|
+
cx: 0,
|
|
5341
|
+
cy: 0
|
|
5342
|
+
};
|
|
5343
|
+
const positioningProps = {
|
|
5344
|
+
x: cx,
|
|
5345
|
+
y: (cy || 0) + 25,
|
|
5346
|
+
height: 20,
|
|
5347
|
+
textAnchor: "middle",
|
|
5348
|
+
verticalAnchor: "middle"
|
|
5349
|
+
};
|
|
5350
|
+
if (hoveredItem) {
|
|
5351
|
+
return /* @__PURE__ */ import_react56.default.createElement(
|
|
5352
|
+
import_recharts2.Text,
|
|
5353
|
+
{
|
|
5354
|
+
...positioningProps,
|
|
5355
|
+
className: "pie-center-label__share"
|
|
5356
|
+
},
|
|
5357
|
+
`${formatPercent(
|
|
5358
|
+
filteredData.find(
|
|
5359
|
+
(x) => x.display_name === hoveredItem
|
|
5360
|
+
)?.share
|
|
5361
|
+
)}%`
|
|
5362
|
+
);
|
|
5363
|
+
}
|
|
5364
|
+
return;
|
|
5365
|
+
}
|
|
5366
|
+
}
|
|
5367
|
+
)
|
|
5368
|
+
)))), /* @__PURE__ */ import_react56.default.createElement("div", { className: "filters" }, /* @__PURE__ */ import_react56.default.createElement(Text, { size: "sm" /* sm */, className: "Layer__label" }, "Filters"), /* @__PURE__ */ import_react56.default.createElement(
|
|
5369
|
+
import_react_select3.default,
|
|
5370
|
+
{
|
|
5371
|
+
className: "type-select",
|
|
5372
|
+
classNamePrefix: "Layer__select",
|
|
5373
|
+
value: sidebarScope && filters[sidebarScope]?.types ? sidebarScope && filters[sidebarScope]?.types?.map((x) => ({
|
|
5374
|
+
value: x,
|
|
5375
|
+
label: x
|
|
5376
|
+
})) : [],
|
|
5377
|
+
isMulti: true,
|
|
5378
|
+
isClearable: false,
|
|
5379
|
+
options: [...new Set(filteredData?.map((x) => x.type))].map((x) => ({
|
|
5380
|
+
label: x,
|
|
5381
|
+
value: x
|
|
5382
|
+
})),
|
|
5383
|
+
onChange: (selected) => {
|
|
5384
|
+
setFilterTypes(
|
|
5385
|
+
sidebarScope ?? "expenses",
|
|
5386
|
+
selected.map((x) => x.value)
|
|
5387
|
+
);
|
|
5388
|
+
}
|
|
5389
|
+
}
|
|
5390
|
+
)), /* @__PURE__ */ import_react56.default.createElement("div", { className: "details-container" }, /* @__PURE__ */ import_react56.default.createElement("div", { className: "table" }, /* @__PURE__ */ import_react56.default.createElement("table", null, /* @__PURE__ */ import_react56.default.createElement("thead", null, /* @__PURE__ */ import_react56.default.createElement("tr", null, /* @__PURE__ */ import_react56.default.createElement(
|
|
5391
|
+
"th",
|
|
5392
|
+
{
|
|
5393
|
+
className: buildColClass("category"),
|
|
5394
|
+
onClick: () => sortBy(sidebarScope ?? "expenses", "category")
|
|
5395
|
+
},
|
|
5396
|
+
"Expense/Sale ",
|
|
5397
|
+
/* @__PURE__ */ import_react56.default.createElement(SortArrows_default, { className: "Layer__sort-arrows" })
|
|
5398
|
+
), /* @__PURE__ */ import_react56.default.createElement(
|
|
5399
|
+
"th",
|
|
5400
|
+
{
|
|
5401
|
+
className: buildColClass("type"),
|
|
5402
|
+
onClick: () => sortBy(sidebarScope ?? "expenses", "type")
|
|
5403
|
+
},
|
|
5404
|
+
"Type ",
|
|
5405
|
+
/* @__PURE__ */ import_react56.default.createElement(SortArrows_default, { className: "Layer__sort-arrows" })
|
|
5406
|
+
), /* @__PURE__ */ import_react56.default.createElement("th", null), /* @__PURE__ */ import_react56.default.createElement(
|
|
5407
|
+
"th",
|
|
5408
|
+
{
|
|
5409
|
+
className: buildColClass("value"),
|
|
5410
|
+
onClick: () => sortBy(sidebarScope ?? "expenses", "value")
|
|
5411
|
+
},
|
|
5412
|
+
"Value ",
|
|
5413
|
+
/* @__PURE__ */ import_react56.default.createElement(SortArrows_default, { className: "Layer__sort-arrows" })
|
|
5414
|
+
))), /* @__PURE__ */ import_react56.default.createElement("tbody", null, filteredData.filter((x) => !x.hidden).map((item, idx) => {
|
|
5415
|
+
const colorConfig = DEFAULT_CHART_COLORS[idx % DEFAULT_CHART_COLORS.length];
|
|
5416
|
+
return /* @__PURE__ */ import_react56.default.createElement(
|
|
5417
|
+
"tr",
|
|
5418
|
+
{
|
|
5419
|
+
key: `pl-side-table-item-${idx}`,
|
|
5420
|
+
className: (0, import_classnames24.default)(
|
|
5421
|
+
"Layer__profit-and-loss-detailed-table__row",
|
|
5422
|
+
hoveredItem && hoveredItem !== item.display_name ? "inactive" : ""
|
|
5423
|
+
),
|
|
5424
|
+
onMouseEnter: () => setHoveredItem(item.display_name),
|
|
5425
|
+
onMouseLeave: () => setHoveredItem(void 0)
|
|
5426
|
+
},
|
|
5427
|
+
/* @__PURE__ */ import_react56.default.createElement("td", { className: "category-col" }, item.display_name),
|
|
5428
|
+
/* @__PURE__ */ import_react56.default.createElement("td", { className: "type-col" }, item.type),
|
|
5429
|
+
/* @__PURE__ */ import_react56.default.createElement("td", { className: "value-col" }, "$", centsToDollars(item.value)),
|
|
5430
|
+
/* @__PURE__ */ import_react56.default.createElement("td", { className: "share-col" }, /* @__PURE__ */ import_react56.default.createElement("span", { className: "share-cell-content" }, formatPercent(item.share), "%", /* @__PURE__ */ import_react56.default.createElement(
|
|
5431
|
+
"div",
|
|
5432
|
+
{
|
|
5433
|
+
className: "share-icon",
|
|
5434
|
+
style: {
|
|
5435
|
+
background: colorConfig.color,
|
|
5436
|
+
opacity: colorConfig.opacity
|
|
5437
|
+
}
|
|
5438
|
+
}
|
|
5439
|
+
)))
|
|
5440
|
+
);
|
|
5441
|
+
}))))))
|
|
5442
|
+
);
|
|
5443
|
+
};
|
|
5444
|
+
|
|
5445
|
+
// src/components/ProfitAndLossView/ProfitAndLossView.tsx
|
|
4801
5446
|
var COMPONENT_NAME3 = "profit-and-loss";
|
|
4802
5447
|
var ProfitAndLossView = (props) => {
|
|
4803
|
-
return /* @__PURE__ */
|
|
5448
|
+
return /* @__PURE__ */ import_react57.default.createElement(Container, { name: COMPONENT_NAME3 }, /* @__PURE__ */ import_react57.default.createElement(ProfitAndLoss, null, /* @__PURE__ */ import_react57.default.createElement("div", { className: `Layer__${COMPONENT_NAME3}__main-panel` }, /* @__PURE__ */ import_react57.default.createElement(Header, { className: `Layer__${COMPONENT_NAME3}__header` }, /* @__PURE__ */ import_react57.default.createElement(Heading, { className: "Layer__bank-transactions__title" }, "Profit & Loss")), /* @__PURE__ */ import_react57.default.createElement(Components, { ...props })), props.showDetailedCharts !== false && /* @__PURE__ */ import_react57.default.createElement(ProfitAndLossDetailedCharts, null)));
|
|
4804
5449
|
};
|
|
4805
5450
|
var Components = ({
|
|
4806
5451
|
hideChart = false,
|
|
4807
5452
|
hideTable = false
|
|
4808
5453
|
}) => {
|
|
4809
|
-
const { error, isLoading, isValidating, refetch } = (0,
|
|
5454
|
+
const { error, isLoading, isValidating, refetch } = (0, import_react57.useContext)(
|
|
4810
5455
|
ProfitAndLoss.Context
|
|
4811
5456
|
);
|
|
4812
5457
|
if (!isLoading && error) {
|
|
4813
|
-
return /* @__PURE__ */
|
|
5458
|
+
return /* @__PURE__ */ import_react57.default.createElement("div", { className: "Layer__table-state-container" }, /* @__PURE__ */ import_react57.default.createElement(
|
|
4814
5459
|
DataState,
|
|
4815
5460
|
{
|
|
4816
5461
|
status: "failed" /* failed */,
|
|
@@ -4821,25 +5466,25 @@ var Components = ({
|
|
|
4821
5466
|
}
|
|
4822
5467
|
));
|
|
4823
5468
|
}
|
|
4824
|
-
return /* @__PURE__ */
|
|
5469
|
+
return /* @__PURE__ */ import_react57.default.createElement(import_react57.default.Fragment, null, !hideChart && /* @__PURE__ */ import_react57.default.createElement("div", { className: `Layer__${COMPONENT_NAME3}__chart_with_summaries` }, /* @__PURE__ */ import_react57.default.createElement(
|
|
4825
5470
|
"div",
|
|
4826
5471
|
{
|
|
4827
5472
|
className: `Layer__${COMPONENT_NAME3}__chart_with_summaries__summary-col`
|
|
4828
5473
|
},
|
|
4829
|
-
/* @__PURE__ */
|
|
4830
|
-
/* @__PURE__ */
|
|
4831
|
-
), /* @__PURE__ */
|
|
5474
|
+
/* @__PURE__ */ import_react57.default.createElement(ProfitAndLoss.DatePicker, null),
|
|
5475
|
+
/* @__PURE__ */ import_react57.default.createElement(ProfitAndLoss.Summaries, { vertical: true })
|
|
5476
|
+
), /* @__PURE__ */ import_react57.default.createElement(
|
|
4832
5477
|
"div",
|
|
4833
5478
|
{
|
|
4834
5479
|
className: `Layer__${COMPONENT_NAME3}__chart_with_summaries__chart-col`
|
|
4835
5480
|
},
|
|
4836
|
-
/* @__PURE__ */
|
|
4837
|
-
)), !hideTable && /* @__PURE__ */
|
|
5481
|
+
/* @__PURE__ */ import_react57.default.createElement(ProfitAndLoss.Chart, null)
|
|
5482
|
+
)), !hideTable && /* @__PURE__ */ import_react57.default.createElement(ProfitAndLoss.Table, null));
|
|
4838
5483
|
};
|
|
4839
5484
|
|
|
4840
5485
|
// src/providers/LayerProvider/LayerProvider.tsx
|
|
4841
|
-
var
|
|
4842
|
-
var
|
|
5486
|
+
var import_react58 = __toESM(require("react"));
|
|
5487
|
+
var import_date_fns15 = require("date-fns");
|
|
4843
5488
|
var import_swr5 = __toESM(require("swr"));
|
|
4844
5489
|
var reducer = (state, action) => {
|
|
4845
5490
|
switch (action.type) {
|
|
@@ -4880,7 +5525,7 @@ var LayerProvider = ({
|
|
|
4880
5525
|
};
|
|
4881
5526
|
const colors = buildColorsPalette(theme);
|
|
4882
5527
|
const { url, scope, apiUrl } = LayerEnvironment[environment];
|
|
4883
|
-
const [state, dispatch] = (0,
|
|
5528
|
+
const [state, dispatch] = (0, import_react58.useReducer)(reducer, {
|
|
4884
5529
|
auth: {
|
|
4885
5530
|
access_token: "",
|
|
4886
5531
|
token_type: "",
|
|
@@ -4894,7 +5539,7 @@ var LayerProvider = ({
|
|
|
4894
5539
|
colors
|
|
4895
5540
|
});
|
|
4896
5541
|
const { data: auth } = appId !== void 0 && appSecret !== void 0 ? (0, import_swr5.default)(
|
|
4897
|
-
businessAccessToken === void 0 && appId !== void 0 && appSecret !== void 0 && (0,
|
|
5542
|
+
businessAccessToken === void 0 && appId !== void 0 && appSecret !== void 0 && (0, import_date_fns15.isBefore)(state.auth.expires_at, /* @__PURE__ */ new Date()) && "authenticate",
|
|
4898
5543
|
Layer.authenticate({
|
|
4899
5544
|
appId,
|
|
4900
5545
|
appSecret,
|
|
@@ -4903,7 +5548,7 @@ var LayerProvider = ({
|
|
|
4903
5548
|
}),
|
|
4904
5549
|
defaultSWRConfig
|
|
4905
5550
|
) : { data: void 0 };
|
|
4906
|
-
(0,
|
|
5551
|
+
(0, import_react58.useEffect)(() => {
|
|
4907
5552
|
if (businessAccessToken) {
|
|
4908
5553
|
dispatch({
|
|
4909
5554
|
type: "LayerContext.setAuth" /* setAuth */,
|
|
@@ -4912,7 +5557,7 @@ var LayerProvider = ({
|
|
|
4912
5557
|
access_token: businessAccessToken,
|
|
4913
5558
|
token_type: "Bearer",
|
|
4914
5559
|
expires_in: 3600,
|
|
4915
|
-
expires_at: (0,
|
|
5560
|
+
expires_at: (0, import_date_fns15.add)(/* @__PURE__ */ new Date(), { seconds: 3600 })
|
|
4916
5561
|
}
|
|
4917
5562
|
}
|
|
4918
5563
|
});
|
|
@@ -4922,7 +5567,7 @@ var LayerProvider = ({
|
|
|
4922
5567
|
payload: {
|
|
4923
5568
|
auth: {
|
|
4924
5569
|
...auth,
|
|
4925
|
-
expires_at: (0,
|
|
5570
|
+
expires_at: (0, import_date_fns15.add)(/* @__PURE__ */ new Date(), { seconds: auth.expires_in })
|
|
4926
5571
|
}
|
|
4927
5572
|
}
|
|
4928
5573
|
});
|
|
@@ -4953,11 +5598,11 @@ var LayerProvider = ({
|
|
|
4953
5598
|
}
|
|
4954
5599
|
return;
|
|
4955
5600
|
};
|
|
4956
|
-
return /* @__PURE__ */
|
|
5601
|
+
return /* @__PURE__ */ import_react58.default.createElement(import_swr5.SWRConfig, { value: defaultSWRConfig }, /* @__PURE__ */ import_react58.default.createElement(LayerContext.Provider, { value: { ...state, setTheme, getColor } }, children));
|
|
4957
5602
|
};
|
|
4958
5603
|
|
|
4959
5604
|
// src/components/ChartOfAccounts/ChartOfAccounts.tsx
|
|
4960
|
-
var
|
|
5605
|
+
var import_react61 = __toESM(require("react"));
|
|
4961
5606
|
|
|
4962
5607
|
// src/hooks/useChartOfAccounts/useChartOfAccounts.tsx
|
|
4963
5608
|
var import_swr6 = __toESM(require("swr"));
|
|
@@ -4977,21 +5622,21 @@ var useChartOfAccounts = () => {
|
|
|
4977
5622
|
};
|
|
4978
5623
|
|
|
4979
5624
|
// src/components/ChartOfAccountsNewForm/ChartOfAccountsNewForm.tsx
|
|
4980
|
-
var
|
|
4981
|
-
var
|
|
5625
|
+
var import_react59 = __toESM(require("react"));
|
|
5626
|
+
var import_react_select4 = __toESM(require("react-select"));
|
|
4982
5627
|
var flattenAccounts = (accounts) => accounts.flatMap((a) => [a, flattenAccounts(a.subAccounts || [])]).flat().filter((id) => id);
|
|
4983
5628
|
var ChartOfAccountsNewForm = () => {
|
|
4984
5629
|
const { data, create: createAccount2 } = useChartOfAccounts();
|
|
4985
|
-
const accountOptions = (0,
|
|
5630
|
+
const accountOptions = (0, import_react59.useMemo)(
|
|
4986
5631
|
() => flattenAccounts(data?.accounts || []).sort(
|
|
4987
5632
|
(a, b) => a?.name && b?.name ? a.name.localeCompare(b.name) : 0
|
|
4988
5633
|
),
|
|
4989
5634
|
[data?.accounts?.length]
|
|
4990
5635
|
);
|
|
4991
|
-
const [name, setName] = (0,
|
|
4992
|
-
const [description, setDescription] = (0,
|
|
4993
|
-
const [normality, setNormality] = (0,
|
|
4994
|
-
const [parentAccount, setParentAccount] = (0,
|
|
5636
|
+
const [name, setName] = (0, import_react59.useState)("");
|
|
5637
|
+
const [description, setDescription] = (0, import_react59.useState)("");
|
|
5638
|
+
const [normality, setNormality] = (0, import_react59.useState)("DEBIT" /* DEBIT */);
|
|
5639
|
+
const [parentAccount, setParentAccount] = (0, import_react59.useState)(
|
|
4995
5640
|
data?.accounts[0]
|
|
4996
5641
|
);
|
|
4997
5642
|
const save = () => {
|
|
@@ -5005,22 +5650,22 @@ var ChartOfAccountsNewForm = () => {
|
|
|
5005
5650
|
description
|
|
5006
5651
|
});
|
|
5007
5652
|
};
|
|
5008
|
-
return /* @__PURE__ */
|
|
5653
|
+
return /* @__PURE__ */ import_react59.default.createElement("div", { className: "Layer__chart-of-accounts-new-form" }, /* @__PURE__ */ import_react59.default.createElement("div", { className: "Layer__chart-of-accounts-new-form__field" }, /* @__PURE__ */ import_react59.default.createElement("span", null, "Name"), /* @__PURE__ */ import_react59.default.createElement(
|
|
5009
5654
|
"input",
|
|
5010
5655
|
{
|
|
5011
5656
|
name: "name",
|
|
5012
5657
|
value: name,
|
|
5013
5658
|
onChange: (event) => setName(event.target.value)
|
|
5014
5659
|
}
|
|
5015
|
-
)), /* @__PURE__ */
|
|
5660
|
+
)), /* @__PURE__ */ import_react59.default.createElement("div", { className: "Layer__chart-of-accounts-new-form__field" }, /* @__PURE__ */ import_react59.default.createElement("span", null, "Description"), /* @__PURE__ */ import_react59.default.createElement(
|
|
5016
5661
|
"input",
|
|
5017
5662
|
{
|
|
5018
5663
|
name: "description",
|
|
5019
5664
|
value: description,
|
|
5020
5665
|
onChange: (event) => setDescription(event.target.value)
|
|
5021
5666
|
}
|
|
5022
|
-
)), /* @__PURE__ */
|
|
5023
|
-
|
|
5667
|
+
)), /* @__PURE__ */ import_react59.default.createElement("div", { className: "Layer__chart-of-accounts-new-form__field" }, /* @__PURE__ */ import_react59.default.createElement("span", null, "Normality"), /* @__PURE__ */ import_react59.default.createElement(
|
|
5668
|
+
import_react_select4.default,
|
|
5024
5669
|
{
|
|
5025
5670
|
isSearchable: false,
|
|
5026
5671
|
onChange: (value) => value && setNormality(value.value),
|
|
@@ -5029,8 +5674,8 @@ var ChartOfAccountsNewForm = () => {
|
|
|
5029
5674
|
{ label: "Debit", value: "DEBIT" /* DEBIT */ }
|
|
5030
5675
|
]
|
|
5031
5676
|
}
|
|
5032
|
-
)), /* @__PURE__ */
|
|
5033
|
-
|
|
5677
|
+
)), /* @__PURE__ */ import_react59.default.createElement("div", { className: "Layer__chart-of-accounts-new-form__field" }, /* @__PURE__ */ import_react59.default.createElement("span", null, "Parent Account"), /* @__PURE__ */ import_react59.default.createElement(
|
|
5678
|
+
import_react_select4.default,
|
|
5034
5679
|
{
|
|
5035
5680
|
isSearchable: true,
|
|
5036
5681
|
value: parentAccount,
|
|
@@ -5039,49 +5684,49 @@ var ChartOfAccountsNewForm = () => {
|
|
|
5039
5684
|
getOptionValue: (a) => a.id,
|
|
5040
5685
|
options: accountOptions
|
|
5041
5686
|
}
|
|
5042
|
-
)), /* @__PURE__ */
|
|
5687
|
+
)), /* @__PURE__ */ import_react59.default.createElement("div", { className: "Layer__chart-of-accounts-new-form__field Layer__chart-of-accounts-new-form__field--actions" }, /* @__PURE__ */ import_react59.default.createElement("button", { onClick: save }, "Save")));
|
|
5043
5688
|
};
|
|
5044
5689
|
|
|
5045
5690
|
// src/components/ChartOfAccountsRow/ChartOfAccountsRow.tsx
|
|
5046
|
-
var
|
|
5691
|
+
var import_react60 = __toESM(require("react"));
|
|
5047
5692
|
var ChartOfAccountsRow = ({ account, depth = 0 }) => {
|
|
5048
|
-
const
|
|
5693
|
+
const classNames24 = [
|
|
5049
5694
|
"Layer__chart-of-accounts-row__table-cell",
|
|
5050
5695
|
depth > 0 && `Layer__chart-of-accounts-row__table-cell--depth-${depth}`
|
|
5051
5696
|
];
|
|
5052
|
-
const className =
|
|
5697
|
+
const className = classNames24.filter((id) => id).join(" ");
|
|
5053
5698
|
const amountClassName = account.balance < 0 ? "Layer__chart-of-accounts-row__table-cell--amount-negative" : "Layer__chart-of-accounts-row__table-cell--amount-positive";
|
|
5054
|
-
return /* @__PURE__ */
|
|
5699
|
+
return /* @__PURE__ */ import_react60.default.createElement(import_react60.default.Fragment, null, /* @__PURE__ */ import_react60.default.createElement(
|
|
5055
5700
|
"div",
|
|
5056
5701
|
{
|
|
5057
5702
|
className: `${className} Layer__chart-of-accounts-row__table-cell--name`
|
|
5058
5703
|
},
|
|
5059
5704
|
account.name
|
|
5060
|
-
), /* @__PURE__ */
|
|
5705
|
+
), /* @__PURE__ */ import_react60.default.createElement(
|
|
5061
5706
|
"div",
|
|
5062
5707
|
{
|
|
5063
5708
|
className: `${className} Layer__chart-of-accounts-row__table-cell--type`
|
|
5064
5709
|
},
|
|
5065
5710
|
"Assets"
|
|
5066
|
-
), /* @__PURE__ */
|
|
5711
|
+
), /* @__PURE__ */ import_react60.default.createElement(
|
|
5067
5712
|
"div",
|
|
5068
5713
|
{
|
|
5069
5714
|
className: `${className} Layer__chart-of-accounts-row__table-cell--subtype`
|
|
5070
5715
|
},
|
|
5071
5716
|
"Cash"
|
|
5072
|
-
), /* @__PURE__ */
|
|
5717
|
+
), /* @__PURE__ */ import_react60.default.createElement(
|
|
5073
5718
|
"div",
|
|
5074
5719
|
{
|
|
5075
5720
|
className: `${className} Layer__chart-of-accounts-row__table-cell--balance ${amountClassName}`
|
|
5076
5721
|
},
|
|
5077
5722
|
centsToDollars(Math.abs(account.balance || 0))
|
|
5078
|
-
), /* @__PURE__ */
|
|
5723
|
+
), /* @__PURE__ */ import_react60.default.createElement(
|
|
5079
5724
|
"div",
|
|
5080
5725
|
{
|
|
5081
5726
|
className: `${className} Layer__chart-of-accounts-row__table-cell--actions`
|
|
5082
5727
|
},
|
|
5083
|
-
/* @__PURE__ */
|
|
5084
|
-
), (account.subAccounts || []).map((subAccount) => /* @__PURE__ */
|
|
5728
|
+
/* @__PURE__ */ import_react60.default.createElement("button", { className: "Layer__chart-of-accounts-row__view-entries-button" }, "View Entries")
|
|
5729
|
+
), (account.subAccounts || []).map((subAccount) => /* @__PURE__ */ import_react60.default.createElement(
|
|
5085
5730
|
ChartOfAccountsRow,
|
|
5086
5731
|
{
|
|
5087
5732
|
key: subAccount.id,
|
|
@@ -5094,15 +5739,15 @@ var ChartOfAccountsRow = ({ account, depth = 0 }) => {
|
|
|
5094
5739
|
// src/components/ChartOfAccounts/ChartOfAccounts.tsx
|
|
5095
5740
|
var ChartOfAccounts = () => {
|
|
5096
5741
|
const { data, isLoading } = useChartOfAccounts();
|
|
5097
|
-
const [showingForm, setShowingForm] = (0,
|
|
5098
|
-
return /* @__PURE__ */
|
|
5742
|
+
const [showingForm, setShowingForm] = (0, import_react61.useState)(false);
|
|
5743
|
+
return /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__component Layer__chart-of-accounts" }, !data || isLoading ? "Loading." : /* @__PURE__ */ import_react61.default.createElement(import_react61.default.Fragment, null, /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__chart-of-accounts__header" }, /* @__PURE__ */ import_react61.default.createElement("h2", { className: "Layer__chart-of-accounts__title" }, "Chart of Accounts"), /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__chart-of-accounts__actions" }, /* @__PURE__ */ import_react61.default.createElement("button", { className: "Layer__chart-of-accounts__download-button" }, /* @__PURE__ */ import_react61.default.createElement(DownloadCloud_default, null), "Download"), /* @__PURE__ */ import_react61.default.createElement(
|
|
5099
5744
|
"button",
|
|
5100
5745
|
{
|
|
5101
5746
|
className: "Layer__chart-of-accounts__edit-accounts-button",
|
|
5102
5747
|
onClick: () => setShowingForm(!showingForm)
|
|
5103
5748
|
},
|
|
5104
5749
|
"Edit Accounts"
|
|
5105
|
-
))), showingForm && /* @__PURE__ */
|
|
5750
|
+
))), showingForm && /* @__PURE__ */ import_react61.default.createElement(ChartOfAccountsNewForm, null), /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__chart-of-accounts__table" }, /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__chart-of-accounts__table-cell Layer__chart-of-accounts__table-cell--header" }, "Name"), /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__chart-of-accounts__table-cell Layer__chart-of-accounts__table-cell--header" }, "Type"), /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__chart-of-accounts__table-cell Layer__chart-of-accounts__table-cell--header" }, "Sub-Type"), /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__chart-of-accounts__table-cell Layer__chart-of-accounts__table-cell--header Layer__chart-of-accounts__table-cell--header-balance" }, "Balance"), /* @__PURE__ */ import_react61.default.createElement("div", { className: "Layer__chart-of-accounts__table-cell Layer__chart-of-accounts__table-cell--header" }), data.accounts.map((account) => /* @__PURE__ */ import_react61.default.createElement(
|
|
5106
5751
|
ChartOfAccountsRow,
|
|
5107
5752
|
{
|
|
5108
5753
|
key: account.id,
|