law-common 10.16.1 → 10.17.0

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,4 +1,4 @@
1
- import { BillingImpactEnum, BillingStatusEnum, IBillingEntity, IEntityCreateDto } from "../../entities";
1
+ import { BillingImpactEnum, BillingStatusEnum, IBillingEntity, IBillingTimesheetEntity, IEntityCreateDto, IProjectEntity, ITimesheetEntity } from "../../entities";
2
2
  export type IBillingCreateExclude = "paymentStatus" | "status" | "writeoffAmount" | "tdsAmount" | "totalAmountPaid" | "creditNoteAmount" | "invoicePdfUrl";
3
3
  export interface IBillingCreateDto extends Omit<IEntityCreateDto<IBillingEntity>, IBillingCreateExclude> {
4
4
  timesheets: IBillingTimesheetsDto;
@@ -24,3 +24,8 @@ export interface IBillingTimesheetsDto {
24
24
  updateDetails: IBillingTimesheetUpdateDeleteDetailDto[];
25
25
  deleteDetails: IBillingTimesheetUpdateDeleteDetailDto[];
26
26
  }
27
+ export interface IBillingEntityCreateDtoValidationData {
28
+ projectEntity: IProjectEntity;
29
+ billingTimesheetEntities: IBillingTimesheetEntity[];
30
+ timesheetEntities: ITimesheetEntity[];
31
+ }
@@ -1,4 +1,5 @@
1
- import { BillingActionsEnum, IBillingEntity, IBillingEntityCreateDtoValidationData, IBillingTimesheetUpdateDto, IEntityUpdateDto } from "../../entities";
1
+ import { BillingActionsEnum, IBillingEntity, IBillingTimesheetUpdateDto, IEntityUpdateDto } from "../../entities";
2
+ import { IBillingEntityCreateDtoValidationData } from "./billing.create.dto.interface";
2
3
  export interface IBillingUpdateDto extends IEntityUpdateDto<IBillingEntity> {
3
4
  }
4
5
  export interface IUpdateBillingDto extends IBillingUpdateDto {
@@ -11,3 +11,4 @@ export declare const usersToExcludeFromSearchResponse: string[];
11
11
  export declare const systemUsers: string[];
12
12
  export declare const reimbursementExpenseProjectUserInactiveBuffer: number;
13
13
  export declare const annualPaidLeaves = 24;
14
+ export declare const designationPriorityOrder: Record<string, number>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.annualPaidLeaves = exports.reimbursementExpenseProjectUserInactiveBuffer = exports.systemUsers = exports.usersToExcludeFromSearchResponse = exports.freezeTimesheetAfterBillingStatus = exports.leaveImplicitDays = exports.reimbursementPaymentProcessorPermissionName = exports.toDoListMinimumEstimatedDuration = exports.timesheetMinimumTotalDuration = exports.timesheetEnterThreshold = exports.timesheetThreshold = exports.timesheetViewThreshold = void 0;
3
+ exports.designationPriorityOrder = exports.annualPaidLeaves = exports.reimbursementExpenseProjectUserInactiveBuffer = exports.systemUsers = exports.usersToExcludeFromSearchResponse = exports.freezeTimesheetAfterBillingStatus = exports.leaveImplicitDays = exports.reimbursementPaymentProcessorPermissionName = exports.toDoListMinimumEstimatedDuration = exports.timesheetMinimumTotalDuration = exports.timesheetEnterThreshold = exports.timesheetThreshold = exports.timesheetViewThreshold = void 0;
4
4
  const entities_1 = require("../entities");
5
5
  exports.timesheetViewThreshold = "timesheetViewThreshold";
6
6
  exports.timesheetThreshold = "timesheetThreshold";
@@ -14,3 +14,9 @@ exports.usersToExcludeFromSearchResponse = ["DB migration"];
14
14
  exports.systemUsers = ["DB migration"];
15
15
  exports.reimbursementExpenseProjectUserInactiveBuffer = 24 * 60;
16
16
  exports.annualPaidLeaves = 24;
17
+ exports.designationPriorityOrder = {
18
+ seniorPartner: 1,
19
+ partner: 2,
20
+ seniorAssociate: 3,
21
+ associate: 4,
22
+ };
@@ -1,10 +1,9 @@
1
+ import { CurrencyEnum } from "../../enums";
1
2
  import { BillingStatusEnum } from "../enums/billing.status.enum";
2
3
  import { BillingInvoiceTypeEnum } from "../enums/billing_invoice_type.enum";
3
4
  import { PaymentStatusEnum } from "../enums/payment_status.enum";
4
5
  import { IAuditColumnEntity } from "./audit-column.entity.interface";
5
6
  import { EntityEnum, IEntityFilterData } from "./entity.utils.interface";
6
- import { IProjectEntity } from "./project.entity.interface";
7
- import { ITimesheetEntity } from "./timesheet.entity.interface";
8
7
  export interface IBillingEntity extends IAuditColumnEntity {
9
8
  id: number;
10
9
  startDate: string;
@@ -24,12 +23,11 @@ export interface IBillingEntity extends IAuditColumnEntity {
24
23
  invoicePdfUrl?: string | null;
25
24
  invoiceContactName: string;
26
25
  bankId: number;
26
+ conversionRate?: number;
27
+ particulars: string;
28
+ currency: CurrencyEnum;
27
29
  }
28
30
  export interface IBillingEntityFilterDto extends IEntityFilterData<IBillingEntity> {
29
31
  }
30
- export interface IBillingEntityCreateDtoValidationData {
31
- projectEntity: IProjectEntity;
32
- timesheetEntities: ITimesheetEntity[];
33
- }
34
32
  export declare const billingRelations: EntityEnum[];
35
33
  export declare const billingEntities: EntityEnum[];
@@ -39,7 +39,8 @@ export interface IBillingTimesheetDetailsArray extends Array<IBillingTimesheetDe
39
39
  export interface IBillingTimesheetEntityFilterDto extends IEntityFilterData<IBillingTimesheetEntity> {
40
40
  }
41
41
  export interface IBillingTimesheetEntityCreateDtoValidationResult {
42
- timesheets: ITimesheetEntity[];
42
+ billingTimesheetEntities: IBillingTimesheetEntity[];
43
+ timesheetEntities: ITimesheetEntity[];
43
44
  }
44
45
  export interface IBillingTimesheetUpdateDto extends IEntityUpdateDto<IBillingTimesheetEntity> {
45
46
  }
@@ -37,17 +37,19 @@ export interface IProjectHourlyRate {
37
37
  rate: number;
38
38
  unit: TimeUnitEnum.HOUR;
39
39
  }
40
- export interface IProjectFixedMonthlyRate {
40
+ export interface IProjectFixedTypeRate {
41
41
  rate: number;
42
- unit: TimeUnitEnum.MONTH;
42
+ unit: TimeUnitEnum;
43
43
  maxEstimatedHours: number;
44
+ extraHoursRate: number;
44
45
  }
45
46
  export interface IProjectAdhocRate {
46
47
  rate: number;
47
48
  maxEstimatedHours: number;
49
+ extraHoursRate: number;
48
50
  }
49
51
  export interface IProjectCreateDtoExtra {
50
- projectBillingRate: IProjectHourlyRate[] | IProjectFixedMonthlyRate | IProjectAdhocRate;
52
+ projectBillingRate: IProjectHourlyRate[] | IProjectFixedTypeRate | IProjectAdhocRate;
51
53
  }
52
54
  export interface IProjectEntityCreateDto extends Omit<IEntityCreateDto<IProjectEntity>, IProjectExclude>, IProjectEntityDependent, IProjectCreateDtoExtra {
53
55
  }
@@ -5,6 +5,7 @@ export declare enum TimeUnitEnum {
5
5
  DAY = "DAY",
6
6
  WEEK = "WEEK",
7
7
  MONTH = "MONTH",
8
+ QUARTER = "QUARTER",
8
9
  YEAR = "YEAR"
9
10
  }
10
11
  export declare namespace TimeUnitEnum {
@@ -11,6 +11,7 @@ var TimeUnitEnum;
11
11
  TimeUnitEnum["DAY"] = "DAY";
12
12
  TimeUnitEnum["WEEK"] = "WEEK";
13
13
  TimeUnitEnum["MONTH"] = "MONTH";
14
+ TimeUnitEnum["QUARTER"] = "QUARTER";
14
15
  TimeUnitEnum["YEAR"] = "YEAR";
15
16
  })(TimeUnitEnum || (exports.TimeUnitEnum = TimeUnitEnum = {}));
16
17
  (function (TimeUnitEnum) {
@@ -28,6 +29,8 @@ var TimeUnitEnum;
28
29
  return 60 * 24 * 7;
29
30
  case TimeUnitEnum.MONTH:
30
31
  return 60 * 24 * 30;
32
+ case TimeUnitEnum.QUARTER:
33
+ return 60 * 24 * 30 * 3;
31
34
  case TimeUnitEnum.YEAR:
32
35
  return 60 * 24 * 365;
33
36
  }
@@ -55,15 +58,16 @@ var TimeUnitEnum;
55
58
  return TimeUnitEnum.YEAR;
56
59
  default:
57
60
  throw new exceptions_1.AppBadRequestException({
58
- message: [`Invalid time unit: ${value}. Valid values are: ${TimeUnitEnum.getNames().join(", ")}`],
61
+ message: [
62
+ `Invalid time unit: ${value}. Valid values are: ${TimeUnitEnum.getNames().join(", ")}`,
63
+ ],
59
64
  key: error_key_enum_1.ErrorKeyEnum.TIME_UNIT,
60
65
  });
61
66
  }
62
67
  }
63
68
  TimeUnitEnum.parse = parse;
64
69
  function getNames() {
65
- return Object.values(TimeUnitEnum).filter(value => typeof value === 'string');
66
- ;
70
+ return Object.values(TimeUnitEnum).filter((value) => typeof value === "string");
67
71
  }
68
72
  TimeUnitEnum.getNames = getNames;
69
73
  })(TimeUnitEnum || (exports.TimeUnitEnum = TimeUnitEnum = {}));
