$redirectLink = "Location:../clients-list.php"; } else { if ($action == "desister") { $idContrat = $_POST['idContrat']; $contrat = $contratManager->getContratById($idContrat); //Change status of the old contrat Bien from "Vendu" to "Disponible" if ($contrat->typeBien() == "appartement") { $appartementManager = new AppartementManager($pdo); $appartementManager->changeStatus($contrat->idBien(), "Disponible"); } else { if ($contrat->typeBien() == "localCommercial") { $locauxManager = new LocauxManager($pdo); $locauxManager->changeStatus($contrat->idBien(), "Disponible"); } } $contratManager->desisterContrat($idContrat); //add history data to db $createdBy = $_SESSION['userMerlaTrav']->login(); $created = date('Y-m-d h:i:s'); $history = new History(array('action' => "Désistement", 'target' => "Table des contrats", 'description' => "Désister un contrat", 'created' => $created, 'createdBy' => $createdBy)); //add it to db $historyManager->add($history); $actionMessage = "<strong>Opération valide : </strong>Le contrat est désisté avec succès."; $typeMessage = "success"; $redirectLink = 'Location:../contrats-list.php?idProjet=' . $idProjet; if (isset($_POST["source"]) and $_POST["source"] == "clients-search") { $redirectLink = 'Location:../clients-search.php'; } } else { if ($action == "activer") { $idContrat = $_POST['idContrat'];
//create classes $contrat = $contratManager->getContratById($idContrat); //change status of the old contrat Bien from reservé to non reservé if ($contrat->typeBien() == "appartement") { $appartementManager->updateStatus("Disponible", $contrat->idBien()); } else { if ($contrat->typeBien() == "localCommercial") { $locauxManager->updateStatus("Disponible", $contrat->idBien()); } else { if ($contrat->typeBien() == "maison") { $maisonManager->updateStatus("Disponible", $contrat->idBien()); } else { if ($contrat->typeBien() == "terrain") { $terrainManager->updateStatus("Disponible", $contrat->idBien()); } } } } $contratManager->desisterContrat($contrat->id()); //add history data to db $projetManager = new ProjetManager($pdo); $historyManager = new HistoryManager($pdo); $projet = $projetManager->getProjetById($idProjet); $createdBy = $_SESSION['userMerlaTrav']->login(); $created = date('Y-m-d h:i:s'); $history = new History(array('action' => "Désistement", 'target' => "Table des contrats clients", 'description' => "Désistement contrat - Client : " . $contrat->nomClient() . " - CIN : " . $contrat->cin() . " - ID Contrat : " . $contrat->id() . " - Type bien : " . $contrat->typeBien() . " - ID Bien : " . $contrat->idBien() . " - Projet : " . $projet->nom(), 'created' => $created, 'createdBy' => $createdBy)); //add it to db $historyManager->add($history); $_SESSION['contrat-desister-success'] = "<strong>Opération valide : </strong>Le contrat est désisté avec succès."; $redirectLink = 'Location:../contrats-list.php?idProjet=' . $idProjet . '&idSociete=' . $idSociete; header($redirectLink);