Skip to content

Commit

Permalink
Add mass action on project's list to close projects
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe-opendsi committed Mar 16, 2018
1 parent 9997a6c commit 452c9e2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
4 changes: 3 additions & 1 deletion htdocs/langs/en_US/projects.lang
Expand Up @@ -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
48 changes: 48 additions & 0 deletions htdocs/projet/list.php
Expand Up @@ -195,6 +195,52 @@
$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();
}
}
}


Expand Down Expand Up @@ -390,7 +436,9 @@
);
//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 '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
Expand Down

0 comments on commit 452c9e2

Please sign in to comment.