header('Location: fiche.php?id=' . $_GET['id'] . '&error=NoMotifRefuse'); exit; } } // Si Validation de la demande if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') { $cp = new Holiday($db); $cp->fetch($_GET['id']); // Si statut en attente de validation et valideur = utilisateur if (($cp->statut == 2 || $cp->statut == 3) && ($user->id == $cp->fk_validator || $user->id == $cp->fk_user)) { $db->begin(); $oldstatus = $cp->statut; $cp->date_cancel = dol_now(); $cp->fk_user_cancel = $user->id; $cp->statut = 4; $result = $cp->update($user->id); if ($result >= 0 && $oldstatus == 3) { // Calculcate number of days consummed $nbopenedday = num_open_day($cp->date_debut_gmt, $cp->date_fin_gmt, 0, 1, $cp->halfday); $soldeActuel = $cp->getCpforUser($cp->fk_user); $newSolde = $soldeActuel + $nbopenedday * $cp->getConfCP('nbHolidayDeducted'); // On ajoute la modification dans le LOG $result1 = $cp->addLogCP($user->id, $cp->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde); // Mise à jour du solde $result2 = $cp->updateSoldeCP($cp->fk_user, $newSolde); if ($result1 < 0 || $result2 < 0) { $error = $langs->trans('ErrorCantDeleteCP'); } } if (!$error) { $db->commit();
/** * testHolidayUpdate * * @param Holiday $localobject Holiday * @return int * * @depends testHolidayFetch * The depends says test is run only if previous is ok */ public function testHolidayUpdate($localobject) { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; $localobject->oldcopy = clone $localobject; $localobject->note_private = 'New private note after update'; $localobject->note_public = 'New public note after update'; $localobject->lastname = 'New name'; $localobject->firstname = 'New firstname'; $localobject->address = 'New address'; $localobject->zip = 'New zip'; $localobject->town = 'New town'; $localobject->country_id = 2; //$localobject->status=0; $localobject->phone_pro = 'New tel pro'; $localobject->phone_perso = 'New tel perso'; $localobject->phone_mobile = 'New tel mobile'; $localobject->fax = 'New fax'; $localobject->email = '*****@*****.**'; $localobject->jabberid = 'New im id'; $localobject->default_lang = 'es_ES'; $result = $localobject->update($localobject->id, $user); print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n"; $this->assertLessThan($result, 0, 'Holiday::update error'); $result = $localobject->update_note($localobject->note_private, '_private'); print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n"; $this->assertLessThan($result, 0, 'Holiday::update_note (private) error'); $result = $localobject->update_note($localobject->note_public, '_public'); print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n"; $this->assertLessThan($result, 0, 'Holiday::update_note (public) error'); $newobject = new Holiday($this->savdb); $result = $newobject->fetch($localobject->id); print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n"; $this->assertLessThan($result, 0, 'Holiday::fetch error'); print __METHOD__ . " old=" . $localobject->note . " new=" . $newobject->note . "\n"; $this->assertEquals($localobject->note, $newobject->note, 'Holiday::update_note error compare note'); //print __METHOD__." old=".$localobject->note_public." new=".$newobject->note_public."\n"; //$this->assertEquals($localobject->note_public, $newobject->note_public); return $localobject; }