@powerhousedao/contributor-billing 0.1.9 → 0.1.12
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/editors/contributor-billing/components/InvoiceTable/HeaderStats.d.ts.map +1 -1
- package/dist/editors/contributor-billing/components/InvoiceTable/HeaderStats.js +2 -1
- package/dist/editors/contributor-billing/hooks/useTransformedNodes.d.ts +1 -2
- package/dist/editors/contributor-billing/hooks/useTransformedNodes.d.ts.map +1 -1
- package/dist/editors/invoice/components/currencyForm.d.ts.map +1 -1
- package/dist/editors/invoice/components/currencyForm.js +1 -0
- package/dist/editors/invoice/ingestPDF.d.ts.map +1 -1
- package/dist/editors/invoice/ingestPDF.js +34 -6
- package/dist/editors/invoice/invoiceToGnosis.js +1 -1
- package/dist/editors/invoice/requestFinance.js +1 -1
- package/dist/editors/invoice/uploadPdfChunked.js +1 -1
- package/dist/reducers/general.d.ts +8 -0
- package/dist/reducers/general.d.ts.map +1 -0
- package/dist/reducers/general.js +73 -0
- package/dist/reducers/items.d.ts +8 -0
- package/dist/reducers/items.d.ts.map +1 -0
- package/dist/reducers/items.js +195 -0
- package/dist/reducers/parties.d.ts +8 -0
- package/dist/reducers/parties.d.ts.map +1 -0
- package/dist/reducers/parties.js +266 -0
- package/dist/reducers/transitions.d.ts +8 -0
- package/dist/reducers/transitions.d.ts.map +1 -0
- package/dist/reducers/transitions.js +162 -0
- package/dist/scripts/invoice/pdfToClaudeAI.d.ts +4 -0
- package/dist/scripts/invoice/pdfToClaudeAI.d.ts.map +1 -0
- package/dist/scripts/invoice/pdfToClaudeAI.js +339 -0
- package/dist/style.css +26 -65
- package/dist/subgraphs/invoice/customResolvers.d.ts +18 -6
- package/dist/subgraphs/invoice/customResolvers.d.ts.map +1 -1
- package/dist/subgraphs/invoice/customResolvers.js +30 -9
- package/package.json +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeaderStats.d.ts","sourceRoot":"","sources":["../../../../../editors/contributor-billing/components/InvoiceTable/HeaderStats.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HeaderStats.d.ts","sourceRoot":"","sources":["../../../../../editors/contributor-billing/components/InvoiceTable/HeaderStats.tsx"],"names":[],"mappings":"AAmBA,eAAO,MAAM,WAAW,+CAoHvB,CAAC"}
|
|
@@ -6,6 +6,7 @@ import { getExchangeRate } from "../../util.js";
|
|
|
6
6
|
import { Tooltip, TooltipProvider } from "@powerhousedao/design-system";
|
|
7
7
|
const currencyList = [
|
|
8
8
|
{ ticker: "USDS", crypto: true },
|
|
9
|
+
{ ticker: "USDC", crypto: true },
|
|
9
10
|
{ ticker: "DAI", crypto: true },
|
|
10
11
|
{ ticker: "USD", crypto: false },
|
|
11
12
|
{ ticker: "EUR", crypto: false },
|
|
@@ -30,7 +31,7 @@ export const HeaderStats = () => {
|
|
|
30
31
|
for (const doc of invoices) {
|
|
31
32
|
const invoice = doc;
|
|
32
33
|
const invoiceAmount = invoice.state.global.totalPriceTaxIncl;
|
|
33
|
-
let invoiceCurrency = invoice.state.global.currency ||
|
|
34
|
+
let invoiceCurrency = invoice.state.global.currency || "USD"; // Fallback to USD if currency is empty
|
|
34
35
|
let selectCurrency = selectedCurrency;
|
|
35
36
|
if (invoiceCurrency === selectedCurrency) {
|
|
36
37
|
total += invoiceAmount;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { Node } from "document-drive";
|
|
2
|
-
|
|
3
|
-
export declare function useTransformedNodes(nodes: Node[], driveId: string): (UiFileNode | UiFolderNode)[];
|
|
2
|
+
export declare function useTransformedNodes(nodes: Node[], driveId: string): any[];
|
|
4
3
|
//# sourceMappingURL=useTransformedNodes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransformedNodes.d.ts","sourceRoot":"","sources":["../../../../editors/contributor-billing/hooks/useTransformedNodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useTransformedNodes.d.ts","sourceRoot":"","sources":["../../../../editors/contributor-billing/hooks/useTransformedNodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,gBAAgB,CAAC;AAGrD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,SA8BjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencyForm.d.ts","sourceRoot":"","sources":["../../../../editors/invoice/components/currencyForm.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,UAAU,iBAAiB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACpE,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACtC;AAED,eAAO,MAAM,YAAY;;;
|
|
1
|
+
{"version":3,"file":"currencyForm.d.ts","sourceRoot":"","sources":["../../../../editors/invoice/components/currencyForm.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,UAAU,iBAAiB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACpE,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACtC;AAED,eAAO,MAAM,YAAY;;;GAWxB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,8CAI1B,iBAAiB,4CA4BnB,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Form, CurrencyCodeField } from "@powerhousedao/document-engineering/scalars";
|
|
3
3
|
export const currencyList = [
|
|
4
4
|
{ ticker: "USDS", crypto: true },
|
|
5
|
+
{ ticker: "USDC", crypto: true },
|
|
5
6
|
{ ticker: "DAI", crypto: true },
|
|
6
7
|
{ ticker: "USD", crypto: false },
|
|
7
8
|
{ ticker: "EUR", crypto: false },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingestPDF.d.ts","sourceRoot":"","sources":["../../../editors/invoice/ingestPDF.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAW,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"ingestPDF.d.ts","sourceRoot":"","sources":["../../../editors/invoice/ingestPDF.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAW,MAAM,wCAAwC,CAAC;AAahF,wBAAsB,WAAW,CAAC,EAChC,IAAI,EACJ,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3C,iBAUA;AAED,UAAU,gBAAgB;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1C,kBAAkB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7C;AA0BD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,QAAQ,EACR,kBAAkB,GACnB,EAAE,gBAAgB,2CA2QlB"}
|
|
@@ -4,9 +4,10 @@ import { actions } from "../../document-models/invoice/index.js";
|
|
|
4
4
|
import { toast } from "@powerhousedao/design-system";
|
|
5
5
|
import { uploadPdfChunked } from "./uploadPdfChunked.js";
|
|
6
6
|
import { getCountryCodeFromName } from "./utils/utils.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import { LoaderCircle } from "lucide-react";
|
|
8
|
+
let GRAPHQL_URL = 'http://localhost:4001/graphql/invoice';
|
|
9
|
+
if (!window.document.baseURI.includes('localhost')) {
|
|
10
|
+
GRAPHQL_URL = 'https://switchboard-dev.powerhouse.xyz/graphql/invoice';
|
|
10
11
|
}
|
|
11
12
|
export async function loadPDFFile({ file, dispatch, }) {
|
|
12
13
|
if (!file)
|
|
@@ -17,6 +18,31 @@ export async function loadPDFFile({ file, dispatch, }) {
|
|
|
17
18
|
console.log("Loading PDF file:", file.name);
|
|
18
19
|
return file;
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Extracts the actual error message from Claude API error format
|
|
23
|
+
* Format: "Claude API error: 400 - {...json...}"
|
|
24
|
+
*/
|
|
25
|
+
function extractErrorMessage(errorMsg) {
|
|
26
|
+
if (errorMsg.includes("Claude API error")) {
|
|
27
|
+
try {
|
|
28
|
+
const jsonMatch = errorMsg.match(/Claude API error: \d+ - (.+)/);
|
|
29
|
+
if (jsonMatch) {
|
|
30
|
+
const errorJson = JSON.parse(jsonMatch[1]);
|
|
31
|
+
if (errorJson?.error?.message) {
|
|
32
|
+
return errorJson.error.message;
|
|
33
|
+
}
|
|
34
|
+
else if (errorJson?.message) {
|
|
35
|
+
return errorJson.message;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (parseError) {
|
|
40
|
+
// If parsing fails, use the original error message
|
|
41
|
+
console.error("Failed to parse error message:", parseError);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return errorMsg;
|
|
45
|
+
}
|
|
20
46
|
export default function PDFUploader({ dispatch, changeDropdownOpen, }) {
|
|
21
47
|
const [isLoading, setIsLoading] = useState(false);
|
|
22
48
|
const [error, setError] = useState(null);
|
|
@@ -162,14 +188,16 @@ export default function PDFUploader({ dispatch, changeDropdownOpen, }) {
|
|
|
162
188
|
changeDropdownOpen(false);
|
|
163
189
|
}
|
|
164
190
|
else {
|
|
165
|
-
|
|
191
|
+
const errorMsg = extractErrorMessage(result.error || "Failed to process PDF");
|
|
192
|
+
throw new Error(errorMsg);
|
|
166
193
|
}
|
|
167
194
|
}
|
|
168
195
|
catch (error) {
|
|
169
196
|
console.error("Error processing PDF:", error);
|
|
170
|
-
|
|
197
|
+
const errorMessage = extractErrorMessage(error instanceof Error
|
|
171
198
|
? error.message
|
|
172
199
|
: "An error occurred while processing the PDF");
|
|
200
|
+
setError(errorMessage);
|
|
173
201
|
}
|
|
174
202
|
finally {
|
|
175
203
|
setIsLoading(false);
|
|
@@ -189,5 +217,5 @@ export default function PDFUploader({ dispatch, changeDropdownOpen, }) {
|
|
|
189
217
|
setIsLoading(false);
|
|
190
218
|
}
|
|
191
219
|
};
|
|
192
|
-
return (_jsx("div", { className: "flex flex-col gap-4", children: _jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("label", { htmlFor: "pdf-upload", className: "
|
|
220
|
+
return (_jsx("div", { className: "flex flex-col gap-4", children: _jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("label", { htmlFor: "pdf-upload", className: "flex items-center gap-2 px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer", children: [isLoading && (_jsx(LoaderCircle, { className: "w-4 h-4 text-blue-600 animate-spin" })), isLoading ? "Uploading..." : "Upload PDF", _jsx("input", { id: "pdf-upload", type: "file", accept: "application/pdf", onChange: handleFileChange, className: "hidden", disabled: isLoading })] }), error && _jsx("p", { className: "text-red-500 text-sm mt-2", children: error })] }) }));
|
|
193
221
|
}
|
|
@@ -4,7 +4,7 @@ import { actions } from "../../document-models/invoice/index.js";
|
|
|
4
4
|
import { generateId } from "document-model";
|
|
5
5
|
let GRAPHQL_URL = "http://localhost:4001/graphql/invoice";
|
|
6
6
|
if (!window.document.baseURI.includes("localhost")) {
|
|
7
|
-
GRAPHQL_URL = "https://switchboard.powerhouse.xyz/graphql/invoice";
|
|
7
|
+
GRAPHQL_URL = "https://switchboard-dev.powerhouse.xyz/graphql/invoice";
|
|
8
8
|
}
|
|
9
9
|
const InvoiceToGnosis = ({ docState, dispatch, }) => {
|
|
10
10
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -4,7 +4,7 @@ import { actions } from "../../document-models/invoice/index.js";
|
|
|
4
4
|
import { generateId } from "document-model";
|
|
5
5
|
let GRAPHQL_URL = "http://localhost:4001/graphql/invoice";
|
|
6
6
|
if (!window.document.baseURI.includes("localhost")) {
|
|
7
|
-
GRAPHQL_URL = "https://switchboard.powerhouse.xyz/graphql/invoice";
|
|
7
|
+
GRAPHQL_URL = "https://switchboard-dev.powerhouse.xyz/graphql/invoice";
|
|
8
8
|
}
|
|
9
9
|
const RequestFinance = ({ docState, dispatch, }) => {
|
|
10
10
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
let GRAPHQL_URL = 'http://localhost:4001/graphql/invoice';
|
|
9
9
|
if (!window.document.baseURI.includes('localhost')) {
|
|
10
|
-
GRAPHQL_URL = 'https://switchboard.powerhouse.xyz/graphql/invoice';
|
|
10
|
+
GRAPHQL_URL = 'https://switchboard-dev.powerhouse.xyz/graphql/invoice';
|
|
11
11
|
}
|
|
12
12
|
export async function uploadPdfChunked(pdfData, endpoint = GRAPHQL_URL, chunkSize = 500 * 1024, // 500KB chunks
|
|
13
13
|
onProgress) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a scaffold file meant for customization:
|
|
3
|
+
* - modify it by implementing the reducer functions
|
|
4
|
+
* - delete the file and run the code generator again to have it reset
|
|
5
|
+
*/
|
|
6
|
+
import type { InvoiceGeneralOperations } from "../../gen/general/operations.js";
|
|
7
|
+
export declare const reducer: InvoiceGeneralOperations;
|
|
8
|
+
//# sourceMappingURL=general.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../reducers/general.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAEhF,eAAO,MAAM,OAAO,EAAE,wBAkErB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a scaffold file meant for customization:
|
|
3
|
+
* - modify it by implementing the reducer functions
|
|
4
|
+
* - delete the file and run the code generator again to have it reset
|
|
5
|
+
*/
|
|
6
|
+
export const reducer = {
|
|
7
|
+
editInvoiceOperation(state, action, dispatch) {
|
|
8
|
+
try {
|
|
9
|
+
const newState = { ...state };
|
|
10
|
+
newState.currency = action.input.currency ?? state.currency;
|
|
11
|
+
newState.dateDue = action.input.dateDue ?? state.dateDue;
|
|
12
|
+
newState.dateIssued = action.input.dateIssued ?? state.dateIssued;
|
|
13
|
+
newState.invoiceNo = action.input.invoiceNo ?? state.invoiceNo;
|
|
14
|
+
newState.notes = action.input.notes ?? state.notes;
|
|
15
|
+
state = Object.assign(state, newState);
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.error(e);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
editStatusOperation(state, action, dispatch) {
|
|
22
|
+
try {
|
|
23
|
+
state.status = action.input.status;
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
console.error(e);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
editPaymentDataOperation(state, action, dispatch) {
|
|
30
|
+
try {
|
|
31
|
+
const payment = state.payments.find((payment) => payment.id === action.input.id);
|
|
32
|
+
if (payment) {
|
|
33
|
+
payment.processorRef = action.input.processorRef ?? payment.processorRef;
|
|
34
|
+
payment.paymentDate = action.input.paymentDate ?? payment.paymentDate;
|
|
35
|
+
payment.txnRef = action.input.txnRef ?? payment.txnRef;
|
|
36
|
+
payment.confirmed = action.input.confirmed ?? payment.confirmed;
|
|
37
|
+
payment.issue = action.input.issue ?? payment.issue;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.error(e);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
addPaymentOperation(state, action, dispatch) {
|
|
45
|
+
try {
|
|
46
|
+
const payment = {
|
|
47
|
+
id: action.input.id,
|
|
48
|
+
processorRef: action.input.processorRef ?? "",
|
|
49
|
+
paymentDate: action.input.paymentDate ?? "",
|
|
50
|
+
txnRef: action.input.txnRef ?? "",
|
|
51
|
+
confirmed: action.input.confirmed ?? false,
|
|
52
|
+
issue: action.input.issue ?? "",
|
|
53
|
+
amount: 0,
|
|
54
|
+
};
|
|
55
|
+
state.payments.push(payment);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error(e);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
setExportedDataOperation(state, action, dispatch) {
|
|
62
|
+
try {
|
|
63
|
+
const exportedData = {
|
|
64
|
+
timestamp: action.input.timestamp,
|
|
65
|
+
exportedLineItems: action.input.exportedLineItems,
|
|
66
|
+
};
|
|
67
|
+
state.exported = exportedData;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
console.error(e);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a scaffold file meant for customization:
|
|
3
|
+
* - modify it by implementing the reducer functions
|
|
4
|
+
* - delete the file and run the code generator again to have it reset
|
|
5
|
+
*/
|
|
6
|
+
import type { InvoiceItemsOperations } from "../../gen/items/operations.js";
|
|
7
|
+
export declare const reducer: InvoiceItemsOperations;
|
|
8
|
+
//# sourceMappingURL=items.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../../reducers/items.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAG5E,eAAO,MAAM,OAAO,EAAE,sBA6GrB,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a scaffold file meant for customization:
|
|
3
|
+
* - modify it by implementing the reducer functions
|
|
4
|
+
* - delete the file and run the code generator again to have it reset
|
|
5
|
+
*/
|
|
6
|
+
export const reducer = {
|
|
7
|
+
addLineItemOperation(state, action, dispatch) {
|
|
8
|
+
try {
|
|
9
|
+
const item = {
|
|
10
|
+
...action.input,
|
|
11
|
+
lineItemTag: [],
|
|
12
|
+
};
|
|
13
|
+
if (state.lineItems.find((x) => x.id === item.id))
|
|
14
|
+
throw new Error("Duplicate input.id");
|
|
15
|
+
validatePrices(item);
|
|
16
|
+
state.lineItems.push(item);
|
|
17
|
+
updateTotals(state);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.error(e);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
editLineItemOperation(state, action, dispatch) {
|
|
24
|
+
try {
|
|
25
|
+
const stateItem = state.lineItems.find((x) => x.id === action.input.id);
|
|
26
|
+
if (!stateItem)
|
|
27
|
+
throw new Error("Item matching input.id not found");
|
|
28
|
+
const sanitizedInput = Object.fromEntries(Object.entries(action.input).filter(([, value]) => value !== null));
|
|
29
|
+
// Ensure lineItemTag is always an array if provided
|
|
30
|
+
if ('lineItemTag' in action.input) {
|
|
31
|
+
sanitizedInput.lineItemTag = (action.input.lineItemTag ?? []);
|
|
32
|
+
}
|
|
33
|
+
const nextItem = {
|
|
34
|
+
...stateItem,
|
|
35
|
+
...sanitizedInput,
|
|
36
|
+
};
|
|
37
|
+
validatePrices(nextItem);
|
|
38
|
+
applyInvariants(state, nextItem);
|
|
39
|
+
Object.assign(stateItem, nextItem);
|
|
40
|
+
updateTotals(state);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
console.error(e);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
deleteLineItemOperation(state, action, dispatch) {
|
|
47
|
+
try {
|
|
48
|
+
state.lineItems = state.lineItems.filter((x) => x.id !== action.input.id);
|
|
49
|
+
updateTotals(state);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.error(e);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
setLineItemTagOperation(state, action, dispatch) {
|
|
56
|
+
try {
|
|
57
|
+
const stateItem = state.lineItems.find((x) => x.id === action.input.lineItemId);
|
|
58
|
+
if (!stateItem)
|
|
59
|
+
throw new Error("Item matching input.id not found");
|
|
60
|
+
// if tag already exists with the same dimension, update the value and label
|
|
61
|
+
const existingTag = stateItem.lineItemTag?.find((tag) => tag.dimension === action.input.dimension);
|
|
62
|
+
if (existingTag) {
|
|
63
|
+
existingTag.value = action.input.value;
|
|
64
|
+
existingTag.label = action.input.label || null;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// if tag does not exist, add it
|
|
68
|
+
const newTag = {
|
|
69
|
+
dimension: action.input.dimension,
|
|
70
|
+
value: action.input.value,
|
|
71
|
+
label: action.input.label || null,
|
|
72
|
+
};
|
|
73
|
+
if (!stateItem.lineItemTag) {
|
|
74
|
+
stateItem.lineItemTag = [];
|
|
75
|
+
}
|
|
76
|
+
// Add the new tag
|
|
77
|
+
stateItem.lineItemTag?.push(newTag);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
console.error(e);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
setInvoiceTagOperation(state, action, dispatch) {
|
|
85
|
+
try {
|
|
86
|
+
// if tag already exists with the same dimension, update the value and label
|
|
87
|
+
const existingTag = state.invoiceTags?.find((tag) => tag.dimension === action.input.dimension);
|
|
88
|
+
if (existingTag) {
|
|
89
|
+
existingTag.value = action.input.value;
|
|
90
|
+
existingTag.label = action.input.label || null;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// if tag does not exist, add it
|
|
94
|
+
const newTag = {
|
|
95
|
+
dimension: action.input.dimension,
|
|
96
|
+
value: action.input.value,
|
|
97
|
+
label: action.input.label || null,
|
|
98
|
+
};
|
|
99
|
+
if (!state.invoiceTags) {
|
|
100
|
+
state.invoiceTags = [];
|
|
101
|
+
}
|
|
102
|
+
// Add the new tag
|
|
103
|
+
state.invoiceTags.push(newTag);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
console.error(e);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
function updateTotals(state) {
|
|
112
|
+
state.totalPriceTaxExcl = state.lineItems.reduce((total, lineItem) => {
|
|
113
|
+
return total + lineItem.quantity * lineItem.unitPriceTaxExcl;
|
|
114
|
+
}, 0.0);
|
|
115
|
+
state.totalPriceTaxIncl = state.lineItems.reduce((total, lineItem) => {
|
|
116
|
+
return total + lineItem.quantity * lineItem.unitPriceTaxIncl;
|
|
117
|
+
}, 0.0);
|
|
118
|
+
}
|
|
119
|
+
function validatePrices(item) {
|
|
120
|
+
const EPSILON = 0.00001; // Small value for floating point comparisons
|
|
121
|
+
// Calculate total prices from unit prices and quantity
|
|
122
|
+
const calcPriceIncl = item.quantity * item.unitPriceTaxIncl;
|
|
123
|
+
const calcPriceExcl = item.quantity * item.unitPriceTaxExcl;
|
|
124
|
+
// Convert tax percentage to decimal rate
|
|
125
|
+
const taxRate = item.taxPercent / 100;
|
|
126
|
+
// Helper function to compare floating point numbers
|
|
127
|
+
const isClose = (a, b) => Math.abs(a - b) < EPSILON;
|
|
128
|
+
// Validate unit prices (tax-exclusive should equal tax-inclusive / (1 + taxRate))
|
|
129
|
+
const expectedUnitPriceExcl = item.unitPriceTaxIncl / (1 + taxRate);
|
|
130
|
+
if (!isClose(item.unitPriceTaxExcl, expectedUnitPriceExcl)) {
|
|
131
|
+
throw new Error("Tax inclusive/exclusive unit prices failed comparison.");
|
|
132
|
+
}
|
|
133
|
+
// Validate total prices
|
|
134
|
+
if (!isClose(calcPriceIncl, item.totalPriceTaxIncl)) {
|
|
135
|
+
throw new Error("Calculated unitPriceTaxIncl does not match input total");
|
|
136
|
+
}
|
|
137
|
+
if (!isClose(calcPriceExcl, item.totalPriceTaxExcl)) {
|
|
138
|
+
throw new Error("Calculated unitPriceTaxExcl does not match input total");
|
|
139
|
+
}
|
|
140
|
+
// Validate total prices using the tax rate
|
|
141
|
+
const expectedTotalPriceExcl = calcPriceIncl / (1 + taxRate);
|
|
142
|
+
if (!isClose(calcPriceExcl, expectedTotalPriceExcl)) {
|
|
143
|
+
throw new Error("Tax inclusive/exclusive totals failed comparison.");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const applyInvariants = (state, nextItem) => {
|
|
147
|
+
const EPSILON = 0.00001; // Small value for floating point comparisons
|
|
148
|
+
// Helper function to compare floating point numbers
|
|
149
|
+
const isClose = (a, b) => Math.abs(a - b) < EPSILON;
|
|
150
|
+
// Helper function to check if a value has changed significantly
|
|
151
|
+
const hasChanged = (oldValue, newValue) => !isClose(oldValue, newValue);
|
|
152
|
+
// Find the current state of this line item
|
|
153
|
+
const currentItem = state.lineItems.find(item => item.id === nextItem.id);
|
|
154
|
+
if (!currentItem) {
|
|
155
|
+
// New item, no comparison needed
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const taxRate = nextItem.taxPercent / 100;
|
|
159
|
+
// Check if totalPriceTaxExcl was changed and update unitPriceTaxExcl accordingly
|
|
160
|
+
const expectedTotalPriceTaxExcl = nextItem.quantity * nextItem.unitPriceTaxExcl;
|
|
161
|
+
if (hasChanged(expectedTotalPriceTaxExcl, nextItem.totalPriceTaxExcl)) {
|
|
162
|
+
// Total was changed, update unit price
|
|
163
|
+
nextItem.unitPriceTaxExcl = nextItem.totalPriceTaxExcl / nextItem.quantity;
|
|
164
|
+
// Update tax-inclusive unit price to maintain tax relationship
|
|
165
|
+
nextItem.unitPriceTaxIncl = nextItem.unitPriceTaxExcl * (1 + taxRate);
|
|
166
|
+
// Update tax-inclusive total to maintain consistency
|
|
167
|
+
nextItem.totalPriceTaxIncl = nextItem.quantity * nextItem.unitPriceTaxIncl;
|
|
168
|
+
}
|
|
169
|
+
// Check if totalPriceTaxIncl was changed and update unitPriceTaxIncl accordingly
|
|
170
|
+
const expectedTotalPriceTaxIncl = nextItem.quantity * nextItem.unitPriceTaxIncl;
|
|
171
|
+
if (hasChanged(expectedTotalPriceTaxIncl, nextItem.totalPriceTaxIncl)) {
|
|
172
|
+
// Total was changed, update unit price
|
|
173
|
+
nextItem.unitPriceTaxIncl = nextItem.totalPriceTaxIncl / nextItem.quantity;
|
|
174
|
+
// Update tax-exclusive unit price to maintain tax relationship
|
|
175
|
+
nextItem.unitPriceTaxExcl = nextItem.unitPriceTaxIncl / (1 + taxRate);
|
|
176
|
+
// Update tax-exclusive total to maintain consistency
|
|
177
|
+
nextItem.totalPriceTaxExcl = nextItem.quantity * nextItem.unitPriceTaxExcl;
|
|
178
|
+
}
|
|
179
|
+
// Check if unitPriceTaxExcl was changed and update totals accordingly
|
|
180
|
+
const expectedUnitPriceTaxIncl = nextItem.unitPriceTaxExcl * (1 + taxRate);
|
|
181
|
+
if (hasChanged(expectedUnitPriceTaxIncl, nextItem.unitPriceTaxIncl)) {
|
|
182
|
+
// Unit price was changed, update tax-inclusive unit price and totals
|
|
183
|
+
nextItem.unitPriceTaxIncl = nextItem.unitPriceTaxExcl * (1 + taxRate);
|
|
184
|
+
nextItem.totalPriceTaxExcl = nextItem.quantity * nextItem.unitPriceTaxExcl;
|
|
185
|
+
nextItem.totalPriceTaxIncl = nextItem.quantity * nextItem.unitPriceTaxIncl;
|
|
186
|
+
}
|
|
187
|
+
// Check if unitPriceTaxIncl was changed and update totals accordingly
|
|
188
|
+
const expectedUnitPriceTaxExcl = nextItem.unitPriceTaxIncl / (1 + taxRate);
|
|
189
|
+
if (hasChanged(expectedUnitPriceTaxExcl, nextItem.unitPriceTaxExcl)) {
|
|
190
|
+
// Unit price was changed, update tax-exclusive unit price and totals
|
|
191
|
+
nextItem.unitPriceTaxExcl = nextItem.unitPriceTaxIncl / (1 + taxRate);
|
|
192
|
+
nextItem.totalPriceTaxExcl = nextItem.quantity * nextItem.unitPriceTaxExcl;
|
|
193
|
+
nextItem.totalPriceTaxIncl = nextItem.quantity * nextItem.unitPriceTaxIncl;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a scaffold file meant for customization:
|
|
3
|
+
* - modify it by implementing the reducer functions
|
|
4
|
+
* - delete the file and run the code generator again to have it reset
|
|
5
|
+
*/
|
|
6
|
+
import type { InvoicePartiesOperations } from "../../gen/parties/operations.js";
|
|
7
|
+
export declare const reducer: InvoicePartiesOperations;
|
|
8
|
+
//# sourceMappingURL=parties.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parties.d.ts","sourceRoot":"","sources":["../../reducers/parties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAShF,eAAO,MAAM,OAAO,EAAE,wBAwarB,CAAC"}
|