merge release/calc-72_registation-gibdd

This commit is contained in:
vchikalkin 2021-05-25 13:47:11 +03:00
parent 12f0bf2d8d
commit 44050895e3
51 changed files with 1185 additions and 518 deletions

View File

@ -1,6 +1,7 @@
import { Modal } from 'antd';
import { Outlined as SpinnerOutlined } from 'client/Components/Spinner';
import Button from 'client/Elements/Button';
import { CenterContent } from 'client/Elements/Wrapper';
import { Box } from 'client/UIKit/grid';
import { lazy, Suspense, useState } from 'react';
@ -32,7 +33,13 @@ const ELT = ({ title }) => {
width="max-content"
centered
>
<Suspense fallback={<SpinnerOutlined />}>
<Suspense
fallback={
<CenterContent>
<SpinnerOutlined />
</CenterContent>
}
>
<Content />
</Suspense>
</Modal>

View File

@ -1,21 +1,7 @@
import LoadingOutlined from '@ant-design/icons/lib/icons/LoadingOutlined';
import { Spin } from 'antd';
import { Flex } from 'client/UIKit/grid';
const Wrapper = props => (
<Flex height="100%" py="10px" justifyContent="center" alignItems="center">
{props.children}
</Flex>
);
const Spinner = props => (
<Wrapper>
<Spin {...props} />
</Wrapper>
);
export default Spinner;
export default Spin;
const loadingOutlined = <LoadingOutlined style={{ fontSize: 24 }} spin />;
export const Outlined = () => <Spinner indicator={loadingOutlined} />;
export const Outlined = () => <Spin indicator={loadingOutlined} />;

View File

@ -317,11 +317,43 @@ const sections: ISection[] = [
title: 'Доп. продукты',
groups: [
{
title: 'Регистрация',
blocks: [
{
elements: [
'radioObjectRegistration',
'selectRegionRegistration',
'selectTownRegistration',
'selectObjectRegionRegistration',
'tbxLeaseObjectYear',
'tbxLeaseObjectMotorPower',
],
},
{
elements: [
'radioTypePTS',
'selectObjectCategoryTax',
'selectObjectTypeTax',
'tbxVehicleTaxInYear',
'tbxVehicleTaxInLeasingPeriod',
],
},
],
},
{
style: { columnsNumber: 1 },
blocks: [
{
elements: ['selectRegistration', 'labelRegistrationDescription'],
},
],
},
{
title: 'Доп. продукты',
style: { columnsNumber: 1 },
blocks: [
{
elements: [
'selectRegistration',
'selectTechnicalCard',
'selectInsNSIB',
'radioRequirementTelematic',

View File

@ -1,5 +1,6 @@
import Result from 'client/Components/Result';
import Spinner from 'client/Components/Spinner';
import { CenterContent } from 'client/Elements/Wrapper';
import { useFetch } from 'client/hooks/Calculation/useFetch';
import { Box, Flex } from 'client/UIKit/grid';
import mq from 'client/UIKit/mq';
@ -35,7 +36,11 @@ const Calculation = () => {
const { isLoading, error } = useFetch({ fetchData });
if (isLoading) {
return <Spinner />;
return (
<CenterContent>
<Spinner />
</CenterContent>
);
}
if (error) {

View File

@ -162,6 +162,14 @@ const elementsComponents: TElements<Component> = {
radioCalcType: Radio,
tbxTotalPayments: InputNumber,
componentElt: ELT,
radioObjectRegistration: Radio,
selectObjectRegionRegistration: Select,
tbxVehicleTaxInYear: InputNumber,
tbxVehicleTaxInLeasingPeriod: InputNumber,
selectObjectCategoryTax: Select,
selectObjectTypeTax: Select,
radioTypePTS: Radio,
labelRegistrationDescription: Label,
};
const tablesComponents: StoreTables<Component> = {

View File

@ -5,6 +5,7 @@ const elementsComputedValues: TElements<ComputedValuesNames> = {
labelLeaseObjectRisk: 'leaseObjectRiskName',
tbxInsKaskoPriceLeasePeriod: 'insKaskoPriceLeasePeriod',
labelIrrInfo: 'irrInfo',
labelRegistrationDescription: 'registrationDescription',
};
export default elementsComputedValues;

View File

@ -339,6 +339,27 @@ const elementsProps: TElements<ElementProps> = {
componentElt: {
title: 'Расчет страховки в ЭЛТ',
},
radioObjectRegistration: {
style: 'button',
},
radioTypePTS: {
style: 'button',
},
tbxVehicleTaxInYear: {
min: 0,
step: 100,
max: 9999999,
precision: 2,
},
tbxVehicleTaxInLeasingPeriod: {
min: 0,
step: 100,
max: 9999999,
precision: 2,
},
selectObjectRegionRegistration: {
showSearch: true,
},
};
const resultElementsProps: TElements<ElementProps> = [

View File

@ -125,6 +125,14 @@ export const elementsTitles: TElements<string> = {
tbxMileage: 'Пробег, км',
radioCalcType: 'Расчет от',
tbxTotalPayments: 'Сумма платежей',
radioObjectRegistration: 'На кого регистрируется ТС',
selectObjectRegionRegistration: 'Регион регистрации в ГИБДД',
tbxVehicleTaxInYear: 'Транспортный налог, в год',
tbxVehicleTaxInLeasingPeriod: 'Транспортный налог на срок ДЛ',
selectObjectCategoryTax: 'Категория в соответствии с ТР ТС 018/2011',
selectObjectTypeTax: 'Тип ТС для ТН',
radioTypePTS: 'Тип ПТС',
labelRegistrationDescription: 'Описание регистрации',
};
const resultsTitles: TElements<string> = {

View File

@ -12,6 +12,7 @@ const elementsTypes: TElements<ElementType> = {
labelIrrInfo: ElementType.Computed,
linkDownloadKp: ElementType.Link,
componentElt: ElementType.Custom,
labelRegistrationDescription: ElementType.Computed,
};
const tablesTypes: StoreTables<ElementType> = {

View File

@ -126,6 +126,13 @@ export const elementsValues: TElements<ValuesNames> = {
tbxMileage: 'mileage',
radioCalcType: 'calcType',
tbxTotalPayments: 'totalPayments',
radioObjectRegistration: 'objectRegistration',
selectObjectRegionRegistration: 'objectRegionRegistration',
tbxVehicleTaxInYear: 'vehicleTaxInYear',
tbxVehicleTaxInLeasingPeriod: 'vehicleTaxInLeasingPeriod',
selectObjectCategoryTax: 'objectCategoryTax',
selectObjectTypeTax: 'objectTypeTax',
radioTypePTS: 'typePTS',
};
const resultElementsValues: TElements<ResultValuesNames> = {

View File

@ -56,6 +56,8 @@ const query = gql`
evo_name
evo_regionid
evo_fias_id
evo_businessunit_evolution
evo_oktmo
}
selectAccount: accounts(
evo_account_type: $account_account_type
@ -71,6 +73,7 @@ const query = gql`
evo_brandid
evo_importer_reward_perc
evo_importer_reward_rub
evo_vehicle_type
}
selectProduct: evo_baseproducts(
statecode: $statecode
@ -109,6 +112,11 @@ const query = gql`
evo_max_period
evo_min_period
evo_controls_program
evo_towtruck
evo_pts_type
evo_description
evo_gibdd_region
evo_whom_register
}
selectInsNSIB: evo_addproduct_types(
statecode: $statecode
@ -258,6 +266,17 @@ const query = gql`
evo_expluatation_period1
evo_expluatation_period2
evo_type_code
evo_category
evo_category_tr
evo_vehicle_type_tax
evo_vehicle_type
}
selectObjectRegionRegistration: evo_regions(statecode: $statecode) {
evo_name
evo_regionid
evo_fias_id
evo_businessunit_evolution
evo_oktmo
}
}
`;
@ -297,6 +316,7 @@ const toOptions = [
'selectTarif',
'selectRate',
'selectLeaseObjectType',
'selectObjectRegionRegistration',
];
export default {

View File

@ -1,5 +1,22 @@
import { Form, InputNumber as AntInputNumber } from 'antd';
import { Outlined } from 'client/Components/Spinner';
import { ElementStatus } from 'core/types/statuses';
import styled from 'styled-components';
const { Disabled, Loading } = ElementStatus;
const FormWrapper = styled(Form.Item)`
${props =>
props.withSpinner &&
`
.ant-form-item-control-input-content {
display: grid;
grid-template-columns: 9fr 1fr;
align-items: center;
gap:2px;
}
`}
`;
const InputNumber = ({
value,
@ -10,7 +27,11 @@ const InputNumber = ({
...props
}) => {
return (
<Form.Item validateStatus={validateStatus} help={message}>
<FormWrapper
validateStatus={validateStatus}
help={message}
withSpinner={status === ElementStatus.Loading}
>
<AntInputNumber
{...props}
parser={value => {
@ -20,12 +41,13 @@ const InputNumber = ({
}
return value;
}}
disabled={status === ElementStatus.Disabled}
disabled={[Disabled, Loading].includes(status)}
style={styles}
onChange={value => setCurrentValue(value)}
value={value}
/>
</Form.Item>
{status === ElementStatus.Loading && <Outlined />}
</FormWrapper>
);
};

View File

@ -0,0 +1,13 @@
import { Flex } from 'client/UIKit/grid';
export const CenterContent = props => (
<Flex
height="100%"
py="10px"
justifyContent="center"
alignItems="center"
px="5px"
>
{props.children}
</Flex>
);

View File

@ -1,11 +1,18 @@
import paths from 'core/common/paths';
import Spinner from 'client/Components/Spinner';
import { CenterContent } from 'client/Elements/Wrapper';
import paths from 'core/common/paths';
import { container as resolveContainer } from 'core/tools/resolve';
import { Suspense } from 'react';
import { Route, Switch } from 'react-router-dom';
import { container as resolveContainer } from 'core/tools/resolve';
export default () => (
<Suspense fallback={<Spinner />}>
<Suspense
fallback={
<CenterContent>
<Spinner />
</CenterContent>
}
>
<Switch>
{paths.map((path, i) => (
<Route

View File

@ -1,10 +1,12 @@
import { useStores } from 'client/hooks/useStores';
import { action as resolveAction } from 'core/tools/resolve';
export const useAction = ({ actionName }) => {
const { calculationStore } = useStores();
const action = () => {
resolveAction({ storeName: 'CalculationStore', actionName }).then(
({ default: resolvedAction }) => {
resolvedAction();
resolvedAction.call(calculationStore);
},
);
};

View File

@ -3,7 +3,7 @@ import initialFilters from 'client/stores/CalculationStore/config/initialFilters
import initialOptions from 'client/stores/CalculationStore/config/initialOptions';
import initialStatuses from 'client/stores/CalculationStore/config/initialStatuses';
import initialValues from 'client/stores/CalculationStore/config/initialValues';
import { isNil, mergeWith } from 'lodash';
import { isNil, mergeWith, pick } from 'lodash';
const valuesData = {
values: initialValues,
@ -17,6 +17,9 @@ const valuesActions = {
getValue(sourceValueName) {
return this.values[sourceValueName];
},
getValues(valuesNames) {
return pick(this.values, valuesNames);
},
setValue(sourceValueName, newValue) {
this.values[sourceValueName] = newValue;
},
@ -94,8 +97,16 @@ const valuesActions = {
getFilter(elementName) {
return this.filters[elementName];
},
setFilter(elementName, filters) {
this.filters[elementName] = filters;
setFilter(elementName, filter) {
const valueName = elementsValues[elementName];
const value = this.getValue(valueName);
if (
filter &&
!filter(this.getOptions(elementName)).some(x => x.value === value)
) {
this.setValue(valueName, null);
}
this.filters[elementName] = filter;
},
// applyFilters(filters) {
// this.filters = { ...this.filters, ...filters };

View File

@ -1,14 +0,0 @@
import { ICalculationStore } from 'core/types/Calculation/Store/index';
export default ({
calculationStore,
}: {
calculationStore: ICalculationStore;
}): any => {
const tarif = calculationStore.getOption('selectTarif');
if (tarif) {
return {
minCashflowMSFONominal: tarif.evo_min_irr,
maxCashflowMSFONominal: tarif.evo_max_irr,
};
}
};

View File

@ -1,14 +1,14 @@
import elementsTitles, {
tablesTitles
tablesTitles,
} from 'client/Containers/Calculation/lib/elements/titles';
import CalculationStore from 'client/stores/CalculationStore';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { TableNames } from 'core/types/Calculation/Store/tables';
import { omit } from 'lodash';
import { toJS } from 'mobx';
export default () => {
export default function (this: ICalculationStore) {
const invalidElements: string[] = [];
const { validations: storeValidations } = CalculationStore;
const { validations: storeValidations } = this;
const validations = toJS(storeValidations);
Object.keys(validations).forEach(elementName => {
if (validations[elementName] === false) {
@ -17,7 +17,7 @@ export default () => {
});
const invalidTables: string[] = [];
const { tables: storeTables } = CalculationStore;
const { tables: storeTables } = this;
const tables = omit(toJS(storeTables), tablesExclusion);
Object.keys(tables).forEach(tableName => {
if (
@ -32,6 +32,6 @@ export default () => {
});
return { invalidElements, invalidTables };
};
}
const tablesExclusion: TableNames[] = ['tableResults'];

View File

@ -1,40 +1,39 @@
import { message } from 'antd';
import { openNotification } from 'client/Elements/Notification';
import CalculationService from 'core/services/CalculationService';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { resultsValues } from 'core/types/Calculation/Store/values';
import { ElementStatus } from 'core/types/statuses';
import CalculationStore from '../../..';
import getAdditionalData from './additionalData';
import checkValidation from './checkValidation';
import prepareCalculationData from './prepareData';
import results from './results';
import validate from './validate';
const cleanResults = () => {
for (let resultValue of resultsValues) {
CalculationStore.setValue(resultValue, '');
}
};
const BUTTONS_TIMEOUT = 500;
function blockButtons() {
CalculationStore.setStatus('btnCreateKP', ElementStatus.Loading);
CalculationStore.setStatus('btnCalculate', ElementStatus.Loading);
}
export default function (this: ICalculationStore) {
const cleanResults = () => {
for (let resultValue of resultsValues) {
this.setValue(resultValue, '');
}
};
function unlockButtons() {
setTimeout(() => {
CalculationStore.setStatus('btnCreateKP', ElementStatus.Default);
}, BUTTONS_TIMEOUT);
setTimeout(() => {
CalculationStore.setStatus('btnCalculate', ElementStatus.Default);
}, BUTTONS_TIMEOUT);
}
const blockButtons = () => {
this.setStatus('btnCreateKP', ElementStatus.Loading);
this.setStatus('btnCalculate', ElementStatus.Loading);
};
export default async () => {
validate();
const { invalidElements, invalidTables } = checkValidation();
const unlockButtons = () => {
setTimeout(() => {
this.setStatus('btnCreateKP', ElementStatus.Default);
}, BUTTONS_TIMEOUT);
setTimeout(() => {
this.setStatus('btnCalculate', ElementStatus.Default);
}, BUTTONS_TIMEOUT);
};
validate.call(this);
const { invalidElements, invalidTables } = checkValidation.call(this);
if (invalidElements.length > 0 || invalidTables.length > 0) {
if (invalidElements.length > 0)
openNotification({
@ -56,17 +55,23 @@ export default async () => {
blockButtons();
var preparedData = prepareCalculationData({
calculationStore: CalculationStore,
});
var preparedData = prepareCalculationData.call(this);
console.log('preparedData', preparedData);
var additionalData = getAdditionalData({
calculationStore: CalculationStore,
});
const getAdditionalData = () => {
const tarif = this.getOption('selectTarif');
if (tarif) {
return {
minCashflowMSFONominal: tarif.evo_min_irr,
maxCashflowMSFONominal: tarif.evo_max_irr,
};
}
};
var additionalData = getAdditionalData.call(this);
console.log('additionalData', additionalData);
CalculationStore.cleanTable('tableResults');
this.cleanTable('tableResults');
cleanResults();
return CalculationService.calculate(
@ -79,9 +84,9 @@ export default async () => {
content: 'Расчет завершен успешно!',
});
results.showResultsTable(preparedData, res);
results.showResults(preparedData, res);
results.setResValues(res);
results.showResultsTable.call(this, preparedData, res);
results.showResults.call(this, preparedData, res);
results.setResValues.call(this, res);
return Object.assign(preparedData, res);
})
@ -102,4 +107,4 @@ export default async () => {
.finally(() => {
unlockButtons();
});
};
}

View File

@ -6,12 +6,8 @@ import { ICalculationStore } from 'core/types/Calculation/Store';
import NIL from 'uuid/dist/nil';
import { convertPrice } from '../../lib/tools';
export default ({
calculationStore,
}: {
calculationStore: ICalculationStore;
}): IPreparedData => {
const { values, options, tables } = calculationStore;
export default function (this: ICalculationStore): IPreparedData {
const { values, options, tables } = this;
const preparedPaymentsRows: PaymentRow[] = Array.from(
{ length: values.leasingPeriod },
@ -125,10 +121,11 @@ export default ({
preparedValues.carCarrying = values.maxMass;
preparedValues.bonus = (values.saleBonus as number) / 100;
preparedValues.bonusFix = 0;
preparedValues.transTax = 0;
preparedValues.transIncludeGr = false;
preparedValues.transportTaxGrYear = 0;
preparedValues.transportTaxGr = 0;
preparedValues.transTax = values.vehicleTaxInYear;
preparedValues.transIncludeGr = values.vehicleTaxInYear > 0;
preparedValues.transportTaxGrYear = values.vehicleTaxInYear;
preparedValues.transportTaxGr = values.vehicleTaxInLeasingPeriod;
const insuranceKaskoRow = tables.tableInsurance.rows.find(
x => x.policyType?.value === 'КАСКО',
@ -177,16 +174,14 @@ export default ({
preparedValues.repayment = 0.25;
if (values.firstPaymentPerc < 30) {
const evo_coefficient_season = calculationStore
.getStaticData('evo_coefficient')
.filter(
x =>
x.evo_corfficient_type === 100000000 &&
x.evo_min_period &&
x.evo_min_period <= values.leasingPeriod &&
x.evo_max_period &&
x.evo_max_period >= values.leasingPeriod,
);
const evo_coefficient_season = this.getStaticData('evo_coefficient').filter(
x =>
x.evo_corfficient_type === 100000000 &&
x.evo_min_period &&
x.evo_min_period <= values.leasingPeriod &&
x.evo_max_period &&
x.evo_max_period >= values.leasingPeriod,
);
switch (values.graphType) {
case 100000003:
if (evo_coefficient_season && evo_coefficient_season.length > 0) {
@ -231,9 +226,7 @@ export default ({
x => x.transactioncurrencyid === values.supplierCurrency,
);
const evo_currencychanges = calculationStore.getStaticData(
'evo_currencychange',
);
const evo_currencychanges = this.getStaticData('evo_currencychange');
const evo_currencychange = evo_currencychanges.find(
x => x.evo_ref_transactioncurrency === values.supplierCurrency,
);
@ -290,12 +283,10 @@ export default ({
(values.importerRewardPerc / 100) * preparedValues.acceptSum;
}
const evo_coefficient_bonuses = calculationStore
.getStaticData('evo_coefficient')
.filter(
x => x.evo_corfficient_type === 100000002 && x.evo_sot_coefficient_typeid,
);
const systemuser = calculationStore.getStaticData('systemuser')[0];
const evo_coefficient_bonuses = this.getStaticData('evo_coefficient').filter(
x => x.evo_corfficient_type === 100000002 && x.evo_sot_coefficient_typeid,
);
const systemuser = this.getStaticData('systemuser')[0];
if (
evo_coefficient_bonuses &&
@ -303,9 +294,9 @@ export default ({
systemuser &&
!Array.isArray(systemuser)
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'EXTRA_BONUS');
const evo_sot_coefficient_type = this.getStaticData(
'evo_sot_coefficient_type',
).find(x => x.evo_id === 'EXTRA_BONUS');
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
@ -324,9 +315,9 @@ export default ({
evo_coefficient_bonuses.length > 0 &&
systemuser
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'DIRECTOR_BONUS');
const evo_sot_coefficient_type = this.getStaticData(
'evo_sot_coefficient_type',
).find(x => x.evo_id === 'DIRECTOR_BONUS');
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
@ -344,9 +335,9 @@ export default ({
evo_coefficient_bonuses.length > 0 &&
systemuser
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'MARKET_RATE');
const evo_sot_coefficient_type = this.getStaticData(
'evo_sot_coefficient_type',
).find(x => x.evo_id === 'MARKET_RATE');
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
@ -367,9 +358,9 @@ export default ({
evo_coefficient_bonuses.length > 0 &&
systemuser
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'DISTRICT_RATE');
const evo_sot_coefficient_type = this.getStaticData(
'evo_sot_coefficient_type',
).find(x => x.evo_id === 'DISTRICT_RATE');
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
@ -390,9 +381,9 @@ export default ({
evo_coefficient_bonuses.length > 0 &&
systemuser
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'SALARY_RATE');
const evo_sot_coefficient_type = this.getStaticData(
'evo_sot_coefficient_type',
).find(x => x.evo_id === 'SALARY_RATE');
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
@ -442,7 +433,7 @@ export default ({
(preparedValues.registration || 0) +
(preparedValues.trackerCost || 0) +
(preparedValues.tLMCost || 0) +
preparedValues.transportTaxGr +
(preparedValues.transportTaxGr || 0) +
(preparedValues.tlmCostPaymentSum || 0) +
(preparedValues.gpsCostPaymentSum || 0)) *
preparedValues.leasing0K -
@ -480,9 +471,9 @@ export default ({
systemuser &&
!Array.isArray(systemuser)
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'BONUS_RAT_PR');
const evo_sot_coefficient_type = this.getStaticData(
'evo_sot_coefficient_type',
).find(x => x.evo_id === 'BONUS_RAT_PR');
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
@ -503,9 +494,9 @@ export default ({
systemuser &&
!Array.isArray(systemuser)
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'BONUS_NSIB_PR');
const evo_sot_coefficient_type = this.getStaticData(
'evo_sot_coefficient_type',
).find(x => x.evo_id === 'BONUS_NSIB_PR');
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
@ -527,9 +518,9 @@ export default ({
systemuser &&
!Array.isArray(systemuser)
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
.find(x => x.evo_id === 'BONUS_NS_PR');
const evo_sot_coefficient_type = this.getStaticData(
'evo_sot_coefficient_type',
).find(x => x.evo_id === 'BONUS_NS_PR');
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
@ -554,22 +545,20 @@ export default ({
preparedValues.irr_MSFO_Plan = (tarif.evo_irr_plan || 0) / 100;
}
const evo_coefficient_risk = calculationStore
.getStaticData('evo_coefficient')
?.find(
x =>
x.evo_corfficient_type === 100000001 &&
x.evo_min_period &&
x.evo_min_period <= values.leasingPeriod &&
x.evo_max_period &&
x.evo_max_period >= values.leasingPeriod,
// x.evo_client_riskid === values.clientRisk,
// x.evo_leasingobject_types &&
// x.evo_leasingobject_types.length > 0 &&
// x.evo_leasingobject_types.filter(
// z => z.evo_leasingobject_typeid === values.leaseObjectType,
// ).length > 0,
);
const evo_coefficient_risk = this.getStaticData('evo_coefficient')?.find(
x =>
x.evo_corfficient_type === 100000001 &&
x.evo_min_period &&
x.evo_min_period <= values.leasingPeriod &&
x.evo_max_period &&
x.evo_max_period >= values.leasingPeriod,
// x.evo_client_riskid === values.clientRisk,
// x.evo_leasingobject_types &&
// x.evo_leasingobject_types.length > 0 &&
// x.evo_leasingobject_types.filter(
// z => z.evo_leasingobject_typeid === values.leaseObjectType,
// ).length > 0,
);
if (evo_coefficient_risk)
preparedValues.npvniDelta = evo_coefficient_risk.evo_risk_delta || 0;
@ -619,4 +608,4 @@ export default ({
preparedPayments: { rows: preparedPaymentsRows },
preparedValues,
};
};
}

View File

@ -1,14 +1,15 @@
import CalculationStore from 'client/stores/CalculationStore';
import valuesConstants from 'core/constants/values';
import { IPreparedData } from 'core/types/Calculation/Requests';
import { IGetCalculationResponse } from 'core/types/Calculation/Responses';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { ITableCell, TableProps } from 'core/types/Calculation/Store/tables';
export default {
showResultsTable: (
showResultsTable: function (
this: ICalculationStore,
preparedData: IPreparedData,
res: IGetCalculationResponse,
) => {
) {
if (preparedData.preparedValues.nmper) {
const { sumWithVatColumn, vatColumn, sumRepaymentColumn } = res.columns;
const results: TableProps<ITableCell>[] = [];
@ -23,45 +24,46 @@ export default {
});
}
//TODO: speed up table render
CalculationStore.setTableRows('tableResults', 0)(results);
this.setTableRows('tableResults', 0)(results);
}
},
showResults: (preparedData: IPreparedData, res: IGetCalculationResponse) => {
showResults: function (
this: ICalculationStore,
preparedData: IPreparedData,
res: IGetCalculationResponse,
) {
const { sumWithVatColumn } = res.columns;
CalculationStore.setValue(
'resultTotalGraphwithNDS',
sumWithVatColumn?.values[0] || 0,
);
CalculationStore.setValue(
this.setValue('resultTotalGraphwithNDS', sumWithVatColumn?.values[0] || 0);
this.setValue(
'resultPlPrice',
(preparedData?.preparedValues?.acceptSum || 0) *
(1 + valuesConstants.VAT),
);
CalculationStore.setValue(
this.setValue(
'resultPriceUpPr',
(res?.postValues?.priceUP_Year_PR || 0) * 100,
);
CalculationStore.setValue(
this.setValue(
'resultIRRGraphPerc',
(res?.columns?.cashflowColumn?.irr || 0) * 100,
);
CalculationStore.setValue(
this.setValue(
'resultIRRNominalPerc',
(res?.columns?.cashflowMsfoColumn?.nominal || 0) * 100,
);
CalculationStore.setValue(
this.setValue(
'resultInsKasko',
preparedData?.preparedValues?.insuranceKasko || 0,
);
CalculationStore.setValue(
this.setValue(
'resultInsOsago',
preparedData?.preparedValues?.insuranceOsago || 0,
);
CalculationStore.setValue(
this.setValue(
'resultInsOsago',
preparedData?.preparedValues?.insuranceOsago || 0,
);
CalculationStore.setValue(
this.setValue(
'resultDopProdSum',
(preparedData?.preparedValues?.rats || 0) +
(preparedData?.preparedValues?.registration || 0) +
@ -69,29 +71,26 @@ export default {
(preparedData?.preparedValues?.tLMCost || 0) +
(preparedData?.preparedValues?.nsibBrutto || 0),
);
CalculationStore.setValue(
this.setValue(
'resultFirstPayment',
(preparedData?.preparedValues?.firstPaymentSum || 0) *
(1 + valuesConstants.VAT),
);
CalculationStore.setValue(
this.setValue(
'resultLastPayment',
(preparedData?.preparedValues?.lastPaymentSum || 0) *
(1 + valuesConstants.VAT),
);
CalculationStore.setValue(
'resultTerm',
preparedData?.preparedValues?.nmper || '',
);
CalculationStore.setValue(
this.setValue('resultTerm', preparedData?.preparedValues?.nmper || '');
this.setValue(
'resultAB_FL',
(((preparedData?.preparedValues?.agentsSum || 0) +
(preparedData?.preparedValues?.doubleAgentsSum || 0)) /
valuesConstants.ESN) *
(1 - valuesConstants.NDFL),
);
CalculationStore.setValue(
this.setValue(
'resultAB_UL',
((preparedData?.preparedValues?.deliverySum || 0) +
(preparedData?.preparedValues?.brokerSum || 0) +
@ -99,7 +98,7 @@ export default {
(preparedData?.preparedValues?.financialDeptOfDeliverySum || 0)) *
(1 + valuesConstants.VAT),
);
CalculationStore.setValue(
this.setValue(
'resultBonusMPL',
Math.abs(
((res?.columns?.npvBonusExpensesColumn?.values[2] || 0) /
@ -107,7 +106,7 @@ export default {
(1 - valuesConstants.NDFL),
),
);
CalculationStore.setValue(
this.setValue(
'resultDopMPLLeasing',
Math.abs(
((res?.columns?.extraBonusSumColumn?.values[2] || 0) /
@ -115,7 +114,7 @@ export default {
(1 - valuesConstants.NDFL),
),
);
CalculationStore.setValue(
this.setValue(
'resultBonusDopProd',
Math.abs(
((res?.columns?.npvBonusExpensesColumn?.values[1] || 0) /
@ -124,12 +123,15 @@ export default {
),
);
},
setResValues: (res: IGetCalculationResponse) => {
CalculationStore.setValue(
setResValues: function (
this: ICalculationStore,
res: IGetCalculationResponse,
) {
this.setValue(
'IRR_Perc',
(res?.columns?.cashflowMsfoColumn?.nominal || 0) * 100,
);
CalculationStore.setValue(
this.setValue(
'totalPayments',
res?.columns?.sumWithVatColumn?.values[0] || 0,
);

View File

@ -0,0 +1,106 @@
import { elementsValues } from 'client/Containers/Calculation/lib/elements/values';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { TElements } from 'core/types/Calculation/Store/elements';
const CONDITIONS = {
IS_NULL: value => value === undefined || value === null,
LESS_ZERO: value => value < 0,
LESS_OR_EQUALS_ZERO: value => value <= 0,
};
const CUSTOM_CONDITIONS: TElements<
(calculationStore: ICalculationStore) => boolean
> = {
selectLeaseObjectCategory: calculationStore => {
return (
calculationStore.values['selectLeaseObjectCategory'] &&
['6', '9', '10'].includes(
calculationStore.getOption('selectLeaseObjectType')?.evo_id || '',
)
);
},
selectQuote: calculationStore => {
const quote = calculationStore.getValue('quote');
return (
calculationStore.getValue('recalcWithRevision') === true &&
!CONDITIONS.IS_NULL(quote)
);
},
tbxVehicleTaxInYear: calculationStore => {
const objectRegistration = calculationStore.getValue('objectRegistration');
if (objectRegistration === 100000001) {
const vehicleTaxInYear = calculationStore.getValue('vehicleTaxInYear');
return CONDITIONS.LESS_OR_EQUALS_ZERO(vehicleTaxInYear);
}
return true;
},
radioTypePTS: calculationStore => {
const objectRegistration = calculationStore.getValue('objectRegistration');
if (objectRegistration === 100000001) {
const typePTS = calculationStore.getValue('typePTS');
return CONDITIONS.IS_NULL(typePTS);
}
return true;
},
selectObjectRegionRegistration: calculationStore => {
const objectRegistration = calculationStore.getValue('objectRegistration');
if (objectRegistration === 100000001) {
const objectRegionRegistration = calculationStore.getValue(
'objectRegionRegistration',
);
return CONDITIONS.IS_NULL(objectRegionRegistration);
}
return true;
},
};
const elementsValidations: TElements<any> = {
selectLead: CONDITIONS.IS_NULL,
selectProduct: CONDITIONS.IS_NULL,
selectSupplierCurrency: CONDITIONS.IS_NULL,
selectLeaseObjectType: CONDITIONS.IS_NULL,
selectBrand: CONDITIONS.IS_NULL,
selectModel: CONDITIONS.IS_NULL,
selectLeaseObjectUseFor: CONDITIONS.IS_NULL,
selectDealer: CONDITIONS.IS_NULL,
selectDealerPerson: CONDITIONS.IS_NULL,
selectRegionRegistration: CONDITIONS.IS_NULL,
selectTownRegistration: CONDITIONS.IS_NULL,
selectTarif: CONDITIONS.IS_NULL,
// selectRate: VALIDATIONS.IS_NULL,
selectRegistration: CONDITIONS.IS_NULL,
selectLeaseObjectCategory: CUSTOM_CONDITIONS.selectLeaseObjectCategory,
// selectSeasonType: valueName =>
// CalculationStore.getValue('graphType') === 100000003 &&
// VALIDATIONS.IS_NULL(valueName),
// selectHighSeasonStart: valueName =>
// CalculationStore.getValue('graphType') === 100000003 &&
// VALIDATIONS.IS_NULL(valueName),
tbxLeaseObjectPrice: CONDITIONS.LESS_OR_EQUALS_ZERO,
// tbxLastPaymentPerc: VALIDATIONS.IS_NULL,
// tbxLastPaymentRub: VALIDATIONS.IS_NULL,
// tbxFirstPaymentPerc: VALIDATIONS.IS_NULL,
// tbxFirstPaymentRub: VALIDATIONS.IS_NULL,
tbxLeaseObjectCount: CONDITIONS.LESS_OR_EQUALS_ZERO,
selectQuote: CUSTOM_CONDITIONS.selectQuote,
tbxVehicleTaxInYear: CUSTOM_CONDITIONS.tbxVehicleTaxInYear,
radioTypePTS: CUSTOM_CONDITIONS.radioTypePTS,
selectObjectRegionRegistration:
CUSTOM_CONDITIONS.selectObjectRegionRegistration,
};
export default function (this: ICalculationStore) {
Object.keys(elementsValidations).forEach(elementName => {
const valueName = elementsValues[elementName];
const value = this.getValue(valueName);
const condition = elementsValidations[elementName];
let conditionRes;
if (Object.keys(CUSTOM_CONDITIONS).includes(elementName)) {
conditionRes = condition(this);
} else {
conditionRes = condition(value);
}
//@ts-ignore
this.setValidation(elementName, !conditionRes);
});
}

View File

@ -0,0 +1,8 @@
import { ICalculationStore } from 'core/types/Calculation/Store';
import validateElements from './elements';
import validateTables from './tables';
export default function (this: ICalculationStore) {
validateElements.call(this);
validateTables.call(this);
}

View File

@ -1,78 +1,11 @@
import { elementsValues } from 'client/Containers/Calculation/lib/elements/values';
import valuesConstants from 'core/constants/values';
import { shiftRight } from 'core/tools/array';
import { TElements } from 'core/types/Calculation/Store/elements';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { isEqual, isNil } from 'lodash';
import CalculationStore from '../../..';
const { PERIODS_NUMBER } = valuesConstants;
const VALIDATIONS = {
IS_NULL: valueName =>
CalculationStore.getValue(valueName) === undefined ||
CalculationStore.getValue(valueName) === null,
LESS_ZERO: valueName => CalculationStore.getValue(valueName) < 0,
LESS_OR_EQUALS_ZERO: valueName => CalculationStore.getValue(valueName) <= 0,
};
const elementsValidations: TElements<any> = {
selectLead: VALIDATIONS.IS_NULL,
selectProduct: VALIDATIONS.IS_NULL,
selectSupplierCurrency: VALIDATIONS.IS_NULL,
selectLeaseObjectType: VALIDATIONS.IS_NULL,
selectBrand: VALIDATIONS.IS_NULL,
selectModel: VALIDATIONS.IS_NULL,
selectLeaseObjectUseFor: VALIDATIONS.IS_NULL,
selectDealer: VALIDATIONS.IS_NULL,
selectDealerPerson: VALIDATIONS.IS_NULL,
selectRegionRegistration: VALIDATIONS.IS_NULL,
selectTownRegistration: VALIDATIONS.IS_NULL,
selectTarif: VALIDATIONS.IS_NULL,
// selectRate: VALIDATIONS.IS_NULL,
selectRegistration: VALIDATIONS.IS_NULL,
selectLeaseObjectCategory: valueName => {
return (
!CalculationStore.values[valueName] &&
!['6', '9', '10'].includes(
CalculationStore.getOption('selectLeaseObjectType')?.evo_id || '',
)
);
},
// selectSeasonType: valueName =>
// CalculationStore.getValue('graphType') === 100000003 &&
// VALIDATIONS.IS_NULL(valueName),
// selectHighSeasonStart: valueName =>
// CalculationStore.getValue('graphType') === 100000003 &&
// VALIDATIONS.IS_NULL(valueName),
tbxLeaseObjectPrice: VALIDATIONS.LESS_OR_EQUALS_ZERO,
// tbxLastPaymentPerc: VALIDATIONS.IS_NULL,
// tbxLastPaymentRub: VALIDATIONS.IS_NULL,
// tbxFirstPaymentPerc: VALIDATIONS.IS_NULL,
// tbxFirstPaymentRub: VALIDATIONS.IS_NULL,
tbxLeaseObjectCount: VALIDATIONS.LESS_OR_EQUALS_ZERO,
selectQuote: valueName =>
CalculationStore.getValue('recalcWithRevision') === true &&
VALIDATIONS.IS_NULL(valueName),
};
const validateElement = (elementName, condition) => {
if (condition) {
CalculationStore.setValidation(elementName, false);
} else {
CalculationStore.setValidation(elementName, true);
}
};
const validateElements = () => {
Object.keys(elementsValidations).forEach(elementName => {
validateElement(
elementName,
elementsValidations[elementName](elementsValues[elementName]),
);
});
};
const validateInsuranceTable = () => {
const tableInsurance = CalculationStore.tables.tableInsurance;
function validateInsuranceTable(this: ICalculationStore) {
const tableInsurance = this.tables.tableInsurance;
const kaskoRowIndex = tableInsurance.rows.findIndex(
x => x.policyType?.value === 'КАСКО',
@ -81,7 +14,7 @@ const validateInsuranceTable = () => {
x => x.policyType?.value === 'ОСАГО',
);
CalculationStore.setTableRows(
this.setTableRows(
'tableInsurance',
0,
)([
@ -106,14 +39,14 @@ const validateInsuranceTable = () => {
},
},
]);
};
}
const validatePaymentsTable = () => {
const { graphType } = CalculationStore.values;
const payments = CalculationStore.tables.tablePayments.rows.map(
function validatePaymentsTable(this: ICalculationStore) {
const { graphType } = this.values;
const payments = this.tables.tablePayments.rows.map(
x => x.paymentRelation?.value,
);
const rows = CalculationStore.tables.tablePayments.rows;
const rows = this.tables.tablePayments.rows;
const isValidRows = () =>
!rows.some(x => x.paymentRelation?.validation === false);
@ -123,7 +56,7 @@ const validatePaymentsTable = () => {
const areMiddleRowsEqual =
new Set(payments.slice(1, payments.length - 1)).size === 1;
CalculationStore.setTableRows(
this.setTableRows(
'tablePayments',
1,
)(
@ -141,7 +74,7 @@ const validatePaymentsTable = () => {
const max = Math.max(...target_payments);
const areInvalidRows = max - min > 10;
CalculationStore.setTableRows(
this.setTableRows(
'tablePayments',
1,
)(
@ -168,7 +101,7 @@ const validatePaymentsTable = () => {
}
});
CalculationStore.setTableRows(
this.setTableRows(
'tablePayments',
2,
)(
@ -184,7 +117,7 @@ const validatePaymentsTable = () => {
payments.forEach((x, i) => {
if (i > 1 && i < rows.length - 1) {
const isInvalidValue = x > payments[i - 1] || x < 3;
CalculationStore.setTableRow(
this.setTableRow(
'tablePayments',
i,
)({
@ -200,18 +133,18 @@ const validatePaymentsTable = () => {
}
case 100000003: {
const { highSeasonStart: highSeasonStartId } = CalculationStore.values;
const { highSeasonStart: highSeasonStartId } = this.values;
if (!highSeasonStartId) {
return;
}
const highSeasonStart = parseInt(
CalculationStore.getOption('selectHighSeasonStart')?.name || '2',
this.getOption('selectHighSeasonStart')?.name || '2',
);
const shiftNumber = highSeasonStart - 2;
const middleRows = payments.slice(1, PERIODS_NUMBER + 1);
const unshiftedMiddleRows = shiftRight(middleRows, shiftNumber);
const seasonTypeOptions = CalculationStore.getOption('selectSeasonType');
const seasonTypeOptions = this.getOption('selectSeasonType');
if (!seasonTypeOptions) {
return;
}
@ -228,7 +161,7 @@ const validatePaymentsTable = () => {
stepsValues,
[...stepsValues].sort((a, b) => b - a),
);
CalculationStore.setTableRows(
this.setTableRows(
'tablePayments',
1,
)(
@ -244,7 +177,7 @@ const validatePaymentsTable = () => {
case 100000004: {
const targetRows = payments.slice(1, 4);
const areEqual3MiddleRows = new Set(targetRows).size === 1;
CalculationStore.setTableRows(
this.setTableRows(
'tablePayments',
1,
)(
@ -260,7 +193,7 @@ const validatePaymentsTable = () => {
targetRows.slice(0).sort((a, b) => a - b),
targetRows,
);
CalculationStore.setTableRows(
this.setTableRows(
'tablePayments',
1,
)(
@ -274,10 +207,9 @@ const validatePaymentsTable = () => {
break;
}
}
};
}
export default () => {
validateElements();
validateInsuranceTable();
validatePaymentsTable();
};
export default function (this: ICalculationStore) {
validateInsuranceTable.call(this);
validatePaymentsTable.call(this);
}

View File

@ -4,16 +4,16 @@ import { openNotification } from 'client/Elements/Notification';
import UserStore from 'client/stores/UserStore';
import { CRM_PROXY_URL } from 'core/constants/urls';
import CrmService from 'core/services/CrmService';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { toJS } from 'mobx';
import CalculationStore from '../..';
import customValues from '../lib/customValues';
import { quoteFields } from '../lib/queries';
import calculate from './calculate';
export default async () => {
const { values, tables } = CalculationStore;
const { calculationUrls } = CalculationStore.stores;
const calculationRes = await calculate();
export default async function (this: ICalculationStore) {
const { values, tables } = this;
const { calculationUrls } = this.stores;
const calculationRes = await calculate.call(this);
if (!calculationRes) {
return;
@ -38,14 +38,10 @@ export default async () => {
} = calculationRes;
const domainname = UserStore.getDomainName();
// if (process.env.NODE_ENV === 'development') {
console.log('domainname', domainname);
console.log('values', values);
console.log(
'insKaskoPriceLeasePeriod',
CalculationStore.insKaskoPriceLeasePeriod(),
);
// }
//@ts-ignore
console.log('insKaskoPriceLeasePeriod', this.insKaskoPriceLeasePeriod());
CrmService.createKp({
domainName: domainname,
@ -58,7 +54,7 @@ export default async () => {
calculationValues: {
...values,
insKaskoPriceLeasePeriod: customValues.insKaskoPriceLeasePeriod.call(
CalculationStore,
this,
),
},
},
@ -92,11 +88,12 @@ export default async () => {
),
});
}
CalculationStore.setValue('recalcWithRevision', false);
let quotes = toJS(CalculationStore.getOptions('selectQuote'));
this.setValue('recalcWithRevision', false);
let quotes = toJS(this.getOptions('selectQuote')) || [];
//@ts-ignore
quotes = [new_quote].concat(quotes);
const { quote: selected_quoteid } = CalculationStore.values;
const { quote: selected_quoteid } = this.values;
const {
entities: { quote: updated_quote },
} = await CrmService.crmgqlquery({
@ -113,14 +110,14 @@ export default async () => {
toOptions: ['quote'],
});
if (updated_quote) {
if (updated_quote && !Array.isArray(updated_quote)) {
const qIndex = quotes.findIndex(
quote => quote.quoteid === updated_quote.quoteid,
);
quotes.splice(qIndex, 1, updated_quote);
if (qIndex) quotes.splice(qIndex, 1, updated_quote);
}
CalculationStore.setOptions('selectQuote', quotes);
this.setOptions('selectQuote', quotes);
}
});
})
@ -134,4 +131,4 @@ export default async () => {
throw err.response.data;
});
};
}

View File

@ -1,7 +1,7 @@
import { openNotification } from 'client/Elements/Notification';
import CalculationStore from '../..';
import { ICalculationStore } from 'core/types/Calculation/Store';
export default () => {
export default function (this: ICalculationStore) {
const {
contactClient,
contact,
@ -9,10 +9,10 @@ export default () => {
account,
commentLead,
phoneNumber,
} = CalculationStore.values;
} = this.values;
if (!contactClient && !contact) {
CalculationStore.setValidation('selectContactClient', false);
CalculationStore.setValidation('tbxContact', false);
this.setValidation('selectContactClient', false);
this.setValidation('tbxContact', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -20,8 +20,8 @@ export default () => {
})();
}
if (!newClient && !account) {
CalculationStore.setValidation('tbxNewClient', false);
CalculationStore.setValidation('selectAccount', false);
this.setValidation('tbxNewClient', false);
this.setValidation('selectAccount', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -29,7 +29,7 @@ export default () => {
})();
}
if (!commentLead) {
CalculationStore.setValidation('tbxCommentLead', false);
this.setValidation('tbxCommentLead', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -37,7 +37,7 @@ export default () => {
})();
}
if (contact && !phoneNumber) {
CalculationStore.setValidation('tbxPhoneNumber', false);
this.setValidation('tbxPhoneNumber', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -45,22 +45,22 @@ export default () => {
})();
}
const { channel } = CalculationStore.values;
const { channel } = this.values;
if (!channel) {
CalculationStore.setValidation('selectChannel', false);
this.setValidation('selectChannel', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
description: 'Не указан канал привлечения',
})();
} else {
const { supplier, agent, finDepartment, broker } = CalculationStore.values;
const { supplier, agent, finDepartment, broker } = this.values;
switch (channel) {
case 100000000: {
CalculationStore.setValidation('selectFinDepartment', true);
CalculationStore.setValidation('selectBroker', true);
this.setValidation('selectFinDepartment', true);
this.setValidation('selectBroker', true);
if (!supplier) {
CalculationStore.setValidation('selectSupplier', false);
this.setValidation('selectSupplier', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -68,7 +68,7 @@ export default () => {
})();
}
if (!agent) {
CalculationStore.setValidation('selectAgent', false);
this.setValidation('selectAgent', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -78,10 +78,10 @@ export default () => {
break;
}
case 100000001: {
CalculationStore.setValidation('selectAgent', true);
CalculationStore.setValidation('selectBroker', true);
this.setValidation('selectAgent', true);
this.setValidation('selectBroker', true);
if (!supplier) {
CalculationStore.setValidation('selectSupplier', false);
this.setValidation('selectSupplier', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -89,7 +89,7 @@ export default () => {
})();
}
if (!finDepartment) {
CalculationStore.setValidation('selectFinDepartment', false);
this.setValidation('selectFinDepartment', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -99,11 +99,11 @@ export default () => {
break;
}
case 100000002: {
CalculationStore.setValidation('selectFinDepartment', true);
CalculationStore.setValidation('selectSupplier', true);
CalculationStore.setValidation('selectBroker', true);
this.setValidation('selectFinDepartment', true);
this.setValidation('selectSupplier', true);
this.setValidation('selectBroker', true);
if (!agent) {
CalculationStore.setValidation('selectAgent', false);
this.setValidation('selectAgent', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -113,11 +113,11 @@ export default () => {
break;
}
case 100000003: {
CalculationStore.setValidation('selectFinDepartment', true);
CalculationStore.setValidation('selectSupplier', true);
CalculationStore.setValidation('selectAgent', true);
this.setValidation('selectFinDepartment', true);
this.setValidation('selectSupplier', true);
this.setValidation('selectAgent', true);
if (!broker) {
CalculationStore.setValidation('selectBroker', false);
this.setValidation('selectBroker', false);
openNotification({
type: 'error',
title: 'Ошибка во время создания интереса',
@ -128,12 +128,12 @@ export default () => {
}
case 100000004:
default: {
CalculationStore.setValidation('selectFinDepartment', true);
CalculationStore.setValidation('selectSupplier', true);
CalculationStore.setValidation('selectAgent', true);
CalculationStore.setValidation('selectBroker', true);
this.setValidation('selectFinDepartment', true);
this.setValidation('selectSupplier', true);
this.setValidation('selectAgent', true);
this.setValidation('selectBroker', true);
break;
}
}
}
};
}

View File

@ -138,10 +138,6 @@ const autorunEffects: IAutorunEffect[] = [
calculationStore => () => {
const { leaseObjectType: leaseObjectTypeId } = calculationStore.values;
if (!leaseObjectTypeId) {
calculationStore.setStatus(
'selectLeaseObjectCategory',
ElementStatus.Default,
);
return;
}

View File

@ -55,6 +55,12 @@ const computedEffects = {
}
return '-';
},
registrationDescription() {
const registration = this.getOption('selectRegistration');
if (registration && registration.evo_description) {
return registration.evo_description;
}
},
};
export default computedEffects;

View File

@ -0,0 +1,413 @@
import { elementsValues } from 'client/Containers/Calculation/lib/elements/values';
import { openNotification } from 'client/Elements/Notification';
import _1CService from 'core/services/1CService';
import { currentDate } from 'core/tools/date';
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
import { TElements } from 'core/types/Calculation/Store/elements';
import { Process } from 'core/types/Calculation/Store/process';
import { ElementStatus } from 'core/types/statuses';
import { get } from 'lodash';
const v = {
tbxVehicleTaxInYear: { value: 0, validator: value => value === 0 },
radioTypePTS: { value: null, validator: value => value === null },
selectObjectRegionRegistration: {
value: null,
validator: value => value === null,
},
} as TElements<any>;
const gibddReactions: IReactionEffect[] = [
calculationStore => ({
expression: () => {
return calculationStore.getOption('selectLeaseObjectType');
},
effect: leaseObjectType => {
if (['6', '9', '10', '11'].includes(leaseObjectType.evo_id)) {
calculationStore.setStatus(
'radioObjectRegistration',
ElementStatus.Disabled,
);
calculationStore.setValue('objectRegistration', 100000000);
} else {
calculationStore.setStatus(
'radioObjectRegistration',
ElementStatus.Default,
);
}
},
options: {
fireImmediately: true,
},
}),
...Object.keys(v).map(elementName => {
const valueName = elementsValues[elementName];
const value = v[elementName].value;
const validator = v[elementName].validator;
return calculationStore => ({
expression: () => {
return calculationStore.getValues([valueName, 'objectRegistration']);
},
effect: values => {
calculationStore.setValidation(elementName, undefined);
if (values.objectRegistration === 100000001) {
calculationStore.setStatus(elementName, ElementStatus.Default);
calculationStore.setValidation(
elementName,
!validator(values[valueName]),
);
} else {
calculationStore.setStatus(elementName, ElementStatus.Disabled);
calculationStore.setValue(valueName, value);
}
},
options: {
fireImmediately: true,
},
});
}),
calculationStore => ({
expression: () => {
return calculationStore.getValues(['leasingPeriod', 'vehicleTaxInYear']);
},
effect: ({ vehicleTaxInYear, leasingPeriod }) => {
if (vehicleTaxInYear > 0) {
calculationStore.setValue(
'vehicleTaxInLeasingPeriod',
(vehicleTaxInYear / 12) * leasingPeriod,
);
} else {
calculationStore.setValue('vehicleTaxInLeasingPeriod', 0);
}
},
options: {
fireImmediately: true,
},
}),
(calculationStore, calculationProcess) => ({
expression: () => {
return calculationStore.getValues([
'leaseObjectType',
'objectCategoryTax',
'objectRegistration',
]);
},
effect: ({ objectRegistration, objectCategoryTax }) => {
if (calculationProcess.process === Process.LoadKp) {
return;
}
if (objectRegistration === 100000001) {
if ([100000006, 100000009].includes(objectCategoryTax)) {
calculationStore.setValue('objectTypeTax', 100000002);
} else {
const leaseObjectType = calculationStore.getOption(
'selectLeaseObjectType',
);
if (leaseObjectType && leaseObjectType.evo_vehicle_type_tax) {
calculationStore.setValue(
'objectTypeTax',
leaseObjectType.evo_vehicle_type_tax,
);
}
}
} else {
calculationStore.setValue('objectTypeTax', null);
}
},
options: {
fireImmediately: true,
},
}),
calculationStore => ({
expression: () => {
return calculationStore.getValues(['leaseObjectCategory', 'maxMass']);
},
effect: ({ leaseObjectCategory, maxMass }) => {
calculationStore.setValidation('tbxMaxMass', undefined);
switch (leaseObjectCategory) {
case 100000001: {
if (maxMass > 3500) {
calculationStore.setValidation('tbxMaxMass', false);
openNotification({
type: 'error',
title: 'Ошибка',
description:
'При категории ТС = В Разерешенная макс.масс не может быть больше 3500кг',
})();
}
break;
}
case 100000002: {
if (maxMass <= 3500) {
calculationStore.setValidation('tbxMaxMass', false);
openNotification({
type: 'error',
title: 'Ошибка',
description: 'Разерешенная макс.масс не может быть меньше 3500кг',
})();
}
break;
}
}
},
options: {
fireImmediately: true,
},
}),
calculationStore => ({
expression: () => {
return calculationStore.getOption('selectLeaseObjectType');
},
effect: ({ evo_category }) => {
calculationStore.setValue('leaseObjectCategory', evo_category);
},
options: {
fireImmediately: true,
},
}),
calculationStore => ({
expression: () => {
return calculationStore.getValues([
'leaseObjectType',
'leaseObjectCategory',
'typePTS',
'objectRegistration',
]);
},
effect: ({ leaseObjectCategory, typePTS, objectRegistration }) => {
calculationStore.setStatus(
'selectObjectCategoryTax',
ElementStatus.Disabled,
);
if (objectRegistration === 100000001 && typePTS === 100000001) {
calculationStore.setStatus(
'selectObjectCategoryTax',
ElementStatus.Default,
);
const leaseObjectType = calculationStore.getOption(
'selectLeaseObjectType',
);
if (leaseObjectCategory === leaseObjectType?.evo_category) {
calculationStore.setFilter('selectObjectCategoryTax', options =>
options.filter(option =>
//@ts-ignore
leaseObjectType?.evo_category_tr?.includes(option.value),
),
);
}
} else {
calculationStore.setValue('objectCategoryTax', null);
}
},
}),
calculationStore => ({
expression: () => {
return {
...calculationStore.getValues([
'typePTS',
'objectRegistration',
'objectCategoryTax',
]),
leaseObjectType: calculationStore.getOption('selectLeaseObjectType'),
};
},
effect: ({
leaseObjectType,
typePTS,
objectRegistration,
objectCategoryTax,
}) => {
if (
objectRegistration === 100000001 &&
typePTS === 100000001 &&
objectCategoryTax === null &&
leaseObjectType &&
leaseObjectType.evo_category_tr &&
leaseObjectType.evo_category_tr.length
) {
calculationStore.setValidation('selectObjectCategoryTax', false);
openNotification({
type: 'error',
title: 'Ошибка',
description:
'Необходимо из ЭПТС указать Категорию в соответствии с ТР ТС 018/2011',
})();
} else {
calculationStore.setValidation('selectObjectCategoryTax', undefined);
}
},
}),
calculationStore => ({
expression: () => {
return {
leaseObjectType: calculationStore.getOption('selectLeaseObjectType'),
...calculationStore.getValues(['insNSIB']),
};
},
effect: ({ leaseObjectType }) => {
if (
leaseObjectType.evo_id === '11' &&
calculationStore.getValue('insNSIB') === null
) {
calculationStore.setValidation('selectInsNSIB', false);
openNotification({
type: 'error',
title: 'Ошибка',
description: 'Страхование НСИБ обязательно для мотоциклистов',
})();
} else {
calculationStore.setValidation('selectInsNSIB', undefined);
}
},
}),
(calculationStore, calculationProcess) => ({
expression: () => {
return calculationStore.getValues([
'objectRegistration',
'objectTypeTax',
'regionRegistration',
'leaseObjectYear',
'leaseObjectMotorPower',
]);
},
effect: ({
objectRegistration,
objectTypeTax,
regionRegistration,
leaseObjectYear,
leaseObjectMotorPower,
}) => {
if (calculationProcess.process !== Process.Default) {
return;
}
if (
objectRegistration === null ||
objectRegistration !== 100000001 ||
objectTypeTax === null ||
regionRegistration === null ||
leaseObjectYear === 0 ||
leaseObjectMotorPower === 0
) {
calculationStore.setValue('vehicleTaxInYear', 0);
return;
}
calculationStore.setStatus('tbxVehicleTaxInYear', ElementStatus.Loading);
const regionRegistrationOption = calculationStore.getOption(
'selectRegionRegistration',
);
const objectTypeTaxOption = calculationStore.getOption(
'selectObjectTypeTax',
);
_1CService.leasingTrial
.getTransTax({
calcDate: currentDate,
power: leaseObjectMotorPower,
year: leaseObjectYear,
OKTMO: regionRegistrationOption?.evo_oktmo || '',
//@ts-ignore
carCategory: objectTypeTaxOption.type,
})
.then(res => {
calculationStore.setValue('vehicleTaxInYear', res.tax || 0);
})
.finally(() => {
calculationStore.setStatus(
'tbxVehicleTaxInYear',
ElementStatus.Default,
);
});
},
}),
calculationStore => ({
expression: () => {
return calculationStore.getValues([
'objectRegistration',
'objectRegionRegistration',
'regionRegistration',
'typePTS',
]);
},
effect: ({
objectRegistration,
objectRegionRegistration,
regionRegistration,
typePTS,
}) => {
calculationStore.setFilter('selectRegistration', options =>
options.filter(
x =>
x.evo_whom_register === objectRegistration &&
x.evo_pts_type &&
x.evo_pts_type.includes(typePTS) &&
x.evo_gibdd_region ===
(objectRegionRegistration === regionRegistration),
),
);
},
}),
(calculationStore, calculationProcess) => ({
expression: () => {
return {
lead: calculationStore.getOption('selectLead'),
opportunity: calculationStore.getOption('selectOpportunity'),
objectRegistration: calculationStore.getValue('objectRegistration'),
};
},
effect: ({ lead, opportunity, objectRegistration }) => {
if (calculationProcess.process !== Process.Default) {
return;
}
calculationStore.setFilter('selectRegionRegistration', undefined);
calculationStore.setStatus(
'selectRegionRegistration',
ElementStatus.Default,
);
calculationStore.setValue('regionRegistration', null);
if (objectRegistration === 100000001) {
calculationStore.setFilter('selectRegionRegistration', options =>
options.filter(x => x.evo_businessunit_evolution === true),
);
} else {
const evo_region_fias_id = get(
lead.accountidData || opportunity.accountidData,
'evo_address_legalidData.evo_region_fias_id',
undefined,
);
if (evo_region_fias_id) {
calculationStore.setStatus(
'selectRegionRegistration',
ElementStatus.Disabled,
);
const targetObjectRegistration = calculationStore.getOption(
'selectRegionRegistration',
{
evo_fias_id: evo_region_fias_id,
},
);
if (targetObjectRegistration) {
calculationStore.setValue(
'regionRegistration',
targetObjectRegistration.evo_regionid,
);
}
}
}
},
}),
];
export default gibddReactions;

View File

@ -1,10 +1,11 @@
import requestReactions from './requestReactions';
import gibddReactions from './gibddReactions';
import loadKpReaction from './loadKpReaction';
import otherReactions from './otherReactions';
import priceReactions from './priceReactions';
import tablesReactions from './tablesReactions';
import loadKpReaction from './loadKpReaction';
import statusReactions from './statusReactions';
import recalcWoRevisionReactions from './recalcWoRevisionReactions';
import requestReactions from './requestReactions';
import statusReactions from './statusReactions';
import tablesReactions from './tablesReactions';
export default [
...otherReactions,
@ -13,5 +14,6 @@ export default [
...tablesReactions,
...statusReactions,
...recalcWoRevisionReactions,
...gibddReactions,
loadKpReaction,
];

View File

@ -87,48 +87,6 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
let regionRegistration = quote.evo_regionid,
townRegistration = quote.evo_townid;
let accountidData;
if (lead) {
const selected_lead = calculationStore.getOption('selectLead', {
value: lead,
});
if (selected_lead && selected_lead.accountidData) {
accountidData = selected_lead.accountidData;
}
}
if (opportunity) {
const selected_opportunity = calculationStore.getOption(
'selectOpportunity',
{
value: opportunity,
},
);
if (selected_opportunity && selected_opportunity.accountidData) {
accountidData = selected_opportunity.accountidData;
}
}
let evo_region_fias_id, evo_city_fias_id;
if (accountidData) {
const { evo_address_legalidData } = accountidData;
evo_region_fias_id = evo_address_legalidData.evo_region_fias_id;
evo_city_fias_id = evo_address_legalidData.evo_city_fias_id;
}
if (evo_region_fias_id) {
const region = calculationStore.getOption(
'selectRegionRegistration',
{
evo_fias_id: evo_region_fias_id,
},
);
if (region) {
regionRegistration = region.evo_regionid;
}
}
const {
entities: options,
}: IGetCRMEntitiesResponse & {
@ -210,15 +168,6 @@ const loadKpReaction: IReactionEffect = calculationStore => ({
},
]);
if (evo_city_fias_id) {
const city = calculationStore.getOption('selectTownRegistration', {
evo_fias_id: evo_city_fias_id,
});
if (city) {
townRegistration = city.evo_townid;
}
}
let evo_graph: IEvoGraph = {};
if (quote.evo_graphs) {
evo_graph = quote.evo_graphs.sort(

View File

@ -86,6 +86,11 @@ const mapKPtoValues: TValues<string> = {
requirementTelematic: 'evo_req_telematic_accept',
mileage: 'evo_mileage',
fullPriceWithDiscount: 'evo_price_without_discount_quote',
objectRegistration: 'evo_object_registration',
objectRegionRegistration: 'evo_registration_regionid',
vehicleTaxInYear: 'evo_vehicle_tax_approved',
objectCategoryTax: 'evo_category_tr',
objectTypeTax: 'evo_vehicle_type_tax',
};
export default mapKPtoValues;

View File

@ -32,6 +32,11 @@ export default gql`
evo_client_riskid
evo_regionid
evo_townid
evo_object_registration
evo_registration_regionid
evo_vehicle_tax_approved
evo_category_tr
evo_vehicle_type_tax
}
}
`;

View File

@ -2,7 +2,7 @@ import { openNotification } from 'client/Elements/Notification';
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
import { Process } from 'core/types/Calculation/Store/process';
import { ElementStatus } from 'core/types/statuses';
import { round } from 'lodash';
import { intersection, round } from 'lodash';
const reactionEffects: IReactionEffect[] = [
// calculationStore => ({
@ -1361,34 +1361,6 @@ const reactionEffects: IReactionEffect[] = [
// },
// }),
calculationStore => ({
expression: () => {
const { product } = calculationStore.values;
return product;
},
effect: productId => {
if (productId) {
const product = calculationStore.getOption('selectProduct', {
evo_id: productId,
});
if (product) {
const registraction_2020_3 = calculationStore.getOption(
'selectRegistration',
{
evo_id: '2020_3',
},
);
if (registraction_2020_3) {
calculationStore.setValue(
'registration',
registraction_2020_3.evo_addproduct_typeid,
);
}
}
}
},
}),
calculationStore => ({
expression: () => {
const { product, leasingPeriod } = calculationStore.values;
@ -1513,24 +1485,6 @@ const reactionEffects: IReactionEffect[] = [
},
}),
//TODO: global setFilter => reset Value
calculationStore => ({
expression: () => {
const { selectLeaseObjectCategory } = calculationStore.filters;
return selectLeaseObjectCategory;
},
effect: selectLeaseObjectCategoryFilter => {
const { leaseObjectCategory } = calculationStore.values;
if (
!selectLeaseObjectCategoryFilter(
calculationStore.getOptions('selectLeaseObjectCategory'),
).some(x => x.value === leaseObjectCategory)
) {
calculationStore.setValue('leaseObjectCategory', null);
}
},
}),
calculationStore => ({
expression: () => {
const {
@ -1560,12 +1514,6 @@ const reactionEffects: IReactionEffect[] = [
if (leaseObjectType) {
switch (leaseObjectType.evo_id) {
case '1': {
calculationStore.setValue('leaseObjectCategory', 100000001);
calculationStore.setStatus(
'selectLeaseObjectCategory',
ElementStatus.Disabled,
);
const { countSeats } = calculationStore.values;
if (countSeats && countSeats >= 9) {
calculationStore.setValidation('tbxCountSeats', false);
@ -1579,16 +1527,6 @@ const reactionEffects: IReactionEffect[] = [
}
case '2': {
calculationStore.setStatus(
'selectLeaseObjectCategory',
ElementStatus.Default,
);
calculationStore.setFilter('selectLeaseObjectCategory', options =>
options.filter(
x => x.value === 100000001 || x.value === 100000002,
),
);
const { maxMass } = calculationStore.values;
if (!maxMass) {
calculationStore.setValidation('tbxMaxMass', false);
@ -1604,16 +1542,6 @@ const reactionEffects: IReactionEffect[] = [
case '4':
case '5': {
calculationStore.setStatus(
'selectLeaseObjectCategory',
ElementStatus.Default,
);
calculationStore.setFilter('selectLeaseObjectCategory', options =>
options.filter(
x => x.value === 100000001 || x.value === 100000003,
),
);
const { countSeats } = calculationStore.values;
if (countSeats <= 8) {
calculationStore.setValidation('tbxCountSeats', false);
@ -1625,43 +1553,6 @@ const reactionEffects: IReactionEffect[] = [
}
break;
}
case '6':
case '9':
case '10': {
calculationStore.setValue('leaseObjectCategory', null);
calculationStore.setStatus(
'selectLeaseObjectCategory',
ElementStatus.Disabled,
);
break;
}
case '3':
case '7': {
calculationStore.setValue('leaseObjectCategory', 100000002);
calculationStore.setStatus(
'selectLeaseObjectCategory',
ElementStatus.Disabled,
);
break;
}
case '8': {
calculationStore.setValue('leaseObjectCategory', 100000004);
calculationStore.setStatus(
'selectLeaseObjectCategory',
ElementStatus.Disabled,
);
break;
}
default: {
calculationStore.setStatus(
'selectLeaseObjectCategory',
ElementStatus.Default,
);
break;
}
}
}
},
@ -1780,6 +1671,53 @@ const reactionEffects: IReactionEffect[] = [
);
},
}),
calculationStore => ({
expression: () => {
return calculationStore.getOption('selectLeaseObjectType');
},
effect: leaseObjectType => {
calculationStore.setStatus(
'selectBrand',
leaseObjectType ? ElementStatus.Default : ElementStatus.Disabled,
);
calculationStore.setValue('brand', null);
calculationStore.setFilter('selectBrand', options =>
options.filter(
option =>
option.evo_vehicle_type &&
intersection(
option.evo_vehicle_type?.filter(x => x > 0),
leaseObjectType.evo_vehicle_type,
).length > 0,
),
);
},
options: {
fireImmediately: true,
},
}),
calculationStore => ({
expression: () => {
return calculationStore.getOption('selectBrand');
},
effect: () => {
const leaseObjectType = calculationStore.getOption(
'selectLeaseObjectType',
);
calculationStore.setFilter('selectModel', options =>
options.filter(
option =>
option.evo_vehicle_type &&
leaseObjectType &&
leaseObjectType.evo_vehicle_type &&
leaseObjectType.evo_vehicle_type.includes(option.evo_vehicle_type),
),
);
},
}),
];
export default reactionEffects;

View File

@ -819,6 +819,8 @@ export default [
evo_importer_reward_perc
evo_importer_reward_rub
evo_impairment_groupid
evo_vehicle_type
evo_gps
}
}
`,
@ -1040,6 +1042,7 @@ export default [
) {
evo_name
evo_gps_modelid
evo_moto
}
}
`,

View File

@ -334,6 +334,77 @@ const initialOptions: TElements<IBaseOption[]> = {
value: 100000002,
},
],
radioObjectRegistration: [
{
name: 'Лизингополучатель',
value: 100000000,
},
{
name: 'Лизингодатель',
value: 100000001,
},
],
radioTypePTS: [
{
name: 'Бумажный',
value: 100000000,
},
{
name: 'Электронный',
value: 100000001,
},
],
selectObjectCategoryTax: [
'M1',
'M2',
'M3',
'M1G',
'M2G',
'M3G',
'N1',
'N2',
'N3',
'N1G',
'N2G',
'N3G',
'O1',
'O2',
'O3',
'O4',
'L1',
'L2',
'L3',
'L4',
'L5',
].map((name, i) => ({
name,
value: 100000000 + i,
})),
selectObjectTypeTax: [
{
name: 'Автобус',
type: 'D',
},
{
name: 'Легковой',
type: 'B',
},
{
name: 'Грузовой',
type: 'C',
},
{
name: 'Спецтехника',
type: 'T',
},
{
name: 'Мотоцикл',
type: 'A',
},
].map((v, i) => ({
...v,
value: 100000000 + i,
})),
};
export default initialOptions;

View File

@ -1,5 +1,5 @@
import { ElementStatus } from 'core/types/statuses';
import { TElements } from 'core/types/Calculation/Store/elements';
import { ElementStatus } from 'core/types/statuses';
const initialStatuses: TElements<ElementStatus> = {
selectIndAgent: ElementStatus.Disabled,
@ -34,8 +34,11 @@ const initialStatuses: TElements<ElementStatus> = {
tbxCommentLead: ElementStatus.Disabled,
btnCreateLead: ElementStatus.Disabled,
selectRegistration: ElementStatus.Disabled,
selectTracker: ElementStatus.Disabled,
tbxVehicleTaxInLeasingPeriod: ElementStatus.Disabled,
selectObjectTypeTax: ElementStatus.Disabled,
selectLeaseObjectCategory: ElementStatus.Disabled,
};
export default initialStatuses;

View File

@ -82,5 +82,10 @@ const initialValues: TValues<TValue> = {
rate: 'BASE',
calcType: 100000000,
totalPayments: 0,
vehicleTaxInYear: 0,
vehicleTaxInLeasingPeriod: 0,
objectRegistration: 100000000,
typePTS: 100000001,
insNSIB: null,
};
export default initialValues;

View File

@ -3,7 +3,7 @@ import { makeAutoObservable } from 'mobx';
const calculationUrls = makeAutoObservable({
urls: {},
setUrl({ name, url }: { name: LinksNames; url: string }) {
setUrl({ name, url }: { name: LinksNames; url?: string }) {
this.urls[name] = url;
},
});

View File

@ -2,3 +2,4 @@ export const CRM_PROXY_URL = '/crmgraphql';
export const CORE_PROXY_URL = '/core';
export const AUTH_PROXY_URL = '/auth-srv';
export const ELT_PROXY_URL = '/elt';
export const _1C_PROXY_URL = '/1c';

View File

@ -0,0 +1,3 @@
import leasingTrial from './leasingTrial';
export default { leasingTrial };

View File

@ -0,0 +1,23 @@
import axios from 'axios';
import { _1C_PROXY_URL } from 'core/constants/urls';
import { IGetTransTaxRequest } from 'core/types/Calculation/Requests';
import { IGetTransTaxResponse } from 'core/types/Calculation/Responses';
export default class {
static getTransTax = (
payload: IGetTransTaxRequest,
): Promise<IGetTransTaxResponse> =>
new Promise((resolve, reject) => {
axios
.post(
String.prototype.concat(_1C_PROXY_URL, '/leasingTrial', '/transTax'),
payload,
)
.then(res => {
resolve(res.data);
})
.catch(err => {
reject(err);
});
});
}

View File

@ -4,7 +4,7 @@ import { CRM_PROXY_URL } from 'core/constants/urls';
import {
ICreateKpRequest,
IMutateToCRMGQL,
IQueryToCRMGQL
IQueryToCRMGQL,
} from 'core/types/Calculation/Requests';
import { IGetCRMEntitiesResponse } from 'core/types/Calculation/Responses';
import { IBaseOption } from 'core/types/Calculation/Store/options';
@ -45,6 +45,7 @@ export default class {
const optionatedEntities: (TCRMEntity & IBaseOption)[] = [];
for (const entity of targetEnt) {
const entityOption = convertEntityToOption(
targetName,
entity,
entity.__typename,
);
@ -58,6 +59,7 @@ export default class {
] = optionatedEntities;
} else {
const entityOption = convertEntityToOption(
targetName,
targetEnt,
targetEnt.__typename,
);

View File

@ -2,11 +2,12 @@ import { TCRMEntity } from 'core/types/Entities/crmEntities';
import { TEntities } from 'core/types/Entities/crmEntityNames';
const propsMap: TEntities<{
name: keyof TCRMEntity | (keyof TCRMEntity)[];
name?: keyof TCRMEntity;
value: keyof TCRMEntity;
getName?: (entity: TCRMEntity, targetName: string) => string | undefined;
}> = {
account: {
name: ['name', 'evo_kpp'],
getName: account => `${account.name} ${account.evo_kpp || ''}`,
value: 'accountid',
},
lead: {
@ -54,7 +55,8 @@ const propsMap: TEntities<{
value: 'evo_modelid',
},
evo_equipment: {
name: ['evo_name', 'evo_start_production_year'],
getName: equipment =>
`${equipment.evo_name} (${equipment.evo_start_production_year})`,
value: 'evo_equipmentid',
},
evo_reward_condition: {
@ -94,7 +96,20 @@ const propsMap: TEntities<{
value: 'evo_coefficientid',
},
evo_addproduct_type: {
name: 'evo_name',
getName: (productType, targetName) => {
if (
[
'selectRegistration',
'selectTechnicalCard',
'selectTelematic',
'selectTracker',
].includes(targetName) &&
productType.evo_graph_price !== undefined
) {
return `${productType.evo_name} (${productType.evo_graph_price} руб.)`;
}
return productType.evo_name;
},
value: 'evo_addproduct_typeid',
},
evo_planpayment: {

View File

@ -4,8 +4,9 @@ import { CRMEntityNames } from 'core/types/Entities/crmEntityNames';
import propsMap from '../propsMap';
export function convertEntityToOption(
targetName: string,
entity: TCRMEntity,
entityName?: CRMEntityNames
entityName?: CRMEntityNames,
): (TCRMEntity & IBaseOption) | undefined {
if (!entityName) {
throw new Error('entityName is missing');
@ -17,20 +18,24 @@ export function convertEntityToOption(
const entityPropsMap = propsMap[entityName];
if (entityPropsMap) {
const { name: propName, value: propValue } = entityPropsMap;
const { name: propName, getName, value: propValue } = entityPropsMap;
let name;
const value = entity[propValue];
if (!Array.isArray(propName)) {
if (propName) {
name = entity[propName];
} else {
name = propName.map(field => entity[field]).join(' ');
}
if (getName) {
name = getName(entity, targetName);
}
if (targetName) {
}
const optionatedObject = {
...entity,
name,
value
value,
};
return optionatedObject;
}

View File

@ -1,7 +1,7 @@
import { ColumnsNames, IColumn, PostValues } from 'core/types/Calculation/Core';
import {
PreparedPayments,
PreparedValues
PreparedValues,
} from 'core/types/Calculation/Prepare';
import { ElementsNames } from 'core/types/Calculation/Store/elements';
import { TableProps } from 'core/types/Calculation/Store/tables';
@ -33,8 +33,16 @@ export interface ICreateKpRequest {
insurances: TableProps<any>[];
preparedValues: PreparedValues;
preparedPayments: PreparedPayments;
calculationColumns: { [column in ColumnsNames]?: IColumn };
postValues: PostValues;
calculationValues: TValues<any>;
columns: { [column in ColumnsNames]?: IColumn };
};
}
export interface IGetTransTaxRequest {
calcDate: Date;
OKTMO: string;
carCategory: string;
power: number;
year: number;
}

View File

@ -1,7 +1,7 @@
import { PreparedValues } from './Prepare';
import { TCRMEntity } from '../Entities/crmEntities';
import { TEntities } from '../Entities/crmEntityNames';
import { ColumnsNames, IColumn, PostValues } from './Core';
import { PreparedValues } from './Prepare';
export interface IGetCRMEntitiesResponse {
entities: TEntities<TCRMEntity | TCRMEntity[]>;
@ -12,3 +12,8 @@ export interface IGetCalculationResponse {
postValues: PostValues;
preparedValues: PreparedValues;
}
export interface IGetTransTaxResponse {
tax: number;
error: string;
}

View File

@ -135,7 +135,15 @@ export type ElementsNames =
| 'labelIrrInfo'
| 'tbxMileage'
| 'radioCalcType'
| 'tbxTotalPayments';
| 'tbxTotalPayments'
| 'radioObjectRegistration'
| 'selectObjectRegionRegistration'
| 'tbxVehicleTaxInYear'
| 'tbxVehicleTaxInLeasingPeriod'
| 'selectObjectCategoryTax'
| 'selectObjectTypeTax'
| 'radioTypePTS'
| 'labelRegistrationDescription';
export type LinkElementsNames = 'linkDownloadKp';

View File

@ -56,6 +56,7 @@ interface ICalculationValues {
values: TValues<any>;
getValue: (sourceValueName: ValuesNames) => TValue;
getValues: (valuesNames: ValuesNames[]) => TValues<any>;
setValue: (
sourceValueName: ValuesNames | ResultValuesNames,
newValue: TValue,

View File

@ -122,14 +122,22 @@ export type ValuesNames =
| 'tracker'
| 'mileage'
| 'calcType'
| 'totalPayments';
| 'totalPayments'
| 'objectRegistration'
| 'objectRegionRegistration'
| 'vehicleTaxInYear'
| 'vehicleTaxInLeasingPeriod'
| 'objectCategoryTax'
| 'objectTypeTax'
| 'typePTS';
export type ComputedValuesNames =
| 'leadName'
| 'opportunityName'
| 'leaseObjectRiskName'
| 'insKaskoPriceLeasePeriod'
| 'irrInfo';
| 'irrInfo'
| 'registrationDescription';
export const resultsValues = [
'resultTotalGraphwithNDS',

View File

@ -133,6 +133,10 @@ export interface IEvoLeasingObjectType {
evo_expluatation_period2?: number;
evo_type_code?: string;
evo_baseproduct?: any;
evo_category?: number;
evo_category_tr?: number[];
evo_vehicle_type_tax?: number;
evo_vehicle_type?: number[];
}
export interface IEvoBrand {
@ -141,6 +145,7 @@ export interface IEvoBrand {
evo_importer_reward_perc?: number;
evo_importer_reward_rub?: number;
statecode?: number;
evo_vehicle_type?: number[];
}
export interface IEvoModel {
@ -153,6 +158,8 @@ export interface IEvoModel {
evo_importer_reward_rub?: number;
statecode?: number;
evo_baseproduct?: any;
evo_vehicle_type?: number;
evo_gps?: boolean;
}
export interface IEvoEquipment {
@ -166,6 +173,7 @@ export interface IEvoEquipment {
evo_supplier_accountid?: string;
evo_dealer_person_accountid?: string;
evo_dealer_broker_accountid?: string;
evo_vehicle_type?: number;
}
export interface IEvoRewardCondition {
@ -190,12 +198,15 @@ export interface IEvoGPSModel {
evo_name?: string;
evo_gps_brandid?: string;
statecode?: number;
evo_moto?: boolean;
}
export interface IEvoRegion {
evo_name?: string;
evo_regionid?: string;
evo_fias_id?: string;
statecode?: number;
evo_businessunit_evolution?: boolean;
evo_oktmo?: string;
}
export interface IEvoTown {
evo_name?: string;
@ -301,6 +312,11 @@ export interface IEvoAddproductType {
evo_cost_equipment?: number;
evo_controls_program?: number[];
evo_helpcard_type?: number;
evo_towtruck?: boolean;
evo_pts_type?: number[];
evo_description?: string;
evo_whom_register?: number;
evo_gibdd_region?: boolean;
}
export interface IEvoTarif {