diff --git a/services/manso/src/index.js b/services/manso/src/index.js
index f9d5f48..b093dee 100644
--- a/services/manso/src/index.js
+++ b/services/manso/src/index.js
@@ -661,25 +661,78 @@ app.post('/api/rpc/asistencia_delete_raw', async (req, res) => {
}
});
-app.post('/api/rpc/report_asistencia', async (req,res)=>{
- const {desde, hasta} = req.body||{};
- const sql = 'SELECT * FROM public.report_asistencia($1::date,$2::date)';
- const {rows} = await pool.query(sql,[desde, hasta]);
- res.json(rows);
-});
-
+// POST /api/rpc/report_tickets { year }
app.post('/api/rpc/report_tickets', async (req, res) => {
try {
- const { year } = req.body || {};
- const sql = 'SELECT public.report_tickets_year($1::int) AS data';
- const { rows } = await pool.query(sql, [year]);
- res.json(rows[0]?.data || {});
+ const y = parseInt(req.body?.year ?? req.query?.year, 10);
+ const year = (Number.isFinite(y) && y >= 2000 && y <= 2100)
+ ? y
+ : (new Date()).getFullYear();
+
+ const { rows } = await pool.query(
+ 'SELECT public.report_tickets_year($1::int) AS j', [year]
+ );
+ res.json(rows[0].j);
} catch (e) {
- console.error(e);
- res.status(500).json({ error: 'report_tickets failed' });
+ console.error('report_tickets error:', e);
+ res.status(500).json({
+ error: 'report_tickets failed',
+ message: e.message, detail: e.detail, where: e.where, code: e.code
+ });
}
});
+// POST /api/rpc/report_asistencia { desde: 'YYYY-MM-DD', hasta: 'YYYY-MM-DD' }
+app.post('/api/rpc/report_asistencia', async (req, res) => {
+ try {
+ let { desde, hasta } = req.body || {};
+ // defaults si vienen vacíos/invalidos
+ const re = /^\d{4}-\d{2}-\d{2}$/;
+ if (!re.test(desde) || !re.test(hasta)) {
+ const end = new Date();
+ const start = new Date(end); start.setDate(end.getDate()-30);
+ desde = start.toISOString().slice(0,10);
+ hasta = end.toISOString().slice(0,10);
+ }
+
+ const { rows } = await pool.query(
+ 'SELECT public.report_asistencia($1::date,$2::date) AS j', [desde, hasta]
+ );
+ res.json(rows[0].j);
+ } catch (e) {
+ console.error('report_asistencia error:', e);
+ res.status(500).json({
+ error: 'report_asistencia failed',
+ message: e.message, detail: e.detail, where: e.where, code: e.code
+ });
+ }
+});
+
+
+// app.post('/api/rpc/report_asistencia', async (req,res)=>{
+// try{
+// const {desde, hasta} = req.body||{};
+// const sql = 'SELECT * FROM public.report_asistencia($1::date,$2::date)';
+// const {rows} = await pool.query(sql,[desde, hasta]);
+// res.json(rows);
+// } catch (e) {
+// console.error(e);
+// res.status(500).json({ error: 'report_tickets failed' + e });
+// }
+// });
+
+// app.post('/api/rpc/report_tickets', async (req, res) => {
+// try {
+// const { year } = req.body || {};
+// const sql = 'SELECT public.report_tickets_year($1::int) AS data';
+// const { rows } = await pool.query(sql, [year]);
+// res.json(rows[0]?.data || {});
+// } catch (e) {
+// console.error(e);
+// res.status(500).json({ error: 'report_tickets failed' + e });
+// }
+// });
+
// Guardar (insert/update)
app.post('/api/rpc/save_compra', async (req, res) => {
diff --git a/services/manso/src/views/reportes.ejs b/services/manso/src/views/reportes.ejs
index 0716a16..7d9feb7 100644
--- a/services/manso/src/views/reportes.ejs
+++ b/services/manso/src/views/reportes.ejs
@@ -42,26 +42,17 @@
-
-
-
-
+
-
-
-
-
-
-
Total: —
-
Compras: —
-
Renglones: —
+
-
-
-
-
-
-
-
-
-
- | Fecha |
- Proveedor |
- Tipo |
- Ítem |
- Cantidad |
- Precio |
- Subtotal |
-
-
-
- | Sin datos |
-
-
+
+
+
+
+ Total: —
+ Compras: —
+ Renglones: —
+ —
+
+
+
+
+
-
+
@@ -201,27 +222,84 @@
\ No newline at end of file