law-common 11.0.1-beta.2 → 11.0.1-beta.5

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 = [
@@ -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 {
@@ -77,9 +78,14 @@ export declare class ClientEntityModel extends BaseEntityModel<EntityEnum.CLIENT
77
78
  get addressLineTwo(): string;
78
79
  get city(): string;
79
80
  get state(): string;
80
- get creditNoteTransactions(): import("./billing-transaction.model").BillingTransactionEntityModel[];
81
- get adjustedCreditNoteTransactions(): import("./billing-transaction.model").BillingTransactionEntityModel[];
81
+ getBillingsFromProfileCode(billingProfileCode?: string): import("./billing.entity.model").BillingEntityModel[];
82
+ getCreditNoteTransactions(billingProfileCode?: string): BillingTransactionEntityModel[];
83
+ getAdjustedCreditNoteTransactions(billingProfileCode?: string): BillingTransactionEntityModel[];
82
84
  get totalCreditNoteAmount(): number;
83
85
  get totalCreditNoteAmountAdjusted(): number;
84
86
  get totalCreditNoteAmountPendingForAdjustment(): number;
87
+ getUnsettledCreditNoteSummary(billingProfileCode?: string): {
88
+ creditNote: BillingTransactionEntityModel;
89
+ amountPendingToBeSettled: number;
90
+ }[];
85
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);
@@ -105,11 +106,16 @@ class ClientEntityModel extends base_entity_model_1.BaseEntityModel {
105
106
  var _a, _b;
106
107
  return (_b = (_a = this.parsedAddress) === null || _a === void 0 ? void 0 : _a.state) !== null && _b !== void 0 ? _b : "";
107
108
  }
108
- get creditNoteTransactions() {
109
- return this.projects.flatMap((project) => { var _a; return (_a = project.settledBillings) !== null && _a !== void 0 ? _a : []; }).flatMap((billing) => { var _a; return (_a = billing.creditNoteTransactions) !== null && _a !== void 0 ? _a : []; });
109
+ getBillingsFromProfileCode(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
- get adjustedCreditNoteTransactions() {
112
- return this.projects.flatMap((project) => { var _a; return (_a = project.settledBillings) !== null && _a !== void 0 ? _a : []; }).flatMap((billing) => { var _a; return (_a = billing.adjustedCreditNoteTransactions) !== null && _a !== void 0 ? _a : []; });
114
+ getCreditNoteTransactions(billingProfileCode) {
115
+ return this.getBillingsFromProfileCode(billingProfileCode).flatMap((billing) => { var _a; return (_a = billing.creditNoteTransactions) !== null && _a !== void 0 ? _a : []; });
116
+ }
117
+ getAdjustedCreditNoteTransactions(billingProfileCode) {
118
+ return this.getBillingsFromProfileCode(billingProfileCode).flatMap((billing) => { var _a; return (_a = billing.adjustedCreditNoteTransactions) !== null && _a !== void 0 ? _a : []; });
113
119
  }
114
120
  get totalCreditNoteAmount() {
115
121
  const creditNoteTransactions = this.projects.flatMap((project) => { var _a; return (_a = project.settledBillings) !== null && _a !== void 0 ? _a : []; }).flatMap((billing) => { var _a; return (_a = billing.creditNoteTransactions) !== null && _a !== void 0 ? _a : []; });
@@ -124,6 +130,9 @@ class ClientEntityModel extends base_entity_model_1.BaseEntityModel {
124
130
  get totalCreditNoteAmountPendingForAdjustment() {
125
131
  return this.totalCreditNoteAmount - this.totalCreditNoteAmountAdjusted;
126
132
  }
133
+ getUnsettledCreditNoteSummary(billingProfileCode) {
134
+ return billing_transaction_model_1.BillingTransactionEntityModel.getUnsettledCreditNoteSummary(this.getCreditNoteTransactions(billingProfileCode), this.getAdjustedCreditNoteTransactions(billingProfileCode));
135
+ }
127
136
  }
128
137
  exports.ClientEntityModel = ClientEntityModel;
129
138
  ClientEntityModel.CLIENT_ENTITY_DOCUMENT_TYPES = ["pan", "tan", "gst"];
package/dist/src/index.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
37
  };
@@ -149,12 +149,12 @@ export declare function getEnumNames(enumType: object): string[];
149
149
  export declare function getFilterByPermission<T extends EnumEntityType<EntityEnum>>(permissionFilterConfig: {
150
150
  [key: string]: IEntityFilterData<T>;
151
151
  }, propertyName: keyof T, userPermission: string, filterDto: IEntityFilterData<T>, emptyValue?: any): {
152
- [x: string]: any;
152
+ [propertyName]: any;
153
153
  };
154
154
  export declare function getFilterByPermissionFn<T extends EnumEntityType<EntityEnum>>(permissionFilterConfig: {
155
155
  [key: string]: () => Promise<IEntityFilterData<T>>;
156
156
  }, propertyName: keyof T, userPermission: string, filterDto: IEntityFilterData<T>, emptyValue?: any): Promise<{
157
- [x: string]: any;
157
+ [propertyName]: any;
158
158
  }>;
159
159
  export declare function getPropertyFilterByPermissionFn<T extends EnumEntityType<EntityEnum>>(permissionFilterConfig: {
160
160
  [key: string]: () => Promise<IEntityFilterData<T>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "11.0.1-beta.2",
3
+ "version": "11.0.1-beta.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [