Skip to content

Instantly share code, notes, and snippets.

@adejorosam
Last active August 6, 2023 20:24
Show Gist options
  • Save adejorosam/987f69d6fc67328e2926e4da895937fc to your computer and use it in GitHub Desktop.
Save adejorosam/987f69d6fc67328e2926e4da895937fc to your computer and use it in GitHub Desktop.
// input
Loan amount = 3,000,000 Interest rate per annum = 17%
$jsonData = '{
"data": [
{
"ValueDate": "7/1/2023",
"Description": "Opening Balance",
"Debit": "",
"Credit": "",
"Balance": "-1233291.17"
},
{
"ValueDate": "7/3/2023",
"Description": "{Batch#: 14395} BEING MARGIN INTEREST FOR JUNE 23",
"Debit": "-15,042.21",
"Credit": "",
"Balance": "-1248333.38"
},
{
"ValueDate": "7/4/2023",
"Description": "Stock Sale: 1,000 DANGSUGAR @NGN25.10 for A/C 5500",
"Debit": "",
"Credit": "24,846.27",
"Balance": "1223487.11"
},
{
"ValueDate": "7/5/2023",
"Description": "Being payment for STOCKBROKING (NG) from NWANEKEZI MARYANN UGOCHIs wallet",
"Debit": "200,000.00",
"Credit": "",
"Balance": "-1023487.11"
},
{
"ValueDate": "7/4/2023",
"Description": "Stock Purchase: 5,000 FIDELITYBK @NGN7.69 for A/C 5500",
"Debit": "-38,703.74",
"Credit": "",
"Balance": "-1062190.85"
},
{
"ValueDate": "7/5/2023",
"Description": "Stock Purchase: 3,000 UBA @NGN12.80 for A/C 5500",
"Debit": "-38,653.42",
"Credit": "",
"Balance": "1100844.27"
},
{
"ValueDate": "7/5/2023",
"Description": "Stock Purchase: 56,000 JAPAULGOLD @NGN0.92 for A/C 5500",
"Debit": "-51,858.54",
"Credit": "",
"Balance": "-1152702.81"
},
{
"ValueDate": "7/5/2023",
"Description": "Stock Purchase: 74,000 JAPAULGOLD @NGN0.92 for A/C 5500",
"Debit": "-68,525.97",
"Credit": "",
"Balance": "-1221228.78"
},
{
"ValueDate": "7/10/2023",
"Description": "Stock Sale: 500 DANGCEM @NGN285.00 for A/C 5500",
"Debit": "",
"Credit": "141,079.61",
"Balance": "-1080149.17"
},
{
"ValueDate": "7/6/2023",
"Description": "Stock Purchase: 100,000 RTBRISCOE @NGN0.81 for A/C 5500",
"Debit": "-81,529.79",
"Credit": "",
"Balance": "-1161678.96"
},
{
"ValueDate": "7/6/2023",
"Description": "Stock Purchase: 15,240 JAPAULGOLD @NGN1.00 for A/C 5500",
"Debit": "-15,343.17",
"Credit": "",
"Balance": "-1177022.13"
},
{
"ValueDate": "7/6/2023",
"Description": "Stock Purchase: 50,000 RTBRISCOE @NGN0.71 for A/C 5500",
"Debit": "-35,734.61",
"Credit": "",
"Balance": "-1212756.74"
},
{
"ValueDate": "7/7/2023",
"Description": "Stock Purchase: 1,500 DANGSUGAR @NGN27.80 for A/C 5500",
"Debit": "-41,974.83",
"Credit": "",
"Balance": "-1254731.57"
},
{
"ValueDate": "7/7/2023",
"Description": "Stock Purchase: 67 JAPAULGOLD @NGN1.11 for A/C 5500",
"Debit": "-79.15",
"Credit": "",
"Balance": "-1254810.72"
},
{
"ValueDate": "7/12/2023",
"Description": "Stock Purchase: 30,000 JAPAULGOLD @NGN1.47 for A/C 5500",
"Debit": "-44,390.40",
"Credit": "",
"Balance": "-1299201.12"
}
]
}';
//our output
[
{
"ValueDate": "7/1/2023",
"Description": "Opening Balance",
"Debit": "",
"Credit": "",
"Balance": "-1233291.17",
"NewValueDate": "2023-07-01",
"DayDifference": "",
"MarginInterest": "0",
"Overdraft": "0",
"MarginPlusOverdraft": "0"
},
{
"ValueDate": "7/3/2023",
"Description": "{Batch#: 14395} BEING MARGIN INTEREST FOR JUNE 23",
"Debit": "-15,042.21",
"Credit": "",
"Balance": "-1248333.38",
"NewValueDate": "2023-07-03",
"DayDifference": "2",
"MarginInterest": "1162.830739726",
"Overdraft": "0",
"MarginPlusOverdraft": "1162.830739726"
},
{
"ValueDate": "7/4/2023",
"Description": "Stock Sale: 1,000 DANGSUGAR @NGN25.10 for A/C 5500",
"Debit": "",
"Credit": "24,846.27",
"Balance": "1223487.11",
"NewValueDate": "2023-07-04",
"DayDifference": "1",
"MarginInterest": "0",
"Overdraft": "0",
"MarginPlusOverdraft": "0"
},
{
"ValueDate": "7/5/2023",
"Description": "Being payment for STOCKBROKING (NG) from NWANEKEZI MARYANN UGOCHIs wallet",
"Debit": "200,000.00",
"Credit": "",
"Balance": "-1023487.11",
"NewValueDate": "2023-07-05",
"DayDifference": "1",
"MarginInterest": "476.69257534247",
"Overdraft": "0",
"MarginPlusOverdraft": "476.69257534247"
},
{
"ValueDate": "7/4/2023",
"Description": "Stock Purchase: 5,000 FIDELITYBK @NGN7.69 for A/C 5500",
"Debit": "-38,703.74",
"Credit": "",
"Balance": "-1062190.85",
"NewValueDate": "2023-07-07",
"DayDifference": "2",
"MarginInterest": "989.43726027397",
"Overdraft": "0",
"MarginPlusOverdraft": "989.43726027397"
},
{
"ValueDate": "7/5/2023",
"Description": "Stock Purchase: 3,000 UBA @NGN12.80 for A/C 5500",
"Debit": "-38,653.42",
"Credit": "",
"Balance": "1100844.27",
"NewValueDate": "2023-07-10",
"DayDifference": "",
"MarginInterest": "",
"Overdraft": "",
"MarginPlusOverdraft": ""
},
{
"ValueDate": "7/5/2023",
"Description": "Stock Purchase: 56,000 JAPAULGOLD @NGN0.92 for A/C 5500",
"Debit": "-51,858.54",
"Credit": "",
"Balance": "-1152702.81",
"NewValueDate": "2023-07-10",
"DayDifference": "",
"MarginInterest": "",
"Overdraft": "",
"MarginPlusOverdraft": ""
},
{
"ValueDate": "7/5/2023",
"Description": "Stock Purchase: 74,000 JAPAULGOLD @NGN0.92 for A/C 5500",
"Debit": "-68,525.97",
"Credit": "",
"Balance": "-1221228.78",
"NewValueDate": "2023-07-10",
"DayDifference": "",
"MarginInterest": "",
"Overdraft": "",
"MarginPlusOverdraft": ""
},
{
"ValueDate": "7/10/2023",
"Description": "Stock Sale: 500 DANGCEM @NGN285.00 for A/C 5500",
"Debit": "",
"Credit": "141,079.61",
"Balance": "-1080149.17",
"NewValueDate": "2023-07-10",
"DayDifference": "3",
"MarginInterest": "1509.2492876712",
"Overdraft": "0",
"MarginPlusOverdraft": "1509.2492876712"
},
{
"ValueDate": "7/6/2023",
"Description": "Stock Purchase: 100,000 RTBRISCOE @NGN0.81 for A/C 5500",
"Debit": "-81,529.79",
"Credit": "",
"Balance": "-1161678.96",
"NewValueDate": "2023-07-11",
"DayDifference": "",
"MarginInterest": "",
"Overdraft": "",
"MarginPlusOverdraft": ""
},
{
"ValueDate": "7/6/2023",
"Description": "Stock Purchase: 15,240 JAPAULGOLD @NGN1.00 for A/C 5500",
"Debit": "-15,343.17",
"Credit": "",
"Balance": "-1177022.13",
"NewValueDate": "2023-07-11",
"DayDifference": "",
"MarginInterest": "",
"Overdraft": "",
"MarginPlusOverdraft": ""
},
{
"ValueDate": "7/6/2023",
"Description": "Stock Purchase: 50,000 RTBRISCOE @NGN0.71 for A/C 5500",
"Debit": "-35,734.61",
"Credit": "",
"Balance": "-1212756.74",
"NewValueDate": "2023-07-11",
"DayDifference": "1",
"MarginInterest": "564.84526027397",
"Overdraft": "0",
"MarginPlusOverdraft": "564.84526027397"
},
{
"ValueDate": "7/7/2023",
"Description": "Stock Purchase: 1,500 DANGSUGAR @NGN27.80 for A/C 5500",
"Debit": "-41,974.83",
"Credit": "",
"Balance": "-1254731.57",
"NewValueDate": "2023-07-12",
"DayDifference": "",
"MarginInterest": "",
"Overdraft": "",
"MarginPlusOverdraft": ""
},
{
"ValueDate": "7/7/2023",
"Description": "Stock Purchase: 67 JAPAULGOLD @NGN1.11 for A/C 5500",
"Debit": "-79.15",
"Credit": "",
"Balance": "-1254810.72",
"NewValueDate": "2023-07-12",
"DayDifference": "1",
"MarginInterest": "584.43205479452",
"Overdraft": "0",
"MarginPlusOverdraft": "584.43205479452"
},
{
"ValueDate": "7/12/2023",
"Description": "Stock Purchase: 30,000 JAPAULGOLD @NGN1.47 for A/C 5500",
"Debit": "-44,390.40",
"Credit": "",
"Balance": "-1299201.12",
"NewValueDate": "2023-07-17",
"DayDifference": "5",
"MarginInterest": "3025.5365753425",
"Overdraft": "0",
"MarginPlusOverdraft": "3025.5365753425"
},
{
"Total-DayDifference": 16,
"Total-MarginInterest": 8309,
"Total-Overdraft": 0
}
]
//expected output
[
{
"ValueDate": "01-Jul-2023",
"GL Description": "Opening Balance",
"Debit": "",
"Credit": "",
"Balance": "(1,233,291.17)",
"Original Value date": "01-Jul-2023",
"Day end Balance": "(1,233,291.17)",
"Day": "2.00",
"Interest": "(1,148.82)",
"Overdraft Charge": "-"
},
{
"ValueDate": "03-Jul-2023",
"GL Description": "{Batch#: 14395} BEING MARGIN INTEREST FOR JUNE '23",
"Debit": "-15,042.21",
"Credit": "",
"Balance": "(1,248,333.38)",
"Original Value date": "03-Jul-2023",
"Day end Balance": "(1,248,333.38)",
"Day": "1.00",
"Interest": "(581.42)",
"Overdraft Charge": "-"
},
{
"ValueDate": "04-Jul-2023",
"GL Description": "Stock Sale: 1,000 DANGSUGAR @NGN25.10 for A/C 5500",
"Debit": "",
"Credit": "24,846.27",
"Balance": "(1,223,487.11)",
"Original Value date": "04-Jul-2023",
"Day end Balance": "(1,223,487.11)",
"Day": "1.00",
"Interest": "(569.84)",
"Overdraft Charge": "-"
},
{
"ValueDate": "05-Jul-2023",
"GL Description": "Being payment for STOCKBROKING (NG) from NWANEKEZI MARYANN UGOCHI's wallet",
"Debit": "200,000.00",
"Credit": "",
"Balance": "(1,023,487.11)",
"Original Value date": "05-Jul-2023",
"Day end Balance": "(1,023,487.11)",
"Day": "2.00",
"Interest": "(953.39)",
"Overdraft Charge": "-"
},
{
"ValueDate": "04-Jul-2023",
"GL Description": "Stock Purchase: 5,000 FIDELITYBK @NGN7.69 for A/C 5500",
"Debit": "-38,703.74",
"Credit": "",
"Balance": "(1,062,190.85)",
"Original Value date": "07-Jul-2023",
"Day end Balance": "(1,062,190.85)",
"Day": "3.00",
"Interest": "(1,484.16)",
"Overdraft Charge": "-"
},
{
"ValueDate": "05-Jul-2023",
"GL Description": "Stock Purchase: 3,000 UBA @NGN12.80 for A/C 5500",
"Debit": "-38,653.42",
"Credit": "",
"Balance": "(1,100,844.27)",
"Original Value date": "10-Jul-2023",
"Day end Balance": "(1,100,844.27)",
"Interest": "-",
"Overdraft Charge": "-"
},
{
"ValueDate": "05-Jul-2023",
"GL Description": "Stock Purchase: 56,000 JAPAULGOLD @NGN0.92 for A/C 5500",
"Debit": "-51,858.54",
"Credit": "",
"Balance": "(1,152,702.81)",
"Original Value date": "10-Jul-2023",
"Day end Balance": "(1,152,702.81)",
"Interest": "-",
"Overdraft Charge": "-"
},
{
"ValueDate": "05-Jul-2023",
"GL Description": "Stock Purchase: 74,000 JAPAULGOLD @NGN0.92 for A/C 5500",
"Debit": "-68,525.97",
"Credit": "",
"Balance": "(1,221,228.78)",
"Original Value date": "10-Jul-2023",
"Day end Balance": "(1,221,228.78)",
"Interest": "-",
"Overdraft Charge": "-"
},
{
"ValueDate": "10-Jul-2023",
"GL Description": "Stock Sale: 500 DANGCEM @NGN285.00 for A/C 5500",
"Debit": "",
"Credit": "141,079.61",
"Balance": "(1,080,149.17)",
"Original Value date": "10-Jul-2023",
"Day end Balance": "(1,080,149.17)",
"Day": "1.00",
"Interest": "(503.08)",
"Overdraft Charge": "-"
},
{
"ValueDate": "06-Jul-2023",
"GL Description": "Stock Purchase: 100,000 RTBRISCOE @NGN0.81 for A/C 5500",
"Debit": "-81,529.79",
"Credit": "",
"Balance": "(1,161,678.96)",
"Original Value date": "11-Jul-2023",
"Day end Balance": "(1,161,678.96)",
"Interest": "-",
"Overdraft Charge": "-"
},
{
"ValueDate": "06-Jul-2023",
"GL Description": "Stock Purchase: 15,240 JAPAULGOLD @NGN1.00 for A/C 5500",
"Debit": "-15,343.17",
"Credit": "",
"Balance": "(1,177,022.13)",
"Original Value date": "11-Jul-2023",
"Day end Balance": "(1,177,022.13)",
"Interest": "-",
"Overdraft Charge": "-"
},
{
"ValueDate": "06-Jul-2023",
"GL Description": "Stock Purchase: 50,000 RTBRISCOE @NGN0.71 for A/C 5500",
"Debit": "-35,734.61",
"Credit": "",
"Balance": "(1,212,756.74)",
"Original Value date": "11-Jul-2023",
"Day end Balance": "(1,212,756.74)",
"Day": "1.00",
"Interest": "(564.85)",
"Overdraft Charge": "-"
},
{
"ValueDate": "07-Jul-2023",
"GL Description": "Stock Purchase: 1,500 DANGSUGAR @NGN27.80 for A/C 5500",
"Debit": "-41,974.83",
"Credit": "",
"Balance": "(1,254,731.57)",
"Original Value date": "12-Jul-2023",
"Day end Balance": "(1,254,731.57)",
"Interest": "-",
"Overdraft Charge": "-"
},
{
"ValueDate": "07-Jul-2023",
"GL Description": "Stock Purchase: 67 JAPAULGOLD @NGN1.11 for A/C 5500",
"Debit": "-79.15",
"Credit": "",
"Balance": "(1,254,810.72)",
"Original Value date": "12-Jul-2023",
"Day end Balance": "(1,254,810.72)",
"Day": "5.00",
"Interest": "(2,922.16)",
"Overdraft Charge": "-"
},
{
"ValueDate": "12-Jul-2023",
"GL Description": "Stock Purchase: 30,000 JAPAULGOLD @NGN1.47 for A/C 5500",
"Debit": "-44,390.40",
"Credit": "",
"Balance": "(1,299,201.12)",
"Original Value date": "17-Jul-2023",
"Day end Balance": "(1,299,201.12)",
"Day": "15.00",
"Interest": "(9,076.61)",
"Overdraft Charge": "-"
}
]
// total interest => (17,804.32)
// total day difference = 31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment