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 {
|
|
2
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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.
|
|
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
|
|
7
|
-
constructor(
|
|
8
|
-
var _a;
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
return
|
|
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.
|
|
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 {
|
|
5
|
-
import {
|
|
6
|
-
export declare class
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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:
|
|
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.
|
|
3
|
+
exports.BillingCreateModel = void 0;
|
|
4
4
|
const helper_function_utils_1 = require("../helpers/helper.function.utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.billingRateTenure =
|
|
15
|
-
this.invoiceNo =
|
|
16
|
-
this.invoiceUrl =
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
|
|
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.
|
|
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.
|
|
65
|
+
exports.BillingCreateModel = BillingCreateModel;
|