Skip to content

Commit

Permalink
Merge pull request Dolibarr#2 from atm-ph/3.4_akteos_rtt
Browse files Browse the repository at this point in the history
New fonctionnalité RTT avec les congés payés de Dolibarr
  • Loading branch information
FHenry committed May 25, 2016
2 parents c015e55 + 4462b8c commit 2e6bba1
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 38 deletions.
42 changes: 42 additions & 0 deletions htdocs/holiday/admin/holiday.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@

// Option du délai pour faire une demande de congés payés
if (!$cp->updateConfCP('delayForRequest',$_POST['delayForRequest']))
{
$error = true;
}

// Option du délai pour faire une demande de congés payés
if (!$cp->updateConfCP('delayForRTT',$_POST['delayForRTT']))
{
$error = true;
}
Expand All @@ -82,6 +88,14 @@
$error = true;
}

// Option du nombre de jours à ajouter chaque mois
$nbRttEveryMonth = price2num($_POST['nbRttEveryMonth'],5);

if(!$cp->updateConfCP('nbRttEveryMonth',$nbRttEveryMonth))
{
$error = true;
}

// Option du nombre de jours pour un mariage
$OptMariageCP = price2num($_POST['OptMariage'],5);

Expand Down Expand Up @@ -138,6 +152,13 @@
if(!$cp->updateConfCP('nbHolidayDeducted',$nbHolidayDeducted)) {
$error = true;
}

// Option du nombre de jours à déduire pour 1 jour de congés
$nbRttDeducted = price2num($_POST['nbRttDeducted'],2);

if(!$cp->updateConfCP('nbRttDeducted',$nbRttDeducted)) {
$error = true;
}

