Browse Source

Introduce table llx_c_holiday_type

Laurent Destailleur 10 years ago
parent
commit
4f1538f502

+ 18 - 7
htdocs/admin/dict.php

@@ -70,7 +70,7 @@ $hookmanager->initHooks(array('admin'));
 // Put here declaration of dictionaries properties
 
 // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
-$taborder=array(9,0,4,3,2,0,1,8,19,16,27,0,5,11,0,6,0,10,23,12,13,0,14,0,7,17,24,0,22,20,18,21,0,15,0,25,0,26);
+$taborder=array(9,0,4,3,2,0,1,8,19,16,27,0,5,11,0,6,0,7,17,24,28,0,10,23,12,13,0,14,0,22,20,18,21,0,15,0,25,0,26);
 
 // Name of SQL tables of dictionaries
 $tabname=array();
@@ -101,6 +101,7 @@ $tabname[24]= MAIN_DB_PREFIX."c_type_resource";
 $tabname[25]= MAIN_DB_PREFIX."c_email_templates";
 $tabname[26]= MAIN_DB_PREFIX."c_units";
 $tabname[27]= MAIN_DB_PREFIX."c_stcomm";
+$tabname[28]= MAIN_DB_PREFIX."c_holiday_types";
 
 // Dictionary labels
 $tablib=array();
@@ -131,22 +132,23 @@ $tablib[24]= "DictionaryResourceType";
 $tablib[25]= "DictionaryEMailTemplates";
 $tablib[26]= "DictionaryUnits";
 $tablib[27]= "DictionaryProspectStatus";
+$tablib[28]= "DictionaryHolidayTypes";
 
 // Requests to extract data
 $tabsql=array();
 $tabsql[1] = "SELECT f.rowid as rowid, f.code, f.libelle, c.code as country_code, c.label as country, f.active FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c WHERE f.fk_pays=c.rowid";
 $tabsql[2] = "SELECT d.rowid as rowid, d.code_departement as code, d.nom as libelle, d.fk_region as region_id, r.nom as region, c.code as country_code, c.label as country, d.active FROM ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and r.active=1 and c.active=1";
 $tabsql[3] = "SELECT r.rowid as rowid, r.code_region as code, r.nom as libelle, r.fk_pays as country_id, c.code as country_code, c.label as country, r.active FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE r.fk_pays=c.rowid and c.active=1";
-$tabsql[4] = "SELECT rowid   as rowid, code, label, active, favorite FROM ".MAIN_DB_PREFIX."c_country";
+$tabsql[4] = "SELECT c.rowid as rowid, c.code, c.label, c.active, c.favorite FROM ".MAIN_DB_PREFIX."c_country AS c";
 $tabsql[5] = "SELECT c.rowid as rowid, c.code as code, c.label, c.active FROM ".MAIN_DB_PREFIX."c_civility AS c";
 $tabsql[6] = "SELECT a.id    as rowid, a.code as code, a.libelle AS libelle, a.type, a.active, a.module, a.color, a.position FROM ".MAIN_DB_PREFIX."c_actioncomm AS a";
 $tabsql[7] = "SELECT a.id    as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, a.deductible, c.code as country_code, c.label as country, a.fk_pays as country_id, a.active FROM ".MAIN_DB_PREFIX."c_chargesociales AS a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_pays=c.rowid and c.active=1";
 $tabsql[8] = "SELECT t.id    as rowid, t.code as code, t.libelle, t.fk_country as country_id, c.code as country_code, c.label as country, t.active FROM ".MAIN_DB_PREFIX."c_typent as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON t.fk_country=c.rowid";
-$tabsql[9] = "SELECT code_iso as code, label, unicode, active FROM ".MAIN_DB_PREFIX."c_currencies";
+$tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c";
 $tabsql[10]= "SELECT t.rowid, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
 $tabsql[11]= "SELECT t.rowid as rowid, element, source, code, libelle, active FROM ".MAIN_DB_PREFIX."c_type_contact AS t";
-$tabsql[12]= "SELECT c.rowid as rowid, code, sortorder, c.libelle, c.libelle_facture, nbjour, fdm, decalage, active FROM ".MAIN_DB_PREFIX.'c_payment_term AS c';
-$tabsql[13]= "SELECT id      as rowid, code, c.libelle, type, active, accountancy_code FROM ".MAIN_DB_PREFIX."c_paiement AS c";
+$tabsql[12]= "SELECT c.rowid as rowid, c.code, c.sortorder, c.libelle, c.libelle_facture, nbjour, fdm, decalage, active FROM ".MAIN_DB_PREFIX.'c_payment_term AS c';
+$tabsql[13]= "SELECT c.id    as rowid, c.code, c.libelle, c.type, c.active, c.accountancy_code FROM ".MAIN_DB_PREFIX."c_paiement AS c";
 $tabsql[14]= "SELECT e.rowid as rowid, e.code as code, e.libelle, e.price, e.organization, e.fk_pays as country_id, c.code as country_code, c.label as country, e.active FROM ".MAIN_DB_PREFIX."c_ecotaxe AS e, ".MAIN_DB_PREFIX."c_country as c WHERE e.fk_pays=c.rowid and c.active=1";
 $tabsql[15]= "SELECT rowid   as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format";
 $tabsql[16]= "SELECT code, label as libelle, sortorder, active FROM ".MAIN_DB_PREFIX."c_prospectlevel";
@@ -161,6 +163,7 @@ $tabsql[24]= "SELECT rowid   as rowid, code, label, active FROM ".MAIN_DB_PREFIX
 $tabsql[25]= "SELECT rowid   as rowid, label, type_template, private, position, topic, content, active FROM ".MAIN_DB_PREFIX."c_email_templates";
 $tabsql[26]= "SELECT rowid   as rowid, code, label, short_label, active FROM ".MAIN_DB_PREFIX."c_units";
 $tabsql[27]= "SELECT id      as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_stcomm";
+$tabsql[28]= "SELECT h.rowid as rowid, h.code, h.label, h.delay, h.newByMonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid";
 
 // Criteria to sort dictionaries
 $tabsqlsort=array();
@@ -191,6 +194,7 @@ $tabsqlsort[24]="code ASC,label ASC";
 $tabsqlsort[25]="label ASC";
 $tabsqlsort[26]="code ASC";
 $tabsqlsort[27]="code ASC";
+$tabsqlsort[28]="country ASC, code ASC";
 
 // Nom des champs en resultat de select pour affichage du dictionnaire
 $tabfield=array();
@@ -221,6 +225,7 @@ $tabfield[24]= "code,label";
 $tabfield[25]= "label,type_template,private,position,topic,content";
 $tabfield[26]= "code,label,short_label";
 $tabfield[27]= "code,libelle";
+$tabfield[28]= "code,label,delay,newByMonth,country_id,country";
 
 // Nom des champs d'edition pour modification d'un enregistrement
 $tabfieldvalue=array();
@@ -251,6 +256,7 @@ $tabfieldvalue[24]= "code,label";
 $tabfieldvalue[25]= "label,type_template,private,position,topic,content";
 $tabfieldvalue[26]= "code,label,short_label";
 $tabfieldvalue[27]= "code,libelle";
+$tabfieldvalue[28]= "code,label,delay,newByMonth,country";
 
 // Nom des champs dans la table pour insertion d'un enregistrement
 $tabfieldinsert=array();
@@ -281,6 +287,7 @@ $tabfieldinsert[24]= "code,label";
 $tabfieldinsert[25]= "label,type_template,private,position,topic,content";
 $tabfieldinsert[26]= "code,label,short_label";
 $tabfieldinsert[27]= "code,libelle";
+$tabfieldinsert[28]= "code,label,delay,newByMonth,fk_country";
 
 // Nom du rowid si le champ n'est pas de type autoincrement
 // Example: "" if id field is "rowid" and has autoincrement on
