@controleonline/ui-crm 1.0.42

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.
Files changed (141) hide show
  1. package/.github/actions/workers/manager/action.yml +147 -0
  2. package/.github/actions/workers/qa/action.yml +44 -0
  3. package/.github/actions/workers/security/action.yml +44 -0
  4. package/.github/actions/workers/technical-documenter/action.yml +51 -0
  5. package/.github/workflows/manager-worker.yml +167 -0
  6. package/.github/workflows/publish-npm.yml +40 -0
  7. package/.github/workflows/pull-request-checks.yml +29 -0
  8. package/.scrutinizer.yml +24 -0
  9. package/AGENTS.md +56 -0
  10. package/FUNDING.yml +1 -0
  11. package/docs/technical/Cliente-Vendedor-Vinculo-e-Permissoes.md +121 -0
  12. package/docs/technical/Income-Statements-Demonstrativo.md +38 -0
  13. package/docs/technical/Oportunidades-Ordenacao-por-Data-de-Retorno.md +134 -0
  14. package/docs/technical/Propostas-Filtro-de-Status.md +147 -0
  15. package/docs/technical/Royalties-a-pagar-Franqueado.md +51 -0
  16. package/docs/technical/Visao-Vendedor-Comissoes.md +58 -0
  17. package/docs/wiki.md +1 -0
  18. package/package.json +43 -0
  19. package/scripts/validate-wiki-pointer.cjs +13 -0
  20. package/src/react/components/AnimatedModal.js +149 -0
  21. package/src/react/components/AnimatedModal.styles.js +21 -0
  22. package/src/react/components/CreateContractModal.js +151 -0
  23. package/src/react/components/CreateContractModal.styles.js +43 -0
  24. package/src/react/hooks/useToastMessage.js +59 -0
  25. package/src/react/index.js +4 -0
  26. package/src/react/pages/ModelTemplatesPage.js +1461 -0
  27. package/src/react/pages/ModelTemplatesPage.styles.js +441 -0
  28. package/src/react/pages/comissions/IncomeStatementDetailsModal.js +102 -0
  29. package/src/react/pages/comissions/IncomeStatementsFilters.js +120 -0
  30. package/src/react/pages/comissions/SellerCommissionsPage.js +368 -0
  31. package/src/react/pages/comissions/SellerCommissionsPage.styles.js +219 -0
  32. package/src/react/pages/comissions/incomeStatementsHelpers.js +233 -0
  33. package/src/react/pages/comissions/index.js +309 -0
  34. package/src/react/pages/comissions/index.styles.js +381 -0
  35. package/src/react/pages/comissions/sellerCommissionsHelpers.js +222 -0
  36. package/src/react/pages/crm/components/CrmHeader.js +117 -0
  37. package/src/react/pages/crm/components/MarketingEventsSection.js +142 -0
  38. package/src/react/pages/crm/components/MarketingEventsSection.styles.js +105 -0
  39. package/src/react/pages/crm/components/OpportunityCard.js +138 -0
  40. package/src/react/pages/crm/components/OpportunityFormModal.js +279 -0
  41. package/src/react/pages/crm/components/OpportunityList.js +113 -0
  42. package/src/react/pages/crm/components/OpportunitySkeletons.js +53 -0
  43. package/src/react/pages/crm/components/ProviderSelectModal.js +166 -0
  44. package/src/react/pages/crm/components/SelectModal.js +178 -0
  45. package/src/react/pages/crm/conversation.js +342 -0
  46. package/src/react/pages/crm/conversation.styles.js +206 -0
  47. package/src/react/pages/crm/hooks/useCrmData.js +494 -0
  48. package/src/react/pages/crm/hooks/useOpportunityForms.js +306 -0
  49. package/src/react/pages/crm/index.js +262 -0
  50. package/src/react/pages/crm/index.styles.js +13 -0
  51. package/src/react/pages/crm/marketingEventsHelpers.js +41 -0
  52. package/src/react/pages/crm/styles/card.styles.js +178 -0
  53. package/src/react/pages/crm/styles/layout.styles.js +184 -0
  54. package/src/react/pages/crm/styles/modal.styles.js +347 -0
  55. package/src/react/pages/home/index.js +559 -0
  56. package/src/react/pages/home/index.styles.js +268 -0
  57. package/src/react/pages/proposals/CreateProposalsModal.js +466 -0
  58. package/src/react/pages/proposals/CreateProposalsModal.styles.js +344 -0
  59. package/src/react/pages/proposals/CreateProposalsPickers.js +187 -0
  60. package/src/react/pages/proposals/CreateProposalsProductSection.js +117 -0
  61. package/src/react/pages/proposals/ProposalCard.js +112 -0
  62. package/src/react/pages/proposals/ProposalDetails.js +263 -0
  63. package/src/react/pages/proposals/ProposalDetails.styles.js +195 -0
  64. package/src/react/pages/proposals/index.js +488 -0
  65. package/src/react/pages/proposals/index.styles.js +248 -0
  66. package/src/react/pages/proposals/proposalListHelpers.js +216 -0
  67. package/src/react/pages/proposals/proposalNavigation.js +26 -0
  68. package/src/react/pages/royalties/ReceivablePage.js +233 -0
  69. package/src/react/pages/royalties/RoyaltiesPayablePage.js +260 -0
  70. package/src/react/pages/royalties/index.js +2 -0
  71. package/src/react/pages/royalties/royaltiesReceivableHelpers.js +68 -0
  72. package/src/react/pages/settings/GeneralSettings.js +317 -0
  73. package/src/react/pages/settings/GeneralSettings.shared.js +490 -0
  74. package/src/react/pages/settings/GeneralSettings.styles.js +746 -0
  75. package/src/react/pages/settings/GeneralSettingsSection.js +57 -0
  76. package/src/react/pages/settings/generalSettingsActiveTab.js +85 -0
  77. package/src/react/pages/settings/sections/CrmSection.js +281 -0
  78. package/src/react/pages/settings/sections/DeviceRuntimeFooterSection.js +128 -0
  79. package/src/react/pages/settings/sections/DisplayPreparationSection.js +155 -0
  80. package/src/react/pages/settings/sections/IntegrationsSection.js +392 -0
  81. package/src/react/pages/settings/sections/LogSection.js +322 -0
  82. package/src/react/pages/settings/sections/LoginSection.js +137 -0
  83. package/src/react/pages/settings/sections/LoyaltyProductPicker.js +230 -0
  84. package/src/react/pages/settings/sections/LoyaltySection.js +451 -0
  85. package/src/react/pages/settings/sections/MaintenanceSection.js +205 -0
  86. package/src/react/pages/settings/sections/MapsSection.js +629 -0
  87. package/src/react/pages/settings/sections/MenuCatalogSection.js +405 -0
  88. package/src/react/pages/settings/sections/OperationsSection.js +303 -0
  89. package/src/react/pages/settings/sections/OrderPaymentSection.js +379 -0
  90. package/src/react/pages/settings/sections/OrderPrintSection.js +308 -0
  91. package/src/react/pages/settings/sections/ShopSection.js +490 -0
  92. package/src/react/pages/settings/sections/shop/FranchiseMapPreview.js +124 -0
  93. package/src/react/pages/settings/sections/shop/ShopDomainCreateForm.js +57 -0
  94. package/src/react/pages/settings/sections/shop/ShopDomainPanel.js +184 -0
  95. package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.js +237 -0
  96. package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.styles.js +256 -0
  97. package/src/react/pages/settings/sections/shop/ShopDomainTabs.js +61 -0
  98. package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +526 -0
  99. package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +426 -0
  100. package/src/react/pages/settings/sections/shop/ShopSettingsSection.js +10 -0
  101. package/src/react/pages/settings/sections/shop/mapsFranchiseMapHelpers.js +163 -0
  102. package/src/react/pages/settings/sections/shop/shopDomainShowcasesUtils.js +68 -0
  103. package/src/react/pages/settings/sections/shop/shopFranchiseVisibility.js +158 -0
  104. package/src/react/pages/settings/sections/shop/shopSettingsShared.js +427 -0
  105. package/src/react/router/routes.js +135 -0
  106. package/src/react/utils/opportunityDate.js +82 -0
  107. package/src/react/utils/opportunityEditorReferences.js +76 -0
  108. package/src/react/utils/opportunityEmptyState.js +20 -0
  109. package/src/react/utils/opportunityPeople.js +111 -0
  110. package/src/react/utils/opportunityPhone.js +82 -0
  111. package/src/react/utils/opportunityStage.js +30 -0
  112. package/src/react/utils/opportunityStatusFilter.js +54 -0
  113. package/src/react/utils/proposalCreateHelpers.js +61 -0
  114. package/src/react/utils/proposalProductSelection.js +71 -0
  115. package/src/react/utils/royaltiesPayableParams.js +37 -0
  116. package/src/react/utils/translateWithFallback.js +42 -0
  117. package/src/store/crm/index.js +2 -0
  118. package/src/store/model/index.js +104 -0
  119. package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +149 -0
  120. package/src/tests/browser/crm/crm-index-status-filter.spec.js +263 -0
  121. package/src/tests/browser/crm/crm-opportunity-category-editor.spec.js +269 -0
  122. package/src/tests/browser/crm/royalties-payable.spec.js +122 -0
  123. package/src/tests/browser/crm/royalties-receivable.spec.js +121 -0
  124. package/src/tests/browser/crm/seller-commissions.spec.js +214 -0
  125. package/src/tests/browser/manager/general-settings-maps.spec.js +400 -0
  126. package/src/tests/react/pages/comissions/incomeStatementsHelpers.test.js +181 -0
  127. package/src/tests/react/pages/comissions/sellerCommissionsHelpers.test.js +132 -0
  128. package/src/tests/react/pages/crm/marketingEventsHelpers.test.cjs +53 -0
  129. package/src/tests/react/pages/crm/opportunitySearchParams.test.cjs +44 -0
  130. package/src/tests/react/pages/proposals/navigation.test.js +71 -0
  131. package/src/tests/react/pages/proposals/proposalListHelpers.test.js +42 -0
  132. package/src/tests/react/pages/royalties/royaltiesReceivableHelpers.test.js +60 -0
  133. package/src/tests/react/pages/settings/generalSettings.shared.test.js +102 -0
  134. package/src/tests/react/pages/settings/sections/shop/shopDomainShowcasesUtils.test.js +60 -0
  135. package/src/tests/react/pages/settings/sections/shop/shopFranchiseVisibility.test.js +80 -0
  136. package/src/tests/react/utils/opportunityEditorReferences.test.js +70 -0
  137. package/src/tests/react/utils/opportunityEmptyState.test.js +39 -0
  138. package/src/tests/react/utils/opportunityStatusFilter.test.cjs +81 -0
  139. package/src/tests/react/utils/proposalCreateHelpers.test.js +25 -0
  140. package/src/tests/react/utils/proposalProductSelection.test.js +76 -0
  141. package/src/tests/react/utils/royaltiesPayableParams.test.js +44 -0
