diff --git a/frontend/src/components/btmbuch/BuchungTabelle.js b/frontend/src/components/btmbuch/BuchungTabelle.js index be7f3cedc0a0165275b22751ed01b61f0b35be1f..a6f3e5507fa32ad2555b057da27490ebcd0966f0 100644 --- a/frontend/src/components/btmbuch/BuchungTabelle.js +++ b/frontend/src/components/btmbuch/BuchungTabelle.js @@ -1,21 +1,28 @@ -import React, {useState, useEffect} from 'react'; -import { faEdit, faTrash, faPlus, faCheck } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import {Table, Button, Row, Col} from 'react-bootstrap'; -import { Collapse } from '@material-ui/core'; -import Moment from 'react-moment'; -import { useSnackbar } from 'notistack'; -import { useParams } from 'react-router-dom'; +import React, { useState, useEffect } from "react"; +import { + faEdit, + faTrash, + faPlus, + faCheck, +} from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { Table, Button, Row, Col } from "react-bootstrap"; +import { Collapse } from "@material-ui/core"; +import Moment from "react-moment"; +import { useSnackbar } from "notistack"; +import { useParams } from "react-router-dom"; import NeueBuchungModal from "./NeueBuchungModal"; -import UpdateBuchungModal from '../../modals/UpdateBuchungModal'; -import DeleteModal from '../../modals/DeleteModal'; +import UpdateBuchungModal from "../../modals/UpdateBuchungModal"; +import DeleteModal from "../../modals/DeleteModal"; +import { ContactSupportOutlined } from "@material-ui/icons"; function BuchungTabelle(props) { let { btm } = props; const { apoId } = useParams(); + const [date, setDate] = useState(""); - const [dateClicked, setDateClicked]=useState(false) + const [dateClicked, setDateClicked] = useState(false); const [open, setOpen] = useState(false); const { enqueueSnackbar } = useSnackbar(); @@ -23,166 +30,250 @@ function BuchungTabelle(props) { const [showUpdateBuchungModal, setShowUpdateBuchungModal] = useState(false); const [showDeleteModal, setShowDeleteModal] = useState(false); - const [lieferanten, setLieferanten] = useState([]); - const [aerzte, setAerzte] = useState([]); - const [empfaenger, setEmpfaenger] = useState([]); - const [selectedBuchung, setSelectedBuchung] = useState({}); - - - const loadLieferanten = async () => { - const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/lieferant`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), - } - }).catch((err) => { - //SHOW ERROR - console.log(err); - }); + const [lieferanten, setLieferanten] = useState([]); + const [aerzte, setAerzte] = useState([]); + const [empfaenger, setEmpfaenger] = useState([]); + const [selectedBuchung, setSelectedBuchung] = useState({}); - if (response.status === 200) { - setLieferanten(await response.json()); - console.log(lieferanten); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); + const loadLieferanten = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/lieferant`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, } - } + ).catch((err) => { + //SHOW ERROR + console.log(err); + }); + + if (response.status === 200) { + setLieferanten(await response.json()); + console.log(lieferanten); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }; const loadAerzte = async () => { - const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/arzt`, { - method: 'GET', + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/arzt`, + { + method: "GET", headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), - } - }).catch((err) => { - //SHOW ERROR - console.log(err); + "Content-Type": "application/json", + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + console.log(err); }); if (response.status === 200) { - setAerzte(await response.json()); + setAerzte(await response.json()); } else if (response.status === 403) { - // props.history.push('/forbidden'); + // props.history.push('/forbidden'); } else if (response.status === 400) { - // props.history.push('/badrequest'); + // props.history.push('/badrequest'); } -} + }; - const loadEmpfaenger = async () => { - const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/empfaenger`, { - method: 'GET', + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/empfaenger`, + { + method: "GET", headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), - } - }).catch((err) => { - //SHOW ERROR - console.log(err); + "Content-Type": "application/json", + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + console.log(err); }); if (response.status === 200) { - setEmpfaenger(await response.json()); + setEmpfaenger(await response.json()); } else if (response.status === 403) { - // props.history.push('/forbidden'); + // props.history.push('/forbidden'); } else if (response.status === 400) { - // props.history.push('/badrequest'); + // props.history.push('/badrequest'); } -} - const update = buchung => { - setSelectedBuchung(buchung); - setShowUpdateBuchungModal(true); - } + }; + + const deleteBtm = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${selectedBuchung.id}`, + { + method: "DELETE", + headers: { + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), + }, + } + ).catch((err) => { + //SHOW ERROR + console.log(err); + }); + + if (response && response.status === 200) { + props.apothekeRefFunctions.updateBtmList(); + enqueueSnackbar("Buchung erfolgreich gelöscht", { + variant: "success", + autoHideDuration: 3000, + }); + } else { + //SHOW ERROR + console.log(response); + } + }; - const del = buchung => { + const update = (buchung) => { + setSelectedBuchung(buchung); + setShowUpdateBuchungModal(true); + }; + + const del = (buchung) => { setSelectedBuchung(buchung); setShowDeleteModal(true); -} + }; - const renderEditButtons = (buchung) => { - return( - <Row style={{display:'block'}}> - <Button onClick={() => update(buchung)} style={{marginLeft:'0.5em'}}><FontAwesomeIcon icon={faEdit} /></Button> - <Button onClick={() => del(buchung)} style={{marginLeft:'0.5em'}}><FontAwesomeIcon icon={faTrash} /></Button> - </Row> - ) - } - - -const renderPruefButton = () => { - return ( - <Row style={{display:'block'}}> - <Button onClick={() => setPruefDatum()} style={{marginLeft:'0.5em'}}>{dateClicked ? '' :<FontAwesomeIcon icon={faCheck} />}</Button> - </Row> - ) -} + const renderEditButtons = (buchung) => { + return ( + <Row style={{ display: "block" }}> + <Button onClick={() => update(buchung)} style={{ marginLeft: "0.5em" }}> + <FontAwesomeIcon icon={faEdit} /> + </Button> + <Button onClick={() => del(buchung)} style={{ marginLeft: "0.5em" }}> + <FontAwesomeIcon icon={faTrash} /> + </Button> + </Row> + ); + }; -const setPruefDatum = () => { - const current = new Date(); - const date = `${current.getDate()}/${current.getMonth()+1}/${current.getFullYear()}`; - console.log(date); -} + const renderPruefButton = (buchung) => { + console.log('buchung>>', buchung); + return ( + <Row> + <Button onClick={() => {setSelectedBuchung(buchung); makePruefDatum(buchung)}} style={{ marginLeft: "0.5em" }} > <FontAwesomeIcon icon={faCheck} />{" "}</Button> + </Row> + ); + }; - const deleteBtm = async () => { - const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${selectedBuchung.id}`, { - method: 'DELETE', + const sendUpdateRequest = async (buchung) => { + const response = await fetch( + + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${buchung.id}`, + { + method: "PUT", headers: { - 'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), + "Content-Type": "application/json", + Authorization: + "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, - }).catch((err) => { - //SHOW ERROR - console.log(err); + body: JSON.stringify(buchung), + } + + ).catch((err) => { + //SHOW ERROR + console.log(err); }); if (response && response.status === 200) { - props.apothekeRefFunctions.updateBtmList(); - enqueueSnackbar('Buchung erfolgreich gelöscht', { variant:'success', autoHideDuration: 3000} ); + // enqueueSnackbar('Buchung erfolgreich aktualisiert', { variant: 'success', autoHideDuration: 3000 }); + props.apothekeRefFunctions.updateBtmList(); } else { - //SHOW ERROR - console.log(response); + //SHOW ERROR + console.log(response); } -} + }; -useEffect(() => { - loadLieferanten(); - loadAerzte(); - loadEmpfaenger(); - }, []); + const makePruefDatum = (buchung) => { + const current = new Date(); + const date = `${current.getFullYear()}-${current.getMonth()+1}-${current.getDate()}`; + let buchungData = { + ...buchung, + pruefdatum: date + } + console.log(buchungData); + sendUpdateRequest(buchungData); +} + useEffect(() => { + loadLieferanten(); + loadAerzte(); + loadEmpfaenger(); + }, []); return ( <React.Fragment> <NeueBuchungModal - {...props} lieferanten={lieferanten} - aerzte={aerzte} empfaenger={empfaenger} - buchung={selectedBuchung} show={showNewBuchungModal} onHide={() => setShowNewBuchungModal(false)} + {...props} + lieferanten={lieferanten} + aerzte={aerzte} + empfaenger={empfaenger} + buchung={selectedBuchung} + show={showNewBuchungModal} + onHide={() => setShowNewBuchungModal(false)} + /> + <UpdateBuchungModal + {...props} + lieferanten={lieferanten} + aerzte={aerzte} + empfaenger={empfaenger} + buchung={selectedBuchung} + show={showUpdateBuchungModal} + onHide={() => setShowUpdateBuchungModal(false)} /> - <UpdateBuchungModal {...props} lieferanten={lieferanten} - aerzte={aerzte} empfaenger={empfaenger} - buchung={selectedBuchung} show={showUpdateBuchungModal} onHide={() => setShowUpdateBuchungModal(false)} /> - <DeleteModal {...props} headertext={'Betäubungsmittel-Buchung löschen'} - maintext={'Möchtest du diese Buchung wirklich löschen?'} onSubmit={deleteBtm} subtext={'Dieser Vorgang kann nicht rückgängig gemacht werden'} - show={showDeleteModal} onHide={() => setShowDeleteModal(false)} /> + <DeleteModal + {...props} + headertext={"Betäubungsmittel-Buchung löschen"} + maintext={"Möchtest du diese Buchung wirklich löschen?"} + onSubmit={deleteBtm} + subtext={"Dieser Vorgang kann nicht rückgängig gemacht werden"} + show={showDeleteModal} + onHide={() => setShowDeleteModal(false)} + /> - <div style={{ marginBottom: "2em" }}> - <Row onClick={() => setOpen(!open)} className="noselect btm-table-header-name"> - <Col sm={3}><p >{btm.btm.name} ({btm.btm.menge})</p></Col> - <Col sm={9}> - <div style={{marginLeft:'-9em'}}> - <Button onClick={event => {event.stopPropagation(); setShowNewBuchungModal(true)}}> - Neue Buchung - <FontAwesomeIcon style={{marginLeft:'0.4em'}} icon={faPlus}/> - </Button> - </div> - </Col> - </Row> + <Row + onClick={() => setOpen(!open)} + className="noselect btm-table-header-name" + > + <Col sm={3}> + <p> + {btm.btm.name} ({btm.btm.menge}) + </p> + </Col> + <Col sm={9}> + <div style={{ marginLeft: "-9em" }}> + <Button + onClick={(event) => { + event.stopPropagation(); + setShowNewBuchungModal(true); + }} + > + Neue Buchung + <FontAwesomeIcon + style={{ marginLeft: "0.4em" }} + icon={faPlus} + /> + </Button> + </div> + </Col> + </Row> <Collapse in={open}> <Table striped bordered hover> <thead> @@ -195,7 +286,9 @@ useEffect(() => { <th>Rezept Nr. / Lieferschein Nr.</th> <th>Prüfdatum</th> <th>Prüfer Kürzel</th> - {props.aktiveRolle.toLowerCase() !== "pruefer" ? (<th></th> ) : null} + {props.aktiveRolle.toLowerCase() !== "pruefer" ? ( + <th></th> + ) : null} </tr> </thead> <tbody> @@ -205,18 +298,37 @@ useEffect(() => { <Moment format="DD.MM.YYYY">{buchung.datum}</Moment> </td> <td> - {buchung.typ === "ZUGANG" ? buchung.lieferant.name : buchung.empfaenger.vorname + " " + buchung.empfaenger.name} </td> + {buchung.typ === "ZUGANG" + ? buchung.lieferant.name + : buchung.empfaenger.vorname + + " " + + buchung.empfaenger.name}{" "} + </td> <td>{buchung.typ === "ABGANG" ? buchung.arzt.name : ""}</td> <td>{buchung.typ === "ZUGANG" ? buchung.menge : ""}</td> <td>{buchung.typ === "ZUGANG" ? "" : buchung.menge}</td> <td> - {buchung.typ === "ZUGANG" ? buchung.anforderungsschein : buchung.rezept} + {buchung.typ === "ZUGANG" + ? buchung.anforderungsschein + : buchung.rezept} </td> <td> - {props.aktiveRolle.toLowerCase() === 'admin' ? <td style={{textAlign:'center', verticalAlign:'middle'}}>{renderPruefButton()}</td> : null} + {props.aktiveRolle.toLowerCase() === "admin" || props.aktiveRolle.toLowerCase() === "pruefer" ? ( + <td + style={{ textAlign: "center", verticalAlign: "middle" }} + > + {renderPruefButton(buchung)} + </td> + ) : null} </td> <td></td> - {props.aktiveRolle.toLowerCase() === 'admin' ? <td style={{textAlign:'center', verticalAlign:'middle'}}>{renderEditButtons(buchung)}</td> : null} + {props.aktiveRolle.toLowerCase() === "admin" ? ( + <td + style={{ textAlign: "center", verticalAlign: "middle" }} + > + {renderEditButtons(buchung)} + </td> + ) : null} </tr> ))} </tbody> diff --git a/frontend/src/components/btmbuch/PruefDatum.js b/frontend/src/components/btmbuch/PruefDatum.js new file mode 100644 index 0000000000000000000000000000000000000000..5972607c1389a2fa56e3b33b09eddfeb8bb030bd --- /dev/null +++ b/frontend/src/components/btmbuch/PruefDatum.js @@ -0,0 +1,13 @@ +import React from 'react' + +function PruefDatum(props) { + return ( + <div> + + </div> + ) +} + +export default PruefDatum; + +