+
-
-
-
+
({
@@ -246,8 +243,18 @@ const form = reactive({
vehicleId: ''
})
+const createEmptyWeightEntry = (type: 'gross' | 'tare'): WeightEntryData => ({
+ type,
+ dsd: null,
+ weight: null,
+ weighedAt: null
+})
+
+const grossWeight = ref(createEmptyWeightEntry('gross'))
+const tareWeight = ref(createEmptyWeightEntry('tare'))
+
const { printPdf } = usePdfPrinter()
-const activeTab = ref<'weightsEmpty' | 'weights' | 'merchandise'>('weightsEmpty')
+const activeTab = ref<'weightsEmpty' | 'weights' | 'merchandise'>('weights')
const router = useRouter()
const receptionStore = useReceptionStore()
const allowAnyLicensePlate = ref(false)
@@ -377,6 +384,10 @@ const hydrateFromReception = (reception: ReceptionData | null) => {
form.receptionTypeId = reception?.receptionType?.id
? String(reception.receptionType.id)
: ''
+ const gross = reception.weights?.find((weight) => weight.type === 'gross') ?? null
+ const tare = reception.weights?.find((weight) => weight.type === 'tare') ?? null
+ grossWeight.value = gross ? {...gross} : createEmptyWeightEntry('gross')
+ tareWeight.value = tare ? {...tare} : createEmptyWeightEntry('tare')
isHydrating.value = false
syncMerchandiseFlag()
}
@@ -629,6 +640,30 @@ const printReceipt = async () => {
// Laisse le temps a la boite de dialogue d'impression de s'ouvrir.
await new Promise((resolve) => setTimeout(resolve, 600))
}
+
+const saveWeightEntry = async (entry: WeightEntryData) => {
+ if (!idReception || entry.weight === null) {
+ return
+ }
+
+ const payload = {
+ type: entry.type,
+ dsd: entry.dsd ?? null,
+ weight: entry.weight,
+ weighedAt: entry.weighedAt ?? null
+ }
+
+ if (entry.id) {
+ await updateWeight(entry.id, payload)
+ return
+ }
+
+ await createWeight({
+ reception: `api/receptions/${idReception}`,
+ ...payload
+ })
+}
+
async function validate() {
const normalizedLicensePlate = form.licensePlate.trim()
const normalizedReceptionDate = form.receptionDate.trim()
@@ -683,6 +718,10 @@ async function validate() {
await receptionStore.updateReception(idReception, {
...payload
})
+ await saveWeightEntry(grossWeight.value)
+ await saveWeightEntry(tareWeight.value)
+ const refreshedReception = await getReception(idReception)
+ hydrateFromReception(refreshedReception)
if (isMerchandise.value) {
await clearReceptionBovines(idReception)
diff --git a/frontend/services/dto/reception-data.ts b/frontend/services/dto/reception-data.ts
index 68ba019..d5f50f3 100644
--- a/frontend/services/dto/reception-data.ts
+++ b/frontend/services/dto/reception-data.ts
@@ -44,6 +44,8 @@ export interface WeightEntryData {
export interface WeightFormData {
id: number
weight: number
+ weighedAt : string
+ dsd: number
type: 'gross' | 'tare'
}
@@ -80,6 +82,7 @@ export type ReceptionFormData = {
carrierId: string
driverId: string
vehicleId: string
+ weight?: ReceptionFormWeight | null
}
export type ReceptionFormWeight = {