@@ -176,3 +176,39 @@ export declare function transformDate<T extends {
176
176
  export declare function capitalizeFirstWord(str: string): string;
177
177
  export declare function getEntitiesFromSearchV2Response<E extends EntityEnum, // Enum key like EntityEnum.USER, EntityEnum.PROJECT, etc.
178
178
  T extends EnumEntityType<E>>(searchResponseV2: IBaseEntityServiceResponse<EnumEntityType<EntityEnum>>, entityEnumKey: E, EntityClass: new () => T): T[];
179
+ /**
180
+ * Checks if two decimal numbers are approximately equal within a given tolerance.
181
+ *
182
+ * @param {number} firstValue - The first number to compare.
183
+ * @param {number} secondValue - The second number to compare.
184
+ * @param {number} allowedDifference - The maximum difference allowed for the numbers
185
+ * to be considered equal.
186
+ *
187
+ * @returns {boolean} Returns `true` if the numbers are within the allowed difference;
188
+ * otherwise, returns `false`.
189
+ *
190
+ * @example
191
+ * areDecimalNumbersEqual(5483.86, 5483.87, 0.5); // true
192
+ * areDecimalNumbersEqual(5483.86, 5484.5, 0.5); // false
193
+ */
194
+ export declare function areDecimalNumbersEqual(firstValue: number, secondValue: number, allowedDifference?: number): boolean;
195
+ /**
196
+ * Formats a number into the Indian numbering system with commas.
197
+ *
198
+ * - Ensures **two decimal places**.
199
+ * - Applies Indian digit grouping: last 3 digits, then groups of 2 (e.g., 1,23,456.00).
200
+ * - Accepts both `number` and `string` input.
201
+ * - Returns an empty string if the input is not a valid number.
202
+ *
203
+ * @param {number | string} amount - The number or numeric string to format.
204
+ * @returns {string} The formatted number as a string in Indian number format.
205
+ *
206
+ * @example
207
+ * formatIndianNumber(123456); // "1,23,456.00"
208
+ * formatIndianNumber(1891250); // "18,91,250.00"
209
+ * formatIndianNumber("21250"); // "21,250.00"
210
+ * formatIndianNumber("abc"); // ""
211
+ */
212
+ export declare function formatIndianNumber(amount: number | string): string;
213
+ export declare function findDuplicateIds(ids: number[]): number[];
214
+ export declare function getDecimalNumberFromString(value: string | number, placesAfterDecimal?: number): number;
@@ -33,6 +33,10 @@ exports.createKeyLabelMap = createKeyLabelMap;
33
33
  exports.transformDate = transformDate;
34
34
  exports.capitalizeFirstWord = capitalizeFirstWord;
35
35
  exports.getEntitiesFromSearchV2Response = getEntitiesFromSearchV2Response;
36
+ exports.areDecimalNumbersEqual = areDecimalNumbersEqual;
37
+ exports.formatIndianNumber = formatIndianNumber;
38
+ exports.findDuplicateIds = findDuplicateIds;
39
+ exports.getDecimalNumberFromString = getDecimalNumberFromString;
36
40
  const util_constants_1 = require("../constants/util.constants");
37
41
  const error_key_enum_1 = require("../enums/error.key.enum");
38
42
  const exceptions_1 = require("../exceptions");
@@ -393,3 +397,73 @@ function getEntitiesFromSearchV2Response(searchResponseV2, entityEnumKey, Entity
393
397
  }
394
398
  return (((_a = searchResponseV2.relatedEntities[entityEnumKey]) === null || _a === void 0 ? void 0 : _a.baseEntities) || []).map((entity) => Object.assign(new EntityClass(), entity));
395
399
  }
