invoice-system-common 1.0.30-beta.2 → 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.
@@ -1,10 +1,8 @@
1
- import { BillingLineItemStatusEnum } from "../enums/billing-line-item-status.enum";
2
- import { IBillingLineItemEntity } from "../interfaces/billing-line-item.entity.interface";
3
- export declare class BillingLineItemModel implements IBillingLineItemEntity {
4
- id: number;
1
+ import { IBillingLineItemCreateDto } from "../interfaces/billing-line-item.dto.interface";
2
+ export declare class BillingLineItemCreateModel implements IBillingLineItemCreateDto {
5
3
  billId: number;
6
4
  inventoryId: number;
7
- rateId?: number;
5
+ rateId?: number | null;
8
6
  rateAmount: number;
9
7
  quantity: number;
10
8
  tenureValue: number;
@@ -13,11 +11,17 @@ export declare class BillingLineItemModel implements IBillingLineItemEntity {
13
11
  endDate: string;
14
12
  totalAmount: number;
15
13
  description: string;
16
- status: BillingLineItemStatusEnum;
17
- createdOn: Date;
18
- updatedOn: Date;
19
- createdBy: number;
20
- updatedBy: number;
21
- constructor(data: IBillingLineItemEntity);
22
- getLineItemTotalAmount(): number;
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;
23
27
  }
@@ -1,37 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BillingLineItemModel = void 0;
3
+ exports.BillingLineItemCreateModel = void 0;
4
4
  const date_utils_1 = require("../helpers/date.utils");
5
5
  const helper_function_utils_1 = require("../helpers/helper.function.utils");
6
- class BillingLineItemModel {
7
- constructor(data) {
8
- var _a;
9
- this.id = data.id;
10
- this.billId = data.billId;
11
- this.inventoryId = data.inventoryId;
12
- this.rateId = (_a = data.rateId) !== null && _a !== void 0 ? _a : undefined;
13
- this.rateAmount = data.rateAmount;
14
- this.quantity = data.quantity;
15
- this.tenureValue = data.tenureValue;
16
- this.normalizedTenureInDays = data.normalizedTenureInDays;
17
- this.startDate = data.startDate;
18
- this.endDate = data.endDate;
19
- this.totalAmount = Number(data.totalAmount);
20
- this.description = data.description;
21
- this.status = data.status;
22
- // audit
23
- this.createdOn = data.createdOn;
24
- this.updatedOn = data.updatedOn;
25
- this.createdBy = data.createdBy;
26
- this.updatedBy = data.updatedBy;
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;
27
20
  }
28
- getLineItemTotalAmount() {
29
- // calculate number of days between startDate and endDate
21
+ /**
22
+ * Calculates and mutates totalAmount
23
+ */
24
+ calculateTotalAmount() {
25
+ if (!this.rateAmount || this.quantity <= 0) {
26
+ this.totalAmount = 0;
27
+ return 0;
28
+ }
30
29
  const numberOfDays = new date_utils_1.DateUtils().getDaysBetween(this.startDate, this.endDate);
31
- // then find the rate per day
32
30
  const ratePerDay = (0, helper_function_utils_1.getDecimalNoUptoNPlaces)(this.rateAmount / this.normalizedTenureInDays);
33
- // then total number of days * rate per day * quantity gives total amount for that item
34
- return numberOfDays * ratePerDay * this.quantity;
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
+ };
35
63
  }
36
64
  }
37
- exports.BillingLineItemModel = BillingLineItemModel;
65
+ exports.BillingLineItemCreateModel = BillingLineItemCreateModel;
@@ -1,32 +1,24 @@
1
- import { BillingStatusEnum } from "../enums/billing.status.enum";
2
- import { EntityList } from "../enums/entity-list.enum";
3
1
  import { BillingRateTenureEnum } from "../enums/tenure.enum";
4
- import { EntityType } from "../helpers/generics";
5
- import { BillingLineItemModel } from "./billing-line-item-model";
6
- export declare class BillingModel implements EntityType<EntityList.BILLING> {
7
- id: number;
8
- organizationId: number;
9
- clientId: number;
10
- referenceClientId: number;
2
+ import { IBillingCreateDtoV2 } from "../interfaces/billing.dto.interface";
3
+ import { BillingLineItemCreateModel } from "./billing-line-item-model";
4
+ export declare class BillingCreateModel implements IBillingCreateDtoV2 {
11
5
  startDate: string;
12
6
  endDate: string;
7
+ clientId: number;
8
+ organizationId: number;
9
+ referenceClientId: number;
13
10
  billingRateTenure: BillingRateTenureEnum;
14
11
  invoiceNo: string;
15
12
  invoiceUrl: string | null;
16
- totalAmount: number;
17
13
  discount: number;
18
- netBillingAmount: number;
19
- accountNumber?: string;
20
- ifscCode?: string;
21
- gstNumber?: string;
22
- status: BillingStatusEnum;
23
- createdOn: Date;
24
- updatedOn: Date;
25
- createdBy: number;
26
- updatedBy: number;
27
- constructor(data: EntityType<EntityList.BILLING>);
14
+ totalAmount: number;
15
+ lineItems: BillingLineItemCreateModel[];
16
+ constructor(dto: IBillingCreateDtoV2);
17
+ calculateBillingTotalAmount(): void;
18
+ calculateNetAmount(): number;
19
+ toCreateDto(): IBillingCreateDtoV2;
28
20
  getBillingStartDate(): string;
29
21
  getBillingEndDate(): string;
30
- static getBillingTotalAmountFromLineItems(lineItems: BillingLineItemModel[]): number;
22
+ static getBillingTotalAmountFromLineItems(lineItems: BillingLineItemCreateModel[]): number;
31
23
  getNetBillingAmountAfterDiscount(): number;
32
24
  }
@@ -1,30 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BillingModel = void 0;
3
+ exports.BillingCreateModel = void 0;
4
4
  const helper_function_utils_1 = require("../helpers/helper.function.utils");
5
- class BillingModel {
6
- constructor(data) {
7
- var _a, _b, _c, _d;
8
- this.id = data.id;
9
- this.organizationId = data.organizationId;
10
- this.clientId = data.clientId;
11
- this.referenceClientId = (_a = data.referenceClientId) !== null && _a !== void 0 ? _a : undefined;
12
- this.startDate = data.startDate;
13
- this.endDate = data.endDate;
14
- this.billingRateTenure = data.billingRateTenure;
15
- this.invoiceNo = data.invoiceNo;
16
- this.invoiceUrl = data.invoiceUrl;
17
- this.totalAmount = Number(data.totalAmount);
18
- this.discount = data.discount;
19
- this.netBillingAmount = Number(data.netBillingAmount);
20
- this.accountNumber = (_b = data.accountNumber) !== null && _b !== void 0 ? _b : undefined;
21
- this.ifscCode = (_c = data.ifscCode) !== null && _c !== void 0 ? _c : undefined;
22
- this.gstNumber = (_d = data.gstNumber) !== null && _d !== void 0 ? _d : undefined;
23
- this.status = data.status;
24
- this.createdOn = data.createdOn;
25
- this.updatedOn = data.updatedOn;
26
- this.createdBy = data.createdBy;
27
- this.updatedBy = data.updatedBy;
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
+ };
28
47
  }
29
48
  getBillingStartDate() {
30
49
  return this.startDate;
@@ -35,7 +54,7 @@ class BillingModel {
35
54
  static getBillingTotalAmountFromLineItems(lineItems) {
36
55
  let totalAmount = 0;
37
56
  for (const item of lineItems) {
38
- totalAmount += item.getLineItemTotalAmount();
57
+ totalAmount += item.calculateTotalAmount();
39
58
  }
40
59
  return (0, helper_function_utils_1.getDecimalNoUptoNPlaces)(totalAmount);
41
60
  }
@@ -43,4 +62,4 @@ class BillingModel {
43
62
  return (0, helper_function_utils_1.getDecimalNoUptoNPlaces)(this.totalAmount - (this.totalAmount * this.discount) / 100);
44
63
  }
45
64
  }
46
- exports.BillingModel = BillingModel;
65
+ exports.BillingCreateModel = BillingCreateModel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "invoice-system-common",
3
- "version": "1.0.30-beta.2",
3
+ "version": "1.0.30-beta.3",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/Kashyap2210/invoice-system-common#readme",
6
6
  "bugs": {