refactoring: payment receive and sale invoice actions.

This commit is contained in:
Ahmed Bouhuolia
2020-10-25 18:30:44 +02:00
parent 39d1875cbb
commit 426f9fcf55
20 changed files with 820 additions and 1069 deletions

View File

@@ -316,7 +316,9 @@ export default class BillPaymentsService {
...omit(billPaymentObj, ['entries']),
entries: billPaymentDTO.entries,
});
await this.eventDispatcher.dispatch(events.billPayments.onEdited);
await this.eventDispatcher.dispatch(events.billPayments.onEdited, {
tenantId, billPaymentId, billPayment, oldPaymentMade,
});
this.logger.info('[bill_payment] edited successfully.', { tenantId, billPaymentId, billPayment, oldPaymentMade });
return billPayment;

View File

@@ -184,7 +184,10 @@ export default class BillsService extends SalesInvoicesCost {
await this.getVendorOrThrowError(tenantId, billDTO.vendorId);
await this.validateBillNumberExists(tenantId, billDTO.billNumber);
// Validate items IDs existance.
await this.itemsEntriesService.validateItemsIdsExistance(tenantId, billDTO.entries);
// Validate non-purchasable items.
await this.itemsEntriesService.validateNonPurchasableEntriesItems(tenantId, billDTO.entries);
const bill = await Bill.query()
@@ -232,7 +235,7 @@ export default class BillsService extends SalesInvoicesCost {
this.logger.info('[bill] trying to edit bill.', { tenantId, billId });
const oldBill = await this.getBillOrThrowError(tenantId, billId);
const billObj = this.billDTOToModel(tenantId, billDTO, oldBill);
const billObj = await this.billDTOToModel(tenantId, billDTO, oldBill);
await this.getVendorOrThrowError(tenantId, billDTO.vendorId);
await this.validateBillNumberExists(tenantId, billDTO.billNumber, billId);
@@ -242,7 +245,7 @@ export default class BillsService extends SalesInvoicesCost {
await this.itemsEntriesService.validateNonPurchasableEntriesItems(tenantId, billDTO.entries);
// Update the bill transaction.
const bill = await Bill.query().upsertGraph({
const bill = await Bill.query().upsertGraphAndFetch({
id: billId,
...omit(billObj, ['entries', 'invLotNumber']),