@esvndev/es-data-sharing 1.0.0 → 1.1.0

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.
package/dist/index.js CHANGED
@@ -3,6 +3,9 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var react = require('react');
5
5
  var reactstrap = require('reactstrap');
6
+ var reactI18next = require('react-i18next');
7
+ var esGridTemplate = require('es-grid-template');
8
+ var becoxyIcons = require('becoxy-icons');
6
9
 
7
10
  var classnames$1 = {exports: {}};
8
11
 
@@ -87,7 +90,13 @@ const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared
87
90
  return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center mb-3", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary p-50 me-2 rounded", children: jsxRuntime.jsx("span", { className: "avatar-content fs-4", children: "\uD83C\uDFE2" }) }), jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: title })] }), jsxRuntime.jsx("div", { className: "master-fields-list", children: fields.map(f => (jsxRuntime.jsxs("div", { className: "mb-2 row align-items-center", children: [jsxRuntime.jsxs("label", { className: "col-5 text-muted small mb-0", children: [f.label, ":"] }), jsxRuntime.jsx("div", { className: "col-7 fw-bold text-truncate text-dark", title: data[f.key] ? String(data[f.key]) : '', children: data[f.key] !== undefined && data[f.key] !== null && data[f.key] !== '' ? String(data[f.key]) : '-' })] }, f.key))) }), jsxRuntime.jsx("hr", { className: "my-3" }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between p-2 rounded bg-light-secondary bg-opacity-10", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: "Danh m\u1EE5c d\u00F9ng chung to\u00E0n t\u1EADp \u0111o\u00E0n" }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: "T\u1EF1 \u0111\u1ED9ng c\u1EA5p quy\u1EC1n s\u1EED d\u1EE5ng cho t\u1EA5t c\u1EA3 \u0111\u01A1n v\u1ECB th\u00E0nh vi\u00EAn" })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] })] }) }));
88
91
  };
89
92
 
90
- const OrgTable = ({ orgList, onChangeOrg }) => {
93
+ const BatchMasterCard = ({ title, items, isGlobalShared, onToggleGlobalShared }) => {
94
+ const { t } = reactI18next.useTranslation();
95
+ return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between mb-2", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary p-50 me-2 rounded", children: jsxRuntime.jsx("span", { className: "avatar-content fs-4", children: "\uD83D\uDCE6" }) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_BatchModeSubtitle', 'Chế độ chia sẻ hàng loạt') })] })] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", pill: true, children: [items.length, " ", t('DataSharing_SelectedItems', 'đối tượng')] })] }), jsxRuntime.jsx("div", { className: "border rounded bg-white p-2", style: { maxHeight: '215px', overflowY: 'auto' }, children: items.map((item, idx) => (jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between py-1 border-bottom last-no-border", children: [jsxRuntime.jsxs("div", { className: "text-truncate me-2", children: [jsxRuntime.jsx("span", { className: "fw-bold text-primary me-1", children: item.code || item.Code || '-' }), jsxRuntime.jsx("span", { className: "small text-dark", children: item.name || item.Name || '' })] }), item.taxCode && jsxRuntime.jsx("small", { className: "text-muted text-nowrap", children: item.taxCode })] }, item.id || item.Id || idx))) }), jsxRuntime.jsx("hr", { className: "my-3" }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between p-2 rounded bg-light-secondary bg-opacity-10", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] })] }) }));
96
+ };
97
+
98
+ const OrgTable = ({ orgList, onChangeOrg, showEffectiveDate = false }) => {
99
+ const { t } = reactI18next.useTranslation();
91
100
  const [search, setSearch] = react.useState('');
92
101
  const [filterType, setFilterType] = react.useState('ALL');
93
102
  const filtered = orgList.filter(o => {
@@ -96,6 +105,27 @@ const OrgTable = ({ orgList, onChangeOrg }) => {
96
105
  const matchType = filterType === 'ALL' || o.orgType === filterType;
97
106
  return matchSearch && matchType;
98
107
  });
108
+ const selectedCount = orgList.filter(o => o.isSelected).length;
109
+ const overrideCount = orgList.filter(o => o.isSelected && o.canOverrideConfig).length;
110
+ const allFilteredSelected = filtered.length > 0 && filtered.every(o => o.isSelected);
111
+ const handleToggleSelectAll = (checked) => {
112
+ const filteredIds = new Set(filtered.map(f => f.targetOrgId));
113
+ const next = orgList.map(item => {
114
+ if (!filteredIds.has(item.targetOrgId))
115
+ return item;
116
+ return {
117
+ ...item,
118
+ isSelected: checked,
119
+ status: checked ? 1 : 0,
120
+ statusText: checked ? t('DataSharing_Sharing', 'Đang chia sẻ') : t('DataSharing_NotShared', 'Chưa chia sẻ')
121
+ };
122
+ });
123
+ onChangeOrg(next);
124
+ };
125
+ const handleToggleAllOverride = (enable) => {
126
+ const next = orgList.map(item => item.isSelected ? { ...item, canOverrideConfig: enable } : item);
127
+ onChangeOrg(next);
128
+ };
99
129
  const handleSelectRow = (targetOrgId, checked) => {
100
130
  const next = orgList.map(item => {
101
131
  if (item.targetOrgId === targetOrgId) {
@@ -103,38 +133,355 @@ const OrgTable = ({ orgList, onChangeOrg }) => {
103
133
  ...item,
104
134
  isSelected: checked,
105
135
  status: checked ? 1 : 0,
106
- statusText: checked ? 'Đang chia sẻ' : 'Chưa chia sẻ'
136
+ statusText: checked ? t('DataSharing_Sharing', 'Đang chia sẻ') : t('DataSharing_NotShared', 'Chưa chia sẻ')
107
137
  };
108
138
  }
109
139
  return item;
110
140
  });
111
141
  onChangeOrg(next);
112
142
  };
113
- const handleToggleInherit = (targetOrgId, checked) => {
114
- const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item, isInheritMaster: checked } : item);
143
+ const handleFieldChange = (targetOrgId, field, value) => {
144
+ const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item, [field]: value } : item);
115
145
  onChangeOrg(next);
116
146
  };
