From 8d7c1b5ca795c9ab1ec94e5ce60d2e93701dea9f Mon Sep 17 00:00:00 2001 From: Nikolai Date: Thu, 10 Nov 2022 17:37:51 +0600 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BA=D0=B8=D0=B4=D0=BA=D0=B8=20-=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B4=D1=83=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Content/Tariffs/DataGridElement/index.tsx | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Components/LoggedIn/Content/Tariffs/DataGridElement/index.tsx b/src/Components/LoggedIn/Content/Tariffs/DataGridElement/index.tsx index 712fd39..60e23e8 100644 --- a/src/Components/LoggedIn/Content/Tariffs/DataGridElement/index.tsx +++ b/src/Components/LoggedIn/Content/Tariffs/DataGridElement/index.tsx @@ -216,6 +216,13 @@ const DataGridElement: React.FC = ({ openModal }) => { return 0; } + const discountProduct = ( days:string, generations:string ) => { + if( parseInt(days) > 30 && parseInt(generations) > 100 ) { return 0.02; } + if( parseInt(days) > 60 && parseInt(generations) > 300 ) { return 0.03; } + if( parseInt(days) > 90 && parseInt(generations) > 600 ) { return 0.04; } + return 0; + } + return ( @@ -537,7 +544,22 @@ const DataGridElement: React.FC = ({ openModal }) => { if( item.tariffs ) { item.tariffs.forEach( (t) => { if( t.time ) { percents = percents + discountTime( t.time ); } - if( t.time ) { percents = percents + discountCapacity( t.time ); } + if( t.points ) { percents = percents + discountCapacity( t.time ); } + }); + } + }); + }); + } + + // применяем активные скидки на продукт + if( discountsActiveArray.length >= 0 && checkboxStates == 1 && selectedPromocode < 0 ) { + discountsActiveArray.forEach( (activeDiscount) => { + discountsArray.forEach( (discount, i) => { + if( item.tariffs ) { + item.tariffs.forEach( (t) => { + if( t.time && t.points ) { + percents = percents + discountProduct( t.time, t.points ); + } }); } }); @@ -616,11 +638,24 @@ const DataGridElement: React.FC = ({ openModal }) => { discountsActiveArray.forEach( (activeDiscount) => { discountsArray.forEach( (discount, i) => { if( item.time ) { percents = percents + discountTime( item.time ); } - if( item.time ) { percents = percents + discountCapacity( item.time ); } + if( item.points ) { percents = percents + discountCapacity( item.time ); } }); }); } + // применяем активные скидки на продукт + if( discountsActiveArray.length >= 0 && checkboxStates == 1 && selectedPromocode < 0 ) { + discountsActiveArray.forEach( (activeDiscount) => { + discountsArray.forEach( (discount, i) => { + if( item.time && item.points ) { + percents = percents + discountProduct( item.time, item.points ); + } + }); + }); + } + + percents = Number( percents.toFixed(2) ); + price = price - (price * percents); }