law-common 11.0.1-beta.4 → 11.0.1-beta.6

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.
@@ -37,4 +37,8 @@ export declare class BillingTransactionEntityModel extends BaseEntityModel<Entit
37
37
  get transactionCurrency(): CurrencyEnum;
38
38
  getFileName(): string;
39
39
  get isBillingSettled(): boolean;
40
+ static getUnsettledCreditNoteSummary(creditNotes: BillingTransactionEntityModel[], adjustedCreditNotes: BillingTransactionEntityModel[]): {
41
+ creditNote: BillingTransactionEntityModel;
42
+ amountPendingToBeSettled: number;
43
+ }[];
40
44
  }
@@ -61,6 +61,17 @@ class BillingTransactionEntityModel extends base_entity_model_1.BaseEntityModel
61
61
  var _a;
62
62
  return ((_a = this.billing) === null || _a === void 0 ? void 0 : _a.status) === billing_status_enum_1.BillingStatusEnum.SETTLED;
63
63
  }
64
+ static getUnsettledCreditNoteSummary(creditNotes, adjustedCreditNotes) {
65
+ return creditNotes.reduce((acc, creditNote) => {
66
+ const creditNoteAmount = (0, utils_1.getDecimalNumberFromString)(creditNote.amount);
67
+ const totalAdjusted = BillingTransactionEntityModel.sumAmounts(adjustedCreditNotes.filter((adj) => adj.referenceNo === creditNote.referenceNo));
68
+ const amountPendingToBeSettled = creditNoteAmount - totalAdjusted;
69
+ if (amountPendingToBeSettled > 0) {
70
+ acc.push({ creditNote, amountPendingToBeSettled });
71
+ }
72
+ return acc;
73
+ }, []);
74
+ }
64
75
  }
65
76
  exports.BillingTransactionEntityModel = BillingTransactionEntityModel;
