3import { useState, useEffect } from 'react';
4import { Icon } from '@/contexts/IconContext';
6interface ProfileUsage {
12export default function CashDrawersPage() {
13 const [profileUsage, setProfileUsage] = useState<ProfileUsage[]>([
14 { id: 0, name: 'No Profile', used: 0 },
15 { id: 1, name: 'Profile 1', used: 0 },
16 { id: 2, name: 'Profile 2', used: 0 },
17 { id: 3, name: 'Profile 3', used: 0 },
18 { id: 4, name: 'Profile 4', used: 0 },
19 { id: 5, name: 'Profile 5', used: 0 },
20 { id: 6, name: 'Profile 6', used: 0 },
21 { id: 7, name: 'Profile 7', used: 0 },
22 { id: 8, name: 'Profile 8', used: 0 },
29 const loadData = async () => {
30 // Load profile usage from API
31 // API call: /BUCK?3=retailmax.elink.lane.summary&100=profileuse
32 console.log('Loading profile usage data...');
35 const saveSetting = (settingName: string, value: boolean) => {
36 console.log(`Saving ${settingName} = ${value}`);
37 // API call to save setting via DATI XML
38 // <DATI><f8_s>retailmax.elink.config.basesetting.edit</f8_s>
39 // <f11_B>E</f11_B><f100_s>${settingName}</f100_s>
40 // <f101_E>${value ? 1 : 0}</f101_E><f112_E>1</f112_E></DATI>
43 // Reusable toggle switch component
44 const ToggleSwitch = ({ settingName, onChange }: { settingName: string; onChange?: (checked: boolean) => void }) => {
45 const [checked, setChecked] = useState(false);
47 const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
48 const newValue = e.target.checked;
50 saveSetting(settingName, newValue);
51 if (onChange) onChange(newValue);
55 <label className="relative inline-flex items-center cursor-pointer">
58 className="sr-only peer"
60 onChange={handleChange}
62 <div className="w-11 h-6 bg-danger peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-brand rounded-full peer peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-border after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-brand"></div>
68 <div className="p-6 min-h-screen bg-bg">
69 <div className="max-w-[1600px] mx-auto">
71 <div className="mb-6">
72 <h1 className="text-3xl font-bold text-text mb-2 flex items-center gap-2">
73 <Icon name="payments" size={32} />
79 <div className="bg-info/10 border border-info/30 rounded-lg p-4 mb-6">
80 <p className="text-text mb-2">
81 Cash drawers are typically connected to retail printers, and those printers provide the electronic signal to open the drawer.
83 <p className="text-text">
84 Fieldpine drives the cash drawer directly. You should not use printer driver options to always open the cash drawer after printing
85 as this causes the drawer to open when anything is printed, which is less secure and annoying for transactions that do not need it.
89 {/* Profile-based Settings Table */}
90 <div className="bg-surface rounded-lg shadow-md overflow-x-auto">
91 <table className="w-full border-collapse">
93 <tr className="bg-surface-2 border-b border-border">
94 <th className="px-4 py-3 text-left font-semibold text-text sticky left-0 bg-surface-2 z-10 min-w-[200px]">
97 {profileUsage.map((profile) => (
98 <th key={profile.id} className="px-3 py-3 text-center font-semibold text-text min-w-[80px]">
99 <div dangerouslySetInnerHTML={{ __html: profile.name }} />
100 <div className="text-xs font-normal text-muted mt-1">
101 {profile.id === 0 && profile.used === 0 ? '' : `${profile.used} lane${profile.used !== 1 ? 's' : ''}`}
105 <th className="px-3 py-3 text-right font-semibold text-text min-w-[80px]">
111 {/* Allow Quickcode to open drawer */}
112 <tr className="border-b border-border">
113 <td className="px-4 py-3 text-sm font-semibold text-text sticky left-0 bg-surface z-10">
114 Allow Quickcode to open drawer
116 <td className="px-3 py-3 text-center">
117 <ToggleSwitch settingName="QuickCodeOpenDrawer" />
119 <td className="px-3 py-3 text-center">
120 <ToggleSwitch settingName="QuickCodeOpenDrawer@p1" />
122 <td className="px-3 py-3 text-center">
123 <ToggleSwitch settingName="QuickCodeOpenDrawer@p2" />
125 <td className="px-3 py-3 text-center">
126 <ToggleSwitch settingName="QuickCodeOpenDrawer@p3" />
128 <td className="px-3 py-3 text-center">
129 <ToggleSwitch settingName="QuickCodeOpenDrawer@p4" />
131 <td className="px-3 py-3 text-center">
132 <ToggleSwitch settingName="QuickCodeOpenDrawer@p5" />
134 <td className="px-3 py-3 text-center">
135 <ToggleSwitch settingName="QuickCodeOpenDrawer@p6" />
137 <td className="px-3 py-3 text-center">
138 <ToggleSwitch settingName="QuickCodeOpenDrawer@p7" />
140 <td className="px-3 py-3 text-center">
141 <ToggleSwitch settingName="QuickCodeOpenDrawer@p8" />
143 <td className="px-3 py-3 text-right text-xs text-muted">
147 <tr className="bg-surface-2 border-b border-border">
148 <td colSpan={11} className="px-4 py-2 text-sm text-muted">
149 Can the user enter a quickcode to open the cash drawer without a sale requiring it to open? This is disabled by default
150 as it makes systems slightly less secure.
154 {/* Display Errors to Users */}
155 <tr className="border-b border-border">
156 <td className="px-4 py-3 text-sm font-semibold text-text sticky left-0 bg-surface z-10">
157 Display Errors to Users
159 <td className="px-3 py-3 text-center">
160 <ToggleSwitch settingName="CashDrawer0Error" />
162 <td className="px-3 py-3 text-center">
163 <ToggleSwitch settingName="CashDrawer0Error@p1" />
165 <td className="px-3 py-3 text-center">
166 <ToggleSwitch settingName="CashDrawer0Error@p2" />
168 <td className="px-3 py-3 text-center">
169 <ToggleSwitch settingName="CashDrawer0Error@p3" />
171 <td className="px-3 py-3 text-center">
172 <ToggleSwitch settingName="CashDrawer0Error@p4" />
174 <td className="px-3 py-3 text-center">
175 <ToggleSwitch settingName="CashDrawer0Error@p5" />
177 <td className="px-3 py-3 text-center">
178 <ToggleSwitch settingName="CashDrawer0Error@p6" />
180 <td className="px-3 py-3 text-center">
181 <ToggleSwitch settingName="CashDrawer0Error@p7" />
183 <td className="px-3 py-3 text-center">
184 <ToggleSwitch settingName="CashDrawer0Error@p8" />
186 <td className="px-3 py-3 text-right text-xs text-muted">
190 <tr className="bg-surface-2 border-b border-border">
191 <td colSpan={11} className="px-4 py-2 text-sm text-muted">
192 If a technical issue is detected while opening the cash drawer, should we tell the staff member (on) or silently fail (off).
199 {/* Additional Info */}
200 <div className="mt-6 bg-surface-2 border border-border rounded-lg p-4">
201 <h3 className="text-sm font-semibold text-text mb-2">About Cash Drawer Settings</h3>
202 <ul className="text-sm text-muted space-y-1 list-disc list-inside">
203 <li>Cash drawers open automatically when a sale requires it (cash payments, change given)</li>
204 <li>Quickcode opening allows staff to manually open the drawer without a sale</li>
205 <li>Error display helps diagnose hardware connectivity issues</li>
206 <li>Settings are profile-based to allow different behavior per store or lane type</li>