Various Cargo Improvements (#4435)

Implements #4434
The reason for the order can now be viewed in the cargo control application
Calculate the shuttle fee per order
It is now possible to pay for orders that have been approved by cargo before they are shipped to the station
A mainfest spawns in the crates
Schema Changes:
The supplier, path and amount columns have been retired and are no longer used
Instead the following columns will be used:
supplier - the short name of the supplier that will be used
price - the price for the items
items - the items and their variables

If you are storing the cargo items in the SQL DB, then you dont have to do anything.
They will be migrated automatically to the new format

If you are storing the cargo items in JSON Files then you have to rewrite the files to adhere to the new format.
A example file of the new format is included
This commit is contained in:
Werner
2018-03-31 22:26:23 +02:00
committed by Erki
parent afd00d021a
commit d89798cf7e
13 changed files with 703 additions and 590 deletions

View File

@@ -140,7 +140,7 @@
if(href_list["order_approve"])
var/datum/cargo_order/co = SScargo.get_order_by_id(text2num(href_list["order_approve"]))
if(co)
var/message = SScargo.approve_order(co,last_user_name)
var/message = co.set_approved(last_user_name)
if(message)
status_message = message
return 1
@@ -149,7 +149,7 @@
if(href_list["order_reject"])
var/datum/cargo_order/co = SScargo.get_order_by_id(text2num(href_list["order_reject"]))
if(co)
var/message = SScargo.reject_order(co)
var/message = co.set_rejected()
if(message)
status_message = message
return 1

View File

@@ -38,10 +38,7 @@
last_user_name = data["id_owner"]
//Pass the shipped orders
var/list/shipped_orders = SScargo.get_orders_by_status("shipped",1)
data["order_shipped_list"] = shipped_orders
data["order_shipped_number"] = shipped_orders.len
data["order_shipped_value"] = SScargo.get_orders_value_by_status("shipped",1)
data["order_list"] = SScargo.get_orders_by_status("shipped",1) + SScargo.get_orders_by_status("approved",1)
//Pass along the order details
data["order_details"] = order_details
@@ -65,75 +62,94 @@
if(..())
return 1
//Everyone can pay
if(href_list["pay"])
if(order_details["payment_status"] == 1)
status_message = "Unable to Pay - Order has already been paid."
//Check if we want to deliver or pay
//If we are at the status shipped, then only the confirm delivery and pay button should be shown (deliver)
//If the status is not shipped, then only show the pay button as we can not confirm that it has been paid so far
//Everyone can pay / confirm delivery
if(href_list["deliver"])
order_details = co.get_list()
//Check if its already delivered
if(order_details["status"] == "delivered" && !order_details["needs_payment"])
status_message = "Unable to Deliver - Order has already been delivered and paid for."
return 1
if(program && program.computer && program.computer.card_slot && program.computer.network_card)
var/transaction_amount = order_details["price_customer"];
var/transaction_purpose = "Cargo Order #[order_details["order_id"]]";
var/obj/item/weapon/card/id/id_card = program.computer.card_slot.stored_card
if(!id_card || !id_card.registered_name)
status_message = "Card Error: Invalid ID Card in Card Reader"
return 1
var/datum/money_account/D = get_account(id_card.associated_account_number)
var/attempt_pin
if(D.security_level)
attempt_pin = input("Enter pin code", "EFTPOS transaction") as num
D = null
D = attempt_account_access(id_card.associated_account_number, attempt_pin, 2)
if(D)
if(!D.suspended)
if(transaction_amount <= D.money)
playsound(program.computer, 'sound/machines/chime.ogg', 50, 1)
//Check if a payment is required
if(order_details["needs_payment"])
var/transaction_amount = order_details["price_customer"];
var/transaction_purpose = "Cargo Order #[order_details["order_id"]]";
var/datum/money_account/D = get_account(id_card.associated_account_number)
if(!D)
status_message = "Unable to access account. Check security settings and try again."
return 1
var/attempt_pin
if(D.security_level)
attempt_pin = input("Enter pin code", "EFTPOS transaction") as num
D = null
D = attempt_account_access(id_card.associated_account_number, attempt_pin, 2)
if(D)
if(!D.suspended)
if(transaction_amount <= D.money)
playsound(program.computer, 'sound/machines/chime.ogg', 50, 1)
//transfer the money
D.money -= transaction_amount
SScargo.supply_account.money += transaction_amount
//transfer the money
D.money -= transaction_amount
SScargo.supply_account.money += transaction_amount
//create entries in the two account transaction logs
var/datum/transaction/T = new()
T.target_name = "[SScargo.supply_account.owner_name]"
T.purpose = transaction_purpose
if(transaction_amount > 0)
T.amount = "([transaction_amount])"
else
//create entries in the two account transaction logs
var/datum/transaction/T = new()
T.target_name = "[SScargo.supply_account.owner_name]"
T.purpose = transaction_purpose
if(transaction_amount > 0)
T.amount = "([transaction_amount])"
else
T.amount = "[transaction_amount]"
T.source_terminal = "Modular Computer #[program.computer.network_card.identification_id]"
T.date = current_date_string
T.time = worldtime2text()
D.transaction_log.Add(T)
//
T = new()
T.target_name = D.owner_name
T.purpose = transaction_purpose
T.amount = "[transaction_amount]"
T.source_terminal = "Modular Computer #[program.computer.network_card.identification_id]"
T.date = current_date_string
T.time = worldtime2text()
D.transaction_log.Add(T)
//
T = new()
T.target_name = D.owner_name
T.purpose = transaction_purpose
T.amount = "[transaction_amount]"
T.source_terminal = "Modular Computer #[program.computer.network_card.identification_id]"
T.date = current_date_string
T.time = worldtime2text()
SScargo.supply_account.transaction_log.Add(T)
T.source_terminal = "Modular Computer #[program.computer.network_card.identification_id]"
T.date = current_date_string
T.time = worldtime2text()
SScargo.supply_account.transaction_log.Add(T)
//Get the cargo order and update its status to delivered and paid
status_message = SScargo.deliver_order(co,id_card.registered_name)
order_details = co.get_list()
return 1
//Check if we have delivered it aswell or only paid
if(order_details["status"] == "shipped")
status_message = co.set_delivered(id_card.registered_name,1)
else
status_message = co.set_paid(id_card.registered_name)
order_details = co.get_list()
return 1
else
status_message = "You don't have that much money!"
return 1
else
status_message = "You don't have that much money!"
status_message = "Your account has been suspended."
return 1
else
status_message = "Your account has been suspended."
status_message = "Unable to access account. Check security settings and try again."
return 1
else
status_message = "Unable to access account. Check security settings and try again."
return 1
//TODO: Add a sound effect here
//If a payment is not needed and we are at the status shipped, then confirm the delivery
if(order_details["status"] == "shipped")
status_message = co.set_delivered(id_card.registered_name,0)
order_details = co.get_list()
else
status_message = "Unable to pay - Network Card or Cardreader Missing"
status_message = "Unable to process - Network Card or Cardreader Missing"
return 1
@@ -147,6 +163,7 @@
return
if(href_list["page"])
status_message = null //Null the previous status, so its not confusing
switch(href_list["page"])
if("overview_main")
page = "overview_main" //Main overview page that shows all the orders with the status shipped

View File

@@ -41,7 +41,6 @@
data["order_items"] = co.get_item_list()
data["order_value"] = co.get_value(0)
data["order_item_count"] = co.get_item_count()
data["order_shuttle_fee"] = co.get_max_shipment_cost()
//Pass Data for Main page
if(page == "main")
@@ -53,10 +52,10 @@
data["category_items"] = SScargo.get_items_for_category(selected_category)
//Pass Data for Item Details Page
else if(page == "item_details")
var/datum/cargo_item/ci = SScargo.cargo_items[selected_item]
if(ci)
data["item_details"] = ci.get_list()
//else if(page == "item_details")
// var/datum/cargo_item/ci = SScargo.cargo_items[selected_item]
// if(ci)
// data["item_details"] = ci.get_list()
else if (page == "tracking")
data["tracking_id"] = user_tracking_id
@@ -72,7 +71,7 @@
if(co.tracking_code == user_tracking_code)
data["tracking_status"] = "Success"
data["tracked_order"] = co.get_list()
data["tracked_order_report"] = co.get_report()
data["tracked_order_report"] = co.get_report_invoice()
else
data["tracking_status"] = "Invalid Tracking Code"
else
@@ -113,9 +112,9 @@
status_message = "Unable to submit order. No reason supplied."
return 1
co.customer = last_user_name
co.ordered_by = last_user_name
co.reason = reason
SScargo.submit_order(co)
co.set_submitted()
status_message = "Order submitted successfully. Order ID: [co.order_id] Tracking code: [co.get_tracking_code()]"
//TODO: Print a list with the order data
co = null
@@ -124,22 +123,19 @@
//Add item to the order list
if(href_list["add_item"])
var/datum/cargo_order_item/coi = new
coi.ci = SScargo.cargo_items[href_list["add_item"]]
coi.supplier = href_list["supplier"]
//Check if the selected supplier exists for the item and get the price for the supplier
var/supplier_details = coi.ci.suppliers[coi.supplier]
if(supplier_details)
coi.cs = SScargo.get_supplier_by_name(coi.supplier)
var/datum/cargo_item/ci = SScargo.cargo_items[href_list["add_item"]]
if(ci)
coi.ci = ci
coi.calculate_price()
if(coi.price > 0)
status_message = co.add_item(coi)
else
status_message = "Unable to add item [coi.ci.name] - Internal Error 602."
log_debug("Cargo Order: Warning - Attempted to order item [coi.ci.name] from supplier [href_list["supplier"]] with invalid purchase price")
status_message = "Unable to add item [text2num(href_list["add_item"])] - Internal Error 601."
log_debug("Cargo Order: Warning - Attempted to order item [coi.ci.name] with invalid purchase price")
qdel(coi)
else
status_message = "Unable to add item [coi.ci.name] - Internal Error 605."
log_debug("Cargo Order: Warning - Attempted to order item [coi.ci.name] from non existant supplier [href_list["supplier"]]")
status_message = "Unable to locate item in sales database - Internal Error 602."
log_debug("Cargo Order: Warning - Attempted to order item with non-existant id: [href_list["add_item"]]")
qdel(coi)
//Reset page to main page - TODO: Maybe add a way to disable jumping back to the main page - Commented out for now