Skip to content

Commit

Permalink
pdf de receitas
Browse files Browse the repository at this point in the history
  • Loading branch information
TI JONNY committed Oct 6, 2023
1 parent 056736e commit 5cfa853
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 19 deletions.
13 changes: 7 additions & 6 deletions src/Pdf/PdfPrioridadeStudent/relatorioPrioridades.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,7 @@ const MyDocument = () => {
</Padding>
<div ref={contentRef}>
<Padding padding="16px">
<Column id="center">
<Row id="center">
<img style={{ width: "256px", padding: "8px 16px" }} alt="" src={logo} />
</Row>
</Column>

<Column>
<Row id='space-between'>
<Column>
Expand All @@ -231,6 +227,11 @@ const MyDocument = () => {
<Padding />
<h1 style={{ padding: "0 4px", margin: 0, color: "#000" }}>Data de Emissão: {formatarDataHora()}</h1>
</Column>
<Column id="center">
<Row id="center">
<img style={{ width: "256px", padding: "8px 16px" }} alt="" src={logo} />
</Row>
</Column>
</Row>
</Column>
<Padding padding="8px" />
Expand All @@ -256,7 +257,7 @@ const MyDocument = () => {
<tr key={index}>
<TableData>{item.student.object.name}</TableData>
<TableData>{item.points}</TableData>
<TableData>{item.points < 5 ? "Prioridade minima" : (item.points >= 5 && item.points < 9) ? "Prioridade média" : item.points >= 10 ? "Prioridade máxima": ""}</TableData>
<TableData>{item.points < 5 ? "Prioridade minima" : (item.points >= 5 && item.points < 9) ? "Prioridade média" : item.points >= 10 ? "Prioridade máxima" : ""}</TableData>
</tr>
)
})}
Expand Down
11 changes: 6 additions & 5 deletions src/Pdf/PdfReceita/receita.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ const MyDocument = () => {
</Padding>
<div ref={contentRef}>
<Padding padding="16px">
<Column id="center">
<Row id="center">
<img style={{ width: "256px", padding: "8px 16px" }} alt="" src={logo} />
</Row>
</Column>

<Column>
<Row id='space-between'>
<Column>
Expand All @@ -89,6 +85,11 @@ const MyDocument = () => {
<Padding />
<h2 style={{ padding: "0 4px", margin: 0, color: "#000" }}>Médico: {students?.object.nomeMedico} <Padding /> CRM: {students?.object.crmMedico}</h2>
</Column>
<Column id="center">
<Row id="center">
<img style={{ width: "256px", padding: "8px 16px" }} alt="" src={logo} />
</Row>
</Column>
</Row>
</Column>
<Padding padding="8px" />
Expand Down
11 changes: 11 additions & 0 deletions src/Pdf/PdfTodasReceitas/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import MyDocument from "./receita";

const PdfTodasReceita = () => {

return (
<MyDocument />
)
}

export default PdfTodasReceita
157 changes: 157 additions & 0 deletions src/Pdf/PdfTodasReceitas/receita.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { SaveAlt } from '@material-ui/icons';
import html2canvas from 'html2canvas';
import jsPDF from 'jspdf';
import React, { useEffect, useRef, useState } from 'react';
import { useParams } from "react-router-dom";
import logo from "../../assets/images/logo.svg";
import fetchRegistration from '../../controller/registration/fetchRegistration';
import { Column, Padding, Row } from '../../styles/style';
import { Table, TableData, TableHeader, TableWrapper } from '../style';
import fetchOneClassroom from '../../controller/classroom/fetchOneClassroom';




// Create Document Component
const MyDocument = () => {


const contentRef = useRef(null);


const { id } = useParams()


const [students, setStudents] = useState()
const [classroom, setClassroom] = useState([])


const generatePDF = () => {
if (!contentRef.current) return;

const elementToCapture = contentRef.current;

html2canvas(elementToCapture).then((canvas) => {
const pdf = new jsPDF('p', 'mm', 'a4');

const imgData = canvas.toDataURL('image/png');
const imgWidth = 210;
const imgHeight = (canvas.height * imgWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, imgWidth, imgHeight);

pdf.save(`Receita-${classroom.object.name}-Lupa.pdf`);
});
};

useEffect(() => {
fetchRegistration()
.then((testDataList) => {
const student = testDataList.filter(props => props.object.classroom_fk === id)
setStudents(student)
})
.catch((err) => {
// Trate erros, se ocorrerem
console.error(err)
})
fetchOneClassroom(id)
.then((testDataList) => {
setClassroom(testDataList)
})
.catch((err) => {
// Trate erros, se ocorrerem
console.error(err)
})
}, [id])

function formatarDataHora() {
const agora = new Date();
const dia = agora.getDate().toString().padStart(2, '0');
const mes = (agora.getMonth() + 1).toString().padStart(2, '0'); // Lembre-se de que os meses são baseados em zero
const ano = agora.getFullYear();
const hora = agora.getHours().toString().padStart(2, '0');
const minutos = agora.getMinutes().toString().padStart(2, '0');

return `${dia}/${mes}/${ano} - ${hora}:${minutos}h`;
}

const filterReceitas = students?.filter(props => props.object.receitaEsfericoOlhoDireito);

return (
<div style={{ width: "100%" }}>


<Padding padding="32px 16px">
<button style={{ padding: "8px", cursor: "pointer" }} onClick={generatePDF}><Row><SaveAlt /><h3 style={{ padding: "0 4px", margin: 0, color: "#000" }}>Gerar PDF</h3></Row></button>
</Padding>
<div ref={contentRef}>
{filterReceitas?.map((item) => {
return (
<Padding padding="16px">
<Column>
<Row id='space-between'>
<Column>
<h1 style={{ padding: "0 4px", margin: 0, color: "#000" }}>Nome: {item?.object.name}</h1>
<Padding />
<h2 style={{ padding: "0 4px", margin: 0, color: "#000" }}>Data de Nascimento: {item?.object.birthday}</h2>
<Padding />
<h2 style={{ padding: "0 4px", margin: 0, color: "#000" }}>Data da consulta: {item?.object.dataConsulta}</h2>
<Padding />
<h2 style={{ padding: "0 4px", margin: 0, color: "#000" }}>Médico: {item?.object.nomeMedico} <Padding /> CRM: {item?.object.crmMedico}</h2>
</Column>
<Column id="center">
<Row id="center">
<img style={{ width: "256px", padding: "8px 16px" }} alt="" src={logo} />
</Row>
</Column>
</Row>
</Column>
<Padding padding="8px" />
<div style={{ backgroundColor: "black", height: "1px" }}></div>
<Column>
<Row id='center'>
<h1 style={{ padding: "0px" }}>Receita de óculos </h1>
</Row>
</Column>
<div>
<TableWrapper>
<Table>
<thead>
<tr>
<TableHeader></TableHeader>
<TableHeader style={{ textAlign: "center" }}>Esférico</TableHeader>
<TableHeader style={{ textAlign: "center" }}>Cilíndrico</TableHeader>
<TableHeader style={{ textAlign: "center" }}>Eixo</TableHeader>
<TableHeader style={{ textAlign: "center" }}>DP</TableHeader>
</tr>
</thead>
<tbody>

<tr>
<TableData>Olho direito</TableData>
<TableData style={{ textAlign: "center" }}>{item?.object.receitaEsfericoOlhoDireito}</TableData>
<TableData style={{ textAlign: "center" }}>{item?.object.receitaCilindricoOlhoDireito}</TableData>
<TableData style={{ textAlign: "center" }}>{item?.object.receitaEixoOlhoDireito}</TableData>
<TableData style={{ textAlign: "center" }}>{item?.object.receitaDpOlhoDireito}</TableData>
</tr>
<tr>
<TableData>Olho esquerdo</TableData>
<TableData style={{ textAlign: "center" }}>{item?.object.receitaEsfericoOlhoEsquerdo}</TableData>
<TableData style={{ textAlign: "center" }}>{item?.object.receitaCilindricoOlhoEsquerdo}</TableData>
<TableData style={{ textAlign: "center" }}>{item?.object.receitaEixoOlhoEsquerdo}</TableData>
<TableData style={{ textAlign: "center" }}>{item?.object.receitaDpOlhoEsquerdo}</TableData>
</tr>
</tbody>
</Table>
</TableWrapper>
</div>
<p>Receita feita por um profisional da saúde. Data de emissão: {formatarDataHora()} </p>
<div style={{ height: "1px", width: "100%", background: "black", border: "2px dashed white", marginTop: "16px" }} />
</Padding>
)
})}
</div>
</div>
)

}
export default MyDocument
12 changes: 12 additions & 0 deletions src/containers/Classroom/ClasroomForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useParams } from "react-router-dom";
import { useEffect } from "react";
import { useState } from "react";
import fetchRegistration from "../../controller/registration/fetchRegistration";
import fetchOneClassroom from "../../controller/classroom/fetchOneClassroom";

const Form = props => {

Expand All @@ -21,6 +22,7 @@ const Form = props => {
});

const [students, setStudents] = useState([])
const [classroom, setClassroom] = useState([])

useEffect(() => {
fetchRegistration()
Expand All @@ -32,6 +34,15 @@ const Form = props => {
// Trate erros, se ocorrerem
console.error(err)
})

fetchOneClassroom(id)
.then((testDataList) => {
setClassroom(testDataList)
})
.catch((err) => {
// Trate erros, se ocorrerem
console.error(err)
})
}, [id])


