depreciation.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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) {
  51. accessforbidden();
  52. }
  53. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  54. restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  55. if (!isModEnabled('asset')) {
  56. accessforbidden();
  57. }
  58. if (!empty($object->not_depreciated)) {
  59. accessforbidden();
  60. }
  61. $object->asset_depreciation_options = &$assetdepreciationoptions;
  62. $result = $assetdepreciationoptions->fetchDeprecationOptions($object->id);
  63. if ($result < 0) {
  64. setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
  65. }
  66. $result = $object->fetchDepreciationLines();
  67. if ($result < 0) {
  68. setEventMessages($object->error, $object->errors, 'errors');
  69. }
  70. /*
  71. * Actions
  72. */
  73. $parameters = array();
  74. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  75. if ($reshook < 0) {
  76. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  77. }
  78. if (empty($reshook)) {
  79. }
  80. /*
  81. * View
  82. */
  83. $form = new Form($db);
  84. $help_url = '';
  85. llxHeader('', $langs->trans('Asset'), $help_url);
  86. if ($id > 0 || !empty($ref)) {
  87. $head = assetPrepareHead($object);
  88. print dol_get_fiche_head($head, 'depreciation', $langs->trans("Asset"), -1, $object->picto);
  89. // Object card
  90. // ------------------------------------------------------------
  91. $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  92. $morehtmlref = '<div class="refidno">';
  93. $morehtmlref .= '</div>';
  94. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  95. print '<div class="fichecenter">';
  96. print '<div class="underbanner clearboth"></div>';
  97. print '</div>';
  98. print dol_get_fiche_end();
  99. $parameters = array();
  100. $reshook = $hookmanager->executeHooks('listAssetDeprecation', $parameters, $object, $action);
  101. print $hookmanager->resPrint;
  102. if ($reshook < 0) {
  103. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  104. } elseif (empty($reshook)) {
  105. $bookkeeping_icon = '<i class="fas fa-save" title="'.$langs->trans('AssetDispatchedInBookkeeping').'"></i>';
  106. $future_icon = '<i class="fas fa-clock" title="'.$langs->trans('AssetFutureDepreciationLine').'"></i>';
  107. $now = dol_now();
  108. foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $fields) {
  109. $lines = $object->depreciation_lines[$mode_key];
  110. if (!empty($lines)) {
  111. $mode_info = $assetdepreciationoptions->deprecation_options_fields[$mode_key];
  112. $depreciation_info = $assetdepreciationoptions->getGeneralDepreciationInfoForMode($mode_key);
  113. print load_fiche_titre($langs->trans($mode_info['label']), '', '');
  114. // Depreciation general info
  115. //---------------------------------
  116. print '<div class="fichecenter">';
  117. print '<div class="fichehalfleft">';
  118. print '<div class="underbanner clearboth"></div>';
  119. print '<table class="border centpercent tableforfield">' . "\n";
  120. print '<tr><td class="titlefield">' . $langs->trans('AssetBaseDepreciationHT') . '</td><td>' . price($depreciation_info['base_depreciation_ht']) . '</td></tr>';
  121. 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>';
  122. print '</table>';
  123. // We close div and reopen for second column
  124. print '</div>';
  125. print '<div class="fichehalfright">';
  126. print '<div class="underbanner clearboth"></div>';
  127. print '<table class="border centpercent tableforfield">';
  128. print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationDuration') . '</td><td>' . $depreciation_info['duration'] . ' ( ' . $depreciation_info['duration_type'] . ' )</td></tr>';
  129. print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationRate') . '</td><td>' . $depreciation_info['rate'] . '</td></tr>';
  130. print '</table>';
  131. print '</div>';
  132. print '</div>';
  133. print '<div class="clearboth"></div>';
  134. // Depreciation lines
  135. //---------------------------------
  136. print '<br>';
  137. print '<div class="div-table-responsive-no-min">';
  138. print '<table class="noborder allwidth">';
  139. print '<tr class="liste_titre">';
  140. print '<td class="width20"></td>';
  141. print '<td>' . $langs->trans("Ref") . '</td>';
  142. print '<td class="center">' . $langs->trans("AssetDepreciationDate") . '</td>';
  143. print '<td class="right">' . $langs->trans("AssetDepreciationHT") . '</td>';
  144. print '<td class="right">' . $langs->trans("AssetCumulativeDepreciationHT") . '</td>';
  145. print '<td class="right">' . $langs->trans("AssetResidualHT") . '</td>';
  146. print '</tr>';
  147. if (empty($lines)) {
  148. print '<tr><td class="impair center" colspan="6"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
  149. } else {
  150. foreach ($lines as $line) {
  151. print '<tr class="oddeven">';
  152. print '<td>' . ($line['bookkeeping'] ? $bookkeeping_icon : ($line['depreciation_date'] > $now ? $future_icon : '')) . '</td>';
  153. print '<td >' . (empty($line['ref']) ? $langs->trans('AssetDepreciationReversal') : $line['ref']) . '</td>';
  154. print '<td class="center">' . dol_print_date($line['depreciation_date'], 'day') . '</td>';
  155. print '<td class="right">';
  156. print price($line['depreciation_ht']);
  157. print '</td>';
  158. print '<td class="right">';
  159. print price($line['cumulative_depreciation_ht']);
  160. print '</td>';
  161. print '<td class="right">';
  162. print price(price2num($depreciation_info['base_depreciation_ht'] - $line['cumulative_depreciation_ht'], 'MT'));
  163. print '</td>';
  164. print "</tr>\n";
  165. }
  166. }
  167. print '</table>';
  168. print '</div>';
  169. }
  170. }
  171. }
  172. }
  173. // End of page
  174. llxFooter();
  175. $db->close();