117
- const handleToggleOverride = (targetOrgId, checked) => {
118
- const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item, canOverrideConfig: checked } : item);
119
- onChangeOrg(next);
147
+ return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxRuntime.jsxs(reactstrap.Badge, { color: "light-primary", className: "text-primary", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "light-info", className: "text-info", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-1", style: { minWidth: '280px' }, children: [jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }), jsxRuntime.jsxs(reactstrap.Input, { type: "select", bsSize: "sm", style: { width: '125px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsxRuntime.jsx("option", { value: "ALL", children: t('DataSharing_All', 'Tất cả') }), jsxRuntime.jsx("option", { value: "C\u00F4ng ty", children: t('DataSharing_Company', 'Công ty') }), jsxRuntime.jsx("option", { value: "Chi nh\u00E1nh", children: t('DataSharing_Branch', 'Chi nhánh') })] })] })] }), selectedCount > 0 && (jsxRuntime.jsxs("div", { className: "d-flex justify-content-end gap-2 mb-2", children: [jsxRuntime.jsx(reactstrap.Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(true), children: t('DataSharing_EnableAllOverride', 'Cho phép tất cả cấu hình riêng') }), jsxRuntime.jsx(reactstrap.Button, { size: "sm", color: "secondary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(false), children: t('DataSharing_DisableAllOverride', 'Chỉ kế thừa gốc') })] })), jsxRuntime.jsx("div", { className: "table-responsive border rounded", style: { maxHeight: '235px' }, children: jsxRuntime.jsxs(reactstrap.Table, { size: "sm", hover: true, className: "align-middle mb-0", children: [jsxRuntime.jsx("thead", { className: "table-light sticky-top", children: jsxRuntime.jsxs("tr", { children: [jsxRuntime.jsx("th", { style: { width: 42 }, className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", title: t('DataSharing_SelectAll', 'Chọn tất cả'), checked: allFilteredSelected, onChange: e => handleToggleSelectAll(e.target.checked) }) }), jsxRuntime.jsx("th", { children: t('DataSharing_Organization', 'Đơn vị') }), jsxRuntime.jsx("th", { style: { width: 90 }, children: t('DataSharing_OrgType', 'Loại') }), jsxRuntime.jsx("th", { className: "text-center", style: { width: 105 }, children: t('DataSharing_InheritMaster', 'Kế thừa gốc') }), jsxRuntime.jsx("th", { className: "text-center", style: { width: 120 }, children: t('DataSharing_CanOverride', 'Cấu hình riêng') }), showEffectiveDate && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("th", { style: { width: 135 }, children: t('DataSharing_EffectiveFrom', 'Hiệu lực từ') }), jsxRuntime.jsx("th", { style: { width: 135 }, children: t('DataSharing_EffectiveTo', 'Hiệu lực đến') })] })), jsxRuntime.jsx("th", { style: { width: 110 }, children: t('DataSharing_Status', 'Trạng thái') })] }) }), jsxRuntime.jsx("tbody", { children: filtered.length === 0 ? (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { colSpan: showEffectiveDate ? 8 : 6, className: "text-center text-muted py-3", children: t('DataSharing_NoOrgFound', 'Không tìm thấy đơn vị phù hợp') }) })) : (filtered.map(row => (jsxRuntime.jsxs("tr", { className: row.isSelected ? 'table-primary bg-opacity-10' : '', children: [jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", checked: row.isSelected, onChange: e => handleSelectRow(row.targetOrgId, e.target.checked) }) }), jsxRuntime.jsxs("td", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: row.orgName }), jsxRuntime.jsxs("span", { className: "text-muted small", children: ["(", row.orgCode, ")"] })] }), jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Badge, { color: row.orgType === 'Công ty' ? 'light-primary' : 'light-info', children: row.orgType === 'Công ty'
148
+ ? t('DataSharing_Company', 'Công ty')
149
+ : t('DataSharing_Branch', 'Chi nhánh') }) }), jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: row.isInheritMaster, onChange: e => handleFieldChange(row.targetOrgId, 'isInheritMaster', e.target.checked) }) }) }), jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", disabled: !row.isSelected, checked: row.canOverrideConfig, onChange: e => handleFieldChange(row.targetOrgId, 'canOverrideConfig', e.target.checked) }) }) }), showEffectiveDate && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Input, { bsSize: "sm", type: "date", disabled: !row.isSelected, value: row.effectiveFrom ? String(row.effectiveFrom).substring(0, 10) : '', onChange: e => handleFieldChange(row.targetOrgId, 'effectiveFrom', e.target.value || null) }) }), jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Input, { bsSize: "sm", type: "date", disabled: !row.isSelected, value: row.effectiveTo ? String(row.effectiveTo).substring(0, 10) : '', onChange: e => handleFieldChange(row.targetOrgId, 'effectiveTo', e.target.value || null) }) })] })), jsxRuntime.jsx("td", { children: row.isSelected ? (jsxRuntime.jsx("span", { className: "badge bg-light-success text-success", children: t('DataSharing_Sharing', 'Đang chia sẻ') })) : (jsxRuntime.jsx("span", { className: "badge bg-light-secondary text-secondary", children: t('DataSharing_NotShared', 'Chưa chia sẻ') })) })] }, row.targetOrgId)))) })] }) })] }) }));
150
+ };
151
+
152
+ function resolveFieldDisplayValue(field, rowData, rawVal) {
153
+ const fieldKey = field.fieldKey ?? 'value';
154
+ const fieldLabel = field.fieldLabel ?? 'label';
155
+ if (field.type === 'select' || field.type === 'selectTable') {
156
+ const found = (field.options ?? []).find(opt => opt?.[fieldKey] === rawVal ||
157
+ opt?.value === rawVal ||
158
+ (opt?.key !== undefined && rowData?.bankCode && opt.key === rowData.bankCode));
159
+ if (found) {
160
+ return found.name || found[fieldLabel] || rawVal;
161
+ }
162
+ return rowData?.name || rawVal || '';
163
+ }
164
+ return rawVal ?? '';
165
+ }
166
+ function buildGridColumns(fields, options) {
167
+ const { t, isFieldEditable, formatDisplayValue } = options;
168
+ return fields.map(field => {
169
+ const fieldKey = field.fieldKey ?? 'value';
170
+ const fieldLabel = field.fieldLabel ?? 'label';
171
+ const numericWidth = typeof field.width === 'number' ? field.width : 170;
172
+ let editType = 'text';
173
+ let type = undefined;
174
+ if (field.type === 'select') {
175
+ editType = 'select';
176
+ }
177
+ else if (field.type === 'selectTable') {
178
+ editType = 'selectTable';
179
+ }
180
+ else if (field.type === 'number' || field.type === 'numeric') {
181
+ editType = 'numeric';
182
+ type = 'number';
183
+ }
184
+ else if (field.type === 'currency') {
185
+ editType = 'currency';
186
+ type = 'number';
187
+ }
188
+ else if (field.type === 'date') {
189
+ editType = 'date';
190
+ type = 'date';
191
+ }
192
+ else if (field.type === 'checkbox' || field.type === 'switch') {
193
+ editType = 'checkbox';
194
+ type = 'checkbox';
195
+ }
196
+ const col = {
197
+ field: field.key,
198
+ headerText: field.label,
199
+ headerTooltip: String(t(field.label, field.label)),
200
+ width: numericWidth,
201
+ minWidth: Math.min(numericWidth, 120),
202
+ type,
203
+ editType,
204
+ textAlign: field.textAlign,
205
+ fixedType: field.fixedType,
206
+ editEnable: (rowData) => {
207
+ if (field.readonly)
208
+ return false;
209
+ return isFieldEditable ? isFieldEditable(field, rowData) : true;
210
+ }
211
+ };
212
+ if (field.type === 'select') {
213
+ col.editSelectSettings = {
214
+ options: field.options ?? [],
215
+ fieldLabel: fieldLabel
216
+ };
217
+ }
218
+ else if (field.type === 'selectTable') {
219
+ col.editSelectSettings = {
220
+ options: field.options ?? [],
221
+ fieldLabel: fieldLabel,
222
+ fieldKey: fieldKey,
223
+ columns: field.selectTableColumns ?? [],
224
+ menuWidth: field.menuWidth ?? 580
225
+ };
226
+ }
227
+ if (field.type === 'checkbox' || field.type === 'switch') {
228
+ col.textAlign = field.textAlign ?? 'center';
229
+ col.template = (props) => (jsxRuntime.jsx(reactstrap.Input, { className: "form-check-input", type: "checkbox", disabled: true, checked: Boolean(props.rowData?.[field.key]), value: props.rowData?.[field.key] }));
230
+ }
231
+ else if (field.type === 'select' || field.type === 'selectTable' || formatDisplayValue) {
232
+ col.template = (props) => {
233
+ const rawVal = props.rowData?.[field.key];
234
+ const resolved = resolveFieldDisplayValue(field, props.rowData, rawVal);
235
+ if (formatDisplayValue) {
236
+ return formatDisplayValue(field, props.rowData, resolved);
237
+ }
238
+ return resolved ?? '';
239
+ };
240
+ }
241
+ return col;
242
+ });
243
+ }
244
+
245
+ const OverrideTable = ({ orgList, overrideColumns, masterData, onChangeOverride, onApplyFirstToAll }) => {
246
+ const { t, i18n } = reactI18next.useTranslation();
247
+ const selectedOrgs = orgList.filter(o => o.isSelected);
248
+ const editableOrgs = selectedOrgs.filter(o => o.canOverrideConfig);
249
+ const gridDataSource = react.useMemo(() => selectedOrgs.map(org => {
250
+ const row = {
251
+ rowId: org.targetOrgId,
252
+ targetOrgId: org.targetOrgId,
253
+ orgName: org.orgName,
254
+ orgCode: org.orgCode,
255
+ _canOverrideConfig: Boolean(org.canOverrideConfig)
256
+ };
257
+ overrideColumns.forEach(col => {
258
+ if (org.canOverrideConfig) {
259
+ row[col.key] = org.overrideData?.[col.key] ?? col.defaultValue ?? '';
260
+ }
261
+ else {
262
+ row[col.key] = masterData?.[col.key] ?? '';
263
+ }
264
+ });
265
+ return row;
266
+ }), [selectedOrgs, overrideColumns, masterData]);
267
+ const headerColumns = react.useMemo(() => {
268
+ const baseCols = [
269
+ {
270
+ field: '#',
271
+ headerText: 'STT',
272
+ textAlign: 'center',
273
+ width: 50,
274
+ minWidth: 50,
275
+ maxWidth: 70,
276
+ fixedType: 'left'
277
+ },
278
+ {
279
+ field: 'orgName',
280
+ headerText: t('DataSharing_Organization', 'Đơn vị'),
281
+ headerTooltip: t('DataSharing_Organization', 'Đơn vị'),
282
+ width: 220,
283
+ minWidth: 180,
284
+ fixedType: 'left',
285
+ editEnable: false,
286
+ template: (props) => (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: props.rowData?.orgName }), jsxRuntime.jsxs("small", { className: "text-muted", children: ["(", props.rowData?.orgCode, ")"] })] }))
287
+ }
288
+ ];
289
+ const dynamicCols = buildGridColumns(overrideColumns, {
290
+ t,
291
+ isFieldEditable: (_field, rowData) => Boolean(rowData?._canOverrideConfig),
292
+ formatDisplayValue: (_field, rowData, resolved) => {
293
+ if (!rowData?._canOverrideConfig) {
294
+ const hasMasterVal = resolved !== undefined && resolved !== null && resolved !== '';
295
+ return (jsxRuntime.jsx("span", { className: "text-muted fst-italic", children: hasMasterVal
296
+ ? `${t('DataSharing_InheritFromMaster', 'Kế thừa')}: ${String(resolved)}`
297
+ : t('DataSharing_InheritFromMaster', 'Kế thừa từ gốc') }));
298
+ }
299
+ return resolved ?? '';
300
+ }
301
+ });
302
+ return [...baseCols, ...dynamicCols];
303
+ }, [overrideColumns, t]);
304
+ const handleCellChange = (args, handleCallback) => {
305
+ const item = args.rowData;
306
+ const field = args.field;
307
+ if (field && item?._canOverrideConfig) {
308
+ onChangeOverride(item.targetOrgId, field, item[field]);
309
+ }
310
+ handleCallback(item, args.indexRow);
120
311
  };
