Tabelle anpassen

This commit is contained in:
dfuhrmann3 2026-07-03 10:22:56 +02:00
parent 487722333a
commit 6d0701f911
1 changed files with 74 additions and 86 deletions

160
main.py
View File

@ -502,96 +502,84 @@ with col2:
r_zip = st.text_input("PLZ (Kunde)", value=data.get("recipient_zip", "")) r_zip = st.text_input("PLZ (Kunde)", value=data.get("recipient_zip", ""))
r_city = st.text_input("Stadt (Kunde)", value=data.get("recipient_city", "")) r_city = st.text_input("Stadt (Kunde)", value=data.get("recipient_city", ""))
# ========================================== # 🔥 NEU: Die Positionen-Karten befinden sich ab jetzt genau hier innerhalb von Spalte 2!
# 6. MODULARES POSITIONEN-FRONTEND (VOLLBREITE OHNE TRUNCATION) st.markdown("### 3. Positionen")
# ==========================================
if st.session_state.extracted_data:
data = st.session_state.extracted_data
st.markdown("### 3. Positionen")
# Button zum manuellen Hinzufügen einer leeren Position
if st.button("➕ Neue Position hinzufügen"):
data["items"].append({"name": "Neue Dienstleistung", "description": "", "quantity": 1.0, "unit": "Stk.", "unit_price": 0.0})
st.rerun()
edited_items = [] if st.button("➕ Neue Position hinzufügen"):
data["items"].append({"name": "Neue Dienstleistung", "description": "", "quantity": 1.0, "unit": "Stk.", "unit_price": 0.0})
# Jede Position bekommt eine eigene, vollflächige Karte (Expander) st.rerun()
for idx, item in enumerate(data.get("items", [])):
with st.expander(f"📋 Position {idx+1}: {item.get('name', 'Dienstleistung')}", expanded=True):
# Löschen-Button für diese spezifische Position edited_items = []
c_del, _ = st.columns([1, 11])
with c_del: for idx, item in enumerate(data.get("items", [])):
if st.button("🗑️ Position löschen", key=f"del_btn_{idx}"): with st.expander(f"📋 Position {idx+1}: {item.get('name', 'Dienstleistung')}", expanded=True):
data["items"].pop(idx)
st.rerun()
# Zeile 1: Name und Beschreibung nebeneinander (Beschreibung als echtes, umbrechendes Textfeld!)
c_name, c_desc = st.columns([1, 2])
with c_name:
item_name = st.text_input("Artikelname (BT-153)", value=item.get("name", ""), key=f"item_name_{idx}")
with c_desc:
item_description = st.text_area("Zusatzbeschreibung (BT-154)", value=item.get("description", ""), key=f"item_desc_{idx}", height=68)
# Zeile 2: Numerische Werte sauber aufgeteilt c_del, _ = st.columns([1, 4])
c_qty, c_unit, c_price, c_total = st.columns(4) with c_del:
with c_qty: if st.button("🗑️ Position löschen", key=f"del_btn_{idx}"):
item_quantity = st.number_input("Menge", value=float(item.get("quantity") or 0.0), format="%.4f", key=f"item_qty_{idx}") data["items"].pop(idx)
with c_unit: st.rerun()
item_unit = st.text_input("Einheit", value=item.get("unit", "Stk."), key=f"item_unit_{idx}")
with c_price:
item_price = st.number_input("Einzelpreis (€)", value=float(item.get("unit_price") or 0.0), format="%.2f", key=f"item_price_{idx}")
with c_total:
# Automatische Live-Berechnung des Zeilen-Gesamtwerts
raw_item_total = item_quantity * item_price
item_total_amount = kaufmaennisches_runden(raw_item_total)
st.markdown("**Gesamtbetrag (€):**")
st.markdown(f"#### {item_total_amount:.2f} €")
# Speichert den editierten Zustand dieses Blocks ab c_name, c_desc = st.columns([1, 1])
edited_items.append({ with c_name:
"name": item_name, item_name = st.text_input("Artikelname (BT-153)", value=item.get("name", ""), key=f"item_name_{idx}")
"description": item_description, with c_desc:
"quantity": item_quantity, item_description = st.text_area("Zusatzbeschreibung (BT-154)", value=item.get("description", ""), key=f"item_desc_{idx}", height=68)
"unit": item_unit,
"unit_price": item_price, c_qty, c_unit, c_price, c_total = st.columns(4)
"total_amount": item_total_amount with c_qty:
}) # 🔥 OPTIMIERUNG: Format auf %.1f gesetzt für genau eine Nachkommastelle
item_quantity = st.number_input("Menge", value=float(item.get("quantity") or 0.0), format="%.1f", key=f"item_qty_{idx}")
st.markdown("---") with c_unit:
vat_rate = st.number_input("Steuersatz (%)", value=float(data.get("vat_rate_percent") or 19.0)) item_unit = st.text_input("Einheit", value=item.get("unit", "Stk."), key=f"item_unit_{idx}")
with c_price:
# Globale Summenberechnung item_price = st.number_input("Einzelpreis (€)", value=float(item.get("unit_price") or 0.0), format="%.2f", key=f"item_price_{idx}")
computed_net_amount = sum(item["total_amount"] for item in edited_items) with c_total:
raw_vat_amount = computed_net_amount * (vat_rate / 100.0) raw_item_total = item_quantity * item_price
computed_vat_amount = kaufmaennisches_runden(raw_vat_amount) item_total_amount = kaufmaennisches_runden(raw_item_total)
computed_gross_amount = kaufmaennisches_runden(computed_net_amount + computed_vat_amount) st.markdown("**Gesamt betrag (€):**")
st.markdown(f"**{item_total_amount:.2f} €**")
st.markdown("**Berechnete Summen:**")
c_net_ui, c_vat_ui, c_gross_ui = st.columns(3) edited_items.append({
with c_net_ui: st.metric("Netto-Gesamt (€)", f"{computed_net_amount:.2f}") "name": item_name,
with c_vat_ui: st.metric("MwSt-Gesamt (€)", f"{computed_vat_amount:.2f}") "description": item_description,
with c_gross_ui: st.metric("Brutto-Zahlbetrag (€)", f"{computed_gross_amount:.2f}") "quantity": item_quantity,
"unit": item_unit,
st.markdown("---") "unit_price": item_price,
if st.button("🔒 XRechnung exportieren", type="primary", width="stretch"): "total_amount": item_total_amount
final_invoice_dict = { })
"invoice_type_code": selected_type_code,
"invoice_number": inv_num, "invoice_date": inv_date, "delivery_date": inv_delivery, st.markdown("---")
"buyer_reference": buyer_ref, "recipient_name": r_name, "recipient_email": r_email, vat_rate = st.number_input("Steuersatz (%)", value=float(data.get("vat_rate_percent") or 19.0))
"recipient_street": r_street, "recipient_zip": r_zip, "recipient_city": r_city,
"items": edited_items, "total_net_amount": computed_net_amount, "total_vat_amount": computed_vat_amount, computed_net_amount = sum(item["total_amount"] for item in edited_items)
"vat_rate_percent": vat_rate, "total_gross_amount": computed_gross_amount, "iban": "DE06120700240456207000", raw_vat_amount = computed_net_amount * (vat_rate / 100.0)
"delivery_note_id": dn_id, computed_vat_amount = kaufmaennisches_runden(raw_vat_amount)
"order_id": o_id, computed_gross_amount = kaufmaennisches_runden(computed_net_amount + computed_vat_amount)
"contract_id": c_id,
"service_start_date": s_start, st.markdown("**Berechnete Summen:**")
"service_end_date": s_end, c_net_ui, c_vat_ui, c_gross_ui = st.columns(3)
"invoice_note": i_note with c_net_ui: st.metric("Netto-Gesamt (€)", f"{computed_net_amount:.2f}")
} with c_vat_ui: st.metric("MwSt-Gesamt (€)", f"{computed_vat_amount:.2f}")
st.download_button(label="📥 Download XML", data=generate_compliant_xrechnung(final_invoice_dict), file_name=f"XRechnung_{inv_num}.xml", mime="text/xml") with c_gross_ui: st.metric("Brutto-Zahlbetrag (€)", f"{computed_gross_amount:.2f}")
st.markdown("---")
if st.button("🔒 XRechnung exportieren", type="primary", width="stretch"):
final_invoice_dict = {
"invoice_type_code": selected_type_code,
"invoice_number": inv_num, "invoice_date": inv_date, "delivery_date": inv_delivery,
"buyer_reference": buyer_ref, "recipient_name": r_name, "recipient_email": r_email,
"recipient_street": r_street, "recipient_zip": r_zip, "recipient_city": r_city,
"items": edited_items, "total_net_amount": computed_net_amount, "total_vat_amount": computed_vat_amount,
"vat_rate_percent": vat_rate, "total_gross_amount": computed_gross_amount, "iban": "DE06120700240456207000",
"delivery_note_id": dn_id,
"order_id": o_id,
"contract_id": c_id,
"service_start_date": s_start,
"service_end_date": s_end,
"invoice_note": i_note
}
st.download_button(label="📥 Download XML", data=generate_compliant_xrechnung(final_invoice_dict), file_name=f"XRechnung_{inv_num}.xml", mime="text/xml")
# ========================================== # ==========================================
# DYNAMISCHER FOOTER # DYNAMISCHER FOOTER