fix prepare data

This commit is contained in:
Владислав Чикалкин 2020-11-12 18:31:49 +03:00
parent 5a2c629e1b
commit 82eb2e8cc6
5 changed files with 31 additions and 20 deletions

View File

@ -128,7 +128,6 @@ class CalculationService {
});
const convertedQuery = convertJSONToGQLQuery(queries);
console.log('CalculationService -> convertedQuery', convertedQuery);
await client
.query({
query: gql`

View File

@ -9,21 +9,23 @@ import { DateTime } from 'luxon';
export const prepareCalculationData = ({
calculationStore,
username,
}: IGetCalculationRequest): any => {
const currentDate = DateTime.local().toUTC().toJSDate();
let preparedPayments: PreparedPayments = [];
const { values, options, tables } = calculationStore;
const tracker = options.selectTracker?.find(x => x.evo_id === values.tracker);
const telematic = options.selectTelematic?.find(
x => x.evo_id === values.telematics,
//@ts-ignore
let preparedPayments: PreparedPayments = Array.from(
{ length: values.leasingPeriod },
() => ({}),
);
for (let i = 0; i <= values.leasingPeriod; i++) {
const tracker = options.selectTracker?.find(x => x.evo_id === values.tracker);
const telematic = options.selectTelematic?.find(
x => x.evo_id === values.telematic,
);
for (let i = 0; i < values.leasingPeriod; i++) {
preparedPayments[i].numberPayment = i + 1;
preparedPayments[i].percentPayment =
i === 0 ? 0 : tables.tablePayments.rows[i].paymentRelation?.value;
@ -286,7 +288,8 @@ export const prepareCalculationData = ({
if (
evo_coefficient_bonuses &&
evo_coefficient_bonuses.length > 0 &&
systemuser
systemuser &&
!Array.isArray(systemuser)
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
@ -294,7 +297,7 @@ export const prepareCalculationData = ({
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
x.evo_job_titleid === systemuser[0].evo_job_titleid &&
x.evo_job_titleid === systemuser.evo_job_titleid &&
x.evo_sot_coefficient_typeid ===
evo_sot_coefficient_type?.evo_sot_coefficient_typeid,
);
@ -458,7 +461,8 @@ export const prepareCalculationData = ({
if (
evo_coefficient_bonuses &&
evo_coefficient_bonuses.length > 0 &&
systemuser
systemuser &&
!Array.isArray(systemuser)
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
@ -466,7 +470,7 @@ export const prepareCalculationData = ({
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
x.evo_job_titleid === systemuser[0].evo_job_titleid &&
x.evo_job_titleid === systemuser.evo_job_titleid &&
x.evo_sot_coefficient_typeid ===
evo_sot_coefficient_type?.evo_sot_coefficient_typeid,
);
@ -480,7 +484,8 @@ export const prepareCalculationData = ({
if (
evo_coefficient_bonuses &&
evo_coefficient_bonuses.length > 0 &&
systemuser
systemuser &&
!Array.isArray(systemuser)
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
@ -488,7 +493,7 @@ export const prepareCalculationData = ({
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
x.evo_job_titleid === systemuser[0].evo_job_titleid &&
x.evo_job_titleid === systemuser.evo_job_titleid &&
x.evo_sot_coefficient_typeid ===
evo_sot_coefficient_type?.evo_sot_coefficient_typeid,
);
@ -503,7 +508,8 @@ export const prepareCalculationData = ({
if (
evo_coefficient_bonuses &&
evo_coefficient_bonuses.length > 0 &&
systemuser
systemuser &&
!Array.isArray(systemuser)
) {
const evo_sot_coefficient_type = calculationStore
.getStaticData('evo_sot_coefficient_type')
@ -511,7 +517,7 @@ export const prepareCalculationData = ({
const evo_coefficient = evo_coefficient_bonuses.find(
x =>
x.evo_job_titleid === systemuser[0].evo_job_titleid &&
x.evo_job_titleid === systemuser.evo_job_titleid &&
x.evo_sot_coefficient_typeid ===
evo_sot_coefficient_type?.evo_sot_coefficient_typeid,
);

View File

@ -1,6 +1,7 @@
import { openNotification } from 'client/Elements/Notification';
import CalculationStore from 'client/stores/CalculationStore';
import { TAction } from 'core/types/Calculation/Store/effect';
import { prepareCalculationData } from 'client/services/prepareData';
const actions: TAction = {
createLead: () => {
@ -205,6 +206,11 @@ const actions: TAction = {
validation: true,
},
});
var preparedData = prepareCalculationData({
calculationStore: CalculationStore,
});
console.log('preparedData', preparedData);
},
};

View File

@ -14,5 +14,4 @@ export interface IRequestToCRMGQL {
export interface IGetCalculationRequest {
calculationStore: ICalculationStore;
username: string;
}

View File

@ -1,8 +1,9 @@
import { CRMEntityNames } from '../../Entities/crmEntityNames';
import { TCRMEntity } from './../../Entities/crmEntities';
import { IBaseOption } from './options';
import { TValue } from './values';
export type TStaticData = {
[dataName in CRMEntityNames]?: (IBaseOption & TCRMEntity)[] | TValue;
[dataName in CRMEntityNames]?:
| (IBaseOption & TCRMEntity)
| (IBaseOption & TCRMEntity)[];
};