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