From 5432536b2ea1d491d737c8cdb2b262909403fce0 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 21 Apr 2023 10:19:33 +0300 Subject: [PATCH] fix prepared-values --- .../server/routers/calculate/lib/request.ts | 58 +++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/apps/web/server/routers/calculate/lib/request.ts b/apps/web/server/routers/calculate/lib/request.ts index 1601561..222ae74 100644 --- a/apps/web/server/routers/calculate/lib/request.ts +++ b/apps/web/server/routers/calculate/lib/request.ts @@ -33,16 +33,44 @@ export async function createRequestData({ const { RUB } = createCurrencyUtility({ apolloClient }); + let tracker: CRMTypes.GetAddProductTypeQuery['evo_addproduct_type'] = null; + + if (input.values.tracker) { + const { data } = await apolloClient.query({ + query: CRMTypes.GetAddProductTypeDocument, + variables: { addproductTypeId: input.values.tracker }, + }); + tracker = data.evo_addproduct_type; + } + + let telematic: CRMTypes.GetAddProductTypeQuery['evo_addproduct_type'] = null; + if (input.values.telematic) { + const { data } = await apolloClient.query({ + query: CRMTypes.GetAddProductTypeDocument, + variables: { addproductTypeId: input.values.telematic }, + }); + telematic = data.evo_addproduct_type; + } + const preparedPayments: CoreTypes.PreparedPayments = { - rows: payments.values.map((value, index) => ({ - gpsBasePayment: 0, - gpsCostPayment: 0, - numberPayment: index + 1, - percentPayment: index === 0 ? 0 : value, - sumPayment: (payments.sums[index] ?? 0) / (1 + VAT), - tlmBasePayment: 0, - tlmCostPayment: 0, - })), + rows: payments.values.map((value, index) => { + const tracker_evo_planpayments = tracker?.evo_planpayments?.[index]; + const telematic_evo_planpayments = telematic?.evo_planpayments?.[index]; + + return { + gpsBasePayment: + (tracker_evo_planpayments?.evo_cost_price_telematics_withoutnds || 0) + + (tracker_evo_planpayments?.evo_cost_equipment_withoutnds || 0), + gpsCostPayment: tracker_evo_planpayments?.evo_cost_telematics_withoutnds || 0, + numberPayment: index + 1, + percentPayment: index === 0 ? 0 : value, + sumPayment: (payments.sums[index] ?? 0) / (1 + VAT), + tlmBasePayment: + (telematic_evo_planpayments?.evo_cost_price_telematics_withoutnds || 0) + + (telematic_evo_planpayments?.evo_cost_equipment_withoutnds || 0), + tlmCostPayment: telematic_evo_planpayments?.evo_cost_telematics_withoutnds || 0, + }; + }), }; const currentDate = dayjs().utc(false); @@ -389,7 +417,9 @@ export async function createRequestData({ (x) => x?.evo_sot_coefficient_typeidData?.evo_id === 'DIRECTOR_BONUS_NSIB' ); - return evo_coefficient?.evo_sot_coefficient || 0; + const nsibBrutto = await this.nsibBrutto(); + + return (evo_coefficient?.evo_sot_coefficient || 0) * nsibBrutto; }, async directorExtraBonus() { @@ -832,13 +862,7 @@ export async function createRequestData({ }, async nsBonus() { - const evo_coefficient = evo_coefficients?.find( - (x) => - x?.evo_job_titleid === systemuser?.evo_job_titleid && - x?.evo_sot_coefficient_typeidData?.evo_id === 'BONUS_NS_PR' - ); - - return evo_coefficient?.evo_sot_coefficient || 0; + return 0; }, async nsibBase() {