dolibarr 25.0.0-alpha
accountancy_codes.php
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-2026 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
37require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
38require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php';
39require_once DOL_DOCUMENT_ROOT . '/asset/class/assetaccountancycodes.class.php';
40require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
41
42// Load translation files required by the page
43$langs->loadLangs(array("assets", "companies"));
44
45// Get parameters
46$id = GETPOSTINT('id');
47$ref = GETPOST('ref', 'alpha');
48$action = GETPOST('action', 'aZ09');
49$cancel = GETPOST('cancel', 'alpha');
50$backtopage = GETPOST('backtopage', 'alpha');
51$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
52
53// Initialize a technical objects
54$object = new Asset($db);
55$assetaccountancycodes = new AssetAccountancyCodes($db);
56$assetdepreciationoptions = new AssetDepreciationOptions($db);
57
58$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
59$hookmanager->initHooks(array('assetaccountancycodes', 'globalcard')); // Note that conf->hooks_modules contains array
60// Fetch optionals attributes and labels
61$extrafields->fetch_name_optionals_label($object->table_element);
62
63// Load object
64include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
65if ($id > 0 || !empty($ref)) {
66 $upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1] . "/" . $object->id;
67}
68
69$permissiontoadd = $user->hasRight('asset', 'write'); // Used by the include of actions_addupdatedelete.inc.php
70
71// Security check (enable the most restrictive one)
72if ($user->socid > 0) {
74}
75$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
76restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
77if (!isModEnabled('asset')) {
79}
80
81$object->asset_depreciation_options = &$assetdepreciationoptions;
82$object->asset_accountancy_codes = &$assetaccountancycodes;
83if (!empty($id)) {
84 $depreciationoptionserrors = $assetdepreciationoptions->fetchDeprecationOptions($object->id, 0);
85 $accountancycodeserrors = $assetaccountancycodes->fetchAccountancyCodes($object->id, 0);
86
87 if ($depreciationoptionserrors < 0) {
88 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
89 }
90 if ($accountancycodeserrors < 0) {
91 setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors, 'errors');
92 }
93}
94
95
96/*
97 * Actions
98 */
99
100$reshook = $hookmanager->executeHooks('doActions', array(), $object, $action); // Note that $action and $object may have been modified by some hooks
101if ($reshook < 0) {
102 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
103}
104if (empty($reshook)) {
105 $backurlforlist = DOL_URL_ROOT.'/asset/list.php';
106
107 if (empty($backtopage) || ($cancel && empty($id))) {
108 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
109 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
110 $backtopage = $backurlforlist;
111 } else {
112 $backtopage = DOL_URL_ROOT.'/asset/accountancy_codes.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
113 }
114 }
115 }
116
117 if ($cancel) {
118 /*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
119 if (!empty($backtopageforcancel)) {
120 header("Location: ".$backtopageforcancel);
121 exit;
122 } elseif (!empty($backtopage)) {
123 header("Location: ".$backtopage);
124 exit;
125 }
126 $action = '';
127 }
128
129 if ($action == "update" && $permissiontoadd) {
130 $assetaccountancycodes->setAccountancyCodesFromPost();
131
132 $result = $assetaccountancycodes->updateAccountancyCodes($user, $object->id);
133 if ($result < 0) {
134 setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors, 'errors');
135 $action = 'edit';
136 } else {
137 setEventMessage($langs->trans('RecordSaved'));
138 header("Location: " . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
139 exit;
140 }
141 }
142}
143
144
145/*
146 * View
147 */
148
149$form = new Form($db);
150
151$help_url = '';
152llxHeader('', $langs->trans('Asset'), $help_url, '', 0, 0, '', '', '', 'mod-asset page-card_accountancy');
153
154if ($id > 0 || !empty($ref)) {
155 $head = assetPrepareHead($object);
156 print dol_get_fiche_head($head, 'accountancy_codes', $langs->trans("Asset"), -1, $object->picto);
157
158 // Object card
159 // ------------------------------------------------------------
160 $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
161
162 $morehtmlref = '<div class="refidno">';
163 $morehtmlref .= '</div>';
164
165 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
166
167 print '<div class="fichecenter">';
168 print '<div class="underbanner clearboth"></div>';
169 print '</div>';
170
171 print '<br>';
172
173 if ($action == 'edit') {
174 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">';
175 print '<input type="hidden" name="token" value="' . newToken() . '">';
176 print '<input type="hidden" name="action" value="update">';
177 if ($backtopage) {
178 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
179 }
180 if ($backtopageforcancel) {
181 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
182 }
183
184 include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_edit.tpl.php';
185
186 print $form->buttonsSaveCancel();
187
188 print '</form>';
189 } else {
190 include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_view.tpl.php';
191 }
192
193 print dol_get_fiche_end();
194
195 if ($action != 'edit') {
196 print '<div class="tabsAction">' . "\n";
197 $parameters = array();
198 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
199 if ($reshook < 0) {
200 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
201 }
202
203 if (empty($reshook)) {
204 if ($object->status == $object::STATUS_DRAFT/* && !empty($object->enabled_modes)*/) {
205 print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
206 }
207 }
208 print '</div>' . "\n";
209 }
210}
211
212// End of page
213llxFooter();
214$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
assetPrepareHead(Asset $object)
Prepare array of tabs for Asset.
Definition asset.lib.php:88
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class for AssetAccountancyCodes.
Class for AssetDepreciationOptions.
Class for Asset.
Class to manage generation of HTML components Only common components must be here.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.