@@ -0,0 +1,381 @@
1
+ import { StyleSheet } from 'react-native';
2
+
3
+ const styles = StyleSheet.create({
4
+ page: {
5
+ flex: 1,
6
+ backgroundColor: '#F1F5F9',
7
+ },
8
+ filtersContainer: {
9
+ backgroundColor: '#FFFFFF',
10
+ borderBottomWidth: 1,
11
+ borderBottomColor: '#E2E8F0',
12
+ paddingHorizontal: 12,
13
+ paddingVertical: 10,
14
+ },
15
+ yearRow: {
16
+ flexDirection: 'row',
17
+ justifyContent: 'space-between',
18
+ alignItems: 'center',
19
+ marginBottom: 8,
20
+ },
21
+ filterLabel: {
22
+ color: '#334155',
23
+ fontWeight: '700',
24
+ fontSize: 13,
25
+ },
26
+ yearControl: {
27
+ flexDirection: 'row',
28
+ alignItems: 'center',
29
+ },
30
+ yearStepButton: {
31
+ width: 28,
32
+ height: 28,
33
+ borderRadius: 8,
34
+ backgroundColor: '#E2E8F0',
35
+ alignItems: 'center',
36
+ justifyContent: 'center',
37
+ marginHorizontal: 4,
38
+ },
39
+ yearStepButtonText: {
40
+ color: '#334155',
41
+ fontSize: 18,
42
+ lineHeight: 18,
43
+ fontWeight: '700',
44
+ },
45
+ yearInput: {
46
+ width: 70,
47
+ height: 32,
48
+ borderWidth: 1,
49
+ borderColor: '#CBD5E1',
50
+ borderRadius: 8,
51
+ textAlign: 'center',
52
+ color: '#0F172A',
53
+ fontWeight: '700',
54
+ backgroundColor: '#fff',
55
+ paddingVertical: 0,
56
+ marginHorizontal: 2,
57
+ },
58
+ monthList: {
59
+ paddingVertical: 2,
60
+ },
61
+ monthChip: {
62
+ borderWidth: 1,
63
+ borderColor: '#CBD5E1',
64
+ backgroundColor: '#F8FAFC',
65
+ borderRadius: 999,
66
+ paddingHorizontal: 12,
67
+ paddingVertical: 6,
68
+ marginRight: 8,
69
+ },
70
+ monthChipActive: {
71
+ borderColor: '#0EA5E9',
72
+ backgroundColor: '#E0F2FE',
73
+ },
74
+ monthChipText: {
75
+ color: '#475569',
76
+ fontSize: 12,
77
+ fontWeight: '600',
78
+ },
79
+ monthChipTextActive: {
80
+ color: '#0369A1',
81
+ fontWeight: '700',
82
+ },
83
+ centerState: {
84
+ flex: 1,
85
+ alignItems: 'center',
86
+ justifyContent: 'center',
87
+ padding: 20,
88
+ },
89
+ errorTitle: {
90
+ fontSize: 20,
91
+ fontWeight: '700',
92
+ color: '#c10015',
93
+ marginBottom: 6,
94
+ },
95
+ errorSubtitle: {
96
+ color: '#c10015',
97
+ marginBottom: 14,
98
+ },
99
+ retryButton: {
100
+ backgroundColor: '#007AFF',
101
+ borderRadius: 8,
102
+ paddingVertical: 10,
103
+ paddingHorizontal: 16,
104
+ },
105
+ retryButtonText: {
106
+ color: '#FFFFFF',
107
+ fontWeight: '700',
108
+ },
109
+ emptyText: {
110
+ color: '#64748B',
111
+ fontSize: 15,
112
+ fontWeight: '500',
113
+ },
114
+ scrollContent: {
115
+ paddingBottom: 20,
116
+ },
117
+ listContainer: {
118
+ padding: 10,
119
+ },
120
+ card: {
121
+ backgroundColor: '#FFFFFF',
122
+ borderRadius: 10,
123
+ padding: 14,
124
+ marginBottom: 10,
125
+ borderWidth: 1,
126
+ borderColor: '#E2E8F0',
127
+ },
128
+ cardHeader: {
129
+ flexDirection: 'row',
130
+ justifyContent: 'space-between',
131
+ alignItems: 'center',
132
+ },
133
+ cardTitle: {
134
+ fontSize: 16,
135
+ fontWeight: '700',
136
+ color: '#0F172A',
137
+ },
138
+ statusPill: {
139
+ color: '#FFFFFF',
140
+ fontSize: 11,
141
+ fontWeight: '700',
142
+ paddingHorizontal: 8,
143
+ paddingVertical: 3,
144
+ borderRadius: 999,
145
+ },
146
+ amount: {
147
+ marginTop: 8,
148
+ marginBottom: 8,
149
+ fontSize: 17,
150
+ fontWeight: '700',
151
+ color: '#007AFF',
152
+ },
153
+ metaLine: {
154
+ color: '#475569',
155
+ marginBottom: 4,
156
+ },
157
+ modalContainer: {
158
+ backgroundColor: '#fff',
159
+ borderTopLeftRadius: 24,
160
+ borderTopRightRadius: 24,
161
+ maxHeight: '80%',
162
+ width: '100%',
163
+ shadowColor: '#000',
164
+ shadowOffset: { width: 0, height: -4 },
165
+ shadowOpacity: 0.1,
166
+ shadowRadius: 12,
167
+ elevation: 10,
168
+ },
169
+ modalHeader: {
170
+ flexDirection: 'row',
171
+ justifyContent: 'space-between',
172
+ alignItems: 'center',
173
+ paddingHorizontal: 24,
174
+ paddingVertical: 20,
175
+ borderBottomWidth: 1,
176
+ borderBottomColor: '#F1F5F9',
177
+ },
178
+ modalTitle: {
179
+ fontSize: 20,
180
+ fontWeight: '700',
181
+ color: '#0F172A',
182
+ },
183
+ modalCloseButton: {
184
+ width: 32,
185
+ height: 32,
186
+ borderRadius: 16,
187
+ backgroundColor: '#F1F5F9',
188
+ alignItems: 'center',
189
+ justifyContent: 'center',
190
+ },
191
+ modalBody: {
192
+ padding: 24,
193
+ gap: 16,
194
+ },
195
+ modalSummaryCard: {
196
+ backgroundColor: '#F8FAFC',
197
+ borderRadius: 14,
198
+ padding: 16,
199
+ borderWidth: 1,
200
+ borderColor: '#E2E8F0',
201
+ },
202
+ modalAmount: {
203
+ fontSize: 24,
204
+ fontWeight: '700',
205
+ color: '#007AFF',
206
+ marginBottom: 12,
207
+ },
208
+ modalStatusPill: {
209
+ alignSelf: 'flex-start',
210
+ paddingHorizontal: 10,
211
+ paddingVertical: 5,
212
+ borderRadius: 999,
213
+ },
214
+ modalStatusText: {
215
+ color: '#FFFFFF',
216
+ fontSize: 11,
217
+ fontWeight: '700',
218
+ },
219
+ modalDetailsCard: {
220
+ backgroundColor: '#FFFFFF',
221
+ borderRadius: 14,
222
+ borderWidth: 1,
223
+ borderColor: '#E2E8F0',
224
+ overflow: 'hidden',
225
+ },
226
+ modalDetailRow: {
227
+ flexDirection: 'row',
228
+ justifyContent: 'space-between',
229
+ alignItems: 'center',
230
+ paddingHorizontal: 16,
231
+ paddingVertical: 14,
232
+ borderBottomWidth: 1,
233
+ borderBottomColor: '#F1F5F9',
234
+ gap: 12,
235
+ },
236
+ modalDetailLabel: {
237
+ fontSize: 13,
238
+ fontWeight: '600',
239
+ color: '#64748B',
240
+ },
241
+ modalDetailValue: {
242
+ flex: 1,
243
+ textAlign: 'right',
244
+ fontSize: 14,
245
+ fontWeight: '600',
246
+ color: '#0F172A',
247
+ },
248
+ modalSectionTitle: {
249
+ fontSize: 14,
250
+ fontWeight: '700',
251
+ color: '#0F172A',
252
+ paddingHorizontal: 16,
253
+ paddingTop: 14,
254
+ paddingBottom: 10,
255
+ },
256
+ modalGroupBlock: {
257
+ paddingHorizontal: 16,
258
+ paddingBottom: 12,
259
+ },
260
+ modalGroupHeader: {
261
+ flexDirection: 'row',
262
+ justifyContent: 'space-between',
263
+ alignItems: 'center',
264
+ marginBottom: 6,
265
+ },
266
+ modalGroupTitle: {
267
+ flex: 1,
268
+ color: '#0F172A',
269
+ fontSize: 13,
270
+ fontWeight: '600',
271
+ marginRight: 8,
272
+ },
273
+ modalGroupAmount: {
274
+ color: '#0F172A',
275
+ fontSize: 13,
276
+ fontWeight: '700',
277
+ },
278
+ modalCategoryRow: {
279
+ flexDirection: 'row',
280
+ justifyContent: 'space-between',
281
+ alignItems: 'center',
282
+ paddingVertical: 4,
283
+ },
284
+ modalCategoryText: {
285
+ flex: 1,
286
+ color: '#475569',
287
+ fontSize: 12,
288
+ marginRight: 8,
289
+ },
290
+ modalCategoryAmount: {
291
+ color: '#475569',
292
+ fontSize: 12,
293
+ fontWeight: '600',
294
+ },
295
+ modalEmptyText: {
296
+ color: '#64748B',
297
+ fontSize: 12,
298
+ paddingHorizontal: 16,
299
+ paddingBottom: 14,
300
+ },
301
+ modalFooter: {
302
+ padding: 20,
303
+ borderTopWidth: 1,
304
+ borderTopColor: '#E9ECEF',
305
+ },
306
+ modalPrimaryButton: {
307
+ paddingVertical: 14,
308
+ borderRadius: 12,
309
+ backgroundColor: '#007AFF',
310
+ alignItems: 'center',
311
+ },
312
+ modalPrimaryButtonText: {
313
+ fontSize: 16,
314
+ fontWeight: '600',
315
+ color: '#FFFFFF',
316
+ },
317
+ monthListContent: {
318
+ paddingRight: 8,
319
+ alignItems: 'center',
320
+ },
321
+ natureList: {
322
+ paddingVertical: 2,
323
+ marginTop: 4,
324
+ },
325
+ categoryFilterRow: {
326
+ flexDirection: 'row',
327
+ alignItems: 'center',
328
+ marginTop: 8,
329
+ borderWidth: 1,
330
+ borderColor: '#CBD5E1',
331
+ borderRadius: 10,
332
+ backgroundColor: '#F8FAFC',
333
+ paddingHorizontal: 10,
334
+ height: 36,
335
+ },
336
+ categoryFilterIcon: {
337
+ marginRight: 6,
338
+ },
339
+ categoryFilterInput: {
340
+ flex: 1,
341
+ color: '#0F172A',
342
+ fontSize: 13,
343
+ paddingVertical: 0,
344
+ },
345
+ emptyTitle: {
346
+ marginTop: 12,
347
+ fontSize: 16,
348
+ fontWeight: '700',
349
+ color: '#334155',
350
+ textAlign: 'center',
351
+ },
352
+ emptySubtitle: {
353
+ marginTop: 6,
354
+ fontSize: 13,
355
+ color: '#64748B',
356
+ textAlign: 'center',
357
+ paddingHorizontal: 24,
358
+ },
359
+ listScroll: {
360
+ flex: 1,
361
+ },
362
+ listContent: {
363
+ padding: 12,
364
+ paddingBottom: 24,
365
+ },
366
+ cardsWrap: {
367
+ gap: 10,
368
+ },
369
+ });
370
+
371
+ export default styles;
372
+
373
+ export const inlineStyle_353_8 = {
374
+ justifyContent: 'flex-end',
375
+ };
376
+
377
+ export const inlineStyle_365_47 = {
378
+ paddingBottom: 20,
379
+ };
380
+
381
+
@@ -0,0 +1,222 @@
1
+ /*
2
+ * Seller commissions helpers — pure functions for grouping, filtering and
3
+ * normalizing invoices of type `comission` (vendedor recebe da empresa).
4
+ */
5
+
6
+ export const MONTH_OPTION_IDS = [
7
+ '0',
8
+ '1',
9
+ '2',
10
+ '3',
11
+ '4',
12
+ '5',
13
+ '6',
14
+ '7',
15
+ '8',
16
+ '9',
17
+ '10',
18
+ '11',
19
+ '12',
20
+ ];
21
+
22
+ export const buildMonthOptions = translate => {
23
+ const t = typeof translate === 'function' ? translate : () => '';
24
+ return [
25
+ {id: '0', label: t('people', 'month', 'all') || 'Todos'},
26
+ {id: '1', label: t('people', 'month', 'jan') || 'Jan'},
27
+ {id: '2', label: t('people', 'month', 'feb') || 'Fev'},
28
+ {id: '3', label: t('people', 'month', 'mar') || 'Mar'},
29
+ {id: '4', label: t('people', 'month', 'apr') || 'Abr'},
30
+ {id: '5', label: t('people', 'month', 'may') || 'Mai'},
31
+ {id: '6', label: t('people', 'month', 'jun') || 'Jun'},
32
+ {id: '7', label: t('people', 'month', 'jul') || 'Jul'},
33
+ {id: '8', label: t('people', 'month', 'aug') || 'Ago'},
34
+ {id: '9', label: t('people', 'month', 'sep') || 'Set'},
35
+ {id: '10', label: t('people', 'month', 'oct') || 'Out'},
36
+ {id: '11', label: t('people', 'month', 'nov') || 'Nov'},
37
+ {id: '12', label: t('people', 'month', 'dec') || 'Dez'},
38
+ ];
39
+ };
40
+
41
+ export const formatCurrency = value =>
42
+ new Intl.NumberFormat('pt-BR', {
43
+ style: 'currency',
44
+ currency: 'BRL',
45
+ }).format(Number(value || 0));
46
+
47
+ /**
48
+ * Resolve invoice date (dueDate preferred, then invoice_date / invoiceDate).
49
+ * @returns {Date|null}
50
+ */
51
+ export const resolveInvoiceDate = invoice => {
52
+ const raw =
53
+ invoice?.dueDate ||
54
+ invoice?.due_date ||
55
+ invoice?.invoice_date ||
56
+ invoice?.invoiceDate ||
57
+ null;
58
+ if (!raw) return null;
59
+ const date = raw instanceof Date ? raw : new Date(raw);
60
+ return Number.isNaN(date.getTime()) ? null : date;
61
+ };
62
+
63
+ /**
64
+ * Extract client People from a comission invoice via linked orders.
65
+ * Supports shapes: order[] → {order:{client}} | {client} | nested hydra.
66
+ */
67
+ export const extractClientFromInvoice = invoice => {
68
+ const orderLinks = Array.isArray(invoice?.order)
69
+ ? invoice.order
70
+ : invoice?.order
71
+ ? [invoice.order]
72
+ : [];
73
+
74
+ for (const link of orderLinks) {
75
+ const order = link?.order || link;
76
+ const client = order?.client || order?.client_id || null;
77
+ if (!client) continue;
78
+ if (typeof client === 'object') {
79
+ const id = client.id || client.value || null;
80
+ if (id == null) continue;
81
+ return {
82
+ id: Number(id) || id,
83
+ name: client.name || client.alias || client.label || `#${id}`,
84
+ alias: client.alias || '',
85
+ };
86
+ }
87
+ const id = Number(client) || client;
88
+ return {id, name: `#${id}`, alias: ''};
89
+ }
90
+ return null;
91
+ };
92
+
93
+ export const normalizeComissionList = response => {
94
+ if (Array.isArray(response)) return response;
95
+ if (Array.isArray(response?.member)) return response.member;
96
+ if (Array.isArray(response?.['hydra:member'])) return response['hydra:member'];
97
+ if (response && typeof response === 'object') {
98
+ const values = Object.values(response);
99
+ if (values.every(v => v && typeof v === 'object' && (v.id != null || v.price != null))) {
100
+ return values;
101
+ }
102
+ }
103
+ return [];
104
+ };
105
+
106
+ /**
107
+ * Build request params for GET /finance/comission (or invoices?invoiceType=comission).
108
+ * Seller is always the receiver; optional client and period.
109
+ */
110
+ export const buildComissionRequestParams = ({
111
+ year,
112
+ month,
113
+ receiverId,
114
+ clientId,
115
+ } = {}) => {
116
+ const params = {
117
+ invoiceType: 'comission',
118
+ };
119
+
120
+ if (receiverId != null && String(receiverId).trim() !== '') {
121
+ params.receiver = receiverId;
122
+ }
123
+
124
+ const yearNumber = parseInt(year, 10);
125
+ if (yearNumber >= 2000 && yearNumber <= 2100) {
126
+ params.year = yearNumber;
127
+ }
128
+
129
+ const monthNumber = parseInt(month, 10);
130
+ if (monthNumber >= 1 && monthNumber <= 12) {
131
+ params.month = monthNumber;
132
+ }
133
+
134
+ if (clientId != null && String(clientId).trim() !== '') {
135
+ params.client = clientId;
136
+ }
137
+
138
+ return params;
139
+ };
140
+
141
+ /**
142
+ * Client-side filter by client id (fallback when API ignores client param).
143
+ */
144
+ export const filterInvoicesByClient = (invoices, clientId) => {
145
+ if (clientId == null || String(clientId).trim() === '') {
146
+ return Array.isArray(invoices) ? invoices : [];
147
+ }
148
+ const target = String(clientId);
149
+ return (Array.isArray(invoices) ? invoices : []).filter(invoice => {
150
+ const client = extractClientFromInvoice(invoice);
151
+ return client != null && String(client.id) === target;
152
+ });
153
+ };
154
+
155
+ /**
156
+ * Group invoices by calendar month of the resolved date; optionally restrict to one month.
157
+ * Returns rows sorted by month ascending with total (seller receives).
158
+ */
159
+ export const groupCommissionsByMonth = (
160
+ invoices,
161
+ {selectedMonth = '0', year = null, monthLabelById = {}} = {},
162
+ ) => {
163
+ const list = Array.isArray(invoices) ? invoices : [];
164
+ const yearNumber = year != null ? parseInt(year, 10) : null;
165
+ const selectedMonthNumber = parseInt(selectedMonth, 10);
166
+
167
+ const buckets = {};
168
+
169
+ list.forEach(invoice => {
170
+ const date = resolveInvoiceDate(invoice);
171
+ if (!date) return;
172
+ if (yearNumber && date.getFullYear() !== yearNumber) return;
173
+
174
+ const monthNumber = date.getMonth() + 1;
175
+ if (
176
+ selectedMonthNumber >= 1 &&
177
+ selectedMonthNumber <= 12 &&
178
+ monthNumber !== selectedMonthNumber
179
+ ) {
180
+ return;
181
+ }
182
+
183
+ if (!buckets[monthNumber]) {
184
+ buckets[monthNumber] = {
185
+ month: monthNumber,
186
+ label:
187
+ monthLabelById[String(monthNumber)] ||
188
+ String(monthNumber).padStart(2, '0'),
189
+ total: 0,
190
+ count: 0,
191
+ invoices: [],
192
+ };
193
+ }
194
+
195
+ const price = Number(invoice?.price ?? invoice?.amount ?? 0);
196
+ buckets[monthNumber].total += price;
197
+ buckets[monthNumber].count += 1;
198
+ buckets[monthNumber].invoices.push(invoice);
199
+ });
200
+
201
+ return Object.keys(buckets)
202
+ .map(key => Number(key))
203
+ .sort((a, b) => a - b)
204
+ .map(monthNumber => buckets[monthNumber]);
205
+ };
206
+
207
+ /**
208
+ * Unique clients present in the invoice list (for filter dropdown).
209
+ */
210
+ export const collectClientsFromInvoices = invoices => {
211
+ const map = new Map();
212
+ (Array.isArray(invoices) ? invoices : []).forEach(invoice => {
213
+ const client = extractClientFromInvoice(invoice);
214
+ if (!client || client.id == null) return;
215
+ if (!map.has(String(client.id))) {
216
+ map.set(String(client.id), client);
217
+ }
218
+ });
219
+ return Array.from(map.values()).sort((a, b) =>
220
+ String(a.name).localeCompare(String(b.name), 'pt-BR'),
221
+ );
222
+ };
@@ -0,0 +1,117 @@
1
+ import React from 'react';
2
+ import { ScrollView, TextInput, TouchableOpacity, View } from 'react-native';
3
+ import { Text } from 'react-native-animatable';
4
+ import Icon from 'react-native-vector-icons/FontAwesome';
5
+ import IconAdd from 'react-native-vector-icons/MaterialIcons';
6
+
7
+ import { colors } from '@controleonline/../../src/styles/colors';
8
+ import { getColorWithAlpha } from '../../../utils/opportunityStage';
9
+ import styles from '../index.styles';
10
+
11
+ const CrmHeader = ({
12
+ getStatusFilterKey,
13
+ getStatusFilterLabel,
14
+ onAddOpportunity,
15
+ searchText,
16
+ selectedStatusFilterKey,
17
+ setSearchText,
18
+ setSelectedStatusFilterKey,
19
+ showStatusFilterSkeleton,
20
+ status,
21
+ }) => (
22
+ <View style={styles.subHeader}>
23
+ <View style={styles.searchRow}>
24
+ <View style={styles.searchInputContainer}>
25
+ <Icon name="search" size={16} color="#94A3B8" />
26
+ <TextInput
27
+ style={styles.searchInput}
28
+ placeholder={global.t?.t('people', 'search', 'placeholder')}
29
+ placeholderTextColor="#94A3B8"
30
+ value={searchText}
31
+ onChangeText={setSearchText}
32
+ underlineColorAndroid="transparent"
33
+ />
34
+ {searchText.length > 0 && (
35
+ <TouchableOpacity
36
+ onPress={() => setSearchText('')}
37
+ style={styles.clearSearchButton}>
38
+ <Icon name="times-circle" size={16} color="#94A3B8" />
39
+ </TouchableOpacity>
40
+ )}
41
+ </View>
42
+ <TouchableOpacity style={styles.addButton} onPress={onAddOpportunity}>
43
+ <IconAdd name="add" size={24} color="#FFFFFF" />
44
+ </TouchableOpacity>
45
+ </View>
46
+
47
+ <View style={styles.statusFilterSection}>
48
+ <Text style={styles.statusFilterLabel}>
49
+ {global.t?.t('people', 'filter', 'status')}
50
+ </Text>
51
+ <ScrollView
52
+ horizontal
53
+ showsHorizontalScrollIndicator={false}
54
+ contentContainerStyle={styles.statusFilterRow}>
55
+ {showStatusFilterSkeleton ? (
56
+ [1, 2, 3, 4].map(key => (
57
+ <View
58
+ key={`status-skeleton-${key}`}
59
+ style={[styles.skeletonLine, styles.statusChipSkeleton]}
60
+ />
61
+ ))
62
+ ) : (
63
+ <>
64
+ <TouchableOpacity
65
+ onPress={() => setSelectedStatusFilterKey('')}
66
+ style={[
67
+ styles.statusFilterChip,
68
+ !selectedStatusFilterKey && styles.statusFilterChipActive,
69
+ ]}>
70
+ <Text
71
+ style={[
72
+ styles.statusFilterChipText,
73
+ !selectedStatusFilterKey && styles.statusFilterChipTextActive,
74
+ ]}>
75
+ {global.t?.t('people', 'filter', 'all')}
76
+ </Text>
77
+ </TouchableOpacity>
78
+
79
+ {status.map(item => {
80
+ const statusKey = getStatusFilterKey(item);
81
+ const isActive =
82
+ selectedStatusFilterKey &&
83
+ selectedStatusFilterKey === statusKey;
84
+ const chipColor = item?.color || colors.primary;
85
+
86
+ return (
87
+ <TouchableOpacity
88
+ key={statusKey || String(item.id || item.status)}
89
+ onPress={() => setSelectedStatusFilterKey(statusKey)}
90
+ style={[
91
+ styles.statusFilterChip,
92
+ isActive && styles.statusFilterChipActive,
93
+ {
94
+ borderColor: isActive ? chipColor : '#DCE3EC',
95
+ backgroundColor: isActive
96
+ ? getColorWithAlpha(chipColor, '24')
97
+ : '#F8FAFC',
98
+ },
99
+ ]}>
100
+ <Text
101
+ style={[
102
+ styles.statusFilterChipText,
103
+ { color: isActive ? chipColor : '#64748B' },
104
+ ]}>
105
+ {getStatusFilterLabel(item)}
106
+ </Text>
107
+ </TouchableOpacity>
108
+ );
109
+ })}
110
+ </>
111
+ )}
112
+ </ScrollView>
113
+ </View>
114
+ </View>
115
+ );
116
+
117
+ export default CrmHeader;