-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: working on post invoice refactor ui
- Loading branch information
1 parent
03a9599
commit 234b052
Showing
7 changed files
with
193 additions
and
15 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
apps/dashboard/src/modules/financial/components/invoice/InvoiceAmountCard.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<FormCard :header="t('c_invoiceInfo.Amount')" v-if="invoice" @cancel="form.context.resetForm" | ||
@update:modelValue="edit = $event" @save="formSubmit" :enableEdit="!deleted"> | ||
<div class="flex flex-column justify-content-between gap-2"> | ||
<InvoiceAmountForm :invoice="invoice" :form="form" :edit="edit" @update:edit="edit = $event"/> | ||
</div> | ||
</FormCard> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, onBeforeMount, ref, watch } from "vue"; | ||
import type { InvoiceResponse } from "@sudosos/sudosos-client"; | ||
import { updateInvoiceAmountObject } from "@/utils/validation-schema"; | ||
import { schemaToForm } from "@/utils/formUtils"; | ||
import { InvoiceStatusResponseStateEnum } from "@sudosos/sudosos-client/src/api"; | ||
import { useInvoiceStore } from "@/stores/invoice.store"; | ||
import { useI18n } from "vue-i18n"; | ||
import InvoiceAmountForm from "@/modules/financial/components/invoice/forms/InvoiceAmountForm.vue"; | ||
import FormCard from "@/components/FormCard.vue"; | ||
const { t } = useI18n(); | ||
const edit = ref(false); | ||
const invoiceStore = useInvoiceStore(); | ||
const deleted = computed(() => invoice.value.currentState.state === InvoiceStatusResponseStateEnum.Deleted); | ||
const invoice = computed(() => invoiceStore.getInvoice(props.invoiceId) as InvoiceResponse); | ||
const props = defineProps({ | ||
invoiceId: { | ||
type: Number, | ||
required: true | ||
} | ||
}); | ||
const form = schemaToForm(updateInvoiceAmountObject); | ||
const formSubmit = () => { | ||
form.submit(); | ||
}; | ||
const updateFieldValues = (p: InvoiceResponse) => { | ||
if (!p) return; | ||
const values = { | ||
amount: p.transfer.amountInclVat.amount / 100, | ||
}; | ||
form.context.resetForm({ values }); | ||
}; | ||
watch(() => invoice.value, (newValue) => { | ||
updateFieldValues(newValue); | ||
}); | ||
onBeforeMount(() => { | ||
if (invoice.value) { | ||
updateFieldValues(invoice.value); | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
apps/dashboard/src/modules/financial/components/invoice/forms/InvoiceAmountForm.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<template> | ||
<div class="flex flex-column justify-content-between gap-2"> | ||
<InputSpan :label="t('c_invoiceInfo.Amount')" | ||
:value="form.model.amount.value.value" | ||
:attributes="form.model.amount.attr.value" | ||
@update:value="form.context.setFieldValue('amount', $event)" | ||
:errors="form.context.errors.value.amount" | ||
id="name" placeholder="0" type="currency" :disabled="!edit"/> | ||
The current total on the invoice is {{ formatPrice(entryTotal) }} | ||
<!-- {{ entryTotal }}--> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import InputSpan from "@/components/InputSpan.vue"; | ||
import { useI18n } from "vue-i18n"; | ||
import { useToast } from "primevue/usetoast"; | ||
import { useInvoiceStore } from "@/stores/invoice.store"; | ||
import { computed, type PropType } from "vue"; | ||
import type { InvoiceResponse } from "@sudosos/sudosos-client"; | ||
import { type Form, setSubmit } from "@/utils/formUtils"; | ||
import * as yup from "yup"; | ||
import { updateInvoiceAddressingObject, updateInvoiceAmountObject } from "@/utils/validation-schema"; | ||
import { handleError } from "@/utils/errorUtils"; | ||
import { formatPrice } from "@/utils/formatterUtils"; | ||
import type { DineroObject } from "dinero.js"; | ||
const { t } = useI18n(); | ||
const toast = useToast(); | ||
const emit = defineEmits(['update:edit']); | ||
const invoiceStore = useInvoiceStore(); | ||
const entryTotal = computed(() => { | ||
const total: DineroObject = { amount: 0, precision: 2, currency: 'EUR' }; | ||
props.invoice.invoiceEntries.forEach((entry) => { | ||
console.error(entry.amount, entry.priceInclVat.amount, entry.amount * entry.priceInclVat.amount); | ||
total.amount += ((entry.amount * entry.priceInclVat.amount)); | ||
}); | ||
return total; | ||
}); | ||
const props = defineProps({ | ||
invoice: { | ||
type: Object as PropType<InvoiceResponse>, | ||
required: true | ||
}, | ||
form: { | ||
type: Object as PropType<Form<yup.InferType<typeof updateInvoiceAmountObject>>>, | ||
required: true, | ||
}, | ||
edit: { | ||
type: Boolean, | ||
required: false, | ||
default: false, | ||
}, | ||
}); | ||
setSubmit(props.form, props.form.context.handleSubmit(async (values) => { | ||
await invoiceStore.updateInvoice(props.invoice.id, { amount: { | ||
amount: Math.round(values.amount * 100), | ||
currency: 'EUR', | ||
precision: 2 | ||
} }).then(() => { | ||
toast.add({ | ||
severity: 'success', | ||
summary: t('successMessages.success'), | ||
detail: t('c_invoiceInfo.AmountUpdated'), | ||
life: 3000, | ||
}); | ||
emit('update:edit', false); | ||
}).catch((error) => { | ||
handleError(error, toast); | ||
}); | ||
})); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { InvoiceResponse } from "@sudosos/sudosos-client"; | ||
|
||
export function isDirty(invoice: InvoiceResponse): boolean { | ||
const entryTotal = invoice.invoiceEntries.reduce((sum, entry) => sum + entry.priceInclVat.amount * entry.amount, 0); | ||
return entryTotal !== invoice.transfer.amountInclVat.amount; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters