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); }