if ($error) {
$message = '<div class="error">'.$langs->trans('ErrorUpdateConfCP').'</div>';
Expand Down Expand Up @@ -313,6 +334,27 @@
print '<td style="padding:5px;"><input class="flat" type="text" name="nbHolidayDeducted" value="'.$cp->getConfCP('nbHolidayDeducted').'" size="2"/> '.$langs->trans('DurationDays').'</td>'."\n";
print '</tr>'."\n";



//RTT
$var=!$var;
print '<tr '.$bc[$var].'>'."\n";
print '<td style="padding:5px;">'.$langs->trans('Délai pour faire une demande de RTT avant ceux-ci').'</td>'."\n";
print '<td style="padding:5px;"><input class="flat" type="text" name="delayForRTT" value="'.$cp->getConfCP('delayForRTT').'" size="2" /> '.$langs->trans('DurationDays').'</td>'."\n";
print '</tr>'."\n";

$var=!$var;
print '<tr '.$bc[$var].'>'."\n";
print '<td style="padding:5px;">'.$langs->trans('Nombre de RTT ajoutés chaque mois').'</td>'."\n";
print '<td style="padding:5px;"><input class="flat" type="text" name="nbRttEveryMonth" value="'.$cp->getConfCP('nbRttEveryMonth').'" size="5"/> '.$langs->trans('DurationDays').'</td>'."\n";
print '</tr>'."\n";

$var=!$var;
print '<tr '.$bc[$var].'>'."\n";
print '<td style="padding:5px;">'.$langs->trans('Nombre de RTT à déduire par jour de RTT pris').'</td>'."\n";
print '<td style="padding:5px;"><input class="flat" type="text" name="nbRttDeducted" value="'.$cp->getConfCP('nbRttDeducted').'" size="2"/> '.$langs->trans('DurationDays').'</td>'."\n";
print '</tr>'."\n";

print '</tbody>'."\n";
print '</table>'."\n";

Expand Down
65 changes: 44 additions & 21 deletions htdocs/holiday/class/holiday.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Holiday extends CommonObject
var $optValue = '';
var $optRowid = '';

var $type_conges='conges';
/**
* Constructor
*
Expand Down Expand Up @@ -118,7 +119,8 @@ function create($user, $notrigger=0)
$sql.= "date_fin,";
$sql.= "halfday,";
$sql.= "statut,";
$sql.= "fk_validator";
$sql.= "fk_validator,";
$sql.= "type_conges";
$sql.= ") VALUES (";

// User
Expand All @@ -129,7 +131,8 @@ function create($user, $notrigger=0)
$sql.= " '".$this->db->idate($this->date_fin)."',";
$sql.= " ".$this->halfday.",";
$sql.= " '1',";
$sql.= " '".$this->fk_validator."'";
$sql.= " '".$this->fk_validator."',";
$sql.= " '".$this->db->escape($this->type_conges)."'";

$sql.= ")";

Expand Down Expand Up @@ -194,7 +197,8 @@ function fetch($id)
$sql.= " cp.fk_user_cancel,";
$sql.= " cp.detail_refuse,";
$sql.= " cp.note_private,";
$sql.= " cp.note_public";
$sql.= " cp.note_public,";
$sql.= " cp.type_conges";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
$sql.= " WHERE cp.rowid = ".$id;

Expand Down Expand Up @@ -226,6 +230,7 @@ function fetch($id)
$this->detail_refuse = $obj->detail_refuse;
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
$this->type_conges = $obj->type_conges;
}
$this->db->free($resql);

Expand Down Expand Up @@ -269,6 +274,7 @@ function fetchByUser($user_id,$order='',$filter='')
$sql.= " cp.date_cancel,";
$sql.= " cp.fk_user_cancel,";
$sql.= " cp.detail_refuse,";
$sql.= " cp.type_conges,";

$sql.= " uu.lastname as user_lastname,";
$sql.= " uu.firstname as user_firstname,";
Expand Down Expand Up @@ -327,6 +333,7 @@ function fetchByUser($user_id,$order='',$filter='')
$tab_result[$i]['date_cancel'] = $this->db->jdate($obj->date_cancel);
$tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
$tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
$tab_result[$i]['type_conges'] = $obj->type_conges;

$tab_result[$i]['user_firstname'] = $obj->user_firstname;
$tab_result[$i]['user_lastname'] = $obj->user_lastname;
Expand Down Expand Up @@ -379,6 +386,7 @@ function fetchAll($order,$filter)
$sql.= " cp.date_cancel,";
$sql.= " cp.fk_user_cancel,";
$sql.= " cp.detail_refuse,";
$sql.= " cp.type_conges,";

$sql.= " uu.lastname as user_lastname,";
$sql.= " uu.firstname as user_firstname,";
Expand Down Expand Up @@ -436,6 +444,7 @@ function fetchAll($order,$filter)
$tab_result[$i]['date_cancel'] = $obj->date_cancel;
$tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
$tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
$tab_result[$i]['type_conges'] = $obj->type_conges;

$tab_result[$i]['user_firstname'] = $obj->user_firstname;
$tab_result[$i]['user_lastname'] = $obj->user_lastname;
Expand Down Expand Up @@ -474,6 +483,7 @@ function update($user=0, $notrigger=0)
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";

$sql.= " description= '".$this->db->escape($this->description)."',";
$sql.= " type_conges= '".$this->db->escape($this->type_conges)."',";

if(!empty($this->date_debut)) {
$sql.= " date_debut = '".$this->db->idate($this->date_debut)."',";
Expand Down Expand Up @@ -873,10 +883,13 @@ function getConfCP($name)
* @param int $nbHoliday Nb of days
* @return void
*/
function updateSoldeCP($userID='',$nbHoliday='')
function updateSoldeCP($userID='',$nbHoliday='', $updateRtt=false)
{
global $user, $langs;

$rtt = false;
if ($this->type_conges == 'rtt') $rtt = true;

if (empty($userID) && empty($nbHoliday))
{
// Si mise à jour pour tout le monde en début de mois
Expand All @@ -887,7 +900,7 @@ function updateSoldeCP($userID='',$nbHoliday='')
$lastUpdate = $this->getConfCP('lastUpdate');
$monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
//print 'month: '.$month.' '.$lastUpdate.' '.$monthLastUpdate;

// Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp
if ($month != $monthLastUpdate)
{
Expand All @@ -899,18 +912,21 @@ function updateSoldeCP($userID='',$nbHoliday='')
$result = $this->db->query($sql);

// On ajoute x jours à chaque utilisateurs
$nb_holiday = $this->getConfCP('nbHolidayEveryMonth');
if ($rtt) $nb_holiday = $this->getConfCP('nbRttEveryMonth');
else $nb_holiday = $this->getConfCP('nbHolidayEveryMonth');

if (empty($nb_holiday)) $nb_holiday=0;

$users = $this->fetchUsers(false,false);
$nbUser = count($users);

$i = 0;

while($i < $nbUser)
{
$now_holiday = $this->getCPforUser($users[$i]['rowid']);
$new_solde = $now_holiday + $this->getConfCP('nbHolidayEveryMonth');
$now_holiday = $this->getCPforUser($users[$i]['rowid'], $rtt);
if ($rtt) $new_solde = $now_holiday + $this->getConfCP('nbRttEveryMonth');
else $new_solde = $now_holiday + $this->getConfCP('nbHolidayEveryMonth');

// On ajoute la modification dans le LOG
$this->addLogCP($user->id,$users[$i]['rowid'], $langs->trans('Event').': '.$langs->trans('HolidaysMonthlyUpdate'),$new_solde);
Expand All @@ -919,7 +935,8 @@ function updateSoldeCP($userID='',$nbHoliday='')
}

$sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
$sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
if ($rtt) $sql2.= " nb_rtt = nb_rtt + ".$nb_holiday;
else $sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;

dol_syslog(get_class($this).'::updateSoldeCP sql='.$sql2);
$this->db->query($sql2);
Expand All @@ -930,7 +947,8 @@ function updateSoldeCP($userID='',$nbHoliday='')

// Mise à jour pour un utilisateur
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
$sql.= " nb_holiday = ".$nbHoliday;
if ($updateRtt) $sql.= " nb_rtt = ".$nbHoliday;
else $sql.= " nb_holiday = ".$nbHoliday;
$sql.= " WHERE fk_user = '".$userID."'";

dol_syslog(get_class($this).'::updateSoldeCP sql='.$sql);
Expand Down Expand Up @@ -979,15 +997,15 @@ function createCPusers($single=false,$userid='')
dol_syslog(get_class($this).'::createCPusers');
foreach($this->fetchUsers(false,true) as $users) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
$sql.= " (fk_user, nb_holiday)";
$sql.= " VALUES ('".$users['rowid']."','0')";
$sql.= " (fk_user, nb_holiday, nb_rtt)";
$sql.= " VALUES ('".$users['rowid']."','0', '0')";

$this->db->query($sql);
}
} else {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
$sql.= " (fk_user, nb_holiday)";
$sql.= " VALUES ('".$userid."','0')";
$sql.= " (fk_user, nb_holiday, nb_rtt)";
$sql.= " VALUES ('".$userid."','0', '0')";

$this->db->query($sql);
}
Expand Down Expand Up @@ -1016,17 +1034,18 @@ function deleteCPuser($user_id) {
* @param int $user_id ID de l'utilisateur
* @return float Retourne le solde de congés payés de l'utilisateur
*/
function getCPforUser($user_id) {
function getCPforUser($user_id, $rtt=false) {

$sql = "SELECT nb_holiday";
$sql = "SELECT nb_holiday, nb_rtt";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users";
$sql.= " WHERE fk_user = '".$user_id."'";

dol_syslog(get_class($this).'::getCPforUser sql='.$sql);
$result = $this->db->query($sql);
if($result) {
$obj = $this->db->fetch_object($result);
return number_format($obj->nb_holiday,2);
if ($rtt) return number_format($obj->nb_rtt,2);
else return number_format($obj->nb_holiday,2);
} else {
return '0';
}
Expand Down Expand Up @@ -1562,12 +1581,14 @@ function getNameEventCp($rowid) {
* @param int $new_solde New value
* @return number|string
*/
function addLogCP($fk_user_action,$fk_user_update,$type,$new_solde) {
function addLogCP($fk_user_action,$fk_user_update,$type,$new_solde,$type_conges='') {

global $conf, $langs;

$error=0;

if (empty($type_conges)) $type_conges = $this->type_conges;

$prev_solde = $this->getCPforUser($fk_user_update);
$new_solde = number_format($new_solde,2,'.','');

Expand All @@ -1579,7 +1600,8 @@ function addLogCP($fk_user_action,$fk_user_update,$type,$new_solde) {
$sql.= "fk_user_update,";
$sql.= "type_action,";
$sql.= "prev_solde,";
$sql.= "new_solde";
$sql.= "new_solde,";
$sql.= "type_conges";

$sql.= ") VALUES (";

Expand All @@ -1588,7 +1610,8 @@ function addLogCP($fk_user_action,$fk_user_update,$type,$new_solde) {
$sql.= " '".$fk_user_update."',";
$sql.= " '".$this->db->escape($type)."',";
$sql.= " '".$prev_solde."',";
$sql.= " '".$new_solde."'";
$sql.= " '".$new_solde."',";
$sql.= " '".$this->db->escape($type_conges)."'";
$sql.= ")";

$this->db->begin();
Expand Down
26 changes: 24 additions & 2 deletions htdocs/holiday/define_holiday.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,35 @@

$userValue = $_POST['nb_holiday'];
$userValue = $userValue[$userID];

$userValueRtt = GETPOST('nb_rtt');
$userValueRtt = $userValueRtt[$userID];

if(!empty($userValue)) {
$userValue = price2num($userValue,2);
} else {
$userValue = 0;
}

if(!empty($userValueRtt)) {
$userValueRtt = price2num($userValueRtt,2);
} else {
$userValueRtt = 0;
}

// On ajoute la modification dans le LOG
$holiday->addLogCP($user->id,$userID, $langs->trans('Event').': '.$langs->trans('ManualUpdate'),$userValue);

// Mise à jour des congés de l'utilisateur
$holiday->updateSoldeCP($userID,$userValue);


// On ajoute la modification dans le LOG => RTT
$holiday->addLogCP($user->id,$userID, $langs->trans('Event').': '.$langs->trans('ManualUpdate'),$userValueRtt, 'rtt');

// Mise à jour des congés de l'utilisateur => RTT
$holiday->updateSoldeCP($userID,$userValueRtt, true);


// If it first update of sold, we set date to havoid to have sold incremented by new month
$now=dol_now();
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
Expand Down Expand Up @@ -147,7 +163,8 @@
print "<tr class=\"liste_titre\">";
print '<td width="5%">'.$langs->trans('ID').'</td>';
print '<td width="60%">'.$langs->trans('UserName').'</td>';
print '<td width="20%" style="text-align:center">'.$langs->trans('Available').'</td>';
print '<td width="20%" style="text-align:center">CP '.$langs->trans('Available').'</td>';
print '<td width="10%" style="text-align:center"> '.$langs->trans('RTT').' '.$langs->trans('Available').'</td>';
print '<td>'.$langs->trans('UpdateButtonCP').'</td>';
print '</tr>';

Expand All @@ -167,6 +184,11 @@
print '<td style="text-align:center">';
print '<input type="text" value="'.$holiday->getCPforUser($users['rowid']).'" name="nb_holiday['.$users['rowid'].']" size="5" style="text-align: center;"/>';
print ' '.$langs->trans('days').'</td>'."\n";

print '<td style="text-align:center">';
print '<input type="text" value="'.$holiday->getCPforUser($users['rowid'], true).'" name="nb_rtt['.$users['rowid'].']" size="5" style="text-align: center;"/>';
print ' '.$langs->trans('days').'</td>'."\n";

print '<td><input type="submit" name="update_cp['.$users['rowid'].']" value="'.dol_escape_htmltag($langs->trans("Update")).'" class="button"/></td>'."\n";
print '</tr>';

Expand Down
Loading

0 comments on commit 2e6bba1

Please sign in to comment.