diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index f95c0b147b4..14a999063ba 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -6,6 +6,7 @@ * Copyright (C) 2015-2019 Alexandre Spangaro * Copyright (C) 2015 Marcos García * Copyright (C) 2016 Josep Lluís Amador + * Copyright (C) 2020 Tobias Sekan * * 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 @@ -99,7 +100,7 @@ $mine = $_REQUEST['mode'] == 'mine' ? 1 : 0; $object = new Project($db); -include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments(); // Security check @@ -169,21 +170,21 @@ print ''; print ''; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { - print 'usage_opportunity ? ' checked="checked"' : '')).'"> '; + print 'usage_opportunity ? ' checked="checked"' : '')).'"> '; $htmltext = $langs->trans("ProjectFollowOpportunity"); print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext); print '
'; } if (empty($conf->global->PROJECT_HIDE_TASKS)) { - print 'usage_task ? ' checked="checked"' : '')).'"> '; + print 'usage_task ? ' checked="checked"' : '')).'"> '; $htmltext = $langs->trans("ProjectFollowTasks"); print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext); print '
'; } if (!empty($conf->global->PROJECT_BILL_TIME_SPENT)) { - print 'usage_bill_time ? ' checked="checked"' : '')).'"> '; + print 'usage_bill_time ? ' checked="checked"' : '')).'"> '; $htmltext = $langs->trans("ProjectBillTimeDescription"); print $form->textwithpicto($langs->trans("BillTime"), $htmltext); print '
'; @@ -618,7 +619,7 @@ foreach ($listofreferent as $key => $value) { $element = new $classname($db); - $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) { @@ -639,12 +640,12 @@ foreach ($listofreferent as $key => $value) $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 (!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 ($element->statut == Propal::STATUS_NOTSIGNED) $qualifiedfortotal = false; // Refused proposal must not be included in total + if ($element->statut == Propal::STATUS_NOTSIGNED) $qualifiedfortotal = false; // Refused proposal must not be included in total } if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty(); @@ -652,7 +653,7 @@ foreach ($listofreferent as $key => $value) // Define $total_ht_by_line 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 == 'stock_mouvement') $total_ht_by_line = $element->price*abs($element->qty); elseif ($tablename == 'projet_task') { if ($idofelementuser) @@ -667,7 +668,7 @@ foreach ($listofreferent as $key => $value) } } elseif ($key == 'loan') { - if ((empty($dates) && empty($datee)) || (intval($dates) <= $element->datestart && intval($datee) >= $element->dateend)) { + if((empty($dates) && empty($datee)) || (intval($dates) <= $element->datestart && intval($datee) >= $element->dateend)){ // Get total loan $total_ht_by_line = -$element->capital; } @@ -676,8 +677,8 @@ foreach ($listofreferent as $key => $value) $total_ht_by_line = 0; $loanScheduleStatic = new LoanSchedule($element->db); $loanScheduleStatic->fetchAll($element->id); - if (!empty($loanScheduleStatic->lines)) { - foreach ($loanScheduleStatic->lines as $loanSchedule) { + if(!empty($loanScheduleStatic->lines)){ + foreach($loanScheduleStatic->lines as $loanSchedule){ /** * @var $loanSchedule LoanSchedule */ @@ -775,7 +776,11 @@ print ""; print '

