From 452c9e22bb4a443a8387a22b37a79cdbceb9b406 Mon Sep 17 00:00:00 2001 From: philippe-opendsi Date: Fri, 16 Mar 2018 15:24:49 +0100 Subject: [PATCH] Add mass action on project's list to close projects --- htdocs/langs/en_US/projects.lang | 4 ++- htdocs/projet/list.php | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index a064d032083..8d62a4190ca 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -222,4 +222,6 @@ NoAssignedTasks=No assigned tasks (assign project/tasks the current user from th # Comments trans AllowCommentOnTask=Allow user comments on tasks AllowCommentOnProject=Allow user comments on projects - +DontHavePermissionForCloseProject=You do not have permissions to close the project %s +DontHaveTheValidateStatus=The project %s must be open to be closed +RecordsClosed=%s project(s) closed diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index e148caeb328..90f0fc56755 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -195,6 +195,52 @@ if (empty($reshook)) $permtodelete = $user->rights->projet->supprimer; $uploaddir = $conf->projet->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + + // Close records + if (! $error && $massaction == 'close' && $user->rights->projet->creer) + { + $db->begin(); + + $objecttmp=new $objectclass($db); + $nbok = 0; + foreach($toselect as $toselectid) + { + $result=$objecttmp->fetch($toselectid); + if ($result > 0) + { + $userWrite = $object->restrictedProjectArea($user,'write'); + if ($userWrite > 0 && $objecttmp->statut == 1) { + $result = $objecttmp->setClose($user); + if ($result <= 0) { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } else $nbok++; + } elseif($userWrite <= 0) { + setEventMessages($langs->trans("DontHavePermissionForCloseProject", $objecttmp->ref), null, 'warnings'); + } else { + setEventMessages($langs->trans("DontHaveTheValidateStatus", $objecttmp->ref), null, 'warnings'); + } + } + else + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (! $error) + { + if ($nbok > 1) setEventMessages($langs->trans("RecordsClosed", $nbok), null, 'mesgs'); + else setEventMessages($langs->trans("RecordsClosed", $nbok), null, 'mesgs'); + $db->commit(); + } + else + { + $db->rollback(); + } + } } @@ -390,7 +436,9 @@ $arrayofmassactions = array( ); //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer"); if ($user->rights->societe->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete"); +if ($user->rights->projet->creer) $arrayofmassactions['close']=$langs->trans("Close"); if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); print '
';