david-rosval commited on
Commit
c7195b2
·
1 Parent(s): 0c8d1c4

boleta terminado, posiblemente corrija prescripcion

Browse files
src/App.jsx CHANGED
@@ -58,6 +58,7 @@ export default function App() {
58
  setMonturas={setMonturas}
59
  setPrecioTotal={setPrecioTotal}
60
  setPrescripcion={setPrescripcion}
 
61
  />
62
  }
63
  />
 
58
  setMonturas={setMonturas}
59
  setPrecioTotal={setPrecioTotal}
60
  setPrescripcion={setPrescripcion}
61
+ prescripcion={prescripcion}
62
  />
63
  }
64
  />
src/Carrito.jsx CHANGED
@@ -2,24 +2,39 @@ import React, { useEffect, useState } from 'react'
2
  import { CarritoItem } from './components/CarritoItem'
3
  import { actualizarPut, cargarApi, obtenerEspecifico, registrarPost, obtenerGet } from "./lib/conexionApi";
4
  import ModalBoleta from './components/ModalBoleta';
 
5
 
6
  export const Carrito = ({setCarrito, carrito, precioTotal, setPrecioTotal, fecha, prescripcion}) => {
7
 
8
  const [modalBoleta, setModalBoleta] = useState(false)
9
  const [adelanto, setAdelanto] = useState('')
 
 
 
10
 
11
  useEffect(() => {
12
  setPrecioTotal(carrito.reduce((total, carritoItem) => total + (carritoItem["cantidad"]*carritoItem["monturaInventario"]["precio_unit"]), 0))
13
  }, [])
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  return (
16
  <div className='w-3/5'>
17
  <div className='flex justify-between'>
18
  <h1 className="my-10 text-4xl font-semibold text-center">Carrito de compras</h1>
19
 
20
- <button className='bg-slate-700 text-white my-8 rounded-lg hover:bg-slate-800 uppercase text-xl font-semibold px-5' onClick={()=>{
21
- setModalBoleta(true)
22
- }}>
23
  Continuar S/. {precioTotal}
24
  </button>
25
  </div>
@@ -27,6 +42,7 @@ export const Carrito = ({setCarrito, carrito, precioTotal, setPrecioTotal, fecha
27
  {(carrito.length > 0) && carrito.map((item) => {
28
  return <CarritoItem key={item["monturaInventario"]["codigo"]} carritoItem={item} setCarrito={setCarrito} precioTotal={precioTotal} setPrecioTotal={setPrecioTotal} carrito={carrito} />
29
  })}
 
30
  </div>
31
  <div className='flex justify-end mt-10 items-center'>
32
  <label htmlFor="input-buscar-cliente" className='mr-2 font-semibold'>Adelanto: S/.</label>
@@ -42,9 +58,10 @@ export const Carrito = ({setCarrito, carrito, precioTotal, setPrecioTotal, fecha
42
  />
43
  </div>
44
  {(modalBoleta && precioTotal !== 0) && (
45
- <ModalBoleta fecha={fecha} setModalBoleta={setModalBoleta} precioTotal={precioTotal} carrito={carrito} prescripcion={prescripcion} adelanto={adelanto} />
46
  )}
47
-
 
48
  </div>
49
  )
50
  }
 
2
  import { CarritoItem } from './components/CarritoItem'
3
  import { actualizarPut, cargarApi, obtenerEspecifico, registrarPost, obtenerGet } from "./lib/conexionApi";
4
  import ModalBoleta from './components/ModalBoleta';
5
+ import {CarritoItemLunas} from './components/CarritoItemLunas';
6
 
7
  export const Carrito = ({setCarrito, carrito, precioTotal, setPrecioTotal, fecha, prescripcion}) => {
8
 
9
  const [modalBoleta, setModalBoleta] = useState(false)
10
  const [adelanto, setAdelanto] = useState('')
11
+ const [precioLunas, setPrecioLunas] = useState('')
12
+ const [error, setError] = useState('')
13
+ const [errorPrecioLuna, setErrorPrecioLuna] = useState('')
14
 
15
  useEffect(() => {
16
  setPrecioTotal(carrito.reduce((total, carritoItem) => total + (carritoItem["cantidad"]*carritoItem["monturaInventario"]["precio_unit"]), 0))
17
  }, [])
18
 
19
+ const handleContinuarClick = () => {
20
+ if (adelanto === '' || precioLunas === '') {
21
+ setError('todos los campos son obligatorios')
22
+ } else if (isNaN(parseFloat(adelanto)) || isNaN(parseFloat(precioLunas))) {
23
+ setError('Ingresar campos válidos')
24
+ } else {
25
+ setModalBoleta(true)
26
+ setError('')
27
+ setErrorPrecioLuna('')
28
+ }
29
+
30
+ }
31
+
32
  return (
33
  <div className='w-3/5'>
34
  <div className='flex justify-between'>
35
  <h1 className="my-10 text-4xl font-semibold text-center">Carrito de compras</h1>
36
 
37
+ <button className='bg-slate-700 text-white my-8 rounded-lg hover:bg-slate-800 uppercase text-xl font-semibold px-5' onClick={handleContinuarClick}>
 
 
38
  Continuar S/. {precioTotal}
39
  </button>
40
  </div>
 
42
  {(carrito.length > 0) && carrito.map((item) => {
43
  return <CarritoItem key={item["monturaInventario"]["codigo"]} carritoItem={item} setCarrito={setCarrito} precioTotal={precioTotal} setPrecioTotal={setPrecioTotal} carrito={carrito} />
44
  })}
45
+ <CarritoItemLunas prescripcion={prescripcion} precioLunas={precioLunas} setPrecioLunas={setPrecioLunas} setPrecioTotal={setPrecioTotal} precioTotal={precioTotal} />
46
  </div>
47
  <div className='flex justify-end mt-10 items-center'>
48
  <label htmlFor="input-buscar-cliente" className='mr-2 font-semibold'>Adelanto: S/.</label>
 
58
  />
59
  </div>
60
  {(modalBoleta && precioTotal !== 0) && (
61
+ <ModalBoleta fecha={fecha} setModalBoleta={setModalBoleta} precioTotal={precioTotal+parseFloat(precioLunas)} carrito={carrito} prescripcion={prescripcion} adelanto={adelanto} precioLunas={precioLunas} />
62
  )}
63
+ {errorPrecioLuna && <p className="text-red-500 text-xl">{errorPrecioLuna}</p>}
64
+ {error && <p className="text-red-500 text-xl">{error}</p>}
65
  </div>
66
  )
67
  }
src/Catalogo.jsx CHANGED
@@ -6,11 +6,12 @@ import {
6
  obtenerEspecifico,
7
  registrarPost,
8
  obtenerGet,
 
9
  } from "./lib/conexionApi";
10
  import ModalVerCarrito from "./components/ModalVerCarrito";
11
  import { Navigate } from "react-router";
12
 
13
- export const Catalogo = ({ setCarrito, carrito, monturas, setMonturas, setPrecioTotal, setPrescripcion }) => {
14
  // Se obtienen primero los detalles de cada montura
15
 
16
  // se obtienen los datos de precio, stock y código
@@ -31,7 +32,9 @@ export const Catalogo = ({ setCarrito, carrito, monturas, setMonturas, setPrecio
31
 
32
  const [irAlCarrito, setIrAlCarrito] = useState(false)
33
 
34
- // obtener detalle de monturas
 
 
35
 
36
  // obtener catalogo de monturas
37
  useEffect(() => {
@@ -43,7 +46,11 @@ export const Catalogo = ({ setCarrito, carrito, monturas, setMonturas, setPrecio
43
  }, []);
44
 
45
  useEffect(() => {
46
- obtenerGet("prescripciones/ultimoregistro", setPrescripcion, setsetErrorUltimaPrescripcion);
 
 
 
 
47
  }, []);
48
 
49
 
 
6
  obtenerEspecifico,
7
  registrarPost,
8
  obtenerGet,
9
+ prescripcionPdff,
10
  } from "./lib/conexionApi";
11
  import ModalVerCarrito from "./components/ModalVerCarrito";
12
  import { Navigate } from "react-router";
13
 
14
+ export const Catalogo = ({ setCarrito, carrito, monturas, setMonturas, setPrecioTotal, setPrescripcion, prescripcion }) => {
15
  // Se obtienen primero los detalles de cada montura
16
 
17
  // se obtienen los datos de precio, stock y código
 
32
 
33
  const [irAlCarrito, setIrAlCarrito] = useState(false)
34
 
35
+ useEffect(() => {
36
+
37
+ }, []);
38
 
39
  // obtener catalogo de monturas
40
  useEffect(() => {
 
46
  }, []);
47
 
48
  useEffect(() => {
49
+ const pdfPrescripcion = async () => {
50
+ await obtenerGet("prescripciones/ultimoregistro", setPrescripcion, setsetErrorUltimaPrescripcion);
51
+ await prescripcionPdff(prescripcion[0]["id_prescripcion"])
52
+ }
53
+ pdfPrescripcion()
54
  }, []);
55
 
56
 
src/assets/lunas.jpg ADDED
src/assets/lunas.webp ADDED
src/components/CarritoItemLunas.jsx ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from 'react'
2
+ // cantidad 1 prescripcion[0]["detalle_lunas"] input precio precio*cantidad
3
+ export const CarritoItemLunas = ({ prescripcion, precioLunas, setPrecioLunas, setPrecioTotal, precioTotal }) => {
4
+ return (
5
+ <div className="w-full p-10 flex justify-between items-center border-b border-black">
6
+ <div className="">
7
+ <img width={200} src="../src/assets/lunas.jpg" alt="lunas" border="0" />
8
+ </div>
9
+ <div className="block w-[350px]">
10
+ <p className="truncate text-xl ">
11
+ Detalle de lunas: <span className='font-semibold uppercase'>{prescripcion[0]["detalle_lunas"] }</span>
12
+ </p>
13
+ </div>
14
+
15
+ <div className="flex">
16
+ <button
17
+ className="bg-gray-200 h-8 w-8 text-lg hover:bg-gray-300 disabled:cursor-default disabled:text-gray-400 disabled:hover:bg-gray-200"
18
+ onClick={() => {
19
+
20
+ }}
21
+ disabled={true}
22
+ >
23
+ -
24
+ </button>
25
+ <p className="mx-2 h-8 w-10 text-center">{1}</p>
26
+ <button
27
+ className="bg-gray-200 h-8 w-8 text-lg hover:bg-gray-300 disabled:cursor-default disabled:text-gray-400 disabled:hover:bg-gray-200"
28
+ onClick={() => {
29
+
30
+ }}
31
+ disabled={true}
32
+ >
33
+ +
34
+ </button>
35
+ </div>
36
+ <div className="w-[80px] flex items-end">
37
+ <p className='text-sm'>S/.</p>
38
+ <input className='text-2xl border w-20 text-center ml-2' type="text" placeholder='00.00' value={precioLunas} onChange={e => {
39
+ setPrecioLunas(e.target.value)
40
+ //setPrecioTotal(pre)
41
+ }} />
42
+
43
+
44
+ </div>
45
+
46
+ </div>
47
+ )
48
+ }
src/components/ModalBoleta.jsx CHANGED
@@ -1,7 +1,7 @@
1
  import React, { useEffect, useState } from "react";
2
  import { obtenerEspecifico, obtenerGet, procesarBoleta, registrarPost } from "../lib/conexionApi";
3
 
4
- const ModalBoleta = ({ fecha, setModalBoleta, precioTotal, carrito, prescripcion, adelanto }) => {
5
 
6
  const [clienteBoleta, setClienteBoleta] = useState({})
7
  const [errorClienteBoleta, setErrorClienteBoleta] = useState(false)
@@ -72,6 +72,12 @@ const ModalBoleta = ({ fecha, setModalBoleta, precioTotal, carrito, prescripcion
72
  </tr>
73
  )
74
  })}
 
 
 
 
 
 
75
  </tbody>
76
  </table>
77
  </div>
@@ -97,8 +103,9 @@ const ModalBoleta = ({ fecha, setModalBoleta, precioTotal, carrito, prescripcion
97
  <button
98
  type="submit"
99
  className="w-1/2 mt-2 cursor-pointer py-2 bg-slate-700 hover:bg-slate-800 text-white font-semibold text-center rounded-md "
100
- onClick={(e) => {
101
- procesarBoleta(precioTotal, carrito)
 
102
  }}
103
  >
104
 
 
1
  import React, { useEffect, useState } from "react";
2
  import { obtenerEspecifico, obtenerGet, procesarBoleta, registrarPost } from "../lib/conexionApi";
3
 
4
+ const ModalBoleta = ({ fecha, setModalBoleta, precioTotal, carrito, prescripcion, adelanto, precioLunas }) => {
5
 
6
  const [clienteBoleta, setClienteBoleta] = useState({})
7
  const [errorClienteBoleta, setErrorClienteBoleta] = useState(false)
 
72
  </tr>
73
  )
74
  })}
75
+ <tr>
76
+ <td className="border">{1}</td>
77
+ <td className="border">detalle de lunas: {prescripcion[0]["detalle_lunas"]}</td>
78
+ <td className="border">S/.{parseFloat(precioLunas)}</td>
79
+ <td className="border">S/.{1*parseFloat(precioLunas)}</td>
80
+ </tr>
81
  </tbody>
82
  </table>
83
  </div>
 
103
  <button
104
  type="submit"
105
  className="w-1/2 mt-2 cursor-pointer py-2 bg-slate-700 hover:bg-slate-800 text-white font-semibold text-center rounded-md "
106
+ onClick={async (e) => {
107
+ procesarBoleta(precioTotal, carrito, adelanto, prescripcion[0]["id_prescripcion"], prescripcion[0]["detalle_lunas"], precioLunas );
108
+
109
  }}
110
  >
111
 
src/lib/conexionApi.js CHANGED
@@ -67,7 +67,7 @@ export const emitirPdfPrescripcion = (idPrescripcion) => {
67
  return urlPdf
68
  }
69
 
70
- export const procesarBoleta = async (precioTotal, carrito) => {
71
  const responseRegistrarBoleta = await fetch(`${url}/boletas`, {
72
  method: 'POST',
73
  body: JSON.stringify({
@@ -104,4 +104,29 @@ export const procesarBoleta = async (precioTotal, carrito) => {
104
  const resMonturasPedidos = await responseMonturasPedidos.json()
105
  console.log(resMonturasPedidos)
106
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  }
 
67
  return urlPdf
68
  }
69
 
70
+ export const procesarBoleta = async (precioTotal, carrito, adelanto, idprescripcion, descripcion, precioLunas) => {
71
  const responseRegistrarBoleta = await fetch(`${url}/boletas`, {
72
  method: 'POST',
73
  body: JSON.stringify({
 
104
  const resMonturasPedidos = await responseMonturasPedidos.json()
105
  console.log(resMonturasPedidos)
106
  })
107
+
108
+ const lunasPedido = await fetch(`${url}/lunas_pedido`, {
109
+ method: 'POST',
110
+ body: JSON.stringify({
111
+ "id_prescripcion": idprescripcion,
112
+ "precio": parseFloat(precioLunas),
113
+ "id_boleta": responseBoleta["id_boleta"] ,
114
+ "descripcion": descripcion,
115
+ "cantidad": 1
116
+ }),
117
+ headers: {
118
+ 'Content-type': 'application/json'
119
+ }
120
+ })
121
+ const resLunasPedido = await lunasPedido.json()
122
+ console.log(resLunasPedido);
123
+
124
+ const responsePDF = await fetch(`${url}/boleta/descargarPDF/${responseBoleta["id_boleta"]}/${adelanto}`)
125
+
126
+ window.open(responsePDF.url, "_blank");
127
+ }
128
+
129
+ export const prescripcionPdff = async (idPrescripcion) => {
130
+ const responsePDF = await fetch(`${url}/prescripcion/pdf/${idPrescripcion}`)
131
+ window.open(responsePDF.url, "_blank");
132
  }