Hey Everyone.
I am trying to perform a mathematical calculation in Business Central, the idea is to run the code automatically every month. I have created a table in General Ledger Setup of interest percentages that will be used to calculate the interest on a payment. I am trying to calculate interest on an amount that will be posted manually by a user. The thing I am struggling with is that how do I retrieve the percentage and # of total days in a year from General Ledger table that I have created meaning what is the command for it. Rough sketch which is not an actual code but more of a pseudocode is shown below,
Table in General Ledger Setup I have created which are editable fields:
Interest Payment = 3%
Total # days year = 365
WHILE
{
Document Type = Invoice;
Posting Date = Date < 20th of the month
DO
{
Document Type = Invoice;
Account Type = G/L Account;
Account No. = Interest Expense;
Description = ‘Interest Invoice’;
Bal. Account Type = Vendor;
Amount = Required Interest Amount;
}
{
Procedure Required Interest Amount (): Decimal
Begin
Interest Calculation Required = Actual Amount * Interest Rate * [(20 Days – Posted Day Actual) + 1 day] / Total # days year;
Return Required Interest Amount;
End;
}