gemcap-be-common 1.4.130 → 1.4.132

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.130",
3
+ "version": "1.4.132",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -45,7 +45,7 @@ export declare class ComplianceBorrowersService {
45
45
  };
46
46
  };
47
47
  getFullComplianceBorrowerById(complianceBorrowerId: string): Promise<any>;
48
- getAllBorrowersShortened(userAccess: IUserAccess): Promise<(Pick<IComplianceBorrowerDocument, "borrower" | "fundingStatus" | "items"> | {
48
+ getAllBorrowersShortened(userAccess: IUserAccess): Promise<(Pick<IComplianceBorrowerDocument, "borrower" | "items" | "fundingStatus"> | {
49
49
  items: {
50
50
  instances: any[];
51
51
  item: import("../models/ComplianceItem.model").IComplianceItemDocument;
@@ -78,6 +78,7 @@ export declare class QuickbooksService {
78
78
  chargeTypes: string[];
79
79
  reportDate: Date;
80
80
  format: 'IIF' | 'CSV';
81
+ companyIds: string[];
81
82
  }): Promise<{
82
83
  reportData: IQBReportTransaction[];
83
84
  reportErrors: string[];
@@ -15,7 +15,6 @@ const Borrower_model_1 = require("../models/Borrower.model");
15
15
  const TermLoan_model_1 = require("../models/TermLoan.model");
16
16
  const reports_db_1 = require("../db/reports.db");
17
17
  const QuickbooksAccount_model_1 = require("../models/QuickbooksAccount.model");
18
- const Company_model_1 = require("../models/Company.model");
19
18
  const headersIIF = [
20
19
  {
21
20
  service: '!TRNS',
@@ -113,9 +112,6 @@ class QuickbooksService {
113
112
  }
114
113
  if (deleteOld) {
115
114
  const companyId = accounts[0].companyId;
116
- // console.log({ companyId });
117
- // const existingAccounts = await QuickbooksAccount.find({ companyId: new mongoose.Types.ObjectId(companyId) });
118
- // console.log({ existingAccounts });
119
115
  const accountIds = accounts
120
116
  .filter((account) => !account._id.startsWith('new_'))
121
117
  .map((account) => new mongoose_1.default.Types.ObjectId(account._id));
@@ -301,10 +297,7 @@ class QuickbooksService {
301
297
  if (reportErrorsSet.size > 0) {
302
298
  return { reportData: [], reportErrors: Array.from(reportErrorsSet) };
303
299
  }
304
- const assetCompany = await Company_model_1.Company.findOne({ name: 'AssetCo' }).lean();
305
- if (!assetCompany) {
306
- return { reportData: [], reportErrors: ['AssetCo company not found'] };
307
- }
300
+ const companyFilter = { companyId: { $in: params.companyIds.map((id) => new mongoose_1.default.Types.ObjectId(id)) } };
308
301
  const { reportType, productIds, chargeTypes, reportDate } = params;
309
302
  const reportDateFormatted = (0, dayjs_1.default)(reportDate).utcOffset(0).format('MM/DD/YYYY').toUpperCase();
310
303
  const reportDateTrFormatted = (0, dayjs_1.default)(reportDate).utcOffset(0).format(transactionsDateFormat).toUpperCase();
@@ -356,8 +349,8 @@ class QuickbooksService {
356
349
  }
357
350
  let totalAmount = product.isParticipant ? -totalAmountValue : totalAmountValue;
358
351
  totalAmount = isAccrual ? totalAmount : -totalAmount;
359
- const quickbooksAccountBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: charge.code, companyId: assetCompany._id.toString() }).lean();
360
- const quickbooksAccountPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: PLCode, companyId: assetCompany._id.toString() }).lean();
352
+ const quickbooksAccountBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: charge.code, ...companyFilter }).lean();
353
+ const quickbooksAccountPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: PLCode, ...companyFilter }).lean();
361
354
  if (!quickbooksAccountBS || !quickbooksAccountPL) {
362
355
  if (!quickbooksAccountBS) {
363
356
  reportErrorsSet.add(charge.code);
@@ -381,8 +374,8 @@ class QuickbooksService {
381
374
  mainData.push({ ...tr });
382
375
  if (chargeTypes.includes('BROKERS') && isAccrual) {
383
376
  const handleFee = async (broker, shareName) => {
384
- const quickbooksAccountBrokerBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: broker.BSCode, companyId: assetCompany._id.toString() }).lean();
385
- const quickbooksAccountBrokerPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: broker.PLCode, companyId: assetCompany._id.toString() }).lean();
377
+ const quickbooksAccountBrokerBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: broker.BSCode, ...companyFilter }).lean();
378
+ const quickbooksAccountBrokerPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: broker.PLCode, ...companyFilter }).lean();
386
379
  if (!quickbooksAccountBrokerBS || !quickbooksAccountBrokerPL) {
387
380
  if (!quickbooksAccountBrokerBS) {
388
381
  reportErrorsSet.add(broker.BSCode);
@@ -436,8 +429,8 @@ class QuickbooksService {
436
429
  settlementCode = revolverProduct.code;
437
430
  }
438
431
  }
439
- const quickbooksAccountPaymentBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: product.code, companyId: assetCompany._id.toString() }).lean();
440
- const quickbooksAccountPaymentPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: settlementCode, companyId: assetCompany._id.toString() }).lean();
432
+ const quickbooksAccountPaymentBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: product.code, ...companyFilter }).lean();
433
+ const quickbooksAccountPaymentPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: settlementCode, ...companyFilter }).lean();
441
434
  if (!quickbooksAccountPaymentBS || !quickbooksAccountPaymentPL) {
442
435
  if (!quickbooksAccountPaymentBS) {
443
436
  reportErrorsSet.add(product.code);
@@ -11,7 +11,6 @@ import { BorrowerModel } from '../models/Borrower.model';
11
11
  import { ETermLoanStatus, TermLoanModel } from '../models/TermLoan.model';
12
12
  import { EChargeType } from '../db/reports.db';
13
13
  import { IBankView } from '../models/Banks.model';
14
-
15
14
  import { IQuickbooksAccount, QuickbooksAccount } from '../models/QuickbooksAccount.model';
16
15
  import { IQuickbooksUploadItem } from '../classes/quickbook-item';
17
16
  import { IUploadedBankTransaction } from '../models/UploadedBankTransaction.model';
@@ -23,7 +22,6 @@ import { CashAllocationService } from './cash-allocation.service';
23
22
  import { CompaniesService } from './companies.service';
24
23
  import { LoanChargesService } from './loan-charges.service';
25
24
  import { LoanPaymentsService } from './loan-payments.service';
26
- import { Company } from '../models/Company.model';
27
25
 
28
26
  export type QuickBookReportType = 'accrual' | 'payment' | 'cash';
29
27
 
@@ -156,9 +154,6 @@ export class QuickbooksService {
156
154
  }
157
155
  if (deleteOld) {
158
156
  const companyId = accounts[0].companyId;
159
- // console.log({ companyId });
160
- // const existingAccounts = await QuickbooksAccount.find({ companyId: new mongoose.Types.ObjectId(companyId) });
161
- // console.log({ existingAccounts });
162
157
  const accountIds = accounts
163
158
  .filter((account) => !account._id.startsWith('new_'))
164
159
  .map((account) => new mongoose.Types.ObjectId(account._id));
@@ -341,6 +336,7 @@ export class QuickbooksService {
341
336
  chargeTypes: string[],
342
337
  reportDate: Date,
343
338
  format: 'IIF' | 'CSV',
339
+ companyIds: string[],
344
340
  }) {
345
341
  const reportErrorsSet = new Set<string>();
346
342
  await Promise.all(params.productIds.map(async (productId) => {
@@ -356,10 +352,7 @@ export class QuickbooksService {
356
352
  return { reportData: [], reportErrors: Array.from(reportErrorsSet) };
357
353
  }
358
354
 
359
- const assetCompany = await Company.findOne({ name: 'AssetCo' }).lean();
360
- if (!assetCompany) {
361
- return { reportData: [], reportErrors: ['AssetCo company not found'] };
362
- }
355
+ const companyFilter = { companyId: { $in: params.companyIds.map((id) => new mongoose.Types.ObjectId(id)) } }
363
356
 
364
357
  const { reportType, productIds, chargeTypes, reportDate } = params;
365
358
  const reportDateFormatted = dayjs(reportDate).utcOffset(0).format('MM/DD/YYYY').toUpperCase();
@@ -418,8 +411,8 @@ export class QuickbooksService {
418
411
  }
419
412
  let totalAmount = product.isParticipant ? -totalAmountValue : totalAmountValue;
420
413
  totalAmount = isAccrual ? totalAmount : -totalAmount;
421
- const quickbooksAccountBS = await QuickbooksAccount.findOne({ accountCode: charge.code, companyId: assetCompany._id.toString() }).lean();
422
- const quickbooksAccountPL = await QuickbooksAccount.findOne({ accountCode: PLCode, companyId: assetCompany._id.toString() }).lean();
414
+ const quickbooksAccountBS = await QuickbooksAccount.findOne({ accountCode: charge.code, ...companyFilter }).lean();
415
+ const quickbooksAccountPL = await QuickbooksAccount.findOne({ accountCode: PLCode, ...companyFilter }).lean();
423
416
  if (!quickbooksAccountBS || !quickbooksAccountPL) {
424
417
  if (!quickbooksAccountBS) {
425
418
  reportErrorsSet.add(charge.code);
@@ -448,8 +441,8 @@ export class QuickbooksService {
448
441
 
449
442
  const handleFee = async (broker: IProductBrokerDocWithBroker, shareName: 'adminShare' | 'interestShare' | 'otherShare') => {
450
443
 
451
- const quickbooksAccountBrokerBS = await QuickbooksAccount.findOne({ accountCode: broker.BSCode, companyId: assetCompany._id.toString() }).lean();
452
- const quickbooksAccountBrokerPL = await QuickbooksAccount.findOne({ accountCode: broker.PLCode, companyId: assetCompany._id.toString() }).lean();
444
+ const quickbooksAccountBrokerBS = await QuickbooksAccount.findOne({ accountCode: broker.BSCode, ...companyFilter }).lean();
445
+ const quickbooksAccountBrokerPL = await QuickbooksAccount.findOne({ accountCode: broker.PLCode, ...companyFilter }).lean();
453
446
  if (!quickbooksAccountBrokerBS || !quickbooksAccountBrokerPL) {
454
447
  if (!quickbooksAccountBrokerBS) {
455
448
  reportErrorsSet.add(broker.BSCode);
@@ -512,8 +505,8 @@ export class QuickbooksService {
512
505
  }
513
506
  }
514
507
 
515
- const quickbooksAccountPaymentBS = await QuickbooksAccount.findOne({ accountCode: product.code, companyId: assetCompany._id.toString() }).lean();
516
- const quickbooksAccountPaymentPL = await QuickbooksAccount.findOne({ accountCode: settlementCode, companyId: assetCompany._id.toString() }).lean();
508
+ const quickbooksAccountPaymentBS = await QuickbooksAccount.findOne({ accountCode: product.code, ...companyFilter }).lean();
509
+ const quickbooksAccountPaymentPL = await QuickbooksAccount.findOne({ accountCode: settlementCode, ...companyFilter }).lean();
517
510
  if (!quickbooksAccountPaymentBS || !quickbooksAccountPaymentPL) {
518
511
  if (!quickbooksAccountPaymentBS) {
519
512
  reportErrorsSet.add(product.code);