Finance Management App

The client wanted an easy way to divide the day's takings between all outstanding debts and the companies own profits.
I worked with them to establish an initial ratio of 1:2 for company profits vs company debts.
The parameters of the solution were the following:


Originally I had intended to use a webhook to keep a running total of the days takings and then use a scheduled rake task to calculate and deliver the data, however the client expressed that they would prefer another approach as they didn't want their incomings documented anywhere external. Given the size of the store, where a normal API call would work, I instead had to set up a series of API calls inside the rake task that would total the incomings inside an instance variable before performing it's primary function.
The client was concerned about future proofing the application as they had seen a huge growth in recent times and didn't want to risk running out of resources. The Shopify REST API call limits operate on a leaky bucket principle, with a bucket size of 40 dropping by 2 per second. I upped the returned results to 250 and this in turn gave me the option to pull an initial 9750 orders plus an additional 500 orders per second, which was easily enough.
I protected the interface of the app by creating a superuser role with a password stored as an MD5 hash inside an environment variable, this prevented any unauthorized staff members from accessing data they weren't supposed to.
I added a slider for the profit:debt ratio which updated the figures on input, however it was also possible to save the current configuration as the primary calculation for the rake task.
Inside the interface, I also added a form to add a new debt which took creditor, amount and due date parameters.
A rake task was scheduled for 8:45AM every day. It took the previous 24 hours takings and adjusted the figure for selling fees. It then calculated the 'days til due' for all outstanding debts and normalized the figure to between 1 and 2 to create a pseudo priority system. I then simply had to create a ratio for outstanding amounts and with all the data together calculate a recommended payment to each creditor as well as a profit total for this 24 hour period.
Finally, I made use of the Twilio Programmable SMS API to automatically deliver the results to the client's mobile phone just as they arrived for work in the morning.