From 50b27239a7dcb80b882d7998701931280a404fcd Mon Sep 17 00:00:00 2001 From: ATM john Date: Tue, 15 Dec 2020 11:34:04 +0100 Subject: [PATCH 1/5] Fix missing hook for project overview control --- htdocs/projet/class/project.class.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index a0b6e38423b..335b06a0456 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -576,6 +576,9 @@ class Project extends CommonObject public function get_element_list($type, $tablename, $datefieldname = '', $dates = '', $datee = '', $projectkey = 'fk_projet') { // phpcs:enable + + global $hookmanager; + $elements = array(); if ($this->id <= 0) return $elements; @@ -630,6 +633,21 @@ class Project extends CommonObject if (empty($datefieldname)) return 'Error this object has no date field defined'; $sql .= " AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)"; } + + $hookmanager->initHooks(array('projectdao')); + $parameters = array( + 'sql'=>$sql, + 'type' => $type, + 'tablename' => $tablename, + 'datefieldname' => $datefieldname, + 'dates' => $dates, + 'datee' => $datee, + 'fk_projet' => $projectkey + ); + $reshook = $hookmanager->executeHooks('getElementList', $parameters, $object, $action); + if ($reshook > 0) $sql = $hookmanager->resPrint; + else $sql .= $hookmanager->resPrint; + if (!$sql) return -1; //print $sql; From 1f29d4f5e8c47144db678abd0bf835e513f3964a Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 16 Dec 2020 16:25:30 +0100 Subject: [PATCH 2/5] Add missing hooks --- htdocs/projet/element.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index c513123c9bf..975b8fcdbed 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -652,9 +652,29 @@ print ''.$langs->trans("AmountTTC").''; print ''; $total_revenue_ht = 0; +$balance_ht = 0; +$balance_ttc = 0; foreach ($listofreferent as $key => $value) { + $parameters = array( + 'total_revenue_ht' =>& $total_revenue_ht, + 'balance_ht' =>& $balance_ht, + 'balance_ttc' =>& $balance_ttc, + 'key' => $key, + 'value' =>& $value, + 'dates' => $dates, + 'datee' => $datee + ); + $reshook = $hookmanager->executeHooks('printOverviewProfit', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + elseif ($reshook > 0){ + print $hookmanager->resPrint; + continue; + } + $name = $langs->trans($value['name']); $title = $value['title']; $classname = $value['class']; @@ -849,6 +869,22 @@ print '
'; // Detail foreach ($listofreferent as $key => $value) { + + $parameters = array( + 'key' => $key, + 'value' =>& $value, + 'dates' => $dates, + 'datee' => $datee + ); + $reshook = $hookmanager->executeHooks('printOverviewDetail', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + elseif ($reshook > 0){ + print $hookmanager->resPrint; + continue; + } + $title = $value['title']; $classname = $value['class']; $tablename = $value['table']; From e61b71bc93801a8771d4c0eead1f37838c201fa1 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 16 Dec 2020 15:40:38 +0000 Subject: [PATCH 3/5] Fixing style errors. --- htdocs/projet/element.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 975b8fcdbed..b334688558b 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -869,7 +869,6 @@ print '
'; // Detail foreach ($listofreferent as $key => $value) { - $parameters = array( 'key' => $key, 'value' =>& $value, From f6b280c9df27b29e9ad9954ee7a7f39d28222c36 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 17 Dec 2020 13:57:12 +0100 Subject: [PATCH 4/5] Update project.class.php --- htdocs/projet/class/project.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 335b06a0456..76e3d8888cb 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -634,7 +634,6 @@ class Project extends CommonObject $sql .= " AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)"; } - $hookmanager->initHooks(array('projectdao')); $parameters = array( 'sql'=>$sql, 'type' => $type, From 842d6f695f31cabd0974c5841fb337b87cf7ac74 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 17 Dec 2020 14:01:42 +0100 Subject: [PATCH 5/5] Update element.php --- htdocs/projet/element.php | 61 +++++++++++++-------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index b334688558b..6a9c1ec9911 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -669,8 +669,7 @@ foreach ($listofreferent as $key => $value) $reshook = $hookmanager->executeHooks('printOverviewProfit', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - } - elseif ($reshook > 0){ + } elseif ($reshook > 0) { print $hookmanager->resPrint; continue; } @@ -683,20 +682,17 @@ foreach ($listofreferent as $key => $value) $qualified = $value['test']; $margin = $value['margin']; $project_field = $value['project_field']; - if ($qualified && isset($margin)) // If this element must be included into profit calculation ($margin is 'minus' or 'add') - { + if ($qualified && isset($margin)) { // If this element must be included into profit calculation ($margin is 'minus' or 'add') $element = new $classname($db); $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet'); - if (is_array($elementarray) && count($elementarray) > 0) - { + if (is_array($elementarray) && count($elementarray) > 0) { $total_ht = 0; $total_ttc = 0; $num = count($elementarray); - for ($i = 0; $i < $num; $i++) - { + for ($i = 0; $i < $num; $i++) { $tmp = explode('_', $elementarray[$i]); $idofelement = $tmp[0]; $idofelementuser = $tmp[1]; @@ -706,13 +702,11 @@ foreach ($listofreferent as $key => $value) // Define if record must be used for total or not $qualifiedfortotal = true; - if ($key == 'invoice') - { + if ($key == 'invoice') { if (!empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal = false; // Replacement invoice, do not include into total if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS) && $element->type == Facture::TYPE_DEPOSIT) $qualifiedfortotal = false; // If hidden option to use deposits as payment (deprecated, not recommended to use this), deposits are not included } - if ($key == 'propal') - { + if ($key == 'propal') { if ($element->status != Propal::STATUS_SIGNED && $element->status != Propal::STATUS_BILLED) $qualifiedfortotal = false; // Only signed proposal must not be included in total } @@ -722,15 +716,11 @@ foreach ($listofreferent as $key => $value) if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'payment_salary') $total_ht_by_line = $element->amount; elseif ($tablename == 'fichinter') $total_ht_by_line = $element->getAmount(); elseif ($tablename == 'stock_mouvement') $total_ht_by_line = $element->price * abs($element->qty); - elseif ($tablename == 'projet_task') - { - if ($idofelementuser) - { + elseif ($tablename == 'projet_task') { + if ($idofelementuser) { $tmp = $element->getSumOfAmount($elementuser, $dates, $datee); $total_ht_by_line = price2num($tmp['amount'], 'MT'); - } - else - { + } else { $tmp = $element->getSumOfAmount('', $dates, $datee); $total_ht_by_line = price2num($tmp['amount'], 'MT'); } @@ -739,8 +729,7 @@ foreach ($listofreferent as $key => $value) if ((empty($dates) && empty($datee)) || (intval($dates) <= $element->datestart && intval($datee) >= $element->dateend)) { // Get total loan $total_ht_by_line = -$element->capital; - } - else { + } else { // Get loan schedule according to date filter $total_ht_by_line = 0; $loanScheduleStatic = new LoanSchedule($element->db); @@ -766,29 +755,23 @@ foreach ($listofreferent as $key => $value) if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'payment_salary') $total_ttc_by_line = $element->amount; elseif ($tablename == 'fichinter') $total_ttc_by_line = $element->getAmount(); elseif ($tablename == 'stock_mouvement') $total_ttc_by_line = $element->price * abs($element->qty); - elseif ($tablename == 'projet_task') - { + elseif ($tablename == 'projet_task') { $defaultvat = get_default_tva($mysoc, $mysoc); $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT'); - } - elseif ($key == 'loan') { + } elseif ($key == 'loan') { $total_ttc_by_line = $total_ht_by_line; // For loan there is actually no taxe managed in Dolibarr - } - else $total_ttc_by_line = $element->total_ttc; + } else $total_ttc_by_line = $element->total_ttc; // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases - if ($tablename == 'payment_various') - { - if ($element->sens == 1) - { + if ($tablename == 'payment_various') { + if ($element->sens == 1) { $total_ht_by_line = -$total_ht_by_line; $total_ttc_by_line = -$total_ttc_by_line; } } // Add total if we have to - if ($qualifiedfortotal) - { + if ($qualifiedfortotal) { $total_ht = $total_ht + $total_ht_by_line; $total_ttc = $total_ttc + $total_ttc_by_line; } @@ -801,14 +784,12 @@ foreach ($listofreferent as $key => $value) //var_dump($key.' '.$qualifiedforfinalprofit); // Calculate margin - if ($qualifiedforfinalprofit) - { + if ($qualifiedforfinalprofit) { if ($margin == 'add') { $total_revenue_ht += $total_ht; } - if ($margin != "add") // Revert sign - { + if ($margin != "add") { // Revert sign $total_ht = -$total_ht; $total_ttc = -$total_ttc; } @@ -878,8 +859,7 @@ foreach ($listofreferent as $key => $value) $reshook = $hookmanager->executeHooks('printOverviewDetail', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - } - elseif ($reshook > 0){ + } elseif ($reshook > 0) { print $hookmanager->resPrint; continue; } @@ -898,8 +878,7 @@ foreach ($listofreferent as $key => $value) $exclude_select_element = array('payment_various'); if (!empty($value['exclude_select_element'])) $exclude_select_element[] = $value['exclude_select_element']; - if ($qualified) - { + if ($qualified) { // If we want the project task array to have details of users //if ($key == 'project_task') $key = 'project_task_time';