@7365admin1/core 3.32.2-staging.57 → 3.32.2-staging.58

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.
package/dist/index.d.ts CHANGED
@@ -6996,14 +6996,27 @@ type TBillingPayments = {
6996
6996
  };
6997
6997
 
6998
6998
  declare const useRedDotPaymentRepo: () => {
6999
- createIndexes: () => Promise<void>;
7000
- getPaymentByReference: (referenceNumber: string, session?: ClientSession) => Promise<TBillingPayments>;
7001
6999
  paySingleUnitBill: (refId: string, payload: Partial<TUnitBilling>) => Promise<mongodb.WithId<bson.Document> | null>;
7002
7000
  createPayment: (type: string, payload: Partial<TBillingPayments>, session?: ClientSession) => Promise<string | undefined>;
7003
7001
  payMultipleUnitBill: (refId: string[], payload: Partial<TUnitBilling>) => Promise<{
7004
7002
  message: string;
7005
7003
  remainingBalance: number;
7006
7004
  }>;
7005
+ getPaidBills: ({ search, page, limit, sort, month, year, unitId, }: {
7006
+ search?: string | undefined;
7007
+ page?: number | undefined;
7008
+ limit?: number | undefined;
7009
+ sort?: Record<string, any> | undefined;
7010
+ month?: string | undefined;
7011
+ year?: string | undefined;
7012
+ unitId: string | ObjectId;
7013
+ }, session?: ClientSession) => Promise<{
7014
+ items: any[];
7015
+ pages: number;
7016
+ pageRange: string;
7017
+ }>;
7018
+ createIndexes: () => Promise<void>;
7019
+ getPaymentByReference: (referenceNumber: string, session?: ClientSession) => Promise<TBillingPayments>;
7007
7020
  updateStatus: (referenceNumber: string, status: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
7008
7021
  };
7009
7022
 
package/dist/index.js CHANGED
@@ -65221,6 +65221,76 @@ var useRedDotPaymentRepo = () => {
65221
65221
  }
65222
65222
  }
65223
65223
  }
65224
+ async function getPaidBills({
65225
+ search = "",
65226
+ page = 1,
65227
+ limit = 10,
65228
+ sort = {},
65229
+ month,
65230
+ year,
65231
+ unitId
65232
+ }, session) {
65233
+ let _unitId;
65234
+ try {
65235
+ _unitId = new import_mongodb135.ObjectId(unitId);
65236
+ } catch {
65237
+ throw new import_node_server_utils224.BadRequestError("Invalid unit ID format.");
65238
+ }
65239
+ page = page > 0 ? page - 1 : 0;
65240
+ let dateExpr = {};
65241
+ const datePaidRange = buildDatePaidRange(month, year);
65242
+ if (datePaidRange) {
65243
+ dateExpr.datePaid = datePaidRange;
65244
+ }
65245
+ const query = {
65246
+ unitId: _unitId,
65247
+ status: "success",
65248
+ ...search && {
65249
+ $or: [
65250
+ { referenceNumber: { $regex: search, $options: "i" } },
65251
+ { unitOwner: { $regex: search, $options: "i" } },
65252
+ { method: { $regex: search, $options: "i" } },
65253
+ { transaction_id: { $regex: search, $options: "i" } },
65254
+ { "unitBillingItems.name": { $regex: search, $options: "i" } },
65255
+ {
65256
+ $expr: {
65257
+ $regexMatch: {
65258
+ input: { $toString: "$totalAmount" },
65259
+ regex: search,
65260
+ options: "i"
65261
+ }
65262
+ }
65263
+ }
65264
+ ]
65265
+ },
65266
+ ...dateExpr
65267
+ };
65268
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
65269
+ try {
65270
+ const basePipeline = [
65271
+ { $match: query },
65272
+ { $sort: sort },
65273
+ { $skip: page * limit },
65274
+ { $limit: limit }
65275
+ ];
65276
+ const [items, countResult] = await Promise.all([
65277
+ paymentCollection().aggregate(basePipeline, { session }).toArray(),
65278
+ paymentCollection().aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
65279
+ ]);
65280
+ const totalCount = countResult[0]?.total || 0;
65281
+ const data = (0, import_node_server_utils224.paginate)(items, page, limit, totalCount);
65282
+ return data;
65283
+ } catch (error) {
65284
+ if (error instanceof import_node_server_utils224.AppError) {
65285
+ throw error;
65286
+ }
65287
+ import_node_server_utils224.logger.log({
65288
+ level: "error",
65289
+ message: error.message
65290
+ });
65291
+ throw new import_node_server_utils224.InternalServerError("Failed to retrieve paid bills.");
65292
+ }
65293
+ }
65224
65294
  async function paySingleUnitBill(refId, payload) {
65225
65295
  const session = import_node_server_utils224.useAtlas.getClient()?.startSession();
65226
65296
  try {
@@ -65383,6 +65453,28 @@ var useRedDotPaymentRepo = () => {
65383
65453
  session?.endSession();
65384
65454
  }
65385
65455
  }
65456
+ function buildDatePaidRange(month, year) {
65457
+ if (!year)
65458
+ return null;
65459
+ const yearNum = Number(year);
65460
+ if (!Number.isInteger(yearNum) || yearNum < 1970 || yearNum > 9999) {
65461
+ throw new import_node_server_utils224.BadRequestError("Invalid year filter.");
65462
+ }
65463
+ if (month) {
65464
+ const monthNum = Number(month);
65465
+ if (!Number.isInteger(monthNum) || monthNum < 1 || monthNum > 12) {
65466
+ throw new import_node_server_utils224.BadRequestError("Invalid month filter.");
65467
+ }
65468
+ return {
65469
+ $gte: new Date(yearNum, monthNum - 1, 1),
65470
+ $lt: new Date(yearNum, monthNum, 1)
65471
+ };
65472
+ }
65473
+ return {
65474
+ $gte: new Date(yearNum, 0, 1),
65475
+ $lt: new Date(yearNum + 1, 0, 1)
65476
+ };
65477
+ }
65386
65478
  async function updateStatus(referenceNumber, status, session) {
65387
65479
  const reference = typeof referenceNumber === "string" ? referenceNumber.trim() : "";
65388
65480
  if (!reference) {
@@ -65416,11 +65508,12 @@ var useRedDotPaymentRepo = () => {
65416
65508
  return formattedDate;
65417
65509
  }
65418
65510
  return {
65419
- createIndexes,
65420
- getPaymentByReference,
65421
65511
  paySingleUnitBill,
65422
65512
  createPayment,
65423
65513
  payMultipleUnitBill,
65514
+ getPaidBills,
65515
+ createIndexes,
65516
+ getPaymentByReference,
65424
65517
  updateStatus
65425
65518
  };
65426
65519
  };