- Ajout page infrastructure/bovine avec CRUD - Refacto BuildingCase (suppression Statut, simplification) - Commande EnrichBovinesCommand pour enrichir les données bovins - 4 migrations Doctrine - Mise à jour composables shipment/weighing - Mise à jour README et CHANGELOG Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import type { Ref } from 'vue'
|
|
import { useWeighing } from '~/composables/useWeighing'
|
|
import { usePdfPrinter } from '~/composables/usePdfPrinter'
|
|
import type { WeightData } from '~/services/dto/weight-data'
|
|
|
|
interface UseWeighingStepOptions {
|
|
mode: 'gross' | 'tare'
|
|
entity: Ref<any>
|
|
entityName: 'reception' | 'shipment'
|
|
apiResource: string
|
|
titleLabel: string
|
|
isFinal: boolean
|
|
getWeightFromScale: () => Promise<WeightData>
|
|
updateEntity: (id: number, payload: any) => Promise<any>
|
|
loadEntity: (id: number) => Promise<any>
|
|
clearEntity: () => void
|
|
buildReceiptFilename: (entity: any) => string
|
|
}
|
|
|
|
export const useWeighingStep = (options: UseWeighingStepOptions) => {
|
|
const router = useRouter()
|
|
const { printPdf } = usePdfPrinter()
|
|
|
|
const {
|
|
weightData,
|
|
currentWeightEntry,
|
|
displayWeight,
|
|
displayDsd,
|
|
title,
|
|
showLoadingBox,
|
|
fetchWeight,
|
|
saveWeight,
|
|
saveWeightDraft
|
|
} = useWeighing({
|
|
mode: options.mode,
|
|
entity: options.entity,
|
|
entityName: options.entityName,
|
|
apiResource: options.apiResource,
|
|
titleLabel: options.titleLabel,
|
|
isFinal: options.isFinal,
|
|
getWeightFromScale: options.getWeightFromScale,
|
|
updateEntity: options.updateEntity,
|
|
loadEntity: options.loadEntity
|
|
})
|
|
|
|
const showGenerateReceipt = computed(
|
|
() => options.isFinal && displayWeight.value !== null
|
|
)
|
|
|
|
const printReceipt = async () => {
|
|
if (!import.meta.client || !options.entity.value) return
|
|
|
|
await saveWeight()
|
|
const entity = options.entity.value
|
|
const filename = options.buildReceiptFilename(entity)
|
|
await printPdf(`/${options.apiResource}/${entity.id}/receipt`, filename)
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 600))
|
|
|
|
const result = await options.updateEntity(entity.id, { isValid: true })
|
|
if (!result) return
|
|
|
|
options.clearEntity()
|
|
await router.push('/')
|
|
}
|
|
|
|
return {
|
|
weightData,
|
|
currentWeightEntry,
|
|
displayWeight,
|
|
displayDsd,
|
|
title,
|
|
showLoadingBox,
|
|
fetchWeight,
|
|
saveWeight,
|
|
saveWeightDraft,
|
|
showGenerateReceipt,
|
|
printReceipt
|
|
}
|
|
}
|