mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-22 14:38:19 +02:00
Merge pull request #410 from R0m1k3/1.1
Update invoice editing to correctly save financial amounts
This commit is contained in:
1 file changed
+22
-17
+22
-17
@@ -128,6 +128,9 @@ export default function Avoirs() {
|
|||||||
// États pour le système de vérification de facture
|
// États pour le système de vérification de facture
|
||||||
const [avoirVerificationResults, setAvoirVerificationResults] = useState<Record<number, any>>({});
|
const [avoirVerificationResults, setAvoirVerificationResults] = useState<Record<number, any>>({});
|
||||||
const [verifyingAvoirs, setVerifyingAvoirs] = useState<Set<number>>(new Set());
|
const [verifyingAvoirs, setVerifyingAvoirs] = useState<Set<number>>(new Set());
|
||||||
|
|
||||||
|
// ✅ État local pour le champ montant d'édition pour éviter les conflits avec React Hook Form
|
||||||
|
const [editAmountValue, setEditAmountValue] = useState<string>("");
|
||||||
// Utiliser le contexte global du magasin
|
// Utiliser le contexte global du magasin
|
||||||
const { selectedStoreId } = useStore();
|
const { selectedStoreId } = useStore();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@@ -383,12 +386,21 @@ export default function Avoirs() {
|
|||||||
// Handle edit form submission
|
// Handle edit form submission
|
||||||
const onEditSubmit = (data: AvoirFormData) => {
|
const onEditSubmit = (data: AvoirFormData) => {
|
||||||
if (selectedAvoir) {
|
if (selectedAvoir) {
|
||||||
|
// ✅ Utiliser la valeur de l'état local pour le montant
|
||||||
|
const finalAmount = editAmountValue === "" ? undefined : parseFloat(editAmountValue);
|
||||||
|
const finalData = {
|
||||||
|
...data,
|
||||||
|
amount: finalAmount
|
||||||
|
};
|
||||||
|
|
||||||
console.log('💰 Editing avoir - Form data sent:', {
|
console.log('💰 Editing avoir - Form data sent:', {
|
||||||
originalCommercial: selectedAvoir.commercialProcessed,
|
originalCommercial: selectedAvoir.commercialProcessed,
|
||||||
formCommercial: data.commercialProcessed,
|
formCommercial: finalData.commercialProcessed,
|
||||||
fullData: data
|
editAmountValue,
|
||||||
|
finalAmount,
|
||||||
|
fullData: finalData
|
||||||
});
|
});
|
||||||
editAvoirMutation.mutate({ id: selectedAvoir.id, data });
|
editAvoirMutation.mutate({ id: selectedAvoir.id, data: finalData });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -397,11 +409,14 @@ export default function Avoirs() {
|
|||||||
if (!avoir || !avoir.id) return;
|
if (!avoir || !avoir.id) return;
|
||||||
|
|
||||||
setSelectedAvoir(avoir);
|
setSelectedAvoir(avoir);
|
||||||
|
// ✅ Initialiser l'état local du montant
|
||||||
|
setEditAmountValue(avoir.amount !== null && avoir.amount !== undefined ? avoir.amount.toString() : "");
|
||||||
|
|
||||||
editForm.reset({
|
editForm.reset({
|
||||||
supplierId: avoir.supplierId || 0,
|
supplierId: avoir.supplierId || 0,
|
||||||
groupId: avoir.groupId || 0,
|
groupId: avoir.groupId || 0,
|
||||||
invoiceReference: avoir.invoiceReference || "",
|
invoiceReference: avoir.invoiceReference || "",
|
||||||
amount: avoir.amount ?? undefined, // ✅ Convertir null en undefined pour permettre la suppression
|
amount: avoir.amount ?? undefined,
|
||||||
comment: avoir.comment || "",
|
comment: avoir.comment || "",
|
||||||
commercialProcessed: avoir.commercialProcessed || false,
|
commercialProcessed: avoir.commercialProcessed || false,
|
||||||
status: avoir.status || "En attente de demande",
|
status: avoir.status || "En attente de demande",
|
||||||
@@ -1361,21 +1376,11 @@ export default function Avoirs() {
|
|||||||
type="number"
|
type="number"
|
||||||
step="0.01"
|
step="0.01"
|
||||||
placeholder="Montant en euros (optionnel)"
|
placeholder="Montant en euros (optionnel)"
|
||||||
value={field.value ?? ""}
|
value={editAmountValue}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = e.target.value;
|
// ✅ Utiliser seulement l'état local, complètement séparé de React Hook Form
|
||||||
if (value === "") {
|
setEditAmountValue(e.target.value);
|
||||||
field.onChange(undefined);
|
|
||||||
} else {
|
|
||||||
const num = parseFloat(value);
|
|
||||||
if (!isNaN(num)) {
|
|
||||||
field.onChange(num);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
onBlur={field.onBlur}
|
|
||||||
name={field.name}
|
|
||||||
ref={field.ref}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
Reference in new issue
Block a user