Open RyanLaForge opened 9 years ago
I got this shit yo
Initial pseudocode:
buy_item(item, recipient, purchasedate, cost)
if(item is null or recipient is null or purchase_date is null or cost is null)
raise exception("Can't buy an item with null info)
if(item doesn't exist or recipient doesn't exist)
raise exception("Can't sell an item if the item/recipient doesn't exist")
if(recipient doesn't equal one of us)
raise exception("Can't buy an item on behalf of someone who isn't us")
if(recipient = current item owner)
raise exception("Can't buy an item from yourself")
if(purchasedate < now)
raise exception("Can't buy an item in the past")
if(purchasedate is at midnight)
raise warning("Are you sure you specified a date and time?")
write transaction:
item = item, recipient = recipient, proprietor = current_owner, startDate = purchasedate, gross = value, type = purchase
write item:
owner = recipient
write location:
location = storage, startdate = purchasedate, enddate = null
write item:
owner = client
This ones a little more complex. What happens when we're buying an item that we already have on loan, and as such is already in a location?
I'm going to need to add some logic where if the item is currently in a location then do nothing, else put it in storage.
Erm, I wrote this one out and added the function, but then when I ran a \df it showed an add_purchase in there already? Was someone already working on this?
update items table, including inserting if you have to. NOTE:: The buyer must be one of our museums. Inserting may be quite complex, so it should be acceptable to assume they have already inserted the item and its client, or maybe we can use nested transactions? update item transactions table(there may be a trigger to perform the insert to item locations).