121
- return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: "Ph\u1EA1m vi chia s\u1EBB xu\u1ED1ng \u0111\u01A1n v\u1ECB" }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-1 w-50", children: [jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: "T\u00ECm ki\u1EBFm \u0111\u01A1n v\u1ECB...", value: search, onChange: e => setSearch(e.target.value) }), jsxRuntime.jsxs(reactstrap.Input, { type: "select", bsSize: "sm", style: { width: '120px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsxRuntime.jsx("option", { value: "ALL", children: "T\u1EA5t c\u1EA3" }), jsxRuntime.jsx("option", { value: "C\u00F4ng ty", children: "C\u00F4ng ty" }), jsxRuntime.jsx("option", { value: "Chi nh\u00E1nh", children: "Chi nh\u00E1nh" })] })] })] }), jsxRuntime.jsx("div", { className: "table-responsive border rounded", style: { maxHeight: '250px' }, children: jsxRuntime.jsxs(reactstrap.Table, { size: "sm", hover: true, className: "align-middle mb-0", children: [jsxRuntime.jsx("thead", { className: "table-light sticky-top", children: jsxRuntime.jsxs("tr", { children: [jsxRuntime.jsx("th", { style: { width: 40 }, className: "text-center", children: "Ch\u1ECDn" }), jsxRuntime.jsx("th", { children: "\u0110\u01A1n v\u1ECB" }), jsxRuntime.jsx("th", { style: { width: 90 }, children: "Lo\u1EA1i" }), jsxRuntime.jsx("th", { className: "text-center", style: { width: 110 }, children: "K\u1EBF th\u1EEBa g\u1ED1c" }), jsxRuntime.jsx("th", { className: "text-center", style: { width: 130 }, children: "C\u1EA5u h\u00ECnh ri\u00EAng" }), jsxRuntime.jsx("th", { style: { width: 110 }, children: "Tr\u1EA1ng th\u00E1i" })] }) }), jsxRuntime.jsx("tbody", { children: filtered.length === 0 ? (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { colSpan: 6, className: "text-center text-muted py-3", children: "Kh\u00F4ng t\u00ECm th\u1EA5y \u0111\u01A1n v\u1ECB ph\u00F9 h\u1EE3p" }) })) : (filtered.map(row => (jsxRuntime.jsxs("tr", { className: row.isSelected ? 'table-primary bg-opacity-10' : '', children: [jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", checked: row.isSelected, onChange: e => handleSelectRow(row.targetOrgId, e.target.checked) }) }), jsxRuntime.jsxs("td", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: row.orgName }), jsxRuntime.jsxs("span", { className: "text-muted small", children: ["(", row.orgCode, ")"] })] }), jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Badge, { color: row.orgType === 'Công ty' ? 'light-primary' : 'light-info', children: row.orgType }) }), jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: row.isInheritMaster, onChange: e => handleToggleInherit(row.targetOrgId, e.target.checked) }) }), jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", disabled: !row.isSelected, checked: row.canOverrideConfig, onChange: e => handleToggleOverride(row.targetOrgId, e.target.checked) }) }), jsxRuntime.jsx("td", { children: row.isSelected ? (jsxRuntime.jsx("span", { className: "badge bg-light-success text-success", children: "\u0110ang chia s\u1EBB" })) : (jsxRuntime.jsx("span", { className: "badge bg-light-secondary text-secondary", children: "Ch\u01B0a chia s\u1EBB" })) })] }, row.targetOrgId)))) })] }) })] }) }));
312
+ return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsxRuntime.jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxRuntime.jsxs(reactstrap.Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: onApplyFirstToAll, children: ["\uD83D\uDCCB ", t('DataSharing_ApplyFirstToAll', 'Áp dụng cấu hình dòng đầu cho các đơn vị khác')] }) })), selectedOrgs.length === 0 ? (jsxRuntime.jsx("div", { className: "border rounded text-center text-muted py-4 bg-light small", children: t('DataSharing_NoOrgSelected', 'Chưa có đơn vị nào được chọn chia sẻ ở bảng trên.') })) : (jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, allowResizing: true, t: t, format: {
313
+ decimalSeparator: '.',
314
+ thousandSeparator: ',',
315
+ decimalScale: 0
316
+ }, showEmptyText: false }, "DataSharingOverrideGrid")), jsxRuntime.jsxs("div", { className: "d-flex align-items-center mt-2 text-muted small p-1 bg-light rounded", children: [jsxRuntime.jsx("span", { className: "me-1", children: "\u2139\uFE0F" }), jsxRuntime.jsx("span", { children: t('DataSharing_OverrideNote', 'Thông tin gốc do công ty mẹ quản lý. Các đơn vị được bật "Cấu hình riêng" sẽ có thể nhập thông số riêng tại đây.') })] })] }));
122
317
  };
