remove useless files
This commit is contained in:
parent
ce56656c9e
commit
360f6cde17
@ -1,187 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { Box, Modal, Fade, Backdrop, Button, TextField } from "@mui/material";
|
||||
import theme from "../../../../theme";
|
||||
import { ArrayProps } from "../../../../model/tariff";
|
||||
import { useTariffStore } from "../../../../stores/tariffs";
|
||||
|
||||
|
||||
export interface MWProps {
|
||||
open: boolean;
|
||||
type: number;
|
||||
variant: number;
|
||||
close: () => void;
|
||||
}
|
||||
|
||||
const ModalMini = ({ open, type, variant, close }: MWProps) => {
|
||||
let tariffsArray = useTariffStore(state => state.tariffs);
|
||||
const tariffsArraySet = useTariffStore(state => state.setTariffs);
|
||||
|
||||
const types = ["", "Шаблонизатор документов", "Опросник", "Сокращатель ссылок"];
|
||||
const variants = ["Количество", "Срок (дней)", "Количество (гб)"];
|
||||
|
||||
const fieldName = React.useRef<HTMLInputElement | null>(null);
|
||||
const fieldTime = React.useRef<HTMLInputElement | null>(null);
|
||||
const fieldPrice = React.useRef<HTMLInputElement | null>(null);
|
||||
|
||||
const checkTariff = () => {
|
||||
if (fieldName.current != null && fieldTime.current != null && fieldPrice.current != null) {
|
||||
if (fieldName.current.value && fieldTime.current.value && fieldPrice.current.value) {
|
||||
|
||||
const data = [0, 0, 0];
|
||||
|
||||
if (variant === 0) { data[0] = parseInt(fieldTime.current.value); }
|
||||
if (variant === 1) { data[1] = parseInt(fieldTime.current.value); }
|
||||
if (variant === 2) { data[2] = parseInt(fieldTime.current.value); }
|
||||
|
||||
const tariffsArrayNew = [...tariffsArray, {
|
||||
"id": new Date().getTime(),
|
||||
"name": fieldName.current.value,
|
||||
"type": "tariff",
|
||||
"service": types[type],
|
||||
"disk": data[2],
|
||||
"time": data[1],
|
||||
"points": data[0],
|
||||
"price": +fieldPrice.current.value
|
||||
} as ArrayProps];
|
||||
|
||||
tariffsArraySet(tariffsArrayNew);
|
||||
|
||||
close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Modal
|
||||
aria-labelledby="transition-modal-title"
|
||||
aria-describedby="transition-modal-description"
|
||||
open={open}
|
||||
onClose={() => close()}
|
||||
closeAfterTransition
|
||||
BackdropComponent={Backdrop}
|
||||
BackdropProps={{
|
||||
timeout: 500,
|
||||
}}
|
||||
>
|
||||
<Fade in={open}>
|
||||
<Box sx={{
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%, -50%)",
|
||||
width: "350px",
|
||||
height: "350px",
|
||||
bgcolor: theme.palette.menu.main,
|
||||
boxShadow: 24,
|
||||
color: theme.palette.secondary.main,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}>
|
||||
<TextField
|
||||
id="standard-basic"
|
||||
label={types[type]}
|
||||
disabled={true}
|
||||
variant="filled"
|
||||
color="secondary"
|
||||
sx={{ width: "80%", marginTop: theme.spacing(1) }}
|
||||
InputProps={{
|
||||
style: {
|
||||
backgroundColor: theme.palette.content.main,
|
||||
color: theme.palette.secondary.main,
|
||||
}
|
||||
}}
|
||||
InputLabelProps={{
|
||||
style: {
|
||||
color: theme.palette.secondary.main
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
id="standard-basic"
|
||||
label={"Название тарифа"}
|
||||
variant="filled"
|
||||
color="secondary"
|
||||
sx={{ width: "80%", marginTop: theme.spacing(1) }}
|
||||
InputProps={{
|
||||
style: {
|
||||
backgroundColor: theme.palette.content.main,
|
||||
color: theme.palette.secondary.main,
|
||||
}
|
||||
}}
|
||||
InputLabelProps={{
|
||||
style: {
|
||||
color: theme.palette.secondary.main
|
||||
}
|
||||
}}
|
||||
inputRef={fieldName}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
id="standard-basic"
|
||||
label={variants[variant]}
|
||||
variant="filled"
|
||||
color="secondary"
|
||||
sx={{ width: "80%", marginTop: theme.spacing(1) }}
|
||||
InputProps={{
|
||||
style: {
|
||||
backgroundColor: theme.palette.content.main,
|
||||
color: theme.palette.secondary.main,
|
||||
}
|
||||
}}
|
||||
InputLabelProps={{
|
||||
style: {
|
||||
color: theme.palette.secondary.main
|
||||
}
|
||||
}}
|
||||
inputRef={fieldTime}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
id="standard-basic"
|
||||
label="Цена"
|
||||
variant="filled"
|
||||
color="secondary"
|
||||
sx={{ width: "80%", marginTop: theme.spacing(1) }}
|
||||
InputProps={{
|
||||
style: {
|
||||
backgroundColor: theme.palette.content.main,
|
||||
color: theme.palette.secondary.main,
|
||||
}
|
||||
}}
|
||||
InputLabelProps={{
|
||||
style: {
|
||||
color: theme.palette.secondary.main
|
||||
}
|
||||
}}
|
||||
inputRef={fieldPrice}
|
||||
/>
|
||||
|
||||
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => checkTariff()}
|
||||
sx={{
|
||||
backgroundColor: theme.palette.grayDark.main,
|
||||
marginTop: "30px",
|
||||
height: "42px",
|
||||
fontWeight: "normal",
|
||||
fontSize: "17px",
|
||||
"&:hover": {
|
||||
backgroundColor: theme.palette.grayMedium.main
|
||||
}
|
||||
}}>
|
||||
Применить
|
||||
</Button>
|
||||
</Box>
|
||||
</Fade>
|
||||
</Modal>
|
||||
</React.Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export default ModalMini;
|
@ -1,242 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { Box, Typography, TextField } from "@mui/material";
|
||||
import { DataGrid, GridColDef, GridSelectionModel, GridToolbar } from "@mui/x-data-grid";
|
||||
import theme from "../../../../theme";
|
||||
import { useMemo, useState } from "react";
|
||||
import { convertTariffs, formatPromocodePriveleges } from "./utils";
|
||||
import CustomButton from "./CustomButton";
|
||||
import Cart from "./Cart";
|
||||
import type { ArrayProps } from "../../../../model/tariff";
|
||||
import { Promocode } from "../../../../model/cart";
|
||||
import { usePromocodeStore } from "../../../../stores/promocodes";
|
||||
import { useTariffStore } from "../../../../stores/tariffs";
|
||||
import { useCartStore } from "../../../../stores/cart";
|
||||
|
||||
|
||||
export interface MWProps {
|
||||
openModal: () => void;
|
||||
}
|
||||
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "id",
|
||||
headerName: "ID",
|
||||
width: 30,
|
||||
sortable: false,
|
||||
},
|
||||
{
|
||||
field: "name",
|
||||
headerName: "Название тарифа",
|
||||
width: 200,
|
||||
sortable: false,
|
||||
},
|
||||
{
|
||||
field: "service",
|
||||
headerName: "Сервис",
|
||||
width: 210,
|
||||
sortable: false,
|
||||
}, {
|
||||
field: "disk",
|
||||
headerName: "Гигабайты",
|
||||
type: "number",
|
||||
width: 110,
|
||||
sortable: false,
|
||||
},
|
||||
{
|
||||
field: "time",
|
||||
headerName: "Время",
|
||||
type: "number",
|
||||
width: 110,
|
||||
sortable: false,
|
||||
},
|
||||
{
|
||||
field: "points",
|
||||
headerName: "Объем",
|
||||
width: 110,
|
||||
sortable: false,
|
||||
},
|
||||
{
|
||||
field: "price",
|
||||
headerName: "Стоимость",
|
||||
width: 160,
|
||||
sortable: false,
|
||||
},
|
||||
{
|
||||
field: "conditions",
|
||||
headerName: "Условия",
|
||||
width: 110,
|
||||
sortable: false,
|
||||
},
|
||||
];
|
||||
|
||||
const DataGridElement: React.FC<MWProps> = ({ openModal }) => {
|
||||
const promocodeArray = usePromocodeStore(state => state.promocodeArray);
|
||||
const tariffsSelectedRowsData = useTariffStore(state => state.tariffsSelectedRowsData);
|
||||
const tariffsSelectedRowsDataSet = useTariffStore(state => state.setTariffsSelectedRowsData);
|
||||
const tariffsArray = useTariffStore(state => state.tariffs);
|
||||
const cartRowsDataSet = useCartStore(state => state.setCartRowsData);
|
||||
const [selectedPromocodeIndex, setSelectedPromocodeIndex] = useState(-1);
|
||||
const [promocodeField, setPromocodeField] = useState<string>("");
|
||||
|
||||
const onRowsSelectionHandler = (ids: GridSelectionModel) => {
|
||||
const result: Array<ArrayProps> = [];
|
||||
ids.forEach((id) => tariffsArray.forEach((row) => {
|
||||
if (row.id === id) result.push(row);
|
||||
}));
|
||||
|
||||
tariffsSelectedRowsDataSet(result);
|
||||
};
|
||||
|
||||
const handleToBasket = () => cartRowsDataSet(tariffsSelectedRowsData);
|
||||
|
||||
const checkPromocode = () => {
|
||||
setSelectedPromocodeIndex(promocodeArray.findIndex(promocode => promocode.name === promocodeField));
|
||||
};
|
||||
|
||||
const tariffsArrayConverted = useMemo(() => convertTariffs(tariffsArray), [tariffsArray]);
|
||||
|
||||
const promocode = promocodeArray[selectedPromocodeIndex] as Promocode | undefined;
|
||||
|
||||
return (
|
||||
<Box style={{ width: "93%" }}>
|
||||
<Box style={{ height: 400 }}>
|
||||
<DataGrid
|
||||
checkboxSelection={true}
|
||||
rows={tariffsArrayConverted}
|
||||
columns={columns}
|
||||
sx={{
|
||||
color: theme.palette.secondary.main,
|
||||
"& .MuiDataGrid-iconSeparator": {
|
||||
display: "none"
|
||||
},
|
||||
"& .css-levciy-MuiTablePagination-displayedRows": {
|
||||
color: theme.palette.secondary.main
|
||||
},
|
||||
"& .MuiSvgIcon-root": {
|
||||
color: theme.palette.secondary.main
|
||||
},
|
||||
"& .MuiTablePagination-selectLabel": {
|
||||
color: theme.palette.secondary.main
|
||||
},
|
||||
"& .MuiInputBase-root": {
|
||||
color: theme.palette.secondary.main
|
||||
},
|
||||
"& .MuiButton-text": {
|
||||
color: theme.palette.secondary.main
|
||||
},
|
||||
}}
|
||||
components={{ Toolbar: GridToolbar }}
|
||||
onSelectionModelChange={(ids) => onRowsSelectionHandler(ids)}
|
||||
/>
|
||||
|
||||
<Box sx={{
|
||||
width: "100%",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
alignItems: "center"
|
||||
}}>
|
||||
<CustomButton
|
||||
onClick={() => openModal()}
|
||||
sx={{
|
||||
padding: "6px 30px",
|
||||
marginTop: "45px",
|
||||
marginBottom: "15px",
|
||||
maxWidth: '320px',
|
||||
width: '100%',
|
||||
}}>
|
||||
Пакетизировать
|
||||
</CustomButton>
|
||||
|
||||
<CustomButton
|
||||
onClick={() => handleToBasket()}
|
||||
sx={{
|
||||
padding: "6px 69px",
|
||||
marginBottom: "95px",
|
||||
}}>
|
||||
Сложить в корзину
|
||||
</CustomButton>
|
||||
</Box>
|
||||
|
||||
<Box sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
marginBottom: "45px",
|
||||
}}>
|
||||
<Box sx={{
|
||||
maxWidth: "480px",
|
||||
width: '100%',
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
}}>
|
||||
<TextField
|
||||
id="standard-basic"
|
||||
label={"Ввести промокод"}
|
||||
variant="filled"
|
||||
size="small"
|
||||
color="secondary"
|
||||
sx={{
|
||||
width: "200px",
|
||||
height: "30px",
|
||||
}}
|
||||
InputProps={{
|
||||
style: {
|
||||
backgroundColor: theme.palette.content.main,
|
||||
color: theme.palette.secondary.main,
|
||||
}
|
||||
}}
|
||||
InputLabelProps={{
|
||||
style: {
|
||||
color: theme.palette.secondary.main
|
||||
}
|
||||
}}
|
||||
value={promocodeField}
|
||||
onChange={e => setPromocodeField(e.target.value)}
|
||||
/>
|
||||
|
||||
<CustomButton
|
||||
onClick={() => checkPromocode()}
|
||||
sx={{
|
||||
width: "200px",
|
||||
height: "48px",
|
||||
}}>
|
||||
Готово
|
||||
</CustomButton>
|
||||
</Box>
|
||||
|
||||
{selectedPromocodeIndex >= 0 &&
|
||||
<Box>
|
||||
<Box sx={{ marginTop: "35px", display: "flex" }}>
|
||||
<Typography sx={{ color: theme.palette.grayDisabled.main, minWidth: "150px" }}>
|
||||
Введен промокод:
|
||||
</Typography>
|
||||
<Typography sx={{ width: "100%", textAlign: "center" }}>
|
||||
{promocodeArray[selectedPromocodeIndex].name}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: "flex" }}>
|
||||
<Typography sx={{ color: theme.palette.grayDisabled.main, minWidth: "150px" }}>
|
||||
Привилегии:  
|
||||
</Typography>
|
||||
|
||||
<Box sx={{ width: "100%", textAlign: "center" }}>
|
||||
<Typography>
|
||||
{formatPromocodePriveleges(promocodeArray[selectedPromocodeIndex])}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
}
|
||||
</Box>
|
||||
|
||||
<Cart promocode={promocode} />
|
||||
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default DataGridElement;
|
@ -1,260 +0,0 @@
|
||||
import { CartSummary, Discount, Promocode } from "../../../../model/cart";
|
||||
import { ArrayProps, Tariff } from "../../../../model/tariff";
|
||||
|
||||
|
||||
/** @deprecated */
|
||||
export function calcFitDiscounts(discountsArray: Discount[], discountsActiveArray: number[], cartSummary: { [key: string]: CartSummary; }, fieldAddedValue: string) {
|
||||
const result = discountsActiveArray.filter(e => {
|
||||
const discount = discountsArray[e];
|
||||
const summary = cartSummary[discount.privileges[0].good];
|
||||
return (discount.incomeMore * 100 < parseInt(fieldAddedValue) && discount.incomeMore > 0) ||
|
||||
(discount.toTime < (summary ? summary.days : 0) && discount.toTime > 0 && discount.toCapacity === 0) ||
|
||||
(discount.toCapacity > 0 && discount.toCapacity < (summary ? summary.points : 0) && discount.toTime === 0) ||
|
||||
(discount.toCapacity > 0 && discount.toTime > 0 && discount.toCapacity < (summary ? summary.points : 0) && discount.toTime < (summary ? summary.days : 0)) ||
|
||||
(!discount.toCapacity && !discount.toTime && !discount.incomeMore && !discount.basketMore) ||
|
||||
discount.basketMore;
|
||||
}).filter((e, i, a) => {
|
||||
const discount: Discount = discountsArray[e];
|
||||
if (discount.incomeMore) {
|
||||
return discount.incomeMore === a.reduce((a, e) => Math.max(a, discountsArray[e].incomeMore || 0), 0);
|
||||
}
|
||||
if (discount.toTime && discount.toCapacity) {
|
||||
return discount.toTime === a.reduce((a, e) => Math.max(a, (discountsArray[e].toTime && discountsArray[e].toCapacity) ? discountsArray[e].toTime : 0), 0) && discount.toCapacity === a.reduce((a, e) => Math.max(a, (discountsArray[e].toCapacity && discountsArray[e].toTime) ? discountsArray[e].toCapacity : 0), 0);
|
||||
}
|
||||
if (discount.toTime && !discount.toCapacity) {
|
||||
return discount.toTime === a.reduce((a, e) => Math.max(a, discountsArray[e].toTime && !discountsArray[e].toCapacity ? discountsArray[e].toTime : 0), 0);
|
||||
}
|
||||
if (!discount.toTime && discount.toCapacity) {
|
||||
return discount.toCapacity === a.reduce((a, e) => Math.max(a, discountsArray[e].toCapacity && !discountsArray[e].toTime ? discountsArray[e].toCapacity : 0), 0);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export function separator(amount: number) {
|
||||
if (String(amount).length < 4) { return amount; }
|
||||
|
||||
let result: Array<string> = [];
|
||||
const arrs = String(amount).split('.');
|
||||
const arr = arrs[0].split('').reverse();
|
||||
|
||||
arr.forEach((item, i: number) => {
|
||||
result.push(String(arr[i]));
|
||||
if (((i + 1) / 3) - Math.round((i + 1) / 3) === 0) result.push(" ");
|
||||
});
|
||||
|
||||
if (arrs.length > 1) { return result.reverse().join("") + "." + arrs[1]; }
|
||||
else { return result.reverse().join(""); }
|
||||
};
|
||||
|
||||
export function formatPromocodePriveleges(promocode: Promocode) {
|
||||
return promocode.privileges.map(privelege => `${privelege.good} - ${Math.round(privelege.discount * 100)}%`).join(", ");
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export function calcTotalAndRowData(
|
||||
cartRowsData: ArrayProps[],
|
||||
isNonCommercial: boolean,
|
||||
discountsArray: Discount[],
|
||||
discountsActiveArray: number[],
|
||||
fitDiscounts: number[],
|
||||
addedValueField: string,
|
||||
cartSummary: { [key: string]: CartSummary; },
|
||||
promocode?: Promocode,
|
||||
) {
|
||||
let totalPrice = 0;
|
||||
|
||||
const calculatedCartRowData = cartRowsData.map(cartRow => {
|
||||
let price = cartRow.price;
|
||||
const appliedDiscounts: number[] = [];
|
||||
if (!isNonCommercial) {
|
||||
let percents = 0;
|
||||
if (cartRow.type === "package") {
|
||||
// считаем цену в ПАКЕТАХ
|
||||
price = 0;
|
||||
|
||||
cartRow.tariffs?.forEach((tariff) => {
|
||||
let tariffPrice = tariff.price;
|
||||
percents = 0;
|
||||
|
||||
// применяем скидки по промокоду
|
||||
if (promocode) {
|
||||
promocode.privileges.forEach(privilege => {
|
||||
if (tariff.service === privilege.good) {
|
||||
percents = percents + privilege.discount;
|
||||
}
|
||||
});
|
||||
} else {// применяем активные скидки
|
||||
percents = applyActiveDiscounts(
|
||||
percents,
|
||||
tariff,
|
||||
discountsArray,
|
||||
discountsActiveArray,
|
||||
addedValueField,
|
||||
);
|
||||
}
|
||||
|
||||
// применяем активные скидки по времени объему
|
||||
if (!promocode) {
|
||||
discountsActiveArray.forEach(activeDiscount => {
|
||||
discountsArray.forEach((discount, i) => {
|
||||
if (i === activeDiscount) {
|
||||
if (tariff.time) {
|
||||
const dTime = 0.1;
|
||||
percents = percents + dTime;
|
||||
}
|
||||
|
||||
if (tariff.points) {
|
||||
//const cTime = discountCapacity( tariff.points );
|
||||
//percents = percents + cTime;
|
||||
|
||||
//if( discounts ) discounts += " × ";
|
||||
//if( cTime != 0 ) discounts += `${ Math.round(cTime * 100) }%`;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// применяем активные скидки на продукт
|
||||
if (!promocode) {
|
||||
discountsActiveArray.forEach(activeDiscount => {
|
||||
discountsArray.forEach((discount, i) => {
|
||||
if (i === activeDiscount) {
|
||||
if (tariff.time && tariff.points) {
|
||||
// const dProduct = discountProduct( tariff.time, tariff.points );
|
||||
//percents = percents + dProduct;
|
||||
|
||||
//if( discounts ) discounts += " × ";
|
||||
//if( dProduct != 0 ) discounts += `${ Math.round(dProduct * 100) }%`;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
tariffPrice = tariffPrice - (tariffPrice * percents);
|
||||
|
||||
price += tariffPrice;
|
||||
});
|
||||
} else {
|
||||
// считаем цену в ТАРИФАХ
|
||||
price = cartRow.price;
|
||||
percents = 0;
|
||||
|
||||
// применяем скидки по промокоду
|
||||
if (promocode) {
|
||||
promocode.privileges.forEach(privilege => {
|
||||
if (cartRow.service === privilege.good) {
|
||||
appliedDiscounts.push(privilege.discount);
|
||||
price *= (1 - privilege.discount);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// применяем активные скидки
|
||||
fitDiscounts.forEach(activeDiscount => {
|
||||
const discount = discountsArray[activeDiscount];
|
||||
discount.privileges.forEach((p) => {
|
||||
const svcName = cartRow.service;
|
||||
if (p.good === svcName) {
|
||||
const summary = cartSummary[svcName] || { mbs: 0, points: 0, days: 0 };
|
||||
if (
|
||||
(discount.toCapacity === 0 && discount.toTime === 0 && discount.basketMore === 0 && !(discount.incomeMore)) ||
|
||||
(discount.toCapacity > 0 && summary.points > discount.toCapacity && cartRow.points > 0 && discount.toTime === 0) ||
|
||||
(discount.toTime > 0 && summary.days > discount.toTime * 100 && cartRow.time > 0 && discount.toCapacity === 0) ||
|
||||
(discount.toTime > 0 && discount.toCapacity > 0 && summary.days > discount.toTime * 100 && summary.points > discount.toCapacity)
|
||||
) {
|
||||
price *= (1 - p.discount);
|
||||
appliedDiscounts.push(p.discount);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
percents = Number(percents.toFixed(2));
|
||||
|
||||
price = price - (price * percents);
|
||||
}
|
||||
}
|
||||
totalPrice += price;
|
||||
|
||||
return {
|
||||
...cartRow,
|
||||
price,
|
||||
appliedDiscounts,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
totalPrice,
|
||||
calculatedCartRowData
|
||||
};
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
function applyActiveDiscounts(
|
||||
percents: number,
|
||||
tariff: Tariff,
|
||||
discountsArray: Discount[],
|
||||
discountsActiveArray: number[],
|
||||
addedValueField: string,
|
||||
) {
|
||||
discountsActiveArray.forEach(activeDiscountIndex => {
|
||||
discountsArray[activeDiscountIndex].privileges.forEach((privilege) => {
|
||||
if (privilege.discount !== 0) {
|
||||
if (addedValueField) { // внесено
|
||||
const addedValue = Number(addedValueField);
|
||||
let minDiscount = 100;
|
||||
let minI = -1;
|
||||
discountsArray.forEach((discount, index) => {
|
||||
discount.privileges.forEach((y) => {
|
||||
if (
|
||||
discount.active &&
|
||||
addedValue - y.discount * 100 < minDiscount &&
|
||||
addedValue - y.discount * 100 > 0
|
||||
) {
|
||||
minDiscount = addedValue - y.discount * 100;
|
||||
minI = index;
|
||||
}
|
||||
});
|
||||
});
|
||||
if (minI >= 0) {
|
||||
discountsArray[minI].privileges.forEach((y) => {
|
||||
percents = percents + y.discount / discountsActiveArray.length; // костыль
|
||||
});
|
||||
}
|
||||
} else { // не внесено
|
||||
if (tariff.service === privilege.good) {
|
||||
percents = percents + privilege.discount;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return percents;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export function convertTariffs(tariffsArray: ArrayProps[]) {
|
||||
return tariffsArray.map((item) => {
|
||||
if (item.type === "package" && item.tariffs) {
|
||||
const result = item.tariffs.reduce((acc, tariff) => {
|
||||
acc.service = acc.service ? `${acc.service}, ${tariff.service}` : tariff.service;
|
||||
acc.disk = acc.disk + tariff.disk;
|
||||
acc.time = acc.time + tariff.time;
|
||||
acc.points = acc.points + tariff.points;
|
||||
acc.price = acc.price + tariff.price;
|
||||
|
||||
return acc;
|
||||
}, { service: "", disk: "", time: "", points: "", price: 0 });
|
||||
|
||||
return { id: item.id, name: item.name, type: item.type, ...result };
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user