@powerhousedao/contributor-billing 0.0.82 → 0.0.84

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.
Files changed (39) hide show
  1. package/dist/document-models/invoice/gen/ph-factories.js +1 -1
  2. package/dist/document-models/invoice/gen/schema/types.d.ts +1 -0
  3. package/dist/document-models/invoice/gen/schema/types.d.ts.map +1 -1
  4. package/dist/document-models/invoice/gen/schema/zod.d.ts.map +1 -1
  5. package/dist/document-models/invoice/gen/schema/zod.js +1 -0
  6. package/dist/document-models/invoice/src/reducers/general.d.ts.map +1 -1
  7. package/dist/document-models/invoice/src/reducers/general.js +1 -0
  8. package/dist/editors/contributor-billing/components/DriveExplorer.d.ts.map +1 -1
  9. package/dist/editors/contributor-billing/components/DriveExplorer.js +1 -26
  10. package/dist/editors/contributor-billing/components/EditorContainer.d.ts.map +1 -1
  11. package/dist/editors/contributor-billing/components/EditorContainer.js +1 -13
  12. package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.d.ts +1 -2
  13. package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.d.ts.map +1 -1
  14. package/dist/editors/contributor-billing/components/InvoiceTable/HeaderControls.js +12 -3
  15. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.d.ts +1 -3
  16. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.d.ts.map +1 -1
  17. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTable.js +112 -56
  18. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableRow.d.ts.map +1 -1
  19. package/dist/editors/contributor-billing/components/InvoiceTable/InvoiceTableRow.js +9 -19
  20. package/dist/editors/contributor-billing/hooks/useTransformedNodes.d.ts +2 -1
  21. package/dist/editors/contributor-billing/hooks/useTransformedNodes.d.ts.map +1 -1
  22. package/dist/editors/invoice/editor.d.ts.map +1 -1
  23. package/dist/editors/invoice/editor.js +1 -3
  24. package/dist/editors/invoice/invoiceToGnosis.d.ts.map +1 -1
  25. package/dist/editors/invoice/invoiceToGnosis.js +18 -6
  26. package/dist/scripts/invoice/gnosisTransactionBuilder.js +1 -1
  27. package/package.json +1 -1
  28. package/dist/reducers/general.d.ts +0 -8
  29. package/dist/reducers/general.d.ts.map +0 -1
  30. package/dist/reducers/general.js +0 -73
  31. package/dist/reducers/items.d.ts +0 -8
  32. package/dist/reducers/items.d.ts.map +0 -1
  33. package/dist/reducers/items.js +0 -195
  34. package/dist/reducers/parties.d.ts +0 -8
  35. package/dist/reducers/parties.d.ts.map +0 -1
  36. package/dist/reducers/parties.js +0 -266
  37. package/dist/reducers/transitions.d.ts +0 -8
  38. package/dist/reducers/transitions.d.ts.map +0 -1
  39. package/dist/reducers/transitions.js +0 -162