400
+ /**
401
+ * Checks if two decimal numbers are approximately equal within a given tolerance.
402
+ *
403
+ * @param {number} firstValue - The first number to compare.
404
+ * @param {number} secondValue - The second number to compare.
405
+ * @param {number} allowedDifference - The maximum difference allowed for the numbers
406
+ * to be considered equal.
407
+ *
408
+ * @returns {boolean} Returns `true` if the numbers are within the allowed difference;
409
+ * otherwise, returns `false`.
410
+ *
411
+ * @example
412
+ * areDecimalNumbersEqual(5483.86, 5483.87, 0.5); // true
413
+ * areDecimalNumbersEqual(5483.86, 5484.5, 0.5); // false
414
+ */
415
+ function areDecimalNumbersEqual(firstValue, secondValue, allowedDifference = 0.5) {
416
+ // Calculate the absolute difference between both values
417
+ const actualDifference = Math.abs(firstValue - secondValue);
418
+ // Return true if the actual difference is less than or equal to the allowed difference
419
+ return actualDifference <= allowedDifference;
420
+ }
421
+ /**
422
+ * Formats a number into the Indian numbering system with commas.
423
+ *
424
+ * - Ensures **two decimal places**.
425
+ * - Applies Indian digit grouping: last 3 digits, then groups of 2 (e.g., 1,23,456.00).
426
+ * - Accepts both `number` and `string` input.
427
+ * - Returns an empty string if the input is not a valid number.
428
+ *
429
+ * @param {number | string} amount - The number or numeric string to format.
430
+ * @returns {string} The formatted number as a string in Indian number format.
431
+ *
432
+ * @example
433
+ * formatIndianNumber(123456); // "1,23,456.00"
434
+ * formatIndianNumber(1891250); // "18,91,250.00"
435
+ * formatIndianNumber("21250"); // "21,250.00"
436
+ * formatIndianNumber("abc"); // ""
437
+ */
438
+ function formatIndianNumber(amount) {
439
+ let num = Number(amount);
440
+ if (isNaN(num))
441
+ return "";
442
+ // Ensure 2 decimal places
443
+ let [integerPart, decimalPart] = num.toFixed(2).split(".");
444
+ // Indian grouping: last 3 digits, then groups of 2
445
+ let lastThree = integerPart.slice(-3);
446
+ let otherNumbers = integerPart.slice(0, -3);
447
+ if (otherNumbers !== "") {
448
+ lastThree = "," + lastThree;
449
+ }
450
+ let formattedInt = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
451
+ return formattedInt + "." + decimalPart;
452
+ }
453
+ function findDuplicateIds(ids) {
454
+ const seen = new Set();
455
+ const duplicates = new Set();
456
+ for (const id of ids) {
457
+ if (seen.has(id)) {
458
+ duplicates.add(id);
459
+ }
460
+ else {
461
+ seen.add(id);
462
+ }
463
+ }
464
+ return Array.from(duplicates);
465
+ }
466
+ function getDecimalNumberFromString(value, placesAfterDecimal = 2) {
467
+ // this method should internally handle if the value is number or string
468
+ return Number(Number(value).toFixed(placesAfterDecimal));
469
+ }
@@ -34,4 +34,6 @@ export declare class DateCodeModel {
34
34
  isSame(dateCodeModel: DateCodeModel): boolean;
35
35
  getWeekday(): Weekday;
36
36
  getDateInIST(): Date;
37
+ static getDaysInCurrentMonth(): number;
38
+ getDaysInMonth(dateCode?: string): number;
37
39
  }
