mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-23 08:31:57 +00:00
Adds a helper proc for money transfers between two accounts. Cleans up the EFTPOS and cargo delivery code to use said helper proc. Changes SSEconomy to use indexed lists for accounts and look up the accounts by accessing it via the index.
274 lines
8.1 KiB
Plaintext
274 lines
8.1 KiB
Plaintext
|
|
/obj/machinery/account_database
|
|
name = "Accounts uplink terminal"
|
|
desc = "Access transaction logs, account data and all kinds of other financial records."
|
|
icon = 'icons/obj/computer.dmi'
|
|
icon_state = "account_uplink"
|
|
density = 1
|
|
req_one_access = list(access_hop, access_captain, access_cent_captain)
|
|
anchored = 1
|
|
var/receipt_num
|
|
var/machine_id = ""
|
|
var/obj/item/weapon/card/id/held_card
|
|
var/datum/money_account/detailed_account_view
|
|
var/creating_new_account = 0
|
|
var/const/fund_cap = 1000000
|
|
|
|
proc/get_access_level()
|
|
if (!held_card)
|
|
return 0
|
|
if(access_cent_captain in held_card.access)
|
|
return 2
|
|
else if((access_hop in held_card.access) || (access_captain in held_card.access))
|
|
return 1
|
|
|
|
proc/create_transation(target, reason, amount)
|
|
var/datum/transaction/T = new()
|
|
T.target_name = target
|
|
T.purpose = reason
|
|
T.amount = amount
|
|
T.date = worlddate2text()
|
|
T.time = worldtime2text()
|
|
T.source_terminal = machine_id
|
|
return T
|
|
|
|
proc/accounting_letterhead(report_name)
|
|
return {"
|
|
<center><h1><b>[report_name]</b></h1></center>
|
|
<center><small><i>[station_name()] Accounting Report</i></small></center>
|
|
<hr>
|
|
<u>Generated By:</u> [held_card.registered_name], [held_card.assignment]<br>
|
|
"}
|
|
|
|
/obj/machinery/account_database/Initialize()
|
|
. = ..()
|
|
machine_id = "[station_name()] Acc. DB #[SSeconomy.num_financial_terminals++]"
|
|
|
|
/obj/machinery/account_database/attackby(obj/O, mob/user)
|
|
if(!istype(O, /obj/item/weapon/card/id))
|
|
return ..()
|
|
|
|
if(!held_card)
|
|
user.drop_from_inventory(O,src)
|
|
held_card = O
|
|
|
|
SSnanoui.update_uis(src)
|
|
|
|
attack_hand(user)
|
|
|
|
/obj/machinery/account_database/attack_hand(mob/user as mob)
|
|
if(stat & (NOPOWER|BROKEN)) return
|
|
ui_interact(user)
|
|
|
|
/obj/machinery/account_database/ui_interact(mob/user, ui_key="main", var/datum/nanoui/ui = null, var/force_open = 1)
|
|
user.set_machine(src)
|
|
|
|
var/data[0]
|
|
data["src"] = "\ref[src]"
|
|
data["id_inserted"] = !!held_card
|
|
data["id_card"] = held_card ? text("[held_card.registered_name], [held_card.assignment]") : "-----"
|
|
data["access_level"] = get_access_level()
|
|
data["machine_id"] = machine_id
|
|
data["creating_new_account"] = creating_new_account
|
|
data["detailed_account_view"] = !!detailed_account_view
|
|
data["station_account_number"] = SSeconomy.station_account.account_number
|
|
data["transactions"] = null
|
|
data["accounts"] = null
|
|
|
|
if (detailed_account_view)
|
|
data["account_number"] = detailed_account_view.account_number
|
|
data["owner_name"] = detailed_account_view.owner_name
|
|
data["money"] = detailed_account_view.money
|
|
data["suspended"] = detailed_account_view.suspended
|
|
|
|
var/list/trx[0]
|
|
for (var/datum/transaction/T in detailed_account_view.transactions)
|
|
trx.Add(list(list(\
|
|
"date" = T.date, \
|
|
"time" = T.time, \
|
|
"target_name" = T.target_name, \
|
|
"purpose" = T.purpose, \
|
|
"amount" = T.amount, \
|
|
"source_terminal" = T.source_terminal)))
|
|
|
|
if (trx.len > 0)
|
|
data["transactions"] = trx
|
|
|
|
var/list/accounts[0]
|
|
for(var/M in SSeconomy.all_money_accounts)
|
|
var/datum/money_account/D = SSeconomy.get_account(M)
|
|
accounts.Add(list(list(\
|
|
"account_number"=D.account_number,\
|
|
"owner_name"=D.owner_name,\
|
|
"suspended"=D.suspended ? "SUSPENDED" : "")))
|
|
|
|
if (accounts.len > 0)
|
|
data["accounts"] = accounts
|
|
|
|
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
|
|
if (!ui)
|
|
ui = new(user, src, ui_key, "accounts_terminal.tmpl", src.name, 400, 640)
|
|
ui.set_initial_data(data)
|
|
ui.open()
|
|
|
|
/obj/machinery/account_database/Topic(href, href_list)
|
|
if(..())
|
|
return 1
|
|
|
|
var/datum/nanoui/ui = SSnanoui.get_open_ui(usr, src, "main")
|
|
|
|
if(href_list["choice"])
|
|
switch(href_list["choice"])
|
|
if("create_account")
|
|
creating_new_account = 1
|
|
|
|
if("add_funds")
|
|
var/amount = input("Enter the amount you wish to add", "Silently add funds") as num
|
|
if(detailed_account_view)
|
|
detailed_account_view.money = min(detailed_account_view.money + amount, fund_cap)
|
|
|
|
if("remove_funds")
|
|
var/amount = input("Enter the amount you wish to remove", "Silently remove funds") as num
|
|
if(detailed_account_view)
|
|
detailed_account_view.money = max(detailed_account_view.money - amount, -fund_cap)
|
|
|
|
if("toggle_suspension")
|
|
if(detailed_account_view)
|
|
detailed_account_view.suspended = !detailed_account_view.suspended
|
|
callHook("change_account_status", list(detailed_account_view))
|
|
|
|
if("finalise_create_account")
|
|
var/account_name = href_list["holder_name"]
|
|
var/starting_funds = max(text2num(href_list["starting_funds"]), 0)
|
|
|
|
starting_funds = Clamp(starting_funds, 0, SSeconomy.station_account.money) // Not authorized to put the station in debt.
|
|
starting_funds = min(starting_funds, fund_cap) // Not authorized to give more than the fund cap.
|
|
|
|
SSeconomy.create_account(account_name, starting_funds, src)
|
|
if(starting_funds > 0)
|
|
//subtract the money
|
|
SSeconomy.station_account.money -= starting_funds
|
|
|
|
//create a transaction log entry
|
|
var/datum/transaction/trx = create_transation(account_name, "New account activation", "([starting_funds])")
|
|
SSeconomy.add_transaction_log(SSeconomy.station_account,trx)
|
|
|
|
creating_new_account = 0
|
|
ui.close()
|
|
|
|
creating_new_account = 0
|
|
if("insert_card")
|
|
if(held_card)
|
|
held_card.forceMove(src.loc)
|
|
|
|
if(ishuman(usr) && !usr.get_active_hand())
|
|
usr.put_in_hands(held_card)
|
|
held_card = null
|
|
|
|
else
|
|
var/obj/item/I = usr.get_active_hand()
|
|
if (istype(I, /obj/item/weapon/card/id))
|
|
var/obj/item/weapon/card/id/C = I
|
|
usr.drop_from_inventory(C,src)
|
|
held_card = C
|
|
|
|
if("view_account_detail")
|
|
detailed_account_view = SSeconomy.get_account(href_list["account_number"])
|
|
|
|
if("view_accounts_list")
|
|
detailed_account_view = null
|
|
creating_new_account = 0
|
|
|
|
if("revoke_payroll")
|
|
var/funds = detailed_account_view.money
|
|
var/account_trx = create_transation(SSeconomy.station_account.owner_name, "Revoke payroll", "([funds])")
|
|
var/station_trx = create_transation(detailed_account_view.owner_name, "Revoke payroll", funds)
|
|
|
|
SSeconomy.station_account.money += funds
|
|
detailed_account_view.money = 0
|
|
|
|
SSeconomy.add_transaction_log(detailed_account_view,account_trx)
|
|
SSeconomy.add_transaction_log(SSeconomy.station_account,station_trx)
|
|
|
|
callHook("revoke_payroll", list(detailed_account_view))
|
|
|
|
if("print")
|
|
var/text
|
|
var/obj/item/weapon/paper/P = new()
|
|
var/pname
|
|
if (detailed_account_view)
|
|
pname = "account #[detailed_account_view.account_number] details"
|
|
var/title = "Account #[detailed_account_view.account_number] Details"
|
|
text = {"
|
|
[accounting_letterhead(title)]
|
|
<u>Holder:</u> [detailed_account_view.owner_name]<br>
|
|
<u>Balance:</u> $[detailed_account_view.money]<br>
|
|
<u>Status:</u> [detailed_account_view.suspended ? "Suspended" : "Active"]<br>
|
|
<u>Transactions:</u> ([detailed_account_view.transactions.len])<br>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<td>Timestamp</td>
|
|
<td>Target</td>
|
|
<td>Reason</td>
|
|
<td>Value</td>
|
|
<td>Terminal</td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
"}
|
|
|
|
for (var/datum/transaction/T in detailed_account_view.transactions)
|
|
text += {"
|
|
<tr>
|
|
<td>[T.date] [T.time]</td>
|
|
<td>[T.target_name]</td>
|
|
<td>[T.purpose]</td>
|
|
<td>[T.amount]</td>
|
|
<td>[T.source_terminal]</td>
|
|
</tr>
|
|
"}
|
|
|
|
text += {"
|
|
</tbody>
|
|
</table>
|
|
"}
|
|
|
|
else
|
|
pname = "financial account list"
|
|
text = {"
|
|
[accounting_letterhead("Financial Account List")]
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<td>Account Number</td>
|
|
<td>Holder</td>
|
|
<td>Balance</td>
|
|
<td>Status</td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
"}
|
|
|
|
for(var/M in SSeconomy.all_money_accounts)
|
|
var/datum/money_account/D = SSeconomy.get_account(M)
|
|
text += {"
|
|
<tr>
|
|
<td>#[D.account_number]</td>
|
|
<td>[D.owner_name]</td>
|
|
<td>$[D.money]</td>
|
|
<td>[D.suspended ? "Suspended" : "Active"]</td>
|
|
</tr>
|
|
"}
|
|
|
|
text += {"
|
|
</tbody>
|
|
</table>
|
|
"}
|
|
|
|
P.set_content_unsafe(pname, text)
|
|
print(P)
|
|
|
|
return 1
|