Exemple #1
0
$listUsers = $holiday->fetchUsers(false, false);
// Si il y a une action de mise à jour
if ($action == 'update' && isset($_POST['update_cp'])) {
    $userID = array_keys($_POST['update_cp']);
    $userID = $userID[0];
    $userValue = $_POST['nb_holiday'];
    $userValue = $userValue[$userID];
    if (!empty($userValue)) {
        $userValue = price2num($userValue, 2);
    } else {
        $userValue = 0;
    }
    //If the user set a comment, we add it to the log comment
    $comment = isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID]) ? ' (' . $_POST['note_holiday'][$userID] . ')' : '';
    // We add the modification to the log
    $holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate') . $comment, $userValue);
    // Update of the days of the employee
    $holiday->updateSoldeCP($userID, $userValue);
    // If it first update of sold, we set date to avoid to have sold incremented by new month
    $now = dol_now();
    $sql = "UPDATE " . MAIN_DB_PREFIX . "holiday_config SET";
    $sql .= " value = '" . dol_print_date($now, '%Y%m%d%H%M%S') . "'";
    $sql .= " WHERE name = 'lastUpdate' and value IS NULL";
    // Add value IS NULL to be sure to update only at init.
    dol_syslog('define_holiday update lastUpdate entry', LOG_DEBUG);
    $result = $db->query($sql);
    setEventMessage($langs->trans('UpdateConfCPOK'));
} elseif ($action == 'add_event') {
    $error = 0;
    if (!empty($_POST['list_event']) && $_POST['list_event'] > 0) {
        $event = $_POST['list_event'];
 $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
     if (!$error && $result > 0) {
         // To
         $destinataire = new User($db);
Exemple #3
0
 $userID = array_keys($_POST['update_cp']);
 $userID = $userID[0];
 foreach ($typeleaves as $key => $val) {
     $userValue = $_POST['nb_holiday_' . $val['rowid']];
     $userValue = $userValue[$userID];
     if (!empty($userValue)) {
         $userValue = price2num($userValue, 5);
     } else {
         $userValue = '';
     }
     //If the user set a comment, we add it to the log comment
     $comment = isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID]) ? ' (' . $_POST['note_holiday'][$userID] . ')' : '';
     //print 'eee'.$val['rowid'].'-'.$userValue;
     if ($userValue != '') {
         // We add the modification to the log (must be before update of sold because we read current value of sold)
         $result = $holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate') . $comment, $userValue, $val['rowid']);
         if ($result < 0) {
             setEventMessages($holiday->error, $holiday->errors, 'errors');
             $error++;
         }
         // Update of the days of the employee
         $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']);
         if ($result < 0) {
             setEventMessages($holiday->error, $holiday->errors, 'errors');
             $error++;
         }
         // If it first update of balance, we set date to avoid to have sold incremented by new month
         /*
         			$now=dol_now();
         $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
         $sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'";