Expand All @@ -44,6 +55,7 @@ const Form = props => {
baseLink={`/turmas/${props.match.params.id}/matricula`}
loadingIcon={props?.loading}
data={students}
classroom={classroom}
/>
</>
</>
Expand Down
6 changes: 6 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Login from "./containers/Login";
import Register from "./containers/Register";
import FormRegistration from "./containers/Registration/FormRegistration/FormRegistration";
import { isAuthenticated } from "./services/auth";
import PdfTodasReceita from "./Pdf/PdfTodasReceitas";

//const Home = lazy(() => import("./containers/Home"));

Expand Down Expand Up @@ -81,6 +82,11 @@ const Routes = () => (
path="/turmas/:id/pdf"
component={PdfPrioridade}
/>
<Route
exact
path="/turmas/:id/pdfreceita"
component={PdfTodasReceita}
/>
<PrivateRoute exact path="/turma/adicionar" component={CreateClassroom} />
<Route path="/*" component={NotFoundPage} />
</Switch>
Expand Down
29 changes: 21 additions & 8 deletions src/screens/Classroom/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import Alert from "@material-ui/lab/Alert";
// Third party

// Components
import { useParams } from "react-router-dom";
import { BoxRegistration } from "../../components/Boxes";
import List from "../../components/List";
import { useParams } from "react-router-dom";

// Styles
import { ArrowBack } from "@material-ui/icons";
import { useHistory } from "react-router";
import { Padding } from "../../styles/style";
import { ButtonPurple } from "../../components/Buttons";
import { Padding } from "../../styles/style";

const Create = props => {

Expand All @@ -24,6 +24,7 @@ const Create = props => {
const {
data,
baseLink,
classroom
} = props;

const { id } = useParams()
Expand All @@ -35,7 +36,7 @@ const Create = props => {

const points = () => {
var count = 0;

if (registration) {
if (registration.object.filhoOculos === "1") {
count++;
Expand Down Expand Up @@ -113,7 +114,7 @@ const Create = props => {
count = count + 5;
}
if (
registration.object.acuidadeTriagemEsquerdo === "8"
registration.object.acuidadeTriagemEsquerdo === "8"
) {
count = count + 2;
}
Expand All @@ -134,7 +135,7 @@ const Create = props => {
count = count + 5;
}
if (
registration.object.acuidadeTriagemDireito === "8"
registration.object.acuidadeTriagemDireito === "8"
) {
count = count + 2;
}
Expand All @@ -144,7 +145,7 @@ const Create = props => {
count = count + 2;
}
}

return count;
}

Expand All @@ -164,25 +165,37 @@ const Create = props => {
});
};

console.log(classroom)

return (
<>
<ArrowBack onClick={() => { history.goBack() }} style={{ cursor: "pointer" }} />
<h1>{data && data.name}</h1>
<h1>{classroom && classroom?.object?.name}</h1>
<h2>Alunos</h2>
<Padding padding="16px" />
<Grid
// className={classes.marginButtom}
container

direction="row"
style={{ marginBottom: "16px" }}
>
<Grid item md={2} sm={2}>
<Grid item md={3} sm={2}>
<ButtonPurple
className="t-button-primary"
onClick={() => history.push(`/turmas/${id}/pdf`)}
title={"Relatório de alunos"}
/>
</Grid>

<Padding />
<Grid item md={3} sm={2}>
<ButtonPurple
className="t-button-primary"
onClick={() => history.push(`/turmas/${id}/pdfreceita`)}
title={"Gerar receitas"}
/>
</Grid>
</Grid>
<Grid container direction="row" spacing={4}>
<List items={registrations()}>
Expand Down

0 comments on commit 5cfa853

Please sign in to comment.