@controleonline/ui-common 1.2.117 → 1.2.119

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.117",
2
+ "version": "1.2.118",
3
3
  "rc": 1,
4
- "branch": "rc/1.2.117-rc.1",
5
- "baseMaster": "f25c6fab82270c930c7887fe75c00a1454078931",
4
+ "branch": "rc/1.2.118-rc.1",
5
+ "baseMaster": "cc9e32a018f490505b2199b8c313a5dd68f268cc",
6
6
  "tasks": [
7
7
  1339
8
8
  ],
9
9
  "frozen": true,
10
10
  "repositories": {
11
- "ControleOnline/ui-common": "fd99b408fe97b28c0f872deb6d8420a79a59d349"
11
+ "ControleOnline/ui-common": "f9a7beb517617a51e368a158bca02b33eed842cb"
12
12
  }
13
13
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@controleonline/ui-common",
3
- "version": "1.2.117",
3
+ "version": "1.2.119",
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",
@@ -291,12 +291,12 @@ export default function AiProviderConfigPage({route}) {
291
291
  style={styles.input}
292
292
  value={provider.workspace_id}
293
293
  onChangeText={v => updateField('workspace_id', v)}
294
- placeholder="UUID do workspace (ex.: 697fe52d-...)"
294
+ placeholder="wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
295
295
  autoCapitalize="none"
296
296
  editable={!saving}
297
297
  />
298
298
  <Text style={styles.helper}>
299
- Obrigatorio para API keys service (sk-ant-svc-...). Console Anthropic → Workspace settings.
299
+ Formato wrkspc_... (nao e o UUID da organizacao). Console → Settings → Workspaces → coluna ID. Obrigatorio para keys service (sk-ant-svc-...).
300
300
  </Text>
301
301
  </>
302
302
  ) : null}
