diff --git a/src/client/Containers/Calculation/Results/resultsList.ts b/src/client/Containers/Calculation/Results/resultsList.ts
index 6063d85..11441e3 100644
--- a/src/client/Containers/Calculation/Results/resultsList.ts
+++ b/src/client/Containers/Calculation/Results/resultsList.ts
@@ -1,7 +1,9 @@
+import Button from 'client/Elements/Button';
import Label from 'client/Elements/Label';
import Select from 'client/Elements/Select';
import Switch from 'client/Elements/Switch';
import { IGroup } from 'core/types/Calculation/components';
+import { ElementType } from 'core/types/elements';
const resultsList: IGroup[] = [
{
@@ -24,6 +26,16 @@ const resultsList: IGroup[] = [
computedValue: 'opportunityName',
},
},
+ {
+ type: ElementType.Button,
+ Component: Button,
+ props: {
+ name: 'btnCalculate',
+ actionName: 'calculate',
+ text: 'Рассчитать график',
+ type: 'primary',
+ },
+ },
],
},
],
diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts
index 049375a..0992197 100644
--- a/src/client/Containers/Calculation/Sections/sectionsList.ts
+++ b/src/client/Containers/Calculation/Sections/sectionsList.ts
@@ -1338,11 +1338,8 @@ const sections: ISections[] = [
title: 'Стоимость страховки КАСКО на весь срок',
Component: InputNumber,
props: {
- min: '10000',
- max: '1000000000',
- step: '10000.00',
name: 'tbxInsKaskoPriceLeasePeriod',
- valueName: 'insKaskoPriceLeasePeriod',
+ computedValue: 'insKaskoPriceLeasePeriod',
},
},
],
@@ -1377,6 +1374,11 @@ const sections: ISections[] = [
name: 'insCost',
title: 'Стоимость полиса',
Component: InputNumber,
+ props: {
+ min: '0.00',
+ max: '1500000.00',
+ step: '1000.00',
+ },
},
{
name: 'insTerm',
diff --git a/src/client/Elements/Table.jsx b/src/client/Elements/Table.jsx
index 015a177..cc67863 100644
--- a/src/client/Elements/Table.jsx
+++ b/src/client/Elements/Table.jsx
@@ -89,6 +89,7 @@ const Table = ({ name: tableName, columns, values, features, actions }) => {
tableName,
rowIndex: ri,
propName: key,
+ ...columns[columnIndex].props,
});
return (
diff --git a/src/client/hooks/useValue.js b/src/client/hooks/useValue.js
index 30fded4..95f0147 100644
--- a/src/client/hooks/useValue.js
+++ b/src/client/hooks/useValue.js
@@ -65,7 +65,7 @@ export const useTableValue = ({ tableName, rowIndex, propName }) => {
: undefined;
useEffect(() => {
if (cellCallback) {
- cellCallback(calculationStore, rowIndex, propName);
+ cellCallback(calculationStore, tableName, rowIndex, propName);
}
}, [cellCallback, debouncedValue]);
diff --git a/src/client/stores/CalculationStore/Effects/action.ts b/src/client/stores/CalculationStore/Effects/action.ts
index be7890e..b44ea5f 100644
--- a/src/client/stores/CalculationStore/Effects/action.ts
+++ b/src/client/stores/CalculationStore/Effects/action.ts
@@ -1,6 +1,7 @@
import { openNotification } from 'client/Elements/Notification';
import CalculationStore from 'client/stores/CalculationStore';
import { TAction } from 'core/types/effect';
+import { Status } from 'core/types/statuses';
const actions: TAction = {
createLead: () => {
@@ -144,6 +145,34 @@ const actions: TAction = {
}
}
},
+ calculate: () => {
+ const { values: tableValues } = CalculationStore.tables.tableInsurance;
+ const kaskoRow = tableValues.find(x => x.policyType === 'КАСКО');
+ const DGORow = tableValues.find(x => x.policyType === 'ДГО');
+ const NSRow = tableValues.find(x => x.policyType === 'НС');
+
+ if (
+ kaskoRow &&
+ kaskoRow.insCost === 0 &&
+ ((DGORow && DGORow.insCost > 0) || (NSRow && NSRow.insCost > 0))
+ ) {
+ openNotification({
+ type: 'error',
+ title: 'Ошибка во время расчета графика',
+ description: 'Укажите стоимость КАСКО',
+ })();
+ return;
+ }
+
+ if (kaskoRow && kaskoRow.insured === 100000001 && kaskoRow.insCost === 0) {
+ openNotification({
+ type: 'error',
+ title: 'Ошибка во время расчета графика',
+ description: 'Укажите стоимость КАСКО, включаемую в график',
+ })();
+ return;
+ }
+ },
};
export default { actions };
diff --git a/src/client/stores/CalculationStore/Effects/computed.js b/src/client/stores/CalculationStore/Effects/computed.js
index 5d28c79..9e3d13c 100644
--- a/src/client/stores/CalculationStore/Effects/computed.js
+++ b/src/client/stores/CalculationStore/Effects/computed.js
@@ -41,7 +41,7 @@ const computedEffects = {
}
}
}
-
+
const modelId = this.values.model;
if (modelId) {
const model = this.options.selectModel?.find(
@@ -53,6 +53,21 @@ const computedEffects = {
}
}
},
+ insKaskoPriceLeasePeriod() {
+ const { leasingPeriod } = this.values;
+ const { values: tableValues } = this.tables.tableInsurance;
+ const kaskoRow = tableValues[1];
+ const dgo = tableValues[2];
+ const ns = tableValues[3];
+
+ if (leasingPeriod && leasingPeriod > 15 && kaskoRow.insTerm === 100000001) {
+ return (
+ (leasingPeriod / 12) *
+ (kaskoRow.insCost + dgo.insCost + ns.insCost)
+ ).toFixed(2);
+ }
+ return 0;
+ },
};
export default computedEffects;
diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts
index 934f5c2..6478d90 100644
--- a/src/client/stores/CalculationStore/Effects/reaction.ts
+++ b/src/client/stores/CalculationStore/Effects/reaction.ts
@@ -2032,10 +2032,10 @@ const reactionEffects: IReactionEffect[] = [
);
const kaskoRow = tableValues[kaskoRowIndex];
if (kaskoRow) {
- return kaskoRow.insTerm;
+ return { ...kaskoRow };
}
},
- effect: insTerm => {
+ effect: ({ insuranceCompany, insTerm, insured }) => {
if (insTerm) {
const { values: tableValues } = calculationStore.tables.tableInsurance;
const dgoRowIndex = tableValues.findIndex(x => x.policyType === 'ДГО');
@@ -2046,9 +2046,7 @@ const reactionEffects: IReactionEffect[] = [
rowIndex: dgoRowIndex,
},
{
- values: {
- insTerm,
- },
+ values: { insuranceCompany, insTerm, insured },
},
);
const nsRowIndex = tableValues.findIndex(x => x.policyType === 'НС');
@@ -2060,18 +2058,30 @@ const reactionEffects: IReactionEffect[] = [
},
{
values: {
+ insuranceCompany,
insTerm,
+ insured,
},
},
);
}
+ },
+ }),
+ calculationStore => ({
+ expression: () => {
const { values: tableValues } = calculationStore.tables.tableInsurance;
const kaskoRowIndex = tableValues.findIndex(
x => x.policyType === 'КАСКО',
);
-
- if (insTerm === 'dl_period' && kaskoRowIndex) {
+ const kaskoRow = tableValues[kaskoRowIndex];
+ const { leasingPeriod } = calculationStore.values;
+ if (kaskoRow) {
+ return { insTerm: kaskoRow.insTerm, kaskoRowIndex, leasingPeriod };
+ }
+ },
+ effect: ({ insTerm, kaskoRowIndex, leasingPeriod }) => {
+ if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) {
if (kaskoRowIndex >= 0)
calculationStore.setTableRow(
{
@@ -2080,7 +2090,7 @@ const reactionEffects: IReactionEffect[] = [
},
{
values: {
- insured: 'evo',
+ insured: 100000001,
},
statuses: {
insured: Status.Disabled,
@@ -2114,8 +2124,12 @@ const reactionEffects: IReactionEffect[] = [
const kaskoRowIndex = tableValues.findIndex(
x => x.policyType === 'КАСКО',
);
- if (leasingPeriod)
- if (leasingPeriod < 13) {
+ const osagoRowIndex = tableValues.findIndex(
+ x => x.policyType === 'ОСАГО',
+ );
+
+ if (leasingPeriod) {
+ if (leasingPeriod < 12) {
if (kaskoRowIndex >= 0)
calculationStore.setTableRow(
{
@@ -2124,29 +2138,29 @@ const reactionEffects: IReactionEffect[] = [
},
{
values: {
- insTerm: 'year_period',
+ insured: 100000000,
},
statuses: {
- insTerm: Status.Disabled,
+ insured: Status.Disabled,
},
},
);
- } else if (leasingPeriod > 12 && leasingPeriod < 16) {
- if (kaskoRowIndex >= 0)
+ if (osagoRowIndex >= 0) {
calculationStore.setTableRow(
{
tableName: 'tableInsurance',
- rowIndex: kaskoRowIndex,
+ rowIndex: osagoRowIndex,
},
{
values: {
- insTerm: 'dl_period',
+ insured: 100000000,
},
statuses: {
- insTerm: Status.Disabled,
+ insured: Status.Disabled,
},
},
);
+ }
} else {
if (kaskoRowIndex >= 0)
calculationStore.setTableRow(
@@ -2156,11 +2170,76 @@ const reactionEffects: IReactionEffect[] = [
},
{
statuses: {
+ insured: Status.Default,
+ },
+ },
+ );
+ if (osagoRowIndex >= 0) {
+ calculationStore.setTableRow(
+ {
+ tableName: 'tableInsurance',
+ rowIndex: osagoRowIndex,
+ },
+ {
+ statuses: {
+ insured: Status.Default,
+ },
+ },
+ );
+ }
+ }
+
+ if (leasingPeriod < 13) {
+ if (kaskoRowIndex >= 0)
+ calculationStore.setTableRow(
+ {
+ tableName: 'tableInsurance',
+ rowIndex: kaskoRowIndex,
+ },
+ {
+ values: {
+ insTerm: 100000000,
+ },
+ statuses: {
+ insTerm: Status.Disabled,
+ },
+ },
+ );
+ return;
+ } else if (leasingPeriod > 12 && leasingPeriod < 16) {
+ if (kaskoRowIndex >= 0)
+ calculationStore.setTableRow(
+ {
+ tableName: 'tableInsurance',
+ rowIndex: kaskoRowIndex,
+ },
+ {
+ values: {
+ insTerm: 100000001,
+ },
+ statuses: {
+ insTerm: Status.Disabled,
+ },
+ },
+ );
+ return;
+ } else {
+ if (kaskoRowIndex >= 0) {
+ calculationStore.setTableRow(
+ {
+ tableName: 'tableInsurance',
+ rowIndex: kaskoRowIndex,
+ },
+ {
+ statuses: {
+ insured: Status.Default,
insTerm: Status.Default,
},
},
);
+ }
}
+ }
},
options: {
fireImmediately: true,
diff --git a/src/core/config/initialStatuses.ts b/src/core/config/initialStatuses.ts
index 9de7938..4eb2121 100644
--- a/src/core/config/initialStatuses.ts
+++ b/src/core/config/initialStatuses.ts
@@ -6,6 +6,7 @@ const initialStatuses: TStatuses = {
selectCalcFinDepartment: Status.Disabled,
selectDoubleAgent: Status.Disabled,
selectCalcDoubleAgent: Status.Disabled,
+ tbxInsKaskoPriceLeasePeriod: Status.Disabled,
};
export default initialStatuses;
diff --git a/src/core/config/initialTables.ts b/src/core/config/initialTables.ts
index ab7bd16..bec9afc 100644
--- a/src/core/config/initialTables.ts
+++ b/src/core/config/initialTables.ts
@@ -1,3 +1,4 @@
+import { openNotification } from 'client/Elements/Notification';
import { Status } from 'core/types/statuses';
import { IStoreTable } from './../types/tables';
const initialTables: IStoreTable = {
@@ -8,7 +9,7 @@ const initialTables: IStoreTable = {
insuranceCompany: null,
insured: null,
insCost: 0,
- insTerm: null,
+ insTerm: 100000000,
},
{
policyType: 'КАСКО',
@@ -54,31 +55,105 @@ const initialTables: IStoreTable = {
insured: [
{
name: 'Лизингополучатель',
- value: 'client',
+ value: 100000000,
},
{
name: 'Лизингодатель',
- value: 'evo',
+ value: 100000001,
},
],
insTerm: [
{
name: '12 месяцев',
- value: 'year_period',
+ value: 100000000,
},
{
name: 'Срок ДЛ',
- value: 'dl_period',
+ value: 100000001,
},
],
},
filters: [],
callbacks: {
- policyType: (calculationStore, rowIndex, propName) => {
- //action
+ insCost: (calculationStore, tableName, rowIndex, propName) => {
+ if (
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
+ !calculationStore.tables[tableName].values[rowIndex][
+ 'insuranceCompany'
+ ]
+ ) {
+ openNotification({
+ type: 'error',
+ title: 'Ошибка',
+ description: 'Не указана страховая компания по полису',
+ })();
+ }
+ if (
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
+ !calculationStore.tables[tableName].values[rowIndex]['insTerm']
+ ) {
+ openNotification({
+ type: 'error',
+ title: 'Ошибка',
+ description: 'Не указан срок страхования',
+ })();
+ }
+ if (
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
+ !calculationStore.tables[tableName].values[rowIndex]['insured']
+ ) {
+ openNotification({
+ type: 'error',
+ title: 'Ошибка',
+ description: 'Не указан плательщик',
+ })();
+ }
},
- insuranceCompany: (calculationStore, rowIndex, propName) => {
- //action
+
+ insured: (calculationStore, tableName, rowIndex, propName) => {
+ if (
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
+ !calculationStore.tables[tableName].values[rowIndex]['insured']
+ ) {
+ openNotification({
+ type: 'error',
+ title: 'Ошибка',
+ description: 'Не указан плательщик',
+ })();
+ }
+ },
+
+ insTerm: (calculationStore, tableName, rowIndex, propName) => {
+ if (
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
+ !calculationStore.tables[tableName].values[rowIndex]['insTerm']
+ ) {
+ openNotification({
+ type: 'error',
+ title: 'Ошибка',
+ description: 'Не указан срок страхования',
+ })();
+ }
+ },
+ insuranceCompany: (calculationStore, tableName, rowIndex, propName) => {
+ if (
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
+ calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
+ !calculationStore.tables[tableName].values[rowIndex][
+ 'insuranceCompany'
+ ]
+ ) {
+ openNotification({
+ type: 'error',
+ title: 'Ошибка',
+ description: 'Не указана страховая компания по полису',
+ })();
+ }
},
},
},
diff --git a/src/core/types/effect.ts b/src/core/types/effect.ts
index 96094d3..2120094 100644
--- a/src/core/types/effect.ts
+++ b/src/core/types/effect.ts
@@ -1,10 +1,10 @@
import CommonStore from 'client/stores/CommonStore';
-import { IReactionOptions, IReactionPublic, Lambda, reaction } from 'mobx';
+import { IReactionOptions, IReactionPublic, Lambda } from 'mobx';
import { ICalculationStore } from './stores';
type TCommonStore = typeof CommonStore;
-export type ActionsNames = 'createLead';
+export type ActionsNames = 'createLead' | 'calculate';
export type TAction = {
[actionName in ActionsNames]?: () => void;
diff --git a/src/core/types/elements.ts b/src/core/types/elements.ts
index 92970f5..c6f94c4 100644
--- a/src/core/types/elements.ts
+++ b/src/core/types/elements.ts
@@ -134,7 +134,8 @@ export type ElementsNames =
| 'radioInsuranceOPF'
| 'tableInsurance'
| 'lblLead'
- | 'lblOpportunity';
+ | 'lblOpportunity'
+ | 'btnCalculate';
export enum ElementType {
Default,
diff --git a/src/core/types/tables.ts b/src/core/types/tables.ts
index f533509..3a54362 100644
--- a/src/core/types/tables.ts
+++ b/src/core/types/tables.ts
@@ -16,6 +16,7 @@ export type TTableValues = {
export type TCellCallback = (
calculationStore: ICalculationStore,
+ tableName: TableNames,
rowIndex: number,
propName: TableValuesNames,
) => void;
diff --git a/src/core/types/values.ts b/src/core/types/values.ts
index 7201b83..020d575 100644
--- a/src/core/types/values.ts
+++ b/src/core/types/values.ts
@@ -150,7 +150,8 @@ export type ValuesNames =
export type ComputedValuesNames =
| 'leadName'
| 'opportunityName'
- | 'leaseObjectRiskName';
+ | 'leaseObjectRiskName'
+ | 'insKaskoPriceLeasePeriod';
export type TValues = {
[valueName in ValuesNames]?: T;
|