@controleonline/ui-common 1.2.119 → 1.2.121
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,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.120",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.2.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.2.120-rc.1",
|
|
5
|
+
"baseMaster": "d88e3ddf8397cc22b4dac04522cb000cf43cfeb8",
|
|
6
6
|
"tasks": [
|
|
7
|
-
|
|
7
|
+
128,
|
|
8
|
+
131
|
|
8
9
|
],
|
|
9
10
|
"frozen": true,
|
|
10
11
|
"repositories": {
|
|
11
|
-
"ControleOnline/ui-common": "
|
|
12
|
+
"ControleOnline/ui-common": "7998dc134d7be0e72c864ff0cb6408fd109c561c"
|
|
12
13
|
}
|
|
13
14
|
}
|
package/package.json
CHANGED
|
@@ -9,11 +9,16 @@ import {
|
|
|
9
9
|
TouchableOpacity,
|
|
10
10
|
View,
|
|
11
11
|
} from 'react-native';
|
|
12
|
-
import {useFocusEffect} from '@react-navigation/native';
|
|
12
|
+
import {useFocusEffect, useNavigation} from '@react-navigation/native';
|
|
13
13
|
import {useStore} from '@store';
|
|
14
14
|
import {api} from '@controleonline/ui-common/src/api';
|
|
15
15
|
import Formatter from '@controleonline/ui-common/src/utils/formatter';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
buildCashDrilldownNavigation,
|
|
18
|
+
buildCashSummaryParams,
|
|
19
|
+
resolveDeviceLabel,
|
|
20
|
+
sumDeviceBalances,
|
|
21
|
+
} from '@controleonline/ui-common/src/react/utils/cashRegisterSummary';
|
|
17
22
|
|
|
18
23
|
const PERIOD_OPTIONS = [
|
|
19
24
|
{key: 'today', label: 'Hoje'},
|
|
@@ -34,6 +39,7 @@ const ERROR_MESSAGES = {
|
|
|
34
39
|
* Refs: ControleOnline/ui-common#128
|
|
35
40
|
*/
|
|
36
41
|
export default function CashRegisterSummary() {
|
|
42
|
+
const navigation = useNavigation();
|
|
37
43
|
const peopleStore = useStore('people');
|
|
38
44
|
const {currentCompany} = peopleStore.getters || {};
|
|
39
45
|
const [period, setPeriod] = useState('today');
|
|
@@ -76,6 +82,8 @@ export default function CashRegisterSummary() {
|
|
|
76
82
|
);
|
|
77
83
|
|
|
78
84
|
const payments = data?.payments || [];
|
|
85
|
+
const devices = data?.devices || [];
|
|
86
|
+
const devicesTotal = sumDeviceBalances(devices);
|
|
79
87
|
|
|
80
88
|
return (
|
|
81
89
|
<ScrollView
|
|
@@ -141,15 +149,54 @@ export default function CashRegisterSummary() {
|
|
|
141
149
|
<Text style={styles.empty}>Nenhuma movimentação no período.</Text>
|
|
142
150
|
)}
|
|
143
151
|
|
|
144
|
-
{payments.map(item =>
|
|
145
|
-
|
|
152
|
+
{payments.map(item => {
|
|
153
|
+
const target = buildCashDrilldownNavigation(item, data);
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<TouchableOpacity
|
|
157
|
+
key={`${item.paymentTypeId}-${item.paymentType}`}
|
|
158
|
+
testID={`cash-payment-${item.paymentTypeId}`}
|
|
159
|
+
style={styles.row}
|
|
160
|
+
disabled={!target}
|
|
161
|
+
activeOpacity={0.8}
|
|
162
|
+
onPress={() => target && navigation.navigate(target.routeName, target.params)}>
|
|
163
|
+
<View style={styles.rowInfo}>
|
|
164
|
+
<Text style={styles.rowTitle}>{item.paymentType}</Text>
|
|
165
|
+
<Text style={styles.rowSub}>{item.quantity} lançamentos</Text>
|
|
166
|
+
</View>
|
|
167
|
+
<Text style={styles.rowValue}>{Formatter.formatMoney(item.balance)}</Text>
|
|
168
|
+
{!!target && <Text style={styles.rowChevron}>›</Text>}
|
|
169
|
+
</TouchableOpacity>
|
|
170
|
+
);
|
|
171
|
+
})}
|
|
172
|
+
|
|
173
|
+
<Text style={styles.sectionTitle}>Por dispositivo</Text>
|
|
174
|
+
|
|
175
|
+
{devices.length === 0 && !loading && (
|
|
176
|
+
<Text style={styles.empty}>Nenhuma movimentação por dispositivo no período.</Text>
|
|
177
|
+
)}
|
|
178
|
+
|
|
179
|
+
{devices.map(item => (
|
|
180
|
+
<View
|
|
181
|
+
key={`device-${item.deviceId ?? 'none'}`}
|
|
182
|
+
testID={`cash-device-${item.deviceId ?? 'none'}`}
|
|
183
|
+
style={styles.row}>
|
|
146
184
|
<View style={styles.rowInfo}>
|
|
147
|
-
<Text style={styles.rowTitle}>{item
|
|
185
|
+
<Text style={styles.rowTitle}>{resolveDeviceLabel(item)}</Text>
|
|
148
186
|
<Text style={styles.rowSub}>{item.quantity} lançamentos</Text>
|
|
149
187
|
</View>
|
|
150
188
|
<Text style={styles.rowValue}>{Formatter.formatMoney(item.balance)}</Text>
|
|
151
189
|
</View>
|
|
152
190
|
))}
|
|
191
|
+
|
|
192
|
+
{devices.length > 0 && (
|
|
193
|
+
<View style={styles.row}>
|
|
194
|
+
<View style={styles.rowInfo}>
|
|
195
|
+
<Text style={styles.rowTitle}>Total por dispositivo</Text>
|
|
196
|
+
</View>
|
|
197
|
+
<Text style={styles.rowValue}>{Formatter.formatMoney(devicesTotal)}</Text>
|
|
198
|
+
</View>
|
|
199
|
+
)}
|
|
153
200
|
</>
|
|
154
201
|
)}
|
|
155
202
|
</ScrollView>
|
|
@@ -175,10 +222,12 @@ const styles = StyleSheet.create({
|
|
|
175
222
|
totalLabel: {color: '#64748B', fontSize: 12},
|
|
176
223
|
totalValue: {fontSize: 26, fontWeight: '800', color: '#0F766E'},
|
|
177
224
|
totalSub: {color: '#64748B', fontSize: 12, marginTop: 4},
|
|
225
|
+
sectionTitle: {marginTop: 8, fontSize: 15, fontWeight: '800', color: '#0F172A'},
|
|
178
226
|
empty: {textAlign: 'center', color: '#64748B', marginTop: 16},
|
|
179
227
|
row: {flexDirection: 'row', alignItems: 'center', backgroundColor: '#FFFFFF', borderRadius: 10, padding: 14, borderWidth: 1, borderColor: '#E2E8F0'},
|
|
180
228
|
rowInfo: {flex: 1},
|
|
181
229
|
rowTitle: {fontWeight: '700', color: '#0F172A'},
|
|
182
230
|
rowSub: {color: '#64748B', fontSize: 12},
|
|
183
231
|
rowValue: {fontWeight: '700', color: '#0F172A'},
|
|
232
|
+
rowChevron: {marginLeft: 8, fontSize: 22, color: '#94A3B8'},
|
|
184
233
|
});
|
|
@@ -27,4 +27,36 @@ const buildCashSummaryParams = ({companyId, period, from, to, device}) => {
|
|
|
27
27
|
return {params};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
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
|
+
/** Label of a device row; rows without device are grouped as "Sem dispositivo". */
|
|
46
|
+
const resolveDeviceLabel = item => {
|
|
47
|
+
if (item?.deviceId === null || item?.deviceId === undefined) return 'Sem dispositivo';
|
|
48
|
+
return String(item?.label || item?.device || `#${item.deviceId}`);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** Sum of the device balances, rounded to cents (must equal the payment block total). */
|
|
52
|
+
const sumDeviceBalances = devices =>
|
|
53
|
+
Math.round((devices || []).reduce((sum, item) => sum + Number(item?.balance || 0), 0) * 100) / 100;
|
|
54
|
+
|
|
55
|
+
module.exports = {
|
|
56
|
+
PERIODS,
|
|
57
|
+
isValidDate,
|
|
58
|
+
buildCashSummaryParams,
|
|
59
|
+
buildCashDrilldownNavigation,
|
|
60
|
+
resolveDeviceLabel,
|
|
61
|
+
sumDeviceBalances,
|
|
62
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const test = require('node:test');
|
|
2
2
|
const assert = require('node:assert/strict');
|
|
3
|
-
const {buildCashSummaryParams, isValidDate} = require('../../../react/utils/cashRegisterSummary');
|
|
3
|
+
const {buildCashSummaryParams, buildCashDrilldownNavigation, isValidDate, resolveDeviceLabel, sumDeviceBalances} = require('../../../react/utils/cashRegisterSummary');
|
|
4
4
|
|
|
5
5
|
test('requires company and a known period', () => {
|
|
6
6
|
assert.deepEqual(buildCashSummaryParams({period: 'today'}), {error: 'company'});
|
|
@@ -21,3 +21,34 @@ test('custom period validates dates and order', () => {
|
|
|
21
21
|
});
|
|
22
22
|
assert.equal(isValidDate('2026-10-01'), true);
|
|
23
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
|
+
});
|
|
42
|
+
|
|
43
|
+
test('device label uses the backend label with fallbacks and groups rows without device', () => {
|
|
44
|
+
assert.equal(resolveDeviceLabel({deviceId: 4, label: 'Balcao (123456)'}), 'Balcao (123456)');
|
|
45
|
+
assert.equal(resolveDeviceLabel({deviceId: 4, device: 'web-6'}), 'web-6');
|
|
46
|
+
assert.equal(resolveDeviceLabel({deviceId: 4}), '#4');
|
|
47
|
+
assert.equal(resolveDeviceLabel({deviceId: null}), 'Sem dispositivo');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('device balances sum matches the payment total without float drift', () => {
|
|
51
|
+
assert.equal(sumDeviceBalances([{balance: 1140.01}, {balance: 2}]), 1142.01);
|
|
52
|
+
assert.equal(sumDeviceBalances([{balance: 0.1}, {balance: 0.2}]), 0.3);
|
|
53
|
+
assert.equal(sumDeviceBalances(undefined), 0);
|
|
54
|
+
});
|