123
318
 
124
- const OverrideTable = ({ orgList, overrideColumns, onChangeOverride }) => {
319
+ const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
320
+ const { t, i18n } = reactI18next.useTranslation();
125
321
  const selectedOrgs = orgList.filter(o => o.isSelected);
126
- return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [jsxRuntime.jsx("div", { className: "table-responsive border rounded", style: { maxHeight: '250px' }, children: jsxRuntime.jsxs(reactstrap.Table, { size: "sm", hover: true, className: "align-middle mb-0", children: [jsxRuntime.jsx("thead", { className: "table-light sticky-top", children: jsxRuntime.jsxs("tr", { children: [jsxRuntime.jsx("th", { style: { minWidth: '180px' }, children: "\u0110\u01A1n v\u1ECB" }), overrideColumns.map(col => (jsxRuntime.jsx("th", { style: { minWidth: '140px' }, children: col.label }, col.key)))] }) }), jsxRuntime.jsx("tbody", { children: selectedOrgs.length === 0 ? (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { colSpan: overrideColumns.length + 1, className: "text-center text-muted py-4", children: "Ch\u01B0a c\u00F3 \u0111\u01A1n v\u1ECB n\u00E0o \u0111\u01B0\u1EE3c ch\u1ECDn chia s\u1EBB \u1EDF b\u1EA3ng tr\u00EAn." }) })) : (selectedOrgs.map(org => {
127
- const canEdit = org.canOverrideConfig;
128
- return (jsxRuntime.jsxs("tr", { children: [jsxRuntime.jsxs("td", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: org.orgName }), jsxRuntime.jsxs("small", { className: "text-muted", children: ["(", org.orgCode, ")"] })] }), overrideColumns.map(col => {
129
- const currentVal = org.overrideData?.[col.key] ?? '';
130
- return (jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Input, { bsSize: "sm", type: col.type === 'number' ? 'number' : 'text', disabled: !canEdit, placeholder: !canEdit ? 'Kế thừa từ gốc' : '', value: currentVal, onChange: e => onChangeOverride(org.targetOrgId, col.key, e.target.value) }) }, col.key));
131
- })] }, org.targetOrgId));
132
- })) })] }) }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center mt-2 text-muted small p-1 bg-light rounded", children: [jsxRuntime.jsx("span", { className: "me-1", children: "\u2139\uFE0F" }), jsxRuntime.jsxs("span", { children: ["Th\u00F4ng tin g\u1ED1c do c\u00F4ng ty m\u1EB9 qu\u1EA3n l\u00FD. C\u00E1c \u0111\u01A1n v\u1ECB \u0111\u01B0\u1EE3c b\u1EADt ", jsxRuntime.jsx("strong", { children: "\"\u0110\u01B0\u1EE3c c\u1EADp nh\u1EADt c\u1EA5u h\u00ECnh ri\u00EAng\"" }), " s\u1EBD c\u00F3 th\u1EC3 nh\u1EADp th\u00F4ng s\u1ED1 ri\u00EAng t\u1EA1i \u0111\u00E2y."] })] })] }));
322
+ const availableOrgs = selectedOrgs.length > 0 ? selectedOrgs : orgList;
323
+ const orgOptions = react.useMemo(() => [
324
+ { label: t('DataSharing_SharedForAllOrgs', 'Dùng chung toàn tập đoàn'), value: '' },
325
+ ...availableOrgs.map(org => ({
326
+ label: `${org.orgName} (${org.orgCode})`,
327
+ value: org.targetOrgId
328
+ }))
329
+ ], [availableOrgs, t]);
330
+ const defaultValue = react.useMemo(() => {
331
+ const base = {
332
+ organizationId: '',
333
+ ...(tabConfig.defaultRow ?? {})
334
+ };
335
+ tabConfig.columns.forEach(col => {
336
+ if (base[col.key] === undefined && col.defaultValue !== undefined) {
337
+ base[col.key] = col.defaultValue;
338
+ }
339
+ });
340
+ return base;
341
+ }, [tabConfig]);
342
+ const activeGridRows = react.useMemo(() => (rows ?? [])
343
+ .filter(r => !r._deleted)
344
+ .map(r => ({
345
+ ...r,
346
+ organizationId: r.organizationId ?? ''
347
+ })), [rows]);
348
+ const emitUpdatedRows = (nextActiveRows) => {
349
+ const normalizedActive = (nextActiveRows ?? []).map((row, idx) => ({
350
+ ...row,
351
+ organizationId: row.organizationId ? String(row.organizationId) : null,
352
+ sortOrder: idx + 1
353
+ }));
354
+ // Enforce uniqueScopeKey checkboxes across updated rows
355
+ tabConfig.columns.forEach(col => {
356
+ if ((col.type === 'checkbox' || col.type === 'switch') && col.uniqueScopeKey !== undefined) {
357
+ const seen = new Set();
358
+ normalizedActive.forEach(r => {
359
+ const scopeVal = r[col.uniqueScopeKey] ? String(r[col.uniqueScopeKey]) : '';
360
+ if (r[col.key]) {
361
+ if (seen.has(scopeVal)) {
362
+ r[col.key] = false;
363
+ }
364
+ else {
365
+ seen.add(scopeVal);
366
+ }
367
+ }
368
+ });
369
+ }
370
+ });
371
+ const activeIds = new Set(normalizedActive.map(r => r.id).filter(Boolean));
372
+ const softDeletedPersisted = (rows ?? [])
373
+ .filter(r => r.id && !activeIds.has(r.id))
374
+ .map(r => ({ ...r, _deleted: true }));
375
+ onChangeRows([...normalizedActive, ...softDeletedPersisted]);
376
+ };
377
+ const headerColumns = react.useMemo(() => {
378
+ const baseCols = [
379
+ {
380
+ field: '#',
381
+ headerText: 'STT',
382
+ textAlign: 'center',
383
+ width: 50,
384
+ minWidth: 50,
385
+ maxWidth: 70,
386
+ fixedType: 'left'
387
+ },
388
+ {
389
+ field: 'organizationId',
390
+ headerText: t('DataSharing_Organization', 'Đơn vị áp dụng'),
391
+ headerTooltip: t('DataSharing_Organization', 'Đơn vị áp dụng'),
392
+ editType: 'select',
393
+ editEnable: true,
394
+ editSelectSettings: {
395
+ options: orgOptions,
396
+ fieldLabel: 'label'
397
+ },
398
+ template: (props) => {
399
+ const orgId = props.rowData?.organizationId ?? '';
400
+ if (!orgId) {
401
+ return t('DataSharing_SharedForAllOrgs', 'Dùng chung toàn tập đoàn');
402
+ }
403
+ const found = orgList.find(o => String(o.targetOrgId).toLowerCase() === String(orgId).toLowerCase());
404
+ return found ? `${found.orgName} (${found.orgCode})` : orgId;
405
+ },
406
+ width: 230,
407
+ minWidth: 180
408
+ }
409
+ ];
410
+ const dynamicCols = buildGridColumns(tabConfig.columns, { t });
411
+ const commandCols = tabConfig.allowDelete === false
412
+ ? []
413
+ : [
414
+ {
415
+ field: 'command',
416
+ visible: true,
417
+ textAlign: 'center',
418
+ fixedType: 'right',
419
+ width: 50,
420
+ minWidth: 50,
421
+ maxWidth: 50,
422
+ commandItems: [
423
+ {
424
+ id: 'DELETE',
425
+ title: '',
426
+ icon: jsxRuntime.jsx(becoxyIcons.Trash2, { fontSize: 16 }),
427
+ tooltip: String(t('Delete', 'Xóa'))
428
+ }
429
+ ]
430
+ }
431
+ ];
432
+ return [...baseCols, ...dynamicCols, ...commandCols];
433
+ }, [tabConfig.columns, tabConfig.allowDelete, orgOptions, orgList, t]);
434
+ const handleCellChange = (args, handleCallback) => {
435
+ const item = args.rowData;
436
+ const val = args.option;
437
+ const field = args.field;
438
+ const colDef = tabConfig.columns.find(c => c.key === field);
439
+ if (colDef?.autoFillMap && val && typeof val === 'object') {
440
+ Object.entries(colDef.autoFillMap).forEach(([targetKey, sourceKey]) => {
441
+ const sourceVal = val[sourceKey];
442
+ if (sourceVal !== undefined && sourceVal !== null) {
443
+ item[targetKey] = sourceVal;
444
+ }
445
+ });
446
+ }
447
+ if (colDef && (colDef.type === 'checkbox' || colDef.type === 'switch') && colDef.uniqueScopeKey !== undefined && item[colDef.key]) {
448
+ const currentScope = item[colDef.uniqueScopeKey] ?? '';
449
+ args.rowsData?.forEach((row) => {
450
+ if (row.rowId !== item.rowId && (row[colDef.uniqueScopeKey] ?? '') === currentScope) {
451
+ row[colDef.key] = false;
452
+ }
453
+ });
454
+ emitUpdatedRows(args.rowsData ?? []);
455
+ }
456
+ handleCallback(item, args.indexRow);
457
+ };
458
+ const toolbarBottomItems = tabConfig.allowAdd === false
459
+ ? []
460
+ : [
461
+ { key: 'ADD', label: 'Add item', position: 'Bottom', align: 'left' },
462
+ { key: 'INSERT_AFTER', label: 'Insert item after', position: 'Bottom', align: 'left' },
463
+ { key: 'INSERT_BEFORE', label: 'Insert item before', position: 'Bottom', align: 'left' },
464
+ { key: 'DUPLICATE', label: 'Duplicate', position: 'Bottom', align: 'left' },
465
+ { key: 'DELETE', label: 'Delete all item', position: 'Bottom', align: 'left' }
466
+ ];
467
+ const handleCommandClick = (item) => {
468
+ if (item.id === 'DELETE') {
469
+ emitUpdatedRows(item?.rows ?? []);
470
+ }
471
+ };
472
+ return (jsxRuntime.jsx("div", { className: "es-data-sharing-detail-tab", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: activeGridRows, editAble: true, lang: i18n.language || 'vi', showToolbar: false, onDataChange: emitUpdatedRows, defaultValue: defaultValue, columns: headerColumns, onCellChange: handleCellChange, toolbarItems: toolbarBottomItems, commandClick: handleCommandClick, allowResizing: true, t: t, format: {
473
+ decimalSeparator: '.',
474
+ thousandSeparator: ',',
475
+ decimalScale: 2
476
+ }, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
133
477
  };
134
478
 
135
- const ModalSharingView = ({ isOpen, toggle, config, masterData, entityId, orgList, setOrgList, isGlobalShared, setIsGlobalShared, onSave, loading = false }) => {
136
- const [activeTab, setActiveTab] = react.useState('1');
479
+ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false }) => {
480
+ const { t } = reactI18next.useTranslation();
481
+ const [activeTab, setActiveTab] = react.useState('override');
137
482
  const [saving, setSaving] = react.useState(false);
483
+ const isBatchMode = (entityIds?.length ?? 0) > 1;
484
+ const detailTabs = config.detailTabs ?? [];
138
485
  const handleToggleGlobalShared = (checked) => {
139
486
  setIsGlobalShared(checked);
140
487
  if (checked) {
@@ -142,7 +489,7 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, entityId, orgLis
142
489
  ...o,
143
490
  isSelected: true,
144
491
  status: 1,
145
- statusText: 'Đang chia sẻ'
492
+ statusText: t('DataSharing_Sharing', 'Đang chia sẻ')
146
493
  })));
