26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT .
'/core/lib/asset.lib.php';
28 require_once DOL_DOCUMENT_ROOT .
'/asset/class/asset.class.php';
29 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
32 $langs->loadLangs(array(
"assets",
"companies"));
37 $action =
GETPOST(
'action',
'aZ09');
38 $cancel =
GETPOST(
'cancel',
'aZ09');
39 $backtopage =
GETPOST(
'backtopage',
'alpha');
42 $object =
new Asset($db);
45 $diroutputmassaction = $conf->asset->dir_output.
'/temp/massgeneration/'.$user->id;
46 $hookmanager->initHooks(array(
'assetdepreciationoptions',
'globalcard'));
48 $extrafields->fetch_name_optionals_label($object->table_element);
51 include DOL_DOCUMENT_ROOT .
'/core/actions_fetchobject.inc.php';
52 if ($id > 0 || !empty($ref)) {
53 $upload_dir = $conf->asset->multidir_output[$object->entity] .
"/" . $object->id;
56 $permissiontoadd = $user->hasRight(
'asset',
'write');
60 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
61 restrictedArea($user, $object->element, $object->id, $object->table_element,
'',
'fk_soc',
'rowid', $isdraft);
65 $object->asset_depreciation_options = &$assetdepreciationoptions;
66 $result = $assetdepreciationoptions->fetchDeprecationOptions($object->id);
68 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors,
'errors');
76 $parameters = array();
77 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
81 if (empty($reshook)) {
82 $backurlforlist = DOL_URL_ROOT.
'/asset/list.php';
84 if (empty($backtopage) || ($cancel && empty($id))) {
85 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
86 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
87 $backtopage = $backurlforlist;
89 $backtopage = DOL_URL_ROOT.
'/asset/depreciation_options.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
96 if (!empty($backtopageforcancel)) {
97 header(
"Location: ".$backtopageforcancel);
99 } elseif (!empty($backtopage)) {
100 header(
"Location: ".$backtopage);
106 if ($action ==
"update") {
107 $result = $assetdepreciationoptions->setDeprecationOptionsFromPost();
108 if ($result > 0) $result = $assetdepreciationoptions->updateDeprecationOptions($user, $object->id);
110 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors,
'errors');
114 header(
"Location: " . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id);
130 if ($id > 0 || !empty($ref)) {
132 print
dol_get_fiche_head($head,
'depreciation_options', $langs->trans(
"Asset"), -1, $object->picto);
136 $linkback =
'<a href="'.DOL_URL_ROOT.
'/asset/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
138 $morehtmlref =
'<div class="refidno">';
139 $morehtmlref .=
'</div>';
141 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
143 print
'<div class="fichecenter">';
144 print
'<div class="underbanner clearboth"></div>';
147 if ($action ==
'edit') {
148 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'">';
149 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
150 print
'<input type="hidden" name="action" value="update">';
152 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
154 if ($backtopageforcancel) {
155 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
160 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_edit.tpl.php';
164 print
$form->buttonsSaveCancel();
168 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_view.tpl.php';
173 if ($action !=
'edit') {
174 print
'<div class="tabsAction">' .
"\n";
175 $parameters = array();
176 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
181 if (empty($reshook)) {
182 if ($object->status == $object::STATUS_DRAFT) {
183 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=edit&token=' .
newToken(),
'', $permissiontoadd);
186 print
'</div>' .
"\n";