//NOTE: Cargo orders, categories and suppliers have been moved to singletons (10/11/2024). /datum/cargo_order var/list/items = list() //List of cargo_items in the order var/order_id = 0 //ID of the order var/price = 0 //Total price of the order var/item_id = 1 //Current id of the item in the order var/item_num = 0 //Number of items in the container - Used to limit the items in the crate var/status = "basket" //Status of the order: basket - Adding items, submitted - Submitted to cargo, approved - Order sent to suppliers, rejected - Order has been denied, shipped - Has been shipped to the station, delivered - Order has been delivered var/container_type = "" //Type of the container for the order - cate, box var/list/required_access = list() //Access required to unlock the crate var/can_add_items = 1 //If new items can be added to the order var/ordered_by = null //Person that ordered the items var/ordered_by_id = null //Character ID of the person that ordered the items var/authorized_by = null //Person that authorized the order var/authorized_by_id = null //Character ID of the person that authorized the items var/received_by = null //Person the order has been delivered to by cargo var/received_by_id = null //Character ID of the person that received the items var/paid_by = null //Person that has paid for the order var/paid_by_id = null //Character ID of the Person that paid for the items var/paying_account = null var/time_submitted = null //Time the order has been sent to cargo var/time_approved = null //Time the order has been approved by cargo var/time_shipped = null //Time the order has been shipped to the station var/time_delivered = null //Time the order has been delivered var/time_paid = null //The the order has been paid var/tracking_code = null //Use this code with the order ID to get details about the order var/reason = null //Reason for the order //Gets the tracking code for the order. Generates one if it does not exist already /datum/cargo_order/proc/get_tracking_code() if(!tracking_code) tracking_code = rand(1000,9999) return tracking_code // Returns a list of the items in the order - Formatted as list to be json_encoded /datum/cargo_order/proc/get_item_list() var/list/item_list = list() for (var/datum/cargo_order_item/coi in items) item_list.Add(list(coi.get_list())) return item_list // Returns a list of all the objects in the order - Formatted as a list to be json_encoded /datum/cargo_order/proc/get_object_list() var/list/object_list = list() for(var/item in get_item_list()) object_list.Add(item["name"]) return object_list // Gets a list of the order data - Formatted as list to be json_encoded /datum/cargo_order/proc/get_list() var/list/data = list() data["order_id"] = order_id data["tracking_code"] = get_tracking_code() data["price"] = get_value(2) data["price_customer"] = get_value(0) data["price_cargo"] = get_value(1) data["status"] = get_order_status(0) data["status_pretty"] = get_order_status(1) data["status_payment"] = get_payment_status(1) data["ordered_by"] = ordered_by data["authorized_by"] = authorized_by data["received_by"] = received_by data["paid_by"] = paid_by data["needs_payment"] = paid_by != null ? 0:1 data["time_submitted"] = time_submitted data["time_approved"] = time_approved data["time_shipped"] = time_shipped data["time_delivered"] = time_delivered data["time_paid"] = time_paid data["items"] = get_item_list() data["shipment_cost"] = get_shipment_cost() data["reason"] = reason return data //Adds a item to a order. Returns a status message /datum/cargo_order/proc/add_item(var/datum/cargo_order_item/coi) if(!coi) return "Unable to add item - Internal Error" //Check if the container type of the added item matches the one of the current order if(container_type == "") container_type = coi.ci.container_type else if (container_type != coi.ci.container_type) return "Unable to add item - Different container required" //You can only add items with the same container type to the order //Check if more items can be added to the order if(!can_add_items) return "Unable to add item - Order can not contain more items" if(!coi.ci.groupable) //The item is not groupable with other items and needs to be ordered on its own if(get_item_count() > 0) // There are already other items in the order. -> Reject it return "Unable to add item - Item can not be grouped and must be ordered separately" else //No item in the order. Add it and set can_add_items to 0 can_add_items = 0 //Check if there is space in the container if(item_num + coi.ci.amount > get_container_storage()) return "Unable to add item - Container full" //Set item id of coi and increment item_id of co coi.item_id = item_id item_id += 1 //Increment the item number item_num += coi.ci.amount //Add coi to ordered item items.Add(coi) price += coi.price //Update the access requirement of the order if(coi.ci.access) required_access.Add(coi.ci.access) return "Item successfully added" //Removes a item from a order - Returns a status message /datum/cargo_order/proc/remove_item(var/remove_item_id) //Find the item with the specified id in the items list for (var/datum/cargo_order_item/coi in items) if(coi) if(coi.item_id == remove_item_id) items.Remove(coi) price -= coi.price item_num -= coi.ci.amount qdel(coi) return "Item removed successfully" return "Unable to remove item - Internal Error 608" // Returns the value of the order /datum/cargo_order/proc/get_value(var/type=0) //Type specifies if the price cargo has to pay or the price the customer has to be should be returned // 0 - Price the customer has to pay // 1 - Price cargo has to pay // 2 - Just the value of the items in the crate switch(type) if(0) //The price of the contents of the crate + the price for the crate + the handling fee + the shipment fee return price + SScargo.get_cratefee() + SScargo.get_handlingfee_cost(price) + get_shipment_cost() if(1) //The price of the contents of the crate + the price of the crate + the shipment fee return price + SScargo.get_cratefee() + get_shipment_cost() if(2) //Just the value of the items in the crate return price else //As a fallback, return the value of the items return price // Returns the number of items in the order /datum/cargo_order/proc/get_item_count() return items.len // Returns the type of the required container for the order /datum/cargo_order/proc/get_container_type() switch(container_type) if(CARGO_CONTAINER_CRATE) if(required_access.len > 0) return /obj/structure/closet/crate/secure else return /obj/structure/closet/crate if(CARGO_CONTAINER_BOX) if(required_access.len > 0) return /obj/structure/closet/crate/secure/large else return /obj/structure/largecrate if(CARGO_CONTAINER_FREEZER) return /obj/structure/closet/crate/freezer if(CARGO_CONTAINER_BODYBAG) return /obj/structure/closet/body_bag else LOG_DEBUG("Cargo: Tried to get container type for invalid container [container_type]") return /obj/structure/largecrate // Returns the number of items that can be stored in the container /datum/cargo_order/proc/get_container_storage() switch(container_type) if(CARGO_CONTAINER_CRATE) return 40 //Thats the default storage capacity of a crate if(CARGO_CONTAINER_FREEZER) return 40 if(CARGO_CONTAINER_BOX) return 5 //You can fit 5 larger items into a box if(CARGO_CONTAINER_BODYBAG) return 30 else LOG_DEBUG("Cargo: Tried to get storage size for invalid container [container_type]") return 0 //Something went wrong // Gets the list of the suppliers involved in the order /datum/cargo_order/proc/get_supplier_list() var/list/supplier_list = list() for(var/datum/cargo_order_item/coi in items) supplier_list[coi.ci.supplier] = coi.ci.supplier return supplier_list // Gets the shipment cost for the order /datum/cargo_order/proc/get_shipment_cost() var/list/supplier_list = get_supplier_list() var/cost = 0 for(var/supplier in supplier_list) var/singleton/cargo_supplier/cs = SScargo.cargo_suppliers[supplier] if(cs) cost += cs.shuttle_price return cost // Gets the order status /datum/cargo_order/proc/get_order_status(var/pretty=1) if(pretty) switch(status) if("submitted") return "Submitted to Cargo" if("approved") return "Approved" if("rejected") return "Rejected" if("shipped") return "Shipped to the [station_name(TRUE)]" if("delivered") return "Delivered" else return "Unknown Status" else return status //Returns the payment status /datum/cargo_order/proc/get_payment_status(var/pretty=1) if(pretty) if(paid_by != null) return "Paid by [paid_by] using [(paying_account == "Personal") ? "their personal" : "the [paying_account]"] account" else return "Unpaid" else if(paid_by != null) return TRUE else return FALSE // Returns a Invoice for the Order /datum/cargo_order/proc/get_report_invoice() var/list/order_data = list() var/invoice_type = "Preliminary" if(status == "delivered" && paid_by) invoice_type = "Final" order_data += "
Shipment Data
" invoice_data += "| Shipment Number: | " invoice_data += "[shipment_num] | " invoice_data += "
| Shipment Income: | " invoice_data += "[shipment_cost_sell] | " invoice_data += "
| Shipment Expense: | " invoice_data += "[shipment_cost_purchase] | " invoice_data += "
Shuttle Data
" invoice_data += "| Supplier fee: | " invoice_data += "[shuttle_fee] | " invoice_data += "
| Elevator Time: | " invoice_data += "[shuttle_time] | " invoice_data += "
| Elevator Called By: | " invoice_data += "[shuttle_called_by] | " invoice_data += "
| Elevator Recalled By: | " invoice_data += "[shuttle_recalled_by] | " invoice_data += "
Central Command Message:
" invoice_data += "[nl2br(message)]" shipment_invoice = invoice_data.Join("") completed = 1 return shipment_invoice // Returns the invoice. Generates it if it does not exist /datum/cargo_shipment/proc/get_invoice() if(!shipment_invoice) if(completed == 1) generate_invoice() else return "Invoice Unavailable. Shipment not completed." return shipment_invoice