Skip to content
Snippets Groups Projects
Commit 1b6b7664 authored by Miriam Lang's avatar Miriam Lang
Browse files

check button

parent 9413325f
No related branches found
No related tags found
No related merge requests found
import React, {useState, useEffect} from 'react'; import React, { useState, useEffect } from "react";
import { faEdit, faTrash, faPlus, faCheck } from "@fortawesome/free-solid-svg-icons"; import {
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' faEdit,
import {Table, Button, Row, Col} from 'react-bootstrap'; faTrash,
import { Collapse } from '@material-ui/core'; faPlus,
import Moment from 'react-moment'; faCheck,
import { useSnackbar } from 'notistack'; } from "@fortawesome/free-solid-svg-icons";
import { useParams } from 'react-router-dom'; 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 NeueBuchungModal from "./NeueBuchungModal";
import UpdateBuchungModal from '../../modals/UpdateBuchungModal'; import UpdateBuchungModal from "../../modals/UpdateBuchungModal";
import DeleteModal from '../../modals/DeleteModal'; import DeleteModal from "../../modals/DeleteModal";
import { ContactSupportOutlined } from "@material-ui/icons";
function BuchungTabelle(props) { function BuchungTabelle(props) {
let { btm } = props; let { btm } = props;
const { apoId } = useParams(); const { apoId } = useParams();
const [date, setDate] = useState("");
const [dateClicked, setDateClicked]=useState(false) const [dateClicked, setDateClicked] = useState(false);
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const { enqueueSnackbar } = useSnackbar(); const { enqueueSnackbar } = useSnackbar();
...@@ -23,166 +30,250 @@ function BuchungTabelle(props) { ...@@ -23,166 +30,250 @@ function BuchungTabelle(props) {
const [showUpdateBuchungModal, setShowUpdateBuchungModal] = useState(false); const [showUpdateBuchungModal, setShowUpdateBuchungModal] = useState(false);
const [showDeleteModal, setShowDeleteModal] = useState(false); const [showDeleteModal, setShowDeleteModal] = useState(false);
const [lieferanten, setLieferanten] = useState([]); const [lieferanten, setLieferanten] = useState([]);
const [aerzte, setAerzte] = useState([]); const [aerzte, setAerzte] = useState([]);
const [empfaenger, setEmpfaenger] = useState([]); const [empfaenger, setEmpfaenger] = useState([]);
const [selectedBuchung, setSelectedBuchung] = 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) { const loadLieferanten = async () => {
setLieferanten(await response.json()); const response = await fetch(
console.log(lieferanten); `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/lieferant`,
} else if (response.status === 403) { {
// props.history.push('/forbidden'); method: "GET",
} else if (response.status === 400) { headers: {
// props.history.push('/badrequest'); "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 loadAerzte = async () => {
const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/arzt`, { const response = await fetch(
method: 'GET', `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/arzt`,
{
method: "GET",
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), Authorization:
} "Bearer " + window.sessionStorage.getItem("edbapo-jwt"),
}).catch((err) => { },
//SHOW ERROR }
console.log(err); ).catch((err) => {
//SHOW ERROR
console.log(err);
}); });
if (response.status === 200) { if (response.status === 200) {
setAerzte(await response.json()); setAerzte(await response.json());
} else if (response.status === 403) { } else if (response.status === 403) {
// props.history.push('/forbidden'); // props.history.push('/forbidden');
} else if (response.status === 400) { } else if (response.status === 400) {
// props.history.push('/badrequest'); // props.history.push('/badrequest');
} }
} };
const loadEmpfaenger = async () => { const loadEmpfaenger = async () => {
const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/empfaenger`, { const response = await fetch(
method: 'GET', `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/empfaenger`,
{
method: "GET",
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), Authorization:
} "Bearer " + window.sessionStorage.getItem("edbapo-jwt"),
}).catch((err) => { },
//SHOW ERROR }
console.log(err); ).catch((err) => {
//SHOW ERROR
console.log(err);
}); });
if (response.status === 200) { if (response.status === 200) {
setEmpfaenger(await response.json()); setEmpfaenger(await response.json());
} else if (response.status === 403) { } else if (response.status === 403) {
// props.history.push('/forbidden'); // props.history.push('/forbidden');
} else if (response.status === 400) { } else if (response.status === 400) {
// props.history.push('/badrequest'); // props.history.push('/badrequest');
} }
} };
const update = buchung => {
setSelectedBuchung(buchung); const deleteBtm = async () => {
setShowUpdateBuchungModal(true); 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); setSelectedBuchung(buchung);
setShowDeleteModal(true); setShowDeleteModal(true);
} };
const renderEditButtons = (buchung) => { const renderEditButtons = (buchung) => {
return( return (
<Row style={{display:'block'}}> <Row style={{ display: "block" }}>
<Button onClick={() => update(buchung)} style={{marginLeft:'0.5em'}}><FontAwesomeIcon icon={faEdit} /></Button> <Button onClick={() => update(buchung)} style={{ marginLeft: "0.5em" }}>
<Button onClick={() => del(buchung)} style={{marginLeft:'0.5em'}}><FontAwesomeIcon icon={faTrash} /></Button> <FontAwesomeIcon icon={faEdit} />
</Row> </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 renderPruefButton = (buchung) => {
const current = new Date(); console.log('buchung>>', buchung);
const date = `${current.getDate()}/${current.getMonth()+1}/${current.getFullYear()}`; return (
console.log(date); <Row>
} <Button onClick={() => {setSelectedBuchung(buchung); makePruefDatum(buchung)}} style={{ marginLeft: "0.5em" }} > <FontAwesomeIcon icon={faCheck} />{" "}</Button>
</Row>
);
};
const deleteBtm = async () => { const sendUpdateRequest = async (buchung) => {
const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${selectedBuchung.id}`, { const response = await fetch(
method: 'DELETE',
`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung/${buchung.id}`,
{
method: "PUT",
headers: { headers: {
'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), "Content-Type": "application/json",
Authorization:
"Bearer " + window.sessionStorage.getItem("edbapo-jwt"),
}, },
}).catch((err) => { body: JSON.stringify(buchung),
//SHOW ERROR }
console.log(err);
).catch((err) => {
//SHOW ERROR
console.log(err);
}); });
if (response && response.status === 200) { if (response && response.status === 200) {
props.apothekeRefFunctions.updateBtmList(); // enqueueSnackbar('Buchung erfolgreich aktualisiert', { variant: 'success', autoHideDuration: 3000 });
enqueueSnackbar('Buchung erfolgreich gelöscht', { variant:'success', autoHideDuration: 3000} ); props.apothekeRefFunctions.updateBtmList();
} else { } else {
//SHOW ERROR //SHOW ERROR
console.log(response); console.log(response);
} }
} };
useEffect(() => { const makePruefDatum = (buchung) => {
loadLieferanten();
loadAerzte();
loadEmpfaenger();
}, []);
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 ( return (
<React.Fragment> <React.Fragment>
<NeueBuchungModal <NeueBuchungModal
{...props} lieferanten={lieferanten} {...props}
aerzte={aerzte} empfaenger={empfaenger} lieferanten={lieferanten}
buchung={selectedBuchung} show={showNewBuchungModal} onHide={() => setShowNewBuchungModal(false)} 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'} <DeleteModal
maintext={'Möchtest du diese Buchung wirklich löschen?'} onSubmit={deleteBtm} subtext={'Dieser Vorgang kann nicht rückgängig gemacht werden'} {...props}
show={showDeleteModal} onHide={() => setShowDeleteModal(false)} /> 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" }}> <div style={{ marginBottom: "2em" }}>
<Row onClick={() => setOpen(!open)} className="noselect btm-table-header-name"> <Row
<Col sm={3}><p >{btm.btm.name} ({btm.btm.menge})</p></Col> onClick={() => setOpen(!open)}
<Col sm={9}> className="noselect btm-table-header-name"
<div style={{marginLeft:'-9em'}}> >
<Button onClick={event => {event.stopPropagation(); setShowNewBuchungModal(true)}}> <Col sm={3}>
Neue Buchung <p>
<FontAwesomeIcon style={{marginLeft:'0.4em'}} icon={faPlus}/> {btm.btm.name} ({btm.btm.menge})
</Button> </p>
</div> </Col>
</Col> <Col sm={9}>
</Row> <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}> <Collapse in={open}>
<Table striped bordered hover> <Table striped bordered hover>
<thead> <thead>
...@@ -195,7 +286,9 @@ useEffect(() => { ...@@ -195,7 +286,9 @@ useEffect(() => {
<th>Rezept Nr. / Lieferschein Nr.</th> <th>Rezept Nr. / Lieferschein Nr.</th>
<th>Prüfdatum</th> <th>Prüfdatum</th>
<th>Prüfer Kürzel</th> <th>Prüfer Kürzel</th>
{props.aktiveRolle.toLowerCase() !== "pruefer" ? (<th></th> ) : null} {props.aktiveRolle.toLowerCase() !== "pruefer" ? (
<th></th>
) : null}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -205,18 +298,37 @@ useEffect(() => { ...@@ -205,18 +298,37 @@ useEffect(() => {
<Moment format="DD.MM.YYYY">{buchung.datum}</Moment> <Moment format="DD.MM.YYYY">{buchung.datum}</Moment>
</td> </td>
<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 === "ABGANG" ? buchung.arzt.name : ""}</td>
<td>{buchung.typ === "ZUGANG" ? buchung.menge : ""}</td> <td>{buchung.typ === "ZUGANG" ? buchung.menge : ""}</td>
<td>{buchung.typ === "ZUGANG" ? "" : buchung.menge}</td> <td>{buchung.typ === "ZUGANG" ? "" : buchung.menge}</td>
<td> <td>
{buchung.typ === "ZUGANG" ? buchung.anforderungsschein : buchung.rezept} {buchung.typ === "ZUGANG"
? buchung.anforderungsschein
: buchung.rezept}
</td> </td>
<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></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> </tr>
))} ))}
</tbody> </tbody>
......
import React from 'react'
function PruefDatum(props) {
return (
<div>
</div>
)
}
export default PruefDatum;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment