Skip to content

Commit

Permalink
EFTPOS Tweaks + TGUI makeover (ParadiseSS13#20095)
Browse files Browse the repository at this point in the history
* eftpos changes

* Apply suggestions from code review

Co-authored-by: Henri215 <[email protected]>

* request changes

* tgui rebuild

* Update code/modules/economy/economy_machinery/eftpos.dm

Co-authored-by: Vi3trice <[email protected]>

---------

Co-authored-by: Henri215 <[email protected]>
Co-authored-by: Vi3trice <[email protected]>
  • Loading branch information
3 people authored Feb 23, 2023
1 parent 99d8e34 commit a7848ee
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 107 deletions.
55 changes: 33 additions & 22 deletions code/modules/economy/economy_machinery/eftpos.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
169 changes: 86 additions & 83 deletions tgui/packages/tgui/interfaces/EFTPOS.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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>
);
Expand All @@ -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>
);
};
4 changes: 2 additions & 2 deletions tgui/packages/tgui/public/tgui.bundle.js

Large diffs are not rendered by default.

0 comments on commit a7848ee

Please sign in to comment.