invoice-system-common 1.0.28 → 1.0.30-beta.3

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/index.d.ts CHANGED
@@ -36,3 +36,5 @@ export * from "./helpers/date.utils";
36
36
  export * from "./helpers/generics";
37
37
  export * from "./helpers/helper.function.utils";
38
38
  export * from "./enums/entity-list.enum";
39
+ export * from "./models/billing-line-item-model";
40
+ export * from "./models/billing.model";
package/dist/index.js CHANGED
@@ -52,3 +52,5 @@ __exportStar(require("./helpers/date.utils"), exports);
52
52
  __exportStar(require("./helpers/generics"), exports);
53
53
  __exportStar(require("./helpers/helper.function.utils"), exports);
54
54
  __exportStar(require("./enums/entity-list.enum"), exports);
55
+ __exportStar(require("./models/billing-line-item-model"), exports);
56
+ __exportStar(require("./models/billing.model"), exports);
@@ -6,7 +6,7 @@ export interface IBillingLineItemEntity extends IAuditColumnEntity {
6
6
  inventoryId: number;
7
7
  description: string;
8
8
  rateId?: number | null;
9
- rateAmount?: number | null;
9
+ rateAmount: number;
10
10
  quantity: number;
11
11
  tenureValue: number;
12
12
  normalizedTenureInDays: number;
@@ -0,0 +1,27 @@
1
+ import { IBillingLineItemCreateDto } from "../interfaces/billing-line-item.dto.interface";
2
+ export declare class BillingLineItemCreateModel implements IBillingLineItemCreateDto {
3
+ billId: number;
4
+ inventoryId: number;
5
+ rateId?: number | null;
6
+ rateAmount: number;
7
+ quantity: number;
8
+ tenureValue: number;
9
+ normalizedTenureInDays: number;
10
+ startDate: string;
11
+ endDate: string;
12
+ totalAmount: number;
13
+ description: string;
14
+ constructor(dto: IBillingLineItemCreateDto);
15
+ /**
16
+ * Calculates and mutates totalAmount
17
+ */
18
+ calculateTotalAmount(): number;
19
+ /**
20
+ * Calculates tenureValue based on billing type
21
+ */
22
+ calculateTenureValue(billingTenureInDays: number, billingTenureType: "DAILY" | "MONTHLY"): number;
23
+ /**
24
+ * Returns a clean DTO for API submission
25
+ */
26
+ toCreateDto(): IBillingLineItemCreateDto;
27
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BillingLineItemCreateModel = void 0;
4
+ const date_utils_1 = require("../helpers/date.utils");
5
+ const helper_function_utils_1 = require("../helpers/helper.function.utils");
6
+ class BillingLineItemCreateModel {
7
+ constructor(dto) {
8
+ var _a, _b, _c;
9
+ this.billId = dto.billId;
10
+ this.inventoryId = dto.inventoryId;
11
+ this.rateId = (_a = dto.rateId) !== null && _a !== void 0 ? _a : null;
12
+ this.rateAmount = (_b = dto.rateAmount) !== null && _b !== void 0 ? _b : 0;
13
+ this.quantity = dto.quantity;
14
+ this.tenureValue = dto.tenureValue;
15
+ this.normalizedTenureInDays = dto.normalizedTenureInDays;
16
+ this.startDate = dto.startDate;
17
+ this.endDate = dto.endDate;
18
+ this.totalAmount = (_c = dto.totalAmount) !== null && _c !== void 0 ? _c : 0;
19
+ this.description = dto.description;
20
+ }
21
+ /**
22
+ * Calculates and mutates totalAmount
23
+ */
24
+ calculateTotalAmount() {
25
+ if (!this.rateAmount || this.quantity <= 0) {
26
+ this.totalAmount = 0;
27
+ return 0;
28
+ }
29
+ const numberOfDays = new date_utils_1.DateUtils().getDaysBetween(this.startDate, this.endDate);
30
+ const ratePerDay = (0, helper_function_utils_1.getDecimalNoUptoNPlaces)(this.rateAmount / this.normalizedTenureInDays);
31
+ this.totalAmount = numberOfDays * ratePerDay * this.quantity;
32
+ return this.totalAmount;
33
+ }
34
+ /**
35
+ * Calculates tenureValue based on billing type
36
+ */
37
+ calculateTenureValue(billingTenureInDays, billingTenureType) {
38
+ if (billingTenureType === "DAILY") {
39
+ this.tenureValue = billingTenureInDays;
40
+ }
41
+ else {
42
+ this.tenureValue = billingTenureInDays / this.normalizedTenureInDays;
43
+ }
44
+ return this.tenureValue;
45
+ }
46
+ /**
47
+ * Returns a clean DTO for API submission
48
+ */
49
+ toCreateDto() {
50
+ return {
51
+ billId: this.billId,
52
+ inventoryId: this.inventoryId,
53
+ rateId: this.rateId,
54
+ rateAmount: this.rateAmount,
55
+ quantity: this.quantity,
56
+ tenureValue: this.tenureValue,
57
+ normalizedTenureInDays: this.normalizedTenureInDays,
58
+ startDate: this.startDate,
59
+ endDate: this.endDate,
60
+ totalAmount: this.totalAmount,
61
+ description: this.description,
62
+ };
63
+ }
64
+ }
65
+ exports.BillingLineItemCreateModel = BillingLineItemCreateModel;
@@ -0,0 +1,24 @@
1
+ import { BillingRateTenureEnum } from "../enums/tenure.enum";
2
+ import { IBillingCreateDtoV2 } from "../interfaces/billing.dto.interface";
3
+ import { BillingLineItemCreateModel } from "./billing-line-item-model";
4
+ export declare class BillingCreateModel implements IBillingCreateDtoV2 {
5
+ startDate: string;
6
+ endDate: string;
7
+ clientId: number;
8
+ organizationId: number;
9
+ referenceClientId: number;
10
+ billingRateTenure: BillingRateTenureEnum;
11
+ invoiceNo: string;
12
+ invoiceUrl: string | null;
13
+ discount: number;
14
+ totalAmount: number;
15
+ lineItems: BillingLineItemCreateModel[];
16
+ constructor(dto: IBillingCreateDtoV2);
17
+ calculateBillingTotalAmount(): void;
18
+ calculateNetAmount(): number;
19
+ toCreateDto(): IBillingCreateDtoV2;
20
+ getBillingStartDate(): string;
21
+ getBillingEndDate(): string;
22
+ static getBillingTotalAmountFromLineItems(lineItems: BillingLineItemCreateModel[]): number;
23
+ getNetBillingAmountAfterDiscount(): number;
24
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BillingCreateModel = void 0;
4
+ const helper_function_utils_1 = require("../helpers/helper.function.utils");
5
+ const billing_line_item_model_1 = require("./billing-line-item-model");
6
+ class BillingCreateModel {
7
+ constructor(dto) {
8
+ var _a, _b;
9
+ this.startDate = dto.startDate;
10
+ this.endDate = dto.endDate;
11
+ this.clientId = dto.clientId;
12
+ this.organizationId = dto.organizationId;
13
+ this.referenceClientId = dto.referenceClientId;
14
+ this.billingRateTenure = dto.billingRateTenure;
15
+ this.invoiceNo = dto.invoiceNo;
16
+ this.invoiceUrl = dto.invoiceUrl;
17
+ this.discount = (_a = dto.discount) !== null && _a !== void 0 ? _a : 0;
18
+ this.totalAmount = (_b = dto.totalAmount) !== null && _b !== void 0 ? _b : 0;
19
+ this.lineItems = dto.lineItems.map((li) => new billing_line_item_model_1.BillingLineItemCreateModel(li));
20
+ }
21
+ calculateBillingTotalAmount() {
22
+ let total = 0;
23
+ for (const item of this.lineItems) {
24
+ total += item.calculateTotalAmount();
25
+ }
26
+ this.totalAmount = (0, helper_function_utils_1.getDecimalNoUptoNPlaces)(total);
27
+ }
28
+ calculateNetAmount() {
29
+ if (!this.discount)
30
+ return this.totalAmount;
31
+ return (0, helper_function_utils_1.getDecimalNoUptoNPlaces)(this.totalAmount - (this.totalAmount * this.discount) / 100);
32
+ }
33
+ toCreateDto() {
34
+ return {
35
+ startDate: this.startDate,
36
+ endDate: this.endDate,
37
+ clientId: this.clientId,
38
+ organizationId: this.organizationId,
39
+ referenceClientId: this.referenceClientId,
40
+ billingRateTenure: this.billingRateTenure,
41
+ invoiceNo: this.invoiceNo,
42
+ invoiceUrl: this.invoiceUrl,
43
+ discount: this.discount,
44
+ totalAmount: this.totalAmount,
45
+ lineItems: this.lineItems.map((li) => li.toCreateDto()),
46
+ };
47
+ }
48
+ getBillingStartDate() {
49
+ return this.startDate;
50
+ }
51
+ getBillingEndDate() {
52
+ return this.endDate;
53
+ }
54
+ static getBillingTotalAmountFromLineItems(lineItems) {
55
+ let totalAmount = 0;
56
+ for (const item of lineItems) {
57
+ totalAmount += item.calculateTotalAmount();
58
+ }
59
+ return (0, helper_function_utils_1.getDecimalNoUptoNPlaces)(totalAmount);
60
+ }
61
+ getNetBillingAmountAfterDiscount() {
62
+ return (0, helper_function_utils_1.getDecimalNoUptoNPlaces)(this.totalAmount - (this.totalAmount * this.discount) / 100);
63
+ }
64
+ }
65
+ exports.BillingCreateModel = BillingCreateModel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "invoice-system-common",
3
- "version": "1.0.28",
3
+ "version": "1.0.30-beta.3",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/Kashyap2210/invoice-system-common#readme",
6
6
  "bugs": {