- fix for decimals in tables in appl form;
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
"mustache": "4.2.0",
|
"mustache": "4.2.0",
|
||||||
"object-path-immutable": "4.1.2",
|
"object-path-immutable": "4.1.2",
|
||||||
"primeicons": "7.0.0",
|
"primeicons": "7.0.0",
|
||||||
"primereact": "10.9.4",
|
"primereact": "10.9.6",
|
||||||
"quill": "2.0.3",
|
"quill": "2.0.3",
|
||||||
"ramda": "0.30.1",
|
"ramda": "0.30.1",
|
||||||
"react": "19.1.0",
|
"react": "19.1.0",
|
||||||
@@ -42,8 +42,8 @@
|
|||||||
"recharts": "2.15.2",
|
"recharts": "2.15.2",
|
||||||
"sockjs-client": "1.6.1",
|
"sockjs-client": "1.6.1",
|
||||||
"validate.js": "0.13.1",
|
"validate.js": "0.13.1",
|
||||||
"zustand": "5.0.3",
|
"zustand": "5.0.6",
|
||||||
"zustand-x": "6.1.0"
|
"zustand-x": "6.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "7.27.0",
|
"@babel/cli": "7.27.0",
|
||||||
|
|||||||
@@ -410,12 +410,12 @@
|
|||||||
.appPageSection__actions {
|
.appPageSection__actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 24px;
|
gap: 24px;
|
||||||
padding: 24px 0 0;
|
padding: 0;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.appPageSection__actions > *:first-child{
|
.appPageSection > .appPageSection__actions:first-child {
|
||||||
margin-bottom: 24px;
|
padding-bottom: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.appPageSection .appPageSection__actions:last-of-type {
|
.appPageSection .appPageSection__actions:last-of-type {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { InputNumber } from 'primereact/inputnumber';
|
import { InputNumber } from 'primereact/inputnumber';
|
||||||
|
import parseLocaleNumber from '../../../../../../../helpers/parseLocaleNumber';
|
||||||
|
|
||||||
const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table }) => {
|
const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table }) => {
|
||||||
const initialValue = getValue();
|
const initialValue = getValue();
|
||||||
@@ -19,7 +20,7 @@ const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table })
|
|||||||
return (
|
return (
|
||||||
<InputNumber
|
<InputNumber
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={initialValue}
|
value={parseLocaleNumber(initialValue)}
|
||||||
/*onValueChange={(e) => onChange(e.value)}*/
|
/*onValueChange={(e) => onChange(e.value)}*/
|
||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
onBlur={(e) => onBlur(e.target.value)}
|
onBlur={(e) => onBlur(e.target.value)}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { head, isEmpty, isNil, pathOr, sum } from 'ramda';
|
|||||||
// components
|
// components
|
||||||
import DefaultCell from './components/DefaultCell';
|
import DefaultCell from './components/DefaultCell';
|
||||||
import LastRowCell from './components/LastRowCell';
|
import LastRowCell from './components/LastRowCell';
|
||||||
|
import parseLocaleNumber from '../../../../../helpers/parseLocaleNumber';
|
||||||
|
|
||||||
const RenderTable = ({ tableValue = {}, columnsCfg, lastRowCfg, setTableValueFn, disabled }) => {
|
const RenderTable = ({ tableValue = {}, columnsCfg, lastRowCfg, setTableValueFn, disabled }) => {
|
||||||
const rows = pathOr([], ['rows'], tableValue)
|
const rows = pathOr([], ['rows'], tableValue)
|
||||||
@@ -28,7 +29,7 @@ const RenderTable = ({ tableValue = {}, columnsCfg, lastRowCfg, setTableValueFn,
|
|||||||
if (columnCfgData.meta.enableFormula) {
|
if (columnCfgData.meta.enableFormula) {
|
||||||
const getAllRowsValues = newRowsData.rows
|
const getAllRowsValues = newRowsData.rows
|
||||||
.map(row => row[columnId])
|
.map(row => row[columnId])
|
||||||
.map(v => isEmpty(v) || isNil(v) ? 0 : v);
|
.map(v => parseLocaleNumber(v));
|
||||||
|
|
||||||
if (cellValue === 'sum') {
|
if (cellValue === 'sum') {
|
||||||
total = sum(getAllRowsValues);
|
total = sum(getAllRowsValues);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { head, isEmpty, isNil, sum } from 'ramda';
|
import { head, isNil, sum } from 'ramda';
|
||||||
import getNumberFormatted from '../../../../../../../helpers/getNumberFormatted';
|
import getNumberFormatted from '../../../../../../../helpers/getNumberFormatted';
|
||||||
|
import parseLocaleNumber from '../../../../../../../helpers/parseLocaleNumber';
|
||||||
|
|
||||||
const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, getColumnDataFn}) => {
|
const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, getColumnDataFn}) => {
|
||||||
const cellData = head(lastRowCfg.filter(o => !isNil(o[columnId])));
|
const cellData = head(lastRowCfg.filter(o => !isNil(o[columnId])));
|
||||||
@@ -7,7 +8,7 @@ const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, getColumnDataFn}) =
|
|||||||
|
|
||||||
if (columnMeta.enableFormula) {
|
if (columnMeta.enableFormula) {
|
||||||
const getAllRowsValues = getColumnDataFn(columnId)
|
const getAllRowsValues = getColumnDataFn(columnId)
|
||||||
.map(v => isEmpty(v) || isNil(v) ? 0 : v);
|
.map(v => parseLocaleNumber(v));
|
||||||
|
|
||||||
if (cellValue === 'sum') {
|
if (cellValue === 'sum') {
|
||||||
cellValue = getNumberFormatted(sum(getAllRowsValues));
|
cellValue = getNumberFormatted(sum(getAllRowsValues));
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { InputNumber } from 'primereact/inputnumber';
|
import { InputNumber } from 'primereact/inputnumber';
|
||||||
|
import parseLocaleNumber from '../../../../../../../helpers/parseLocaleNumber';
|
||||||
|
|
||||||
const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table }) => {
|
const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table }) => {
|
||||||
const initialValue = getValue();
|
const initialValue = getValue();
|
||||||
@@ -20,7 +21,7 @@ const NumericFormulaCell = ({ getValue, row: { index }, column: { id }, table })
|
|||||||
return (
|
return (
|
||||||
<InputNumber
|
<InputNumber
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={initialValue}
|
value={parseLocaleNumber(initialValue)}
|
||||||
/*onValueChange={(e) => onChange(e.value)}*/
|
/*onValueChange={(e) => onChange(e.value)}*/
|
||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
onBlur={(e) => onBlur(e.target.value)}
|
onBlur={(e) => onBlur(e.target.value)}
|
||||||
|
|||||||
69
src/helpers/parseLocaleNumber.js
Normal file
69
src/helpers/parseLocaleNumber.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
export default function parseLocaleNumber(numberString) {
|
||||||
|
// Handle null, undefined, and empty values
|
||||||
|
if (numberString === null || numberString === undefined || numberString === '') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const str = String(numberString).trim();
|
||||||
|
|
||||||
|
if (str === '') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any currency symbols, letters, and other non-numeric characters
|
||||||
|
let cleaned = str.replace(/[^\d.,\-+]/g, '');
|
||||||
|
|
||||||
|
// Handle edge cases
|
||||||
|
if (cleaned === '' || cleaned === '-' || cleaned === '+') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count dots and commas
|
||||||
|
const dotCount = (cleaned.match(/\./g) || []).length;
|
||||||
|
const commaCount = (cleaned.match(/,/g) || []).length;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Determine format based on separators
|
||||||
|
if (dotCount === 0 && commaCount === 0) {
|
||||||
|
// Pure integer
|
||||||
|
const result = parseInt(cleaned, 10);
|
||||||
|
return isNaN(result) ? 0 : result;
|
||||||
|
}
|
||||||
|
else if (dotCount === 1 && commaCount === 0) {
|
||||||
|
// US format (123.45)
|
||||||
|
const result = parseFloat(cleaned);
|
||||||
|
return isNaN(result) ? 0 : result;
|
||||||
|
}
|
||||||
|
else if (dotCount === 0 && commaCount === 1) {
|
||||||
|
// Could be European (123,45) or US thousands (1,234)
|
||||||
|
const parts = cleaned.split(',');
|
||||||
|
if (parts.length === 2 && parts[1].length <= 2) {
|
||||||
|
// Likely decimal (123,45)
|
||||||
|
const result = parseFloat(cleaned.replace(',', '.'));
|
||||||
|
return isNaN(result) ? 0 : result;
|
||||||
|
} else {
|
||||||
|
// Likely thousands separator (1,234)
|
||||||
|
const result = parseFloat(cleaned.replace(',', ''));
|
||||||
|
return isNaN(result) ? 0 : result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Mixed separators - use position to determine
|
||||||
|
const lastDot = cleaned.lastIndexOf('.');
|
||||||
|
const lastComma = cleaned.lastIndexOf(',');
|
||||||
|
|
||||||
|
if (lastDot > lastComma) {
|
||||||
|
// Dot is decimal separator (1,234.56)
|
||||||
|
cleaned = cleaned.replace(/,/g, '');
|
||||||
|
} else {
|
||||||
|
// Comma is decimal separator (1.234,56)
|
||||||
|
cleaned = cleaned.replace(/\./g, '').replace(',', '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = parseFloat(cleaned);
|
||||||
|
return isNaN(result) ? 0 : result;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user