@controleonline/ui-common 1.2.118 → 1.2.120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  {
2
- "version": "1.2.118",
2
+ "version": "1.2.119",
3
3
  "rc": 1,
4
- "branch": "rc/1.2.118-rc.1",
5
- "baseMaster": "cc9e32a018f490505b2199b8c313a5dd68f268cc",
4
+ "branch": "rc/1.2.119-rc.1",
5
+ "baseMaster": "d88e3ddf8397cc22b4dac04522cb000cf43cfeb8",
6
6
  "tasks": [
7
- 1339
7
+ 128
8
8
  ],
9
9
  "frozen": true,
10
10
  "repositories": {
11
- "ControleOnline/ui-common": "f9a7beb517617a51e368a158bca02b33eed842cb"
11
+ "ControleOnline/ui-common": "6bb419444fabf184d89c7738795617cb7b527246"
12
12
  }
13
13
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@controleonline/ui-common",
3
- "version": "1.2.118",
3
+ "version": "1.2.120",
4
4
  "author": "ControleOnline",
5
5
  "description": "ControleOnline Common Quasar UI Component",
6
6
  "license": "MIT",
7
7
  "main": "src/react/index.js",
8
8
  "scripts": {
9
- "test": "npm run test:receita-federal && npm run test:imports-status && npm run test:runtime-language && npm run test:runtime-footer && npm run test:runtime-footer-marquee && npm run test:invoice-presentation && npm run test:system-error-message && npm run test:bottom-navigation-toolbar && npm run test:copy-device-configs && npm run test:print-routing && npm run test:device-detail-dependencies && npm run test:runtime-zoom",
9
+ "test": "npm run test:receita-federal && npm run test:imports-status && npm run test:runtime-language && npm run test:runtime-footer && npm run test:runtime-footer-marquee && npm run test:invoice-presentation && npm run test:system-error-message && npm run test:bottom-navigation-toolbar && npm run test:copy-device-configs && npm run test:print-routing && npm run test:device-detail-dependencies && npm run test:runtime-zoom && npm run test:cash-register-summary",
10
10
  "test:receita-federal": "node --test src/tests/react/pages/receitaFederalIntegrationContract.test.mjs",
11
11
  "test:imports-status": "mkdir -p node_modules/@controleonline && rm -rf node_modules/@controleonline/ui-common && ln -s ../.. node_modules/@controleonline/ui-common && node --test src/tests/react/utils/importStatus.test.js",
12
+ "test:cash-register-summary": "node --test src/tests/react/utils/cashRegisterSummary.test.js",
12
13
  "test:runtime-language": "node --test src/tests/react/utils/runtimeLanguage.test.js",
13
14
  "test:runtime-footer": "node --test src/tests/react/utils/runtimeFooter.test.js src/tests/react/utils/runtimeFooterText.test.js",
14
15
  "test:invoice-presentation": "node --test src/tests/react/utils/invoicePresentation.test.mjs",
@@ -0,0 +1,200 @@
1
+ import React, {useCallback, useState} from 'react';
2
+ import {
3
+ ActivityIndicator,
4
+ RefreshControl,
5
+ ScrollView,
6
+ StyleSheet,
7
+ Text,
8
+ TextInput,
9
+ TouchableOpacity,
10
+ View,
11
+ } from 'react-native';
12
+ import {useFocusEffect, useNavigation} from '@react-navigation/native';
13
+ import {useStore} from '@store';
14
+ import {api} from '@controleonline/ui-common/src/api';
15
+ import Formatter from '@controleonline/ui-common/src/utils/formatter';
16
+ import {
17
+ buildCashDrilldownNavigation,
18
+ buildCashSummaryParams,
19
+ } from '@controleonline/ui-common/src/react/utils/cashRegisterSummary';
20
+
21
+ const PERIOD_OPTIONS = [
22
+ {key: 'today', label: 'Hoje'},
23
+ {key: 'yesterday', label: 'Ontem'},
24
+ {key: 'week', label: 'Semana'},
25
+ {key: 'month', label: 'Mês'},
26
+ {key: 'custom', label: 'Período'},
27
+ ];
28
+
29
+ const ERROR_MESSAGES = {
30
+ range: 'Informe datas válidas (AAAA-MM-DD) e a data final não pode ser anterior à inicial.',
31
+ };
32
+
33
+ /**
34
+ * Caixa consolidado por forma de pagamento.
35
+ * Visibility (menu + user type) is enforced by the API; the "scope" returned
36
+ * tells whether the totals are for the whole company or only the current user.
37
+ * Refs: ControleOnline/ui-common#128
38
+ */
39
+ export default function CashRegisterSummary() {
40
+ const navigation = useNavigation();
41
+ const peopleStore = useStore('people');
42
+ const {currentCompany} = peopleStore.getters || {};
43
+ const [period, setPeriod] = useState('today');
44
+ const [from, setFrom] = useState('');
45
+ const [to, setTo] = useState('');
46
+ const [data, setData] = useState(null);
47
+ const [loading, setLoading] = useState(false);
48
+ const [error, setError] = useState(null);
49
+
50
+ const load = useCallback(async () => {
51
+ const {params, error: paramsError} = buildCashSummaryParams({
52
+ companyId: currentCompany?.id,
53
+ period,
54
+ from,
55
+ to,
56
+ });
57
+ if (paramsError) {
58
+ setError(ERROR_MESSAGES[paramsError] || null);
59
+ return;
60
+ }
61
+
62
+ setLoading(true);
63
+ setError(null);
64
+ try {
65
+ const response = await api.fetch('/cash-register/summary', {method: 'GET', params});
66
+ if (response?.error) throw new Error(response.error);
67
+ setData(response);
68
+ } catch (e) {
69
+ setData(null);
70
+ setError(e?.message || 'Não foi possível carregar o caixa.');
71
+ } finally {
72
+ setLoading(false);
73
+ }
74
+ }, [currentCompany?.id, period, from, to]);
75
+
76
+ useFocusEffect(
77
+ useCallback(() => {
78
+ if (period !== 'custom') load();
79
+ }, [load, period]),
80
+ );
81
+
82
+ const payments = data?.payments || [];
83
+
84
+ return (
85
+ <ScrollView
86
+ style={styles.container}
87
+ contentContainerStyle={styles.content}
88
+ refreshControl={<RefreshControl refreshing={loading} onRefresh={load} />}>
89
+ <View style={styles.chips}>
90
+ {PERIOD_OPTIONS.map(option => (
91
+ <TouchableOpacity
92
+ key={option.key}
93
+ testID={`cash-period-${option.key}`}
94
+ style={[styles.chip, period === option.key && styles.chipActive]}
95
+ onPress={() => setPeriod(option.key)}>
96
+ <Text style={[styles.chipText, period === option.key && styles.chipTextActive]}>
97
+ {option.label}
98
+ </Text>
99
+ </TouchableOpacity>
100
+ ))}
101
+ </View>
102
+
103
+ {period === 'custom' && (
104
+ <View style={styles.customRow}>
105
+ <TextInput
106
+ style={styles.input}
107
+ placeholder="De (AAAA-MM-DD)"
108
+ value={from}
109
+ onChangeText={setFrom}
110
+ autoCapitalize="none"
111
+ />
112
+ <TextInput
113
+ style={styles.input}
114
+ placeholder="Até (AAAA-MM-DD)"
115
+ value={to}
116
+ onChangeText={setTo}
117
+ autoCapitalize="none"
118
+ />
119
+ <TouchableOpacity style={styles.apply} onPress={load}>
120
+ <Text style={styles.applyText}>Filtrar</Text>
121
+ </TouchableOpacity>
122
+ </View>
123
+ )}
124
+
125
+ {loading && <ActivityIndicator style={styles.loading} />}
126
+ {!!error && <Text style={styles.error}>{error}</Text>}
127
+
128
+ {data && (
129
+ <>
130
+ <Text style={styles.scope}>
131
+ {data.scope === 'user' ? 'Somente o seu caixa' : 'Caixa da empresa'} · {data.from}
132
+ {data.to !== data.from ? ` a ${data.to}` : ''}
133
+ </Text>
134
+
135
+ <View style={styles.totalCard}>
136
+ <Text style={styles.totalLabel}>Total geral</Text>
137
+ <Text style={styles.totalValue}>{Formatter.formatMoney(data.total?.balance || 0)}</Text>
138
+ <Text style={styles.totalSub}>
139
+ Entradas {Formatter.formatMoney(data.total?.inflow || 0)} · Saídas{' '}
140
+ {Formatter.formatMoney(data.total?.withdrawal || 0)} · {data.total?.quantity || 0} lançamentos
141
+ </Text>
142
+ </View>
143
+
144
+ {payments.length === 0 && !loading && (
145
+ <Text style={styles.empty}>Nenhuma movimentação no período.</Text>
146
+ )}
147
+
148
+ {payments.map(item => {
149
+ const target = buildCashDrilldownNavigation(item, data);
150
+
151
+ return (
152
+ <TouchableOpacity
153
+ key={`${item.paymentTypeId}-${item.paymentType}`}
154
+ testID={`cash-payment-${item.paymentTypeId}`}
155
+ style={styles.row}
156
+ disabled={!target}
157
+ activeOpacity={0.8}
158
+ onPress={() => target && navigation.navigate(target.routeName, target.params)}>
159
+ <View style={styles.rowInfo}>
160
+ <Text style={styles.rowTitle}>{item.paymentType}</Text>
161
+ <Text style={styles.rowSub}>{item.quantity} lançamentos</Text>
162
+ </View>
163
+ <Text style={styles.rowValue}>{Formatter.formatMoney(item.balance)}</Text>
164
+ {!!target && <Text style={styles.rowChevron}>›</Text>}
165
+ </TouchableOpacity>
166
+ );
167
+ })}
168
+ </>
169
+ )}
170
+ </ScrollView>
171
+ );
172
+ }
173
+
174
+ const styles = StyleSheet.create({
175
+ container: {flex: 1, backgroundColor: '#F8FAFC'},
176
+ content: {padding: 16, gap: 12},
177
+ chips: {flexDirection: 'row', flexWrap: 'wrap', gap: 8},
178
+ chip: {paddingHorizontal: 14, paddingVertical: 8, borderRadius: 18, backgroundColor: '#E2E8F0'},
179
+ chipActive: {backgroundColor: '#0891B2'},
180
+ chipText: {color: '#334155', fontWeight: '600'},
181
+ chipTextActive: {color: '#FFFFFF'},
182
+ customRow: {flexDirection: 'row', flexWrap: 'wrap', gap: 8, alignItems: 'center'},
183
+ input: {flex: 1, minWidth: 130, backgroundColor: '#FFFFFF', borderRadius: 8, borderWidth: 1, borderColor: '#CBD5E1', padding: 10},
184
+ apply: {backgroundColor: '#0891B2', borderRadius: 8, paddingHorizontal: 16, paddingVertical: 11},
185
+ applyText: {color: '#FFFFFF', fontWeight: '700'},
186
+ loading: {marginVertical: 8},
187
+ error: {color: '#B91C1C'},
188
+ scope: {color: '#64748B', fontSize: 12},
189
+ totalCard: {backgroundColor: '#FFFFFF', borderRadius: 12, padding: 16, borderWidth: 1, borderColor: '#E2E8F0'},
190
+ totalLabel: {color: '#64748B', fontSize: 12},
191
+ totalValue: {fontSize: 26, fontWeight: '800', color: '#0F766E'},
192
+ totalSub: {color: '#64748B', fontSize: 12, marginTop: 4},
193
+ empty: {textAlign: 'center', color: '#64748B', marginTop: 16},
194
+ row: {flexDirection: 'row', alignItems: 'center', backgroundColor: '#FFFFFF', borderRadius: 10, padding: 14, borderWidth: 1, borderColor: '#E2E8F0'},
195
+ rowInfo: {flex: 1},
196
+ rowTitle: {fontWeight: '700', color: '#0F172A'},
197
+ rowSub: {color: '#64748B', fontSize: 12},
198
+ rowValue: {fontWeight: '700', color: '#0F172A'},
199
+ rowChevron: {marginLeft: 8, fontSize: 22, color: '#94A3B8'},
200
+ });
@@ -1,6 +1,7 @@
1
1
  import ImportsPage from '@controleonline/ui-common/src/react/pages/Imports';
2
2
  import EntityLogPage from '@controleonline/ui-common/src/react/pages/EntityLogPage';
3
3
  import GenericLogPage from '@controleonline/ui-common/src/react/pages/GenericLogPage';
4
+ import CashRegisterSummary from '@controleonline/ui-common/src/react/pages/CashRegisterSummary';
4
5
 
5
6
  const commonRoutes = [
6
7
  {
@@ -24,6 +25,18 @@ const commonRoutes = [
24
25
  title: 'Logs',
25
26
  },
26
27
  },
28
+ {
29
+ name: 'CashRegisterSummary',
30
+ component: CashRegisterSummary,
31
+ options: {
32
+ showCompanyFilter: true,
33
+ companyFilterMode: 'icon',
34
+ headerShown: true,
35
+ headerBackVisible: true,
36
+ showBottomToolBar: true,
37
+ title: 'Caixa',
38
+ },
39
+ },
27
40
  {
28
41
  name: 'ImportsPage',
29
42
  component: ImportsPage,
@@ -0,0 +1,45 @@
1
+ const PERIODS = ['today', 'yesterday', 'week', 'month', 'custom'];
2
+ const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
3
+
4
+ const isValidDate = value => {
5
+ if (!DATE_PATTERN.test(String(value || ''))) return false;
6
+ const parsed = new Date(`${value}T00:00:00Z`);
7
+ return !Number.isNaN(parsed.getTime()) && parsed.toISOString().slice(0, 10) === value;
8
+ };
9
+
10
+ /**
11
+ * Builds the query string params of GET /cash-register/summary.
12
+ * Returns {error} when the selected period is incomplete or invalid.
13
+ */
14
+ const buildCashSummaryParams = ({companyId, period, from, to, device}) => {
15
+ if (!companyId) return {error: 'company'};
16
+ if (!PERIODS.includes(period)) return {error: 'period'};
17
+
18
+ const params = {provider: companyId, period};
19
+ if (period === 'custom') {
20
+ if (!isValidDate(from) || !isValidDate(to) || to < from) {
21
+ return {error: 'range'};
22
+ }
23
+ params.from = from;
24
+ params.to = to;
25
+ }
26
+ if (device) params.device = device;
27
+ return {params};
28
+ };
29
+
30
+ /**
31
+ * Params for navigating from a payment-type row to FinancialHubPage, keeping the
32
+ * period shown on the Caixa screen. Returns null for rows without payment type.
33
+ */
34
+ const buildCashDrilldownNavigation = (item, summary) => {
35
+ const paymentTypeId = Number(item?.paymentTypeId);
36
+ if (!Number.isInteger(paymentTypeId) || paymentTypeId <= 0) return null;
37
+ if (!isValidDate(summary?.from) || !isValidDate(summary?.to)) return null;
38
+
39
+ const cashFilter = {paymentTypeId, from: summary.from, to: summary.to};
40
+ if (summary.scope === 'user' && summary.userId) cashFilter.userId = summary.userId;
41
+
42
+ return {routeName: 'FinancialHubPage', params: {cashFilter}};
43
+ };
44
+
45
+ module.exports = {PERIODS, isValidDate, buildCashSummaryParams, buildCashDrilldownNavigation};
@@ -0,0 +1,41 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const {buildCashSummaryParams, buildCashDrilldownNavigation, isValidDate} = require('../../../react/utils/cashRegisterSummary');
4
+
5
+ test('requires company and a known period', () => {
6
+ assert.deepEqual(buildCashSummaryParams({period: 'today'}), {error: 'company'});
7
+ assert.deepEqual(buildCashSummaryParams({companyId: 1, period: 'x'}), {error: 'period'});
8
+ });
9
+
10
+ test('preset periods only send provider and period', () => {
11
+ assert.deepEqual(buildCashSummaryParams({companyId: 7, period: 'week', from: '2026-01-01'}), {
12
+ params: {provider: 7, period: 'week'},
13
+ });
14
+ });
15
+
16
+ test('custom period validates dates and order', () => {
17
+ assert.deepEqual(buildCashSummaryParams({companyId: 7, period: 'custom', from: '2026-11-01', to: '2026-10-01'}), {error: 'range'});
18
+ assert.deepEqual(buildCashSummaryParams({companyId: 7, period: 'custom', from: '2026-02-30', to: '2026-03-01'}), {error: 'range'});
19
+ assert.deepEqual(buildCashSummaryParams({companyId: 7, period: 'custom', from: '2026-10-01', to: '2026-10-31', device: 'abc'}), {
20
+ params: {provider: 7, period: 'custom', from: '2026-10-01', to: '2026-10-31', device: 'abc'},
21
+ });
22
+ assert.equal(isValidDate('2026-10-01'), true);
23
+ });
24
+
25
+ test('drill-down keeps payment type and period from the summary', () => {
26
+ const summary = {from: '2026-11-01', to: '2026-11-30', scope: 'company'};
27
+ assert.deepEqual(buildCashDrilldownNavigation({paymentTypeId: 63}, summary), {
28
+ routeName: 'FinancialHubPage',
29
+ params: {cashFilter: {paymentTypeId: 63, from: '2026-11-01', to: '2026-11-30'}},
30
+ });
31
+ });
32
+
33
+ test('drill-down carries the user when the scope is the user', () => {
34
+ const nav = buildCashDrilldownNavigation({paymentTypeId: 1}, {from: '2026-11-07', to: '2026-11-07', scope: 'user', userId: 6});
35
+ assert.equal(nav.params.cashFilter.userId, 6);
36
+ });
37
+
38
+ test('drill-down is disabled without payment type or valid period', () => {
39
+ assert.equal(buildCashDrilldownNavigation({paymentTypeId: null}, {from: '2026-11-01', to: '2026-11-30'}), null);
40
+ assert.equal(buildCashDrilldownNavigation({paymentTypeId: 1}, {from: 'x', to: '2026-11-30'}), null);
41
+ });