Posted on March 31, 2023 @ 09:12:00 PM by Paul Meagher
I am currently working on book keeping for our farm business so me and my wife can file our 2022 income tax. The farm generates a large number of expenses for the different enterprises we operate on the farm (e.g., concerts, camping, bike rentals, weddings, airbnb, haymaking, winemaking) so it is non-trivial to do the bookkeeping for all the farm expenses. This year I decided to improve my bookkeeping approach by creating a web application called "Tracker" which will be used to store all farm-related expenses. I want the Tracker program to be able to read and write text files where each line of the text file records an expense. The expenses text file has fixed width fields so that the Tracker program can parse through each line and know what parts of the line are used to record different aspects of the expense (e.g., date, cost, tax, description, category, seller). This will allow me to finesse some banking records, for example, into a structured text file that my tracker program can read and insert into a database. Likewise, the Tracker program can output the contents of the FarmTracker database into a expenses output file with the same format as expenses input file (so that the output file can be modified in a text editor and read back into the database). I want to be able to do my bookkeeping by manipulating text files OR with on online program that will allow me to list, add, edit and delete the same expense records using a web interface.
The reason for wanting to move between both ways of working with expense records is because I have done my farm bookkeeping in the past using text files and found that I can often work with them faster than I can work with data entry forms. My wife, however, is not likely to want to work with text files so I thought creating a web application interface to the farm expense data using a database to also store the expense data might allow us to both work on the books for our farm using our preferred approaches.
You are probably thinking that there are lots of accounting and bookkeeping applications already out there so why re-invent the wheel? I have used online bookkeeping/accounting programs and personally found inputting data to be a bit more cumbersome compared to working with raw text files. I use a powerful text editor, Ultraedit, so I can slice and dice text files with it fairly well and when costs and taxes, for example, occupy fixed positions in each text record, I can easily select those columns of numbers to compute total costs and total taxes for any given category of expense. I think, however, that I can do more by creating a web application interface to these text files that also stores the data in a database that will allow me to do reports on the data more easily than on text files. I expect this to be a program that I continue to develop over time but I do need something that works well enough that I can start working on my bookkeeping with it by next week.
I'm aware that ChatGPT is all the rage these days and thought I would try using it to help me develop my book keeping software. ChatGPT generally doesn't exactly solve the problem I ask it to solve but it gets me in the ball park and with some customization I can get it working in the context of my program. I thought I would share with you a couple of questions I asked ChatGPT and the answers it gave me so that you can see how useful a coding partner ChatGPT can be.
So one question I asked ChatGPT was:
Show me php code that outputs fixed 3 right justified fixed-width fields with the first column being 5 characters, second column being 10 characters, third column being 10 characters.
The answer it gave me was:
$firstColumn = "12345";
$secondColumn = "1234567890";
$thirdColumn = "0987654321";
// Pad the columns to their fixed-widths
$firstColumn = str_pad($firstColumn, 5, " ", STR_PAD_LEFT);
$secondColumn = str_pad($secondColumn, 10, " ", STR_PAD_LEFT);
$thirdColumn = str_pad($thirdColumn, 10, " ", STR_PAD_LEFT);
// Output the columns with fixed widths and right-justified
echo sprintf("%5s%10s%10s", $firstColumn, $secondColumn, $thirdColumn);
This snippet helped set me on a path to figuring out how I might output the database records in a way that matched the format of each expense line in my expenses text file. It isn't a customized solution that I can just pop into my program (variable names are generic, for example) but it refreshes my memory on how to approach fixed width outputting of
data into text files.
As I continued working on the software, I wanted to optimize how easy it might be to input an expense record. I'm a bit rusty on my javascript so I asked ChatGPT this question:
Javascript code to populate a cost input field and a tax input field from a price input field
The answer it gave me was:
// Assuming the cost, tax and price input fields have the following IDs:
var costInput = document.getElementById('cost');
var taxInput = document.getElementById('tax');
var priceInput = document.getElementById('price');
// Event listener to calculate and populate cost and tax when the price input field changes:
priceInput.addEventListener('input', calculateAndPopulateCostAndTax);
function calculateAndPopulateCostAndTax() {
var price = parseFloat(priceInput.value);
if (isNaN(price)) {
costInput.value = ''; // clear the cost field if price is not a valid number
taxInput.value = ''; // clear the tax field if price is not a valid number
} else {
var tax = ((price / 1.00) - (price / 1.08)).toFixed(2); // Assuming the tax rate is 8%
var cost = (price - tax).toFixed(2);
costInput.value = cost; // set the cost field with the calculated value
taxInput.value = tax; // set the tax field with the calculated value
}
}
As you can see, ChatGPT is a pretty good helper when it comes to developing web applications and I expect to have it open in my browser as I'm coding in the future.
Scott Willison had an interesting blog entitled AI-enhanced development makes me more ambitious with my projects. His examples of ChatGPT supported development are more advanced than mine, but the same conclusions he draws apply:
As an experienced developer, ChatGPT (and GitHub Copilot) save me an enormous amount of “figuring things out” time. For everything from writing a for loop in Bash to remembering how to make a cross-domain CORS request in JavaScript—I don’t need to even look things up any more, I can just prompt it and get the right answer 80% of the time.
This doesn’t just make me more productive: it lowers my bar for when a project is worth investing time in at all.
In the past I’ve had plenty of ideas for projects which I’ve ruled out because they would take a day—or days—of work to get to a point where they’re useful. I have enough other stuff to build already!
But if ChatGPT can drop that down to an hour or less, those projects can suddenly become viable.
Which means I’m building all sorts of weird and interesting little things that previously I wouldn’t have invested the time in.
Likewise, I probably would have been more reluctant to work on my Tracker program if I didn't get some good feedback from ChatGPT about how to approach certain parts of the program that might have taken me more time to figure out. ChatGPT is a game changer for programming and for many other domains as well. ChatGPT is helping me develop some personal bookkeeping software but it might be worth pondering whether ChatGPT can help with aspects of actual bookkeeping as well. I haven't gotten that far but I suspect I could start googling ChatGPT and Accounting/Bookkeeping to find some interesting applications.
|