Compare commits
2 Commits
83b339746e
...
v0.0.38
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab6de16319 | ||
| 800ab1d432 |
@@ -34,7 +34,7 @@ Ajouter dans le fichier .env du frontend
|
|||||||
* [#315] Creation page admin utilisateur
|
* [#315] Creation page admin utilisateur
|
||||||
* [#317] Admin modification creation transporteur
|
* [#317] Admin modification creation transporteur
|
||||||
* [#318] Affichage modification reception terminée
|
* [#318] Affichage modification reception terminée
|
||||||
* [#313] Admin modification creation fournisseur
|
* [#320] Affichage modification reception terminée suite
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.0.37'
|
app.version: '0.0.38'
|
||||||
|
|||||||
@@ -123,6 +123,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|||||||
183
frontend/components/reception/update-bovin.vue
Normal file
183
frontend/components/reception/update-bovin.vue
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
<template>
|
||||||
|
<form @submit.prevent="validate">
|
||||||
|
<div
|
||||||
|
class="flex flex-col items-center gap-16">
|
||||||
|
<div
|
||||||
|
class="flex flex-row gap-6 items-center">
|
||||||
|
<div
|
||||||
|
v-for="type in bovineType"
|
||||||
|
:key="type.id"
|
||||||
|
class="flex flex-row mb-2 gap-6 ">
|
||||||
|
<UiNumberInput
|
||||||
|
:label="type.label"
|
||||||
|
:code="type.code"
|
||||||
|
v-model="bovineQuantities[String(type.id)]"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
:placeholder="0"
|
||||||
|
:min="0"
|
||||||
|
:max="10"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class=" flex flex-row mb-2 gap-6">
|
||||||
|
<UiNumberInput
|
||||||
|
label="Autres"
|
||||||
|
v-model="otherQuantity"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
>Valider
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type {BovineTypeData} from "~/services/dto/bovine-type-data";
|
||||||
|
import {getBovineTypeList} from "~/services/bovine-type";
|
||||||
|
import {
|
||||||
|
createReceptionBovine,
|
||||||
|
deleteReceptionBovine,
|
||||||
|
getReceptionBovineList,
|
||||||
|
updateReceptionBovine
|
||||||
|
} from "~/services/reception-bovine";
|
||||||
|
import {computed, onMounted, reactive, ref, watch} from "vue";
|
||||||
|
import {getReception, updateReception} from "~/services/reception";
|
||||||
|
const toast = useToast()
|
||||||
|
const isLoadingBovineType = ref(false)
|
||||||
|
const bovineType = ref<BovineTypeData[]>([])
|
||||||
|
const bovineQuantities = reactive<Record<string, number | null>>({})
|
||||||
|
const otherQuantity = ref<number | null>(0)
|
||||||
|
const auth = useAuthStore()
|
||||||
|
const props = defineProps<{
|
||||||
|
idReception: number
|
||||||
|
}>()
|
||||||
|
const receptionId = props.idReception
|
||||||
|
const reception = await getReception(receptionId)
|
||||||
|
|
||||||
|
const receptionIri = computed(() =>
|
||||||
|
receptionId ? `/api/receptions/${receptionId}` : null
|
||||||
|
)
|
||||||
|
const totalBovines = computed(() => {
|
||||||
|
const base = Object.values(bovineQuantities).reduce((sum, value) => {
|
||||||
|
return sum + (value ?? 0)
|
||||||
|
}, 0)
|
||||||
|
return base + (otherQuantity.value ?? 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
const loadBovineType = async () => {
|
||||||
|
isLoadingBovineType.value = true
|
||||||
|
try {
|
||||||
|
bovineType.value = await getBovineTypeList()
|
||||||
|
} finally {
|
||||||
|
isLoadingBovineType.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await loadBovineType()
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => receptionId,
|
||||||
|
async (id) => {
|
||||||
|
if (!id || !receptionIri.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectionMap: Record<string, number | null> = {}
|
||||||
|
for (const type of bovineType.value) {
|
||||||
|
selectionMap[String(type.id)] = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await getReceptionBovineList(receptionIri.value)
|
||||||
|
for (const selection of existing) {
|
||||||
|
const bovineTypeId = String(selection.bovineType.id)
|
||||||
|
selectionMap[bovineTypeId] = selection.quantity ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key of Object.keys(bovineQuantities)) {
|
||||||
|
delete bovineQuantities[key]
|
||||||
|
}
|
||||||
|
Object.assign(bovineQuantities, selectionMap)
|
||||||
|
|
||||||
|
const existingOther = await reception.bovineDetail
|
||||||
|
const parsedOther =
|
||||||
|
typeof existingOther === 'string' && existingOther.trim() !== ''
|
||||||
|
? Number(existingOther)
|
||||||
|
: 0
|
||||||
|
otherQuantity.value = Number.isFinite(parsedOther) ? parsedOther : 0
|
||||||
|
},
|
||||||
|
{immediate: true}
|
||||||
|
)
|
||||||
|
|
||||||
|
async function syncBovineSelections(receptionIri: string) {
|
||||||
|
const existing = await getReceptionBovineList(receptionIri)
|
||||||
|
const existingMap = new Map<string, { id: number; quantity: number | null }>()
|
||||||
|
|
||||||
|
for (const selection of existing) {
|
||||||
|
const bovineTypeId = String(selection.bovineType.id)
|
||||||
|
existingMap.set(bovineTypeId, {
|
||||||
|
id: selection.id,
|
||||||
|
quantity: selection.quantity ?? 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supprime les entrées supprimées ou modifiées
|
||||||
|
for (const [bovineTypeId, entry] of existingMap.entries()) {
|
||||||
|
const selectedQuantity = bovineQuantities[bovineTypeId] ?? 0
|
||||||
|
if (!selectedQuantity) {
|
||||||
|
await deleteReceptionBovine(entry.id)
|
||||||
|
existingMap.delete(bovineTypeId)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedQuantity !== entry.quantity) {
|
||||||
|
await updateReceptionBovine(entry.id, {quantity: selectedQuantity})
|
||||||
|
existingMap.set(bovineTypeId, {
|
||||||
|
id: entry.id,
|
||||||
|
quantity: selectedQuantity
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crée les entrées manquantes
|
||||||
|
for (const [bovineTypeId, quantity] of Object.entries(bovineQuantities)) {
|
||||||
|
if (!quantity) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (existingMap.has(bovineTypeId)) {
|
||||||
|
// Déjà à jour
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
await createReceptionBovine({
|
||||||
|
reception: receptionIri,
|
||||||
|
bovineType: `/api/bovine_types/${bovineTypeId}`,
|
||||||
|
quantity
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function validate() {
|
||||||
|
// @TODO Ajouter un composable pour le toaster qui gère les key i18n
|
||||||
|
if (totalBovines.value > 52) {
|
||||||
|
toast.error({
|
||||||
|
title: 'Erreur',
|
||||||
|
message: ('Le total des bovins ne peut pas dépasser 52.')
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await syncBovineSelections(receptionIri.value)
|
||||||
|
|
||||||
|
await updateReception(receptionId, {
|
||||||
|
merchandiseType: null,
|
||||||
|
merchandiseDetail: null,
|
||||||
|
bovineDetail: otherQuantity.value ? String(otherQuantity.value) : null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
257
frontend/components/reception/update-merchandise.vue
Normal file
257
frontend/components/reception/update-merchandise.vue
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
<template>
|
||||||
|
<form @submit.prevent="validate">
|
||||||
|
<div class="flex flex-col items-center gap-16">
|
||||||
|
<div
|
||||||
|
class="flex flex-col gap-16 items-center w-full">
|
||||||
|
<UiTextInput
|
||||||
|
id="merchandise-type"
|
||||||
|
v-model="selectedMerchandiseTypeId"
|
||||||
|
label="Type de marchandises"
|
||||||
|
:value="reception.merchandiseType?.label"
|
||||||
|
wrapper-class="w-[550px]"
|
||||||
|
:disabled="true"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="merchandiseTypeId && isAutres"
|
||||||
|
class="flex flex-col w-full max-w-[550px]"
|
||||||
|
>
|
||||||
|
<UiTextInput
|
||||||
|
id="merchandise-detail"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
v-model="merchandiseDetail"
|
||||||
|
label="Préciser"
|
||||||
|
placeholder="Précisions complémentaires"
|
||||||
|
:maxlength="255"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="merchandiseTypeId && !isGranule"
|
||||||
|
class="flex gap-4 w-[550px] justify-evenly"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="building in buildings"
|
||||||
|
:key="building.id"
|
||||||
|
>
|
||||||
|
<UiCheckbox
|
||||||
|
v-model="selectedBuildingIds"
|
||||||
|
:value="String(building.id)"
|
||||||
|
:label="building.label"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
label-class="text-xl"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="merchandiseTypeId && isGranule"
|
||||||
|
class="flex flex-col gap-10 w-full max-w-[1100px]"
|
||||||
|
>
|
||||||
|
<div class="grid grid-cols-1 gap-10 md:grid-cols-4">
|
||||||
|
<div v-for="type in pelletTypes" :key="type.id" class="flex flex-col gap-4">
|
||||||
|
<p class="font-bold uppercase">{{ type.label }}</p>
|
||||||
|
<div
|
||||||
|
v-for="building in buildings"
|
||||||
|
:key="building.id"
|
||||||
|
class="flex items-center gap-2 text-lg"
|
||||||
|
>
|
||||||
|
<UiCheckbox
|
||||||
|
v-model="selectedPelletBuildingIds[String(type.id)]"
|
||||||
|
:value="String(building.id)"
|
||||||
|
:label="building.label"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
label-class="text-lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
>Valider
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {computed, onMounted, ref} from 'vue'
|
||||||
|
import {getBuildingList} from '~/services/building'
|
||||||
|
import {getMerchandiseTypeList} from '~/services/merchandise-type'
|
||||||
|
import type {MerchandiseTypeData} from '~/services/dto/merchandise-type-data'
|
||||||
|
import type {BuildingData} from '~/services/dto/building-data'
|
||||||
|
import type {PelletTypeData} from '~/services/dto/pellet-type-data'
|
||||||
|
import {getPelletTypeList} from '~/services/pellet-type'
|
||||||
|
import {
|
||||||
|
createReceptionPelletBuilding,
|
||||||
|
deleteReceptionPelletBuilding,
|
||||||
|
getReceptionPelletBuildingList
|
||||||
|
} from '~/services/reception-pellet-building'
|
||||||
|
import {MERCHANDISE_TYPE_CODES} from '~/utils/constants'
|
||||||
|
import {getReception, updateReception} from "~/services/reception";
|
||||||
|
|
||||||
|
const merchandiseTypes = ref<MerchandiseTypeData[]>([])
|
||||||
|
const buildings = ref<BuildingData[]>([])
|
||||||
|
const pelletTypes = ref<PelletTypeData[]>([])
|
||||||
|
const selectedMerchandiseTypeId = ref('')
|
||||||
|
const selectedBuildingIds = ref<string[]>([])
|
||||||
|
const selectedPelletBuildingIds = ref<Record<string, string[]>>({})
|
||||||
|
const merchandiseDetail = ref('')
|
||||||
|
const auth = useAuthStore()
|
||||||
|
const props = defineProps<{
|
||||||
|
idReception: number
|
||||||
|
}>()
|
||||||
|
const receptionId = props.idReception
|
||||||
|
const reception = await getReception(receptionId)
|
||||||
|
const merchandiseTypeId = await reception.receptionType?.id
|
||||||
|
|
||||||
|
// Extrait l'ID d'une relation depuis un IRI ou un objet complet.
|
||||||
|
const getRelationId = (value: unknown): string | null => {
|
||||||
|
if (!value) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
const match = value.match(/\/(\d+)$/)
|
||||||
|
return match ? match[1] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === 'object' && 'id' in value) {
|
||||||
|
const record = value as { id?: number | string }
|
||||||
|
if (typeof record.id === 'number') {
|
||||||
|
return String(record.id)
|
||||||
|
}
|
||||||
|
if (typeof record.id === 'string') {
|
||||||
|
return record.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type de marchandise sélectionné dans le select
|
||||||
|
const selectedMerchandiseType = computed(() =>
|
||||||
|
merchandiseTypes.value.find((type) => String(type.id) === selectedMerchandiseTypeId.value)
|
||||||
|
)
|
||||||
|
// Indique si le type est "Granulé"
|
||||||
|
const isGranule = computed(() => selectedMerchandiseType.value?.code === MERCHANDISE_TYPE_CODES.GRANULE)
|
||||||
|
// Indique si le type est "Autres"
|
||||||
|
const isAutres = computed(() => selectedMerchandiseType.value?.code === MERCHANDISE_TYPE_CODES.AUTRES)
|
||||||
|
|
||||||
|
// Charge les référentiels et hydrate le formulaire depuis la réception
|
||||||
|
onMounted(async () => {
|
||||||
|
const [merchandiseTypeList, buildingList, pelletTypeList] = await Promise.all([
|
||||||
|
getMerchandiseTypeList(),
|
||||||
|
getBuildingList(),
|
||||||
|
getPelletTypeList()
|
||||||
|
])
|
||||||
|
merchandiseTypes.value = merchandiseTypeList
|
||||||
|
buildings.value = buildingList
|
||||||
|
pelletTypes.value = pelletTypeList
|
||||||
|
|
||||||
|
const currentId = reception.merchandiseType?.id
|
||||||
|
if (currentId) {
|
||||||
|
selectedMerchandiseTypeId.value = String(currentId)
|
||||||
|
}
|
||||||
|
merchandiseDetail.value = reception.merchandiseDetail ?? ''
|
||||||
|
|
||||||
|
selectedBuildingIds.value =
|
||||||
|
reception.buildings?.map((building) => String(building.id)) ?? []
|
||||||
|
|
||||||
|
const existingPelletSelections = reception.pelletBuildings ?? []
|
||||||
|
const selectionMap: Record<string, string[]> = {}
|
||||||
|
for (const selection of existingPelletSelections) {
|
||||||
|
// L'API peut renvoyer les relations comme IRI ou comme objets selon le contexte.
|
||||||
|
const pelletTypeId = getRelationId(selection.pelletType)
|
||||||
|
const buildingId = getRelationId(selection.building)
|
||||||
|
if (!pelletTypeId || !buildingId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (!selectionMap[pelletTypeId]) {
|
||||||
|
selectionMap[pelletTypeId] = []
|
||||||
|
}
|
||||||
|
selectionMap[pelletTypeId].push(buildingId)
|
||||||
|
}
|
||||||
|
for (const pelletType of pelletTypes.value) {
|
||||||
|
const key = String(pelletType.id)
|
||||||
|
if (!selectionMap[key]) {
|
||||||
|
selectionMap[key] = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selectedPelletBuildingIds.value = selectionMap
|
||||||
|
})
|
||||||
|
// Enregistre les sélections et passe à l'étape suivante
|
||||||
|
async function validate() {
|
||||||
|
|
||||||
|
const receptionIri = `/api/receptions/${reception.id}`
|
||||||
|
|
||||||
|
await updateReception(reception.id, {
|
||||||
|
merchandiseDetail: isAutres.value ? merchandiseDetail.value.trim() : null,
|
||||||
|
buildings: isGranule.value
|
||||||
|
? []
|
||||||
|
: selectedBuildingIds.value.map((id) => `/api/buildings/${id}`),
|
||||||
|
bovineDetail: null,
|
||||||
|
bovinesTypes: null,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (isGranule.value) {
|
||||||
|
await syncPelletSelections(receptionIri)
|
||||||
|
} else {
|
||||||
|
await clearPelletSelections(receptionIri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supprime toutes les associations granulés/bâtiments existantes
|
||||||
|
async function clearPelletSelections(receptionIri: string) {
|
||||||
|
const existing = await getReceptionPelletBuildingList(receptionIri)
|
||||||
|
for (const selection of existing) {
|
||||||
|
await deleteReceptionPelletBuilding(selection.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Synchronise les associations granulés/bâtiments avec l'état du formulaire
|
||||||
|
async function syncPelletSelections(receptionIri: string) {
|
||||||
|
const existing = await getReceptionPelletBuildingList(receptionIri)
|
||||||
|
const existingMap = new Map<string, number>()
|
||||||
|
for (const selection of existing) {
|
||||||
|
// Construit la table de correspondance avec des IDs normalisés pour éviter les doublons.
|
||||||
|
const pelletTypeId = getRelationId(selection.pelletType)
|
||||||
|
const buildingId = getRelationId(selection.building)
|
||||||
|
if (!pelletTypeId || !buildingId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const key = `${pelletTypeId}:${buildingId}`
|
||||||
|
existingMap.set(key, selection.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
const desiredEntries: Array<{ pelletTypeId: string; buildingId: string }> = []
|
||||||
|
for (const [pelletTypeId, buildingIds] of Object.entries(selectedPelletBuildingIds.value)) {
|
||||||
|
for (const buildingId of buildingIds) {
|
||||||
|
desiredEntries.push({pelletTypeId, buildingId})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const desiredKeys = new Set(desiredEntries.map(
|
||||||
|
(entry) => `${entry.pelletTypeId}:${entry.buildingId}`
|
||||||
|
))
|
||||||
|
|
||||||
|
for (const [key, id] of existingMap.entries()) {
|
||||||
|
if (!desiredKeys.has(key)) {
|
||||||
|
await deleteReceptionPelletBuilding(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const entry of desiredEntries) {
|
||||||
|
const key = `${entry.pelletTypeId}:${entry.buildingId}`
|
||||||
|
if (!existingMap.has(key)) {
|
||||||
|
await createReceptionPelletBuilding({
|
||||||
|
reception: receptionIri,
|
||||||
|
pelletType: `/api/pellet_types/${entry.pelletTypeId}`,
|
||||||
|
building: `/api/buildings/${entry.buildingId}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
74
frontend/components/reception/update-weight.vue
Normal file
74
frontend/components/reception/update-weight.vue
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<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"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
:min="0"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UiNumberInput
|
||||||
|
label="Pesée à plein"
|
||||||
|
v-model="form.weights[1].weight"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
:min="0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
>
|
||||||
|
Valider
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type {ReceptionFormWeight} from '~/services/dto/reception-data'
|
||||||
|
import { getReception } from '~/services/reception'
|
||||||
|
import {updateWeight} from "~/services/weight";
|
||||||
|
import {useAuthStore} from "~/stores/auth";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
idReception: number
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const idReception = props.idReception
|
||||||
|
const auth = useAuthStore()
|
||||||
|
|
||||||
|
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(idReception)
|
||||||
|
hydrateFromReception(reception)
|
||||||
|
})
|
||||||
|
|
||||||
|
async function validate() {
|
||||||
|
|
||||||
|
for (const weight of form.weights) {
|
||||||
|
if (weight.id) {
|
||||||
|
await updateWeight(weight.id, {weight: weight.weight})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
<template>
|
|
||||||
<form @submit.prevent="validate">
|
|
||||||
<div class="flex items-center justify-between gap-10">
|
|
||||||
<h1 class="text-3xl font-bold uppercase">
|
|
||||||
{{ supplierId ? "Modifications du fournisseur" : "Ajout d'un fournisseur" }}
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<button
|
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
type="submit"
|
|
||||||
:disabled="isLoading"
|
|
||||||
>
|
|
||||||
{{ supplierId ? "Sauvegarder" : "Ajouter" }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-y-16 gap-x-12 mb-16">
|
|
||||||
<UiTextInput id="supplier-name" v-model="form.name" label="Nom du fournisseur" />
|
|
||||||
<UiTextInput id="supplier-email" v-model="form.email" label="Email" />
|
|
||||||
<UiTextInput id="supplier-phone" v-model="form.phone" label="Téléphone" />
|
|
||||||
|
|
||||||
<UiTextInput id="supplier-street" v-model="form.addresses[0].street" label="Rue" />
|
|
||||||
<UiTextInput id="supplier-street2" v-model="form.addresses[0].street2" label="Complément" />
|
|
||||||
<UiTextInput id="supplier-postalCode" v-model="form.addresses[0].postalCode" label="Code postal" />
|
|
||||||
<UiTextInput id="supplier-city" v-model="form.addresses[0].city" label="Ville" />
|
|
||||||
<UiTextInput id="supplier-country" v-model="form.addresses[0].countryCode" label="Pays" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p v-if="errorMsg" class="text-red-600 mt-4">{{ errorMsg }}</p>
|
|
||||||
</form>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { computed, reactive, ref, watch } from "vue"
|
|
||||||
import { createSupplier, getSupplier, updateSupplier } from "~/services/supplier"
|
|
||||||
import { createAddress, updateAddress, type AddressPayload } from "~/services/address"
|
|
||||||
import type { SupplierData, SupplierFormData, SupplierPayload } from "~/services/dto/supplier-data"
|
|
||||||
import type { AddressFormData } from "~/services/dto/address-data"
|
|
||||||
|
|
||||||
definePageMeta({ layout: "admin" })
|
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const resolveId = (param: unknown) => {
|
|
||||||
const idStr = Array.isArray(param) ? param[0] : param
|
|
||||||
if (!idStr) return null
|
|
||||||
const id = Number(idStr)
|
|
||||||
return Number.isFinite(id) ? id : null
|
|
||||||
}
|
|
||||||
|
|
||||||
const supplierId = computed(() => resolveId(route.params.id))
|
|
||||||
|
|
||||||
const isLoading = ref(false)
|
|
||||||
const errorMsg = ref<string | null>(null)
|
|
||||||
|
|
||||||
const emptyAddress = (): AddressFormData => ({
|
|
||||||
id: null,
|
|
||||||
label: "",
|
|
||||||
street: "",
|
|
||||||
street2: null,
|
|
||||||
postalCode: "",
|
|
||||||
city: "",
|
|
||||||
countryCode: "",
|
|
||||||
})
|
|
||||||
|
|
||||||
const form = reactive<SupplierFormData>({
|
|
||||||
name: "",
|
|
||||||
email: "",
|
|
||||||
phone: "",
|
|
||||||
addresses: [emptyAddress()],
|
|
||||||
})
|
|
||||||
|
|
||||||
const hydrateFromSupplier = (supplier: SupplierData | null) => {
|
|
||||||
if (!supplier) return
|
|
||||||
|
|
||||||
form.name = supplier.name ?? ""
|
|
||||||
form.email = supplier.email ?? ""
|
|
||||||
form.phone = supplier.phone ?? ""
|
|
||||||
|
|
||||||
if (!Array.isArray(supplier.addresses) || supplier.addresses.length === 0) return
|
|
||||||
const a0 = supplier.addresses[0]
|
|
||||||
|
|
||||||
if (typeof a0 === "string") return
|
|
||||||
|
|
||||||
form.addresses[0].id = a0.id ?? null
|
|
||||||
form.addresses[0].label = a0.label ?? ""
|
|
||||||
form.addresses[0].street = a0.street ?? ""
|
|
||||||
form.addresses[0].street2 = a0.street2 ?? null
|
|
||||||
form.addresses[0].postalCode = a0.postalCode ?? ""
|
|
||||||
form.addresses[0].city = a0.city ?? ""
|
|
||||||
form.addresses[0].countryCode = a0.countryCode ?? ""
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => supplierId.value,
|
|
||||||
async (id) => {
|
|
||||||
if (id === null) return
|
|
||||||
isLoading.value = true
|
|
||||||
try {
|
|
||||||
const supplier = await getSupplier(id)
|
|
||||||
hydrateFromSupplier(supplier)
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
async function validate() {
|
|
||||||
if (isLoading.value) return
|
|
||||||
isLoading.value = true
|
|
||||||
errorMsg.value = null
|
|
||||||
|
|
||||||
try {
|
|
||||||
const name = form.name.trim()
|
|
||||||
const email = (form.email ?? "").trim() || null
|
|
||||||
const phone = (form.phone ?? "").trim() || null
|
|
||||||
|
|
||||||
const a0 = form.addresses[0]
|
|
||||||
|
|
||||||
const label = a0.label.trim() || name || "Adresse"
|
|
||||||
|
|
||||||
const addressPayload: AddressPayload = {
|
|
||||||
label,
|
|
||||||
street: a0.street.trim(),
|
|
||||||
street2: a0.street2?.trim() || null,
|
|
||||||
postalCode: a0.postalCode.trim(),
|
|
||||||
city: a0.city.trim(),
|
|
||||||
countryCode: a0.countryCode.trim(),
|
|
||||||
}
|
|
||||||
|
|
||||||
let addressId: number
|
|
||||||
if (a0.id) {
|
|
||||||
const updated = await updateAddress(a0.id, addressPayload)
|
|
||||||
addressId = updated.id
|
|
||||||
} else {
|
|
||||||
const created = await createAddress(addressPayload)
|
|
||||||
addressId = created.id
|
|
||||||
a0.id = addressId
|
|
||||||
}
|
|
||||||
const supplierPayload: SupplierPayload = {
|
|
||||||
name,
|
|
||||||
email,
|
|
||||||
phone,
|
|
||||||
addresses: [`/api/addresses/${addressId}`],
|
|
||||||
}
|
|
||||||
|
|
||||||
if (supplierId.value !== null) {
|
|
||||||
await updateSupplier(supplierId.value, supplierPayload)
|
|
||||||
} else {
|
|
||||||
await createSupplier(supplierPayload)
|
|
||||||
}
|
|
||||||
|
|
||||||
await router.push("/admin/supplier/supplier-list")
|
|
||||||
} catch (e) {
|
|
||||||
errorMsg.value = "Erreur lors de l’enregistrement."
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</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"
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
<template>
|
|
||||||
<SupplierForm/>
|
|
||||||
</template>
|
|
||||||
<script setup lang="ts">
|
|
||||||
definePageMeta({
|
|
||||||
layout: 'admin'
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<h1 class="text-3xl font-bold uppercase">Fournisseurs</h1>
|
<h1 class="text-3xl font-bold uppercase"> Fournisseurs </h1>
|
||||||
<NuxtLink
|
<NuxtLink to="/admin/supplier"
|
||||||
to="/admin/supplier"
|
class="flex items-center justify-center text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
||||||
class="flex items-center justify-center text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
>
|
>
|
||||||
Ajouter
|
Ajouter
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-6 border border-slate-200 mb-16">
|
<div class="mt-6 border border-slate-200 mb-16">
|
||||||
<div class="max-h-96 overflow-y-auto">
|
<div class="max-h-96 overflow-y-auto">
|
||||||
<div
|
<div
|
||||||
class="sticky top-0 z-10 grid grid-cols-7 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide"
|
class="sticky top-0 z-10 grid grid-cols-6 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide"
|
||||||
>
|
>
|
||||||
<div>Nom</div>
|
<div>Nom</div>
|
||||||
<div>Mail</div>
|
<div>Mail</div>
|
||||||
@@ -20,49 +18,31 @@
|
|||||||
<div>Complément</div>
|
<div>Complément</div>
|
||||||
<div>Code Postal</div>
|
<div>Code Postal</div>
|
||||||
<div>Ville</div>
|
<div>Ville</div>
|
||||||
<div>Pays</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="supplierList.length === 0" class="px-4 py-6 text-slate-400">
|
|
||||||
Aucun fournisseur.
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-for="supplier in supplierList" :key="supplier.id">
|
<div v-for="supplier in supplierList" :key="supplier.id">
|
||||||
<div
|
<template v-if="supplier.addresses?.length">
|
||||||
v-if="!supplier.addresses || supplier.addresses.length === 0"
|
|
||||||
class="grid grid-cols-7 border-t gap-4 px-4 py-2 text-slate-400"
|
|
||||||
>
|
|
||||||
<div class="truncate">{{ supplier.name }}</div>
|
|
||||||
<div class="truncate">{{ supplier.email }}</div>
|
|
||||||
<div class="col-span-5">—</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<template v-else-if="isAddressObjectArray(supplier.addresses)">
|
|
||||||
<div
|
<div
|
||||||
v-for="(address, idx) in supplier.addresses"
|
v-for="addr in supplier.addresses"
|
||||||
:key="address.id ?? `${supplier.id}-${idx}-${address.street}-${address.postalCode}`"
|
:key="addr.id"
|
||||||
class="grid grid-cols-7 hover:bg-slate-50 border-t gap-4 px-4 py-2 cursor-pointer"
|
class="grid grid-cols-6 hover:bg-slate-50 border-t gap-4 px-4 py-2"
|
||||||
@click="goToSupplier(supplier.id)"
|
@click="goToSupplier(supplier.id)"
|
||||||
>
|
>
|
||||||
<div class="truncate">{{ supplier.name }}</div>
|
<div class="truncate">
|
||||||
<div class="truncate">{{ supplier.email }}</div>
|
{{ supplier.name }}
|
||||||
<div class="truncate">{{ address.street }}</div>
|
</div>
|
||||||
<div class="truncate">{{ address.street2 }}</div>
|
<div class="truncate">
|
||||||
<div>{{ address.postalCode }}</div>
|
{{ supplier.email }}
|
||||||
<div class="uppercase truncate">{{ address.city }}</div>
|
</div>
|
||||||
<div class="uppercase truncate">{{ address.countryCode }}</div>
|
<div class="truncate">
|
||||||
</div>
|
{{ addr.street }}
|
||||||
</template>
|
</div>
|
||||||
|
<div class="truncate">
|
||||||
<template v-else>
|
{{ addr.street2 }}
|
||||||
<div
|
</div>
|
||||||
class="grid grid-cols-7 hover:bg-slate-50 border-t gap-4 px-4 py-2 cursor-pointer"
|
<div>{{ addr.postalCode }}</div>
|
||||||
@click="goToSupplier(supplier.id)"
|
<div class="uppercase truncate">
|
||||||
>
|
{{ addr.city }}
|
||||||
<div class="truncate">{{ supplier.name }}</div>
|
|
||||||
<div class="truncate">{{ supplier.email }}</div>
|
|
||||||
<div class="col-span-5 text-slate-400">
|
|
||||||
Adresses non chargées (IRIs)
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -72,26 +52,23 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getSupplierList } from "~/services/supplier"
|
import type {SupplierData} from "~/services/dto/supplier-data"
|
||||||
import type { SupplierData } from "~/services/dto/supplier-data"
|
import {getSupplierList} from "~/services/supplier"
|
||||||
import type { AddressFormData } from "~/services/dto/address-data"
|
|
||||||
|
|
||||||
definePageMeta({ layout: "admin" })
|
definePageMeta({layout: "admin"})
|
||||||
|
|
||||||
const supplierList = ref<SupplierData[]>([])
|
const supplierList = ref<SupplierData[]>([])
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
|
||||||
const goToSupplier = (id: number) => {
|
const goToSupplier = (id: number) => {
|
||||||
router.push(`/admin/supplier/${id}`)
|
router.push(`/admin/supplier/${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAddressObjectArray(value: SupplierData["addresses"]): value is AddressFormData[] {
|
|
||||||
if (!Array.isArray(value) || value.length === 0) return false
|
|
||||||
const v0 = value[0]
|
|
||||||
return typeof v0 === "object" && v0 !== null && "street" in v0 && "postalCode" in v0
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
supplierList.value = await getSupplierList()
|
supplierList.value = (await getSupplierList(false)) ?? []
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] justify-self-end"
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] justify-self-end"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
>Enregistrer
|
>Enregistrer
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -119,6 +120,28 @@
|
|||||||
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" @click="isBtWeight = true" >pesées</h1>
|
||||||
|
<h1 class="font-bold text-5xl uppercase col-start-2 row-start-1" @click="isBtWeight = false">{{isMerchandise ? "Marchandises" : "Bovins"}}</h1>
|
||||||
|
</div>
|
||||||
|
<update-weight
|
||||||
|
v-if="isBtWeight"
|
||||||
|
:idReception="idReception"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<update-merchandise
|
||||||
|
v-else-if="isMerchandise"
|
||||||
|
:idReception="idReception"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<update-bovin
|
||||||
|
v-else
|
||||||
|
:idReception="idReception"
|
||||||
|
:disabled="!auth.isAdmin"
|
||||||
|
/>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -141,6 +164,9 @@ 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";
|
||||||
|
import UpdateMerchandise from "~/components/reception/update-merchandise.vue";
|
||||||
|
import UpdateBovin from "~/components/reception/update-bovin.vue";
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const receptionStore = useReceptionStore()
|
const receptionStore = useReceptionStore()
|
||||||
@@ -179,6 +205,8 @@ const idReception = Number(route.params.id)
|
|||||||
const receptionLoad = await getReception(idReception)
|
const receptionLoad = await getReception(idReception)
|
||||||
const receptionType = receptionLoad.receptionType
|
const receptionType = receptionLoad.receptionType
|
||||||
const auth = useAuthStore()
|
const auth = useAuthStore()
|
||||||
|
const isBtWeight = ref(true)
|
||||||
|
const isMerchandise = ref(receptionType.code === 'MARCHANDISES')
|
||||||
|
|
||||||
// Transporteur sélectionné dans le formulaire
|
// Transporteur sélectionné dans le formulaire
|
||||||
const selectedCarrier = computed(() =>
|
const selectedCarrier = computed(() =>
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
import { useApi } from '~/composables/useApi'
|
|
||||||
import type { AddressData } from '~/services/dto/address-data'
|
|
||||||
export interface AddressPayload {
|
|
||||||
label: string
|
|
||||||
street: string
|
|
||||||
street2?: string | null
|
|
||||||
postalCode: string
|
|
||||||
city: string
|
|
||||||
countryCode: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AddressData extends AddressPayload {
|
|
||||||
id: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createAddress(
|
|
||||||
payload: AddressPayload
|
|
||||||
): Promise<AddressData> {
|
|
||||||
const api = useApi()
|
|
||||||
|
|
||||||
return await api.post<AddressData>('addresses', payload, {
|
|
||||||
toastErrorKey: 'errors.address.create',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateAddress(
|
|
||||||
id: number,
|
|
||||||
payload: AddressPayload
|
|
||||||
): Promise<AddressData> {
|
|
||||||
const api = useApi()
|
|
||||||
|
|
||||||
return await api.patch<AddressData>(`addresses/${id}`, payload, {
|
|
||||||
toastErrorKey: 'errors.address.update',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -6,14 +6,5 @@ export interface AddressData {
|
|||||||
postalCode: string
|
postalCode: string
|
||||||
city: string
|
city: string
|
||||||
countryCode: string
|
countryCode: string
|
||||||
}
|
fullAddress?: string
|
||||||
|
|
||||||
export interface AddressFormData {
|
|
||||||
id?: number | null
|
|
||||||
label: string
|
|
||||||
street: string
|
|
||||||
street2?: string | null
|
|
||||||
postalCode: string
|
|
||||||
city: string
|
|
||||||
countryCode: string
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,25 +1,9 @@
|
|||||||
import type { AddressFormData } from "~/services/dto/address-data"
|
import type { AddressData } from '~/services/dto/address-data'
|
||||||
|
|
||||||
export type SupplierAddresses = AddressFormData[] | string[]
|
|
||||||
|
|
||||||
export interface SupplierData {
|
export interface SupplierData {
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
email?: string | null
|
email?: string | null
|
||||||
phone?: string | null
|
phone?: string | null
|
||||||
addresses: SupplierAddresses
|
addresses?: AddressData[] | null
|
||||||
}
|
|
||||||
|
|
||||||
export interface SupplierFormData {
|
|
||||||
name: string
|
|
||||||
email?: string
|
|
||||||
phone?: string
|
|
||||||
addresses: AddressFormData[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SupplierPayload = {
|
|
||||||
name: string
|
|
||||||
email?: string | null
|
|
||||||
phone?: string | null
|
|
||||||
addresses: string[]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,23 @@
|
|||||||
import { useApi } from "~/composables/useApi"
|
import { useApi } from '~/composables/useApi'
|
||||||
import type { SupplierData, SupplierPayload } from "~/services/dto/supplier-data"
|
import type { SupplierData } from '~/services/dto/supplier-data'
|
||||||
|
|
||||||
export type SupplierListResponse =
|
export type SupplierListResponse =
|
||||||
| SupplierData[]
|
| SupplierData[]
|
||||||
| { "hydra:member"?: SupplierData[] }
|
| { 'hydra:member'?: SupplierData[] }
|
||||||
|
|
||||||
export async function getSupplierList(): Promise<SupplierData[]> {
|
export async function getSupplierList(): Promise<SupplierData[]> {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
const response = await api.get<SupplierListResponse>("suppliers", {}, {
|
const response = await api.get<SupplierListResponse>('suppliers', {}, {
|
||||||
toastErrorKey: "errors.supplier.list",
|
toastErrorKey: 'errors.supplier.list'
|
||||||
})
|
})
|
||||||
|
|
||||||
if (Array.isArray(response)) return response
|
if (Array.isArray(response)) {
|
||||||
if (response && typeof response === "object" && Array.isArray(response["hydra:member"])) {
|
return response
|
||||||
return response["hydra:member"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||||
|
return response['hydra:member']
|
||||||
|
}
|
||||||
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSupplier(id: number): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.get<SupplierData>(`suppliers/${id}`, {}, {
|
|
||||||
toastErrorKey: "errors.supplier.fetch",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateSupplier(id: number, payload: SupplierPayload): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.patch<SupplierData>(`suppliers/${id}`, payload, {
|
|
||||||
toastErrorKey: "errors.supplier.update",
|
|
||||||
toastSuccessKey: "success.supplier.update",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createSupplier(payload: SupplierPayload): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.post<SupplierData>("suppliers", payload, {
|
|
||||||
toastErrorKey: "errors.supplier.create",
|
|
||||||
toastSuccessKey: "success.supplier.create",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ namespace App\Entity;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
use ApiPlatform\Metadata\Patch;
|
|
||||||
use ApiPlatform\Metadata\Post;
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -25,16 +23,6 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
new GetCollection(
|
new GetCollection(
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
normalizationContext: ['groups' => ['address:read']],
|
||||||
),
|
),
|
||||||
new Post(
|
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
|
||||||
denormalizationContext: ['groups' => ['address:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
new Patch(
|
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
|
||||||
denormalizationContext: ['groups' => ['address:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_USER')",
|
||||||
)]
|
)]
|
||||||
@@ -47,27 +35,27 @@ class Address
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private string $label = '';
|
private string $label = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private string $street = '';
|
private string $street = '';
|
||||||
|
|
||||||
#[ORM\Column(name: 'street2', length: 180, nullable: true)]
|
#[ORM\Column(name: 'street2', length: 180, nullable: true)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private ?string $street2 = null;
|
private ?string $street2 = null;
|
||||||
|
|
||||||
#[ORM\Column(name: 'postal_code', length: 20)]
|
#[ORM\Column(name: 'postal_code', length: 20)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private string $postalCode = '';
|
private string $postalCode = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private string $city = '';
|
private string $city = '';
|
||||||
|
|
||||||
#[ORM\Column(name: 'country_code', length: 2)]
|
#[ORM\Column(name: 'country_code', length: 2)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read'])]
|
||||||
private string $countryCode = '';
|
private string $countryCode = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ use ApiPlatform\Metadata\ApiProperty;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
use ApiPlatform\Metadata\Patch;
|
|
||||||
use ApiPlatform\Metadata\Post;
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -26,16 +24,6 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
new GetCollection(
|
new GetCollection(
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
normalizationContext: ['groups' => ['supplier:read']],
|
||||||
),
|
),
|
||||||
new Post(
|
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
|
||||||
denormalizationContext: ['groups' => ['supplier:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
new Patch(
|
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
|
||||||
denormalizationContext: ['groups' => ['supplier:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_USER')",
|
||||||
)]
|
)]
|
||||||
@@ -48,15 +36,15 @@ class Supplier
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private string $name = '';
|
private string $name = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 180, nullable: true)]
|
#[ORM\Column(length: 180, nullable: true)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 40, nullable: true)]
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private ?string $phone = null;
|
private ?string $phone = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +52,7 @@ class Supplier
|
|||||||
*/
|
*/
|
||||||
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'suppliers')]
|
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'suppliers')]
|
||||||
#[ORM\JoinTable(name: 'supplier_address')]
|
#[ORM\JoinTable(name: 'supplier_address')]
|
||||||
#[Groups(['supplier:read', 'supplier:write'])]
|
#[Groups(['supplier:read'])]
|
||||||
#[ApiProperty(readableLink: true)]
|
#[ApiProperty(readableLink: true)]
|
||||||
private Collection $addresses;
|
private Collection $addresses;
|
||||||
|
|
||||||
@@ -121,30 +109,4 @@ class Supplier
|
|||||||
{
|
{
|
||||||
return $this->addresses;
|
return $this->addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAddresses(iterable $addresses): self
|
|
||||||
{
|
|
||||||
$this->addresses->clear();
|
|
||||||
foreach ($addresses as $address) {
|
|
||||||
$this->addAddress($address);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAddress(Address $address): self
|
|
||||||
{
|
|
||||||
if (!$this->addresses->contains($address)) {
|
|
||||||
$this->addresses->add($address);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeAddress(Address $address): self
|
|
||||||
{
|
|
||||||
$this->addresses->removeElement($address);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user