Skip to main content

Record general loan repayments

Record the repayment of money owed to the lender for a general loan in the SMB's accounting software

Based on the loan's terms and conditions, the borrower will periodically repay the lender the loan amount and any associated fees.

To reflect that programmatically, perform these steps every time a repayment is made:

  1. Create a transfer from the borrower's bank account to the lender's for each repayment.

  2. Create a direct cost to record interest or fees.

  3. Create bank feed transactions to represent the transfer and direct cost in the lender's bank account.

For example, if the borrower took out a loan of £1000 with a loan charge of 20%, the total amount due comes to £1200. With a 3-month equal instalment repayment plan, the borrower pays back £400 each month.

This means you need to create a transfer of £320 to represent the payment, a direct cost of £80 to record the fees, and a bank transaction of £400 to reduce the liability to the lender.

Repay on your terms

Our example demonstrates how to record loan repayments with terms that include monthly payments covering both drawdown and fees. To separate repayments from fee or interest payments, include a transfer from the borrower’s account to the lender’s account that equals the amount of fees or interest. Then, create the associated direct cost to register the fees and/or interest.

To perform these operations, you will need the following properties:

  • Lender's supplier.id and lendersBankAccountId
  • SMB's expenseAccount.id, borrowersBankAccount.id, and currency
  • repaymentDate - the date of the repayment
  • repaymentAmount - the amount repaying the loan amount
  • interestAndFeesAmount - the amount paying for interest and fees
  • totalRepaymentAmount, where totalRepaymentAmount = repaymentAmount + interestAndFeesAmount

Create transfer

Use the Create transfer endpoint again, this time to record the loan repayment amount. Note that you are performing a transfer from borrowersBankAccount.id to lendersBankAccountId.

codatLending.loanWriteback.transfers.create({
accountingTransfer: {
date: repaymentDate,
from: {
accountRef: {
id: borrowersBankAccount.id,
},
amount: repaymentAmount,
currency: borrowersBankAccount.currency,
},
to: {
accountRef: {
id: lendersBankAccountId,
},
amount: repaymentAmount,
currency: borrowersBankAccount.currency,
},
},
companyId: companyId,
connectionId: connectionId,
}).then((res: CreateTransferResponse) => {
if (res.statusCode == 200) {
// handle response
}
});

Create direct cost

Check the Get create direct cost model, then use the Create direct cost endpoint to capture the amount of fees or interest incurred by the borrower.

codatLending.loanWriteback.directCosts.create({
accountingDirectCost: {
contactRef: {
dataType: "suppliers",
id: supplier.id,
},
currency: borrowersBankAccount.currency,
issueDate: repaymentDate,
lineItems: [
{
accountRef: {
id: expenseAccount.id,
},
description: "Fees and/or interest",
quantity: 1,
taxAmount: 0,
unitAmount: interestAndFeesAmount,
},
],
paymentAllocations: [
{
allocation: {
totalAmount: interestAndFeesAmount,
},
payment: {
accountRef: {
id: lendersBankAccountId,
},
},
},
],
taxAmount: 0.0,
totalAmount: interestAndFeesAmount,
},
companyId: companyId,
connectionId: connectionId,
}).then((res: CreateDirectCostResponse) => {
if (res.statusCode == 200) {
// handle response
}
});

Create bank feed transactions

Use the Create bank account transactions endpoint to deposit the total amount (including the repayment, fees, and any interest) into the lender's bank account.

codatLending.loanWriteback.bankTransactions.create({
accountingCreateBankTransactions: {
accountId: lendersBankAccount.id,
transactions: [
{
id: transactionId, // Unique identifier for this bank transaction
amount: totalRepaymentAmount,
date: repaymentDate,
description: description, // Include a reference to the direct cost, the loan and you, the lender
},
],
},
accountId: lendersBankAccountId,
companyId: companyId,
connectionId: connectionId,
}).then((res: CreateBankTransactionsResponse) => {
if (res.statusCode == 200) {
// handle response
}
});

At the end of this 3-stage process, your borrower will have the loan writeback reflected correctly in their accounting software. This saves them time on reconciliation and makes sure they (and you!) have clarity on the state of the loan.

Recap

In this guide, you have learned:

  • What is loan writeback and what it's used for.
  • How to map and configure the loan writeback solution.
  • How to perform the necessary postings using Codat's endpoints.


Was this page useful?
👏
👍
🤔
👎
😭