@@ -313,6 +320,7 @@ $tabrowid[24]= "";
 $tabrowid[25]= "";
 $tabrowid[26]= "";
 $tabrowid[27]= "id";
+$tabrowid[28]= "";
 
 // Condition to show dictionary in setup page
 $tabcond=array();
@@ -343,6 +351,7 @@ $tabcond[24]= ! empty($conf->resource->enabled);
 $tabcond[25]= true; // && ! empty($conf->global->MAIN_EMAIL_EDIT_TEMPLATE_FROM_DIC);
 $tabcond[26]= ! empty($conf->product->enabled);
 $tabcond[27]= ! empty($conf->societe->enabled);
+$tabcond[28]= ! empty($conf->holiday->enabled);
 
 // List of help for fields
 $tabhelp=array();
@@ -373,6 +382,7 @@ $tabhelp[24] = array();
 $tabhelp[25] = array();
 $tabhelp[26] = array();
 $tabhelp[27] = array();
+$tabhelp[28] = array();
 
 // List of check for fields (NOT USED YET)
 $tabfieldcheck=array();
@@ -403,6 +413,7 @@ $tabfieldcheck[24] = array();
 $tabfieldcheck[25] = array();
 $tabfieldcheck[26] = array();
 $tabfieldcheck[27] = array();
+$tabfieldcheck[28] = array();
 
 // Complete all arrays with entries found into modules
 complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck);
@@ -475,7 +486,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
     $ok=1;
     foreach ($listfield as $f => $value)
     {
-        if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType'))) continue;		// For some pages, country is not mandatory
+        if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes'))) continue;		// For some pages, country is not mandatory
     	if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType'))) continue;		// For some pages, country is not mandatory
         if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue;
         if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue;
@@ -524,7 +535,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
     }
     if (isset($_POST["country"]) && ($_POST["country"]=='0') && ($id != 2))
     {
-    	if (in_array($tablib[$id],array('DictionaryCompanyType')))
+    	if (in_array($tablib[$id],array('DictionaryCompanyType','DictionaryHolidayTypes')))	// Field country is no mandatory for such dictionaries
     	{
     		$_POST["country"]='';
     	}

+ 1 - 1
htdocs/compta/hrm.php

@@ -67,7 +67,7 @@ $childids[]=$user->id;
 
 llxHeader(array(),$langs->trans('HRMArea'));
 
-print_fiche_titre($langs->trans("HRMArea"));
+print_fiche_titre($langs->trans("HRMArea"),'', 'title_hrm.png');
 
 print '<div class="fichecenter"><div class="fichethirdleft">';
 

+ 14 - 17
htdocs/holiday/admin/holiday.php

@@ -52,7 +52,7 @@ if (empty($conf->holiday->enabled)) print $langs->trans('NotActiveModCP');
 llxheader('',$langs->trans('TitleAdminCP'));
 
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
-print_fiche_titre($langs->trans('ConfCP'), $linkback);
+print_fiche_titre($langs->trans('ConfCP'), $linkback, 'title_hrm.png');
 
 $cp = new Holiday($db);
 
@@ -132,7 +132,7 @@ if ($action == "add")
     }
 
     // Option du nombre de jours à déduire pour 1 jour de congés
-    $nbHolidayDeducted = price2num($_POST['nbHolidayDeducted'],2);
+    $nbHolidayDeducted = price2num($_POST['nbHolidayDeducted'],5);
 
     if(!$cp->updateConfCP('nbHolidayDeducted',$nbHolidayDeducted))
     {
@@ -165,7 +165,7 @@ elseif ($action == 'create_event')
     $error = 0;
 
     $optName = trim($optName);
-    $optValue = price2num($optValue,2);
+    $optValue = price2num($optValue,5);
 
     if (! $optName)
     {
@@ -218,7 +218,7 @@ elseif($action == 'event' && isset($_POST['update_event']))
 
     if (!empty($eventValue))
     {
-        $eventValue = price2num($eventValue,2);
+        $eventValue = price2num($eventValue,5);
     } else {
         $error++;
     }
@@ -254,10 +254,11 @@ elseif($action && isset($_POST['delete_event']))
     }
 }
 
-print '<br>';
+/*print '<br>';
 
 print_fiche_titre($langs->trans('TitleOptionMainCP'),'','');
 
+
 dol_fiche_head(array(),'','');
 
 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?leftmenu=setup" name="config">'."\n";
@@ -272,13 +273,6 @@ print '</tr>';
 
 $var=true;
 
-/*$var=!$var;
-print '<tr '.$bc[$var].'>'."\n";
-print '<td style="padding:5px;">'.$langs->trans('GroupToValidateCP').'</td>'."\n";
-print '<td style="padding:5px;">'.$cp->selectUserGroup('userGroup').'</td>'."\n";
-print '</tr>'."\n";
-*/
-
 $var=!$var;
 print '<tr '.$bc[$var].'>'."\n";
 print '<td style="padding:5px;">'.$langs->trans('DelayForSubmitCP').'</td>'."\n";
