[#320] Modification réception terminé étape 2 #21
@@ -123,6 +123,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|||||||
67
frontend/components/reception/update-weight.vue
Normal file
67
frontend/components/reception/update-weight.vue
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<template>
|
||||||
|
<form @submit.prevent="validate">
|
||||||
|
<div class="grid grid-cols-2 gap-x-40 gap-y-8 mb-16">
|
||||||
|
<UiNumberInput
|
||||||
|
label="Pesée à vide"
|
||||||
|
v-model="form.weights[0].weight"
|
||||||
|
:min="0"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UiNumberInput
|
||||||
|
label="Pesée à plein"
|
||||||
|
v-model="form.weights[1].weight"
|
||||||
|
:min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="bg-primary-500 text-white px-6 py-3 rounded-md"
|
||||||
|
>
|
||||||
|
Enregistrer
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type {ReceptionFormWeight, ReceptionUpdatePayload} from '~/services/dto/reception-data'
|
||||||
|
import { getReception } from '~/services/reception'
|
||||||
|
import { useReceptionStore } from '~/stores/reception'
|
||||||
|
import {updateWeight} from "~/services/weight";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
idReception: number
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const receptionStore = useReceptionStore()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const form = reactive({
|
||||||
|
weights: [
|
||||||
|
{ id: 0, type: 'tare' as const, weight: 0 },
|
||||||
|
{ id: 0, type: 'gross' as const, weight: 0 }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const hydrateFromReception = (reception: ReceptionFormWeight) => {
|
||||||
|
const tare = reception.weights.find(weight => weight.type === 'tare')
|
||||||
|
const gross = reception.weights.find(weight => weight.type === 'gross')
|
||||||
|
|
||||||
|
if (tare) form.weights[0] = { ...tare }
|
||||||
|
if (gross) form.weights[1] = { ...gross }
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
const reception = await getReception(props.idReception)
|
||||||
|
hydrateFromReception(reception)
|
||||||
|
})
|
||||||
|
|
||||||
|
async function validate() {
|
||||||
|
|
||||||
|
for (const weight of form.weights) {
|
||||||
|
if (weight.id) {
|
||||||
|
await updateWeight(weight.id, {weight: weight.weight})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -12,7 +12,10 @@
|
|||||||
"fetch": "Impossible de récupérer la réception.",
|
"fetch": "Impossible de récupérer la réception.",
|
||||||
"create": "Impossible de créer la réception.",
|
"create": "Impossible de créer la réception.",
|
||||||
"update": "Impossible de mettre à jour la réception.",
|
"update": "Impossible de mettre à jour la réception.",
|
||||||
"weigh": "Impossible de récupérer la pesée."
|
"weight": "Impossible de récupérer la pesée."
|
||||||
|
},
|
||||||
|
"weight": {
|
||||||
|
"update": "Impossible de mettre à jour la pesée"
|
||||||
},
|
},
|
||||||
"receptionType": {
|
"receptionType": {
|
||||||
"list": "Impossible de récupérer la liste des types de réception."
|
"list": "Impossible de récupérer la liste des types de réception."
|
||||||
@@ -79,6 +82,9 @@
|
|||||||
"carrier": {
|
"carrier": {
|
||||||
"update": "Transporteur mis à jour",
|
"update": "Transporteur mis à jour",
|
||||||
"create": "Transporteur créé"
|
"create": "Transporteur créé"
|
||||||
|
},
|
||||||
|
"weight": {
|
||||||
|
"update": "Pesée mis à jour"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-2 items-start gap-y-8 gap-x-40 mb-16">
|
<div class="grid grid-cols-2 items-start gap-y-8 gap-x-40 mb-16">
|
||||||
|
|
||||||
<UiTextInput
|
<UiTextInput
|
||||||
label = "nom du fournisseur"
|
label = "nom du fournisseur"
|
||||||
id="carrier-name"
|
id="carrier-name"
|
||||||
|
|||||||
@@ -119,6 +119,13 @@
|
|||||||
wrapper-class="col-start-2 row-start-4"
|
wrapper-class="col-start-2 row-start-4"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="grid grid-cols-2 items-start gap-y-8 gap-x-40 mb-16">
|
||||||
|
<h1 class="font-bold text-5xl uppercase col-start-1 row-start-1">pesée</h1>
|
||||||
|
<h1 class="font-bold text-5xl uppercase col-start-2 row-start-1">marchandise</h1>
|
||||||
|
</div>
|
||||||
|
<update-weight
|
||||||
|
:idReception="idReception"
|
||||||
|
/>
|
||||||
</form>
|
</form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -141,6 +148,7 @@ import {SUPLLIER_CODE} from "~/utils/constants";
|
|||||||
import {deleteReceptionBovine, getReceptionBovineList} from "~/services/reception-bovine";
|
import {deleteReceptionBovine, getReceptionBovineList} from "~/services/reception-bovine";
|
||||||
import type {ReceptionData, ReceptionFormData} from "~/services/dto/reception-data";
|
import type {ReceptionData, ReceptionFormData} from "~/services/dto/reception-data";
|
||||||
import {getReception} from "~/services/reception";
|
import {getReception} from "~/services/reception";
|
||||||
|
import UpdateWeight from "~/components/reception/update-weight.vue";
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const receptionStore = useReceptionStore()
|
const receptionStore = useReceptionStore()
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ export interface WeightEntryData {
|
|||||||
weighedAt: string | null
|
weighedAt: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WeightFormData {
|
||||||
|
id: number
|
||||||
|
weight: number
|
||||||
|
type: 'gross' | 'tare'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type ReceptionPayload = {
|
export type ReceptionPayload = {
|
||||||
licensePlate?: string | null
|
licensePlate?: string | null
|
||||||
receptionDate?: string
|
receptionDate?: string
|
||||||
@@ -72,3 +80,14 @@ export type ReceptionFormData = {
|
|||||||
driverId: string
|
driverId: string
|
||||||
vehicleId: string
|
vehicleId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ReceptionFormWeight = {
|
||||||
|
weights: WeightFormData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ReceptionUpdatePayload {
|
||||||
|
weights: {
|
||||||
|
id: number
|
||||||
|
weight: number
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,5 +16,8 @@ export async function createWeight(payload: WeightPayload) {
|
|||||||
|
|
||||||
export async function updateWeight(id: number, payload: Partial<WeightPayload>) {
|
export async function updateWeight(id: number, payload: Partial<WeightPayload>) {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
return api.patch<WeightEntryData>(`weights/${id}`, payload)
|
return api.patch<WeightEntryData>(`weights/${id}`, payload,{
|
||||||
|
toastErrorKey: 'errors.weight.update',
|
||||||
|
toastSuccessKey: 'success.weight.update'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user