dolibarr 20.0.0
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// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
28require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php';
29require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
30
31// Load translation files required by the page
32$langs->loadLangs(array("assets", "companies"));
33
34// Get parameters
35$id = GETPOSTINT('id');
36$ref = GETPOST('ref', 'alpha');
37$action = GETPOST('action', 'aZ09');
38$cancel = GETPOST('cancel', 'aZ09');
39$backtopage = GETPOST('backtopage', 'alpha');
40
41// Initialize technical objects
42$object = new Asset($db);
43$assetdepreciationoptions = new AssetDepreciationOptions($db);
44$extrafields = new ExtraFields($db);
45$diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
46$hookmanager->initHooks(array('assetdepreciation', 'globalcard')); // Note that conf->hooks_modules contains array
47// Fetch optionals attributes and labels
48$extrafields->fetch_name_optionals_label($object->table_element);
49
50// Load object
51include 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
52if ($id > 0 || !empty($ref)) {
53 $upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
54}
55
56// Security check (enable the most restrictive one)
57if ($user->socid > 0) {
59}
60$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
61restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
62if (!isModEnabled('asset')) {
64}
65if (!empty($object->not_depreciated)) {
67}
68
69$object->asset_depreciation_options = &$assetdepreciationoptions;
70$result = $assetdepreciationoptions->fetchDeprecationOptions($object->id);
71if ($result < 0) {
72 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
73}
74$result = $object->fetchDepreciationLines();
75if ($result < 0) {
76 setEventMessages($object->error, $object->errors, 'errors');
77}
78
79
80/*
81 * Actions
82 */
83
84$parameters = array();
85$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
86if ($reshook < 0) {
87 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
88}
89if (empty($reshook)) {
90}
91
92
93/*
94 * View
95 */
96
97$form = new Form($db);
98
99$help_url = '';
100llxHeader('', $langs->trans('Asset'), $help_url, '', 0, 0, '', '', '', 'mod-asset page-card_depreciation');
101
102if ($id > 0 || !empty($ref)) {
103 $head = assetPrepareHead($object);
104 print dol_get_fiche_head($head, 'depreciation', $langs->trans("Asset"), -1, $object->picto);
105
106 // Object card
107 // ------------------------------------------------------------
108 $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
109
110 $morehtmlref = '<div class="refidno">';
111 $morehtmlref .= '</div>';
112
113 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
114
115 print '<div class="fichecenter">';
116 print '<div class="underbanner clearboth"></div>';
117 print '</div>';
118
119 print dol_get_fiche_end();
120
121 $parameters = array();
122 $reshook = $hookmanager->executeHooks('listAssetDeprecation', $parameters, $object, $action);
123 print $hookmanager->resPrint;
124 if ($reshook < 0) {
125 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
126 } elseif (empty($reshook)) {
127 $bookkeeping_icon = '<i class="fas fa-save" title="'.$langs->trans('AssetDispatchedInBookkeeping').'"></i>';
128 $future_icon = '<i class="fas fa-clock" title="'.$langs->trans('AssetFutureDepreciationLine').'"></i>';
129 $now = dol_now();
130
131 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $fields) {
132 $lines = $object->depreciation_lines[$mode_key];
133 if (!empty($lines)) {
134 $mode_info = $assetdepreciationoptions->deprecation_options_fields[$mode_key];
135 $depreciation_info = $assetdepreciationoptions->getGeneralDepreciationInfoForMode($mode_key);
136
137 print load_fiche_titre($langs->trans($mode_info['label']), '', '');
138
139 // Depreciation general info
140 //---------------------------------
141 print '<div class="fichecenter">';
142 print '<div class="fichehalfleft">';
143 print '<div class="underbanner clearboth"></div>';
144 print '<table class="border centpercent tableforfield">' . "\n";
145 print '<tr><td class="titlefield">' . $langs->trans('AssetBaseDepreciationHT') . '</td><td>' . price($depreciation_info['base_depreciation_ht']) . '</td></tr>';
146 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>';
147 print '</table>';
148
149 // We close div and reopen for second column
150 print '</div>';
151 print '<div class="fichehalfright">';
152
153 print '<div class="underbanner clearboth"></div>';
154 print '<table class="border centpercent tableforfield">';
155 print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationDuration') . '</td><td>' . $depreciation_info['duration'] . ' ( ' . $depreciation_info['duration_type'] . ' )</td></tr>';
156 print '<tr><td class="titlefield">' . $langs->trans('AssetDepreciationRate') . '</td><td>' . $depreciation_info['rate'] . '</td></tr>';
157 print '</table>';
158 print '</div>';
159 print '</div>';
160 print '<div class="clearboth"></div>';
161
162 // Depreciation lines
163 //---------------------------------
164 print '<br>';
165 print '<div class="div-table-responsive-no-min">';
166 print '<table class="noborder allwidth">';
167
168 print '<tr class="liste_titre">';
169 print '<td class="width20"></td>';
170 print '<td>' . $langs->trans("Ref") . '</td>';
171 print '<td class="center">' . $langs->trans("AssetDepreciationDate") . '</td>';
172 print '<td class="right">' . $langs->trans("AssetDepreciationHT") . '</td>';
173 print '<td class="right">' . $langs->trans("AssetCumulativeDepreciationHT") . '</td>';
174 print '<td class="right">' . $langs->trans("AssetResidualHT") . '</td>';
175 print '</tr>';
176
177 if (empty($lines)) {
178 print '<tr><td class="impair center" colspan="6"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
179 } else {
180 foreach ($lines as $line) {
181 print '<tr class="oddeven">';
182 print '<td>' . ($line['bookkeeping'] ? $bookkeeping_icon : ($line['depreciation_date'] > $now ? $future_icon : '')) . '</td>';
183 print '<td >' . (empty($line['ref']) ? $langs->trans('AssetDepreciationReversal') : $line['ref']) . '</td>';
184 print '<td class="center">' . dol_print_date($line['depreciation_date'], 'day') . '</td>';
185 print '<td class="right">';
186 print price($line['depreciation_ht']);
187 print '</td>';
188 print '<td class="right">';
189 print price($line['cumulative_depreciation_ht']);
190 print '</td>';
191 print '<td class="right">';
192 print price(price2num($depreciation_info['base_depreciation_ht'] - $line['cumulative_depreciation_ht'], 'MT'));
193 print '</td>';
194 print "</tr>\n";
195 }
196 }
197
198 print '</table>';
199 print '</div>';
200 }
201 }
202 }
203}
204
205// End of page
206llxFooter();
207$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
assetPrepareHead(Asset $object)
Prepare array of tabs for Asset.
Definition asset.lib.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.