66
77
  BillingTransactionEntityModel.relationConfigs = [
@@ -243,7 +243,7 @@ class BillingEntityModel extends base_entity_model_1.BaseEntityModel {
243
243
  }
244
244
  getTotalAmountRecieved() {
245
245
  var _a, _b, _c, _d;
246
- const amountRecieved = (0, utils_1.sumNormalised)((_b = (_a = this.billingTransactions) === null || _a === void 0 ? void 0 : _a.filter((transaction) => [billing_transaction_enum_1.BillingTransactionType.TDS, billing_transaction_enum_1.BillingTransactionType.RECEIPT].includes(transaction.type))) !== null && _b !== void 0 ? _b : [], "amount") - (0, utils_1.sumNormalised)((_d = (_c = this.billingTransactions) === null || _c === void 0 ? void 0 : _c.filter((transaction) => transaction.type === billing_transaction_enum_1.BillingTransactionType.REFUND)) !== null && _d !== void 0 ? _d : [], "amount");
246
+ const amountRecieved = (0, utils_1.sumNormalised)((_b = (_a = this.billingTransactions) === null || _a === void 0 ? void 0 : _a.filter((transaction) => [billing_transaction_enum_1.BillingTransactionType.TDS, billing_transaction_enum_1.BillingTransactionType.RECEIPT, billing_transaction_enum_1.BillingTransactionType.ADJUST_AGAINST_CREDIT_NOTE].includes(transaction.type))) !== null && _b !== void 0 ? _b : [], "amount") - (0, utils_1.sumNormalised)((_d = (_c = this.billingTransactions) === null || _c === void 0 ? void 0 : _c.filter((transaction) => transaction.type === billing_transaction_enum_1.BillingTransactionType.REFUND)) !== null && _d !== void 0 ? _d : [], "amount");
247
247
  return amountRecieved;
248
248
  }
249
249
  getTotalRecievableAmount() {
@@ -263,7 +263,11 @@ class BillingEntityModel extends base_entity_model_1.BaseEntityModel {
263
263
  }
264
264
  getApprovedBillingTransactionsTotalAmount() {
265
265
  var _a, _b;
266
- return (0, utils_1.sumNormalised)((_b = (_a = this.billingTransactions) === null || _a === void 0 ? void 0 : _a.filter((entity) => ![billing_transaction_status_enum_1.BillingTransactionStatusEnum.CREDITNOTE_APPROVAL_PENDING, billing_transaction_status_enum_1.BillingTransactionStatusEnum.WRITEOFF_APPROVAL_PENDING].includes(entity.status))) !== null && _b !== void 0 ? _b : [], "amount");
266
+ return (0, utils_1.sumNormalised)((_b = (_a = this.billingTransactions) === null || _a === void 0 ? void 0 : _a.filter((entity) => ![
267
+ billing_transaction_status_enum_1.BillingTransactionStatusEnum.CREDITNOTE_APPROVAL_PENDING,
268
+ billing_transaction_status_enum_1.BillingTransactionStatusEnum.WRITEOFF_APPROVAL_PENDING,
269
+ billing_transaction_status_enum_1.BillingTransactionStatusEnum.ADJUST_AGAINST_CREDIT_NOTE_APPROVAL_PENDING,
270
+ ].includes(entity.status))) !== null && _b !== void 0 ? _b : [], "amount");
267
271
  }
268
272
  getCurrentBillingBillingProfile(billingProfiles) {
269
273
  const billingParticularsOfCurrentBilling = this.billingProfileParticulars;
@@ -4,6 +4,7 @@ import { IClientEntity } from "../interface/client.entity.interface";
4
4
  import { EntityEnum, Nullable } from "../interface/entity.utils.interface";
5
5
  import { RelationConfigs } from "../interface/relation-config.interface";
6
6
  import { BaseEntityModel } from "./base.entity.model";
7
+ import { BillingTransactionEntityModel } from "./billing-transaction.model";
7
8
  import { ClientAffiliateEntityModel } from "./client-affiliate.entity.model";
8
9
  import { ProjectEntityModel } from "./project.entity.model";
9
10
  export declare class ClientEntityModel extends BaseEntityModel<EntityEnum.CLIENT> implements IClientEntity {
@@ -78,9 +79,13 @@ export declare class ClientEntityModel extends BaseEntityModel<EntityEnum.CLIENT
78
79
  get city(): string;
79
80
  get state(): string;
80
81
  getBillingsFromProfileCode(billingProfileCode?: string): import("./billing.entity.model").BillingEntityModel[];
81
- getCreditNoteTransactions(billingProfileCode?: string): import("./billing-transaction.model").BillingTransactionEntityModel[];
82
- getAdjustedCreditNoteTransactions(billingProfileCode?: string): import("./billing-transaction.model").BillingTransactionEntityModel[];
82
+ getCreditNoteTransactions(billingProfileCode?: string): BillingTransactionEntityModel[];
83
+ getAdjustedCreditNoteTransactions(billingProfileCode?: string): BillingTransactionEntityModel[];
83
84
  get totalCreditNoteAmount(): number;
84
85
  get totalCreditNoteAmountAdjusted(): number;
85
86
  get totalCreditNoteAmountPendingForAdjustment(): number;
87
+ getUnsettledCreditNoteSummary(billingProfileCode?: string): {
88
+ creditNote: BillingTransactionEntityModel;
89
+ amountPendingToBeSettled: number;
90
+ }[];
86
91
  }
@@ -7,6 +7,7 @@ const document_validate_util_1 = require("../../utils/document-validate.util");
7
7
  const relation_type_enum_1 = require("../enums/relation-type.enum");
8
8
  const entity_utils_interface_1 = require("../interface/entity.utils.interface");
9
9
  const base_entity_model_1 = require("./base.entity.model");
10
+ const billing_transaction_model_1 = require("./billing-transaction.model");
10
11
  class ClientEntityModel extends base_entity_model_1.BaseEntityModel {
11
12
  constructor() {
12
13
  super(...arguments);
@@ -106,7 +107,9 @@ class ClientEntityModel extends base_entity_model_1.BaseEntityModel {
106
107
  return (_b = (_a = this.parsedAddress) === null || _a === void 0 ? void 0 : _a.state) !== null && _b !== void 0 ? _b : "";
107
108
  }
108
109
  getBillingsFromProfileCode(billingProfileCode) {
109
- return this.projects.flatMap((project) => { var _a; return (_a = project.billings) !== null && _a !== void 0 ? _a : []; }).filter((billing) => billing.billingProfileCode === billingProfileCode);
110
+ return this.projects
111
+ .flatMap((project) => { var _a; return (_a = project.billings) !== null && _a !== void 0 ? _a : []; })
112
+ .filter((billing) => !billingProfileCode || billing.billingProfileCode === billingProfileCode);
110
113
  }
111
114
  getCreditNoteTransactions(billingProfileCode) {
112
115
  return this.getBillingsFromProfileCode(billingProfileCode).flatMap((billing) => { var _a; return (_a = billing.creditNoteTransactions) !== null && _a !== void 0 ? _a : []; });
@@ -127,6 +130,9 @@ class ClientEntityModel extends base_entity_model_1.BaseEntityModel {
127
130
  get totalCreditNoteAmountPendingForAdjustment() {
128
131
  return this.totalCreditNoteAmount - this.totalCreditNoteAmountAdjusted;
129
132
  }
133
+ getUnsettledCreditNoteSummary(billingProfileCode) {
134
+ return billing_transaction_model_1.BillingTransactionEntityModel.getUnsettledCreditNoteSummary(this.getCreditNoteTransactions(billingProfileCode), this.getAdjustedCreditNoteTransactions(billingProfileCode));
135
+ }
130
136
  }
131
137
  exports.ClientEntityModel = ClientEntityModel;
132
138
  ClientEntityModel.CLIENT_ENTITY_DOCUMENT_TYPES = ["pan", "tan", "gst"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "11.0.1-beta.4",
3
+ "version": "11.0.1-beta.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [