Add sorting for project overview columns

This commit is contained in:
Tobias Sekan 2020-03-05 14:16:56 +01:00 committed by GitHub
parent fe2c25a9a3
commit a155409bc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@
* Copyright (C) 2015-2019 Alexandre Spangaro <aspangaro@open-dsi.fr> * Copyright (C) 2015-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2016 Josep Lluís Amador <joseplluis@lliuretic.cat> * Copyright (C) 2016 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -55,7 +56,6 @@ if (!empty($conf->tax->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/socia
if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
if (! empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; if (! empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (!empty($conf->mrp->enabled)) require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('projects', 'companies', 'suppliers', 'compta')); $langs->loadLangs(array('projects', 'companies', 'suppliers', 'compta'));
@ -68,7 +68,6 @@ if (!empty($conf->expensereport->enabled)) $langs->load("trips");
if (! empty($conf->don->enabled)) $langs->load("donations"); if (! empty($conf->don->enabled)) $langs->load("donations");
if (! empty($conf->loan->enabled)) $langs->load("loan"); if (! empty($conf->loan->enabled)) $langs->load("loan");
if (! empty($conf->salaries->enabled)) $langs->load("salaries"); if (! empty($conf->salaries->enabled)) $langs->load("salaries");
if (!empty($conf->mrp->enabled)) $langs->load("mrp");
$id=GETPOST('id', 'int'); $id=GETPOST('id', 'int');
$ref=GETPOST('ref', 'alpha'); $ref=GETPOST('ref', 'alpha');
@ -251,7 +250,7 @@ print '</td></tr>';
// Categories // Categories
if ($conf->categorie->enabled) { if ($conf->categorie->enabled) {
print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>'; print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1); print $form->showCategories($object->id, 'project', 1);
print "</td></tr>"; print "</td></tr>";
} }
@ -386,18 +385,6 @@ $listofreferent = array(
'buttonnew'=>'CreateShipment', 'buttonnew'=>'CreateShipment',
'testnew'=>0, 'testnew'=>0,
'test'=>$conf->expedition->enabled && $user->rights->expedition->lire), 'test'=>$conf->expedition->enabled && $user->rights->expedition->lire),
'mrp'=>array(
'name'=>"MO",
'title'=>"ListMOAssociatedProject",
'class'=>'Mo',
'table'=>'mrp_mo',
'datefieldname'=>'date_valid',
'urlnew'=>DOL_URL_ROOT.'/mrp/mo_card.php?action=create&origin=project&originid='.$id.'&socid='.$socid,
'lang'=>'mrp',
'buttonnew'=>'CreateMO',
'testnew'=>'$user->rights->mrp->write',
'project_field'=>'fk_project',
'test'=>$conf->mrp->enabled && $user->rights->mrp->read),
'trip'=>array( 'trip'=>array(
'name'=>"TripsAndExpenses", 'name'=>"TripsAndExpenses",
'title'=>"ListExpenseReportsAssociatedProject", 'title'=>"ListExpenseReportsAssociatedProject",
@ -620,7 +607,7 @@ foreach ($listofreferent as $key => $value)
$elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field)?$project_field:'fk_projet'); $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 (count($elementarray)>0 && is_array($elementarray))
{ {
$total_ht = 0; $total_ht = 0;
$total_ttc = 0; $total_ttc = 0;
@ -775,7 +762,12 @@ print "</table>";
print '<br><br>'; print '<br><br>';
print '<br>'; print '<br>';
// TODO: FOR TESTING
$param = 'id='.$object->id.'&mainmenu=home';
$sortfield = GETPOST("sortfield", "alpha");
$sortorder = GETPOST("sortorder", 'alpha');
if (!$sortfield) $sortfield = "nature";
if (!$sortorder) $sortorder = "asc";
// Detail // Detail
foreach ($listofreferent as $key => $value) foreach ($listofreferent as $key => $value)
@ -843,58 +835,62 @@ foreach ($listofreferent as $key => $value)
$addform.='<div class="inline-block valignmiddle">'; $addform.='<div class="inline-block valignmiddle">';
if ($testnew) $addform.='<a class="buttonxxx" href="'.$urlnew.'"><span class="valignmiddle text-plus-circle">'.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>'; if ($testnew) $addform.='<a class="buttonxxx" href="'.$urlnew.'"><span class="valignmiddle text-plus-circle">'.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) { elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
$addform .= '<a class="buttonxxx buttonRefused" disabled="disabled" href="#"><span class="valignmiddle text-plus-circle">'.($buttonnew ? $langs->trans($buttonnew) : $langs->trans("Create")).'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>'; $addform.='<a class="buttonxxx buttonRefused" disabled="disabled" href="#"><span class="valignmiddle text-plus-circle">'.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).'</span><span class="fa fa-plus-circle valignmiddle"></span></a>';
} }
$addform.='<div>'; $addform.='<div>';
} }
print load_fiche_titre($langs->trans($title), $addform, ''); print load_fiche_titre($langs->trans($title), $addform, '');
// Text for line : Date
if (in_array($tablename, array('projet_task'))) $label_date = $langs->trans("TimeSpent");
if (!in_array($tablename, array('projet_task'))) $label_date = $langs->trans("Date");
// Text for line : Thirdparty or user
if (in_array($tablename, array('projet_task')) && $key == 'project_task') $label_user = ''; // if $key == 'project_task', we don't want details per user
elseif (in_array($tablename, array('payment_various'))) $label_user = ''; // if $key == 'payment_various', we don't have any thirdparty
elseif (in_array($tablename, array('expensereport_det', 'don', 'projet_task', 'stock_mouvement', 'payment_salary'))) $label_user = $langs->trans("User");
else $label_user = $langs->trans("ThirdParty");
// Text for line : Amount HT
//if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
//elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("Amount").'</td>';
if ($key == 'loan') $label_amount_ht = $langs->trans("LoanCapital").'</td>';
elseif (empty($value['disableamount'])) $label_amount_ht = $langs->trans("AmountHT");
else $label_amount_ht = '';
// Text for line : Amount TTC
//if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
if ($key == 'loan') $label_amount_ttc = $langs->trans("RemainderToPay");
elseif (empty($value['disableamount'])) $label_amount_ttc = $langs->trans("AmountTTC");
else $label_amount_ttc = '';
// Text for line : Status
if (in_array($tablename, array('projet_task'))) $label_status = $langs->trans("ProgressDeclared");
else $label_status = $langs->trans("Status");
print "\n".'<!-- Table for tablename = '.$tablename.' -->'."\n"; print "\n".'<!-- Table for tablename = '.$tablename.' -->'."\n";
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
$moreattrib = ($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
// Remove link column // Remove link column
print '<td style="width: 24px"></td>'; print '<td style="width: 24px"></td>';
// Ref
print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '').'>'.$langs->trans("Ref").'</td>'; print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "ref", "", $param, 'style="width: 200px"', $sortfield, $sortorder);
// Date print_liste_field_titre($label_date, $_SERVER["PHP_SELF"], "date", "", $param, $moreattrib, $sortfield, $sortorder, "center ");
print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '').' class="center">'; print_liste_field_titre($label_user, $_SERVER["PHP_SELF"], "user", "", $param, "", $sortfield, $sortorder);
if (in_array($tablename, array('projet_task'))) print $langs->trans("TimeSpent"); print_liste_field_titre($label_amount_ht, $_SERVER["PHP_SELF"], "amount_ht", "", $param, 'style="width: 120px"', $sortfield, $sortorder, "right ");
if (!in_array($tablename, array('projet_task'))) print $langs->trans("Date"); print_liste_field_titre($label_amount_ttc, $_SERVER["PHP_SELF"], "amount_ttc", "", $param, 'style="width: 120px"', $sortfield, $sortorder, "right ");
print '</td>'; print_liste_field_titre($label_status, $_SERVER["PHP_SELF"], "status", "", $param, 'style="width: 200px"', $sortfield, $sortorder, "right ");
// Thirdparty or user
print '<td>';
if (in_array($tablename, array('projet_task')) && $key == 'project_task') print ''; // if $key == 'project_task', we don't want details per user
elseif (in_array($tablename, array('payment_various'))) print ''; // if $key == 'payment_various', we don't have any thirdparty
elseif (in_array($tablename, array('expensereport_det', 'don', 'projet_task', 'stock_mouvement', 'payment_salary'))) print $langs->trans("User");
else print $langs->trans("ThirdParty");
print '</td>';
// Duration of intervention
if ($tablename == 'fichinter')
{
print '<td>';
print $langs->trans("TotalDuration");
$total_duration = 0;
print '</td>';
}
// Amount HT
//if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
//elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("Amount").'</td>';
if ($key == 'loan') print '<td class="right" width="120">'.$langs->trans("LoanCapital").'</td>';
elseif (empty($value['disableamount'])) print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
else print '<td width="120"></td>';
// Amount TTC
//if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
if ($key == 'loan') print '<td class="right" width="120">'.$langs->trans("RemainderToPay").'</td>';
elseif (empty($value['disableamount'])) print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
else print '<td width="120"></td>';
// Status
if (in_array($tablename, array('projet_task'))) print '<td class="right" width="200">'.$langs->trans("ProgressDeclared").'</td>';
else print '<td class="right" width="200">'.$langs->trans("Status").'</td>';
print '</tr>'; print '</tr>';
$elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet'); $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet');
$list = array();
if (is_array($elementarray) && count($elementarray) > 0) if (is_array($elementarray) && count($elementarray) > 0)
{ {
$total_ht = 0; $total_ht = 0;
@ -915,6 +911,7 @@ foreach ($listofreferent as $key => $value)
$num = count($elementarray); $num = count($elementarray);
for ($i = 0; $i < $num; $i++) for ($i = 0; $i < $num; $i++)
{ {
$tablerow = new TableRow();
$tmp = explode('_', $elementarray[$i]); $tmp = explode('_', $elementarray[$i]);
$idofelement = $tmp[0]; $idofelement = $tmp[0];
$idofelementuser = $tmp[1]; $idofelementuser = $tmp[1];
@ -953,40 +950,31 @@ foreach ($listofreferent as $key => $value)
if (!empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal = false; // Replacement invoice, do not include into total if (!empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal = false; // Replacement invoice, do not include into total
} }
print '<tr class="oddeven">';
// Remove link
print '<td style="width: 24px">';
if ($tablename != 'projet_task' && $tablename != 'stock_mouvement')
{
if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true
{
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=unlink&tablename='.$tablename.'&elementselect='.$element->id.($project_field ? '&projectfield='.$project_field : '').'" class="reposition">';
print img_picto($langs->trans('Unlink'), 'unlink');
print '</a>';
}
}
print "</td>\n";
// Ref // Ref
print '<td class="left nowrap">';
if ($tablename == 'expensereport_det') if ($tablename == 'expensereport_det')
{ {
print $expensereport->getNomUrl(1); $tablerow->ref = $expensereport->ref;
$tablerow->ref_text = $expensereport->getNomUrl(1);
} }
else else
{ {
$tablerow->ref = $element->ref;
// Show ref with link // Show ref with link
if ($element instanceof Task) if ($element instanceof Task)
{ {
print $element->getNomUrl(1, 'withproject', 'time'); $tablerow->ref_text = $element->getNomUrl(1, 'withproject', 'time');
print ' - '.dol_trunc($element->label, 48); $tablerow->ref_text .= ' - '.dol_trunc($element->label, 48);
} }
elseif ($key == 'loan') { elseif ($key == 'loan')
print $element->getNomUrl(1); {
print ' - '.dol_trunc($element->label, 48); $tablerow->ref_text = $element->getNomUrl(1);
$tablerow->ref_text .= ' - '.dol_trunc($element->label, 48);
}
else
{
$tablerow->ref_text = $element->getNomUrl(1);
} }
else print $element->getNomUrl(1);
$element_doc = $element->element; $element_doc = $element->element;
$filename = dol_sanitizeFileName($element->ref); $filename = dol_sanitizeFileName($element->ref);
@ -1002,14 +990,19 @@ foreach ($listofreferent as $key => $value)
$filedir = $conf->fournisseur->facture->multidir_output[$element->entity].'/'.get_exdir($element->id, 2, 0, 0, $element, 'invoice_supplier').dol_sanitizeFileName($element->ref); $filedir = $conf->fournisseur->facture->multidir_output[$element->entity].'/'.get_exdir($element->id, 2, 0, 0, $element, 'invoice_supplier').dol_sanitizeFileName($element->ref);
} }
print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>'; $tablerow->ref_text .= '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>';
// Show supplier ref // Show supplier ref
if (!empty($element->ref_supplier)) print ' - '.$element->ref_supplier; if (!empty($element->ref_supplier))
// Show customer ref {
if (!empty($element->ref_customer)) print ' - '.$element->ref_customer; $tablerow->ref_text .= ' - '.$element->ref_supplier;
}
// Show customer ref
if (!empty($element->ref_customer))
{
$tablerow->ref_text .= ' - '.$element->ref_customer;
}
} }
print "</td>\n";
// Date or TimeSpent // Date or TimeSpent
$date = ''; $total_time_by_line = null; $date = ''; $total_time_by_line = null;
@ -1033,46 +1026,53 @@ foreach ($listofreferent as $key => $value)
$date = $element->date; // invoice, ... $date = $element->date; // invoice, ...
if (empty($date)) $date = $element->date_contrat; if (empty($date)) $date = $element->date_contrat;
if (empty($date)) $date = $element->datev; if (empty($date)) $date = $element->datev;
if (empty($date) && !empty($datefieldname)) {
$date = $element->$datefieldname;
} }
} }
} elseif ($key == 'loan')
elseif ($key == 'loan') { {
$date = $element->datestart; $date = $element->datestart;
} }
print '<td class="center">'; $tablerow->date = $date;
if ($tablename == 'actioncomm') if ($tablename == 'actioncomm')
{ {
print dol_print_date($element->datep, 'dayhour'); $tablerow->date_text = dol_print_date($element->datep, 'dayhour');
if ($element->datef && $element->datef > $element->datep) print " - ".dol_print_date($element->datef, 'dayhour');
if ($element->datef && $element->datef > $element->datep)
{
$tablerow->date_text .= " - ".dol_print_date($element->datef, 'dayhour');
}
} }
elseif (in_array($tablename, array('projet_task'))) elseif (in_array($tablename, array('projet_task')))
{ {
$tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty $tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty
print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$idofelement.'&withproject=1">'; $tablerow->date_text = '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$idofelement.'&withproject=1">';
print convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin'); $tablerow->date_text .= convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin');
print '</a>'; $tablerow->date_text .= '</a>';
$total_time_by_line = $tmpprojtime['nbseconds']; $total_time_by_line = $tmpprojtime['nbseconds'];
} }
else print dol_print_date($date, 'day'); else
print '</td>'; {
$tablerow->date_text = dol_print_date($date, 'day');
}
// Third party or user // Third party or user
print '<td class="left">'; if (is_object($element->thirdparty))
if (is_object($element->thirdparty)) { {
print $element->thirdparty->getNomUrl(1, '', 48); $tablerow->user = $element->thirdparty;
} elseif ($tablename == 'expensereport_det') { }
elseif ($tablename == 'expensereport_det')
{
$tmpuser = new User($db); $tmpuser = new User($db);
$tmpuser->fetch($expensereport->fk_user_author); $tmpuser->fetch($expensereport->fk_user_author);
print $tmpuser->getNomUrl(1, '', 48); $tablerow->user = $tmpuser;
} }
elseif ($tablename == 'payment_salary') elseif ($tablename == 'payment_salary')
{ {
$tmpuser = new User($db); $tmpuser = new User($db);
$tmpuser->fetch($element->fk_user); $tmpuser->fetch($element->fk_user);
print $tmpuser->getNomUrl(1, '', 48); $tablerow->user = $tmpuser;
} }
elseif ($tablename == 'don' || $tablename == 'stock_mouvement') elseif ($tablename == 'don' || $tablename == 'stock_mouvement')
{ {
@ -1080,22 +1080,12 @@ foreach ($listofreferent as $key => $value)
{ {
$tmpuser2 = new User($db); $tmpuser2 = new User($db);
$tmpuser2->fetch($element->fk_user_author); $tmpuser2->fetch($element->fk_user_author);
print $tmpuser2->getNomUrl(1, '', 48); $tablerow->user = $tmpuser2;
} }
} }
elseif ($tablename == 'projet_task' && $key == 'project_task_time') // if $key == 'project_task', we don't want details per user elseif ($tablename == 'projet_task' && $key == 'project_task_time') // if $key == 'project_task', we don't want details per user
{ {
print $elementuser->getNomUrl(1); $tablerow->user = $elementuser;
}
print '</td>';
// Add duration and store it in counter for fichinter
if ($tablename == 'fichinter')
{
print '<td>';
print convertSecondToTime($element->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
$total_duration += $element->duration;
print '</td>';
} }
// Amount without tax // Amount without tax
@ -1124,7 +1114,10 @@ foreach ($listofreferent as $key => $value)
$othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled")); $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
} }
} }
elseif ($key == 'loan') $total_ht_by_line = $element->capital; elseif ($key == 'loan')
{
$total_ht_by_line = $element->capital;
}
else else
{ {
$total_ht_by_line = $element->total_ht; $total_ht_by_line = $element->total_ht;
@ -1139,18 +1132,33 @@ foreach ($listofreferent as $key => $value)
} }
} }
print '<td class="right">'; $tablerow->amount_ht = $total_ht_by_line;
if ($othermessage) print $othermessage;
if ($othermessage)
{
$tablerow->amount_ht_text .= $othermessage;
}
if (isset($total_ht_by_line)) if (isset($total_ht_by_line))
{ {
if (!$qualifiedfortotal) print '<strike>'; if (! $qualifiedfortotal)
print price($total_ht_by_line); {
if (!$qualifiedfortotal) print '</strike>'; $tablerow->amount_ht_text .= '<strike>';
}
$tablerow->amount_ht_text .= price($total_ht_by_line);
if (! $qualifiedfortotal)
{
$tablerow->amount_ht_text .= '</strike>';
}
}
if ($warning)
{
$tablerow->amount_ht_text .= ' '.img_warning($warning);
} }
if ($warning) print ' '.img_warning($warning);
print '</td>';
} }
else print '<td></td>';
// Amount inc tax // Amount inc tax
if (empty($value['disableamount'])) if (empty($value['disableamount']))
@ -1172,7 +1180,10 @@ foreach ($listofreferent as $key => $value)
$othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled")); $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
} }
} }
elseif ($key == 'loan') $total_ttc_by_line = $element->capital - $element->getSumPayment(); elseif ($key == 'loan')
{
$total_ttc_by_line = $element->capital - $element->getSumPayment();
}
else else
{ {
$total_ttc_by_line = $element->total_ttc; $total_ttc_by_line = $element->total_ttc;
@ -1187,48 +1198,59 @@ foreach ($listofreferent as $key => $value)
} }
} }
print '<td class="right">'; $tablerow->amount_ttc = $total_ttc_by_line;
if ($othermessage) print $othermessage;
if ($othermessage)
{
$tablerow->amount_ttc_text .= $othermessage;
}
if (isset($total_ttc_by_line)) if (isset($total_ttc_by_line))
{ {
if (!$qualifiedfortotal) print '<strike>'; if (! $qualifiedfortotal)
print price($total_ttc_by_line); {
if (!$qualifiedfortotal) print '</strike>'; $tablerow->amount_ttc_text .= '<strike>';
}
$tablerow->amount_ttc_text .= price($total_ttc_by_line);
if (! $qualifiedfortotal)
{
$tablerow->amount_ttc_text .= '</strike>';
}
}
if ($warning)
{
$tablerow->amount_ttc_text .= ' '.img_warning($warning);
} }
if ($warning) print ' '.img_warning($warning);
print '</td>';
} }
else print '<td></td>';
// Status // Status
print '<td class="right">';
if ($tablename == 'expensereport_det') if ($tablename == 'expensereport_det')
{ {
print $expensereport->getLibStatut(5); $tablerow->status = $expensereport->getLibStatut(5);
} }
elseif ($element instanceof CommonInvoice) elseif ($element instanceof CommonInvoice)
{ {
//This applies for Facture and FactureFournisseur //This applies for Facture and FactureFournisseur
print $element->getLibStatut(5, $element->getSommePaiement()); $tablerow->status = $element->getLibStatut(5, $element->getSommePaiement());
} }
elseif ($element instanceof Task) elseif ($element instanceof Task)
{ {
if ($element->progress != '') if ($element->progress != '')
{ {
print $element->progress.' %'; $tablerow->status = $element->progress.' %';
} }
} }
elseif ($tablename == 'stock_mouvement') elseif ($tablename == 'stock_mouvement')
{ {
print $element->getLibStatut(3); $tablerow->status = $element->getLibStatut(3);
} }
else else
{ {
print $element->getLibStatut(5); $tablerow->status = $element->getLibStatut(5);
} }
print '</td>';
print '</tr>';
if ($qualifiedfortotal) if ($qualifiedfortotal)
{ {
@ -1241,6 +1263,53 @@ foreach ($listofreferent as $key => $value)
$total_time = $total_time + $total_time_by_line; $total_time = $total_time + $total_time_by_line;
} }
$sortable_table[] = $tablerow;
}
if($sortfield == "user")
{
if($sortorder == "asc")
{
usort($sortable_table, "sort_by_user_asc");
}
else
{
usort($sortable_table, "sort_by_user_desc");
}
}
else
{
$sortable_table = dol_sort_array($sortable_table, $sortfield, $sortorder, 1, 0, 1);
}
foreach ($sortable_table as $tablerow)
{
print '<tr class="oddeven">';
// Remove link
print '<td style="width: 24px">';
if ($tablename != 'projet_task' && $tablename != 'stock_mouvement')
{
if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true
{
print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=unlink&tablename=' . $tablename . '&elementselect=' . $element->id . ($project_field ? '&projectfield=' . $project_field : '') . '" class="reposition">';
print img_picto($langs->trans('Unlink'), 'unlink');
print '</a>';
}
}
print "</td>\n";
print '<td class="left nowrap" style="width: 200px">'.$tablerow->ref_text."</td>";
print '<td class="center">'.$tablerow->date_text."</td>";
print '<td class="left">'.$tablerow->user->getNomUrl(1, '', 48)."</td>";
print '<td class="right" style="width: 120px">'.$tablerow->amount_ht_text."</td>";
print '<td class="right" style="width: 120px">'.$tablerow->amount_ttc_text."</td>";
print '<td class="right" style="width: 200px">'.$tablerow->status."</td>";
print '</tr>';
}
if (canApplySubtotalOn($tablename)) if (canApplySubtotalOn($tablename))
{ {
$breakline = '<tr class="liste_total liste_sub_total">'; $breakline = '<tr class="liste_total liste_sub_total">';
@ -1259,7 +1328,6 @@ foreach ($listofreferent as $key => $value)
} }
//var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id); //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id);
}
if ($breakline) print $breakline; if ($breakline) print $breakline;
@ -1277,8 +1345,6 @@ foreach ($listofreferent as $key => $value)
} }
//if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>'; //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
//elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>'; //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>';
// If fichinter add the total_duration
if ($tablename == 'fichinter') print '<td class="left">'.convertSecondToTime($total_duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
print '<td class="right">'; print '<td class="right">';
if (empty($value['disableamount'])) if (empty($value['disableamount']))
{ {
@ -1305,6 +1371,7 @@ foreach ($listofreferent as $key => $value)
print $elementarray; print $elementarray;
} }
} }
print "</table>"; print "</table>";
print "<br>\n"; print "<br>\n";
} }
@ -1375,3 +1442,91 @@ function sortElementsByClientName($elementarray)
return $elementarray; return $elementarray;
} }
/**
* Compare two TableRow objects by the $user variable in asc order
*
* @param TableRow $left The left object for the compare
* @param TableRow $right The right object for the compare
* @return int The compare result
*/
function sort_by_user_asc($left, $right)
{
if($left->user instanceof User && $right->user instanceof User)
{
return strtoupper($left->user->getFullName('', 0, -1)) > strtoupper($right->user->getFullName('', 0, -1));
}
elseif($left->user instanceof Societe && $right->user instanceof Societe)
{
return strtoupper($left->user->name) > strtoupper($right->user->name);
}
throw new Exception('unknown class type for sorting in function [sort_by_user_asc] in class [\projet\element.php]');
}
/**
* Compare two TableRow objects by the $user variable in desc order
*
* @param TableRow $left The left object for the compare
* @param TableRow $right The right object for the compare
* @return int The compare result
*/
function sort_by_user_desc($left, $right)
{
if($left->user instanceof User && $right->user instanceof User)
{
return strtoupper($left->user->getFullName('', 0, -1)) < strtoupper($right->user->getFullName('', 0, -1));
}
elseif($left->user instanceof Societe && $right->user instanceof Societe)
{
return strtoupper($left->user->name) < strtoupper($right->user->name);
}
throw new Exception('unknown class type for sorting in function [sort_by_user_des] in class [\projet\element.php]');
}
/**
* Presentation of a table row
*/
class TableRow
{
/**
* The reference of this object (only for sorting)
*/
var $ref;
/**
* The visible text for the reference (string or html)
*/
var $ref_text;
/**
* The related user or societe of the object
*/
var $user;
/**
* The ht amount of this object (only for sorting)
*/
var $amount_ht;
/**
* The visible text for the $amount_ht (string or html)
*/
var $amount_ht_text;
/**
* The ttc amount of this object (only for sorting)
*/
var $amount_ttc;
/**
* The visible text for the $amount_ttc (string or html)
*/
var $amount_ttc_text;
/**
* The status of the object (string or html)
*/
var $status;
}