feat : Ajout de la sélection des bovins étape 3 d'une réception (WIP)

This commit is contained in:
2026-02-05 10:27:04 +01:00
parent 33563addbe
commit 719937d218
11 changed files with 41 additions and 134 deletions

View File

@@ -36,7 +36,7 @@
<script setup lang="ts">
import type {BovineTypeData} from "~/services/dto/bovine-type-data";
import {getBovineTypeList} from "~/services/bovine-type";
import {MERCHANDISE_TYPE_CODES, RECEPTION_TYPE_CODES} from "~/utils/constants";
import {RECEPTION_TYPE_CODES} from "~/utils/constants";
import {useReceptionStore} from '~/stores/reception'
import {
createReceptionBovine,
@@ -46,6 +46,7 @@ import {
} from "~/services/reception-bovine";
import {computed, onMounted, reactive, ref, watch} from "vue";
const toast = useToast()
const isLoadingBovineType = ref(false)
const bovineType = ref<BovineTypeData[]>([])
const receptionStore = useReceptionStore()
@@ -55,19 +56,13 @@ const receptionId = computed(() => receptionStore.current?.id ?? null)
const receptionIri = computed(() =>
receptionId.value ? `/api/receptions/${receptionId.value}` : null
)
const toast = useToast()
const nuxtApp = useNuxtApp()
const i18n = nuxtApp.$i18n as { t: (key: string) => string } |
undefined
const t = (key: string) => (i18n?.t ? String(i18n.t(key)) : key)
const totalBovineQuantity = computed(() => {
const baseTotal = Object.values(bovineQuantities).reduce((sum, value) => {
const n = typeof value === 'number' ? value : 0
return sum + n
const totalBovines = computed(() => {
const base = Object.values(bovineQuantities).reduce((sum, value) => {
return sum + (value ?? 0)
}, 0)
const other = typeof otherQuantity.value === 'number' ? otherQuantity.value : 0
return baseTotal + other
return base + (otherQuantity.value ?? 0)
})
const loadBovineType = async () => {
isLoadingBovineType.value = true
try {
@@ -117,6 +112,7 @@ watch(
async function syncBovineSelections(receptionIri: string) {
const existing = await getReceptionBovineList(receptionIri)
const existingMap = new Map<string, { id: number; quantity: number | null }>()
for (const selection of existing) {
const bovineTypeId = String(selection.bovineType.id)
existingMap.set(bovineTypeId, {
@@ -159,37 +155,21 @@ async function syncBovineSelections(receptionIri: string) {
})
}
}
const hasNegativeQuantity = computed(() => {
const anyNegativeInTypes =
Object.values(bovineQuantities).some((value) => {
return typeof value === 'number' && value < 0
})
const otherNegative =
typeof otherQuantity.value === 'number' &&
otherQuantity.value < 0
return anyNegativeInTypes || otherNegative
})
async function goNext() {
if (!receptionStore.current || !receptionIri.value) {
return
}
if (hasNegativeQuantity.value) {
toast.error({
title: 'Erreur',
message: ("La quantité de bovins ne peut pas être négative.")
})
return
}
// Le 52 à vérifier
if (totalBovineQuantity.value > 52) {
// @TODO Ajouter un composable pour le toaster qui gère les key i18n
if (totalBovines.value > 52) {
toast.error({
title: 'Erreur',
message: ('Le total des bovins ne peut pas dépasser 52.')
})
return
}
const nextStep = receptionStore.current.currentStep + 1
await syncBovineSelections(receptionIri.value)