tables: part of payments
This commit is contained in:
parent
d868f62a8d
commit
017fa89a61
@ -599,33 +599,40 @@ const sections: ISections[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
// {
|
||||
// elements: [
|
||||
// {
|
||||
// type: ElementType.Table,
|
||||
// Component: Table,
|
||||
// props: {
|
||||
// name: 'tablePayments',
|
||||
// features: {
|
||||
// canDeleteRow: false,
|
||||
// numerize: {
|
||||
// columnTitle: 'Номер платежа',
|
||||
// },
|
||||
// },
|
||||
// columns: [
|
||||
// {
|
||||
// name: 'paymentRelation',
|
||||
// title: 'Соотношение платежа',
|
||||
// Component: Label,
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// layout: {
|
||||
// newLine: true,
|
||||
// },
|
||||
// },
|
||||
{
|
||||
elements: [
|
||||
{
|
||||
type: ElementType.Table,
|
||||
Component: Table,
|
||||
props: {
|
||||
name: 'tablePayments',
|
||||
features: {
|
||||
canDeleteRow: false,
|
||||
numerize: {
|
||||
columnTitle: 'Номер платежа',
|
||||
},
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
name: 'paymentRelation',
|
||||
title: 'Соотношение платежа',
|
||||
Component: InputNumber,
|
||||
props: {
|
||||
min: '0.01',
|
||||
max: '100.00',
|
||||
step: '1.00',
|
||||
// TODO: toFixed
|
||||
//numeral.js
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
newLine: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@ -67,7 +67,7 @@ export const useTableValue = ({ tableName, rowIndex, propName }) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (cellCallBack) {
|
||||
cellCallBack(calculationStore, tableName, rowIndex, propName);
|
||||
cellCallBack(calculationStore, tableName, rowIndex, debouncedValue);
|
||||
}
|
||||
}, [debouncedValue, cellCallBack]);
|
||||
|
||||
|
||||
@ -1006,6 +1006,9 @@ const reactionEffects: IReactionEffect[] = [
|
||||
}
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
@ -2198,6 +2201,145 @@ const reactionEffects: IReactionEffect[] = [
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const {
|
||||
leasingPeriod,
|
||||
graphType,
|
||||
parmentsDecreasePercent,
|
||||
seasonType,
|
||||
highSeasonStart,
|
||||
firstPaymentPerc,
|
||||
lastPaymentPerc,
|
||||
} = calculationStore.values;
|
||||
return {
|
||||
leasingPeriod,
|
||||
graphType,
|
||||
parmentsDecreasePercent,
|
||||
seasonType,
|
||||
highSeasonStart,
|
||||
firstPaymentPerc,
|
||||
lastPaymentPerc,
|
||||
};
|
||||
},
|
||||
effect: ({
|
||||
leasingPeriod,
|
||||
graphType,
|
||||
parmentsDecreasePercent,
|
||||
seasonType,
|
||||
highSeasonStart,
|
||||
firstPaymentPerc,
|
||||
lastPaymentPerc,
|
||||
}) => {
|
||||
calculationStore.cleanTable('tablePayments');
|
||||
calculationStore.setTableRow(
|
||||
'tablePayments',
|
||||
0,
|
||||
)({
|
||||
paymentRelation: {
|
||||
value: firstPaymentPerc,
|
||||
status: Status.Disabled,
|
||||
},
|
||||
});
|
||||
|
||||
switch (graphType) {
|
||||
case 100000000: {
|
||||
calculationStore.setTableRows(
|
||||
'tablePayments',
|
||||
1,
|
||||
)(
|
||||
Array.from({ length: leasingPeriod - 2 }, () => ({
|
||||
paymentRelation: {
|
||||
value: 100,
|
||||
status: Status.Disabled,
|
||||
},
|
||||
})),
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case 100000001: {
|
||||
calculationStore.setTableRow(
|
||||
'tablePayments',
|
||||
1,
|
||||
)({
|
||||
paymentRelation: {
|
||||
value: 100,
|
||||
status: Status.Disabled,
|
||||
},
|
||||
});
|
||||
|
||||
calculationStore.setTableRows(
|
||||
'tablePayments',
|
||||
2,
|
||||
)(
|
||||
Array.from({ length: leasingPeriod - 3 }, () => ({
|
||||
paymentRelation: {
|
||||
value: 100,
|
||||
status: Status.Default,
|
||||
},
|
||||
})),
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 100000002: {
|
||||
calculationStore.setTableRow(
|
||||
'tablePayments',
|
||||
1,
|
||||
)({
|
||||
paymentRelation: {
|
||||
value: 100,
|
||||
status: Status.Disabled,
|
||||
},
|
||||
});
|
||||
|
||||
const rows = Array.from({ length: leasingPeriod - 3 }, (v, i) => ({
|
||||
paymentRelation: {
|
||||
value: 100,
|
||||
status: Status.Disabled,
|
||||
},
|
||||
}));
|
||||
|
||||
for (let i in rows) {
|
||||
const currRow = rows[parseInt(i)];
|
||||
const prevRow = rows[parseInt(i) - 1];
|
||||
currRow.paymentRelation.value = parseFloat(
|
||||
(
|
||||
((prevRow ? prevRow.paymentRelation.value : 100) *
|
||||
parmentsDecreasePercent) /
|
||||
100
|
||||
).toFixed(2),
|
||||
);
|
||||
}
|
||||
|
||||
calculationStore.setTableRows('tablePayments', 2)(rows);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
calculationStore.setTableRow(
|
||||
'tablePayments',
|
||||
calculationStore.tables.tablePayments.rows.length,
|
||||
)({
|
||||
paymentRelation: {
|
||||
value: lastPaymentPerc,
|
||||
status: Status.Disabled,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(calculationStore.tables.tablePayments);
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
export default reactionEffects;
|
||||
|
||||
@ -1,7 +1,93 @@
|
||||
import { ITable } from 'core/types/tables';
|
||||
import { toJS } from 'mobx';
|
||||
|
||||
const tablePayments: ITable = {
|
||||
rows: [],
|
||||
rows: [
|
||||
// {
|
||||
// paymentRelation: { value: 5 },
|
||||
// },
|
||||
],
|
||||
callbacks: {
|
||||
paymentRelation: (calculationStore, tableName, rowIndex, value) => {
|
||||
const { graphType } = calculationStore.values;
|
||||
if (graphType === 100000001) {
|
||||
if (
|
||||
rowIndex > 1 &&
|
||||
rowIndex < calculationStore.tables[tableName].rows.length - 1
|
||||
) {
|
||||
calculationStore.setTableRows(
|
||||
tableName,
|
||||
rowIndex,
|
||||
)(
|
||||
Array.from(
|
||||
{
|
||||
length:
|
||||
calculationStore.tables[tableName].rows.length - rowIndex - 1,
|
||||
},
|
||||
() => ({
|
||||
paymentRelation: {
|
||||
value,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
for (let i in calculationStore.tables[tableName].rows) {
|
||||
const currRow =
|
||||
calculationStore.tables[tableName].rows[parseInt(i)];
|
||||
const prevRow =
|
||||
calculationStore.tables[tableName].rows[parseInt(i) - 1];
|
||||
if (
|
||||
parseInt(i) > 1 &&
|
||||
currRow &&
|
||||
prevRow &&
|
||||
currRow.paymentRelation?.value > prevRow.paymentRelation?.value
|
||||
) {
|
||||
calculationStore.setTableRow(
|
||||
tableName,
|
||||
parseInt(i),
|
||||
)({
|
||||
paymentRelation: {
|
||||
validation: false,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
calculationStore.setTableRow(
|
||||
tableName,
|
||||
parseInt(i),
|
||||
)({
|
||||
paymentRelation: {
|
||||
validation: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
const middleRows = toJS(calculationStore.tables[tableName].rows);
|
||||
console.log('middleRows', middleRows);
|
||||
middleRows.splice(0, 1);
|
||||
middleRows.splice(-1, 1);
|
||||
|
||||
if (
|
||||
middleRows.every(
|
||||
x =>
|
||||
x.paymentRelation?.value ===
|
||||
middleRows[0].paymentRelation?.value,
|
||||
)
|
||||
) {
|
||||
calculationStore.setTableRows(
|
||||
tableName,
|
||||
2,
|
||||
)(
|
||||
Array.from({ length: middleRows.length - 1 }, (v, i) => ({
|
||||
paymentRelation: {
|
||||
validation: false,
|
||||
},
|
||||
})),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default tablePayments;
|
||||
|
||||
@ -17,7 +17,7 @@ export type TCellCallback = (
|
||||
calculationStore: ICalculationStore,
|
||||
tableName: TableNames,
|
||||
rowIndex: number,
|
||||
propName: TableValuesNames,
|
||||
value: any,
|
||||
) => void;
|
||||
|
||||
export interface ITableCell {
|
||||
|
||||
Reference in New Issue
Block a user