refactor
This commit is contained in:
parent
643392e6ab
commit
9f697ea161
@ -372,7 +372,7 @@ const sections: ISections[] = [
|
||||
},
|
||||
// TODO formatter + rub, parser
|
||||
{
|
||||
title: 'Скидка от поставщика, рубли',
|
||||
title: 'Скидка от поставщика',
|
||||
Component: InputNumber,
|
||||
props: {
|
||||
min: '0',
|
||||
@ -393,36 +393,37 @@ const sections: ISections[] = [
|
||||
name: 'tbxSupplierDiscountPerc',
|
||||
valueName: 'supplierDiscountPerc',
|
||||
},
|
||||
}, // TODO Input x Addon
|
||||
{
|
||||
title: 'Валюта доп.оборудования',
|
||||
Component: Select,
|
||||
props: {
|
||||
name: 'selectAddEquipmentCurrency',
|
||||
valueName: 'addEquipmentCurrency',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Стоимость доп.оборудования',
|
||||
Component: InputNumber,
|
||||
props: {
|
||||
min: '0',
|
||||
max: '1000000000',
|
||||
step: '10000.00',
|
||||
name: 'tbxAddEquipmentPrice',
|
||||
valueName: 'addEquipmentPrice',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Плательщик доп.оборудования',
|
||||
Component: Radio,
|
||||
props: {
|
||||
name: 'radioAddEquipmentPayer',
|
||||
valueName: 'addEquipmentPayer',
|
||||
withSearch: false,
|
||||
style: 'button',
|
||||
},
|
||||
},
|
||||
// TODO Input x Addon
|
||||
// {
|
||||
// title: 'Валюта доп.оборудования',
|
||||
// Component: Select,
|
||||
// props: {
|
||||
// name: 'selectAddEquipmentCurrency',
|
||||
// valueName: 'addEquipmentCurrency',
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// title: 'Стоимость доп.оборудования',
|
||||
// Component: InputNumber,
|
||||
// props: {
|
||||
// min: '0',
|
||||
// max: '1000000000',
|
||||
// step: '10000.00',
|
||||
// name: 'tbxAddEquipmentPrice',
|
||||
// valueName: 'addEquipmentPrice',
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// title: 'Плательщик доп.оборудования',
|
||||
// Component: Radio,
|
||||
// props: {
|
||||
// name: 'radioAddEquipmentPayer',
|
||||
// valueName: 'addEquipmentPayer',
|
||||
// withSearch: false,
|
||||
// style: 'button',
|
||||
// },
|
||||
// },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@ -5,23 +5,36 @@ import { useStores } from 'client/hooks/useStores';
|
||||
import CalculationService from 'client/services/CalculationService';
|
||||
import { Box, Flex } from 'client/UIKit/grid';
|
||||
import initialOptions from 'core/Data/initialOptions';
|
||||
import staticEntitiesList from 'core/Data/staticEntitiesList';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import Result from 'client/Components/Result';
|
||||
import Modal from 'client/Elements/Modal';
|
||||
import Results from './Results';
|
||||
import Sections from './Sections';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
const Calculation = () => {
|
||||
const [status, setStatus] = useState(LoadingStatus.loading);
|
||||
const { calculationStore } = useStores();
|
||||
//TODO: move to external file
|
||||
useEffect(() => {
|
||||
Promise.all([
|
||||
CalculationService.getEntities({
|
||||
queries: initialOptions,
|
||||
}),
|
||||
CalculationService.getEntities({
|
||||
queries: staticEntitiesList,
|
||||
CalculationService.crmgqlquery({
|
||||
query: gql`
|
||||
query($statecode: Int) {
|
||||
evo_impairment_group: evo_impairment_groups(statecode: $statecode) {
|
||||
evo_impairment_groupid
|
||||
evo_name
|
||||
}
|
||||
evo_currencychange: evo_currencychanges(statecode: $statecode) {
|
||||
evo_currencychange
|
||||
evo_ref_transactioncurrency
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { statecode: 0 },
|
||||
}),
|
||||
CalculationService.getEntities({
|
||||
queries: [
|
||||
@ -46,6 +59,16 @@ const Calculation = () => {
|
||||
calculationStore.setTableColumns('tableInsurance')({
|
||||
options: { ...insuranceCompanies },
|
||||
});
|
||||
|
||||
//TODO: move to external file
|
||||
var supplierCurrency = calculationStore.options.selectSupplierCurrency.find(
|
||||
x => x.isocurrencycode === 'RUB',
|
||||
);
|
||||
calculationStore.setValue(
|
||||
'supplierCurrency',
|
||||
supplierCurrency.transactioncurrencyid,
|
||||
);
|
||||
|
||||
setStatus(LoadingStatus.ready);
|
||||
},
|
||||
)
|
||||
|
||||
@ -92,10 +92,7 @@ class CalculationService {
|
||||
//@ts-ignore
|
||||
resEntities[
|
||||
//@ts-ignore
|
||||
!CRMEntityAliases.includes(targetName) &&
|
||||
isPlural(targetName)
|
||||
? singular(targetName)
|
||||
: targetName
|
||||
isPlural(targetName) ? singular(targetName) : targetName
|
||||
] = entityOption;
|
||||
}
|
||||
}
|
||||
@ -173,9 +170,7 @@ class CalculationService {
|
||||
//@ts-ignore
|
||||
resEntities[
|
||||
//@ts-ignore
|
||||
!CRMEntityAliases.includes(targetName) && isPlural(targetName)
|
||||
? singular(targetName)
|
||||
: targetName
|
||||
isPlural(targetName) ? singular(targetName) : targetName
|
||||
] = entityOption;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,10 +14,9 @@ export function calcPrice(
|
||||
export const calculatePerc = calculationStore => (
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
discountRub,
|
||||
discountPercFieldName,
|
||||
rubSum,
|
||||
percFieldName,
|
||||
) => {
|
||||
// TODO: check evo_currecychange
|
||||
const supplierCurrency = calculationStore
|
||||
.getOptions('selectSupplierCurrency')
|
||||
.find(x => x.transactioncurrencyid === supplierCurrencyId);
|
||||
@ -31,17 +30,16 @@ export const calculatePerc = calculationStore => (
|
||||
parseFloat(leaseObjectPrice),
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
let perc = (discountRub / price) * 100;
|
||||
calculationStore.setValue(discountPercFieldName, perc);
|
||||
let perc = (rubSum / price) * 100;
|
||||
calculationStore.setValue(percFieldName, perc);
|
||||
};
|
||||
|
||||
export const calculateRub = calculationStore => (
|
||||
supplierCurrencyId,
|
||||
leaseObjectPrice,
|
||||
discountPerc,
|
||||
discountRubFieldName,
|
||||
perc,
|
||||
rubFieldName,
|
||||
) => {
|
||||
// TODO: check evo_currecychange
|
||||
const supplierCurrency = calculationStore
|
||||
.getOptions('selectSupplierCurrency')
|
||||
.find(x => x.transactioncurrencyid === supplierCurrencyId);
|
||||
@ -55,6 +53,6 @@ export const calculateRub = calculationStore => (
|
||||
parseFloat(leaseObjectPrice),
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
let rub = (discountPerc * price) / 100;
|
||||
calculationStore.setValue(discountRubFieldName, rub);
|
||||
let rub = (perc * price) / 100;
|
||||
calculationStore.setValue(rubFieldName, rub);
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,7 @@ const initialOptions: TEntityQuery[] = [
|
||||
'accountid',
|
||||
'evo_leadid',
|
||||
'evo_client_riskid',
|
||||
// 'parentaccountid',
|
||||
'parentaccountid',
|
||||
],
|
||||
where: { statecode: 0 },
|
||||
many: true,
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
import { TEntityQuery } from '../types/Entities/query';
|
||||
|
||||
const staticEntitiesList: TEntityQuery[] = [
|
||||
{
|
||||
entityName: 'evo_impairment_group',
|
||||
where: {
|
||||
statecode: 0,
|
||||
},
|
||||
fields: ['evo_impairment_groupid', 'evo_name'],
|
||||
many: true,
|
||||
},
|
||||
{
|
||||
entityName: 'evo_currencychange',
|
||||
where: {
|
||||
//TODO: Date without time
|
||||
// evo_coursedate: new Date(),
|
||||
statecode: 0,
|
||||
},
|
||||
fields: ['evo_currencychange'],
|
||||
many: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default staticEntitiesList;
|
||||
@ -4,7 +4,7 @@ const initialValues: TValues<TValue> = {
|
||||
recalcWithRevision: false,
|
||||
contactGender: 100000000,
|
||||
leaseObjectPrice: 1000000,
|
||||
// supplierCurrency: 'RUB',
|
||||
supplierCurrency: 'RUB',
|
||||
supplierDiscountRub: 0,
|
||||
supplierDiscountPerc: 0,
|
||||
// addEquipmentCurrency: 'RUB',
|
||||
|
||||
@ -16,7 +16,7 @@ import { TValue, TValues, ValuesNames } from './values';
|
||||
|
||||
interface ICalculationValues {
|
||||
staticData: TStaticData;
|
||||
getStaticData: (dataName: CRMEntityNames) => IBaseOption[];
|
||||
getStaticData: (dataName: CRMEntityNames) => (IBaseOption & TCRMEntity)[];
|
||||
applyStaticData: (data: TStaticData) => void;
|
||||
|
||||
options: TElements<(IBaseOption & TCRMEntity)[]>;
|
||||
|
||||
@ -50,6 +50,7 @@ export interface IQuote {
|
||||
ownerid?: string;
|
||||
statecode?: number;
|
||||
evo_statuscodeid?: string;
|
||||
evo_statuscode?: IEvoStatusCode;
|
||||
}
|
||||
|
||||
export interface ITransactionCurrency {
|
||||
@ -191,6 +192,7 @@ export interface IEvoCurrencyChange {
|
||||
evo_currencychange?: number;
|
||||
evo_coursedate?: Date;
|
||||
statecode?: number;
|
||||
evo_coursedate_param: any;
|
||||
}
|
||||
|
||||
export interface IEvoStatusCode {
|
||||
|
||||
@ -30,16 +30,7 @@ export type CRMEntityNames =
|
||||
| 'systemuser'
|
||||
| 'evo_sot_coefficient_type';
|
||||
|
||||
export const CRMEntityAliases = [
|
||||
'agent',
|
||||
'double_agent',
|
||||
'broker',
|
||||
'findepartment',
|
||||
] as const;
|
||||
type CRMEntityAliasesType = typeof CRMEntityAliases;
|
||||
export type CRMEntityAliasesUnion = CRMEntityAliasesType[number];
|
||||
|
||||
//TODO: or string
|
||||
export type TEntities<T> = {
|
||||
[entityName in CRMEntityNames | CRMEntityAliasesUnion]?: T;
|
||||
[entityName in CRMEntityNames]?: T;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user