depreciation.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/asset/depreciation.php
  20. * \ingroup asset
  21. * \brief Card with depreciation on Asset
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
  26. require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php';
  27. require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("assets", "companies"));
  30. // Get parameters
  31. $id = GETPOST('id', 'int');
  32. $ref = GETPOST('ref', 'alpha');
  33. $action = GETPOST('action', 'aZ09');
  34. $cancel = GETPOST('cancel', 'aZ09');
  35. $backtopage = GETPOST('backtopage', 'alpha');
  36. // Initialize technical objects
  37. $object = new Asset($db);
  38. $assetdepreciationoptions = new AssetDepreciationOptions($db);
  39. $extrafields = new ExtraFields($db);
  40. $diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
  41. $hookmanager->initHooks(array('assetdepreciation', 'globalcard')); // Note that conf->hooks_modules contains array
  42. // Fetch optionals attributes and labels
  43. $extrafields->fetch_name_optionals_label($object->table_element);
  44. // Load object
  45. include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  46. if ($id > 0 || !empty($ref)) {
  47. $upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
  48. }
  49. // Security check (enable the most restrictive one)
  50. if ($user->socid > 0) accessforbidden();
  51. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  52. restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  53. if (!isModEnabled('asset')) accessforbidden();
  54. if (!empty($object->not_depreciated)) accessforbidden();
  55. $object->asset_depreciation_options = &$assetdepreciationoptions;
  56. $result = $assetdepreciationoptions->fetchDeprecationOptions($object->id);
  57. if ($result < 0) {
  58. setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
  59. }
  60. $result = $object->fetchDepreciationLines();
  61. if ($result < 0) {
  62. setEventMessages($object->error, $object->errors, 'errors');
  63. }
  64. /*
  65. * Actions
  66. */
  67. $parameters = array();
  68. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  69. if ($reshook < 0) {
  70. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  71. }
  72. if (empty($reshook)) {
  73. }
  74. /*
  75. * View
  76. */
  77. $form = new Form($db);
  78. $help_url = '';
  79. llxHeader('', $langs->trans('Asset'), $help_url);
  80. if ($id > 0 || !empty($ref)) {
  81. $head = assetPrepareHead($object);
  82. print dol_get_fiche_head($head, 'depreciation', $langs->trans("Asset"), -1, $object->picto);
  83. // Object card
  84. // ------------------------------------------------------------
  85. $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  86. $morehtmlref = '<div class="refidno">';
  87. $morehtmlref .= '</div>';
  88. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  89. print '<div class="fichecenter">';
  90. print '<div class="underbanner clearboth"></div>';
  91. print '</div>';
  92. print dol_get_fiche_end();
  93. $parameters = array();
  94. $reshook = $hookmanager->executeHooks('listAssetDeprecation', $parameters, $object, $action);
  95. print $hookmanager->resPrint;
  96. if ($reshook < 0) {
  97. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  98. } elseif (empty($reshook)) {
  99. $bookkeeping_icon = '<i class="fas fa-save" title="'.$langs->trans('AssetDispatchedInBookkeeping').'"></i>';
  100. $future_icon = '<i class="fas fa-clock" title="'.$langs->trans('AssetFutureDepreciationLine').'"></i>';
  101. $now = dol_now();
  102. foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $fields) {
  103. $lines = $object->depreciation_lines[$mode_key];
  104. if (!empty($lines)) {
  105. $mode_info = $assetdepreciationoptions->deprecation_options_fields[$mode_key];
  106. $depreciation_info = $assetdepreciationoptions->getGeneralDepreciationInfoForMode($mode_key);
  107. print load_fiche_titre($langs->trans($mode_info['label']), '', '');
  108. // Depreciation general info
  109. //---------------------------------
  110. print '<div class="fichecenter">';
  111. print '<div class="fichehalfleft">';
  112. print '<div class="underbanner clearboth"></div>';
  113. print '<table class="border centpercent tableforfield">' . "\n";
  114. print '<tr><td class="titlefield">' . $langs->trans('AssetBaseDepreciationHT') . '</td><td>' . price($depreciation_info['base_depreciation_ht']) . '</td></tr>';
  115. print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationBeginDate') . '</td><td>' . dol_print_date($object->date_start > $object->date_acquisition ? $object->date_start : $object->date_acquisition, 'day') . '</td></tr>';
  116. print '</table>';
  117. // We close div and reopen for second column
  118. print '</div>';
  119. print '<div class="fichehalfright">';
  120. print '<div class="underbanner clearboth"></div>';
  121. print '<table class="border centpercent tableforfield">';
  122. print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationDuration') . '</td><td>' . $depreciation_info['duration'] . ' ( ' . $depreciation_info['duration_type'] . ' )</td></tr>';
  123. print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationRate') . '</td><td>' . $depreciation_info['rate'] . '</td></tr>';
  124. print '</table>';
  125. print '</div>';
  126. print '</div>';
  127. print '<div class="clearboth"></div>';
  128. // Depreciation lines
  129. //---------------------------------
  130. print '<br>';
  131. print '<div class="div-table-responsive-no-min">';
  132. print '<table class="noborder allwidth">';
  133. print '<tr class="liste_titre">';
  134. print '<td class="width20"></td>';
  135. print '<td>' . $langs->trans("Ref") . '</td>';
  136. print '<td class="center">' . $langs->trans("AssetDepreciationDate") . '</td>';
  137. print '<td class="right">' . $langs->trans("AssetDepreciationHT") . '</td>';
  138. print '<td class="right">' . $langs->trans("AssetCumulativeDepreciationHT") . '</td>';
  139. print '<td class="right">' . $langs->trans("AssetResidualHT") . '</td>';
  140. print '</tr>';
  141. if (empty($lines)) {
  142. print '<tr><td class="impair center" colspan="6"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
  143. } else {
  144. foreach ($lines as $line) {
  145. print '<tr class="oddeven">';
  146. print '<td>' . ($line['bookkeeping'] ? $bookkeeping_icon : ($line['depreciation_date'] > $now ? $future_icon : '')) . '</td>';
  147. print '<td >' . (empty($line['ref']) ? $langs->trans('AssetDepreciationReversal') : $line['ref']) . '</td>';
  148. print '<td class="center">' . dol_print_date($line['depreciation_date'], 'day') . '</td>';
  149. print '<td class="right">';
  150. print price($line['depreciation_ht']);
  151. print '</td>';
  152. print '<td class="right">';
  153. print price($line['cumulative_depreciation_ht']);
  154. print '</td>';
  155. print '<td class="right">';
  156. print price(price2num($depreciation_info['base_depreciation_ht'] - $line['cumulative_depreciation_ht'], 'MT'));
  157. print '</td>';
  158. print "</tr>\n";
  159. }
  160. }
  161. print '</table>';
  162. print '</div>';
  163. }
  164. }
  165. }
  166. }
  167. // End of page
  168. llxFooter();
  169. $db->close();