mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-13 03:10:31 +00:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import Knex from 'knex';
|
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
import { Service, Inject } from 'typedi';
|
|
|
|
@Service()
|
|
export default class CreditNoteApplySyncCredit {
|
|
@Inject()
|
|
tenancy: HasTenancyService;
|
|
|
|
/**
|
|
* Increment credit note invoiced amount.
|
|
* @param {number} tenantId
|
|
* @param {number} creditNoteId
|
|
* @param {number} invoicesAppliedAmount
|
|
*/
|
|
public incrementCreditNoteInvoicedAmount = async (
|
|
tenantId: number,
|
|
creditNoteId: number,
|
|
invoicesAppliedAmount: number,
|
|
trx?: Knex.Transaction
|
|
) => {
|
|
const { CreditNote } = this.tenancy.models(tenantId);
|
|
|
|
await CreditNote.query(trx)
|
|
.findById(creditNoteId)
|
|
.increment('invoicesAmount', invoicesAppliedAmount);
|
|
};
|
|
|
|
/**
|
|
* Decrement credit note invoiced amount.
|
|
* @param {number} tenantId
|
|
* @param {number} creditNoteId
|
|
* @param {number} invoicesAppliedAmount
|
|
*/
|
|
public decrementCreditNoteInvoicedAmount = async (
|
|
tenantId: number,
|
|
creditNoteId: number,
|
|
invoicesAppliedAmount: number,
|
|
trx?: Knex.Transaction
|
|
) => {
|
|
const { CreditNote } = this.tenancy.models(tenantId);
|
|
|
|
await CreditNote.query(trx)
|
|
.findById(creditNoteId)
|
|
.decrement('invoicesAmount', invoicesAppliedAmount);
|
|
};
|
|
}
|