Update cemento.py

This commit is contained in:
2026-01-20 15:01:37 +01:00
parent 6a9c4233e2
commit 34dec1e646

View File

@@ -54,19 +54,24 @@ def index():
def esegui_stampa_cups(f): def esegui_stampa_cups(f):
try: try:
# Generazione report per CUPS (PDF)
ps_content = f"""%!PS ps_content = f"""%!PS
/Helvetica-Bold findfont 16 scalefont setfont /Helvetica-Bold findfont 12 scalefont setfont
70 750 moveto (REPORT TECNICO CALCOLO CEMENTO) show 70 750 moveto (Volume: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg) show
/Helvetica findfont 11 scalefont setfont 70 735 moveto (ACQUISTI) show
70 720 moveto (Volume: {f.get('res_vol')} m3 | Peso: {f.get('res_peso')} Kg) show /Helvetica findfont 12 scalefont setfont
70 690 moveto (ACQUISTI:) show 70 720 moveto (o Cemento: {f.get('res_s_cem')} sacchetti) show
80 675 moveto (- Cemento: {f.get('res_s_cem')} sacchetti) show 70 705 moveto (o Sabbia: {f.get('res_s_sab')} sacchetti) show
80 660 moveto (- Sabbia: {f.get('res_s_sab')} sacchetti) show 70 690 moveto (o Ghiaia: {f.get('res_s_ghi')} sacchetti) show
80 645 moveto (- 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
70 620 moveto (COSTO TOTALE: {f.get('res_costo_t')} Euro) show /Helvetica-Bold findfont 12 scalefont setfont
70 590 moveto (DOSAGGIO CARICO ({f.get('res_nc')} carichi):) show 70 655 moveto (COSTO TOTALE: {f.get('res_costo_t')} Euro) show
80 575 moveto (- Cemento: {f.get('res_bc_cem')} | Sabbia: {f.get('res_bc_sab')}) show 70 635 moveto (PER OGNI CARICO ({f.get('res_nc')} CARICHI):) show
80 560 moveto (- Ghiaia: {f.get('res_bc_ghi')} | Acqua: {f.get('res_bc_aq')} L) 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""" showpage"""
comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"] comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"]
subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True) subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True)
@@ -76,8 +81,22 @@ showpage"""
@app.route('/download', methods=['POST']) @app.route('/download', methods=['POST'])
def download(): def download():
f = request.form f = request.form
report = f"REPORT TECNICO\nVolume: {f.get('res_vol')} m3\nCosto: {f.get('res_costo_t')} EUR" # Struttura report TXT identica alla richiesta
return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report.txt"}) 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__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000) app.run(host='0.0.0.0', port=5000)