dolibarr  16.0.5
depreciation.php
Go to the documentation of this file.
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 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
27 require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php';
28 require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array("assets", "companies"));
32 
33 // Get parameters
34 $id = GETPOST('id', 'int');
35 $ref = GETPOST('ref', 'alpha');
36 $action = GETPOST('action', 'aZ09');
37 $cancel = GETPOST('cancel', 'aZ09');
38 $backtopage = GETPOST('backtopage', 'alpha');
39 
40 // Initialize technical objects
41 $object = new Asset($db);
42 $assetdepreciationoptions = new AssetDepreciationOptions($db);
43 $extrafields = new ExtraFields($db);
44 $diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
45 $hookmanager->initHooks(array('assetdepreciation', 'globalcard')); // Note that conf->hooks_modules contains array
46 // Fetch optionals attributes and labels
47 $extrafields->fetch_name_optionals_label($object->table_element);
48 
49 // Load object
50 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
51 if ($id > 0 || !empty($ref)) {
52  $upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
53 }
54 
55 // Security check (enable the most restrictive one)
56 if ($user->socid > 0) accessforbidden();
57 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
58 restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
59 if (empty($conf->asset->enabled)) accessforbidden();
60 if (!empty($object->not_depreciated)) accessforbidden();
61 
62 $object->asset_depreciation_options = &$assetdepreciationoptions;
63 $result = $assetdepreciationoptions->fetchDeprecationOptions($object->id);
64 if ($result < 0) {
65  setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
66 }
67 $result = $object->fetchDepreciationLines();
68 if ($result < 0) {
69  setEventMessages($object->error, $object->errors, 'errors');
70 }
71 
72 
73 /*
74  * Actions
75  */
76 
77 $reshook = $hookmanager->executeHooks('doActions', array(), $object, $action); // Note that $action and $object may have been modified by some hooks
78 if ($reshook < 0) {
79  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
80 }
81 if (empty($reshook)) {
82 }
83 
84 
85 /*
86  * View
87  */
88 
89 $form = new Form($db);
90 
91 $help_url = '';
92 llxHeader('', $langs->trans('Asset'), $help_url);
93 
94 if ($id > 0 || !empty($ref)) {
95  $head = assetPrepareHead($object);
96  print dol_get_fiche_head($head, 'depreciation', $langs->trans("Asset"), -1, $object->picto);
97 
98  // Object card
99  // ------------------------------------------------------------
100  $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
101 
102  $morehtmlref = '<div class="refidno">';
103  $morehtmlref .= '</div>';
104 
105  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
106 
107  print '<div class="fichecenter">';
108  print '<div class="underbanner clearboth"></div>';
109  print '</div>';
110 
111  print dol_get_fiche_end();
112 
113  $parameters = array();
114  $reshook = $hookmanager->executeHooks('listAssetDeprecation', $parameters, $object, $action);
115  print $hookmanager->resPrint;
116  if ($reshook < 0) {
117  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118  } elseif (empty($reshook)) {
119  $bookkeeping_icon = '<i class="fas fa-save" title="'.$langs->trans('AssetDispatchedInBookkeeping').'"></i>';
120  $future_icon = '<i class="fas fa-clock" title="'.$langs->trans('AssetFutureDepreciationLine').'"></i>';
121  $now = dol_now();
122 
123  foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $fields) {
124  $lines = $object->depreciation_lines[$mode_key];
125  if (!empty($lines)) {
126  $mode_info = $assetdepreciationoptions->deprecation_options_fields[$mode_key];
127  $depreciation_info = $assetdepreciationoptions->getGeneralDepreciationInfoForMode($mode_key);
128 
129  print load_fiche_titre($langs->trans($mode_info['label']), '', '');
130 
131  // Depreciation general info
132  //---------------------------------
133  print '<div class="fichecenter">';
134  print '<div class="fichehalfleft">';
135  print '<div class="underbanner clearboth"></div>';
136  print '<table class="border centpercent tableforfield">' . "\n";
137  print '<tr><td class="titlefield">' . $langs->trans('AssetBaseDepreciationHT') . '</td><td>' . price($depreciation_info['base_depreciation_ht']) . '</td></tr>';
138  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>';
139  print '</table>';
140 
141  // We close div and reopen for second column
142  print '</div>';
143  print '<div class="fichehalfright">';
144 
145  print '<div class="underbanner clearboth"></div>';
146  print '<table class="border centpercent tableforfield">';
147  print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationDuration') . '</td><td>' . $depreciation_info['duration'] . ' ( ' . $depreciation_info['duration_type'] . ' )</td></tr>';
148  print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationRate') . '</td><td>' . $depreciation_info['rate'] . '</td></tr>';
149  print '</table>';
150  print '</div>';
151  print '</div>';
152  print '<div class="clearboth"></div>';
153 
154  // Depreciation lines
155  //---------------------------------
156  print '<br>';
157  print '<div class="div-table-responsive-no-min">';
158  print '<table class="noborder allwidth">';
159 
160  print '<tr class="liste_titre">';
161  print '<td class="width20"></td>';
162  print '<td>' . $langs->trans("Ref") . '</td>';
163  print '<td class="center">' . $langs->trans("AssetDepreciationDate") . '</td>';
164  print '<td class="right">' . $langs->trans("AssetDepreciationHT") . '</td>';
165  print '<td class="right">' . $langs->trans("AssetCumulativeDepreciationHT") . '</td>';
166  print '<td class="right">' . $langs->trans("AssetResidualHT") . '</td>';
167  print '</tr>';
168 
169  if (empty($lines)) {
170  print '<tr><td class="impair center" colspan="6"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
171  } else {
172  foreach ($lines as $line) {
173  print '<tr class="oddeven">';
174  print '<td>' . ($line['bookkeeping'] ? $bookkeeping_icon : ($line['depreciation_date'] > $now ? $future_icon : '')) . '</td>';
175  print '<td >' . (empty($line['ref']) ? $langs->trans('AssetDepreciationReversal') : $line['ref']) . '</td>';
176  print '<td class="center">' . dol_print_date($line['depreciation_date'], 'day') . '</td>';
177  print '<td class="right">';
178  print price($line['depreciation_ht']);
179  print '</td>';
180  print '<td class="right">';
181  print price($line['cumulative_depreciation_ht']);
182  print '</td>';
183  print '<td class="right">';
184  print price(price2num($depreciation_info['base_depreciation_ht'] - $line['cumulative_depreciation_ht'], 'MT'));
185  print '</td>';
186  print "</tr>\n";
187  }
188  }
189 
190  print '</table>';
191  print '</div>';
192  }
193  }
194  }
195 }
196 
197 // End of page
198 llxFooter();
199 $db->close();
Asset
Class for Asset.
Definition: asset.class.php:30
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
AssetDepreciationOptions
Class for AssetDepreciationOptions.
Definition: assetdepreciationoptions.class.php:29
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
assetPrepareHead
assetPrepareHead(Asset $object)
Prepare array of tabs for Asset.
Definition: asset.lib.php:74
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59