fix loadKp | createKp

This commit is contained in:
Chika 2020-12-09 17:24:30 +03:00
parent 28a8cdbfce
commit 3a2fec4060
6 changed files with 129 additions and 58 deletions

View File

@ -37,9 +37,12 @@ const tablesActions = {
}
}
} else {
this.tables[tableName].rows[i] = Object.assign({}, rows[j]);
this.tables[tableName].rows[i] = rows[j];
}
}
if (override) {
this.tables[tableName].rows.length = rows.length;
}
};
},

View File

@ -86,8 +86,6 @@ export default async () => {
results.showResultsTable(preparedData, res);
results.showResults(preparedData, res);
unlockButtons();
return { ...res, ...preparedData };
})
.catch(err => {
@ -101,8 +99,9 @@ export default async () => {
err.response.data),
})();
unlockButtons();
throw err;
})
.finally(() => {
unlockButtons();
});
};

View File

@ -4,11 +4,15 @@ import CrmService from 'client/services/CrmService';
import { getUser } from 'client/tools/user';
import CalculationStore from '../..';
import customValues from '../lib/customValues';
import calculate from './calculate';
import { openNotification } from 'client/Elements/Notification';
export default async () => {
const { values, tables } = CalculationStore;
const calculationRes = await calculate();
const { values, tables, actions } = CalculationStore;
const calculationRes = await actions.calculate();
if (!calculationRes) {
return;
}
const insurances = tables.tableInsurance.rows.map(insuranceRow => {
const resObj = {};
@ -86,6 +90,13 @@ export default async () => {
});
})
.catch(err => {
throw err;
openNotification({
type: 'error',
title: 'Ошибка во время создания КП!',
description:
err.response.data && JSON.stringify(err.response.data.errors),
})();
throw err.response.data;
});
};

View File

@ -1,5 +1,6 @@
//@ts-nocheck
import { message } from 'antd';
import { elementsValues } from 'client/Containers/Calculation/lib/elements/values';
import CrmService from 'client/services/CrmService';
import { calculationProcess } from 'client/stores/CalculationStore';
@ -21,6 +22,23 @@ const map_add_product_types_to_values = {
telematics: 100000004,
};
const tablePaymentsStatuses = (graphType, leasingPeriod) => {
switch (graphType) {
case 100000001: {
return Array.from({ length: leasingPeriod - 3 }, (_, i) => i + 2);
}
case 100000003: {
return Array.from({ length: 12 }, (_, i) => i + 1);
}
case 100000004: {
return [1, 2, 3];
}
default: {
return [];
}
}
};
const loadKpReaction: IReactionEffect = calculationStore => ({
expression: () => {
const { quote } = calculationStore.values;
@ -146,56 +164,89 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
opportunity,
quote: quoteId,
});
calculationStore.setTableRows(
'tableInsurance',
0,
)([
{
insuranceCompany: {
value: quote?.evo_osago_accountid,
},
insured: { value: quote.evo_osago_payer },
insCost: { value: quote.evo_osago_price },
},
{
insuranceCompany: {
value: quote.evo_kasko_accountid,
},
insured: { value: quote.evo_kasko_payer },
insCost: { value: quote.evo_kasko_price },
insTerm: { value: quote.evo_insurance_period },
},
{
insuranceCompany: {
value: quote.evo_kasko_accountid,
},
insured: { value: quote.evo_kasko_payer },
insCost: { value: quote.evo_dgo_price },
insTerm: { value: quote.evo_insurance_period },
},
{
insuranceCompany: {
value: quote.evo_kasko_accountid,
},
insured: { value: quote.evo_kasko_payer },
insCost: { value: quote.evo_ns_price },
insTerm: { value: quote.evo_insurance_period },
},
]);
const evo_planpayments = quote.evo_graphs.sort(
(a, b) => b.createdon - a.createdon,
)[0].evo_planpayments;
const payments = evo_planpayments
.slice(1, evo_planpayments.length - 1)
.map((evo_planpayment, i) => ({
paymentRelation: {
validation: undefined,
value: evo_planpayment.evo_payment_ratio,
status: tablePaymentsStatuses(
quote.evo_graph_type,
quote.evo_period,
)?.includes(i + 1)
? ElementStatus.Default
: ElementStatus.Disabled,
},
}));
calculationStore.setTableRows(
'tablePayments',
0,
true,
)([
{
paymentRelation: {
value: quote.evo_first_payment_perc,
status: ElementStatus.Disabled,
},
},
...payments,
{
paymentRelation: {
value: quote.evo_last_payment_perc,
status: ElementStatus.Disabled,
},
},
]);
message.success({
content: `КП ${quote?.evo_quotename || ''} загружено!`,
duration: 5,
style: {
marginTop: '7vh',
},
});
}
calculationStore.setTableRows(
'tableInsurance',
0,
)([
{
insuranceCompany: {
value: quote?.evo_osago_accountid,
},
insured: { value: quote.evo_osago_payer },
insCost: { value: quote.evo_osago_price },
},
{
insuranceCompany: {
value: quote.evo_kasko_accountid,
},
insured: { value: quote.evo_kasko_payer },
insCost: { value: quote.evo_kasko_price },
insTerm: { value: quote.evo_insurance_period },
},
{
insuranceCompany: {
value: quote.evo_kasko_accountid,
},
insured: { value: quote.evo_kasko_payer },
insCost: { value: quote.evo_dgo_price },
insTerm: { value: quote.evo_insurance_period },
},
{
insuranceCompany: {
value: quote.evo_kasko_accountid,
},
insured: { value: quote.evo_kasko_payer },
insCost: { value: quote.evo_ns_price },
insTerm: { value: quote.evo_insurance_period },
},
]);
const evo_planpayments = quote.evo_graphs.sort(
(a, b) => b.createdon - a.createdon,
)[0].evo_planpayments;
const payments = evo_planpayments
.slice(1, evo_planpayments.length)
.map(evo_planpayment => ({
paymentRelation: {
value: evo_planpayment.evo_payment_ratio,
},
}));
calculationStore.setTableRows('tablePayments', 1)(payments);
})
.finally(() => {
calculationStore.setStatus('selectQuote', ElementStatus.Default);

View File

@ -24,6 +24,9 @@ export default gql`
evo_payment_ratio
}
}
evo_first_payment_perc
evo_last_payment_perc
evo_quotename
}
}
`;

View File

@ -65,6 +65,10 @@ export interface IQuote {
evo_ns_price?: number;
evo_insurance_period?: number;
evo_graphs?: IEvoGraph[];
evo_graph_type?: number;
evo_period?: number;
evo_first_payment_perc?: number;
evo_last_payment_perc?: number;
}
interface IEvoGraph {