Serial For Breakfast
Posted by Kurt on Wednesday, May 20, 2009 in category:
As I posted mere minutes ago, I’m working on an invoicing system. Part of this blog’s function is to be a regurgitation of things I think about when working of various projects, so here we go.
Being a central database for all our services and all jobs we’ve ever done, it becomes easy to update information regarding our services and have them take effect immediately. It has occurred to me, however, that this could be very bad for invoices we have already submitted and been paid for if, say, we changed the price of plain paper. Those completed invoices would suddenly change. I’ve decided the answer is serialization.
When we submit an invoice to accounting, it changes status to “Submitted” (or it will when the admin section is up and running). At this point, we don’t want the invoices to change any more ever, so we load up an invoice in our Invoice class and call serialize() on it. This makes it a string which we then store in a new field. Upon loading an invoice, the class should check a) the status of the invoice and b) if the serialized field is populated. If the conditions are right, it replaces itself with an unserialize()‘d version of the invoice.
I’m just glad I thought of this before I started coding the admin section. If all goes well, though, nothing should change from the perspective of the parts of the application using the class. It just seems like something that could have easily slipped under the radar and then never gotten fixed because we don’t change our prices often at all and I would be gone the next time we did it.