@appcorp/stellar-solutions-invoice-module 0.1.10 → 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.
@@ -1,4 +1,4 @@
1
- import { INVOICE_DRAWER, InvoiceState, InvoiceTypeBE, Product, Service } from './types';
1
+ import { DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, InvoiceTypeBE, Product, Service } from './types';
2
2
  export declare enum INVOICE_ACTION_TYPES {
3
3
  SET_INPUT_FIELD = "SET_INPUT_FIELD",
4
4
  SET_CUSTOMER_DATA = "SET_CUSTOMER_DATA",
@@ -120,7 +120,7 @@ export type InvoiceDeleteItemServiceAction = {
120
120
  export type InvoiceSetDiscountUnitAction = {
121
121
  type: INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT;
122
122
  payload: {
123
- discountUnit: string;
123
+ discountUnit: DISCOUNT_UNIT;
124
124
  };
125
125
  };
126
126
  export type InvoiceSetCustomerDataAction = {
@@ -1,4 +1,5 @@
1
- export declare const calculateTotal: (subtotal: string, tax: string, discountUnit: string, discount: string) => {
1
+ import { DISCOUNT_UNIT } from "./types";
2
+ export declare const calculateTotal: (subtotal: string, tax: string, discountUnit: DISCOUNT_UNIT, discount: string) => {
2
3
  totalTaxValue: string;
3
4
  totalDiscountValue: number;
4
5
  total: string;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateTotal = void 0;
4
+ var types_1 = require("./types");
4
5
  var calculateTotal = function (subtotal, tax, discountUnit, discount) {
5
6
  var subtotalValue = parseFloat(subtotal || '0');
6
7
  var taxValue = ((subtotalValue * parseFloat(tax)) / 100).toFixed(2);
7
8
  var discountType = discountUnit;
8
9
  var discountValue = parseFloat(discount || '0');
9
- var discountedAmount = discountType === 'percentage-value'
10
+ var discountedAmount = discountType === types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE
10
11
  ? (subtotalValue * discountValue) / 100
11
12
  : discountValue;
12
13
  var totalTaxValue = taxValue;
@@ -11,6 +11,7 @@ var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
11
11
  var vista_button_type_1 = require("@appcorp/app-corp-vista/type/vista-button-type");
12
12
  var solid_1 = require("@heroicons/react/24/solid");
13
13
  var vista_table_type_1 = require("@appcorp/app-corp-vista/type/vista-table-type");
14
+ var types_1 = require("./types");
14
15
  exports.pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT);
15
16
  var handleSplitId = function (value) {
16
17
  return value === null || value === void 0 ? void 0 : value.split(util_functions_1.VALUE_DELIMITER.COLON);
@@ -222,14 +223,14 @@ exports.staticPricingSection = (_b = {},
222
223
  id: 'item-1',
223
224
  label: 'Fixed Value',
224
225
  order: 1,
225
- value: 'fixed-value',
226
+ value: types_1.DISCOUNT_UNIT.FIXED_VALUE,
226
227
  },
227
228
  {
228
229
  enabled: true,
229
230
  id: 'item-2',
230
231
  label: 'Percentage Value',
231
232
  order: 2,
232
- value: 'percentage-value',
233
+ value: types_1.DISCOUNT_UNIT.PERCENTAGE_VALUE,
233
234
  },
234
235
  ],
235
236
  },
@@ -99,7 +99,6 @@ var actions_1 = require("./actions");
99
99
  var constants_1 = require("./constants");
100
100
  var reducer_1 = require("./reducer");
101
101
  var types_1 = require("./types");
102
- var validate_1 = require("./validate");
103
102
  var generate_toast_1 = require("@appcorp/app-corp-vista/utils/generate-toast");
104
103
  var calculate_subtotal_1 = require("./calculate-subtotal");
105
104
  var context_1 = require("@appcorp/stellar-solutions-product-module/base-modules/product/context");
@@ -135,18 +134,27 @@ var useInvoiceState = function () {
135
134
  });
136
135
  }
137
136
  };
138
- // const updateParams: Omit<InvoiceTypeBE, 'createdAt' | 'updatedAt' | 'serial' | 'isDeleted'> = useMemo(() => ({
139
- // buyPrice: state.buyPrice,
140
- // currency: state.currency,
141
- // description: state.description,
142
- // id: state.id,
143
- // images: state.images,
144
- // name: state.name,
145
- // productCategoryId: state.productCategoryId,
146
- // quantity: state.quantity,
147
- // ref: state.ref,
148
- // salePrice: state.salePrice,
149
- // }), [state]);
137
+ var updatedParams = (0, react_1.useMemo)(function () { return ({
138
+ category: state.category,
139
+ companyId: state.companyId,
140
+ currency: state.currency,
141
+ customerId: state.customerId,
142
+ date: state.date,
143
+ discount: state.discount,
144
+ discountUnit: state.discountUnit,
145
+ expiryDate: state.expiryDate,
146
+ id: state.id,
147
+ invoiceStatus: state.invoiceStatus,
148
+ note: state.note,
149
+ payments: state.payments,
150
+ products: state.products,
151
+ quoteStatus: state.quoteStatus,
152
+ ref: state.ref,
153
+ services: state.services,
154
+ subTotal: state.subTotal,
155
+ taxValue: state.taxValue,
156
+ total: state.total,
157
+ }); }, [state]);
150
158
  var updateCallback = function (_a) {
151
159
  var data = _a.data, error = _a.error;
152
160
  if (error) {
@@ -228,7 +236,7 @@ var useInvoiceState = function () {
228
236
  unitUrl: constants_1.INVOICE_API_ROUTES.INVOICE,
229
237
  updateCallback: updateCallback,
230
238
  updateDeps: [state],
231
- updateParams: {},
239
+ updateParams: __assign(__assign({}, updatedParams), { mode: 'Create' }),
232
240
  }), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError, listFetchNow = _b.listFetchNow, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
233
241
  (0, react_1.useEffect)(function () {
234
242
  listFetchNow();
@@ -240,8 +248,6 @@ var useInvoiceState = function () {
240
248
  ]);
241
249
  (0, react_1.useEffect)(function () {
242
250
  var _a = (0, calculate_total_1.calculateTotal)(state.subTotal, state.taxValue, state.discountUnit, state.discount), totalTaxValue = _a.totalTaxValue, total = _a.total, totalDiscountValue = _a.totalDiscountValue;
243
- // setTotalTax(totalTaxValue);
244
- // setTotalDiscount(totalDiscountValue);
245
251
  dispatch({
246
252
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
247
253
  payload: {
@@ -342,33 +348,31 @@ var useInvoiceState = function () {
342
348
  // return urls;
343
349
  // }, [state.images]);
344
350
  var handleSubmit = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
345
- var validationResult, validationErrors_1;
346
351
  return __generator(this, function (_a) {
347
- // let urls;
348
- // if (state.images?.length) {
349
- // urls = await handleUploadImage();
350
- // }
351
352
  dispatch({
352
353
  type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
353
354
  payload: { disableSaveButton: true },
354
355
  });
355
356
  try {
356
- validationResult = validate_1.formValidation === null || validate_1.formValidation === void 0 ? void 0 : validate_1.formValidation.safeParse(__assign({}));
357
- if (validationResult === null || validationResult === void 0 ? void 0 : validationResult.error) {
358
- validationErrors_1 = {};
359
- validationResult === null || validationResult === void 0 ? void 0 : validationResult.error.errors.forEach(function (err) {
360
- validationErrors_1[err.path[0]] = err.message;
361
- });
362
- dispatch({
363
- type: actions_1.INVOICE_ACTION_TYPES.SET_ERRORS,
364
- payload: validationErrors_1,
365
- });
366
- }
367
- if (validationResult === null || validationResult === void 0 ? void 0 : validationResult.success) {
368
- updateFetchNow(undefined, {
369
- body: JSON.stringify(__assign({})),
370
- });
371
- }
357
+ // const validationResult =
358
+ // formValidation?.safeParse({
359
+ // ...updatedParams,
360
+ // });
361
+ // if (validationResult?.error) {
362
+ // const validationErrors: Record<string, string> = {};
363
+ // validationResult?.error.errors.forEach((err) => {
364
+ // validationErrors[err.path[0]] = err.message;
365
+ // });
366
+ // dispatch({
367
+ // type: INVOICE_ACTION_TYPES.SET_ERRORS,
368
+ // payload: validationErrors,
369
+ // });
370
+ // }
371
+ // if (validationResult?.success) {
372
+ updateFetchNow(undefined, {
373
+ body: JSON.stringify(__assign({}, updatedParams)),
374
+ });
375
+ // }
372
376
  }
373
377
  catch (_b) {
374
378
  (0, generate_toast_1.generateToast)({
@@ -384,7 +388,7 @@ var useInvoiceState = function () {
384
388
  });
385
389
  return [2 /*return*/];
386
390
  });
387
- }); }, [updateFetchNow]);
391
+ }); }, [updateFetchNow, updatedParams]);
388
392
  var handleChange = (0, react_1.useCallback)(function (key, value) {
389
393
  if (key === 'taxValue') {
390
394
  dispatch({
@@ -27,42 +27,38 @@ var types_1 = require("./types");
27
27
  var constants_1 = require("./constants");
28
28
  var date_fns_1 = require("date-fns");
29
29
  exports.initialInvoiceState = {
30
- count: 0,
31
- disableSaveButton: false,
32
- drawer: null,
33
- modal: null,
34
- payments: [],
35
- mode: 'Create',
36
- invoiceId: '',
30
+ address: '',
37
31
  category: types_1.QUOTE_INVOICE.INVOICE,
38
- company: {
39
- name: '',
40
- country: '',
41
- createdAt: '',
42
- updatedAt: '',
43
- id: '',
44
- phone: '',
45
- email: '',
46
- website: '',
47
- },
48
- // btnDisableInvoice: false,
32
+ city: '',
49
33
  companyId: '',
50
34
  companyQuery: '',
35
+ count: 0,
36
+ country: '',
51
37
  currency: 'PKR',
52
38
  currentPage: 1,
39
+ customerId: '',
53
40
  date: new Date().toISOString(),
41
+ disableSaveButton: false,
54
42
  discount: '',
55
- discountUnit: '',
43
+ discountUnit: types_1.DISCOUNT_UNIT.FIXED_VALUE,
44
+ drawer: null,
45
+ email: '',
56
46
  errors: {},
57
47
  expiryDate: (0, date_fns_1.addDays)(new Date(), 7).toISOString(),
58
- // formLoadingInvoice: false,
48
+ firstName: '',
59
49
  id: '',
60
- invoiceStatus: '',
50
+ invoiceStatus: types_1.INVOICE_STATUS.UNPAID,
61
51
  invoices: [],
52
+ lastName: '',
62
53
  loading: true,
54
+ modal: null,
55
+ mode: 'Create',
63
56
  netTotal: '',
64
57
  note: '',
65
58
  pageLimit: constants_1.pageLimit,
59
+ payments: [],
60
+ phone: '',
61
+ quoteStatus: types_1.QUOTE_STATUS.DRAFT,
66
62
  ref: '',
67
63
  searchQuery: '',
68
64
  subTotal: '',
@@ -70,6 +66,16 @@ exports.initialInvoiceState = {
70
66
  total: '',
71
67
  totalDiscount: '',
72
68
  totalTax: '',
69
+ company: {
70
+ name: '',
71
+ country: '',
72
+ createdAt: '',
73
+ updatedAt: '',
74
+ id: '',
75
+ phone: '',
76
+ email: '',
77
+ website: '',
78
+ },
73
79
  services: [
74
80
  {
75
81
  mode: 'Create',
@@ -89,18 +95,6 @@ exports.initialInvoiceState = {
89
95
  rowTotal: '',
90
96
  },
91
97
  ],
92
- firstName: '',
93
- lastName: '',
94
- country: '',
95
- phone: '',
96
- email: '',
97
- city: '',
98
- // fetchPhoneLoading: false,
99
- address: '',
100
- customerId: '',
101
- // fieldDisabled: true,
102
- // isInvoiceApiSuccess: false,
103
- // pageLimit: pageLimit
104
98
  };
105
99
  function invoiceReducer(state, action) {
106
100
  var _a;
@@ -94,57 +94,56 @@ export interface PaymentTypeBE {
94
94
  updatedAt: string;
95
95
  }
96
96
  export interface InvoiceTypeBE {
97
- category: string;
97
+ category: QUOTE_INVOICE;
98
98
  company: CompanyTypeBE;
99
99
  companyId: string;
100
100
  createdAt: string;
101
101
  currency: string;
102
- currentPage: number;
102
+ customer?: CustomerTypeBE;
103
103
  customerId: string;
104
104
  date: string;
105
105
  discount: string;
106
- discountUnit: string;
106
+ discountUnit: DISCOUNT_UNIT;
107
107
  expiryDate: string;
108
108
  id: string;
109
- invoiceId: string;
110
- invoiceStatus: string;
111
- loading: boolean;
112
- mode: 'Create' | 'Edit';
109
+ invoiceStatus: INVOICE_STATUS;
113
110
  note: string;
114
111
  payments: PaymentTypeBE[] | [];
115
112
  products: Product[];
113
+ quoteStatus: QUOTE_STATUS;
116
114
  ref: string;
117
115
  services: Service[];
118
116
  subTotal: string;
119
117
  taxValue: string;
120
118
  total: string;
121
- count: number;
122
119
  updatedAt: string;
123
120
  }
124
121
  export interface InvoiceState extends Omit<InvoiceTypeBE, 'createdAt' | 'updatedAt'> {
122
+ address: string;
123
+ city: string;
124
+ companyQuery: string;
125
125
  count: number;
126
+ country: string;
126
127
  currentPage: number;
127
128
  disableSaveButton: boolean;
128
129
  drawer: null | INVOICE_DRAWER;
130
+ email: string;
129
131
  errors: {
130
132
  [key: string]: string;
131
133
  };
134
+ firstName: string;
135
+ invoices: InvoiceTypeBE[];
136
+ lastName: string;
137
+ loading: boolean;
132
138
  modal: null | PRODUCT_MODAL;
139
+ mode: 'Create' | 'Edit';
140
+ netTotal: string;
133
141
  pageLimit: number;
134
- companyQuery: string;
135
- invoices: InvoiceTypeBE[];
142
+ phone: string;
136
143
  products: Product[];
137
144
  searchQuery: string;
138
- netTotal: string;
139
- firstName: string;
140
- lastName: string;
141
- country: string;
142
- phone: string;
143
- email: string;
144
- city: string;
145
- address: string;
146
- totalTax: string;
147
145
  totalDiscount: string;
146
+ totalTax: string;
148
147
  }
149
148
  export interface FetchInvoicesArgs {
150
149
  currentPage: number;
@@ -178,3 +177,18 @@ export declare enum CURRENCY {
178
177
  SAR = "SAR",
179
178
  USD = "USD"
180
179
  }
180
+ export declare enum INVOICE_STATUS {
181
+ UNPAID = "UNPAID",
182
+ PAID = "PAID"
183
+ }
184
+ export declare enum QUOTE_STATUS {
185
+ DRAFT = "DRAFT",
186
+ PENDING = "PENDING",
187
+ SENT = "SENT",
188
+ ACCEPTED = "ACCEPTED",
189
+ DECLINED = "DECLINED"
190
+ }
191
+ export declare enum DISCOUNT_UNIT {
192
+ FIXED_VALUE = "FIXED_VALUE",
193
+ PERCENTAGE_VALUE = "PERCENTAGE_VALUE"
194
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CURRENCY = exports.QUOTE_INVOICE = exports.PRODUCT_MODAL = exports.INVOICE_DRAWER = exports.PAYMENT_TYPE = exports.PAYMENT_MODE = void 0;
3
+ exports.DISCOUNT_UNIT = exports.QUOTE_STATUS = exports.INVOICE_STATUS = exports.CURRENCY = exports.QUOTE_INVOICE = exports.PRODUCT_MODAL = exports.INVOICE_DRAWER = exports.PAYMENT_TYPE = exports.PAYMENT_MODE = void 0;
4
4
  var PAYMENT_MODE;
5
5
  (function (PAYMENT_MODE) {
6
6
  })(PAYMENT_MODE || (exports.PAYMENT_MODE = PAYMENT_MODE = {}));
@@ -38,3 +38,21 @@ var CURRENCY;
38
38
  CURRENCY["SAR"] = "SAR";
39
39
  CURRENCY["USD"] = "USD";
40
40
  })(CURRENCY || (exports.CURRENCY = CURRENCY = {}));
41
+ var INVOICE_STATUS;
42
+ (function (INVOICE_STATUS) {
43
+ INVOICE_STATUS["UNPAID"] = "UNPAID";
44
+ INVOICE_STATUS["PAID"] = "PAID";
45
+ })(INVOICE_STATUS || (exports.INVOICE_STATUS = INVOICE_STATUS = {}));
46
+ var QUOTE_STATUS;
47
+ (function (QUOTE_STATUS) {
48
+ QUOTE_STATUS["DRAFT"] = "DRAFT";
49
+ QUOTE_STATUS["PENDING"] = "PENDING";
50
+ QUOTE_STATUS["SENT"] = "SENT";
51
+ QUOTE_STATUS["ACCEPTED"] = "ACCEPTED";
52
+ QUOTE_STATUS["DECLINED"] = "DECLINED";
53
+ })(QUOTE_STATUS || (exports.QUOTE_STATUS = QUOTE_STATUS = {}));
54
+ var DISCOUNT_UNIT;
55
+ (function (DISCOUNT_UNIT) {
56
+ DISCOUNT_UNIT["FIXED_VALUE"] = "FIXED_VALUE";
57
+ DISCOUNT_UNIT["PERCENTAGE_VALUE"] = "PERCENTAGE_VALUE";
58
+ })(DISCOUNT_UNIT || (exports.DISCOUNT_UNIT = DISCOUNT_UNIT = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "scripts": {
5
5
  "build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib",
6
6
  "build:next": "next build",