From 9413325f8270babd518a2c77e40444ffcbd6ec58 Mon Sep 17 00:00:00 2001 From: Miriam Lang <miriam.lang@student.reutlingen-university.de> Date: Wed, 16 Dec 2020 14:45:06 +0100 Subject: [PATCH] edit end delete buchung --- .../entity/BetaeubungsmittelBuchung.java | 6 +- Datenbank/EDB-Apo_dbdata.sql | 24 +- Datenbank/EDB-Apo_dbdec.sql | 4 +- frontend/package-lock.json | 39 +++ frontend/package.json | 5 + frontend/src/App.js | 2 - frontend/src/components/btmbuch/BTMBuch.js | 2 +- .../src/components/btmbuch/BuchungTabelle.js | 272 ++++++++++++++---- .../components/btmbuch/NeueBuchungModal.js | 102 ++----- frontend/src/modals/ApothekeRegisterModal.js | 3 +- frontend/src/modals/UpdateBuchungModal.js | 200 +++++++++++++ 11 files changed, 505 insertions(+), 154 deletions(-) create mode 100644 frontend/src/modals/UpdateBuchungModal.js diff --git a/Backend/src/main/java/com/ebdapo/backend/entity/BetaeubungsmittelBuchung.java b/Backend/src/main/java/com/ebdapo/backend/entity/BetaeubungsmittelBuchung.java index 35870c0..434a871 100644 --- a/Backend/src/main/java/com/ebdapo/backend/entity/BetaeubungsmittelBuchung.java +++ b/Backend/src/main/java/com/ebdapo/backend/entity/BetaeubungsmittelBuchung.java @@ -19,14 +19,14 @@ public class BetaeubungsmittelBuchung { private String id; @Temporal(TemporalType.DATE) - @Column(name="pruefdatum", nullable = false) + @Column(name="pruefdatum") private Date pruefdatum; @Column(name="menge", nullable = false) private int menge; - @Temporal(TemporalType.TIMESTAMP) - @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss") + @Temporal(TemporalType.DATE) + // @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss") @Column(name="datum", nullable = false) private Date datum; diff --git a/Datenbank/EDB-Apo_dbdata.sql b/Datenbank/EDB-Apo_dbdata.sql index 112cbde..7a8df7d 100644 --- a/Datenbank/EDB-Apo_dbdata.sql +++ b/Datenbank/EDB-Apo_dbdata.sql @@ -86,18 +86,18 @@ INSERT INTO empfaenger (id, name, vorname, anschrift, apotheke) value ('6', 'Ren INSERT INTO empfaenger (id, name, vorname, anschrift, apotheke) value ('7', 'Master', 'Rudolf', '8', '3'); INSERT INTO empfaenger (id, name, vorname, anschrift, apotheke) value ('8', 'Hase', 'Mike', '9', '3'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('1', '2020-11-10', '100', '2020-10-24 20:21:55', '1', '3'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('2', '2020-10-03', '20', '2020-02-17 09:32:58', '1', '3'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('3', '2020-09-10', '20', '2019-12-19 01:46:13', '1', '3'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('4', '2020-09-03', '5', '2020-05-10 16:02:22', '1', '3'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('5', '2020-11-10', '5', '2020-11-25 20:38:01', '7', '7'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('6', '2020-10-03', '10', '2019-12-22 12:06:24', '7', '7'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('7', '2020-10-10', '20', '2020-08-14 07:26:09', '8', '7'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('8', '2020-10-03', '60', '2020-02-17 17:27:00', '8', '7'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('9', '2020-11-10', '5', '2020-05-24 22:21:25', '1', '12'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('10', '2020-09-03', '10', '2020-03-28 01:14:10', '1', '12'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('11', '2020-09-25', '5', '2020-02-18 11:53:21', '1', '12'); -INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('12', '2020-09-25', '20', '2020-08-18 06:43:43', '1', '12'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('1', '2020-11-10', '100', '2020-10-24', '1', '3'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('2', '2020-10-03', '20', '2020-02-17', '1', '3'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('3', '2020-09-10', '20', '2019-12-19', '1', '3'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('4', '2020-09-03', '5', '2020-05-10', '1', '3'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('5', '2020-11-10', '5', '2020-11-25', '7', '7'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('6', '2020-10-03', '10', '2019-12-22', '7', '7'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('7', '2020-10-10', '20', '2020-08-14', '8', '7'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('8', '2020-10-03', '60', '2020-02-17', '8', '7'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('9', '2020-11-10', '5', '2020-05-24', '1', '12'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('10', '2020-09-03', '10', '2020-03-28', '1', '12'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('11', '2020-09-25', '5', '2020-02-18', '1', '12'); +INSERT INTO btm_buchung(id, pruefdatum, menge, datum, btm, benutzer) value ('12', '2020-09-25', '20', '2020-08-18', '1', '12'); INSERT INTO zugang (id, anfordergungsschein, lieferant) value ('1', '63671547', '1'); INSERT INTO zugang (id, anfordergungsschein, lieferant) value ('2', '65571547', '1'); diff --git a/Datenbank/EDB-Apo_dbdec.sql b/Datenbank/EDB-Apo_dbdec.sql index ef09b62..4a7e9f3 100644 --- a/Datenbank/EDB-Apo_dbdec.sql +++ b/Datenbank/EDB-Apo_dbdec.sql @@ -85,9 +85,9 @@ CREATE TABLE empfaenger ( CREATE TABLE btm_buchung ( id VARCHAR (40) NOT NULL, - pruefdatum DATE NOT NULL, + pruefdatum DATE, menge INTEGER NOT NULL, - datum TIMESTAMP NOT NULL, + datum DATE NOT NULL, btm VARCHAR (40) NOT NULL, benutzer VARCHAR (40) NOT NULL, PRIMARY KEY (id), diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 7755f96..142c71f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1227,6 +1227,35 @@ } } }, + "@fortawesome/fontawesome-common-types": { + "version": "0.2.32", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.32.tgz", + "integrity": "sha512-ux2EDjKMpcdHBVLi/eWZynnPxs0BtFVXJkgHIxXRl+9ZFaHPvYamAfCzeeQFqHRjuJtX90wVnMRaMQAAlctz3w==" + }, + "@fortawesome/fontawesome-svg-core": { + "version": "1.2.32", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-1.2.32.tgz", + "integrity": "sha512-XjqyeLCsR/c/usUpdWcOdVtWFVjPbDFBTQkn2fQRrWhhUoxriQohO2RWDxLyUM8XpD+Zzg5xwJ8gqTYGDLeGaQ==", + "requires": { + "@fortawesome/fontawesome-common-types": "^0.2.32" + } + }, + "@fortawesome/free-solid-svg-icons": { + "version": "5.15.1", + "resolved": "https://registry.npmjs.org/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-5.15.1.tgz", + "integrity": "sha512-EFMuKtzRMNbvjab/SvJBaOOpaqJfdSap/Nl6hst7CgrJxwfORR1drdTV6q1Ib/JVzq4xObdTDcT6sqTaXMqfdg==", + "requires": { + "@fortawesome/fontawesome-common-types": "^0.2.32" + } + }, + "@fortawesome/react-fontawesome": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/@fortawesome/react-fontawesome/-/react-fontawesome-0.1.13.tgz", + "integrity": "sha512-/HrLnIft5Ks2511Pz6TxHBIctC9QalVscAC64sufQ4sJH/sXaQlG3uR9LCu6VpEwkBemgcBLrz/QPNP/ddbjDg==", + "requires": { + "prop-types": "^15.7.2" + } + }, "@hapi/address": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@hapi/address/-/address-2.1.4.tgz", @@ -10487,6 +10516,11 @@ "minimist": "^1.2.5" } }, + "moment": { + "version": "2.29.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz", + "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==" + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", @@ -12967,6 +13001,11 @@ "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz", "integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==" }, + "react-moment": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/react-moment/-/react-moment-1.0.0.tgz", + "integrity": "sha512-J4iIiwUT4oZcL7cp2U7naQKbQtqvmzGXXBMg/DLj+Pi7n9EW0VhBRx/1aJ1Tp2poCqTCAPoadLEoUIkReGnNNg==" + }, "react-overlays": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-4.1.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index 3fe502d..59c5d4b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -3,6 +3,9 @@ "version": "0.1.0", "private": true, "dependencies": { + "@fortawesome/fontawesome-svg-core": "^1.2.32", + "@fortawesome/free-solid-svg-icons": "^5.15.1", + "@fortawesome/react-fontawesome": "^0.1.13", "@material-ui/core": "^4.11.2", "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.57", @@ -11,12 +14,14 @@ "@testing-library/user-event": "^12.5.0", "bootstrap": "^4.5.3", "dotenv": "^8.2.0", + "moment": "^2.29.1", "node-sass": "^4.14.1", "notistack": "^1.0.2", "react": "^17.0.1", "react-bootstrap": "^1.4.0", "react-dom": "^17.0.1", "react-hook-form": "^6.12.2", + "react-moment": "^1.0.0", "react-router-dom": "^5.2.0", "react-scripts": "4.0.1", "web-vitals": "^0.2.4" diff --git a/frontend/src/App.js b/frontend/src/App.js index 31131fd..aed9608 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -7,8 +7,6 @@ import ApothekeEinstellungen from './components/apotheke/einstellungen/ApothekeE import { SnackbarProvider } from 'notistack'; require('dotenv').config() -// library.add(fab, faCheckSquare, faBookMedical) - function App() { return ( <React.Fragment> diff --git a/frontend/src/components/btmbuch/BTMBuch.js b/frontend/src/components/btmbuch/BTMBuch.js index 004f8bd..a658866 100644 --- a/frontend/src/components/btmbuch/BTMBuch.js +++ b/frontend/src/components/btmbuch/BTMBuch.js @@ -54,7 +54,7 @@ function BTMBuch (props) { <Col><ApothekenDetails {...props} apothekeRefFunctions={apothekeRefFunctions} apothekeId={apoId}/></Col> <Col>{isLoggedIn ? <UserDetails {...props} user={user} setUser={setUser} aktiveRolle={aktiveRolle} setAktiveRolle={setAktiveRolle}/> : null }</Col> </Row> - <ApothekeBtmList apothekeId={apoId} user={user} apothekeRefFunctions={apothekeRefFunctions} {...props}/> + <ApothekeBtmList apothekeId={apoId} user={user} apothekeRefFunctions={apothekeRefFunctions} {...props} aktiveRolle={aktiveRolle}/> </React.Fragment> ) } diff --git a/frontend/src/components/btmbuch/BuchungTabelle.js b/frontend/src/components/btmbuch/BuchungTabelle.js index b8d0b85..be7f3ce 100644 --- a/frontend/src/components/btmbuch/BuchungTabelle.js +++ b/frontend/src/components/btmbuch/BuchungTabelle.js @@ -1,56 +1,230 @@ -import React, {useState} from 'react'; -import {Table, Button, Row} from 'react-bootstrap'; +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 NeueBuchungModal from './NeueBuchungModal' +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'; function BuchungTabelle(props) { - let {btm} = props; - const [open, setOpen] = useState(false); - const [showBuchungModal, setShowBuchungModal] = useState(false); - - return ( - <React.Fragment> - <NeueBuchungModal {...props} show={showBuchungModal} onHide={() => setShowBuchungModal(false)}/> - <div style={{marginBottom:"2em"}}> - <Row onClick={() => setOpen(!open)} className="noselect btm-table-header-name"> - <div className="float-left"> - <p className="float-left" >{btm.btm.name}</p> - <Button className="btn-circle" style={{marginLeft:'10px'}} onClick={event => {event.stopPropagation(); setShowBuchungModal(true)}}>+</Button> - </div> - </Row> - <Collapse in={open} > - <Table striped bordered hover> - <thead> - <tr> - <th>Datum</th> - <th>Lieferant / Patient</th> - <th>Arztpraxis</th> - <th>Zugang</th> - <th>Abgang</th> - <th>Rezept Nr. / Lieferschein Nr.</th> - <th>Prüfdatum</th> - </tr> - </thead> - <tbody> - {btm.buchungen.map(buchung => - <tr key={buchung.id}> - <td>{buchung.datum}</td> - <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}</td> - <td>{buchung.pruefdatum}</td> - </tr> - )} - </tbody> - </Table> - </Collapse> - </div> - </React.Fragment> - ) + let { btm } = props; + const { apoId } = useParams(); + + const [dateClicked, setDateClicked]=useState(false) + const [open, setOpen] = useState(false); + const { enqueueSnackbar } = useSnackbar(); + + const [showNewBuchungModal, setShowNewBuchungModal] = useState(false); + 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); + }); + + 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', + headers: { + '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()); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } +} + + + const loadEmpfaenger = async () => { + 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); + }); + + if (response.status === 200) { + setEmpfaenger(await response.json()); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } +} + 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 setPruefDatum = () => { + const current = new Date(); + const date = `${current.getDate()}/${current.getMonth()+1}/${current.getFullYear()}`; + console.log(date); +} + + 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); + } +} + +useEffect(() => { + loadLieferanten(); + loadAerzte(); + loadEmpfaenger(); + }, []); + + + + return ( + <React.Fragment> + <NeueBuchungModal + {...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)} /> + + <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> + <Collapse in={open}> + <Table striped bordered hover> + <thead> + <tr> + <th>Datum</th> + <th>Lieferant / Patient</th> + <th>Arztpraxis</th> + <th>Zugang</th> + <th>Abgang</th> + <th>Rezept Nr. / Lieferschein Nr.</th> + <th>Prüfdatum</th> + <th>Prüfer Kürzel</th> + {props.aktiveRolle.toLowerCase() !== "pruefer" ? (<th></th> ) : null} + </tr> + </thead> + <tbody> + {btm.buchungen.map((buchung) => ( + <tr key={buchung.id}> + <td> + <Moment format="DD.MM.YYYY">{buchung.datum}</Moment> + </td> + <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} + </td> + <td> + {props.aktiveRolle.toLowerCase() === 'admin' ? <td style={{textAlign:'center', verticalAlign:'middle'}}>{renderPruefButton()}</td> : null} + </td> + <td></td> + {props.aktiveRolle.toLowerCase() === 'admin' ? <td style={{textAlign:'center', verticalAlign:'middle'}}>{renderEditButtons(buchung)}</td> : null} + </tr> + ))} + </tbody> + </Table> + </Collapse> + </div> + </React.Fragment> + ); +} -export default BuchungTabelle; \ No newline at end of file +export default BuchungTabelle; diff --git a/frontend/src/components/btmbuch/NeueBuchungModal.js b/frontend/src/components/btmbuch/NeueBuchungModal.js index c06a74f..18f216e 100644 --- a/frontend/src/components/btmbuch/NeueBuchungModal.js +++ b/frontend/src/components/btmbuch/NeueBuchungModal.js @@ -6,9 +6,10 @@ function NeueBuchungModal(props) { const { enqueueSnackbar } = useSnackbar(); const [typ, setTyp] = useState(''); - const [lieferanten, setLieferanten] = useState([]); - const [aerzte, setAerzte] = useState([]); - const [empfaenger, setEmpfaenger] = useState([]); + let {lieferanten, aerzte, empfaenger} = props; + + + const [maxMenge, setMaxMenge] = useState(props.btm.btm.menge); const sendNewBuchungAnfrage = async (buchungData) => { const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/btmbuchung`, { @@ -39,7 +40,7 @@ function NeueBuchungModal(props) { const createNewBuchung = event => { event.preventDefault(); if (typ.toLowerCase() === 'zugang') { - let { anforderungsschein, btmMenge, lieferant, pruefdatum } = event.target; + let { anforderungsschein, btmMenge, lieferant, datum} = event.target; let buchungData = { benutzer: props.user.id, btm: props.btm.btm.id, @@ -47,11 +48,12 @@ function NeueBuchungModal(props) { typ: 'ZUGANG', lieferant: lieferant.value, anforderungsschein: anforderungsschein.value, - pruefdatum: pruefdatum.value + datum: datum.value, + pruefdatum: '' } sendNewBuchungAnfrage(buchungData); } else if (typ.toLowerCase() === 'abgang') { - let { btmMenge, rezept, empfaenger, arzt, pruefdatum } = event.target; + let { btmMenge, rezept, empfaenger, arzt, datum} = event.target; let buchungData = { benutzer: props.user.id, btm: props.btm.btm.id, @@ -60,7 +62,8 @@ function NeueBuchungModal(props) { empfaenger: empfaenger.value, arzt: arzt.value, rezept: rezept.value, - pruefdatum: pruefdatum.value + pruefdatum: '', + datum: datum.value } sendNewBuchungAnfrage(buchungData); } @@ -71,75 +74,8 @@ function NeueBuchungModal(props) { props.onHide(); } - - 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', - headers: { - '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()); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); - } - } - - const loadEmpfaenger = async () => { - 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); - }); - - if (response.status === 200) { - setEmpfaenger(await response.json()); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); - } - } - useEffect(() => { - loadLieferanten(); - loadAerzte(); - loadEmpfaenger(); + setMaxMenge(props.btm.btm.menge) }, []); const renderZugang = () => { @@ -147,7 +83,7 @@ function NeueBuchungModal(props) { <React.Fragment> <Form.Group as={Row} controlId="anforderungsschein"> <Form.Label column sm="2"> - Anforderungsschein + Lieferschein </Form.Label> <Col sm="10"> <Form.Control name="anforderungsschein" type="text" required /> @@ -223,7 +159,7 @@ function NeueBuchungModal(props) { label="Zugang" name="TypRadio" id="ZugangRadio" - onClick={() => setTyp('zugang')} + onClick={() => {setTyp('zugang'); setMaxMenge(9999)}} /> <Form.Check required type="radio" @@ -244,14 +180,14 @@ function NeueBuchungModal(props) { <Form.Control name="btmMenge" type="number" min="1" defaultValue="0" /> </Col> </Form.Group> - <Form.Group as={Row} controlId="pruefdatum"> + <Form.Group as={Row} controlId="datum"> <Form.Label column sm="2"> - Prüfdatum + Datum </Form.Label> <Col sm="10"> - <Form.Control name="pruefdatum" type="date" defaultValue={new Date()} /> + <Form.Control name="datum" type="date" defaultValue={new Date()} /> </Col> - </Form.Group> + </Form.Group> {typ.toLowerCase() === 'zugang' ? renderZugang() : null} {typ.toLowerCase() === 'abgang' ? renderAbgang() : null} @@ -267,7 +203,7 @@ function NeueBuchungModal(props) { </Modal> ) - } -export default NeueBuchungModal; \ No newline at end of file +export default NeueBuchungModal; + diff --git a/frontend/src/modals/ApothekeRegisterModal.js b/frontend/src/modals/ApothekeRegisterModal.js index d9b0cc9..b66b2b0 100644 --- a/frontend/src/modals/ApothekeRegisterModal.js +++ b/frontend/src/modals/ApothekeRegisterModal.js @@ -67,7 +67,7 @@ function ApothekeRegisterModal(props) { vorname: values.vorname, nutzername: values.nutzername, passwort: passwords.password, - rolle: "ADMIN", + rolle: 'ADMIN', }; return fetch( @@ -122,7 +122,6 @@ function ApothekeRegisterModal(props) { if (apoResponse.status === 201) { let apoId = await apoResponse.json(); let adminRespone = await createNewAdmin(apoId.id); - console.log("Admin response >>>>", adminRespone); if (adminRespone.status === 201) { let loginResponse = await login(); if (loginResponse.status === 200) { diff --git a/frontend/src/modals/UpdateBuchungModal.js b/frontend/src/modals/UpdateBuchungModal.js new file mode 100644 index 0000000..2fd0370 --- /dev/null +++ b/frontend/src/modals/UpdateBuchungModal.js @@ -0,0 +1,200 @@ +import React,{useEffect} from 'react'; +import { Modal, Button, Form, Row, Col } from 'react-bootstrap'; +import { useSnackbar } from 'notistack'; +import { useParams } from 'react-router-dom'; + + + +function UpdateBuchungModal(props) { + + // let apothekeId = sessionStorage.getItem('apothekeId'); + const { apoId } = useParams(); + // eslint-disable-next-line + let {lieferanten, aerzte, empfaenger} = props; + const { enqueueSnackbar } = useSnackbar(); + + const sendUpdateRequest = async (buchungData) => { + const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${props.buchung.id}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), + }, + body: JSON.stringify(buchungData) + }).catch((err) => { + //SHOW ERROR + console.log(err); + }); + + + if (response && response.status === 200) { + props.onHide(); + enqueueSnackbar('Buchung erfolgreich aktualisiert', { variant: 'success', autoHideDuration: 3000 }); + props.apothekeRefFunctions.updateBtmList(); + } else { + //SHOW ERROR + console.log(response); + } + } + + + + + const updateBuchung = event => { + event.preventDefault(); + + if (props.buchung.typ.toLowerCase() === 'zugang') { + let { anforderungsschein, btmMenge, lieferant, pruefdatum, datum } = event.target; + let buchungData = { + benutzer: props.user.id, + btm: props.btm.btm.id, + menge: btmMenge.value, + typ: 'ZUGANG', + lieferant: lieferant.value, + anforderungsschein: anforderungsschein.value, + pruefdatum: pruefdatum.value, + datum: datum.value + } + sendUpdateRequest(buchungData); + } else if (props.buchung.typ.toLowerCase() === 'abgang') { + let { btmMenge, rezept, empfaenger, arzt, pruefdatum, datum} = event.target; + let buchungData = { + benutzer: props.user.id, + btm: props.btm.btm.id, + menge: btmMenge.value, + typ: 'ABGANG', + empfaenger: empfaenger.value, + arzt: arzt.value, + rezept: rezept.value, + pruefdatum: pruefdatum.value, + datum: datum.value + } + sendUpdateRequest(buchungData); + } + } + + + + + function Zugang({ buchung }) { + if (buchung.typ) { + if (buchung.typ.toLowerCase() === 'zugang') { + return ( + <React.Fragment> + <Form.Group as={Row} controlId="anforderungsschein"> + <Form.Label column sm="2"> + Anforderungsschein + </Form.Label> + <Col sm="10"> + <Form.Control name="anforderungsschein" type="text" required defaultValue={buchung.anforderungsschein} /> + </Col> + </Form.Group> + <Form.Group as={Row} controlId="lieferant"> + <Form.Label column sm="2"> + Lieferant + </Form.Label> + <Col sm="10"> + <Form.Control name="lieferant" defaultValue={buchung.lieferant.name} required as="select"> + {console.log('lieferanten', lieferanten)} + {lieferanten.map(l => <option key={l.id} value={l.id}>{l.name}</option>)} + </Form.Control> + </Col> + </Form.Group> + </React.Fragment>) + } + } + return null; + } + + function Abgang({ buchung }) { + if (buchung.typ) { + if (buchung.typ.toLowerCase() === 'abgang') { + return ( + <React.Fragment> + <Form.Group as={Row} controlId="empfaenger"> + <Form.Label column sm="2"> + Empfaenger + </Form.Label> + <Col sm="10"> + <Form.Control name="empfaenger" defaultValue={buchung.empfaenger.name} required as="select"> + {empfaenger.map(e => <option key={e.id} value={e.id}>{e.vorname} {e.name}</option>)} + </Form.Control> + </Col> + </Form.Group> + <Form.Group as={Row} controlId="arzt"> + <Form.Label column sm="2"> + Arzt + </Form.Label> + <Col sm="10"> + <Form.Control name="arzt" defaultValue={buchung.arzt.name} required as="select"> + {aerzte.map(a => <option key={a.id} value={a.id}>{a.name}</option>)} + </Form.Control> + </Col> + </Form.Group> + <Form.Group as={Row} controlId="rezept"> + <Form.Label column sm="2"> + Rezept + </Form.Label> + <Col sm="10"> + <Form.Control defaultValue={buchung.rezept} name="rezept" type="text" required /> + </Col> + </Form.Group> + </React.Fragment>) + } + } + return null; + } + + + return ( + <Modal + {...props} + size="lg" + aria-labelledby="contained-modal-title-vcenter" + centered + onExiting={props.onHide} + > + <Modal.Header closeButton> + <Modal.Title id="contained-modal-title-vcenter"> + Betäubungsmittel-Buchung aktualisieren + </Modal.Title> + </Modal.Header> + <Form onSubmit={updateBuchung}> + <Modal.Body> + <Form.Group as={Row} controlId="datum"> + <Form.Label column sm="2"> + Datum + </Form.Label> + <Col sm="10"> + <Form.Control name="datum" type="date" defaultValue={props.buchung.datum} /> + </Col> + </Form.Group> + <Form.Group as={Row} controlId="btmMenge"> + <Form.Label column sm="2"> + Menge + </Form.Label> + <Col sm="10"> + <Form.Control name="btmMenge" type="number" min="1" defaultValue={props.buchung.menge} /> + </Col> + </Form.Group> + <Form.Group as={Row} controlId="pruefdatum"> + <Form.Label column sm="2"> + Prüfdatum + </Form.Label> + <Col sm="10"> + <Form.Control name="pruefdatum" type="date" defaultValue={props.buchung.pruefdatum} /> + </Col> + </Form.Group> + <Zugang buchung={props.buchung} /> + <Abgang buchung={props.buchung} /> + </Modal.Body> + <Modal.Footer> + <Button variant="" onClick={props.onHide}>Abbrechen</Button> + <Button variant="primary" type="submit">Bestätigen</Button> + </Modal.Footer> + </Form> + </Modal> + ) +} + +export default UpdateBuchungModal; -- GitLab