скидка - объем и время
This commit is contained in:
parent
29711e5a19
commit
ddbff8cb37
@ -66,6 +66,20 @@ const columns: GridColDef[] = [
|
|||||||
width: 140,
|
width: 140,
|
||||||
sortable: false,
|
sortable: false,
|
||||||
}
|
}
|
||||||
|
,
|
||||||
|
{
|
||||||
|
field: "toTime",
|
||||||
|
headerName: "На время",
|
||||||
|
width: 140,
|
||||||
|
sortable: false,
|
||||||
|
}
|
||||||
|
,
|
||||||
|
{
|
||||||
|
field: "toCapacity",
|
||||||
|
headerName: "На объем",
|
||||||
|
width: 140,
|
||||||
|
sortable: false,
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const rows:Array<DiscountProps> = [
|
const rows:Array<DiscountProps> = [
|
||||||
@ -78,7 +92,7 @@ const rows:Array<DiscountProps> = [
|
|||||||
good: "Товар 2",
|
good: "Товар 2",
|
||||||
discount: 0.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: [
|
{ id: 2, name: "Скидка 2", endless: false, from: "", dueTo: "", privileges: [
|
||||||
{
|
{
|
||||||
good: "Товар 3",
|
good: "Товар 3",
|
||||||
@ -88,7 +102,7 @@ const rows:Array<DiscountProps> = [
|
|||||||
good: "Товар 4",
|
good: "Товар 4",
|
||||||
discount: 0.2
|
discount: 0.2
|
||||||
}
|
}
|
||||||
], active: true, basketMore: 10 },
|
], active: true, basketMore: 10, toTime: 20, toCapacity: 30 },
|
||||||
{ id: 3, name: "Скидка 3", endless: false, from: "", dueTo: "", privileges: [
|
{ id: 3, name: "Скидка 3", endless: false, from: "", dueTo: "", privileges: [
|
||||||
{
|
{
|
||||||
good: "Товар 5",
|
good: "Товар 5",
|
||||||
@ -98,7 +112,7 @@ const rows:Array<DiscountProps> = [
|
|||||||
good: "Товар 6",
|
good: "Товар 6",
|
||||||
discount: 0.2
|
discount: 0.2
|
||||||
}
|
}
|
||||||
], active: false, basketMore: 10 },
|
], active: false, basketMore: 10, toTime: 20, toCapacity: 30 },
|
||||||
];
|
];
|
||||||
|
|
||||||
const Discounts: React.FC = () => {
|
const Discounts: React.FC = () => {
|
||||||
@ -137,7 +151,9 @@ const Discounts: React.FC = () => {
|
|||||||
findActiveDiscounts();
|
findActiveDiscounts();
|
||||||
|
|
||||||
const discountsArrayConverted = discountsArray.map( (item) => {
|
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 dateFrom = item.from ? new Date( Number(item.from) ) : "";
|
||||||
const dateDueTo = item.from ? new Date( Number(item.dueTo) ) : "";
|
const dateDueTo = item.from ? new Date( Number(item.dueTo) ) : "";
|
||||||
@ -159,13 +175,20 @@ const Discounts: React.FC = () => {
|
|||||||
return acc;
|
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 {
|
} 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 = {
|
const newDiscount = {
|
||||||
id: new Date().getTime(),
|
id: new Date().getTime(),
|
||||||
name,
|
name,
|
||||||
@ -177,7 +200,9 @@ const Discounts: React.FC = () => {
|
|||||||
discount: discount / 100
|
discount: discount / 100
|
||||||
}],
|
}],
|
||||||
active: false,
|
active: false,
|
||||||
basketMore: basketMore / 100
|
basketMore: basketMore / 100,
|
||||||
|
toTime: toTime / 100,
|
||||||
|
toCapacity: toCapacity / 100
|
||||||
}
|
}
|
||||||
|
|
||||||
const discountsArrayUpdated = [ ...discountsArray, newDiscount ];
|
const discountsArrayUpdated = [ ...discountsArray, newDiscount ];
|
||||||
@ -188,6 +213,8 @@ const Discounts: React.FC = () => {
|
|||||||
const fieldDiscount = React.useRef<HTMLInputElement | null>(null);
|
const fieldDiscount = React.useRef<HTMLInputElement | null>(null);
|
||||||
const fieldAddedMore = React.useRef<HTMLInputElement | null>(null);
|
const fieldAddedMore = React.useRef<HTMLInputElement | null>(null);
|
||||||
const basketMore = React.useRef<HTMLInputElement | null>(null);
|
const basketMore = React.useRef<HTMLInputElement | null>(null);
|
||||||
|
const toTime = React.useRef<HTMLInputElement | null>(null);
|
||||||
|
const toCapacity = React.useRef<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
const cleraAddedMore = () => {
|
const cleraAddedMore = () => {
|
||||||
if (fieldAddedMore.current) {
|
if (fieldAddedMore.current) {
|
||||||
@ -199,12 +226,16 @@ const Discounts: React.FC = () => {
|
|||||||
if( fieldName.current != null
|
if( fieldName.current != null
|
||||||
&& fieldDiscount.current != null
|
&& fieldDiscount.current != null
|
||||||
&& fieldAddedMore.current != null
|
&& fieldAddedMore.current != null
|
||||||
&& basketMore.current != null ) {
|
&& basketMore.current != null
|
||||||
|
&& toTime.current != null
|
||||||
|
&& toCapacity.current != null ) {
|
||||||
|
|
||||||
createDiscount( fieldName.current.value,
|
createDiscount( fieldName.current.value,
|
||||||
Number(fieldDiscount.current.value),
|
Number(fieldDiscount.current.value),
|
||||||
Number(fieldAddedMore.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() }
|
onChange={ () => cleraAddedMore() }
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
id = "standard-basic"
|
||||||
|
label = { "На время" }
|
||||||
|
variant = "filled"
|
||||||
|
color = "secondary"
|
||||||
|
type = "number"
|
||||||
|
sx={{
|
||||||
|
marginTop: "15px"
|
||||||
|
}}
|
||||||
|
InputProps={{
|
||||||
|
style: {
|
||||||
|
backgroundColor: theme.palette.content.main,
|
||||||
|
color: theme.palette.secondary.main,
|
||||||
|
} }}
|
||||||
|
InputLabelProps={{
|
||||||
|
style: {
|
||||||
|
color: theme.palette.secondary.main
|
||||||
|
} }}
|
||||||
|
inputRef={ toTime }
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
id = "standard-basic"
|
||||||
|
label = { "На объем" }
|
||||||
|
variant = "filled"
|
||||||
|
color = "secondary"
|
||||||
|
type = "number"
|
||||||
|
sx={{
|
||||||
|
marginTop: "15px"
|
||||||
|
}}
|
||||||
|
InputProps={{
|
||||||
|
style: {
|
||||||
|
backgroundColor: theme.palette.content.main,
|
||||||
|
color: theme.palette.secondary.main,
|
||||||
|
} }}
|
||||||
|
InputLabelProps={{
|
||||||
|
style: {
|
||||||
|
color: theme.palette.secondary.main
|
||||||
|
} }}
|
||||||
|
inputRef={ toCapacity }
|
||||||
|
/>
|
||||||
|
|
||||||
<TableContainer component={Paper} sx={{
|
<TableContainer component={Paper} sx={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
marginTop: "35px",
|
marginTop: "35px",
|
||||||
|
@ -12,4 +12,6 @@ export interface DiscountProps {
|
|||||||
privileges: Array<PrivilegesProps>
|
privileges: Array<PrivilegesProps>
|
||||||
active: boolean
|
active: boolean
|
||||||
basketMore: number
|
basketMore: number
|
||||||
|
toTime: number
|
||||||
|
toCapacity: number
|
||||||
}
|
}
|
@ -202,6 +202,21 @@ const DataGridElement: React.FC<MWProps> = ({ 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 (
|
return (
|
||||||
<Box style={{ width: "100%" }}>
|
<Box style={{ width: "100%" }}>
|
||||||
<Box style={{ height: 400 }}>
|
<Box style={{ height: 400 }}>
|
||||||
@ -515,6 +530,22 @@ const DataGridElement: React.FC<MWProps> = ({ 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);
|
tariffPrice = tariffPrice - (tariffPrice * percents);
|
||||||
price += tariffPrice;
|
price += tariffPrice;
|
||||||
} );
|
} );
|
||||||
@ -580,6 +611,16 @@ const DataGridElement: React.FC<MWProps> = ({ 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);
|
price = price - (price * percents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user