'; print '
'; - +$param = 'id='.$object->id.'&mainmenu=home'; +$sortfield = GETPOST("sortfield", "alpha"); +$sortorder = GETPOST("sortorder", 'alpha'); +if (!$sortfield) $sortfield = "nature"; +if (!$sortorder) $sortorder = "asc"; // Detail foreach ($listofreferent as $key => $value) @@ -810,12 +815,12 @@ foreach ($listofreferent as $key => $value) if (!in_array($tablename, $array_of_element_linkable_with_different_thirdparty)) { $idtofilterthirdparty = $object->thirdparty->id; - if (!empty($conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS)) $idtofilterthirdparty .= ','.$conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS; + if (! empty($conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS)) $idtofilterthirdparty .= ','.$conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS; } if (empty($conf->global->PROJECT_LINK_ON_OVERWIEW_DISABLED) && $idtofilterthirdparty && !in_array($tablename, $exclude_select_element)) { - $selectList = $formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300', -2, !empty($project_field) ? $project_field : 'fk_projet'); + $selectList = $formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300', -2, !empty($project_field)?$project_field:'fk_projet'); if ($selectList < 0) { setEventMessages($formproject->error, $formproject->errors, 'errors'); @@ -841,60 +846,64 @@ foreach ($listofreferent as $key => $value) if (empty($conf->global->PROJECT_CREATE_ON_OVERVIEW_DISABLED) && $urlnew) { $addform .= '
'; - if ($testnew) $addform .= ''.($buttonnew ? $langs->trans($buttonnew) : $langs->trans("Create")).''; + if ($testnew) $addform .= ''.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).''; elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) { - $addform .= ''.($buttonnew ? $langs->trans($buttonnew) : $langs->trans("Create")).''; + $addform .= ''.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).''; } $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 ''.$langs->trans("AmountHT").''; + //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print ''.$langs->trans("Amount").''; + if ($key == 'loan') $label_amount_ht = $langs->trans("LoanCapital").''; + 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 ''.$langs->trans("AmountTTC").''; + 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".''."\n"; print ''; + $moreattrib = ($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : ''; + print ''; + // Remove link column print ''; - // Ref - print ''.$langs->trans("Ref").''; - // Date - print ''; - if (in_array($tablename, array('projet_task'))) print $langs->trans("TimeSpent"); - if (!in_array($tablename, array('projet_task'))) print $langs->trans("Date"); - print ''; - // Thirdparty or user - print ''; - // Duration of intervention - if ($tablename == 'fichinter') - { - print ''; - } - // Amount HT - //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print ''; - //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print ''; - if ($key == 'loan') print ''; - elseif (empty($value['disableamount'])) print ''; - else print ''; - // Amount TTC - //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print ''; - if ($key == 'loan') print ''; - elseif (empty($value['disableamount'])) print ''; - else print ''; - // Status - if (in_array($tablename, array('projet_task'))) print ''; - else print ''; + + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "ref", "", $param, 'style="width: 200px"', $sortfield, $sortorder); + print_liste_field_titre($label_date, $_SERVER["PHP_SELF"], "date", "", $param, $moreattrib, $sortfield, $sortorder, "center "); + print_liste_field_titre($label_user, $_SERVER["PHP_SELF"], "user", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre($label_amount_ht, $_SERVER["PHP_SELF"], "amount_ht", "", $param, 'style="width: 120px"', $sortfield, $sortorder, "right "); + print_liste_field_titre($label_amount_ttc, $_SERVER["PHP_SELF"], "amount_ttc", "", $param, 'style="width: 120px"', $sortfield, $sortorder, "right "); + print_liste_field_titre($label_status, $_SERVER["PHP_SELF"], "status", "", $param, 'style="width: 200px"', $sortfield, $sortorder, "right "); + print ''; $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) { $total_ht = 0; @@ -915,6 +924,8 @@ foreach ($listofreferent as $key => $value) $num = count($elementarray); for ($i = 0; $i < $num; $i++) { + $tablerow = new TableRow(); + $tmp = explode('_', $elementarray[$i]); $idofelement = $tmp[0]; $idofelementuser = $tmp[1]; @@ -922,6 +933,7 @@ foreach ($listofreferent as $key => $value) $element->fetch($idofelement); if ($idofelementuser) $elementuser->fetch($idofelementuser); + // Special cases if ($tablename != 'expensereport_det') { @@ -953,40 +965,34 @@ foreach ($listofreferent as $key => $value) if (!empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal = false; // Replacement invoice, do not include into total } - print ''; - - // Remove link - print '\n"; + // Unlink - save id of the element, need for the "unlink" action + $tablerow->id = $element->id; // Ref - print '\n"; // Date or TimeSpent $date = ''; $total_time_by_line = null; @@ -1020,111 +1031,114 @@ foreach ($listofreferent as $key => $value) elseif ($tablename == 'chargesociales') $date = $element->date_ech; elseif (!empty($element->status) || !empty($element->statut) || !empty($element->fk_status)) { - if ($tablename == 'don') $date = $element->datedon; - if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') - { - $date = ($element->date_commande ? $element->date_commande : $element->date_valid); - } - elseif ($tablename == 'supplier_proposal') $date = $element->date_validation; // There is no other date for this - elseif ($tablename == 'fichinter') $date = $element->datev; // There is no other date for this - elseif ($tablename == 'projet_task') $date = ''; // We show no date. Showing date of beginning of task make user think it is date of time consumed + if ($tablename == 'don') $date = $element->datedon; + if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') + { + $date = ($element->date_commande ? $element->date_commande : $element->date_valid); + } + elseif ($tablename == 'supplier_proposal') $date = $element->date_validation; // There is no other date for this + elseif ($tablename == 'fichinter') $date = $element->datev; // There is no other date for this + elseif ($tablename == 'projet_task') $date = ''; // We show no date. Showing date of beginning of task make user think it is date of time consumed else { - $date = $element->date; // invoice, ... - if (empty($date)) $date = $element->date_contrat; - if (empty($date)) $date = $element->datev; - if (empty($date) && !empty($datefieldname)) { + $date = $element->date; // invoice, ... + if (empty($date)) $date = $element->date_contrat; + if (empty($date)) $date = $element->datev; + if (empty($date) && !empty($datefieldname)) { $date = $element->$datefieldname; } - } + } + } + elseif ($key == 'loan') + { + $date = $element->datestart; } - elseif ($key == 'loan') { - $date = $element->datestart; - } - print ''; // Third party or user - print ''; - - // Add duration and store it in counter for fichinter - if ($tablename == 'fichinter') { - print ''; + if ($element->fk_user_author > 0) + { + $tmpuser2 = new User($db); + $tmpuser2->fetch($element->fk_user_author); + $tablerow->user = $tmpuser2; + } + } + elseif ($tablename == 'projet_task' && $key == 'project_task_time') // if $key == 'project_task', we don't want details per user + { + $tablerow->user = $elementuser; } - // Amount without tax + // Amount without tax $warning = ''; if (empty($value['disableamount'])) { - $total_ht_by_line = null; - $othermessage = ''; + $total_ht_by_line = null; + $othermessage = ''; 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 (in_array($tablename, array('projet_task'))) { - if (!empty($conf->salaries->enabled)) - { - // TODO Permission to read daily rate to show value - $total_ht_by_line = price2num($tmpprojtime['amount'], 'MT'); - if ($tmpprojtime['nblinesnull'] > 0) - { - $langs->load("errors"); - $warning = $langs->trans("WarningSomeLinesWithNullHourlyRate", $conf->currency); - } - } - else - { - $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled")); - } + if (!empty($conf->salaries->enabled)) + { + // TODO Permission to read daily rate to show value + $total_ht_by_line = price2num($tmpprojtime['amount'], 'MT'); + if ($tmpprojtime['nblinesnull'] > 0) + { + $langs->load("errors"); + $warning = $langs->trans("WarningSomeLinesWithNullHourlyRate", $conf->currency); + } + } + else + { + $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 { $total_ht_by_line = $element->total_ht; @@ -1133,46 +1147,64 @@ foreach ($listofreferent as $key => $value) // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases if ($tablename == 'payment_various') { - if ($element->sens == 0) - { - $total_ht_by_line = -$total_ht_by_line; - } + if ($element->sens == 0) + { + $total_ht_by_line = -$total_ht_by_line; + } + } + + $tablerow->amount_ht = $total_ht_by_line; + + if ($othermessage) + { + $tablerow->amount_ht_text .= $othermessage; } - print ''; - } - else print ''; + if (! $qualifiedfortotal) + { + $tablerow->amount_ht_text .= ''; + } - // Amount inc tax + $tablerow->amount_ht_text .= price($total_ht_by_line); + + if (! $qualifiedfortotal) + { + $tablerow->amount_ht_text .= ''; + } + } + + if ($warning) + { + $tablerow->amount_ht_text .= ' '.img_warning($warning); + } + } + + // Amount inc tax if (empty($value['disableamount'])) { - $total_ttc_by_line = null; + $total_ttc_by_line = null; 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') { - if (!empty($conf->salaries->enabled)) - { - // TODO Permission to read daily rate - $defaultvat = get_default_tva($mysoc, $mysoc); - $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT'); - } - else - { - $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled")); - } + if (!empty($conf->salaries->enabled)) + { + // TODO Permission to read daily rate + $defaultvat = get_default_tva($mysoc, $mysoc); + $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT'); + } + else + { + $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 { $total_ttc_by_line = $element->total_ttc; @@ -1181,54 +1213,65 @@ foreach ($listofreferent as $key => $value) // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases if ($tablename == 'payment_various') { - if ($element->sens == 0) - { - $total_ttc_by_line = -$total_ttc_by_line; - } + if ($element->sens == 0) + { + $total_ttc_by_line = -$total_ttc_by_line; + } + } + + $tablerow->amount_ttc = $total_ttc_by_line; + + if ($othermessage) + { + $tablerow->amount_ttc_text .= $othermessage; } - print ''; } - else print ''; // Status - print ''; - - print ''; if ($qualifiedfortotal) { @@ -1241,26 +1284,71 @@ foreach ($listofreferent as $key => $value) $total_time = $total_time + $total_time_by_line; } - if (canApplySubtotalOn($tablename)) - { - $breakline = ''; - $breakline .= ''; - $breakline .= ''; - $breakline .= ''; - $breakline .= ''; - $breakline .= ''; - $breakline .= ''; - $breakline .= ''; - } - - //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id); + $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 ''; + + // Remove link + print '\n"; + + print '"; + print '"; + print '"; + print '"; + print '"; + print '"; + + print ''; + } + + if (canApplySubtotalOn($tablename)) + { + $breakline = ''; + $breakline .= ''; + $breakline .= ''; + $breakline .= ''; + $breakline .= ''; + $breakline .= ''; + $breakline .= ''; + $breakline .= ''; + } + + //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id); + if ($breakline) print $breakline; // Total @@ -1269,21 +1357,19 @@ foreach ($listofreferent as $key => $value) print ''; if (in_array($tablename, array('projet_task'))) { - print ''; - print ''; + print ''; + print ''; } //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print ''; //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print ''; - // If fichinter add the total_duration - if ($tablename == 'fichinter') print ''; print ''; //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print ''; @@ -1291,8 +1377,8 @@ foreach ($listofreferent as $key => $value) print ''; print ''; @@ -1305,6 +1391,7 @@ foreach ($listofreferent as $key => $value) print $elementarray; } } + print "
'; - 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 ''; - print $langs->trans("TotalDuration"); - $total_duration = 0; - print ''.$langs->trans("AmountHT").''.$langs->trans("Amount").''.$langs->trans("LoanCapital").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("RemainderToPay").''.$langs->trans("AmountTTC").''.$langs->trans("ProgressDeclared").''.$langs->trans("Status").'
'; - 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 'id.($project_field ? '&projectfield='.$project_field : '').'" class="reposition">'; - print img_picto($langs->trans('Unlink'), 'unlink'); - print ''; - } - } - print "'; if ($tablename == 'expensereport_det') { - print $expensereport->getNomUrl(1); + $tablerow->ref = $expensereport->ref; + $tablerow->ref_text = $expensereport->getNomUrl(1); } else { + $tablerow->ref = $element->ref; + // Show ref with link if ($element instanceof Task) { - print $element->getNomUrl(1, 'withproject', 'time'); - print ' - '.dol_trunc($element->label, 48); + $tablerow->ref_text = $element->getNomUrl(1, 'withproject', 'time'); + $tablerow->ref_text .= ' - '.dol_trunc($element->label, 48); + } + elseif ($key == 'loan') + { + $tablerow->ref_text = $element->getNomUrl(1); + $tablerow->ref_text .= ' - '.dol_trunc($element->label, 48); + } + else + { + $tablerow->ref_text = $element->getNomUrl(1); } - elseif ($key == 'loan') { - print $element->getNomUrl(1); - print ' - '.dol_trunc($element->label, 48); - } - else print $element->getNomUrl(1); $element_doc = $element->element; $filename = dol_sanitizeFileName($element->ref); @@ -1002,14 +1008,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); } - print '
'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'
'; + $tablerow->ref_text .= '
'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'
'; // Show supplier ref - if (!empty($element->ref_supplier)) print ' - '.$element->ref_supplier; + if (!empty($element->ref_supplier)) + { + $tablerow->ref_text .= ' - '.$element->ref_supplier; + } // Show customer ref - if (!empty($element->ref_customer)) print ' - '.$element->ref_customer; + if (!empty($element->ref_customer)) + { + $tablerow->ref_text .= ' - '.$element->ref_customer; + } } - print "
'; + $tablerow->date = $date; + if ($tablename == 'actioncomm') { - print dol_print_date($element->datep, 'dayhour'); - if ($element->datef && $element->datef > $element->datep) print " - ".dol_print_date($element->datef, 'dayhour'); + $tablerow->date_text = dol_print_date($element->datep, 'dayhour'); + + if ($element->datef && $element->datef > $element->datep) + { + $tablerow->date_text .= " - ".dol_print_date($element->datef, 'dayhour'); + } } elseif (in_array($tablename, array('projet_task'))) { - $tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty - print ''; - print convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin'); - print ''; - $total_time_by_line = $tmpprojtime['nbseconds']; + $tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty + $tablerow->date_text = ''; + $tablerow->date_text .= convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin'); + $tablerow->date_text .= ''; + $total_time_by_line = $tmpprojtime['nbseconds']; + } + else + { + $tablerow->date_text = dol_print_date($date, 'day'); } - else print dol_print_date($date, 'day'); - print ''; - if (is_object($element->thirdparty)) { - print $element->thirdparty->getNomUrl(1, '', 48); - } elseif ($tablename == 'expensereport_det') { - $tmpuser = new User($db); - $tmpuser->fetch($expensereport->fk_user_author); - print $tmpuser->getNomUrl(1, '', 48); - } + if (is_object($element->thirdparty)) + { + $tablerow->user = $element->thirdparty; + } + elseif ($tablename == 'expensereport_det') + { + $tmpuser = new User($db); + $tmpuser->fetch($expensereport->fk_user_author); + $tablerow->user = $tmpuser; + } elseif ($tablename == 'payment_salary') { $tmpuser = new User($db); $tmpuser->fetch($element->fk_user); - print $tmpuser->getNomUrl(1, '', 48); + $tablerow->user = $tmpuser; } elseif ($tablename == 'don' || $tablename == 'stock_mouvement') - { - if ($element->fk_user_author > 0) - { - $tmpuser2 = new User($db); - $tmpuser2->fetch($element->fk_user_author); - print $tmpuser2->getNomUrl(1, '', 48); - } - } - elseif ($tablename == 'projet_task' && $key == 'project_task_time') // if $key == 'project_task', we don't want details per user - { - print $elementuser->getNomUrl(1); - } - print ''; - print convertSecondToTime($element->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY); - $total_duration += $element->duration; - print ''; - if ($othermessage) print $othermessage; if (isset($total_ht_by_line)) { - if (!$qualifiedfortotal) print ''; - print price($total_ht_by_line); - if (!$qualifiedfortotal) print ''; - } - if ($warning) print ' '.img_warning($warning); - print ''; - if ($othermessage) print $othermessage; if (isset($total_ttc_by_line)) { - if (!$qualifiedfortotal) print ''; - print price($total_ttc_by_line); - if (!$qualifiedfortotal) print ''; + if (! $qualifiedfortotal) + { + $tablerow->amount_ttc_text .= ''; + } + + $tablerow->amount_ttc_text .= price($total_ttc_by_line); + + if (! $qualifiedfortotal) + { + $tablerow->amount_ttc_text .= ''; + } + } + + if ($warning) + { + $tablerow->amount_ttc_text .= ' '.img_warning($warning); } - if ($warning) print ' '.img_warning($warning); - print ''; if ($tablename == 'expensereport_det') { - print $expensereport->getLibStatut(5); + $tablerow->status = $expensereport->getLibStatut(5); } elseif ($element instanceof CommonInvoice) { //This applies for Facture and FactureFournisseur - print $element->getLibStatut(5, $element->getSommePaiement()); + $tablerow->status = $element->getLibStatut(5, $element->getSommePaiement()); } elseif ($element instanceof Task) { if ($element->progress != '') { - print $element->progress.' %'; + $tablerow->status = $element->progress.' %'; } } elseif ($tablename == 'stock_mouvement') { - print $element->getLibStatut(3); + $tablerow->status = $element->getLibStatut(3); } else { - print $element->getLibStatut(5); + $tablerow->status = $element->getLibStatut(5); } - print '
'; - $breakline .= ''; - $breakline .= ''; - $breakline .= $langs->trans('SubTotal').' : '; - if (is_object($element->thirdparty)) $breakline .= $element->thirdparty->getNomUrl(0, '', 48); - $breakline .= ''.price($total_ht_by_third).''.price($total_ttc_by_third).'
'; + 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 ''; + print img_picto($langs->trans('Unlink'), 'unlink'); + print ''; + } + } + print "'.$tablerow->ref_text."'.$tablerow->date_text."'.$tablerow->user->getNomUrl(1, '', 48)."'.$tablerow->amount_ht_text."'.$tablerow->amount_ttc_text."'.$tablerow->status."
'; + $breakline .= ''; + $breakline .= ''; + $breakline .= $langs->trans('SubTotal').' : '; + if (is_object($element->thirdparty)) $breakline .= $element->thirdparty->getNomUrl(0, '', 48); + $breakline .= ''.price($total_ht_by_third).''.price($total_ttc_by_third).'
'.$langs->trans("Number").': '.$i.''; - print convertSecondToTime($total_time, 'allhourmin'); - print ''; - print ''; + print convertSecondToTime($total_time, 'allhourmin'); + print ''; + print ''.$langs->trans("TotalHT").' : '.price($total_ht).''.$langs->trans("Total").' : '.price($total_ht).''.convertSecondToTime($total_duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).''; if (empty($value['disableamount'])) { - if ($key == 'loan') print $langs->trans("Total").' '.$langs->trans("LoanCapital").' : '.price($total_ttc); - elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) print ''.$langs->trans("TotalHT").' : '.price($total_ht); + if ($key == 'loan') print $langs->trans("Total").' '.$langs->trans("LoanCapital").' : '.price($total_ttc); + elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) print ''.$langs->trans("TotalHT").' : '.price($total_ht); } print ''.$langs->trans("TotalTTC").' : '.price($total_ttc).''; if (empty($value['disableamount'])) { - if ($key == 'loan') print $langs->trans("Total").' '.$langs->trans("RemainderToPay").' : '.price($total_ttc); - elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) print $langs->trans("TotalTTC").' : '.price($total_ttc); + if ($key == 'loan') print $langs->trans("Total").' '.$langs->trans("RemainderToPay").' : '.price($total_ttc); + elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) print $langs->trans("TotalTTC").' : '.price($total_ttc); } print ' 
"; print "
\n"; } @@ -1375,3 +1462,96 @@ function sortElementsByClientName($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 id of this project (need for "unlink" action) + */ + public $id; + + /** + * The reference of this object (only for sorting) + */ + public $ref; + + /** + * The visible text for the reference (string or html) + */ + public $ref_text; + + /** + * The related user or societe of the object + */ + public $user; + + /** + * The ht amount of this object (only for sorting) + */ + public $amount_ht; + + /** + * The visible text for the $amount_ht (string or html) + */ + public $amount_ht_text; + + /** + * The ttc amount of this object (only for sorting) + */ + public $amount_ttc; + + /** + * The visible text for the $amount_ttc (string or html) + */ + public $amount_ttc_text; + + /** + * The status of the object (string or html) + */ + public $status; +}