@appcorp/stellar-solutions-invoice-module 0.1.9 → 0.1.11

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
  },
@@ -391,7 +392,8 @@ exports.staticProductSection = (_d = {},
391
392
  ],
392
393
  _d);
393
394
  exports.INVOICE_API_ROUTES = {
394
- INVOICES: process.env.NODE_ENV === 'production' ? '/api/quotes-invoices' : 'https://stellar-solutions-pattern.vercel.app/api/quotes-invoices',
395
+ // INVOICES: process.env.NODE_ENV === 'production' ? '/api/quotes-invoices' : 'https://stellar-solutions-pattern.vercel.app/api/quotes-invoices',
396
+ INVOICES: '/api/quotes-invoices',
395
397
  INVOICE: '/api/quote-invoice',
396
398
  INVOICE_BY_ID: '/api/quote-invoice/quote-invoice-by-id',
397
399
  };
@@ -135,18 +135,27 @@ var useInvoiceState = function () {
135
135
  });
136
136
  }
137
137
  };
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]);
138
+ var updatedParams = (0, react_1.useMemo)(function () { return ({
139
+ category: state.category,
140
+ companyId: state.companyId,
141
+ currency: state.currency,
142
+ customerId: state.customerId,
143
+ date: state.date,
144
+ discount: state.discount,
145
+ discountUnit: state.discountUnit,
146
+ expiryDate: state.expiryDate,
147
+ id: state.id,
148
+ invoiceStatus: state.invoiceStatus,
149
+ note: state.note,
150
+ payments: state.payments,
151
+ products: state.products,
152
+ quoteStatus: state.quoteStatus,
153
+ ref: state.ref,
154
+ services: state.services,
155
+ subTotal: state.subTotal,
156
+ taxValue: state.taxValue,
157
+ total: state.total,
158
+ }); }, [state]);
150
159
  var updateCallback = function (_a) {
151
160
  var data = _a.data, error = _a.error;
152
161
  if (error) {
@@ -228,7 +237,7 @@ var useInvoiceState = function () {
228
237
  unitUrl: constants_1.INVOICE_API_ROUTES.INVOICE,
229
238
  updateCallback: updateCallback,
230
239
  updateDeps: [state],
231
- updateParams: {},
240
+ updateParams: __assign(__assign({}, updatedParams), { mode: 'Create' }),
232
241
  }), 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
242
  (0, react_1.useEffect)(function () {
234
243
  listFetchNow();
@@ -240,8 +249,6 @@ var useInvoiceState = function () {
240
249
  ]);
241
250
  (0, react_1.useEffect)(function () {
242
251
  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
252
  dispatch({
246
253
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
247
254
  payload: {
@@ -344,10 +351,6 @@ var useInvoiceState = function () {
344
351
  var handleSubmit = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
345
352
  var validationResult, validationErrors_1;
346
353
  return __generator(this, function (_a) {
347
- // let urls;
348
- // if (state.images?.length) {
349
- // urls = await handleUploadImage();
350
- // }
351
354
  dispatch({
352
355
  type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
353
356
  payload: { disableSaveButton: true },
@@ -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.9",
3
+ "version": "0.1.11",
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",