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