From 34dec1e64611560110daf54ae3c85d2f0214440f Mon Sep 17 00:00:00 2001 From: francesco Date: Tue, 20 Jan 2026 15:01:37 +0100 Subject: [PATCH] Update cemento.py --- cemento.py | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/cemento.py b/cemento.py index e554c7f..547c37f 100644 --- a/cemento.py +++ b/cemento.py @@ -54,19 +54,24 @@ def index(): def esegui_stampa_cups(f): try: + # Generazione report per CUPS (PDF) ps_content = f"""%!PS -/Helvetica-Bold findfont 16 scalefont setfont -70 750 moveto (REPORT TECNICO CALCOLO CEMENTO) show -/Helvetica findfont 11 scalefont setfont -70 720 moveto (Volume: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg) show -70 690 moveto (ACQUISTI:) show -80 675 moveto (- Cemento: {f.get('res_s_cem')} sacchetti) show -80 660 moveto (- Sabbia: {f.get('res_s_sab')} sacchetti) show -80 645 moveto (- Ghiaia: {f.get('res_s_ghi')} sacchetti) show -70 620 moveto (COSTO TOTALE: {f.get('res_costo_t')} Euro) show -70 590 moveto (DOSAGGIO CARICO ({f.get('res_nc')} carichi):) show -80 575 moveto (- Cemento: {f.get('res_bc_cem')} | Sabbia: {f.get('res_bc_sab')}) show -80 560 moveto (- Ghiaia: {f.get('res_bc_ghi')} | Acqua: {f.get('res_bc_aq')} L) show +/Helvetica-Bold findfont 12 scalefont setfont +70 750 moveto (Volume: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg) show +70 735 moveto (ACQUISTI) show +/Helvetica findfont 12 scalefont setfont +70 720 moveto (o Cemento: {f.get('res_s_cem')} sacchetti) show +70 705 moveto (o Sabbia: {f.get('res_s_sab')} sacchetti) show +70 690 moveto (o Ghiaia: {f.get('res_s_ghi')} sacchetti) show +70 675 moveto (o Acqua: {f.get('res_aq')} L | Totale: {f.get('res_tot_s')} sacch.) show +/Helvetica-Bold findfont 12 scalefont setfont +70 655 moveto (COSTO TOTALE: {f.get('res_costo_t')} Euro) show +70 635 moveto (PER OGNI CARICO ({f.get('res_nc')} CARICHI):) show +/Helvetica findfont 12 scalefont setfont +70 620 moveto (o Cemento: {f.get('res_bc_cem')} sacchetti) show +70 605 moveto (o Sabbia: {f.get('res_bc_sab')} sacchetti) show +70 590 moveto (o Ghiaia: {f.get('res_bc_ghi')} sacchetti) show +70 575 moveto (o Acqua: {f.get('res_bc_aq')} L) show showpage""" comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"] subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True) @@ -76,8 +81,22 @@ showpage""" @app.route('/download', methods=['POST']) def download(): f = request.form - report = f"REPORT TECNICO\nVolume: {f.get('res_vol')} m3\nCosto: {f.get('res_costo_t')} EUR" - return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report.txt"}) + # Struttura report TXT identica alla richiesta + report = ( + f"Volume: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg\n" + f"ACQUISTI\n" + f"• Cemento: {f.get('res_s_cem')} sacchetti\n" + f"• Sabbia: {f.get('res_s_sab')} sacchetti\n" + f"• Ghiaia: {f.get('res_s_ghi')} sacchetti\n" + f"• Acqua: {f.get('res_aq')} L | Totale: {f.get('res_tot_s')} sacch.\n" + f"COSTO TOTALE: {f.get('res_costo_t')} €\n" + f"PER OGNI CARICO ({f.get('res_nc')} CARICHI):\n" + f"• Cemento: {f.get('res_bc_cem')} sacchetti\n" + f"• Sabbia: {f.get('res_bc_sab')} sacchetti\n" + f"• Ghiaia: {f.get('res_bc_ghi')} sacchetti\n" + f"• Acqua: {f.get('res_bc_aq')} L" + ) + return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report_V1_2.txt"}) if __name__ == '__main__': app.run(host='0.0.0.0', port=5000) \ No newline at end of file