diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index e2d6d87838c..95c918536d9 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -226,6 +226,7 @@ LatestProjects=Latest %s projects LatestModifiedProjects=Latest %s modified projects OtherFilteredTasks=Other filtered tasks NoAssignedTasks=No assigned tasks found (assign project/tasks to the current user from the top select box to enter time on it) +ThirdPartyRequiredToGenerateInvoice=A third party must be defined on project to be able to invoice it. # Comments trans AllowCommentOnTask=Allow user comments on tasks AllowCommentOnProject=Allow user comments on projects @@ -235,4 +236,5 @@ RecordsClosed=%s project(s) closed SendProjectRef=Information project %s ModuleSalaryToDefineHourlyRateMustBeEnabled=Module 'Salaries' must be enabled to define employee hourly rate to have time spent valorized NewTaskRefSuggested=Task ref already used, a new task ref is required -TimeSpentInvoiced=Time spent billed \ No newline at end of file +TimeSpentInvoiced=Time spent billed +GenerateInvoice=Generate invoice \ No newline at end of file diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 90c7434a42a..60144644262 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -285,9 +285,13 @@ if (! empty($project_ref) && ! empty($withproject)) // To show all time lines for project $projectidforalltimes=0; -if (GETPOST('projectid','int')) +if (GETPOST('projectid','int') > 0) { $projectidforalltimes=GETPOST('projectid','int'); + + $result=$projectstatic->fetch($projectidforalltimes); + if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); + $res=$projectstatic->fetch_optionals(); } elseif (GETPOST('project_ref','alpha')) { @@ -296,6 +300,60 @@ elseif (GETPOST('project_ref','alpha')) $withproject=1; } +if ($massaction == 'generateinvoice') +{ + if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); + + //->fetch_thirdparty(); + + if (! ($projectstatic->thirdparty->id > 0)) + { + setEventMessages($langs->trans("ThirdPartyRequiredToGenerateInvoice"), null, 'errors'); + } + else + { + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + include_once DOL_DOCUMENT_ROOT.'/project/class/projet.class.php'; + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + + $tmpinvoice = new Facture($db); + $tmptimespent=new Task(); + $tmpproduct=new Product($db); + $fuser = new User($db); + $idprod = 0; + + $txtva = get_default_tva($mysoc, $projectstatic->thirdparty, $idprod); + + $tmpinvoice->fk_soc = $projectstatic->thirdparty->id; + $tmpinvoice->create($user); + + $arrayoftasks=array(); + $totaltimespent = 0; + foreach($toselect as $key => $value) + { + // Get userid, timepent + //$object->fetchTimeSpent(GETPOST('lineid','int')); + + + $arrayoftasks[$userid]['timespent']+=$timespent; + } + + foreach($arrayoftasks as $userid => $value) + { + $fuser->fetch($userid); + $pu_ht = $value['timespent'] * $fuser->thm; + $username = $fuser->getFullName($langs); + + // Add lines + $tmpinvoice->addline($langs->trans("TotalOfTimeSpentBy", $username).' : '.$value['timespent'], $pu_ht, 1, $txtva); + } + + setEventMessages($langs->trans("InvoiceGeneratedFromTimeSpent", $tmpinvoice->ref), null, 'mesgs'); + + exit; + } +} + /* * View @@ -315,7 +373,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) /* * Fiche projet en mode visu */ - if ($projectidforalltimes) + if ($projectidforalltimes > 0) { $result=$projectstatic->fetch($projectidforalltimes); if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();