147
494
  }
148
495
  };
@@ -159,12 +506,29 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, entityId, orgLis
159
506
  };
160
507
  }));
161
508
  };
509
+ const handleApplyFirstToAll = () => {
510
+ const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
511
+ if (editableOrgs.length < 2)
512
+ return;
513
+ const firstData = editableOrgs[0].overrideData ?? {};
514
+ setOrgList(prev => prev.map(item => {
515
+ if (!item.isSelected || !item.canOverrideConfig)
516
+ return item;
517
+ return {
518
+ ...item,
519
+ overrideData: {
520
+ ...firstData
521
+ }
522
+ };
523
+ }));
524
+ };
162
525
  const handleSubmit = async () => {
163
526
  setSaving(true);
164
527
  try {
165
528
  const payload = {
166
529
  entityType: config.entityType,
167
530
  entityId,
531
+ ...(isBatchMode ? { entityIds } : {}),
168
532
  isGlobalShared,
169
533
  sharingList: orgList.map(o => ({
170
534
  TargetOrgId: o.targetOrgId,
@@ -175,11 +539,12 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, entityId, orgLis
175
539
  Status: o.isSelected ? 1 : 0
176
540
  })),
177
541
  orgConfigList: orgList
178
- .filter(o => o.isSelected)
542
+ .filter(o => o.isSelected && o.canOverrideConfig)
179
543
  .map(o => ({
180
544
  OrganizationId: o.targetOrgId,
181
545
  ...o.overrideData
182
- }))
546
+ })),
547
+ ...(detailTabs.length > 0 ? { detailData } : {})
183
548
  };
