dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
30require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php';
31require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array("assets", "companies"));
43
44// Get parameters
45$id = GETPOSTINT('id');
46$ref = GETPOST('ref', 'alpha');
47$action = GETPOST('action', 'aZ09');
48$cancel = GETPOST('cancel', 'aZ09');
49$backtopage = GETPOST('backtopage', 'alpha');
50
51// Initialize a technical objects
52$object = new Asset($db);
53$assetdepreciationoptions = new AssetDepreciationOptions($db);
54$extrafields = new ExtraFields($db);
55$diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
56$hookmanager->initHooks(array('assetdepreciation', 'globalcard')); // Note that conf->hooks_modules contains array
57// Fetch optionals attributes and labels
58$extrafields->fetch_name_optionals_label($object->table_element);
59
60// Load object
61include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
62if ($id > 0 || !empty($ref)) {
63 $upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
64}
65
66// Security check (enable the most restrictive one)
67if ($user->socid > 0) {
69}
70$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
71restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
72if (!isModEnabled('asset')) {
74}
75if (!empty($object->not_depreciated)) {
77}
78
79$object->asset_depreciation_options = &$assetdepreciationoptions;
80$result = $assetdepreciationoptions->fetchDeprecationOptions($object->id);
81if ($result < 0) {
82 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
83}
84$result = $object->fetchDepreciationLines();
85if ($result < 0) {
86 setEventMessages($object->error, $object->errors, 'errors');
87}
88
89
90/*
91 * Actions
92 */
93
94$parameters = array();
95$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
96if ($reshook < 0) {
97 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
98}
99
100/*
101if (empty($reshook)) {
102}
103*/
104
105
106/*
107 * View
108 */
109
110$form = new Form($db);
111
112$help_url = '';
113llxHeader('', $langs->trans('Asset'), $help_url, '', 0, 0, '', '', '', 'mod-asset page-card_depreciation');
114
115if ($id > 0 || !empty($ref)) {
116 $head = assetPrepareHead($object);
117 print dol_get_fiche_head($head, 'depreciation', $langs->trans("Asset"), -1, $object->picto);
118
119 // Object card
120 // ------------------------------------------------------------
121 $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
122
123 $morehtmlref = '<div class="refidno">';
124 $morehtmlref .= '</div>';
125
126 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
127
128 print '<div class="fichecenter">';
129 print '<div class="underbanner clearboth"></div>';
130 print '</div>';
131
132 print dol_get_fiche_end();
133
134 $parameters = array();
135 $reshook = $hookmanager->executeHooks('listAssetDeprecation', $parameters, $object, $action);
136 print $hookmanager->resPrint;
137 if ($reshook < 0) {
138 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
139 } elseif (empty($reshook)) {
140 $bookkeeping_icon = '<i class="fas fa-save" title="'.$langs->trans('AssetDispatchedInBookkeeping').'"></i>';
141 $future_icon = '<i class="fas fa-clock" title="'.$langs->trans('AssetFutureDepreciationLine').'"></i>';
142 $now = dol_now();
143
144 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $fields) {
145 $lines = $object->depreciation_lines[$mode_key];
146 if (!empty($lines)) {
147 $mode_info = $assetdepreciationoptions->deprecation_options_fields[$mode_key];
148 $depreciation_info = $assetdepreciationoptions->getGeneralDepreciationInfoForMode($mode_key);
149
150 print load_fiche_titre($langs->trans($mode_info['label']), '', '');
151
152 // Depreciation general info
153 //---------------------------------
154 print '<div class="fichecenter">';
155 print '<div class="fichehalfleft">';
156 print '<div class="underbanner clearboth"></div>';
157 print '<table class="border centpercent tableforfield">' . "\n";
158 print '<tr><td class="titlefield">' . $langs->trans('AssetBaseDepreciationHT') . '</td><td>' . price($depreciation_info['base_depreciation_ht']) . '</td></tr>';
159 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>';
160 print '</table>';
161
162 // We close div and reopen for second column
163 print '</div>';
164 print '<div class="fichehalfright">';
165
166 print '<div class="underbanner clearboth"></div>';
167 print '<table class="border centpercent tableforfield">';
168 print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationDuration') . '</td><td>' . $depreciation_info['duration'] . ' ( ' . $depreciation_info['duration_type'] . ' )</td></tr>';
169 print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationRate') . '</td><td>' . $depreciation_info['rate'] . '</td></tr>';
170 print '</table>';
171 print '</div>';
172 print '</div>';
173 print '<div class="clearboth"></div>';
174
175 // Depreciation lines
176 //---------------------------------
177 print '<br>';
178 print '<div class="div-table-responsive-no-min">';
179 print '<table class="noborder allwidth">';
180
181 print '<tr class="liste_titre">';
182 print '<td class="width20"></td>';
183 print '<td>' . $langs->trans("Ref") . '</td>';
184 print '<td class="center">' . $langs->trans("AssetDepreciationDate") . '</td>';
185 print '<td class="right">' . $langs->trans("AssetDepreciationHT") . '</td>';
186 print '<td class="right">' . $langs->trans("AssetCumulativeDepreciationHT") . '</td>';
187 print '<td class="right">' . $langs->trans("AssetResidualHT") . '</td>';
188 print '</tr>';
189
190 if (empty($lines)) {
191 print '<tr><td class="impair center" colspan="6"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
192 } else {
193 foreach ($lines as $line) {
194 print '<tr class="oddeven">';
195 print '<td>' . ($line['bookkeeping'] ? $bookkeeping_icon : ($line['depreciation_date'] > $now ? $future_icon : '')) . '</td>';
196 print '<td >' . (empty($line['ref']) ? $langs->trans('AssetDepreciationReversal') : $line['ref']) . '</td>';
197 print '<td class="center">' . dol_print_date($line['depreciation_date'], 'day') . '</td>';
198 print '<td class="right">';
199 print price($line['depreciation_ht']);
200 print '</td>';
201 print '<td class="right">';
202 print price($line['cumulative_depreciation_ht']);
203 print '</td>';
204 print '<td class="right">';
205 print price(price2num((float) $depreciation_info['base_depreciation_ht'] - (float) $line['cumulative_depreciation_ht'], 'MT'));
206 print '</td>';
207 print "</tr>\n";
208 }
209 }
210
211 print '</table>';
212 print '</div>';
213 }
214 }
215 }
216}
217
218// End of page
219llxFooter();
220$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
assetPrepareHead(Asset $object)
Prepare array of tabs for Asset.
Definition asset.lib.php:88
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class for AssetDepreciationOptions.
Class for Asset.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.