fix : corrections diverses
This commit is contained in:
@@ -4,29 +4,23 @@
|
||||
<UiTextInput
|
||||
label="Dsd"
|
||||
class="col-start-2"
|
||||
v-model="form.weights[0].dsd"
|
||||
v-model="sharedWeightMeta.dsd"
|
||||
:disabled="!auth.isAdmin"
|
||||
/>
|
||||
<UiDateInput
|
||||
label="Date pesée"
|
||||
v-model="form.weights[0].weighedAt"
|
||||
v-model="sharedWeightMeta.weighedAt"
|
||||
:disabled="!auth.isAdmin"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-x-40 mb-16">
|
||||
<UiNumberInput
|
||||
label="Pesée à vide"
|
||||
v-for="weight in form.weights"
|
||||
:key="weight.type"
|
||||
:label="getWeightLabel(weight.type)"
|
||||
labelClass="font-bold uppercase text-xl"
|
||||
v-model="form.weights[0].weight"
|
||||
wrapper-class="col-start-1 row-start-1"
|
||||
:disabled="!auth.isAdmin"
|
||||
/>
|
||||
|
||||
<UiNumberInput
|
||||
label="Pesée à plein"
|
||||
labelClass="font-bold uppercase text-xl"
|
||||
v-model="form.weights[1].weight"
|
||||
wrapper-class="col-start-2 row-start-1"
|
||||
v-model="weight.weight"
|
||||
:wrapper-class="weight.type === 'tare' ? 'col-start-1 row-start-1' : 'col-start-2 row-start-1'"
|
||||
:disabled="!auth.isAdmin"
|
||||
/>
|
||||
</div>
|
||||
@@ -64,13 +58,38 @@ const form = reactive({
|
||||
{id: 0, type: 'gross' as const, weight: 0, dsd: null, weighedAt: null}
|
||||
]
|
||||
})
|
||||
// DSD et date de pesée sont partagés entre tare et gross dans l'UI.
|
||||
const sharedWeightMeta = reactive<{
|
||||
dsd: number | string | null
|
||||
weighedAt: string | null
|
||||
}>({
|
||||
dsd: null,
|
||||
weighedAt: null
|
||||
})
|
||||
|
||||
const getWeightLabel = (type: 'tare' | 'gross'): string => {
|
||||
return type === 'tare' ? 'Pesée à vide' : 'Pesée à plein'
|
||||
}
|
||||
|
||||
const hydrateFromReception = (reception: ReceptionFormWeight) => {
|
||||
const tare = reception.weights.find(weight => weight.type === 'tare')
|
||||
const gross = reception.weights.find(weight => weight.type === 'gross')
|
||||
// On hydrate chaque ligne par son type (tare/gross), sans dépendre d'un index.
|
||||
for (const receptionWeight of reception.weights) {
|
||||
const formWeight = form.weights.find(weight => weight.type === receptionWeight.type)
|
||||
if (formWeight) {
|
||||
Object.assign(formWeight, receptionWeight)
|
||||
}
|
||||
}
|
||||
|
||||
if (tare) form.weights[0] = {...form.weights[0], ...tare}
|
||||
if (gross) form.weights[1] = {...form.weights[1], ...gross}
|
||||
// On récupère une valeur existante pour préremplir les champs partagés.
|
||||
const weightWithMeta = reception.weights.find(weight =>
|
||||
(weight.dsd !== null && weight.dsd !== undefined)
|
||||
|| (weight.weighedAt !== null && weight.weighedAt !== undefined && weight.weighedAt !== '')
|
||||
)
|
||||
|
||||
if (weightWithMeta) {
|
||||
sharedWeightMeta.dsd = weightWithMeta.dsd ?? null
|
||||
sharedWeightMeta.weighedAt = weightWithMeta.weighedAt ?? null
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -80,14 +99,13 @@ onMounted(async () => {
|
||||
|
||||
async function validate() {
|
||||
const sharedDsd =
|
||||
form.weights[0].dsd === null || form.weights[0].dsd === undefined || form.weights[0].dsd === ''
|
||||
sharedWeightMeta.dsd === null || sharedWeightMeta.dsd === undefined || sharedWeightMeta.dsd === ''
|
||||
? null
|
||||
: Number(form.weights[0].dsd)
|
||||
: Number(sharedWeightMeta.dsd)
|
||||
const sharedWeighedAt =
|
||||
form.weights[0].weighedAt === null || form.weights[0].weighedAt === undefined || form.weights[0].weighedAt === ''
|
||||
sharedWeightMeta.weighedAt === null || sharedWeightMeta.weighedAt === undefined || sharedWeightMeta.weighedAt === ''
|
||||
? null
|
||||
: form.weights[0].weighedAt
|
||||
|
||||
: sharedWeightMeta.weighedAt
|
||||
for (const weight of form.weights) {
|
||||
if (weight.id) {
|
||||
await updateWeight(weight.id, {
|
||||
|
||||
@@ -2,4 +2,5 @@ export interface WeightData {
|
||||
weight: number | null
|
||||
dsd: number | null
|
||||
weighedAt: string | null
|
||||
type : string | null
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
),
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['supplier:read']],
|
||||
security: "is_granted('ROLE_USER')"
|
||||
security: "is_granted('ROLE_ADMIN')"
|
||||
),
|
||||
new Post(
|
||||
normalizationContext: ['groups' => ['supplier:read']],
|
||||
|
||||
Reference in New Issue
Block a user