184
549
  await onSave(payload);
185
550
  toggle();
@@ -188,30 +553,67 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, entityId, orgLis
188
553
  setSaving(false);
189
554
  }
190
555
  };
191
- return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, className: "border-bottom pb-2", children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 fs-4", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: config.title }), jsxRuntime.jsx("small", { className: "text-muted", children: "Qu\u1EA3n l\u00FD chia s\u1EBB d\u1EEF li\u1EC7u v\u00E0 ph\u00E2n quy\u1EC1n theo \u0111\u01A1n v\u1ECB th\u00E0nh vi\u00EAn" })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { className: "p-3", children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: "\u0110ang t\u1EA3i d\u1EEF li\u1EC7u chia s\u1EBB..." })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(reactstrap.Row, { className: "mb-3", children: [jsxRuntime.jsx(reactstrap.Col, { md: 5, className: "mb-2 mb-md-0", children: jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle, fields: config.masterFields, data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared }) }), jsxRuntime.jsx(reactstrap.Col, { md: 7, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList }) })] }), jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsx(reactstrap.NavLink, { className: classnames({ active: activeTab === '1' }), onClick: () => setActiveTab('1'), style: { cursor: 'pointer' }, children: "\u2699\uFE0F C\u1EA5u h\u00ECnh theo \u0111\u01A1n v\u1ECB" }) }), jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsx(reactstrap.NavLink, { className: classnames({ active: activeTab === '2' }), onClick: () => setActiveTab('2'), style: { cursor: 'pointer' }, children: "\uD83D\uDD52 L\u1ECBch s\u1EED chia s\u1EBB" }) })] }), jsxRuntime.jsxs(reactstrap.TabContent, { activeTab: activeTab, children: [jsxRuntime.jsx(reactstrap.TabPane, { tabId: "1", children: jsxRuntime.jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns, onChangeOverride: handleChangeOverride }) }), jsxRuntime.jsx(reactstrap.TabPane, { tabId: "2", children: jsxRuntime.jsx("div", { className: "text-center text-muted py-4 small border rounded", children: "Ch\u01B0a c\u00F3 l\u1ECBch s\u1EED thay \u0111\u1ED5i ph\u00E2n quy\u1EC1n g\u1EA7n \u0111\u00E2y" }) })] })] })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { className: "border-top pt-2", children: [jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: "H\u1EE7y" }), jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? 'Đang lưu...' : 'Cập nhật chia sẻ' })] })] }));
556
+ const selectedOrgs = orgList.filter(o => o.isSelected);
557
+ return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, className: "border-bottom pb-2", children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 fs-4", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { className: "p-3", children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(reactstrap.Row, { className: "mb-3", children: [jsxRuntime.jsx(reactstrap.Col, { md: 5, className: "mb-2 mb-md-0", children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle, fields: config.masterFields, data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared })) }), jsxRuntime.jsx(reactstrap.Col, { md: 7, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, showEffectiveDate: config.showEffectiveDate }) })] }), jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) }), detailTabs.map(tab => {
558
+ const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
559
+ return (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? `${tab.icon} ` : '📄 ', t(tab.title), jsxRuntime.jsx(reactstrap.Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
560
+ }), jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: ["\uD83D\uDD52 ", t('DataSharing_SummaryTab', 'Tổng hợp phân quyền')] }) })] }), jsxRuntime.jsxs(reactstrap.TabContent, { activeTab: activeTab, children: [jsxRuntime.jsx(reactstrap.TabPane, { tabId: "override", children: jsxRuntime.jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns, masterData: isBatchMode ? undefined : masterData, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll }) }), detailTabs.map(tab => (jsxRuntime.jsx(reactstrap.TabPane, { tabId: `detail:${tab.key}`, children: jsxRuntime.jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
561
+ ...prev,
562
+ [tab.key]: updatedRows
563
+ })) }) }, tab.key))), jsxRuntime.jsx(reactstrap.TabPane, { tabId: "summary", children: jsxRuntime.jsxs("div", { className: "border rounded p-3 small", children: [jsxRuntime.jsxs("div", { className: "fw-bold mb-2", children: [t('DataSharing_SummaryTitle', 'Tóm tắt cấu hình chuẩn bị áp dụng'), ":"] }), jsxRuntime.jsxs("ul", { className: "mb-0 ps-3", children: [jsxRuntime.jsxs("li", { children: [t('DataSharing_SummaryScope', 'Phạm vi'), ":", ' ', jsxRuntime.jsx("strong", { children: isGlobalShared
564
+ ? t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn')
565
+ : `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxRuntime.jsxs("li", { children: [t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng'), ":", ' ', jsxRuntime.jsx("strong", { children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxRuntime.jsxs("li", { children: [t(tab.title), ":", ' ', jsxRuntime.jsx("strong", { children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) })] })] })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { className: "border-top pt-2", children: [jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') }), jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') })] })] }));
192
566
  };
193
567
 
194
- const DataSharingComponent = react.forwardRef(({ fetchSharingData, onSave, onSuccess }, ref) => {
568
+ const DataSharingComponent = react.forwardRef(({ database, fetchSharingData, onSave, onSuccess }, ref) => {
195
569
  const [isOpen, setIsOpen] = react.useState(false);
196
570
  const [loading, setLoading] = react.useState(false);
197
571
  const [config, setConfig] = react.useState(null);
198
572
  const [masterData, setMasterData] = react.useState({});
573
+ const [masterDataList, setMasterDataList] = react.useState([]);
199
574
  const [entityId, setEntityId] = react.useState('');
575
+ const [entityIds, setEntityIds] = react.useState(undefined);
576
+ const [activeDatabase, setActiveDatabase] = react.useState(database);
200
577
  const [isGlobalShared, setIsGlobalShared] = react.useState(false);
201
578
  const [orgList, setOrgList] = react.useState([]);
579
+ const [detailData, setDetailData] = react.useState({});
202
580
  react.useImperativeHandle(ref, () => ({
203
581
  open: async (params) => {
582
+ const targetDb = params.database ?? database;
583
+ const ids = params.entityIds?.filter(Boolean) ?? [];
584
+ const isBatch = ids.length > 1;
585
+ const primaryEntityId = params.entityId || ids[0] || '';
204
586
  setIsOpen(true);
205
587
  setConfig(params.config);
206
- setMasterData(params.masterData);
207
- setEntityId(params.entityId);
588
+ setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
589
+ setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
590
+ setEntityId(primaryEntityId);
591
+ setEntityIds(isBatch ? ids : undefined);
592
+ setActiveDatabase(targetDb);
208
593
  setIsGlobalShared(params.initialGlobalShared || false);
209
- if (fetchSharingData) {
594
+ setDetailData(params.initialDetailData ?? {});
595
+ if (fetchSharingData && primaryEntityId) {
210
596
  setLoading(true);
211
597
  try {
212
- const res = await fetchSharingData(params.entityType, params.entityId);
213
- setIsGlobalShared(res.isGlobalShared);
214
- setOrgList(res.orgList);
598
+ const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
599
+ if (isBatch) {
600
+ // In batch mode, load org tree cleanly without inheriting single-item selections
601
+ setIsGlobalShared(false);
602
+ setOrgList((res.orgList ?? []).map(o => ({
603
+ ...o,
604
+ isSelected: false,
605
+ isInheritMaster: true,
606
+ canOverrideConfig: false,
607
+ status: 0,
608
+ overrideData: {}
609
+ })));
610
+ setDetailData({});
611
+ }
612
+ else {
613
+ setIsGlobalShared(res.isGlobalShared);
614
+ setOrgList(res.orgList ?? []);
615
+ setDetailData(res.detailData ?? params.initialDetailData ?? {});
616
+ }
215
617
  }
216
618
  finally {
217
619
  setLoading(false);
@@ -225,14 +627,17 @@ const DataSharingComponent = react.forwardRef(({ fetchSharingData, onSave, onSuc
225
627
  if (!isOpen || !config)
226
628
  return null;
227
629
  const handleSave = async (payload) => {
630
+ const finalPayload = activeDatabase
631
+ ? { ...payload, database: activeDatabase }
632
+ : payload;
228
633
  if (onSave) {
229
- await onSave(payload);
634
+ await onSave(finalPayload);
230
635
  }
231
636
  if (onSuccess) {
232
637
  onSuccess();
233
638
  }
234
639
  };
235
- return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, entityId: entityId, orgList: orgList, setOrgList: setOrgList, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading }));
640
+ return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading }));
236
641
  });
237
642
 
238
643
  module.exports = DataSharingComponent;