@@ -0,0 +1,184 @@
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} 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 {buildCashSummaryParams} from '@controleonline/ui-common/src/react/utils/cashRegisterSummary';
17
+
18
+ const PERIOD_OPTIONS = [
19
+ {key: 'today', label: 'Hoje'},
20
+ {key: 'yesterday', label: 'Ontem'},
21
+ {key: 'week', label: 'Semana'},
22
+ {key: 'month', label: 'Mês'},
23
+ {key: 'custom', label: 'Período'},
24
+ ];
25
+
26
+ const ERROR_MESSAGES = {
27
+ range: 'Informe datas válidas (AAAA-MM-DD) e a data final não pode ser anterior à inicial.',
28
+ };
29
+
30
+ /**
31
+ * Caixa consolidado por forma de pagamento.
32
+ * Visibility (menu + user type) is enforced by the API; the "scope" returned
33
+ * tells whether the totals are for the whole company or only the current user.
34
+ * Refs: ControleOnline/ui-common#128
35
+ */
36
+ export default function CashRegisterSummary() {
37
+ const peopleStore = useStore('people');
38
+ const {currentCompany} = peopleStore.getters || {};
39
+ const [period, setPeriod] = useState('today');
40
+ const [from, setFrom] = useState('');
41
+ const [to, setTo] = useState('');
42
+ const [data, setData] = useState(null);
43
+ const [loading, setLoading] = useState(false);
44
+ const [error, setError] = useState(null);
45
+
46
+ const load = useCallback(async () => {
47
+ const {params, error: paramsError} = buildCashSummaryParams({
48
+ companyId: currentCompany?.id,
49
+ period,
50
+ from,
51
+ to,
52
+ });
53
+ if (paramsError) {
54
+ setError(ERROR_MESSAGES[paramsError] || null);
55
+ return;
56
+ }
57
+
58
+ setLoading(true);
59
+ setError(null);
60
+ try {
61
+ const response = await api.fetch('/cash-register/summary', {method: 'GET', params});
62
+ if (response?.error) throw new Error(response.error);
63
+ setData(response);
64
+ } catch (e) {
65
+ setData(null);
66
+ setError(e?.message || 'Não foi possível carregar o caixa.');
67
+ } finally {
68
+ setLoading(false);
69
+ }
70
+ }, [currentCompany?.id, period, from, to]);
71
+
72
+ useFocusEffect(
73
+ useCallback(() => {
74
+ if (period !== 'custom') load();
75
+ }, [load, period]),
76
+ );
77
+
78
+ const payments = data?.payments || [];
79
+
80
+ return (
81
+ <ScrollView
82
+ style={styles.container}
83
+ contentContainerStyle={styles.content}
84
+ refreshControl={<RefreshControl refreshing={loading} onRefresh={load} />}>
85
+ <View style={styles.chips}>
86
+ {PERIOD_OPTIONS.map(option => (
87
+ <TouchableOpacity
88
+ key={option.key}
89
+ testID={`cash-period-${option.key}`}
90
+ style={[styles.chip, period === option.key && styles.chipActive]}
91
+ onPress={() => setPeriod(option.key)}>
92
+ <Text style={[styles.chipText, period === option.key && styles.chipTextActive]}>
93
+ {option.label}
94
+ </Text>
95
+ </TouchableOpacity>
96
+ ))}
97
+ </View>
98
+
99
+ {period === 'custom' && (
100
+ <View style={styles.customRow}>
101
+ <TextInput
102
+ style={styles.input}
103
+ placeholder="De (AAAA-MM-DD)"
104
+ value={from}
105
+ onChangeText={setFrom}
106
+ autoCapitalize="none"
107
+ />
108
+ <TextInput
109
+ style={styles.input}
110
+ placeholder="Até (AAAA-MM-DD)"
111
+ value={to}
112
+ onChangeText={setTo}
113
+ autoCapitalize="none"
114
+ />
115
+ <TouchableOpacity style={styles.apply} onPress={load}>
116
+ <Text style={styles.applyText}>Filtrar</Text>
117
+ </TouchableOpacity>
118
+ </View>
119
+ )}
120
+
121
+ {loading && <ActivityIndicator style={styles.loading} />}
122
+ {!!error && <Text style={styles.error}>{error}</Text>}
123
+
124
+ {data && (
125
+ <>
126
+ <Text style={styles.scope}>
127
+ {data.scope === 'user' ? 'Somente o seu caixa' : 'Caixa da empresa'} · {data.from}
128
+ {data.to !== data.from ? ` a ${data.to}` : ''}
129
+ </Text>
130
+
131
+ <View style={styles.totalCard}>
132
+ <Text style={styles.totalLabel}>Total geral</Text>
133
+ <Text style={styles.totalValue}>{Formatter.formatMoney(data.total?.balance || 0)}</Text>
134
+ <Text style={styles.totalSub}>
135
+ Entradas {Formatter.formatMoney(data.total?.inflow || 0)} · Saídas{' '}
136
+ {Formatter.formatMoney(data.total?.withdrawal || 0)} · {data.total?.quantity || 0} lançamentos
137
+ </Text>
138
+ </View>
139
+
140
+ {payments.length === 0 && !loading && (
141
+ <Text style={styles.empty}>Nenhuma movimentação no período.</Text>
142
+ )}
143
+
144
+ {payments.map(item => (
145
+ <View key={`${item.paymentTypeId}-${item.paymentType}`} style={styles.row}>
146
+ <View style={styles.rowInfo}>
147
+ <Text style={styles.rowTitle}>{item.paymentType}</Text>
148
+ <Text style={styles.rowSub}>{item.quantity} lançamentos</Text>
149
+ </View>
150
+ <Text style={styles.rowValue}>{Formatter.formatMoney(item.balance)}</Text>
151
+ </View>
152
+ ))}
153
+ </>
154
+ )}
155
+ </ScrollView>
156
+ );
157
+ }
158
+
159
+ const styles = StyleSheet.create({
160
+ container: {flex: 1, backgroundColor: '#F8FAFC'},
161
+ content: {padding: 16, gap: 12},
162
+ chips: {flexDirection: 'row', flexWrap: 'wrap', gap: 8},
163
+ chip: {paddingHorizontal: 14, paddingVertical: 8, borderRadius: 18, backgroundColor: '#E2E8F0'},
164
+ chipActive: {backgroundColor: '#0891B2'},
165
+ chipText: {color: '#334155', fontWeight: '600'},
166
+ chipTextActive: {color: '#FFFFFF'},
167
+ customRow: {flexDirection: 'row', flexWrap: 'wrap', gap: 8, alignItems: 'center'},
168
+ input: {flex: 1, minWidth: 130, backgroundColor: '#FFFFFF', borderRadius: 8, borderWidth: 1, borderColor: '#CBD5E1', padding: 10},
169
+ apply: {backgroundColor: '#0891B2', borderRadius: 8, paddingHorizontal: 16, paddingVertical: 11},
170
+ applyText: {color: '#FFFFFF', fontWeight: '700'},
171
+ loading: {marginVertical: 8},
172
+ error: {color: '#B91C1C'},
173
+ scope: {color: '#64748B', fontSize: 12},
174
+ totalCard: {backgroundColor: '#FFFFFF', borderRadius: 12, padding: 16, borderWidth: 1, borderColor: '#E2E8F0'},
175
+ totalLabel: {color: '#64748B', fontSize: 12},
176
+ totalValue: {fontSize: 26, fontWeight: '800', color: '#0F766E'},
177
+ totalSub: {color: '#64748B', fontSize: 12, marginTop: 4},
178
+ empty: {textAlign: 'center', color: '#64748B', marginTop: 16},
179
+ row: {flexDirection: 'row', alignItems: 'center', backgroundColor: '#FFFFFF', borderRadius: 10, padding: 14, borderWidth: 1, borderColor: '#E2E8F0'},
180
+ rowInfo: {flex: 1},
181
+ rowTitle: {fontWeight: '700', color: '#0F172A'},
182
+ rowSub: {color: '#64748B', fontSize: 12},
183
+ rowValue: {fontWeight: '700', color: '#0F172A'},
184
+ });
@@ -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,30 @@
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
+ module.exports = {PERIODS, isValidDate, buildCashSummaryParams};
@@ -0,0 +1,23 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const {buildCashSummaryParams, 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
+ });