fix: corriger le suivi médical et les styles publics

This commit is contained in:
Alexandre NOEL 2026-09-22 18:05:38 +02:00
commit a55d27935f
15 changed files with 206 additions and 24 deletions

View file

@ -400,6 +400,7 @@ trait AnimalMedicalActions
}
$id = (int) ($_POST['animal_id'] ?? 0);
$entryId = (int) ($_POST['entry_id'] ?? 0);
$medId = (int) ($_POST['medication_id'] ?? 0);
$createMedication = !empty($_POST['create_medication']);
if ($id <= 0 || (!$createMedication && $medId <= 0)) {
@ -429,6 +430,15 @@ trait AnimalMedicalActions
}
$db = DB::pdo();
if ($entryId > 0) {
$existing = $db->prepare('SELECT 1 FROM treatments WHERE id=:entry AND animal_id=:animal');
$existing->execute([':entry' => $entryId, ':animal' => $id]);
if (!$existing->fetchColumn()) {
http_response_code(404);
echo h(t('error.not_found'));
return;
}
}
if ($createMedication) {
$medicationName = trim((string) ($_POST['new_medication_name'] ?? ''));
$medicationMolecule = trim((string) ($_POST['new_medication_molecule'] ?? ''));
@ -475,12 +485,7 @@ trait AnimalMedicalActions
return;
}
$vet_name = $vetContact['name'] ?? $vet_name;
$stmt = $db->prepare('
INSERT INTO treatments(animal_id, medication_id, route, dose_text, start_date, end_date, ongoing, notes, clinic_id, vet_name, clinic_contact_id, vet_contact_id, give_morning, give_evening, give_as_needed, created_by)
VALUES(:aid,:mid,:route,:dose,:start,:end,1,:notes,:clinic_id,:vet_name,:clinic_contact_id,:vet_contact_id,:give_morning,:give_evening,:give_as_needed,:created_by)
');
$stmt->execute([
':aid' => $id,
$values = [
':mid' => $medId,
':route' => $route !== '' ? $route : null,
':dose' => $dose,
@ -494,16 +499,32 @@ trait AnimalMedicalActions
':give_morning' => $giveMorning,
':give_evening' => $giveEvening,
':give_as_needed' => $giveAsNeeded,
':created_by' => Auth::id(),
]);
if ((int) ($_POST['tariff_id'] ?? 0) > 0) {
PricingService::record($db, $id, (int) $_POST['tariff_id'], 1, $start, 'Ajoutée avec le traitement');
];
if ($entryId > 0) {
$values[':entry'] = $entryId;
$db->prepare('UPDATE treatments SET medication_id=:mid,route=:route,dose_text=:dose,start_date=:start,
end_date=:end,notes=:notes,clinic_id=:clinic_id,vet_name=:vet_name,
clinic_contact_id=:clinic_contact_id,vet_contact_id=:vet_contact_id,
give_morning=:give_morning,give_evening=:give_evening,give_as_needed=:give_as_needed
WHERE id=:entry')->execute($values);
} else {
$values[':aid'] = $id;
$values[':created_by'] = Auth::id();
$db->prepare('INSERT INTO treatments(animal_id, medication_id, route, dose_text, start_date, end_date,
ongoing, notes, clinic_id, vet_name, clinic_contact_id, vet_contact_id,
give_morning, give_evening, give_as_needed, created_by)
VALUES(:aid,:mid,:route,:dose,:start,:end,1,:notes,:clinic_id,:vet_name,
:clinic_contact_id,:vet_contact_id,:give_morning,:give_evening,:give_as_needed,:created_by)')
->execute($values);
if ((int) ($_POST['tariff_id'] ?? 0) > 0) {
PricingService::record($db, $id, (int) $_POST['tariff_id'], 1, $start, 'Ajoutée avec le traitement');
}
}
self::logHistory(
$id,
'treatment',
'Traitement ajouté',
$entryId > 0 ? 'Traitement corrigé' : 'Traitement ajouté',
"Médicament #$medId\nDose : $dose\nDébut : $start" .
($end !== '' ? "\nFin : $end" : '') .
($notes !== '' ? "\nNotes : $notes" : ''),