diff --git a/frontend/pages/createDocument/edit/[[id]].vue b/frontend/pages/createDocument/edit/[[id]].vue
index 4e0e7da..e91e09a 100644
--- a/frontend/pages/createDocument/edit/[[id]].vue
+++ b/frontend/pages/createDocument/edit/[[id]].vue
@@ -224,6 +224,33 @@ const availableSepaMandates = computed(() => {
})
})
+const getSelectedSepaMandate = () => {
+ return availableSepaMandates.value.find((mandate) => mandate.id === itemInfo.value.outgoingsepamandate) || null
+}
+
+const mapContractPaymentType = (paymentType) => {
+ if (paymentType === "Einzug") return "direct-debit"
+ if (paymentType === "Überweisung") return "transfer"
+ return null
+}
+
+const applyContractPaymentData = () => {
+ const selectedContract = contracts.value.find((contract) => contract.id === itemInfo.value.contract)
+ if (!selectedContract) return
+
+ const mappedPaymentType = mapContractPaymentType(selectedContract.paymentType)
+ if (mappedPaymentType) {
+ itemInfo.value.payment_type = mappedPaymentType
+ }
+
+ const contractMandateId = selectedContract.outgoingsepamandate?.id || selectedContract.outgoingsepamandate
+ if (mappedPaymentType === "direct-debit" && contractMandateId) {
+ itemInfo.value.outgoingsepamandate = contractMandateId
+ } else if (mappedPaymentType === "transfer") {
+ itemInfo.value.outgoingsepamandate = null
+ }
+}
+
const applyDefaultSepaMandate = () => {
if (itemInfo.value.payment_type !== "direct-debit") {
itemInfo.value.outgoingsepamandate = null
@@ -246,6 +273,11 @@ const applyDefaultSepaMandate = () => {
itemInfo.value.outgoingsepamandate = defaultMandate?.id || null
}
+watch(
+ () => itemInfo.value.contract,
+ () => applyContractPaymentData()
+)
+
watch(
() => [itemInfo.value.customer, itemInfo.value.contract, itemInfo.value.payment_type, outgoingsepamandates.value.length],
() => applyDefaultSepaMandate()
@@ -2268,6 +2300,24 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
class="w-full"
/>
+
+
+
+ %
+
+
+
+
+
-
-
- {{ itemInfo.outgoingsepamandate ? availableSepaMandates.find(i => i.id === itemInfo.outgoingsepamandate)?.reference : "Kein Mandat ausgewählt" }}
-
-
- {{ mandate.reference }} - {{ mandate.bankaccount?.displayLabel || "Bankverbindung" }}
-
-
-
-
-
-
- %
-
-
+
+
+
+ {{ getSelectedSepaMandate()?.reference || "Kein Mandat ausgewählt" }}
+
+
+ {{ mandate.reference }} - {{ mandate.bankaccount?.displayLabel || "Bankverbindung" }}
+
+
+
+ itemInfo.outgoingsepamandate = data.id"
+ />
+
itemInfo.contract = data.id"
diff --git a/frontend/stores/data.js b/frontend/stores/data.js
index d3df3f9..128ba0a 100644
--- a/frontend/stores/data.js
+++ b/frontend/stores/data.js
@@ -957,10 +957,14 @@ export const useDataStore = defineStore('data', () => {
inputType: "select",
selectDataType: "outgoingsepamandates",
selectOptionAttribute: "reference",
- selectSearchAttributes: ["reference"],
+ selectSearchAttributes: ["reference", "status"],
selectDataTypeFilter: function (i, item) {
const mandateCustomer = i.customer?.id || i.customer
- return !item.customer || mandateCustomer === item.customer
+ return !i.archived && i.status === "Aktiv" && (!item.customer || mandateCustomer === item.customer)
+ },
+ entityModalButtonsType: "outgoingsepamandates",
+ entityModalCreateQueryFunction: function (item) {
+ return {customer: item.customer}
},
showFunction: function (item) {
return item.paymentType === "Einzug"