// 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();
        } else {
            $db->rollback();
        }
        // Si pas d'erreur SQL on redirige vers la fiche de la demande
示例#2
0
// 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, $cp->fk_type);
            $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, $cp->fk_type);
            // Mise à jour du solde
            $result2 = $cp->updateSoldeCP($cp->fk_user, $newSolde, $cp->fk_type);
            if ($result1 < 0 || $result2 < 0) {
                $error = $langs->trans('ErrorCantDeleteCP');
            }
        }
        if (!$error) {
            $db->commit();
        } else {
            $db->rollback();
        }
        // Si pas d'erreur SQL on redirige vers la fiche de la demande