import React, { useState, useEffect } from "react";
import { useParams } from "react-router-dom";
import Box from "@mui/material/Box";
import Collapse from "@mui/material/Collapse";
import IconButton from "@mui/material/IconButton";
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell, { tableCellClasses } from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Typography from "@mui/material/Typography";
import Paper from "@mui/material/Paper";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
import { styled } from "@mui/material/styles";
import { getListProvidersByIdSupply } from "../services/orders";
import { grey } from "@mui/material/colors";
const StyledTableCell = styled(TableCell)(() => ({
[`&.${tableCellClasses.head}`]: {
backgroundColor: "#23282c",
color: "#fff",
fontSize: 16,
height: "10px",
},
[`&.${tableCellClasses.body}`]: {
fontSize: 14,
color: "#fff",
border: "unset",
backgroundColor: "#23282c",
paddingTop: "5px",
paddingBottom: "5px",
},
}));
const StyledTableRow = styled(TableRow)(() => ({
"&:nth-of-type(odd)": {
backgroundColor: "#23282c",
height: "20px",
},
// hide last border
"&:last-child td, &:last-child th": {
border: 0,
},
}));
function createData(
name,
price,
lastOrderQuantity,
lastOrderDate,
description,
orders,
providersFull
) {
/* console.log("provFULL: ");
console.log(
"name:" + name,
"price: " + price,
"lastOrderQuantity: " + lastOrderQuantity,
"lastOrderDate: " + lastOrderDate,
"description: " + description,
"orders: " + orders,
"providersFull: " + providersFull
);
console.log("providersFull dsde ACa");
console.log(providersFull); */
if (orders) {
const providerMaped = orders.map((order) => {
console.log("provMap: " + order.amount);
console.log("provMap- name: " + order.date);
return {
key: order.amount,
dateH: order.date.slice(0, 10),
priceH: order.amount,
quantityH: order.quantity,
};
});
return {
name,
price,
lastOrderQuantity,
lastOrderDate,
description,
history: providerMaped,
};
} else {
return {
name,
price,
lastOrderQuantity,
lastOrderDate,
description,
history: [],
};
}
}
function Row(props) {
const { row } = props;
const [open, setOpen] = React.useState(false);
return (
*": { borderBottom: "unset" }, background: "#23282C" }}
>
setOpen(!open)}
>
{open ? : }
{/* {row._id} */}
{row._id}
{row.name}
{row.price}
{row.lastOrderQuantity}
{row.lastOrderDate}
Historial
Precio
Cantidad
Fecha de ingreso
{row.history.map((historyRow) => (
{historyRow.priceH}
{historyRow.quantityH}
{historyRow.dateH}
))}
);
}
export default function DataTableProvidersDetail(props) {
console.log("providers desde dataTableP");
console.log(props.selectedSupply);
const [orders, setOrders] = useState([]);
let total = 0;
const params = useParams();
const loadOrders = async () => {
const orders = await getListProvidersByIdSupply(params.id);
setOrders(orders);
};
useEffect(() => {
loadOrders();
}, []);
/* console.log("ver los orders");
console.log(orders); */
const rows = orders.map((e) => {
total += e.total;
props.funcTotal(total);
// last orders amount
const lastOrder = e.orders[e.orders.length - 1].amount;
//last orders quantity
const lastOrderQuantity = e.orders[e.orders.length - 1].quantity;
// last orders date
const lastOrderDate = e.orders[e.orders.length - 1].date.slice(0, 10);
return createData(
e.name.name,
lastOrder,
lastOrderQuantity,
lastOrderDate,
e.name.description,
e.orders,
orders
);
});
return (
<>
Proveedor
Precio
Cantidad
Ășltima Fecha de Ingreso
{rows.map((row) => (
))}
>
);
}