@@ -7,35 +7,25 @@ export const InvoiceTableRow = ({ files, row, isSelected, onSelect, setActiveDoc
7
7
  const menuRef = useRef(null);
8
8
  const formatTimestamp = (timestamp) => {
9
9
  const date = new Date(timestamp);
10
- const day = date.getDate().toString().padStart(2, "0");
10
+ const day = date.getDate().toString().padStart(2, '0');
11
11
  // Use ISO short month names (Jan, Feb, etc.)
12
12
  const monthNames = [
13
- "Jan",
14
- "Feb",
15
- "Mar",
16
- "Apr",
17
- "May",
18
- "Jun",
19
- "Jul",
20
- "Aug",
21
- "Sep",
22
- "Oct",
23
- "Nov",
24
- "Dec",
13
+ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
14
+ 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
25
15
  ];
26
16
  const month = monthNames[date.getMonth()];
27
17
  const year = date.getFullYear();
28
- const hours = date.getHours().toString().padStart(2, "0");
29
- const minutes = date.getMinutes().toString().padStart(2, "0");
18
+ const hours = date.getHours().toString().padStart(2, '0');
19
+ const minutes = date.getMinutes().toString().padStart(2, '0');
30
20
  return `${day}-${month}-${year} ${hours}:${minutes}`;
31
21
  };
32
22
  const formatAmount = (amount) => {
33
- const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
23
+ const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
34
24
  if (isNaN(numAmount))
35
- return "0.00";
36
- return numAmount.toLocaleString("en-US", {
25
+ return '0.00';
26
+ return numAmount.toLocaleString('en-US', {
37
27
  minimumFractionDigits: 2,
38
- maximumFractionDigits: 2,
28
+ maximumFractionDigits: 2
39
29
  });
40
30
  };
41
31
  const billingDoc = billingDocStates?.find((doc) => doc.contributor === row.id);
@@ -1,3 +1,4 @@
1
1
  import type { Node } from "document-drive";
2
- export declare function useTransformedNodes(nodes: Node[], driveId: string): any[];
2
+ import type { UiFileNode, UiFolderNode } from "@powerhousedao/design-system";
3
+ export declare function useTransformedNodes(nodes: Node[], driveId: string): (UiFileNode | UiFolderNode)[];
3
4
  //# 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;AAGrD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,SA8BjE"}
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;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE7E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,iCA8BjE"}
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../editors/invoice/editor.tsx"],"names":[],"mappings":"AA6CA,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,GAAG,2CAk7BxC"}
1
+ {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../editors/invoice/editor.tsx"],"names":[],"mappings":"AA6CA,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,GAAG,2CAg7BxC"}
@@ -391,9 +391,7 @@ export default function Editor(props) {
391
391
  }, value: state.dateIssued })] }), _jsxs("div", { className: "mb-2", children: [_jsx("label", { className: "block mb-1 text-sm", children: "Delivery Date:" }), _jsx(DatePicker, { name: "deliveryDate", className: String.raw `w-full p-0`, onChange: (e) => {
392
392
  const newValue = e.target.value.split("T")[0];
393
393
  if (newValue !== state.dateDelivered) {
394
- // Remove dateDelivered from editInvoice, as it's not a valid property
395
- // dispatch(actions.editInvoice({ dateDelivered: newValue }));
396
- // If you need to update delivery date, implement the correct action here
394
+ dispatch(actions.editInvoice({ dateDelivered: newValue }));
397
395
  }
398
396
  }, value: state.dateDelivered || "" })] })] }), _jsx(LegalEntityForm, { legalEntity: state.issuer, onChangeInfo: (input) => dispatch(actions.editIssuer(input)), onChangeBank: (input) => dispatch(actions.editIssuerBank(input)), onChangeWallet: (input) => dispatch(actions.editIssuerWallet(input)), basicInfoDisabled: false, bankDisabled: !fiatMode, walletDisabled: fiatMode, currency: state.currency, status: state.status, walletvalidation: walletValidation, mainCountryValidation: mainCountryValidation, bankCountryValidation: bankCountryValidation, ibanvalidation: ibanValidation, bicvalidation: bicValidation, banknamevalidation: bankNameValidation, streetaddressvalidation: streetAddressValidation, cityvalidation: cityValidation, postalcodevalidation: postalCodeValidation, payeremailvalidation: payerEmailValidation, routingNumbervalidation: routingNumberValidation })] }), _jsxs("div", { className: "border border-gray-200 rounded-lg p-4", children: [_jsx("h3", { className: "text-lg font-semibold mb-4", children: "Payer" }), _jsxs("div", { className: "mb-2 w-64", children: [_jsx("label", { className: "block mb-1 text-sm", children: "Due Date:" }), _jsx(DatePicker, { name: "dateDue", className: String.raw `w-full p-0`, onChange: (e) => dispatch(actions.editInvoice({
399
397
  dateDue: e.target.value.split("T")[0],
@@ -1 +1 @@
1
- {"version":3,"file":"invoiceToGnosis.d.ts","sourceRoot":"","sources":["../../../editors/invoice/invoiceToGnosis.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAUxC,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC;CACf;AAED,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAmQnD,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"invoiceToGnosis.d.ts","sourceRoot":"","sources":["../../../editors/invoice/invoiceToGnosis.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAUnD,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC;CACf;AAED,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA+QnD,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useState } from "react";
2
+ import { useState, useEffect } from "react";
3
3
  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";
@@ -9,12 +9,23 @@ if (!window.document.baseURI.includes("localhost")) {
9
9
  const InvoiceToGnosis = ({ docState, dispatch, }) => {
10
10
  const [isLoading, setIsLoading] = useState(false);
11
11
  const [error, setError] = useState(null);
12
- const [responseData, setResponseData] = useState(null);
13
12
  const [invoiceStatusResponse, setInvoiceStatusResponse] = useState(null);
14
13
  const [safeTxHash, setsafeTxHash] = useState(null);
14
+ const [safeAddress, setSafeAddress] = useState(null);
15
15
  const currency = docState.currency;
16
16
  const chainName = docState.issuer.paymentRouting.wallet.chainName;
17
17
  const invoiceStatus = docState.status;
18
+ useEffect(() => {
19
+ // set safeADdress from processorRef
20
+ if (docState.payments.length < 1)
21
+ return;
22
+ const lastPayment = docState.payments[docState.payments.length - 1].processorRef;
23
+ console.log(lastPayment);
24
+ const retrievedSafeAddress = lastPayment.split(":");
25
+ if (retrievedSafeAddress[0]) {
26
+ setSafeAddress(retrievedSafeAddress[0]);
27
+ }
28
+ }, [docState.payments.length]);
18
29
  const TOKEN_ADDRESSES = {
19
30
  BASE: {
20
31
  USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
@@ -93,16 +104,17 @@ const InvoiceToGnosis = ({ docState, dispatch, }) => {
93
104
  if (data.success) {
94
105
  const dataObj = typeof data.data === "string" ? JSON.parse(data.data) : data.data;
95
106
  setsafeTxHash(dataObj.txHash);
107
+ setSafeAddress(dataObj.safeAddress);
96
108
  if (invoiceStatus === "ACCEPTED") {
97
109
  dispatch(actions.schedulePayment({
98
110
  id: generateId(),
99
- processorRef: dataObj.txHash,
111
+ processorRef: `${dataObj.safeAddress}:${dataObj.txHash}`,
100
112
  }));
101
113
  }
102
114
  else {
103
115
  dispatch(actions.addPayment({
104
116
  id: generateId(),
105
- processorRef: dataObj.txHash,
117
+ processorRef: `${dataObj.safeAddress}:${dataObj.txHash}`,
106
118
  confirmed: false,
107
119
  }));
108
120
  }
@@ -157,10 +169,10 @@ const InvoiceToGnosis = ({ docState, dispatch, }) => {
157
169
  ? "Processing..."
158
170
  : invoiceStatus === "ACCEPTED"
159
171
  ? "Schedule Payment in Gnosis Safe"
160
- : "Reschedule Payment in Gnosis Safe" })), error && (_jsx("div", { className: "text-red-500 bg-red-50 p-3 rounded-md", children: error })), safeTxHash && (_jsxs("div", { className: "bg-gray-50 mt-4 rounded-md space-y-2", children: [_jsx("a", { href: `https://app.safe.global/transactions/queue?safe=${urlChainName}:0x1FB6bEF04230d67aF0e3455B997a28AFcCe1F45e`, target: "_blank", rel: "noopener noreferrer", className: "text-blue-500 hover:text-blue-600 underline block", children: linkText }), _jsxs("p", { className: "font-medium", children: ["Safe Transaction Hash:", _jsx("span", { className: "font-mono text-sm ml-2 break-all", children: safeTxHash })] })] })), !safeTxHash &&
172
+ : "Reschedule Payment in Gnosis Safe" })), error && (_jsx("div", { className: "text-red-500 bg-red-50 p-3 rounded-md", children: error })), safeTxHash && (_jsxs("div", { className: "bg-gray-50 mt-4 rounded-md space-y-2", children: [_jsx("a", { href: `https://app.safe.global/transactions/queue?safe=${urlChainName}:${safeAddress}`, target: "_blank", rel: "noopener noreferrer", className: "text-blue-500 hover:text-blue-600 underline block", children: linkText }), _jsxs("p", { className: "font-medium", children: ["Safe Transaction Hash:", _jsx("span", { className: "font-mono text-sm ml-2 break-all", children: safeTxHash })] })] })), !safeTxHash &&
161
173
  !error &&
162
174
  invoiceStatus === "PAYMENTSCHEDULED" &&
163
- docState.payments.length > 0 && (_jsx(_Fragment, { children: docState.payments[docState.payments.length - 1].issue !== "" ? (_jsx("div", { className: "mt-4", children: _jsxs("p", { className: "text-red-700 font-medium", children: ["Issue: ", docState.payments[docState.payments.length - 1].issue] }) })) : (_jsxs("div", { className: "mt-4", children: [_jsx("div", { className: "invoice-link text-blue-900 hover:text-blue-600", children: _jsx("a", { className: "view-invoice-button", href: `https://app.safe.global/transactions/queue?safe=${urlChainName}:0x1FB6bEF04230d67aF0e3455B997a28AFcCe1F45e`, target: "_blank", rel: "noopener noreferrer", children: linkText }) }), _jsxs("p", { className: "mt-4 font-medium", children: ["Safe Transaction Hash:", _jsx("span", { className: "font-mono text-sm ml-2 break-all", children: docState.payments[docState.payments.length - 1]
175
+ docState.payments.length > 0 && (_jsx(_Fragment, { children: docState.payments[docState.payments.length - 1].issue !== "" ? (_jsx("div", { className: "mt-4", children: _jsxs("p", { className: "text-red-700 font-medium", children: ["Issue: ", docState.payments[docState.payments.length - 1].issue] }) })) : (_jsxs("div", { className: "mt-4", children: [_jsx("div", { className: "invoice-link text-blue-900 hover:text-blue-600", children: _jsx("a", { className: "view-invoice-button", href: `https://app.safe.global/transactions/queue?safe=${urlChainName}:${safeAddress}`, target: "_blank", rel: "noopener noreferrer", children: linkText }) }), _jsxs("p", { className: "mt-4 font-medium", children: ["Safe Transaction Hash:", _jsx("span", { className: "font-mono text-sm ml-2 break-all", children: docState.payments[docState.payments.length - 1]
164
176
  .processorRef })] })] })) })), invoiceStatusResponse && (_jsxs("div", { className: "bg-gray-50 p-4 rounded-md", children: [_jsx("p", { className: "font-medium", children: "Payment Details:" }), _jsx("p", { className: "text-gray-700", children: invoiceStatusResponse })] }))] }));
165
177
  };
166
178
  export default InvoiceToGnosis;
@@ -4,7 +4,7 @@ import { OperationType } from '@safe-global/types-kit';
4
4
  import { ethers, AbiCoder } from 'ethers';
5
5
  import dotenv from 'dotenv';
6
6
  dotenv.config();
7
- const safeAddress = process.env.DEV_STAGING_SAFE_ADDRESS;
7
+ const safeAddress = process.env.PRODUCTION_SAFE_ADDRESS;
8
8
  if (!safeAddress) {
9
9
  throw new Error('Missing SAFE_ADDRESS in .env');
10
10
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@powerhousedao/contributor-billing",
3
3
  "description": "Document models that help contributors of open organisations get paid anonymously for their work on a monthly basis.",
4
- "version": "0.0.82",
4
+ "version": "0.0.84",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
7
7
  "files": [
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,73 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,195 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}