Merge pull request #15769 from atm-john/fix/12.0_missing_project_overview_hook
FIX/NEW : missing HOOK for project element
This commit is contained in:
commit
4c4e41027a
@ -617,6 +617,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;
|
||||
@ -662,6 +665,20 @@ 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)";
|
||||
}
|
||||
|
||||
$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;
|
||||
|
||||
@ -648,9 +648,28 @@ print '<td class="right" width="100">'.$langs->trans("AmountTTC").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$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'];
|
||||
@ -659,20 +678,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];
|
||||
@ -682,13 +698,11 @@ foreach ($listofreferent as $key => $value)
|
||||
|
||||
// Define if record must be used for total or not
|
||||
$qualifiedfortotal = true;
|
||||
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 == '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
|
||||
}
|
||||
|
||||
@ -698,10 +712,8 @@ 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 {
|
||||
@ -737,8 +749,7 @@ 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') {
|
||||
@ -746,18 +757,15 @@ foreach ($listofreferent as $key => $value)
|
||||
} 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;
|
||||
}
|
||||
@ -770,13 +778,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;
|
||||
@ -838,6 +845,20 @@ print '<br>';
|
||||
// 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'];
|
||||
@ -852,8 +873,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';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user