feat: retrieve bills that associated to payment made transaction.

feat: retrieve sale invoices that associated to payment receive transactions.
This commit is contained in:
Ahmed Bouhuolia
2020-10-28 22:41:16 +02:00
parent fd6a3224fa
commit a457005fd8
4 changed files with 93 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ import TenancyService from 'services/Tenancy/TenancyService';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import { entriesAmountDiff, formatDateFields } from 'utils';
import { ServiceError } from 'exceptions';
import { Bill } from 'models';
const ERRORS = {
BILL_VENDOR_NOT_FOUND: 'VENDOR_NOT_FOUND',
@@ -366,6 +367,22 @@ export default class BillPaymentsService {
this.logger.info('[bill_payment] deleted successfully.', { tenantId, billPaymentId });
}
/**
* Retrieve payment made associated bills.
* @param {number} tenantId -
* @param {number} billPaymentId -
*/
public async getPaymentBills(tenantId: number, billPaymentId: number) {
const { Bill } = this.tenancy.models(tenantId);
const billPayment = await this.getPaymentMadeOrThrowError(tenantId, billPaymentId);
const paymentBillsIds = billPayment.entries.map((entry) => entry.id);
const bills = await Bill.query().whereIn('id', paymentBillsIds);
return bills;
}
/**
* Records bill payment receive journal transactions.
* @param {number} tenantId -

View File

@@ -26,6 +26,7 @@ import { formatDateFields, entriesAmountDiff } from 'utils';
import { ServiceError } from 'exceptions';
import CustomersService from 'services/Contacts/CustomersService';
import ItemsEntriesService from 'services/Items/ItemsEntriesService';
import { SaleInvoice } from 'models';
const ERRORS = {
PAYMENT_RECEIVE_NO_EXISTS: 'PAYMENT_RECEIVE_NO_EXISTS',
@@ -337,7 +338,24 @@ export default class PaymentReceiveService {
}
return paymentReceive;
}
/**
* Retrieve sale invoices that assocaited to the given payment receive.
* @param {number} tenantId - Tenant id.
* @param {number} paymentReceiveId - Payment receive id.
* @return {Promise<ISaleInvoice>}
*/
public async getPaymentReceiveInvoices(tenantId: number, paymentReceiveId: number) {
const { SaleInvoice } = this.tenancy.models(tenantId);
const paymentReceive = await this.getPaymentReceiveOrThrowError(tenantId, paymentReceiveId);
const paymentReceiveInvoicesIds = paymentReceive.entries.map(entry => entry.invoiceId);
const saleInvoices = await SaleInvoice.query().whereIn('id', paymentReceiveInvoicesIds);
return saleInvoices;
}
/**
* Retrieve payment receives paginated and filterable list.
* @param {number} tenantId
@@ -442,7 +460,6 @@ export default class PaymentReceiveService {
]);
}
/**
* Saves difference changing between old and new invoice payment amount.
* @async