@@ -316,19 +310,22 @@ print '<div align="center"><input type="submit" value="'.$langs->trans("ConfirmC
 print '</form>'."\n\n";
 
 dol_fiche_end();
-
+*/
 
 /*$var=!$var;
 print $langs->trans('nbUserCP').': '."\n";
 print $cp->getConfCP('nbUser')."<br>\n";
 */
 
+print '<br>'.$langs->trans("GoIntoDictionaryHolidayTypes").'<br><br>';
+
 $var=!$var;
-print $langs->trans('LastUpdateCP').': '."\n";
-if ($cp->getConfCP('lastUpdate')) print dol_print_date($db->jdate($cp->getConfCP('lastUpdate')),'dayhour','tzuser');
+print '<div class="info">'.$langs->trans('LastUpdateCP').': '."\n";
+if ($cp->getConfCP('lastUpdate')) print '<strong>'.dol_print_date($db->jdate($cp->getConfCP('lastUpdate')),'dayhour','tzuser').'</strong>';
 else print $langs->trans('None');
-print "<br>\n";
+print "</div><br>\n";
 
+/*
 print '<br>';
 
 print_fiche_titre($langs->trans('TitleOptionEventCP'),'','');
@@ -406,7 +403,7 @@ print '</table>';
 print '</form>';
 
 dol_fiche_end();
-
+*/
 
 // Fin de page
 llxFooter();

+ 0 - 225
htdocs/holiday/admin/tomergewithholiday.php

@@ -1,225 +0,0 @@
-<?php
-/* Copyright (C) 2012-2103 Laurent Destailleur	<eldy@users.sourceforge.net>
- * Copyright (C) 2011	   Dimitri Mouillard	<dmouillard@teclib.com>
- * Copyright (C) 2012	   Regis Houssin		<regis.houssin@capnetworks.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * 	Page module configuration paid holiday.
- *
- *  \file       holiday.php
- *	\ingroup    holiday
- *	\brief      Page module configuration paid holiday.
- */
-
-require '../../main.inc.php';
-require DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
-require_once DOL_DOCUMENT_ROOT. '/core/class/html.form.class.php';
-require_once DOL_DOCUMENT_ROOT. '/user/class/user.class.php';
-require_once DOL_DOCUMENT_ROOT. '/user/class/usergroup.class.php';
-
-// Si pas administrateur
-if (! $user->admin) accessforbidden();
-
-
-/*
- * View
- */
-
-// Vérification si module activé
-if (empty($conf->holiday->enabled)) print $langs->trans('NotActiveModCP');
-
-llxheader('',$langs->trans('TitleAdminCP'));
-
-print_fiche_titre($langs->trans('MenuCPTypes'));
-
-echo '<div id="types">';
-
-echo '<table class="noborder" style="width: 100%;">';
-echo '<tr class="liste_titre">';
-echo '<td style="width: 150px">' . $langs->trans('TypeLabel') . '</td>';
-echo '<td>' . $langs->trans('TypeDescription') . '</td>';
-echo '<td style="text-align: center; width: 100px">' . $langs->trans('TypeAffect') . '</td>';
-echo '<td style="text-align: center; width: 50px">' . $langs->trans('TypeDelay') . '</td>';
-echo '<td style="text-align: center;">' . $langs->trans('nbCongesDeductedCPMini') . '</td>';
-echo '<td style="text-align: center;">' . $langs->trans('nbCongesEveryMonthCPMini') . '</td>';
-echo '<td style="width: 40px"></td>';
-echo '</tr>';
-
-$types = $db->query(
-	"SELECT *
-   FROM llx_congespayes_types
-   WHERE deleteAt IS NULL
-   ORDER BY label"
-);
-
-while($type = $db->fetch_array($types))
-{
-   echo'
-      <tr id="row_'.$type['rowid'].'" '.$bc[$var=!$var].'>
-         <td>'.$type['label'].'</td>
-         <td>'.($type['description']?$type['description']:'N/A').'</td>
-         <td style="font-weight: bold; text-align: center">
-         '.($type['affect']?$langs->trans('TypeAffectYes'):$langs->trans('TypeAffectNo')).'
-         </td>
-         <td style="text-align: center">'.$type['delay'].'</td>
-         <td style="text-align: center">'.$type['nbCongesDeducted'].'</td>
-         <td style="text-align: center">'.$type['nbCongesEveryMonth'].'</td>
-         <td>
-            <img class="btn edit" data-rowid="'.$type['rowid'].'" src="../img/edit.png" title="'.$langs->trans('TypeBtnEdit').'">
-            <img class="btn delete" data-rowid="'.$type['rowid'].'" src="../img/delete.png" title="'.$langs->trans('TypeBtnDelete').'">
-         </td>
-      </tr>
-      <tr id="form_'.$type['rowid'].'" '.$bc[$var].' style="display: none">
-         <td colspan="7">
-            <form>
-               <input type="hidden" name="rowid" value="'.$type['rowid'].'">
-               <div>
-                  <label>' . $langs->trans('TypeLabel') . '</label>
-                  <input class="text" maxlength="45" name="label" type="text" value="'.$type['label'].'">
-               </div>
-               <div>
-                  <label>' . $langs->trans('TypeDescription') . '</label>
-                  <textarea name="description">'.$type['description'].'</textarea>
-               </div>
-               <div>
-                  <label>' . $langs->trans('TypeDelay') . '</label>
-                  <input class="text" maxlength="2" name="delay" type="text" value="'.$type['delay'].'" style="width: 50px">
-               </div>
-               <div>
-                  <label>' . $langs->trans('TypeAffect') . '</label>
-                  <select name="affect">
-                     <option value="1"'.($type['affect']?' selected':'').'>
-                        '.$langs->trans('TypeAffectYes').'
-                     </option>
-                     <option value="0"'.($type['affect']?'':' selected').'>
-                        '.$langs->trans('TypeAffectNo').'
-                     </option>
-                  </select>
-               </div>
-               <div>
-                  <label>' . $langs->trans('nbCongesDeductedCPMini') . '</label>
-                  <input class="text" maxlength="5" name="nbCongesDeducted" type="text"
-                        value="'.$type['nbCongesDeducted'].'" style="width: 50px">
-               </div>
-               <div>
-                  <label>' . $langs->trans('nbCongesEveryMonthCPMini') . '</label>
-                  <input class="text" maxlength="5" name="nbCongesEveryMonth" type="text"
-                        value="'.$type['nbCongesEveryMonth'].'" style="width: 50px">
-               </div>
-               <div style="text-align: right">
-                  <input class="btn btn-primary button " type="submit" value="'.$langs->trans('TypeBtnApply').'">
-                  <input data-rowid="'.$type['rowid'].'" class="btn cancel button" type="button" value="'.$langs->trans('TypeBtnCancel').'">
-               </div>
-            </form>
-         </td>
-      </tr>
-   ';
-}
-
-echo '
-   <tr id="row_new" '.$bc[!$var].'>
-      <td colspan="7" style="text-align: right;">
-         <img class="btn" id="new" src="../img/add.png" title="'.$langs->trans('TypeBtnAdd').'">
-      </td>
-   </tr>
-   <tr id="form_new" '.$bc[!$var].' style="display:none">
-      <td colspan="7">
-         <form>
-            <div>
-               <label>' . $langs->trans('TypeLabel') . '</label>
-               <input class="text" maxlength="45" name="label" type="text">
-            </div>
-            <div>
-               <label>' . $langs->trans('TypeDescription') . '</label>
-               <textarea name="description"></textarea>
-            </div>
-            <div>
-               <label>' . $langs->trans('TypeDelay') . '</label>
-               <input class="text" maxlength="2" name="delay" type="text" value="0" style="width: 50px">
-            </div>
-            <div>
-               <label>' . $langs->trans('TypeAffect') . '</label>
-               <select name="affect">
-                  <option value="1">'.$langs->trans('TypeAffectYes').'</option>
-                  <option value="0">'.$langs->trans('TypeAffectNo').'</option>
-               </select>
-            </div>
-            <div>
-               <label>' . $langs->trans('nbCongesDeductedCPMini') . '</label>
-               <input class="text" maxlength="5" name="nbCongesDeducted" type="text"
-                     value="0" style="width: 50px">
-            </div>
-            <div>
-               <label>' . $langs->trans('nbCongesEveryMonthCPMini') . '</label>
-               <input class="text" maxlength="5" name="nbCongesEveryMonth" type="text"
-                     value="0" style="width: 50px">
-            </div>
-            <div style="text-align: right">
-               <input class="btn btn-primary" type="submit" value="'.$langs->trans('TypeBtnAdd').'">
-               <input class="btn cancel" type="button" value="'.$langs->trans('TypeBtnCancel').'">
-            </div>
-         </form>
-      </td>
-   </tr>
-</table>
-<script>
-   $(function(){
-      $(".cancel", "#types").click(function(){
-         var rowid = false;
-         if(rowid = $(this).data("rowid")) {
-             $("#row_"+rowid, "#types").show();
-             $("#form_"+rowid, "#types").hide();
-         } else {
-             $("#row_new", "#types").show();
-             $("#form_new", "#types").hide();
-         }
-      });
-      $(".edit", "#types").click(function(){
-         var rowid = $(this).data("rowid");
-         $("#row_"+rowid, "#types").hide();
-         $("#form_"+rowid, "#types").show();
-      });
-      $("#new", "#types").click(function(){
-         $("#row_new", "#types").hide();
-         $("#form_new", "#types").show();
-      });
-      $("form", "#types").submit(function(){
-         $.post("ajax/types_editor.php", $(this).serialize(), function(response) {
-            if(response.status) window.location.reload();
-            else alert(response.content);
-         }, "json");
-         return false;
-      });
-      $(".delete", "#types").click(function(){
-         if(confirm("'.$langs->trans('TypeBtnDeleteConfirmation').'")) {
-            $.post("ajax/types_delete.php", {
-               rowid: $(this).data("rowid")
-            }, function(response) {
-               if(response.status) window.location.reload();
-               else alert(response.content);
-            }, "json");
-         }
-      });
-   });
-</script>
-';
-
-echo '</div>';
-
-llxFooter();
-
-$db->close();

+ 27 - 11
htdocs/holiday/card.php

@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2011	   Dimitri Mouillard	<dmouillard@teclib.com>
- * Copyright (C) 2012-2013 Laurent Destailleur	<eldy@users.sourceforge.net>
+ * Copyright (C) 2012-2015 Laurent Destailleur	<eldy@users.sourceforge.net>
  * Copyright (C) 2012	   Regis Houssin		<regis.houssin@capnetworks.com>
  * Copyright (C) 2013	   Juanjo Menent		<jmenent@2byte.es>
  * Copyright (C) 2014	   Ferran Marcet		<fmarcet@2byte.es>
@@ -381,7 +381,7 @@ if ($action == 'confirm_send')
 
 
 // Si Validation de la demande
-if($action == 'confirm_valid')
+if ($action == 'confirm_valid')
 {
     $cp = new Holiday($db);
     $cp->fetch($id);
@@ -673,7 +673,7 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
     else
     {
         // Formulaire de demande de congés payés
-        print_fiche_titre($langs->trans('MenuAddCP'));
+        print_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png');
 
         // Si il y a une erreur
         if (GETPOST('error')) {
@@ -747,8 +747,26 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
         print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" onsubmit="return valider()" name="demandeCP">'."\n";
         print '<input type="hidden" name="action" value="create" />'."\n";
         print '<input type="hidden" name="userID" value="'.$userid.'" />'."\n";
-        print '<div class="tabBar">';
-        print '<span>'.$langs->trans('DelayToRequestCP',$cp->getConfCP('delayForRequest')).'</span><br /><br />';
+
+        dol_fiche_head();
+
+        $out='';
+        $typeleaves=$cp->getTypes(1,1);
+    	foreach($typeleaves as $key => $val)
+		{
+			$nb_type = $cp->getCPforUser($user->id, $val['rowid']);
+			$nb_holiday += $nb_type;
+			$out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>';
+		}
+        print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>';
+		print $out;
+
+        dol_fiche_end();
+
+
+        dol_fiche_head();
+
+        //print '<span>'.$langs->trans('DelayToRequestCP',$cp->getConfCP('delayForRequest')).'</span><br /><br />';
 
         print '<table class="border" width="100%">';
         print '<tbody>';
@@ -761,8 +779,6 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
         	print '<input type="hidden" name="userid" value="'.$userid.'">';
         }
         else print $form->select_users(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0);
-        $nb_holiday = $cp->getCPforUser($user->id) / $cp->getConfCP('nbHolidayDeducted');
-        print ' &nbsp; <span>'.$langs->trans('SoldeCPUser', round($nb_holiday,2)).'</span>';
         print '</td>';
         print '</tr>';
         print '<tr>';
@@ -818,17 +834,17 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
 
         print '</tbody>';
         print '</table>';
-        print '<div style="clear: both;"></div>';
-        print '</div>';
-        print '</from>'."\n";
+
+        dol_fiche_end();
 
         print '<div class="center">';
         print '<input type="submit" value="'.$langs->trans("SendRequestCP").'" name="bouton" class="button">';
         print '&nbsp; &nbsp; ';
         print '<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)">';
         print '</div>';
-    }
 
+        print '</from>'."\n";
+    }
 }
 else
 {

+ 185 - 95
htdocs/holiday/class/holiday.class.php

@@ -373,6 +373,7 @@ class Holiday extends CommonObject
         $sql.= " cp.rowid,";
 
         $sql.= " cp.fk_user,";
+        $sql.= " cp.fk_type,";
         $sql.= " cp.date_create,";
         $sql.= " cp.description,";
         $sql.= " cp.date_debut,";
@@ -430,6 +431,7 @@ class Holiday extends CommonObject
                 $tab_result[$i]['rowid'] = $obj->rowid;
                 $tab_result[$i]['ref'] = $obj->rowid;
                 $tab_result[$i]['fk_user'] = $obj->fk_user;
+                $tab_result[$i]['fk_type'] = $obj->fk_type;
                 $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
                 $tab_result[$i]['description'] = $obj->description;
                 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
@@ -846,13 +848,15 @@ class Holiday extends CommonObject
      *  Retourne la valeur d'un paramètre de configuration
      *
      *  @param	string	$name       name du paramètre de configuration
+     *  @param	int		$fk_type	Filter on type
      *  @return string      		retourne la valeur du paramètre
      */
-    function getConfCP($name)
+    function getConfCP($name, $fk_type=0)
     {
         $sql = "SELECT value";
         $sql.= " FROM ".MAIN_DB_PREFIX."holiday_config";
         $sql.= " WHERE name = '".$name."'";
+        if ($fk_type > 0) $sql.=" AND fk_type = ".$fk_type;
 
         dol_syslog(get_class($this).'::getConfCP name='.$name.'', LOG_DEBUG);
         $result = $this->db->query($sql);
@@ -877,13 +881,16 @@ class Holiday extends CommonObject
      *
      *	@param		int		$userID		Id of user
      *	@param		int		$nbHoliday	Nb of days
+     *  @param		int		$fk_type	Type of vacation
      *  @return     int					0=Nothing done, 1=OK, -1=KO
      */
-    function updateSoldeCP($userID='',$nbHoliday='')
+    function updateSoldeCP($userID='',$nbHoliday='', $fk_type='')
     {
         global $user, $langs;
 
-        if (empty($userID) && empty($nbHoliday))
+        $error = 0;
+
+        if (empty($userID) && empty($nbHoliday) && empty($fk_type))
         {
             // Si mise à jour pour tout le monde en début de mois
 			$now=dol_now();
@@ -897,60 +904,112 @@ class Holiday extends CommonObject
             // Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp
             if ($month != $monthLastUpdate)
             {
+            	$this->db->begin();
+
                 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
                 $sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'";
                 $sql.= " WHERE name = 'lastUpdate'";
 
-                dol_syslog(get_class($this).'::updateSoldeCP', LOG_DEBUG);
                 $result = $this->db->query($sql);
 
-                // On ajoute x jours à chaque utilisateurs
-                $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');
-
-                    // On ajoute la modification dans le LOG
-                    $this->addLogCP($user->id,$users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'),$new_solde);
-
-                    $i++;
-                }
-
-                $sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
-                $sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
-
-                dol_syslog(get_class($this).'::updateSoldeCP', LOG_DEBUG);
-                $result= $this->db->query($sql2);
-
-	            if ($result) return 1;
-    	        else return -1;
+				$typeleaves=$cp->getTypes(1,1);
+    			foreach($typeleaves as $key => $val)
+    			{
+	                // On ajoute x jours à chaque utilisateurs
+	                $nb_holiday = $val['newByMonth'];
+					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'], $val['rowid']);
+	                    $new_solde = $now_holiday + $this->getConfCP('nbHolidayEveryMonth');
+
+	                    // On ajoute la modification dans le LOG
+	                    $this->addLogCP($user->id, $users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $new_solde, $val['rowid']);
+
+	                    $i++;
+	                }
+
+	                $sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
+	                $sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
+					$sql2.= " WHERE fk_type = ".$val['rowid'];
+
+	                $result= $this->db->query($sql2);
+
+	                if (! $result) break;
+    			}
+
+				if ($result)
+	           	{
+	            	$this->db->commit();
+	            	return 1;
+	           	}
+    	       	else
+    	      	{
+    	       		$this->db->rollback();
+    	        	return -1;
+    	       	}
             }
 
             return 0;
         }
         else
-        {
-            // Mise à jour pour un utilisateur
-            $nbHoliday = price2num($nbHoliday,2);
-
+		{
             // Mise à jour pour un utilisateur
-            $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
-            $sql.= " nb_holiday = ".$nbHoliday;
-            $sql.= " WHERE fk_user = '".$userID."'";
+            $nbHoliday = price2num($nbHoliday,5);
 
-			dol_syslog(get_class($this).'::updateSoldeCP', LOG_DEBUG);
-            $result = $this->db->query($sql);
+            $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
+            $sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
+            $resql = $this->db->query($sql);
+            if ($resql)
+            {
+            	$num = $this->db->num_rows($resql);
+
+            	if ($num > 0)
+            	{
+		            // Update for user
+		            $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
+		            $sql.= " nb_holiday = ".$nbHoliday;
+		            $sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
+		            $result = $this->db->query($sql);
+		            if (! $result)
+		            {
+		            	$error++;
+		            	$this->errors[]=$this->db->lasterror();
+		            }
+            	}
+            	else
+            	{
+		            // Insert for user
+		            $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
+		            $sql.= $nbHoliday;
+		            $sql.= ", '".$userID."', ".$fk_type.")";
+		            $result = $this->db->query($sql);
+		            if (! $result)
+		            {
+		            	$error++;
+		            	$this->errors[]=$this->db->lasterror();
+		            }
+            	}
+            }
+            else
+			{
+		        $this->errors[]=$this->db->lasterror();
+            	$error++;
+			}
 
-            if ($result) return 1;
-            else return -1;
+            if (! $error)
+            {
+            	return 1;
+            }
+            else
+           {
+            	return -1;
+            }
         }
 
     }
@@ -1036,24 +1095,29 @@ class Holiday extends CommonObject
      *  Retourne le solde de congés payés pour un utilisateur
      *
      *  @param	int		$user_id    ID de l'utilisateur
+     *  @param	int		$fk_type	Filter on type
      *  @return float        		Retourne le solde de congés payés de l'utilisateur
      */
-    function getCPforUser($user_id) {
-
+    function getCPforUser($user_id, $fk_type=0)
+    {
         $sql = "SELECT nb_holiday";
         $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users";
         $sql.= " WHERE fk_user = '".$user_id."'";
+        if ($fk_type > 0) $sql.=" AND fk_type = ".$fk_type;
 
         dol_syslog(get_class($this).'::getCPforUser', LOG_DEBUG);
         $result = $this->db->query($sql);
-        if($result) {
+        if($result)
+        {
             $obj = $this->db->fetch_object($result);
             //return number_format($obj->nb_holiday,2);
-			return $obj->nb_holiday;
-        } else {
-            return '0';
+            if ($obj) return $obj->nb_holiday;
+            else return null;
+        }
+        else
+		{
+            return null;
         }
-
     }
 
     /**
@@ -1067,9 +1131,10 @@ class Holiday extends CommonObject
     function fetchUsers($liste=true,$type=true)
     {
         // Si vrai donc pour user Dolibarr
-        if($liste) {
-
-            if($type) {
+        if ($liste)
+        {
+            if($type)
+            {
                 // Si utilisateur de Dolibarr
 
                 $sql = "SELECT u.rowid";
@@ -1109,7 +1174,9 @@ class Holiday extends CommonObject
                     return -1;
                 }
 
-            } else { // Si utilisateur du module Congés Payés
+            }
+            else
+           { // Si utilisateur du module Congés Payés
                 $sql = "SELECT u.fk_user";
                 $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as u";
 
@@ -1147,11 +1214,13 @@ class Holiday extends CommonObject
                 }
             }
 
-        } else { // Si faux donc user Congés Payés
+        }
+        else
+       { // Si faux donc user Congés Payés
 
             // Si c'est pour les utilisateurs de Dolibarr
-            if($type) {
-
+            if ($type)
+            {
                 $sql = "SELECT u.rowid, u.lastname, u.firstname";
                 $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
                 $sql.= " WHERE statut > 0";
@@ -1188,9 +1257,11 @@ class Holiday extends CommonObject
                 }
 
                 // Si c'est pour les utilisateurs du module Congés Payés
-            } else {
+            }
+            else
+           {
 
-                $sql = "SELECT cpu.fk_user, u.lastname, u.firstname";
+                $sql = "SELECT DISTINCT cpu.fk_user, u.lastname, u.firstname";
                 $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu,";
                 $sql.= " ".MAIN_DB_PREFIX."user as u";
                 $sql.= " WHERE cpu.fk_user = u.rowid";
@@ -1269,8 +1340,8 @@ class Holiday extends CommonObject
      *  @param    int	$userCP    				Number of active users into table of holidays
      *  @return   void
      */
-    function verifNbUsers($userDolibarrWithoutCP,$userCP) {
-
+    function verifNbUsers($userDolibarrWithoutCP,$userCP)
+    {
     	if (empty($userCP)) $userCP=0;
     	dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
 
@@ -1316,7 +1387,9 @@ class Holiday extends CommonObject
                 return -1;
             }
 
-        } else {
+        }
+        else
+       {
         	$this->db->begin();
 
         	// Si il y a moins d'utilisateur Dolibarr que dans le module CP
@@ -1599,51 +1672,53 @@ class Holiday extends CommonObject
      *
      * @param 	int		$fk_user_action		Id user creation
      * @param 	int		$fk_user_update		Id user update
-     * @param 	int		$type				Type
+     * @param 	string	$label				Label
      * @param 	int		$new_solde			New value
-     * @return number|string
+     * @param	int		$fk_type			Type of vacation
+     * @return 	int							Id of record added, 0 if nothing done, < 0 if KO
      */
-    function addLogCP($fk_user_action,$fk_user_update,$type,$new_solde) {
-
+    function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
+    {
         global $conf, $langs;
 
         $error=0;
 
-        $prev_solde = $this->getCPforUser($fk_user_update);
-        $new_solde = number_format($new_solde,2,'.','');
+        $prev_solde = price2num($this->getCPforUser($fk_user_update, $fk_type), 5);
+        $new_solde = price2num($new_solde, 5);
+		//print "$prev_solde == $new_solde";
 
-        // Insert request
-        $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
+        if ($prev_solde == $new_solde) return 0;
+
+		$this->db->begin();
 
+		// Insert request
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
         $sql.= "date_action,";
         $sql.= "fk_user_action,";
         $sql.= "fk_user_update,";
         $sql.= "type_action,";
         $sql.= "prev_solde,";
-        $sql.= "new_solde";
-
+        $sql.= "new_solde,";
+		$sql.= "fk_type";
         $sql.= ") VALUES (";
-
-        $sql.= " NOW(), ";
+        $sql.= " '".$this->db->idate(dol_now())."',";
         $sql.= " '".$fk_user_action."',";
         $sql.= " '".$fk_user_update."',";
-        $sql.= " '".$this->db->escape($type)."',";
+        $sql.= " '".$this->db->escape($label)."',";
         $sql.= " '".$prev_solde."',";
-        $sql.= " '".$new_solde."'";
+        $sql.= " '".$new_solde."',";
+        $sql.= " ".$fk_type;
         $sql.= ")";
 
-        $this->db->begin();
-
-   	   	dol_syslog(get_class($this)."::addLogCP", LOG_DEBUG);
-   	   	$resql=$this->db->query($sql);
-       	if (! $resql) {
+        $resql=$this->db->query($sql);
+       	if (! $resql)
+       	{
        	    $error++; $this->errors[]="Error ".$this->db->lasterror();
        	}
 
        	if (! $error)
        	{
        	    $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
-
        	}
 
        	// Commit or rollback
@@ -1682,8 +1757,8 @@ class Holiday extends CommonObject
         $sql.= " cpl.fk_user_update,";
         $sql.= " cpl.type_action,";
         $sql.= " cpl.prev_solde,";
-        $sql.= " cpl.new_solde";
-
+        $sql.= " cpl.new_solde,";
+		$sql.= " cpl.fk_type";
         $sql.= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
         $sql.= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
 
@@ -1724,6 +1799,7 @@ class Holiday extends CommonObject
   		        $tab_result[$i]['type_action'] = $obj->type_action;
   		        $tab_result[$i]['prev_solde'] = $obj->prev_solde;
   		        $tab_result[$i]['new_solde'] = $obj->new_solde;
+  		        $tab_result[$i]['fk_type'] = $obj->fk_type;
 
   		        $i++;
   		    }
@@ -1743,21 +1819,35 @@ class Holiday extends CommonObject
     /**
      *  Return array with list of types
      *
-     *  @return     boolean    Return array with list of types
+     *  @param		int		$active		Status of type
+     *  @param		int		$affect		Filter on affect
+     *  @return     array	    		Return array with list of types
      */
-    function getTypes()
+    function getTypes($active=-1, $affect=-1)
     {
-    	$result = $this->db->query("SELECT rowid, type, affect FROM " . MAIN_DB_PREFIX . "holiday_types");
-    	$num = $this->db->num_rows($result);
-    	if ($num)
-    	{
-    		while ($obj = $this->db->fetch_object($result))
-    		{
-    			$types[] = array('rowid'=> $obj->rowid, 'type'=> $obj->type, 'affect'=>$obj->affect);
-    		}
+    	global $mysoc;
 
-    		return $types;
+    	$sql = "SELECT rowid, code, label, affect, delay, newByMonth";
+    	$sql.= " FROM " . MAIN_DB_PREFIX . "c_holiday_types";
+    	$sql.= " WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.')';
+    	if ($active >= 0) $sql.=" AND active = ".((int) $active);
+    	if ($affect >= 0) $sql.=" AND affect = ".((int) $affect);
+
+    	$result = $this->db->query($sql);
+    	if ($result)
+    	{
+	    	$num = $this->db->num_rows($result);
+	    	if ($num)
+	    	{
+	    		while ($obj = $this->db->fetch_object($result))
+	    		{
+	    			$types[] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth);
+	    		}
+
+	    		return $types;
+	    	}
     	}
+    	else dol_print_error($this->db);
 
     	return array();
     }

+ 92 - 47
htdocs/holiday/define_holiday.php

@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2007-2012 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2007-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2011      Dimitri Mouillard <dmouillard@teclib.com>
  * Copyright (C) 2013      Marcos García <marcosgdf@gmail.com>
  *
@@ -37,62 +37,77 @@ if(!$user->rights->holiday->define_holiday) accessforbidden();
 
 $action=GETPOST('action');
 
-
-/*
- * View
- */
-
-$form = new Form($db);
-$userstatic=new User($db);
 $holiday = new Holiday($db);
 
 
-llxHeader(array(),$langs->trans('CPTitreMenu'));
-
-print_fiche_titre($langs->trans('MenuConfCP'));
-
-$holiday->updateSold();	// Create users into table holiday if they don't exists. TODO Remove if we use field into table user.
-
-$listUsers = $holiday->fetchUsers(false,false);
+/*
+ * Actions
+ */
 
 // Si il y a une action de mise à jour
 if ($action == 'update' && isset($_POST['update_cp']))
 {
+	$error = 0;
+
+	$typeleaves=$holiday->getTypes(1,1);
+
     $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;
+    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')."'";
+		    $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);
+		    */
+		}
     }
 
-    //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'));
+    if (! $error) setEventMessage($langs->trans('UpdateConfCPOK'));
 }
 elseif($action == 'add_event')
 {
     $error = 0;
 
+	$typeleaves=$holiday->getTypes(1,1);
+
     if(!empty($_POST['list_event']) && $_POST['list_event'] > 0) {
         $event = $_POST['list_event'];
     } else { $error++;
@@ -122,13 +137,29 @@ elseif($action == 'add_event')
     }
 }
 
+
+/*
+ * View
+ */
+
+$form = new Form($db);
+$userstatic=new User($db);
+
 $langs->load('users');
+
+llxHeader(array(),$langs->trans('CPTitreMenu'));
+
+print_fiche_titre($langs->trans('MenuConfCP'), '', 'title_hrm.png');
+
+$holiday->updateSold();	// Create users into table holiday if they don't exists. TODO Remove if we use field into table user.
+
+$listUsers = $holiday->fetchUsers(false,true);
+
 $var=true;
 $i = 0;
 
 $cp_events = $holiday->fetchEventsCP();
-
-if($cp_events == 1)
+if ($cp_events == 1)
 {
 	print '<br><form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
 	print '<input type="hidden" name="action" value="add_event" />';
@@ -144,19 +175,26 @@ if($cp_events == 1)
 	print '</form><br>';
 }
 
+
+$typeleaves=$holiday->getTypes(1,1);
+
 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
 print '<input type="hidden" name="action" value="update" />';
+
 print '<table class="noborder" width="100%;">';
 print "<tr class=\"liste_titre\">";
 print '<td width="55%">'.$langs->trans('Employee').'</td>';
-print '<td width="20%" style="text-align:center">'.$langs->trans('Available').'</td>';
+foreach($typeleaves as $key => $val)
+{
+	print '<td width="20%" style="text-align:center">'.$val['label'].'</td>';
+}
 print '<td width="20%" style="text-align:center">'.$langs->trans('Note').'</td>';
 print '<td></td>';
 print '</tr>';
 
+
 foreach($listUsers as $users)
 {
-
     $var=!$var;
 
     print '<tr '.$bc[$var].' style="height: 20px;">';
@@ -166,9 +204,15 @@ foreach($listUsers as $users)
     $userstatic->firstname=$users['firstname'];
     print $userstatic->getNomUrl(1);
     print '</td>';
-    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";
+	foreach($typeleaves as $key => $val)
+	{
+		$nbtoshow='';
+		if ($holiday->getCPforUser($users['rowid'], $val['rowid']) != '') $nbtoshow=price2num($holiday->getCPforUser($users['rowid'], $val['rowid']), 5);
+    	print '<td style="text-align:center">';
+    	print '<input type="text" value="'.$nbtoshow.'" name="nb_holiday_'.$val['rowid'].'['.$users['rowid'].']" size="5" style="text-align: center;"/>';
+	    //print ' '.$langs->trans('days');
+    	print '</td>'."\n";
+	}
     print '<td style="text-align:center"><input type="text" value="" name="note_holiday['.$users['rowid'].']" size="30"/></td>';
     print '<td><input type="submit" name="update_cp['.$users['rowid'].']" value="'.dol_escape_htmltag($langs->trans("Update")).'" class="button"/></td>'."\n";
     print '</tr>';
@@ -177,6 +221,7 @@ foreach($listUsers as $users)
 }
 
 print '</table>';
+
 print '</form>';
 
 llxFooter();

+ 35 - 21
htdocs/holiday/index.php

@@ -189,24 +189,23 @@ if ($id > 0)
 // Récupération des congés payés de l'utilisateur ou de tous les users
 if (!$user->rights->holiday->write_all || $id > 0)
 {
-	$holiday_payes = $holiday->fetchByUser($user_id,$order,$filter);
+	$holiday_payes = $holiday->fetchByUser($user_id,$order,$filter);	// Load array $holiday->holiday
 }
 else
 {
-    $holiday_payes = $holiday->fetchAll($order,$filter);
+    $holiday_payes = $holiday->fetchAll($order,$filter);	// Load array $holiday->holiday
 }
 // Si erreur SQL
 if ($holiday_payes == '-1')
 {
-    print_fiche_titre($langs->trans('CPTitreMenu'));
+    print_fiche_titre($langs->trans('CPTitreMenu'), '', 'title_hrm.png');
 
     dol_print_error($db, $langs->trans('Error').' '.$holiday->error);
     exit();
 }
 
-/*************************************
- * Affichage du tableau des congés payés
-*************************************/
+
+// Show table of vacations
 
 $var=true; $num = count($holiday->holiday);
 $form = new Form($db);
@@ -242,19 +241,26 @@ if ($id > 0)
 }
 else
 {
-	print_barre_liste($langs->trans("ListeCP"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, "", $num);
+	print_barre_liste($langs->trans("ListeCP"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, "", $num, 0, 'title_hrm.png');
 
 	dol_fiche_head('');
 }
 
 
-$nbaquis=$holiday->getCPforUser($user_id);
-$nbdeduced=$holiday->getConfCP('nbHolidayDeducted');
-$nb_holiday = $nbaquis / $nbdeduced;
-print $langs->trans('SoldeCPUser',round($nb_holiday,2)).($nbdeduced != 1 ? ' ('.$nbaquis.' / '.$nbdeduced.')' : '');
+$out='';
+$typeleaves=$holiday->getTypes(1,1);
+foreach($typeleaves as $key => $val)
+{
+	$nb_type = $holiday->getCPforUser($user->id, $val['rowid']);
+	$nb_holiday += $nb_type;
+	$out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>';
+}
+print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>';
+print $out;
 
 dol_fiche_end();
 
+
 if ($id > 0) print '</br>';
 
 
@@ -265,11 +271,12 @@ print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cp.rowid","",
 print_liste_field_titre($langs->trans("DateCreateCP"),$_SERVER["PHP_SELF"],"cp.date_create","",'','align="center"',$sortfield,$sortorder);
 print_liste_field_titre($langs->trans("Employe"),$_SERVER["PHP_SELF"],"cp.fk_user","",'','',$sortfield,$sortorder);
 print_liste_field_titre($langs->trans("ValidatorCP"),$_SERVER["PHP_SELF"],"cp.fk_validator","",'','',$sortfield,$sortorder);
+print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder);
+print_liste_field_titre($langs->trans("Duration"),$_SERVER["PHP_SELF"],'','','','align="center"',$sortfield,$sortorder);
 print_liste_field_titre($langs->trans("DateDebCP"),$_SERVER["PHP_SELF"],"cp.date_debut","",'','align="center"',$sortfield,$sortorder);
 print_liste_field_titre($langs->trans("DateFinCP"),$_SERVER["PHP_SELF"],"cp.date_fin","",'','align="center"',$sortfield,$sortorder);
-print_liste_field_titre($langs->trans("Duration"),$_SERVER["PHP_SELF"],'','','','align="center"',$sortfield,$sortorder);
 print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cp.statut","",'','align="center"',$sortfield,$sortorder);
-print '<td></td>';
+print_liste_field_titre('');
 print "</tr>\n";
 
 // FILTRES
@@ -285,9 +292,10 @@ $formother->select_year($year_create,'year_create',1, $min_year, 0);
 print '</td>';
 
 // UTILISATEUR
-if($user->rights->holiday->write_all) {
+if($user->rights->holiday->write_all)
+{
     print '<td class="liste_titre" align="left">';
-    $form->select_users($search_employe,"search_employe",1,"",0,'');
+    print $form->select_dolusers($search_employe,"search_employe",1,"",0,'','',0,32);
     print '</td>';
 } else {
     print '<td class="liste_titre">&nbsp;</td>';
@@ -303,7 +311,7 @@ if($user->rights->holiday->write_all)
     $valideurobjects = $validator->listUsersForGroup($excludefilter);
     $valideurarray = array();
     foreach($valideurobjects as $val) $valideurarray[$val->id]=$val->id;
-    $form->select_users($search_valideur,"search_valideur",1,"",0,$valideurarray,'');
+    print $form->select_dolusers($search_valideur,"search_valideur",1,"",0,$valideurarray,'', 0, 32);
     print '</td>';
 }
 else
@@ -311,6 +319,13 @@ else
     print '<td class="liste_titre">&nbsp;</td>';
 }
 
+// Type
+print '<td class="liste_titre" colspan="1" align="center">';
+print '</td>';
+
+// DUREE
+print '<td>&nbsp;</td>';
+
 // DATE DEBUT
 print '<td class="liste_titre" colspan="1" align="center">';
 print '<input class="flat" type="text" size="1" maxlength="2" name="month_start" value="'.$month_start.'">';
@@ -323,9 +338,6 @@ print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" v
 $formother->select_year($year_end,'year_end',1, $min_year, $max_year);
 print '</td>';
 
-// DUREE
-print '<td>&nbsp;</td>';
-
 // STATUT
 print '<td class="liste_titre" width="70px;" align="center">';
 $holiday->selectStatutCP($search_statut);
@@ -371,11 +383,13 @@ if (! empty($holiday->holiday))
 		print '<td style="text-align: center;">'.dol_print_date($date,'day').'</td>';
 		print '<td>'.$userstatic->getNomUrl('1').'</td>';
 		print '<td>'.$approbatorstatic->getNomUrl('1').'</td>';
-		print '<td align="center">'.dol_print_date($infos_CP['date_debut'],'day').'</td>';
-		print '<td align="center">'.dol_print_date($infos_CP['date_fin'],'day').'</td>';
+		print '<td>'.$infos_CP['fk_type'].'</td>';
 		print '<td align="right">';
 		$nbopenedday=num_open_day($infos_CP['date_debut_gmt'], $infos_CP['date_fin_gmt'], 0, 1, $infos_CP['halfday']);
 		print $nbopenedday.' '.$langs->trans('DurationDays');
+		print '</td>';
+		print '<td align="center">'.dol_print_date($infos_CP['date_debut'],'day').'</td>';
+		print '<td align="center">'.dol_print_date($infos_CP['date_fin'],'day').'</td>';
 		print '<td align="right" colspan="2">'.$holidaystatic->LibStatut($infos_CP['statut'],5).'</td>';
 		print '</tr>'."\n";
 

+ 1 - 1
htdocs/holiday/month_report.php

@@ -71,7 +71,7 @@ $sql.= " ORDER BY u.lastname,cp.date_debut";
 $result  = $db->query($sql);
 $num = $db->num_rows($result);
 
-print_fiche_titre($langs->trans('MenuReportMonth'));
+print_fiche_titre($langs->trans('MenuReportMonth'), '', 'title_hrm.png');
 
 print '<div class="tabBar">';
 

+ 6 - 4
htdocs/holiday/view_log.php

@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2007-2014 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2007-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2011      Dimitri Mouillard    <dmouillard@teclib.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -55,7 +55,7 @@ $cp = new Holiday($db);
 // Recent changes are more important than old changes
 $log_holiday = $cp->fetchLog('ORDER BY cpl.rowid DESC', " AND date_action BETWEEN '".$db->idate(dol_get_first_day($year,1,1))."' AND '".$db->idate(dol_get_last_day($year,12,1))."'");	// Load $cp->logs
 
-print_fiche_titre($langs->trans('LogCP'),'<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'">'.img_previous().'</a> '.$langs->trans("Year").':'.$year.' <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'">'.img_next().'</a>');
+print load_fiche_titre($langs->trans('LogCP'), '<div class="pagination"><ul><li class="pagination"><a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'">&lt;</a><li class="pagination"><a href="">'.$langs->trans("Year").' '.$year.'</a></li><li class="pagination"><a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'">&gt;</a></li></lu></div>', 'title_hrm.png');
 
 print '<table class="noborder" width="100%">';
 print '<tbody>';
@@ -66,6 +66,7 @@ print '<td class="liste_titre" align="center">'.$langs->trans('Date').'</td>';
 print '<td class="liste_titre">'.$langs->trans('ActionByCP').'</td>';
 print '<td class="liste_titre">'.$langs->trans('UserUpdateCP').'</td>';
 print '<td class="liste_titre">'.$langs->trans('Description').'</td>';
+print '<td class="liste_titre">'.$langs->trans('Type').'</td>';
 print '<td class="liste_titre" align="right">'.$langs->trans('PrevSoldeCP').'</td>';
 print '<td class="liste_titre" align="right">'.$langs->trans('NewSoldeCP').'</td>';
 
@@ -88,8 +89,9 @@ foreach($cp->logs as $logs_CP)
    	print '<td>'.$user_action->getNomUrl(1).'</td>';
    	print '<td>'.$user_update->getNomUrl(1).'</td>';
    	print '<td>'.$logs_CP['type_action'].'</td>';
-   	print '<td style="text-align: right;">'.price2num($logs_CP['prev_solde'],8).' '.$langs->trans('days').'</td>';
-   	print '<td style="text-align: right;">'.price2num($logs_CP['new_solde'],8).' '.$langs->trans('days').'</td>';
+   	print '<td>'.$logs_CP['fk_type'].'</td>';
+   	print '<td style="text-align: right;">'.price2num($logs_CP['prev_solde'],5).' '.$langs->trans('days').'</td>';
+   	print '<td style="text-align: right;">'.price2num($logs_CP['new_solde'],5).' '.$langs->trans('days').'</td>';
    	print '</tr>'."\n";
 
 }

+ 20 - 1
htdocs/install/mysql/migration/3.7.0-3.8.0.sql

@@ -676,6 +676,8 @@ ALTER TABLE llx_c_stcomm ADD COLUMN picto varchar(128);
 INSERT INTO llx_c_action_trigger (code, label, description, elementtype, rang) VALUES ('BILL_SUPPLIER_UNVALIDATE','Supplier invoice unvalidated','Executed when a supplier invoice status is set back to draft','invoice_supplier',15);
 
 
+ALTER TABLE llx_holiday_users DROP PRIMARY KEY;
+
 DROP TABLE llx_holiday_types;
 
 CREATE TABLE llx_c_holiday_types (
@@ -685,6 +687,23 @@ CREATE TABLE llx_c_holiday_types (
   affect integer NOT NULL,	
   delay integer NOT NULL,
   newByMonth double(8,5) DEFAULT 0 NOT NULL,
-  fk_country integer DEFAULT NULL
+  fk_country integer DEFAULT NULL,
+  active integer DEFAULT 1
 ) ENGINE=innodb;
 
+ALTER TABLE llx_c_holiday_types ADD UNIQUE INDEX uk_c_holiday_types(code);
+
+insert into llx_c_holiday_types(code, label, affect, delay, newByMonth, fk_country) values ('LEAVE_PAID', 'Paid vacation', 1, 7, 0,    NULL);
+insert into llx_c_holiday_types(code, label, affect, delay, newByMonth, fk_country) values ('LEAVE_SICK', 'Sick leave',    0, 0, 0,    NULL);
+insert into llx_c_holiday_types(code, label, affect, delay, newByMonth, fk_country) values ('LEAVE_OTHER','Other leave',   0, 0, 0,    NULL);
+-- Leaves specific to France
+insert into llx_c_holiday_types(code, label, affect, delay, newByMonth, fk_country) values ('LEAVE_RTT',  'RTT'          , 1, 7, 0.83, 1);
+
+ALTER TABLE llx_holiday ADD COLUMN fk_type integer NOT NULL DEFAULT 1;
+ALTER TABLE llx_holiday_users ADD COLUMN fk_type integer NOT NULL DEFAULT 1;
+ALTER TABLE llx_holiday_logs ADD COLUMN fk_type integer NOT NULL DEFAULT 1;
+
+UPDATE llx_holiday_users SET fk_type = 1 WHERE fk_type IS NULL;
+UPDATE llx_holiday_logs SET fk_type = 1 WHERE fk_type IS NULL;
+
+

+ 19 - 0
htdocs/install/mysql/tables/llx_c_holiday_types.key.sql

@@ -0,0 +1,19 @@
+-- ===================================================================
+-- Copyright (C) 2012      Laurent Destailleur  <eldy@users.sourceforge.net>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+ALTER TABLE llx_c_holiday_types ADD UNIQUE INDEX uk_c_holiday_types(code);

+ 2 - 1
htdocs/install/mysql/tables/llx_c_holiday_types.sql

@@ -23,5 +23,6 @@ CREATE TABLE llx_c_holiday_types (
   affect integer NOT NULL,						-- a request will change sold or not
   delay integer NOT NULL,						-- Minimum delay to be allowed to make request
   newByMonth double(8,5) DEFAULT 0 NOT NULL, -- Amount of new days for each user each month
-  fk_country integer DEFAULT NULL				-- This type is dedicated to a country
+  fk_country integer DEFAULT NULL,			-- This type is dedicated to a country
+  active integer DEFAULT 1
 ) ENGINE=innodb;

+ 1 - 0
htdocs/install/mysql/tables/llx_holiday.sql

@@ -21,6 +21,7 @@ CREATE TABLE llx_holiday
 rowid          integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
 fk_user        integer NOT NULL,
 fk_user_create integer,
+fk_type        integer NOT NULL,
 date_create    DATETIME NOT NULL,
 description    VARCHAR( 255 ) NOT NULL,
 date_debut     DATE NOT NULL,

+ 1 - 0
htdocs/install/mysql/tables/llx_holiday_logs.sql

@@ -22,6 +22,7 @@ rowid             integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
 date_action       DATETIME NOT NULL,
 fk_user_action    integer NOT NULL,
 fk_user_update    integer NOT NULL,
+fk_type           integer NOT NULL,
 type_action       VARCHAR( 255 ) NOT NULL,
 prev_solde        VARCHAR( 255 ) NOT NULL,
 new_solde         VARCHAR( 255 ) NOT NULL

+ 4 - 3
htdocs/install/mysql/tables/llx_holiday_users.sql

@@ -1,5 +1,5 @@
 -- ===================================================================
--- Copyright (C) 2012      Laurent Destailleur  <eldy@users.sourceforge.net>
+-- Copyright (C) 2012-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -18,7 +18,8 @@
 
 CREATE TABLE llx_holiday_users 
 (
-fk_user     integer NOT NULL PRIMARY KEY,
-nb_holiday   real NOT NULL DEFAULT '0'
+	fk_user     integer NOT NULL,
+	fk_type     integer NOT NULL,
+	nb_holiday   real NOT NULL DEFAULT '0'
 ) 
 ENGINE=innodb;

+ 1 - 0
htdocs/langs/en_US/admin.lang

@@ -820,6 +820,7 @@ DictionaryAccountancysystem=Models for chart of accounts
 DictionaryEMailTemplates=Emails templates
 DictionaryUnits=Units
 DictionaryProspectStatus=Prospection status
+DictionaryHolidayTypes=Type of leaves
 SetupSaved=Setup saved
 BackToModuleList=Back to modules list
 BackToDictionaryList=Back to dictionaries list

+ 3 - 1
htdocs/langs/en_US/holiday.lang

@@ -71,7 +71,7 @@ MotifCP=Reason
 UserCP=User
 ErrorAddEventToUserCP=An error occurred while adding the exceptional leave.
 AddEventToUserOkCP=The addition of the exceptional leave has been completed.
-MenuLogCP=View logs of leave requests
+MenuLogCP=View change logs
 LogCP=Log of updates of available vacation days
 ActionByCP=Performed by
 UserUpdateCP=For the user
@@ -146,3 +146,5 @@ Permission20003=Delete leave requests
 Permission20004=Setup users available vacation days
 Permission20005=Review log of modified leave requests
 Permission20006=Read leaves monthly report
+NewByMonth=Added per month
+GoIntoDictionaryHolidayTypes=Go into <strong>Home - Setup - Dictionaries - Type of leaves</strong> to setup the different types of leaves.

BIN
htdocs/theme/eldy/img/menus_black/globe.png


BIN
htdocs/theme/eldy/img/menus_black/holiday.png


BIN
htdocs/theme/eldy/img/title_hrm.png