mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-29 15:08:02 +01:00
EFTPOS Tweaks + TGUI makeover (#20095)
* eftpos changes * Apply suggestions from code review Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com> * request changes * tgui rebuild * Update code/modules/economy/economy_machinery/eftpos.dm Co-authored-by: Vi3trice <80771500+Vi3trice@users.noreply.github.com> --------- Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com> Co-authored-by: Vi3trice <80771500+Vi3trice@users.noreply.github.com>
This commit is contained in:
co-authored by
Henri215
Vi3trice
parent
99d8e3473f
commit
a7848ee5be
@@ -6,30 +6,33 @@
|
||||
icon = 'icons/obj/device.dmi'
|
||||
icon_state = "eftpos"
|
||||
w_class = WEIGHT_CLASS_SMALL
|
||||
/// Unique identifying name of this EFTPOS for transaction tracking in money accounts
|
||||
var/machine_name = ""
|
||||
var/transaction_locked = 0
|
||||
var/transaction_paid = 0
|
||||
/// Whether or not the EFTPOS is locked into a transaction
|
||||
var/transaction_locked = FALSE
|
||||
/// Did the transaction go through? Will reset back to FALSE after 5 seconds, used as a cooldown and indicator to consumer
|
||||
var/transaction_paid = FALSE
|
||||
/// Amount in space credits to charge card swiper
|
||||
var/transaction_amount = 0
|
||||
var/transaction_purpose = "Default charge"
|
||||
/// The pin number needed to changed settings on the EFTPOS
|
||||
var/access_code
|
||||
var/transaction_sound = 'sound/machines/chime.ogg'
|
||||
|
||||
///linked money account database to this EFTPOS
|
||||
var/datum/money_account_database/account_database
|
||||
var/datum/money_account_database/main_station/account_database
|
||||
///Current money account the EFTPOS is depositing to
|
||||
var/datum/money_account/linked_account
|
||||
|
||||
/obj/item/eftpos/Initialize(mapload)
|
||||
machine_name = "[station_name()] EFTPOS #[rand(101,999)]"
|
||||
machine_name = "EFTPOS #[rand(101, 999)]"
|
||||
access_code = rand(1000, 9999)
|
||||
reconnect_database()
|
||||
//linked account starts as service account by default
|
||||
linked_account = account_database.get_account_by_department(DEPARTMENT_SERVICE)
|
||||
print_reference()
|
||||
|
||||
//by default, connect to the station vendor account
|
||||
linked_account = GLOB.station_money_database.vendor_account
|
||||
return ..()
|
||||
|
||||
|
||||
/obj/item/eftpos/proc/reconnect_database()
|
||||
account_database = GLOB.station_money_database
|
||||
|
||||
@@ -55,7 +58,7 @@
|
||||
/obj/item/eftpos/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.inventory_state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
ui = new(user, src, ui_key, "EFTPOS", name, 800, 300, master_ui, state)
|
||||
ui = new(user, src, ui_key, "EFTPOS", name, 500, 250, master_ui, state)
|
||||
ui.open()
|
||||
|
||||
/obj/item/eftpos/ui_data(mob/user)
|
||||
@@ -65,7 +68,16 @@
|
||||
data["transaction_paid"] = transaction_paid
|
||||
data["transaction_purpose"] = transaction_purpose
|
||||
data["transaction_amount"] = transaction_amount
|
||||
data["linked_account"] = linked_account ? linked_account.account_name : null
|
||||
data["linked_account"] = list("name" = linked_account?.account_name, "UID" = linked_account?.UID())
|
||||
data["available_accounts"] = list()
|
||||
for(var/datum/money_account/department as anything in (account_database.get_all_department_accounts() + account_database.user_accounts))
|
||||
var/list/account_data = list(
|
||||
"name" = department.account_name,
|
||||
"UID" = department.UID()
|
||||
)
|
||||
data["available_accounts"] += list(account_data)
|
||||
|
||||
|
||||
return data
|
||||
|
||||
/obj/item/eftpos/ui_act(action, list/params, datum/tgui/ui)
|
||||
@@ -95,7 +107,7 @@
|
||||
if(account_database)
|
||||
var/attempt_account_num = input("Enter account number to pay EFTPOS charges into", "New account number") as num
|
||||
var/attempt_pin = input("Enter pin code", "Account pin") as num
|
||||
if(!check_user_position(user))
|
||||
if(!check_user_position(user) || !account_database)
|
||||
return
|
||||
var/datum/money_account/target_account = GLOB.station_money_database.find_user_account(attempt_account_num, include_departments = TRUE)
|
||||
if(!target_account)
|
||||
@@ -109,6 +121,14 @@
|
||||
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to inputed account.</span>")
|
||||
else
|
||||
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to accounts database.</span>")
|
||||
return
|
||||
var/datum/money_account/target_account = locateUID(params["account"])
|
||||
if(!istype(target_account))
|
||||
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to inputted account.</span>")
|
||||
return
|
||||
// in this case we don't care about authenticating login because we're sending money into the account
|
||||
linked_account = target_account
|
||||
to_chat(user, "[bicon(src)]<span class='warning'>Linked account successfully set to [target_account.account_name]</span>")
|
||||
if("trans_purpose")
|
||||
var/purpose = clean_input("Enter reason for EFTPOS transaction", "Transaction purpose", transaction_purpose)
|
||||
if(!check_user_position(user))
|
||||
@@ -138,16 +158,6 @@
|
||||
transaction_locked = TRUE
|
||||
else
|
||||
to_chat(user, "[bicon(src)]<span class='warning'>No account connected to send transactions to.</span>")
|
||||
if("scan_card")
|
||||
//attempt to connect to a new db, and if that doesn't work then fail
|
||||
if(!account_database)
|
||||
reconnect_database()
|
||||
if(account_database && linked_account)
|
||||
var/obj/item/I = user.get_active_hand()
|
||||
if(istype(I, /obj/item/card))
|
||||
scan_card(I, user)
|
||||
else
|
||||
to_chat(user, "[bicon(src)]<span class='warning'>Unable to link accounts.</span>")
|
||||
if("reset")
|
||||
//reset the access code - requires HoP/captain access
|
||||
var/obj/item/I = user.get_active_hand()
|
||||
@@ -182,7 +192,7 @@
|
||||
if(!D || !GLOB.station_money_database.try_authenticate_login(D, attempt_pin, restricted_bypass = FALSE))
|
||||
to_chat(user, "[bicon(src)]<span class='warning'>Unable to access account, insufficient access.</span>")
|
||||
return
|
||||
if(alert("Are you sure you want to pay $[transaction_amount] to Account: [linked_account.account_name] ", "Confirm transaction", "Yes", "No") != "Yes")
|
||||
if(alert("Are you sure you want to pay $[transaction_amount] to: [linked_account.account_name] ", "Confirm transaction", "Yes", "No") != "Yes")
|
||||
return
|
||||
if(!Adjacent(user))
|
||||
return
|
||||
@@ -194,6 +204,7 @@
|
||||
playsound(src, transaction_sound, 50, TRUE)
|
||||
visible_message("<span class='notice'>[src] chimes!</span>")
|
||||
transaction_paid = TRUE
|
||||
addtimer(VARSET_CALLBACK(src, transaction_paid, FALSE), 5 SECONDS)
|
||||
|
||||
///creates and builds paper with info about the EFTPOS
|
||||
/obj/item/eftpos/proc/print_reference()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useBackend } from '../backend';
|
||||
import { Box, Button, LabeledList, NoticeBox, Section } from '../components';
|
||||
import { createSearch } from 'common/string';
|
||||
import { useBackend, useLocalState } from "../backend";
|
||||
import { Box, Button, LabeledList, Section, Input, Dropdown } from '../components';
|
||||
import { Window } from '../layouts';
|
||||
|
||||
export const EFTPOS = (props, context) => {
|
||||
@@ -8,11 +9,25 @@ export const EFTPOS = (props, context) => {
|
||||
return (
|
||||
<Window>
|
||||
<Window.Content>
|
||||
<Box italic>
|
||||
This terminal is {machine_name}. Report this code when contacting
|
||||
Nanotrasen IT Support.
|
||||
</Box>
|
||||
{transaction_locked ? <LockedView /> : <UnlockedView />}
|
||||
<Section title={"POS Terminal " + machine_name}
|
||||
buttons={
|
||||
<>
|
||||
<Button
|
||||
content={transaction_locked ? "Unlock EFTPOS" : "Lock EFTPOS"}
|
||||
tooltip="Enter pin to modify transactions and EFTPOS settings"
|
||||
icon={transaction_locked ? "lock-open" : "lock"}
|
||||
onClick={() => act('toggle_lock')}
|
||||
/>
|
||||
<Button
|
||||
content="Reset EFTPOS"
|
||||
tooltip="Requires Captain, HoP or CC access"
|
||||
icon="sync"
|
||||
onClick={() => act('reset')}
|
||||
/>
|
||||
</>}>
|
||||
{transaction_locked ? <LockedView /> : <UnlockedView />}
|
||||
</Section>
|
||||
|
||||
</Window.Content>
|
||||
</Window>
|
||||
);
|
||||
@@ -21,94 +36,82 @@ export const EFTPOS = (props, context) => {
|
||||
const LockedView = (props, context) => {
|
||||
const { act, data } = useBackend(context);
|
||||
const {
|
||||
transaction_purpose,
|
||||
transaction_amount,
|
||||
linked_account,
|
||||
transaction_paid,
|
||||
} = data;
|
||||
return (
|
||||
<Section title="Current Transaction" mt={1}>
|
||||
<LabeledList>
|
||||
<LabeledList.Item label="Transaction Purpose">
|
||||
{transaction_purpose}
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Value">
|
||||
{/* Ternary required otherwise the 0 is offset weirdly */}
|
||||
{transaction_amount ? transaction_amount : '0'}
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Linked Account">
|
||||
{linked_account ? linked_account : 'None'}
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Actions">
|
||||
<Button
|
||||
content={transaction_paid ? 'Reset' : 'Reset (Auth required)'}
|
||||
icon="unlock"
|
||||
onClick={() => act('toggle_lock')}
|
||||
/>
|
||||
</LabeledList.Item>
|
||||
</LabeledList>
|
||||
<NoticeBox mt={1}>
|
||||
<Button
|
||||
content="------"
|
||||
icon="id-card"
|
||||
mr={2}
|
||||
onClick={() => act('scan_card')}
|
||||
/>
|
||||
<>
|
||||
<Box mt={2} bold width="100%" fontSize="3rem" color={transaction_paid ? 'green' : 'red'} align="center" justify="center">Payment {transaction_paid ? "Accepted" : "Due"}: ${transaction_amount}</Box>
|
||||
<Box mt={.5} fontSize="1.25rem" align="center" justify="center">
|
||||
{transaction_paid
|
||||
? 'This transaction has been processed successfully '
|
||||
: 'Swipe your card to finish this transaction.'}
|
||||
</NoticeBox>
|
||||
</Section>
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const UnlockedView = (props, context) => {
|
||||
const { act, data } = useBackend(context);
|
||||
const { transaction_purpose, transaction_amount, linked_account } = data;
|
||||
const [searchText, setSearchText] = useLocalState(context, 'searchText', '');
|
||||
const {
|
||||
transaction_purpose,
|
||||
transaction_amount,
|
||||
linked_account,
|
||||
available_accounts
|
||||
} = data;
|
||||
|
||||
let accountMap = []
|
||||
available_accounts.map(account => (
|
||||
accountMap[account.name] = account.UID
|
||||
))
|
||||
return (
|
||||
<Section title="Transation Settings" mt={1}>
|
||||
<LabeledList>
|
||||
<LabeledList.Item label="Transaction Purpose">
|
||||
<Button
|
||||
content={transaction_purpose}
|
||||
icon="edit"
|
||||
onClick={() => act('trans_purpose')}
|
||||
/>
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Value">
|
||||
<Button
|
||||
// Ternary required otherwise the 0 is offset weirdly
|
||||
content={transaction_amount ? transaction_amount : '0'}
|
||||
icon="edit"
|
||||
onClick={() => act('trans_value')}
|
||||
/>
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Linked Account">
|
||||
<Button
|
||||
content={linked_account ? linked_account : 'None'}
|
||||
icon="edit"
|
||||
onClick={() => act('link_account')}
|
||||
/>
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Actions">
|
||||
<Button
|
||||
content="Lock in new transaction"
|
||||
icon="lock"
|
||||
onClick={() => act('toggle_lock')}
|
||||
/>
|
||||
<Button
|
||||
content="Change access code"
|
||||
icon="key"
|
||||
onClick={() => act('change_code')}
|
||||
/>
|
||||
<Button
|
||||
content="Reset access code"
|
||||
tooltip="Requires Captain, HoP or CC access"
|
||||
icon="sync-alt"
|
||||
onClick={() => act('reset')}
|
||||
/>
|
||||
</LabeledList.Item>
|
||||
</LabeledList>
|
||||
</Section>
|
||||
<LabeledList>
|
||||
<LabeledList.Item label="Transaction Purpose">
|
||||
<Button
|
||||
content={transaction_purpose}
|
||||
icon="edit"
|
||||
onClick={() => act('trans_purpose')}
|
||||
/>
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Value">
|
||||
<Button
|
||||
content={transaction_amount ? '$' + transaction_amount : '$0'}
|
||||
icon="edit"
|
||||
onClick={() => act('trans_value')}
|
||||
/>
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Linked Account">
|
||||
<Box mb={.5}>{linked_account.name}</Box>
|
||||
<Input
|
||||
width="190px"
|
||||
placeholder="Search by name"
|
||||
onInput={(e, value) => setSearchText(value)}
|
||||
/>
|
||||
<Dropdown
|
||||
mt={0.6}
|
||||
width="190px"
|
||||
options={available_accounts
|
||||
.filter(
|
||||
createSearch(searchText, (account) => {
|
||||
return (
|
||||
account.name
|
||||
);
|
||||
})
|
||||
)
|
||||
.map((account) => account.name)}
|
||||
selected={available_accounts.filter(account => account.UID === linked_account.UID)[0]?.name}
|
||||
onSelected={(val) => act('link_account', {
|
||||
account: accountMap[val],
|
||||
})}/>
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Actions">
|
||||
<Button
|
||||
content="Change access code"
|
||||
icon="key"
|
||||
onClick={() => act('change_code')}
|
||||
/>
|
||||
</LabeledList.Item>
|
||||
</LabeledList>
|
||||
);
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user