diff --git a/src/Components/LoggedIn/Content/Discounts/index.tsx b/src/Components/LoggedIn/Content/Discounts/index.tsx index da8ff5b..c2bb56d 100644 --- a/src/Components/LoggedIn/Content/Discounts/index.tsx +++ b/src/Components/LoggedIn/Content/Discounts/index.tsx @@ -66,6 +66,20 @@ const columns: GridColDef[] = [ width: 140, sortable: false, } + , + { + field: "toTime", + headerName: "На время", + width: 140, + sortable: false, + } + , + { + field: "toCapacity", + headerName: "На объем", + width: 140, + sortable: false, + } ]; const rows:Array = [ @@ -78,7 +92,7 @@ const rows:Array = [ good: "Товар 2", discount: 0.2 } - ], active: false, basketMore: 10 }, + ], active: false, basketMore: 10, toTime: 20, toCapacity: 30 }, { id: 2, name: "Скидка 2", endless: false, from: "", dueTo: "", privileges: [ { good: "Товар 3", @@ -88,7 +102,7 @@ const rows:Array = [ good: "Товар 4", discount: 0.2 } - ], active: true, basketMore: 10 }, + ], active: true, basketMore: 10, toTime: 20, toCapacity: 30 }, { id: 3, name: "Скидка 3", endless: false, from: "", dueTo: "", privileges: [ { good: "Товар 5", @@ -98,7 +112,7 @@ const rows:Array = [ good: "Товар 6", discount: 0.2 } - ], active: false, basketMore: 10 }, + ], active: false, basketMore: 10, toTime: 20, toCapacity: 30 }, ]; const Discounts: React.FC = () => { @@ -137,7 +151,9 @@ const Discounts: React.FC = () => { findActiveDiscounts(); const discountsArrayConverted = discountsArray.map( (item) => { - const basketMorePerc = item.basketMore * 100 + "%"; + const basketMorePerc = Number(item.basketMore) * 100 + "%"; + const toTimePerc = Number(item.toTime) * 100 + "%"; + const toCapacityPerc = Number(item.toCapacity) * 100 + "%"; const dateFrom = item.from ? new Date( Number(item.from) ) : ""; const dateDueTo = item.from ? new Date( Number(item.dueTo) ) : ""; @@ -159,13 +175,20 @@ const Discounts: React.FC = () => { return acc; }, "" ); - return { ...item, privileges: result, from: strFrom, dueTo: strDueTo, basketMore: basketMorePerc } + return { ...item, privileges: result, from: strFrom, dueTo: strDueTo, + basketMore: basketMorePerc, toTime: toTimePerc, toCapacity: toCapacityPerc } } else { - return { ...item, from: strFrom, dueTo: strDueTo, basketMore: basketMorePerc } + return { ...item, from: strFrom, dueTo: strDueTo, + basketMore: basketMorePerc, toTime: toTimePerc, toCapacity: toCapacityPerc } } } ); - const createDiscount = ( name:string, discount: number, addedMore: number, basketMore: number ) => { + const createDiscount = ( name:string, + discount: number, + addedMore: number, + basketMore: number, + toTime: number, + toCapacity: number, ) => { const newDiscount = { id: new Date().getTime(), name, @@ -177,7 +200,9 @@ const Discounts: React.FC = () => { discount: discount / 100 }], active: false, - basketMore: basketMore / 100 + basketMore: basketMore / 100, + toTime: toTime / 100, + toCapacity: toCapacity / 100 } const discountsArrayUpdated = [ ...discountsArray, newDiscount ]; @@ -188,6 +213,8 @@ const Discounts: React.FC = () => { const fieldDiscount = React.useRef(null); const fieldAddedMore = React.useRef(null); const basketMore = React.useRef(null); + const toTime = React.useRef(null); + const toCapacity = React.useRef(null); const cleraAddedMore = () => { if (fieldAddedMore.current) { @@ -199,12 +226,16 @@ const Discounts: React.FC = () => { if( fieldName.current != null && fieldDiscount.current != null && fieldAddedMore.current != null - && basketMore.current != null ) { + && basketMore.current != null + && toTime.current != null + && toCapacity.current != null ) { createDiscount( fieldName.current.value, Number(fieldDiscount.current.value), Number(fieldAddedMore.current.value), - Number(basketMore.current.value) ); + Number(basketMore.current.value), + Number(toTime.current.value), + Number(toCapacity.current.value) ); } } @@ -392,6 +423,48 @@ const Discounts: React.FC = () => { onChange={ () => cleraAddedMore() } /> + + + + active: boolean basketMore: number + toTime: number + toCapacity: number } \ No newline at end of file diff --git a/src/Components/LoggedIn/Content/Tariffs/DataGridElement/index.tsx b/src/Components/LoggedIn/Content/Tariffs/DataGridElement/index.tsx index d6854e5..712fd39 100644 --- a/src/Components/LoggedIn/Content/Tariffs/DataGridElement/index.tsx +++ b/src/Components/LoggedIn/Content/Tariffs/DataGridElement/index.tsx @@ -202,6 +202,21 @@ const DataGridElement: React.FC = ({ openModal }) => { } }; + const discountTime = ( days:string ) => { + if( parseInt(days) > 30 ) { return 0.01; } + if( parseInt(days) > 60 ) { return 0.03; } + if( parseInt(days) > 90 ) { return 0.05; } + return 0; + } + + const discountCapacity = ( generations:string ) => { + if( parseInt(generations) > 100 ) { return 0.01; } + if( parseInt(generations) > 300 ) { return 0.03; } + if( parseInt(generations) > 600 ) { return 0.06; } + return 0; + } + + return ( @@ -515,6 +530,22 @@ const DataGridElement: React.FC = ({ openModal }) => { }); } + // применяем активные скидки по времени / объему + 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 ) { percents = percents + discountTime( t.time ); } + if( t.time ) { percents = percents + discountCapacity( t.time ); } + }); + } + }); + }); + } + + percents = Number( percents.toFixed(2) ); + tariffPrice = tariffPrice - (tariffPrice * percents); price += tariffPrice; } ); @@ -578,6 +609,16 @@ const DataGridElement: React.FC = ({ openModal }) => { } }); }); + } + + // применяем активные скидки по времени / объему + if( discountsActiveArray.length >= 0 && checkboxStates == 1 && selectedPromocode < 0 ) { + discountsActiveArray.forEach( (activeDiscount) => { + discountsArray.forEach( (discount, i) => { + if( item.time ) { percents = percents + discountTime( item.time ); } + if( item.time ) { percents = percents + discountCapacity( item.time ); } + }); + }); } price = price - (price * percents);