diff --git a/htdocs/core/modules/modExpenseReport.class.php b/htdocs/core/modules/modExpenseReport.class.php index 489b0fb77f1..4215bbdfa2a 100644 --- a/htdocs/core/modules/modExpenseReport.class.php +++ b/htdocs/core/modules/modExpenseReport.class.php @@ -115,12 +115,6 @@ class modExpenseReport extends DolibarrModules $this->rights[4][3] = 0; $this->rights[4][4] = 'supprimer'; - $this->rights[2][0] = 774; - $this->rights[2][1] = 'Read all expense reports'; - $this->rights[2][2] = 'r'; - $this->rights[2][3] = 1; - $this->rights[2][4] = 'readall'; - $this->rights[6][0] = 775; $this->rights[6][1] = 'Approve expense reports'; $this->rights[6][2] = 'w'; @@ -133,20 +127,17 @@ class modExpenseReport extends DolibarrModules $this->rights[7][3] = 0; $this->rights[7][4] = 'to_paid'; - if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) - { - $this->rights[8][0] = 777; - $this->rights[8][1] = 'Synchroniser les NDF avec un compte courant'; - $this->rights[8][2] = 'w'; - $this->rights[8][3] = 0; - $this->rights[8][4] = 'synchro'; + $this->rights[2][0] = 777; + $this->rights[2][1] = 'Read expense reports of everybody'; + $this->rights[2][2] = 'r'; + $this->rights[2][3] = 1; + $this->rights[2][4] = 'readall'; - $this->rights[9][0] = 778; - $this->rights[9][1] = 'Exporter les NDF au format CSV'; - $this->rights[9][2] = 'r'; - $this->rights[9][3] = 0; - $this->rights[9][4] = 'export_csv'; - } + $this->rights[2][0] = 778; + $this->rights[2][1] = 'Create expense reports for everybody'; + $this->rights[2][2] = 'w'; + $this->rights[2][3] = 0; + $this->rights[2][4] = 'writeall_advance'; $this->rights[5][0] = 779; $this->rights[5][1] = 'Export expense reports'; diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 84985a8312d..06b7fb94cc0 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -46,6 +46,8 @@ $langs->load("mails"); $action=GETPOST('action'); $cancel=GETPOST('cancel'); +$confirm = GETPOST('confirm', 'alpha'); + $date_start = dol_mktime(0, 0, 0, GETPOST('date_debutmonth'), GETPOST('date_debutday'), GETPOST('date_debutyear')); $date_end = dol_mktime(0, 0, 0, GETPOST('date_finmonth'), GETPOST('date_finday'), GETPOST('date_finyear')); $date = dol_mktime(0, 0, 0, GETPOST('datemonth'), GETPOST('dateday'), GETPOST('dateyear')); @@ -192,6 +194,12 @@ if (empty($reshook)) $object->date_debut = $date_start; $object->date_fin = $date_end; + $object->fk_user_author = GETPOST('fk_user_author','int'); + if (! ($object->fk_user_author > 0)) $object->fk_user_author = $user->id; + + $fuser=new User($db); + $fuser->fetch($object->fk_user_author); + $object->fk_statut = 1; $object->fk_c_paiement = GETPOST('fk_c_paiement','int'); $object->fk_user_validator = GETPOST('fk_user_validator','int'); @@ -204,7 +212,7 @@ if (empty($reshook)) if ($ret < 0) $error++; } - if ($object->periode_existe($user,$object->date_debut,$object->date_fin)) + if ($object->periode_existe($fuser,$object->date_debut,$object->date_fin)) { $error++; setEventMessages($langs->trans("ErrorDoubleDeclaration"), null, 'errors'); @@ -1198,18 +1206,35 @@ if ($action == 'create') print '
| '.$langs->trans("DateStart").' | '; print ''; $form->select_date($date_start?$date_start:-1,'date_debut',0,0,0,'',1,1); print ' | '; print '|
| '.$langs->trans("DateEnd").' | '; print ''; $form->select_date($date_end?$date_end:-1,'date_fin',0,0,0,'',1,1); print ' | '; print '|
| '.$langs->trans("User").' | '; + print ''; + $defaultselectuser=$user->id; + if (GETPOST('fk_user_author') > 0) $defaultselectuser=GETPOST('fk_user_author'); + $include_users = array($user->id); + if (! empty($user->rights->expensereport->writeall)) $include_users=array(); + $s=$form->select_dolusers($defaultselectuser, "fk_user_author", 0, "", 0, $include_users); + print $s; + print ' | '; + print '|
| '.$langs->trans("VALIDATOR").' | '; print ''; @@ -1222,6 +1247,8 @@ if ($action == 'create') print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); print ' | '; print '|
| '.$langs->trans("User").' | '; + print ''; + $userfee=new User($db); + $userfee->fetch($object->fk_user_author); + print $userfee->getNomUrl(-1); + print ' | |
| '.$langs->trans("Ref").' | '; print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); @@ -1372,13 +1408,6 @@ else print ' | |
| '.$langs->trans("AUTHOR").' | '; - print ''; - $userfee=new User($db); - $userfee->fetch($object->fk_user_author); - print $userfee->getNomUrl(-1); - print ' | |
| '.$langs->trans("User").' | '; + print ''; + if ($object->fk_user_author > 0) + { + $userauthor=new User($db); + $result=$userauthor->fetch($object->fk_user_author); + if ($result < 0) dol_print_error('',$userauthor->error); + print $userauthor->getNomUrl(-1); + } + print ' | |
| '.$langs->trans("Period").' | '; print ''; @@ -1595,19 +1651,6 @@ else print ' | '.price($object->total_ttc).' | '; print '
| '.$langs->trans("AUTHOR").' | '; - print ''; - if ($object->fk_user_author > 0) - { - $userauthor=new User($db); - $result=$userauthor->fetch($object->fk_user_author); - if ($result < 0) dol_print_error('',$userauthor->error); - print $userauthor->getNomUrl(-1); - } - print ' | |
| '.$langs->trans("DATE_SAVE").' | '; @@ -2201,6 +2244,10 @@ if ($action != 'create' && $action != 'edit') print ''; } + // Clone + if ($user->rights->expensereport->creer) { + print ''; + } /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */ if ($user->rights->expensereport->creer && $user->id == $object->fk_user_author && $object->fk_statut <= 4) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index f65f0119a85..feb61c130e7 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -126,6 +126,9 @@ class ExpenseReport extends CommonObject $now = dol_now(); + $fuserid = $this->fk_user_author; + if (empty($fuserid)) $fuserid = $user->id; + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; @@ -153,7 +156,7 @@ class ExpenseReport extends CommonObject $sql.= ", '".$this->db->idate($this->date_debut)."'"; $sql.= ", '".$this->db->idate($this->date_fin)."'"; $sql.= ", '".$this->db->idate($now)."'"; - $sql.= ", ".($user->id > 0 ? $user->id:"null"); + $sql.= ", ".$fuserid; $sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null"); $sql.= ", ".($this->fk_user_modif > 0 ? $this->fk_user_modif:"null"); $sql.= ", ".($this->fk_statut > 1 ? $this->fk_statut:0); @@ -222,6 +225,78 @@ class ExpenseReport extends CommonObject } + + /** + * Load an object from its id and create a new one in database + * + * @param int $socid Id of thirdparty + * @return int New id of clone + */ + function createFromClone($socid=0) + { + global $user,$hookmanager; + + $error=0; + + $this->context['createfromclone'] = 'createfromclone'; + + $this->db->begin(); + + // get extrafields so they will be clone + foreach($this->lines as $line) + //$line->fetch_optionals($line->rowid); + + // Load source object + $objFrom = clone $this; + + $this->id=0; + $this->ref = ''; + $this->statut=0; + + // Clear fields + $this->fk_user_author = $user->id; + $this->fk_user_valid = ''; + $this->date_create = ''; + $this->date_creation = ''; + $this->date_validation = ''; + + // Create clone + $result=$this->create($user); + if ($result < 0) $error++; + + if (! $error) + { + // Hook of thirdparty module + if (is_object($hookmanager)) + { + $parameters=array('objFrom'=>$objFrom); + $action=''; + $reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; + } + + // Call trigger + $result=$this->call_trigger('EXPENSEREPORT_CLONE',$user); + if ($result < 0) $error++; + // End call triggers + } + + unset($this->context['createfromclone']); + + // End + if (! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** * update * diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index e6493fe36db..ab9f318ca89 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -100,7 +100,7 @@ if (empty($user->socid)) $fieldstosearchall["d.note_private"]="NotePrivate"; $arrayfields=array( 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), - 'user'=>array('label'=>$langs->trans("Person"), 'checked'=>1), + 'user'=>array('label'=>$langs->trans("User"), 'checked'=>1), 'd.date_debut'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1), 'd.date_fin'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1), 'd.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1), @@ -248,7 +248,8 @@ if ($search_status != '' && $search_status >= 0) else $sql.=" AND d.fk_statut = ".$search_status; } // RESTRICT RIGHTS -if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) +if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) + && empty($user->rights->expensereport->writeall_advance)) { $childids = $user->getAllChildIds(); $childids[]=$user->id; @@ -354,7 +355,7 @@ if ($resql) print '