@@ -98,8 +98,8 @@ class DateCodeModel {
98
98
  }
99
99
  const dateRange = startModel.getRange(endModel);
100
100
  const excludeDayPredicates = (dateModel) => !dateModel.isDayPresent(excludeDays);
101
- const excludeDatePredicates = (dateModel) => !excludeDateCodes.some(d => d.isSame(dateModel));
102
- return dateRange.filter((dateModel => excludeDayPredicates(dateModel) && excludeDatePredicates(dateModel))).length;
101
+ const excludeDatePredicates = (dateModel) => !excludeDateCodes.some((d) => d.isSame(dateModel));
102
+ return dateRange.filter((dateModel) => excludeDayPredicates(dateModel) && excludeDatePredicates(dateModel)).length;
103
103
  }
104
104
  static getByPredicates(models, includePredicates, excludePredicates) {
105
105
  return models.filter((model) => includePredicates.every((predicate) => predicate(model)) &&
@@ -209,5 +209,18 @@ class DateCodeModel {
209
209
  billDateIST.setHours(nowIST.getHours(), nowIST.getMinutes(), nowIST.getSeconds(), nowIST.getMilliseconds());
210
210
  return billDateIST;
211
211
  }
212
+ static getDaysInCurrentMonth() {
213
+ const today = new Date();
214
+ const lastDay = (0, date_fns_1.lastDayOfMonth)(today); // Gives last day of current month
215
+ return lastDay.getDate(); // Number of days in that month
216
+ }
217
+ getDaysInMonth(dateCode) {
218
+ // If a dateCode is provided, use that; otherwise use this instance's dateCode
219
+ const model = dateCode ? new DateCodeModel(dateCode) : this;
220
+ // Reuse existing parsing/normalization via getDate()
221
+ const date = model.getDate();
222
+ // Number of days in that month
223
+ return (0, date_fns_1.lastDayOfMonth)(date).getDate();
224
+ }
212
225
  }
213
226
  exports.DateCodeModel = DateCodeModel;
package/package.json CHANGED
@@ -1,35 +1,35 @@
1
- {
2
- "name": "law-common",
3
- "version": "10.16.1",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "files": [
7
- "dist/**/*"
8
- ],
9
- "scripts": {
10
- "clean": "rm -rf dist",
11
- "build": "npm run clean && tsc",
12
- "publish:beta": "npm version prerelease --preid beta && git push && npm run build && npm publish --tag beta",
13
- "publish:patch": "npm version patch && git push && npm run build && npm publish",
14
- "publish:minor": "npm version minor && git push && npm run build && npm publish",
15
- "publish:major": "npm version major && git push && npm run build && npm publish",
16
- "link": "npm run build && npm link",
17
- "test": "jest"
18
- },
19
- "keywords": [],
20
- "author": "",
21
- "license": "ISC",
22
- "devDependencies": {
23
- "@types/jest": "^29.5.13",
24
- "@types/node": "^22.6.1",
25
- "jest": "^29.7.0",
26
- "ts-jest": "^29.2.5",
27
- "ts-node": "^10.9.2",
28
- "typescript": "^5.6.2"
29
- },
30
- "dependencies": {
31
- "@types/express": "^5.0.0",
32
- "@types/multer": "^1.4.12",
33
- "date-fns": "^4.1.0"
34
- }
35
- }
1
+ {
2
+ "name": "law-common",
3
+ "version": "10.17.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist/**/*"
8
+ ],
9
+ "scripts": {
10
+ "clean": "rm -rf dist",
11
+ "build": "npm run clean && tsc",
12
+ "publish:beta": "npm version prerelease --preid beta && git push && npm run build && npm publish --tag beta",
13
+ "publish:patch": "npm version patch && git push && npm run build && npm publish",
14
+ "publish:minor": "npm version minor && git push && npm run build && npm publish",
15
+ "publish:major": "npm version major && git push && npm run build && npm publish",
16
+ "link": "npm run build && npm link",
17
+ "test": "jest"
18
+ },
19
+ "keywords": [],
20
+ "author": "",
21
+ "license": "ISC",
22
+ "devDependencies": {
23
+ "@types/jest": "^29.5.13",
24
+ "@types/node": "^22.6.1",
25
+ "jest": "^29.7.0",
26
+ "ts-jest": "^29.2.5",
27
+ "ts-node": "^10.9.2",
28
+ "typescript": "^5.6.2"
29
+ },
30
+ "dependencies": {
31
+ "@types/express": "^5.0.0",
32
+ "@types/multer": "^1.4.12",
33
+ "date-fns": "^4.1.0"
34
+ }
35
+ }