@appcorp/stellar-solutions-invoice-module 0.1.62 → 0.1.64

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.
@@ -585,7 +585,7 @@ var useInvoiceState = function () {
585
585
  }, []);
586
586
  var handleRecordPayment = (0, react_1.useCallback)(function (id) {
587
587
  (0, util_functions_1.setStorageValue)("paymentInvoiceId", id);
588
- router.push("/invoice");
588
+ router.push("/erp/payment");
589
589
  }, [router]);
590
590
  var handleDelete = (0, react_1.useCallback)(function (id) {
591
591
  deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
@@ -818,19 +818,19 @@ var useInvoiceState = function () {
818
818
  var rowActions = (0, react_1.useMemo)(function () { return [
819
819
  {
820
820
  enabled: true,
821
- handleAction: function (id) { return handleEdit(id); },
821
+ handleAction: handleEdit,
822
822
  label: "Edit",
823
823
  order: 1,
824
824
  },
825
825
  {
826
826
  enabled: true,
827
- handleAction: function (id) { return handleRecordPayment(id); },
827
+ handleAction: handleRecordPayment,
828
828
  label: "Record payment",
829
829
  order: 2,
830
830
  },
831
831
  {
832
832
  enabled: true,
833
- handleAction: function (id) { return handleDelete(id); },
833
+ handleAction: handleDelete,
834
834
  label: "Delete",
835
835
  order: 3,
836
836
  },
@@ -35,7 +35,8 @@ export declare enum PAYMENT_ACTION_TYPES {
35
35
  SET_QUOTE_INVOICES = "SET_QUOTE_INVOICES",
36
36
  SET_PAYMENT_MODE_QUERY = "SET_PAYMENT_MODE_QUERY",
37
37
  SET_QUOTE_INVOICE_QUERY = "SET_QUOTE_INVOICE_QUERY",
38
- SET_SEARCH_QUERY = "SET_SEARCH_QUERY"
38
+ SET_SEARCH_QUERY = "SET_SEARCH_QUERY",
39
+ SET_INVOICE = "SET_INVOICE"
39
40
  }
40
41
  /**
41
42
  * Reset form validation errors
@@ -187,10 +188,16 @@ export type PaymentSetSearchQueryAction = {
187
188
  searchQuery: string;
188
189
  };
189
190
  };
191
+ export type PaymentSetInvoiceAction = {
192
+ type: PAYMENT_ACTION_TYPES.SET_INVOICE;
193
+ payload: {
194
+ invoice: QuoteInvoiceTypeBE | null;
195
+ };
196
+ };
190
197
  /**
191
198
  * All Payment Actions
192
199
  *
193
200
  * A union of all action types for the Payment module, representing all possible actions
194
201
  * that can be dispatched to modify the Payment state.
195
202
  */
196
- export type PaymentActions = PaymentResetErrorsAction | PaymentResetFormAction | PaymentSetCountAction | PaymentSetCurrentPageAction | PaymentSetDisableSaveButtonAction | PaymentSetDrawerAction | PaymentSetErrorsAction | PaymentSetFormAction | PaymentSetInputFieldAction | PaymentSetModalAction | PaymentSetPageLimitAction | PaymentSetPaymentModeQueryAction | PaymentSetPaymentModesAction | PaymentSetPaymentsAction | PaymentSetQuoteInvoiceQueryAction | PaymentSetQuoteInvoicesAction | PaymentSetSearchQueryAction;
203
+ export type PaymentActions = PaymentResetErrorsAction | PaymentResetFormAction | PaymentSetCountAction | PaymentSetCurrentPageAction | PaymentSetDisableSaveButtonAction | PaymentSetDrawerAction | PaymentSetErrorsAction | PaymentSetFormAction | PaymentSetInputFieldAction | PaymentSetModalAction | PaymentSetPageLimitAction | PaymentSetPaymentModeQueryAction | PaymentSetPaymentModesAction | PaymentSetPaymentsAction | PaymentSetQuoteInvoiceQueryAction | PaymentSetQuoteInvoicesAction | PaymentSetSearchQueryAction | PaymentSetInvoiceAction;
@@ -46,4 +46,5 @@ var PAYMENT_ACTION_TYPES;
46
46
  PAYMENT_ACTION_TYPES["SET_PAYMENT_MODE_QUERY"] = "SET_PAYMENT_MODE_QUERY";
47
47
  PAYMENT_ACTION_TYPES["SET_QUOTE_INVOICE_QUERY"] = "SET_QUOTE_INVOICE_QUERY";
48
48
  PAYMENT_ACTION_TYPES["SET_SEARCH_QUERY"] = "SET_SEARCH_QUERY";
49
+ PAYMENT_ACTION_TYPES["SET_INVOICE"] = "SET_INVOICE";
49
50
  })(PAYMENT_ACTION_TYPES || (exports.PAYMENT_ACTION_TYPES = PAYMENT_ACTION_TYPES = {}));
@@ -89,7 +89,7 @@ var reducer_1 = require("./reducer");
89
89
  var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
90
90
  var types_1 = require("./types");
91
91
  var validate_1 = require("./validate");
92
- var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
92
+ var context_1 = require("../invoice/context");
93
93
  // ============================================================================
94
94
  // MAIN HOOK
95
95
  // ============================================================================
@@ -97,8 +97,8 @@ var usePaymentState = function () {
97
97
  // ---------------------------------------------------------------------------
98
98
  // STATE & CORE HOOKS
99
99
  // ---------------------------------------------------------------------------
100
+ var invoices = (0, context_1.useInvoiceStateContext)().invoices;
100
101
  var _a = (0, react_1.useReducer)(reducer_1.paymentReducer, reducer_1.initialPaymentState), state = _a[0], dispatch = _a[1];
101
- var currencies = (0, context_1.usePreferenceStateContext)().currencies;
102
102
  var theme = (0, next_themes_1.useTheme)().theme;
103
103
  var t = (0, next_intl_1.useTranslations)("payment");
104
104
  // const tCommon = useTranslations("common");
@@ -245,26 +245,44 @@ var usePaymentState = function () {
245
245
  listFetchNow();
246
246
  // eslint-disable-next-line
247
247
  }, [debouncedQuery, state.currentPage, state.pageLimit]);
248
+ (0, react_1.useEffect)(function () {
249
+ var invoiceId = (0, util_functions_1.getStorageValue)("paymentInvoiceId");
250
+ if (invoiceId) {
251
+ var invoice = invoices.filter(function (_a) {
252
+ var id = _a.id;
253
+ return id === invoiceId;
254
+ })[0];
255
+ if (invoice) {
256
+ dispatch({
257
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
258
+ payload: { key: "quoteInvoiceId", value: invoiceId },
259
+ });
260
+ dispatch({
261
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
262
+ payload: { key: "currency", value: invoice === null || invoice === void 0 ? void 0 : invoice.currency },
263
+ });
264
+ dispatch({
265
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
266
+ payload: { key: "amount", value: invoice === null || invoice === void 0 ? void 0 : invoice.total },
267
+ });
268
+ dispatch({
269
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
270
+ payload: { key: "balance", value: "0.00" },
271
+ });
272
+ dispatch({
273
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INVOICE,
274
+ payload: { invoice: invoice },
275
+ });
276
+ dispatch({
277
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
278
+ payload: { drawer: types_1.PAYMENT_DRAWER.PAYMENT_FORM_DRAWER },
279
+ });
280
+ }
281
+ }
282
+ }, [invoices]);
248
283
  // ---------------------------------------------------------------------------
249
284
  // DRAWER & MODAL HANDLERS
250
285
  // ---------------------------------------------------------------------------
251
- var handleCreate = (0, react_1.useCallback)(function () {
252
- var _a;
253
- if (currencies.length > 0) {
254
- var defaultCurrency = (_a = currencies.filter(function (_a) {
255
- var isDefault = _a.isDefault;
256
- return isDefault;
257
- })) === null || _a === void 0 ? void 0 : _a[0];
258
- dispatch({
259
- payload: { key: "currency", value: defaultCurrency.code },
260
- type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
261
- });
262
- }
263
- dispatch({
264
- payload: { drawer: types_1.PAYMENT_DRAWER.PAYMENT_FORM_DRAWER },
265
- type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
266
- });
267
- }, [currencies, dispatch]);
268
286
  var closeDrawer = (0, react_1.useCallback)(function () {
269
287
  dispatch({
270
288
  payload: { drawer: null },
@@ -315,6 +333,30 @@ var usePaymentState = function () {
315
333
  // FORM HANDLERS
316
334
  // ---------------------------------------------------------------------------
317
335
  var handleChange = (0, react_1.useCallback)(function (key, value) {
336
+ var _a, _b, _c, _d;
337
+ console.log("_>>>", state.invoice);
338
+ if (key === "amount" && typeof value === "string") {
339
+ if (Number((_a = state === null || state === void 0 ? void 0 : state.invoice) === null || _a === void 0 ? void 0 : _a.total) > Number(value)) {
340
+ dispatch({
341
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
342
+ payload: { key: "paymentType", value: types_1.PAYMENT_TYPE.PARTIAL_AMOUNT },
343
+ });
344
+ }
345
+ if (Number((_b = state === null || state === void 0 ? void 0 : state.invoice) === null || _b === void 0 ? void 0 : _b.total) === Number(value)) {
346
+ dispatch({
347
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
348
+ payload: { key: "paymentType", value: types_1.PAYMENT_TYPE.FULL_AMOUNT },
349
+ });
350
+ }
351
+ console.log(Number(Number((_c = state === null || state === void 0 ? void 0 : state.invoice) === null || _c === void 0 ? void 0 : _c.total) - Number(value)).toFixed(2));
352
+ dispatch({
353
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
354
+ payload: {
355
+ key: "balance",
356
+ value: Number(Number((_d = state === null || state === void 0 ? void 0 : state.invoice) === null || _d === void 0 ? void 0 : _d.total) - Number(value)).toFixed(2),
357
+ },
358
+ });
359
+ }
318
360
  dispatch({
319
361
  payload: { key: key, value: String(value) },
320
362
  type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
@@ -326,7 +368,7 @@ var usePaymentState = function () {
326
368
  dispatch({
327
369
  type: actions_1.PAYMENT_ACTION_TYPES.RESET_ERRORS,
328
370
  });
329
- }, [dispatch]);
371
+ }, [dispatch, state === null || state === void 0 ? void 0 : state.invoice]);
330
372
  // ---------------------------------------------------------------------------
331
373
  // PAGINATION HANDLERS
332
374
  // ---------------------------------------------------------------------------
@@ -367,14 +409,7 @@ var usePaymentState = function () {
367
409
  // ---------------------------------------------------------------------------
368
410
  // TABLE ACTIONS
369
411
  // ---------------------------------------------------------------------------
370
- var headerActions = (0, react_1.useMemo)(function () { return [
371
- {
372
- enabled: false,
373
- handleOnClick: handleCreate,
374
- label: t("actionsButtonAddItem"),
375
- order: 1,
376
- },
377
- ]; }, [handleCreate, t]);
412
+ var headerActions = (0, react_1.useMemo)(function () { return []; }, []);
378
413
  var rowActions = (0, react_1.useMemo)(function () { return [
379
414
  {
380
415
  enabled: true,
@@ -52,7 +52,7 @@ var PaymentForm = function (_a) {
52
52
  react_1.default.createElement("div", { className: "space-y-2" },
53
53
  react_1.default.createElement(input_1.Input, { id: "amount", type: "text", label: t("formLabelAmount"), value: amount || "", onChange: function (e) { return handleChange("amount", e.target.value); }, placeholder: t("formPlaceholderAmount"), info: t("formInfoAmount"), error: getTranslatedError("amount"), required: true })),
54
54
  react_1.default.createElement("div", { className: "space-y-2" },
55
- react_1.default.createElement(input_1.Input, { id: "balance", type: "text", label: t("formLabelBalance"), value: balance || "", onChange: function (e) { return handleChange("balance", e.target.value); }, placeholder: t("formPlaceholderBalance"), info: t("formInfoBalance"), error: getTranslatedError("balance"), required: true })),
55
+ react_1.default.createElement(input_1.Input, { id: "balance", type: "text", label: t("formLabelBalance"), value: balance || "", onChange: function (e) { return handleChange("balance", e.target.value); }, placeholder: t("formPlaceholderBalance"), info: t("formInfoBalance"), error: getTranslatedError("balance"), required: true, readOnly: true })),
56
56
  react_1.default.createElement("div", { className: "space-y-2" },
57
57
  react_1.default.createElement(input_1.Input, { id: "paymentType", type: "text", label: t("formLabelPaymentType"), value: paymentType || "", readOnly: true, placeholder: t("formPlaceholderPaymentType"), info: t("formInfoPaymentType"), error: getTranslatedError("paymentType"), required: true })),
58
58
  react_1.default.createElement("div", { className: "space-y-2" },
@@ -65,6 +65,7 @@ var getFormResetState = function () { return ({
65
65
  paymentType: types_1.PAYMENT_TYPE.FULL_AMOUNT,
66
66
  quoteInvoiceId: "",
67
67
  ref: "",
68
+ invoice: null,
68
69
  }); };
69
70
  /**
70
71
  * Helper function to safely update array state with immutability
@@ -91,6 +92,7 @@ exports.initialPaymentState = {
91
92
  paymentType: types_1.PAYMENT_TYPE.FULL_AMOUNT,
92
93
  quoteInvoiceId: "",
93
94
  ref: "",
95
+ invoice: null,
94
96
  // List data
95
97
  count: 0,
96
98
  paymentModes: [],
@@ -104,7 +106,7 @@ exports.initialPaymentState = {
104
106
  searchQuery: "",
105
107
  // UI state
106
108
  disableSaveButton: true,
107
- drawer: types_1.PAYMENT_DRAWER.PAYMENT_FORM_DRAWER,
109
+ drawer: null,
108
110
  // Errors
109
111
  errors: {},
110
112
  };
@@ -175,6 +177,8 @@ function paymentReducer(state, action) {
175
177
  return __assign(__assign({}, state), { currentPage: action.payload.currentPage });
176
178
  case actions_1.PAYMENT_ACTION_TYPES.SET_PAGE_LIMIT:
177
179
  return __assign(__assign({}, state), { pageLimit: action.payload.pageLimit });
180
+ case actions_1.PAYMENT_ACTION_TYPES.SET_INVOICE:
181
+ return __assign(__assign({}, state), { invoice: action.payload.invoice });
178
182
  // ------------------------------------------------------------------------
179
183
  // DEFAULT CASE
180
184
  // ------------------------------------------------------------------------
@@ -74,6 +74,7 @@ export interface PaymentState extends Omit<PaymentTypeBE, "createdAt" | "updated
74
74
  quoteInvoiceQuery: string;
75
75
  quoteInvoices: QuoteInvoiceTypeBE[];
76
76
  searchQuery: string;
77
+ invoice: QuoteInvoiceTypeBE | null;
77
78
  }
78
79
  export interface FetchPaymentsArgs {
79
80
  currentPage: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.62",
3
+ "version": "0.1.64",
4
4
  "scripts": {
5
5
  "automate": "./automate.sh",
6
6
  "build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib && cp yarn.lock lib",
File without changes
@@ -1,13 +0,0 @@
1
- // /**
2
- // * Payment Module Exports
3
- // *
4
- // * Central export point for the Payment module
5
- // */
6
- // export { PaymentPage } from "./payment";
7
- // export { PaymentStateContextProvider, usePaymentStateContext } from "./context";
8
- // export { PaymentForm } from "./form";
9
- // export { Drawer as PaymentDrawer } from "./drawer";
10
- // export * from "./types";
11
- // export * from "./actions";
12
- // export * from "./constants";
13
- // export * from "./validate";