diff --git a/resources/js/components/documents/InvoiceDialog.vue b/resources/js/components/documents/InvoiceDialog.vue index 16180f6..ac11685 100644 --- a/resources/js/components/documents/InvoiceDialog.vue +++ b/resources/js/components/documents/InvoiceDialog.vue @@ -131,8 +131,8 @@ watch(invoice, (newValue, oldValue) => { if (newValue == oldValue) return - console.group('watch invoice') - console.log(`isDirty: ${isDirty.value}\tisLoading: ${isLoading.value}`) + // console.group('watch invoice') + // console.log(`isDirty: ${isDirty.value}\tisLoading: ${isLoading.value}`) if (isLoading.value) { if (!newValue) { @@ -160,19 +160,24 @@ watch(invoice, } } - if (newValue.customer?.id !== 0) { + if (newValue.customerId && newValue.customerId !== 0) { // if (importCustomer.value != newValue.customer) // console.warn('trigger importCustomer watcher') - importCustomer.value = newValue.customer as Customer - newValue.customer?.contacts.find(contact => { - if ( - contact.firstName === newValue?.billingData?.contactFirstName && - contact.lastName === newValue?.billingData?.contactLastName - ) { - // if (importContact.value != contact) - // console.warn('trigger importContact watcher') - importContact.value = contact - return true + console.log(newValue, newValue.customerId) + customers.value.find(customer => { + if (customer.id === newValue.customerId) { + if (invoice.value) invoice.value.customer = customer as Customer + importCustomer.value = customer as Customer + + customer.contacts.find(contact => { + if (contact.firstName === newValue?.billingData?.contactFirstName && + contact.lastName === newValue?.billingData?.contactLastName) { + // if (importContact.value != contact) + // console.warn('trigger importContact watcher') + importContact.value = contact + return true + } + }) } }) } @@ -183,8 +188,8 @@ watch(invoice, isDirty.value = true } - console.log(`isDirty: ${isDirty.value}\tisLoading: ${isLoading.value}`) - console.groupEnd() + // console.log(`isDirty: ${isDirty.value}\tisLoading: ${isLoading.value}`) + // console.groupEnd() }, { deep: true } ) @@ -624,7 +629,7 @@ const updateLineItems = (newItems: LineItem[]) => {