Tabelle anpassen
This commit is contained in:
parent
487722333a
commit
6d0701f911
146
main.py
146
main.py
|
|
@ -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")
|
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()
|
||||||
|
|
||||||
# Button zum manuellen Hinzufügen einer leeren Position
|
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})
|
|
||||||
st.rerun()
|
|
||||||
|
|
||||||
edited_items = []
|
for idx, item in enumerate(data.get("items", [])):
|
||||||
|
with st.expander(f"📋 Position {idx+1}: {item.get('name', 'Dienstleistung')}", expanded=True):
|
||||||
|
|
||||||
# Jede Position bekommt eine eigene, vollflächige Karte (Expander)
|
c_del, _ = st.columns([1, 4])
|
||||||
for idx, item in enumerate(data.get("items", [])):
|
with c_del:
|
||||||
with st.expander(f"📋 Position {idx+1}: {item.get('name', 'Dienstleistung')}", expanded=True):
|
if st.button("🗑️ Position löschen", key=f"del_btn_{idx}"):
|
||||||
|
data["items"].pop(idx)
|
||||||
|
st.rerun()
|
||||||
|
|
||||||
# Löschen-Button für diese spezifische Position
|
c_name, c_desc = st.columns([1, 1])
|
||||||
c_del, _ = st.columns([1, 11])
|
with c_name:
|
||||||
with c_del:
|
item_name = st.text_input("Artikelname (BT-153)", value=item.get("name", ""), key=f"item_name_{idx}")
|
||||||
if st.button("🗑️ Position löschen", key=f"del_btn_{idx}"):
|
with c_desc:
|
||||||
data["items"].pop(idx)
|
item_description = st.text_area("Zusatzbeschreibung (BT-154)", value=item.get("description", ""), key=f"item_desc_{idx}", height=68)
|
||||||
st.rerun()
|
|
||||||
|
|
||||||
# Zeile 1: Name und Beschreibung nebeneinander (Beschreibung als echtes, umbrechendes Textfeld!)
|
c_qty, c_unit, c_price, c_total = st.columns(4)
|
||||||
c_name, c_desc = st.columns([1, 2])
|
with c_qty:
|
||||||
with c_name:
|
# 🔥 OPTIMIERUNG: Format auf %.1f gesetzt für genau eine Nachkommastelle
|
||||||
item_name = st.text_input("Artikelname (BT-153)", value=item.get("name", ""), key=f"item_name_{idx}")
|
item_quantity = st.number_input("Menge", value=float(item.get("quantity") or 0.0), format="%.1f", key=f"item_qty_{idx}")
|
||||||
with c_desc:
|
with c_unit:
|
||||||
item_description = st.text_area("Zusatzbeschreibung (BT-154)", value=item.get("description", ""), key=f"item_desc_{idx}", height=68)
|
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:
|
||||||
|
raw_item_total = item_quantity * item_price
|
||||||
|
item_total_amount = kaufmaennisches_runden(raw_item_total)
|
||||||
|
st.markdown("**Gesamt betrag (€):**")
|
||||||
|
st.markdown(f"**{item_total_amount:.2f} €**")
|
||||||
|
|
||||||
# Zeile 2: Numerische Werte sauber aufgeteilt
|
edited_items.append({
|
||||||
c_qty, c_unit, c_price, c_total = st.columns(4)
|
"name": item_name,
|
||||||
with c_qty:
|
"description": item_description,
|
||||||
item_quantity = st.number_input("Menge", value=float(item.get("quantity") or 0.0), format="%.4f", key=f"item_qty_{idx}")
|
"quantity": item_quantity,
|
||||||
with c_unit:
|
"unit": item_unit,
|
||||||
item_unit = st.text_input("Einheit", value=item.get("unit", "Stk."), key=f"item_unit_{idx}")
|
"unit_price": item_price,
|
||||||
with c_price:
|
"total_amount": item_total_amount
|
||||||
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
|
st.markdown("---")
|
||||||
edited_items.append({
|
vat_rate = st.number_input("Steuersatz (%)", value=float(data.get("vat_rate_percent") or 19.0))
|
||||||
"name": item_name,
|
|
||||||
"description": item_description,
|
|
||||||
"quantity": item_quantity,
|
|
||||||
"unit": item_unit,
|
|
||||||
"unit_price": item_price,
|
|
||||||
"total_amount": item_total_amount
|
|
||||||
})
|
|
||||||
|
|
||||||
st.markdown("---")
|
computed_net_amount = sum(item["total_amount"] for item in edited_items)
|
||||||
vat_rate = st.number_input("Steuersatz (%)", value=float(data.get("vat_rate_percent") or 19.0))
|
raw_vat_amount = computed_net_amount * (vat_rate / 100.0)
|
||||||
|
computed_vat_amount = kaufmaennisches_runden(raw_vat_amount)
|
||||||
|
computed_gross_amount = kaufmaennisches_runden(computed_net_amount + computed_vat_amount)
|
||||||
|
|
||||||
# Globale Summenberechnung
|
st.markdown("**Berechnete Summen:**")
|
||||||
computed_net_amount = sum(item["total_amount"] for item in edited_items)
|
c_net_ui, c_vat_ui, c_gross_ui = st.columns(3)
|
||||||
raw_vat_amount = computed_net_amount * (vat_rate / 100.0)
|
with c_net_ui: st.metric("Netto-Gesamt (€)", f"{computed_net_amount:.2f}")
|
||||||
computed_vat_amount = kaufmaennisches_runden(raw_vat_amount)
|
with c_vat_ui: st.metric("MwSt-Gesamt (€)", f"{computed_vat_amount:.2f}")
|
||||||
computed_gross_amount = kaufmaennisches_runden(computed_net_amount + computed_vat_amount)
|
with c_gross_ui: st.metric("Brutto-Zahlbetrag (€)", f"{computed_gross_amount:.2f}")
|
||||||
|
|
||||||
st.markdown("**Berechnete Summen:**")
|
st.markdown("---")
|
||||||
c_net_ui, c_vat_ui, c_gross_ui = st.columns(3)
|
if st.button("🔒 XRechnung exportieren", type="primary", width="stretch"):
|
||||||
with c_net_ui: st.metric("Netto-Gesamt (€)", f"{computed_net_amount:.2f}")
|
final_invoice_dict = {
|
||||||
with c_vat_ui: st.metric("MwSt-Gesamt (€)", f"{computed_vat_amount:.2f}")
|
"invoice_type_code": selected_type_code,
|
||||||
with c_gross_ui: st.metric("Brutto-Zahlbetrag (€)", f"{computed_gross_amount:.2f}")
|
"invoice_number": inv_num, "invoice_date": inv_date, "delivery_date": inv_delivery,
|
||||||
|
"buyer_reference": buyer_ref, "recipient_name": r_name, "recipient_email": r_email,
|
||||||
st.markdown("---")
|
"recipient_street": r_street, "recipient_zip": r_zip, "recipient_city": r_city,
|
||||||
if st.button("🔒 XRechnung exportieren", type="primary", width="stretch"):
|
"items": edited_items, "total_net_amount": computed_net_amount, "total_vat_amount": computed_vat_amount,
|
||||||
final_invoice_dict = {
|
"vat_rate_percent": vat_rate, "total_gross_amount": computed_gross_amount, "iban": "DE06120700240456207000",
|
||||||
"invoice_type_code": selected_type_code,
|
"delivery_note_id": dn_id,
|
||||||
"invoice_number": inv_num, "invoice_date": inv_date, "delivery_date": inv_delivery,
|
"order_id": o_id,
|
||||||
"buyer_reference": buyer_ref, "recipient_name": r_name, "recipient_email": r_email,
|
"contract_id": c_id,
|
||||||
"recipient_street": r_street, "recipient_zip": r_zip, "recipient_city": r_city,
|
"service_start_date": s_start,
|
||||||
"items": edited_items, "total_net_amount": computed_net_amount, "total_vat_amount": computed_vat_amount,
|
"service_end_date": s_end,
|
||||||
"vat_rate_percent": vat_rate, "total_gross_amount": computed_gross_amount, "iban": "DE06120700240456207000",
|
"invoice_note": i_note
|
||||||
"delivery_note_id": dn_id,
|
}
|
||||||
"order_id": o_id,
|
st.download_button(label="📥 Download XML", data=generate_compliant_xrechnung(final_invoice_dict), file_name=f"XRechnung_{inv_num}.xml", mime="text/xml")
|
||||||
"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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue