feat : dernier push avant finalisation de affichage reception finie
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
<template>
|
||||
|
||||
<form @submit.prevent="validate">
|
||||
<div class="flex items-center justify-between mt-12 mb-8 ">
|
||||
<h1 class="font-bold text-5xl uppercase">Réception {{ receptionLoad?.identificationNumber }}</h1>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 items-start gap-y-8 gap-x-40 mb-12">
|
||||
<div class="grid grid-cols-2 items-start gap-y-8 gap-x-40 mb-[60px]">
|
||||
<div class="flex items-center justify-between gap-10 relative">
|
||||
<div class="flex flex-row absolute -left-[60px] justify-between">
|
||||
<Icon @click="router.push('/')" name="gg:arrow-left-o" size="44" class="cursor-pointer text-primary-500"/>
|
||||
</div>
|
||||
<h1 class="font-bold text-4xl col-start-1 row-start-1 text-primary-500 uppercase">Réception {{ form.identificationNumber }}</h1>
|
||||
<Icon @click="router.push('/')" name="mdi:printer-outline" size="44" class="cursor-pointer text-primary-500"/>
|
||||
</div>
|
||||
|
||||
<!-- Nom de l'utilisateur -->
|
||||
<UiSelect
|
||||
id="reception-user"
|
||||
@@ -16,7 +21,7 @@
|
||||
label: user.username
|
||||
}))"
|
||||
:loading="isLoadingUsers"
|
||||
wrapper-class="col-start-1 row-start-1"
|
||||
wrapper-class="col-start-1 row-start-2"
|
||||
/>
|
||||
<!-- Date de réception -->
|
||||
<UiDateInput
|
||||
@@ -24,7 +29,20 @@
|
||||
:disabled="!auth.isAdmin"
|
||||
v-model="form.receptionDate"
|
||||
label="Date de réception"
|
||||
wrapper-class="col-start-1 row-start-2"
|
||||
wrapper-class="col-start-1 row-start-3"
|
||||
/>
|
||||
<!-- type de reception -->
|
||||
<UiSelect
|
||||
id="reception-supplier"
|
||||
v-model="form.receptionTypeId"
|
||||
:disabled="!auth.isAdmin"
|
||||
label="Type de Réception"
|
||||
:options="receptionTypes.map((receptionType) => ({
|
||||
value: String(receptionType.id),
|
||||
label: receptionType.label
|
||||
}))"
|
||||
:loading="isLoadingSuppliers"
|
||||
wrapper-class="col-start-1 row-start-4"
|
||||
/>
|
||||
<!-- Fournisseur -->
|
||||
<UiSelect
|
||||
@@ -37,7 +55,7 @@
|
||||
label: supplier.name
|
||||
}))"
|
||||
:loading="isLoadingSuppliers"
|
||||
wrapper-class="col-start-1 row-start-3"
|
||||
wrapper-class="col-start-1 row-start-5"
|
||||
/>
|
||||
<!-- Adresse fournisseur -->
|
||||
<UiSelect
|
||||
@@ -49,7 +67,7 @@
|
||||
label: address.fullAddress
|
||||
}))"
|
||||
:disabled="(isLoadingSuppliers || supplierAddresses.length === 0) && !auth.isAdmin"
|
||||
wrapper-class="col-start-1 row-start-4"
|
||||
wrapper-class="col-start-2 row-start-1"
|
||||
/>
|
||||
<!-- Camion -->
|
||||
<UiSelect
|
||||
@@ -62,7 +80,7 @@
|
||||
label: truck.name
|
||||
}))"
|
||||
:loading="isLoadingTrucks"
|
||||
wrapper-class="col-start-2 row-start-1"
|
||||
wrapper-class="col-start-2 row-start-2"
|
||||
/>
|
||||
<!-- Transporteur -->
|
||||
<UiSelect
|
||||
@@ -76,7 +94,7 @@
|
||||
}))"
|
||||
:loading="isLoadingCarriers"
|
||||
select-class="h-[34px]"
|
||||
wrapper-class="col-start-2 row-start-2"
|
||||
wrapper-class="col-start-2 row-start-3"
|
||||
/>
|
||||
<!-- Chauffeur (LIOT) -->
|
||||
<UiSelect
|
||||
@@ -89,10 +107,10 @@
|
||||
label: driver.name
|
||||
}))"
|
||||
:loading="isLoadingDrivers"
|
||||
wrapper-class="col-start-2 row-start-3"
|
||||
wrapper-class="col-start-2 row-start-4"
|
||||
/>
|
||||
<!-- Plaque d'immatriculation -->
|
||||
<div v-if="!isLiotCarrier" class="col-start-2 row-start-4">
|
||||
<div v-if="!isLiotCarrier" class="col-start-2 row-start-5">
|
||||
<UiLicensePlateInput
|
||||
:disabled="!auth.isAdmin"
|
||||
v-model="form.licensePlate"
|
||||
@@ -111,30 +129,28 @@
|
||||
}))"
|
||||
:loading="isLoadingVehicles"
|
||||
:disabled="(isLoadingVehicles || filteredVehicles.length === 0) && !auth.isAdmin"
|
||||
wrapper-class="col-start-2 row-start-4"
|
||||
wrapper-class="col-start-2 row-start-5"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex justify-center mb-2">
|
||||
<UiButton
|
||||
v-if="auth.isAdmin"
|
||||
type="submit"
|
||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] mb-16"
|
||||
|
||||
>
|
||||
Enregistrer
|
||||
</UiButton>
|
||||
</div>
|
||||
<div class="flex justify-evenly gap-y-8 gap-x-40 mb-8 border-b border-slate-400">
|
||||
<div v-if="formIsLoading">
|
||||
<div class="flex justify-evenly gap-y-8 gap-x-41 mb-10 border-b border-primary-500/60">
|
||||
<h1
|
||||
class="font-bold text-3xl uppercase col-start-1 row-start-1 cursor-pointer"
|
||||
:class="activeTab === 'weights' ? 'underline' : ''"
|
||||
@click="activeTab = 'weights'"
|
||||
class="font-bold text-3xl uppercase px-12 col-start-1 row-start-1 cursor-pointer "
|
||||
:class="activeTab === 'weightsEmpty' ? 'border-b-[6px] border-primary-500 text-primary-500' : 'text-primary-500/50'"
|
||||
@click="activeTab = 'weightsEmpty'"
|
||||
>
|
||||
pesées
|
||||
pesée à plein
|
||||
</h1>
|
||||
<h1
|
||||
class="font-bold text-3xl uppercase col-start-2 row-start-1 cursor-pointer"
|
||||
:class="activeTab === 'merchandise' ? 'underline' : ''"
|
||||
class="font-bold text-3xl uppercase col-start-1 row-start-1 px-12 cursor-pointer "
|
||||
:class="activeTab === 'weights' ? 'border-b-[6px] border-primary-500 text-primary-500 ' : 'text-primary-500/50'"
|
||||
@click="activeTab = 'weights'"
|
||||
>
|
||||
pesée à vide
|
||||
</h1>
|
||||
<h1
|
||||
class="font-bold text-3xl uppercase px-12 col-start-2 row-start-1 cursor-pointer "
|
||||
:class="activeTab === 'merchandise' ? 'border-b-[6px] border-primary-500 text-primary-500' : 'text-primary-500/50'"
|
||||
@click="activeTab = 'merchandise'"
|
||||
>
|
||||
{{ isMerchandise ? "Marchandise" : "Bovins" }}
|
||||
@@ -142,22 +158,47 @@
|
||||
</div>
|
||||
|
||||
<update-weight
|
||||
v-if="activeTab === 'weights'"
|
||||
v-show="activeTab === 'weights'"
|
||||
:idReception="idReception"
|
||||
:weightType="'tare'"
|
||||
:disabled="!auth.isAdmin"
|
||||
:isValidate="isValid"
|
||||
/>
|
||||
<div class="mb-12 ">
|
||||
<update-weight
|
||||
v-show="activeTab === 'weightsEmpty'"
|
||||
:idReception="idReception"
|
||||
:weightType="'gross'"
|
||||
:disabled="!auth.isAdmin"
|
||||
:isValidate="isValid"
|
||||
/>
|
||||
|
||||
<update-merchandise
|
||||
v-else-if="activeTab === 'merchandise' && isMerchandise"
|
||||
:idReception="idReception"
|
||||
:disabled="!auth.isAdmin"
|
||||
/>
|
||||
<update-merchandise
|
||||
v-show="activeTab === 'merchandise' && isMerchandise"
|
||||
:idReception="idReception"
|
||||
:disabled="!auth.isAdmin"
|
||||
:isValidate="isValidMerchandise"
|
||||
/>
|
||||
|
||||
<update-bovin
|
||||
v-else
|
||||
:idReception="idReception"
|
||||
:disabled="!auth.isAdmin"
|
||||
/>
|
||||
<update-bovin
|
||||
v-show="activeTab === 'merchandise' && !isMerchandise"
|
||||
:idReception="idReception"
|
||||
:disabled="!auth.isAdmin"
|
||||
:isValidate="isValidBovin"
|
||||
|
||||
/>
|
||||
</div>
|
||||
<div class="flex justify-center">
|
||||
<UiButton
|
||||
v-if="auth.isAdmin"
|
||||
type="submit"
|
||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] mb-16"
|
||||
|
||||
>
|
||||
Enregistrer
|
||||
</UiButton>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -176,18 +217,24 @@ import type {DriverData} from '~/services/dto/driver-data'
|
||||
import {getDriverList} from '~/services/driver'
|
||||
import type {VehicleData} from '~/services/dto/vehicle-data'
|
||||
import {getVehicleList} from '~/services/vehicle'
|
||||
import {SUPPLIER_CODE} from "~/utils/constants";
|
||||
import {deleteReceptionBovine, getReceptionBovineList} from "~/services/reception-bovine";
|
||||
import {RECEPTION_TYPE_CODES, SUPPLIER_CODE} from "~/utils/constants";
|
||||
import {
|
||||
deleteReceptionBovine,
|
||||
getReceptionBovineList,
|
||||
} from "~/services/reception-bovine";
|
||||
import type {ReceptionData, ReceptionFormData} from "~/services/dto/reception-data";
|
||||
import {getReception} from "~/services/reception";
|
||||
import {getReception, updateReception} from "~/services/reception";
|
||||
import UpdateWeight from "~/components/reception/update-weight.vue";
|
||||
import UpdateMerchandise from "~/components/reception/update-merchandise.vue";
|
||||
import UpdateBovin from "~/components/reception/update-bovin.vue";
|
||||
import {getReceptionTypeList} from "~/services/reception-type";
|
||||
import type {ReceptionTypeData} from "~/services/dto/reception-type-data";
|
||||
import {computed} from "vue";
|
||||
import {updateWeight} from "~/services/weight";
|
||||
import {deleteReceptionPelletBuilding, getReceptionPelletBuildingList} from "~/services/reception-pellet-building";
|
||||
|
||||
const activeTab = ref<'weights' | 'merchandise'>('weights')
|
||||
const router = useRouter()
|
||||
const receptionStore = useReceptionStore()
|
||||
const form = reactive<ReceptionFormData>({
|
||||
identificationNumber: null,
|
||||
licensePlate: '',
|
||||
receptionDate: new Date().toISOString().slice(0, 10),
|
||||
receptionTypeId: '',
|
||||
@@ -199,11 +246,17 @@ const form = reactive<ReceptionFormData>({
|
||||
driverId: '',
|
||||
vehicleId: ''
|
||||
})
|
||||
|
||||
const activeTab = ref<'weights' | 'weightsEmpty' | 'merchandise'>('weights')
|
||||
const router = useRouter()
|
||||
const receptionStore = useReceptionStore()
|
||||
const allowAnyLicensePlate = ref(false)
|
||||
const isLoading = ref(false)
|
||||
const users = ref<UserData[]>([])
|
||||
const isLoadingUsers = ref(false)
|
||||
const isLoadingTypes = ref(false)
|
||||
const suppliers = ref<SupplierData[]>([])
|
||||
const receptionTypes = ref<ReceptionTypeData[]>([])
|
||||
const isLoadingSuppliers = ref(false)
|
||||
const trucks = ref<TruckData[]>([])
|
||||
const isLoadingTrucks = ref(false)
|
||||
@@ -214,23 +267,27 @@ const isLoadingDrivers = ref(false)
|
||||
const vehicles = ref<VehicleData[]>([])
|
||||
const isLoadingVehicles = ref(false)
|
||||
const authStore = useAuthStore()
|
||||
const isValid = ref(false)
|
||||
const isValidBovin = ref(false)
|
||||
const isValidMerchandise = ref(false)
|
||||
const formIsLoading = ref(false)
|
||||
const route = useRoute()
|
||||
const idReception = Number(route.params.id)
|
||||
const auth = useAuthStore()
|
||||
const isMerchandise = ref(false)
|
||||
|
||||
// Empêche les watchers de reset des champs pendant le remplissage initial
|
||||
const isHydrating = ref(false)
|
||||
const route = useRoute()
|
||||
const idReception = Number(route.params.id)
|
||||
const receptionLoad = await getReception(idReception)
|
||||
const receptionType = receptionLoad.receptionType
|
||||
const auth = useAuthStore()
|
||||
const isBtWeight = ref(true)
|
||||
const isMerchandise = ref(receptionType.code === 'MARCHANDISES')
|
||||
|
||||
|
||||
// Transporteur sélectionné dans le formulaire
|
||||
const selectedCarrier = computed(() =>
|
||||
carriers.value.find((carrier) => String(carrier.id) === form.carrierId) ?? null
|
||||
)
|
||||
|
||||
// Indique si le transporteur est LIOT
|
||||
const isLiotCarrier = computed(() => selectedCarrier.value?.code === SUPPLIER_CODE.LIOT)
|
||||
|
||||
// Adresses disponibles pour le fournisseur sélectionné
|
||||
const supplierAddresses = computed(() => {
|
||||
const supplierId = Number(form.supplierId)
|
||||
@@ -239,6 +296,7 @@ const supplierAddresses = computed(() => {
|
||||
}
|
||||
return suppliers.value.find((supplier) => supplier.id === supplierId)?.addresses ?? []
|
||||
})
|
||||
|
||||
// Chauffeurs filtrés par transporteur (LIOT)
|
||||
const filteredDrivers = computed<DriverData[]>(() => {
|
||||
if (!form.carrierId) {
|
||||
@@ -246,6 +304,7 @@ const filteredDrivers = computed<DriverData[]>(() => {
|
||||
}
|
||||
return drivers.value.filter((driver) => String(driver.carrier?.id) === form.carrierId)
|
||||
})
|
||||
|
||||
// Véhicules filtrés par transporteur + type de camion
|
||||
const filteredVehicles = computed<VehicleData[]>(() => {
|
||||
if (!form.carrierId) {
|
||||
@@ -259,18 +318,43 @@ const filteredVehicles = computed<VehicleData[]>(() => {
|
||||
})
|
||||
|
||||
// Supprime les données bovines si on change de type de réception
|
||||
const clearReceptionBovines = async (receptionIri: string) => {
|
||||
const clearReceptionBovines = async (receptionId: number) => {
|
||||
const receptionIri = `/api/receptions/${receptionId}`
|
||||
const existing = await getReceptionBovineList(receptionIri)
|
||||
for (const selection of existing) {
|
||||
await deleteReceptionBovine(selection.id)
|
||||
}
|
||||
}
|
||||
|
||||
const hydrateFromUser = (reception: ReceptionData | null) => {
|
||||
const syncMerchandiseFlag = () => {
|
||||
const receptionType =
|
||||
receptionTypes.value.find((type) => String(type.id) === form.receptionTypeId) ?? null
|
||||
isMerchandise.value = receptionType?.code === RECEPTION_TYPE_CODES.MERCHANDISES
|
||||
}
|
||||
|
||||
const clearReceptionMerchandise = async (receptionId: number) => {
|
||||
const receptionIri = `/api/receptions/${receptionId}`
|
||||
|
||||
// supprime toutes les associations granulés/bâtiments
|
||||
const existing = await getReceptionPelletBuildingList(receptionIri)
|
||||
for (const selection of existing) {
|
||||
await deleteReceptionPelletBuilding(selection.id)
|
||||
}
|
||||
|
||||
// reset des champs marchandise
|
||||
await updateReception(receptionId, {
|
||||
merchandiseType: null,
|
||||
merchandiseDetail: null,
|
||||
buildings: []
|
||||
})
|
||||
}
|
||||
|
||||
const hydrateFromReception = (reception: ReceptionData | null) => {
|
||||
if (!reception) {
|
||||
return
|
||||
}
|
||||
isHydrating.value = true
|
||||
form.identificationNumber = reception?.identificationNumber ?? ''
|
||||
form.licensePlate = reception?.licensePlate ?? ''
|
||||
form.receptionDate = reception?.receptionDate ?? new Date().toISOString().slice(0, 10)
|
||||
form.userId = reception?.user?.id
|
||||
@@ -291,7 +375,11 @@ const hydrateFromUser = (reception: ReceptionData | null) => {
|
||||
form.driverId = reception?.driver?.id
|
||||
? String(reception.driver.id)
|
||||
: ''
|
||||
form.receptionTypeId = reception?.receptionType?.id
|
||||
? String(reception.receptionType.id)
|
||||
: ''
|
||||
isHydrating.value = false
|
||||
syncMerchandiseFlag()
|
||||
}
|
||||
|
||||
watch(
|
||||
@@ -302,8 +390,8 @@ watch(
|
||||
}
|
||||
isLoading.value = true
|
||||
try {
|
||||
const user = await getReception(id)
|
||||
hydrateFromUser(user)
|
||||
const reception = await getReception(id)
|
||||
hydrateFromReception(reception)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
@@ -311,6 +399,14 @@ watch(
|
||||
{immediate: true}
|
||||
)
|
||||
|
||||
watch(
|
||||
() => form.receptionTypeId,
|
||||
() => {
|
||||
const receptionType = receptionTypes.value.find((type) => String(type.id) === form.receptionTypeId) ?? null
|
||||
isMerchandise.value = receptionType?.code === RECEPTION_TYPE_CODES.MERCHANDISES
|
||||
}
|
||||
)
|
||||
|
||||
// Charge la liste des users pour le select
|
||||
const loadUsers = async () => {
|
||||
isLoadingUsers.value = true
|
||||
@@ -331,6 +427,15 @@ const loadSuppliers = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadTypes = async () => {
|
||||
isLoadingTypes.value = true
|
||||
try {
|
||||
receptionTypes.value = await getReceptionTypeList()
|
||||
} finally {
|
||||
isLoadingSuppliers.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Charge la liste des camions pour le select
|
||||
const loadTrucks = async () => {
|
||||
isLoadingTrucks.value = true
|
||||
@@ -371,7 +476,7 @@ const loadVehicles = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// On met le user connecté par défaut dans le select
|
||||
// On met l'user connecté par défaut dans le select
|
||||
const setDefaultUser = () => {
|
||||
if (form.userId) {
|
||||
return
|
||||
@@ -383,6 +488,9 @@ const setDefaultUser = () => {
|
||||
|
||||
// On récupère toutes les données des selects au chargement du composant
|
||||
onMounted(async () => {
|
||||
await loadTypes()
|
||||
syncMerchandiseFlag()
|
||||
formIsLoading.value =true
|
||||
await loadUsers()
|
||||
await loadSuppliers()
|
||||
await loadTrucks()
|
||||
@@ -507,11 +615,10 @@ watch(
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// Valide le formulaire et crée/met à jour la réception
|
||||
async function validate() {
|
||||
const normalizedLicensePlate = form.licensePlate.trim()
|
||||
const normalizedReceptionDate = form.receptionDate.trim()
|
||||
const normalizedReceptionTypeId = form.receptionTypeId.trim()
|
||||
const normalizedUserId = form.userId.trim()
|
||||
const normalizedSupplierId = form.supplierId.trim()
|
||||
const normalizedAddressId = form.addressId.trim()
|
||||
@@ -536,10 +643,14 @@ async function validate() {
|
||||
const driverIri = normalizedDriverId
|
||||
? `/api/drivers/${normalizedDriverId}`
|
||||
: null
|
||||
const typeIri = normalizedReceptionTypeId
|
||||
? `/api/reception_types/${normalizedReceptionTypeId}`
|
||||
: null
|
||||
|
||||
const basePayload = {
|
||||
licensePlate: normalizedLicensePlate,
|
||||
receptionDate: normalizedReceptionDate,
|
||||
receptionType: typeIri,
|
||||
user: userIri,
|
||||
supplier: supplierIri,
|
||||
address: addressIri,
|
||||
@@ -549,17 +660,27 @@ async function validate() {
|
||||
|
||||
const payload = {
|
||||
...basePayload,
|
||||
...(isLiotCarrier.value && driverIri ? {driver: driverIri} : {})
|
||||
...(isLiotCarrier.value && driverIri ? {driver: driverIri} : {}),
|
||||
}
|
||||
|
||||
if (idReception) {
|
||||
const updated = await receptionStore.updateReception(idReception, {
|
||||
isValid.value = true
|
||||
isMerchandise.value ? (isValidMerchandise.value = true) : (isValidBovin.value = true)
|
||||
await receptionStore.updateReception(idReception, {
|
||||
...payload
|
||||
})
|
||||
if (updated) {
|
||||
await router.push(`/reception/update/${updated.id}`)
|
||||
|
||||
if (isMerchandise.value) {
|
||||
await clearReceptionBovines(idReception)
|
||||
} else {
|
||||
await clearReceptionMerchandise(idReception)
|
||||
}
|
||||
router.push("/reception/finish-reception")
|
||||
|
||||
isValid.value = false
|
||||
isValidBovin.value = false
|
||||
isValidMerchandise.value = false
|
||||
|
||||
await router.push("/reception/finish-reception")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user