mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
Merge pull request #352 from bigcapitalhq/big-138-revert-the-paid-amount-to-bill-transaction-after-editing
fix(server): Revert the paid amount to bill transaction after editing bill payment amount
This commit is contained in:
@@ -10,7 +10,6 @@ import {
|
|||||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
|
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
|
||||||
import { BillPayment } from '@/models';
|
|
||||||
import { ERRORS } from './constants';
|
import { ERRORS } from './constants';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@@ -18,19 +17,6 @@ export class BillPaymentValidators {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private tenancy: TenancyService;
|
private tenancy: TenancyService;
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates the payment existance.
|
|
||||||
* @param {BillPayment | undefined | null} payment
|
|
||||||
* @throws {ServiceError(ERRORS.PAYMENT_MADE_NOT_FOUND)}
|
|
||||||
*/
|
|
||||||
public async validateBillPaymentExistance(
|
|
||||||
payment: BillPayment | undefined | null
|
|
||||||
) {
|
|
||||||
if (!payment) {
|
|
||||||
throw new ServiceError(ERRORS.PAYMENT_MADE_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the bill payment existance.
|
* Validates the bill payment existance.
|
||||||
* @param {Request} req
|
* @param {Request} req
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import UnitOfWork from '@/services/UnitOfWork';
|
import UnitOfWork from '@/services/UnitOfWork';
|
||||||
import { BillPaymentValidators } from './BillPaymentValidators';
|
|
||||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
@@ -21,9 +20,6 @@ export class DeleteBillPayment {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private uow: UnitOfWork;
|
private uow: UnitOfWork;
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private validators: BillPaymentValidators;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the bill payment and associated transactions.
|
* Deletes the bill payment and associated transactions.
|
||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
@@ -36,10 +32,8 @@ export class DeleteBillPayment {
|
|||||||
// Retrieve the bill payment or throw not found service error.
|
// Retrieve the bill payment or throw not found service error.
|
||||||
const oldBillPayment = await BillPayment.query()
|
const oldBillPayment = await BillPayment.query()
|
||||||
.withGraphFetched('entries')
|
.withGraphFetched('entries')
|
||||||
.findById(billPaymentId);
|
.findById(billPaymentId)
|
||||||
|
.throwIfNotFound();
|
||||||
// Validates the bill payment existance.
|
|
||||||
this.validators.validateBillPaymentExistance(oldBillPayment);
|
|
||||||
|
|
||||||
// Deletes the bill transactions with associated transactions under
|
// Deletes the bill transactions with associated transactions under
|
||||||
// unit-of-work envirement.
|
// unit-of-work envirement.
|
||||||
|
|||||||
@@ -57,12 +57,12 @@ export class EditBillPayment {
|
|||||||
|
|
||||||
const tenantMeta = await TenantMetadata.query().findOne({ tenantId });
|
const tenantMeta = await TenantMetadata.query().findOne({ tenantId });
|
||||||
|
|
||||||
const oldBillPayment = await BillPayment.query().findById(billPaymentId);
|
const oldBillPayment = await BillPayment.query()
|
||||||
|
.findById(billPaymentId)
|
||||||
|
.withGraphFetched('entries')
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
// Validates the bill payment existance.
|
// Retrieves the bill payment vendor or throw not found error.
|
||||||
this.validators.validateBillPaymentExistance(oldBillPayment);
|
|
||||||
|
|
||||||
//
|
|
||||||
const vendor = await Contact.query()
|
const vendor = await Contact.query()
|
||||||
.modify('vendor')
|
.modify('vendor')
|
||||||
.findById(billPaymentDTO.vendorId)
|
.findById(billPaymentDTO.vendorId)
|
||||||
@@ -126,7 +126,7 @@ export class EditBillPayment {
|
|||||||
trx,
|
trx,
|
||||||
} as IBillPaymentEditingPayload);
|
} as IBillPaymentEditingPayload);
|
||||||
|
|
||||||
// Deletes the bill payment transaction graph from the storage.
|
// Edits the bill payment transaction graph on the storage.
|
||||||
const billPayment = await BillPayment.query(trx).upsertGraphAndFetch({
|
const billPayment = await BillPayment.query(trx).upsertGraphAndFetch({
|
||||||
id: billPaymentId,
|
id: billPaymentId,
|
||||||
...billPaymentObj,
|
...billPaymentObj,
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { IBillPayment } from '@/interfaces';
|
import { IBillPayment } from '@/interfaces';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { ERRORS } from './constants';
|
|
||||||
import { ServiceError } from '@/exceptions';
|
|
||||||
import { BillPaymentTransformer } from './BillPaymentTransformer';
|
import { BillPaymentTransformer } from './BillPaymentTransformer';
|
||||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||||
import { BillsValidators } from '../Bills/BillsValidators';
|
|
||||||
import { BillPaymentValidators } from './BillPaymentValidators';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class GetBillPayment {
|
export class GetBillPayment {
|
||||||
@@ -16,9 +12,6 @@ export class GetBillPayment {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private transformer: TransformerInjectable;
|
private transformer: TransformerInjectable;
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private validators: BillPaymentValidators;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve bill payment.
|
* Retrieve bill payment.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -37,10 +30,8 @@ export class GetBillPayment {
|
|||||||
.withGraphFetched('paymentAccount')
|
.withGraphFetched('paymentAccount')
|
||||||
.withGraphFetched('transactions')
|
.withGraphFetched('transactions')
|
||||||
.withGraphFetched('branch')
|
.withGraphFetched('branch')
|
||||||
.findById(billPyamentId);
|
.findById(billPyamentId)
|
||||||
|
.throwIfNotFound();
|
||||||
// Validates the bill payment existance.
|
|
||||||
this.validators.validateBillPaymentExistance(billPayment);
|
|
||||||
|
|
||||||
return this.transformer.transform(
|
return this.transformer.transform(
|
||||||
tenantId,
|
tenantId,
|
||||||
|
|||||||
@@ -18,10 +18,9 @@ export class GetPaymentBills {
|
|||||||
public async getPaymentBills(tenantId: number, billPaymentId: number) {
|
public async getPaymentBills(tenantId: number, billPaymentId: number) {
|
||||||
const { Bill, BillPayment } = this.tenancy.models(tenantId);
|
const { Bill, BillPayment } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const billPayment = await BillPayment.query().findById(billPaymentId);
|
const billPayment = await BillPayment.query()
|
||||||
|
.findById(billPaymentId)
|
||||||
// Validates the bill payment existance.
|
.throwIfNotFound();
|
||||||
this.validators.validateBillPaymentExistance(billPayment);
|
|
||||||
|
|
||||||
const paymentBillsIds = billPayment.entries.map((entry) => entry.id);
|
const paymentBillsIds = billPayment.entries.map((entry) => entry.id);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ export class EditPaymentReceive {
|
|||||||
// Validate the payment receive existance.
|
// Validate the payment receive existance.
|
||||||
const oldPaymentReceive = await PaymentReceive.query()
|
const oldPaymentReceive = await PaymentReceive.query()
|
||||||
.withGraphFetched('entries')
|
.withGraphFetched('entries')
|
||||||
.findById(paymentReceiveId);
|
.findById(paymentReceiveId)
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
// Validates the payment existance.
|
// Validates the payment existance.
|
||||||
this.validators.validatePaymentExistance(oldPaymentReceive);
|
this.validators.validatePaymentExistance(oldPaymentReceive);
|
||||||
|
|||||||
Reference in New Issue
Block a user