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->rights->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 $reshook = $hookmanager->executeHooks(
'doActions', array(), $object, $action);
80 if (empty($reshook)) {
81 $backurlforlist = DOL_URL_ROOT.
'/asset/list.php';
83 if (empty($backtopage) || ($cancel && empty($id))) {
84 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
85 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
86 $backtopage = $backurlforlist;
88 $backtopage = DOL_URL_ROOT.
'/asset/depreciation_options.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
95 if (!empty($backtopageforcancel)) {
96 header(
"Location: ".$backtopageforcancel);
98 } elseif (!empty($backtopage)) {
99 header(
"Location: ".$backtopage);
105 if ($action ==
"update") {
106 $result = $assetdepreciationoptions->setDeprecationOptionsFromPost();
107 if ($result > 0) $result = $assetdepreciationoptions->updateDeprecationOptions($user, $object->id);
109 setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors,
'errors');
113 header(
"Location: " . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id);
129 if ($id > 0 || !empty($ref)) {
131 print
dol_get_fiche_head($head,
'depreciation_options', $langs->trans(
"Asset"), -1, $object->picto);
135 $linkback =
'<a href="'.DOL_URL_ROOT.
'/asset/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
137 $morehtmlref =
'<div class="refidno">';
138 $morehtmlref .=
'</div>';
140 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
142 print
'<div class="fichecenter">';
143 print
'<div class="underbanner clearboth"></div>';
146 if ($action ==
'edit') {
147 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'">';
148 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
149 print
'<input type="hidden" name="action" value="update">';
151 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
153 if ($backtopageforcancel) {
154 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
159 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_edit.tpl.php';
163 print
$form->buttonsSaveCancel();
167 include DOL_DOCUMENT_ROOT .
'/asset/tpl/depreciation_options_view.tpl.php';
172 if ($action !=
'edit') {
173 print
'<div class="tabsAction">' .
"\n";
174 $parameters = array();
175 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
180 if (empty($reshook)) {
181 if ($object->status == $object::STATUS_DRAFT) {
182 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=edit&token=' .
newToken(),
'', $permissiontoadd);
185 print
'</div>' .
"\n";