25 require
'../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/asset.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/asset/class/asset.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
32 $langs->loadLangs(array(
"assets",
"other"));
37 $action =
GETPOST(
'action',
'aZ09');
38 $confirm =
GETPOST(
'confirm',
'alpha');
39 $cancel =
GETPOST(
'cancel',
'aZ09');
40 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'assetcard';
41 $backtopage =
GETPOST(
'backtopage',
'alpha');
42 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
45 $object =
new Asset($db);
47 $diroutputmassaction = $conf->asset->dir_output.
'/temp/massgeneration/'.$user->id;
48 $hookmanager->initHooks(array(
'assetcard',
'globalcard'));
51 $extrafields->fetch_name_optionals_label($object->table_element);
53 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
56 $search_all =
GETPOST(
"search_all",
'alpha');
58 foreach ($object->fields as $key => $val) {
59 if (
GETPOST(
'search_'.$key,
'alpha')) {
60 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
64 if (empty($action) && empty($id) && empty($ref)) {
69 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
71 $permissiontoread = $user->rights->asset->read;
72 $permissiontoadd = $user->rights->asset->write;
73 $permissiontodelete = $user->rights->asset->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
74 $permissionnote = $user->rights->asset->write;
75 $permissiondellink = $user->rights->asset->write;
76 $upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1];
80 if ($user->socid > 0) $socid = $user->socid;
81 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
82 restrictedArea($user, $object->element, $object->id, $object->table_element,
'',
'fk_soc',
'rowid', $isdraft);
92 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
97 if (empty($reshook)) {
100 $backurlforlist = DOL_URL_ROOT.
'/asset/list.php';
102 if (empty($backtopage) || ($cancel && empty($id))) {
103 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
104 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
105 $backtopage = $backurlforlist;
107 $backtopage = DOL_URL_ROOT.
'/asset/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
113 $triggermodname =
'ASSET_MODIFY';
116 if ($action ==
'confirm_disposal' && $confirm ==
'yes' && $permissiontoadd) {
117 $object->disposal_date =
dol_mktime(12, 0, 0,
GETPOST(
'disposal_datemonth',
'int'),
GETPOST(
'disposal_dateday',
'int'),
GETPOST(
'disposal_dateyear',
'int'));
118 $object->disposal_amount_ht =
GETPOST(
'disposal_amount',
'int');
119 $object->fk_disposal_type =
GETPOST(
'fk_disposal_type',
'int');
120 $disposal_invoice_id =
GETPOST(
'disposal_invoice_id',
'int');
121 $object->disposal_depreciated = ((
GETPOST(
'disposal_depreciated') ==
'1' ||
GETPOST(
'disposal_depreciated') ==
'on') ? 1 : 0);
122 $object->disposal_subject_to_vat = ((
GETPOST(
'disposal_subject_to_vat') ==
'1' ||
GETPOST(
'disposal_subject_to_vat') ==
'on') ? 1 : 0);
124 $result = $object->dispose($user, $disposal_invoice_id);
129 } elseif ($action ==
"add") {
130 $object->supplier_invoice_id =
GETPOST(
'supplier_invoice_id',
'int');
134 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
137 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
140 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
146 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
149 $triggersendname =
'ASSET_SENTBYMAIL';
150 $autocopy =
'MAIN_MAIL_AUTOCOPY_ASSET_TO';
151 $trackid =
'asset'.$object->id;
152 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
164 $title = $langs->trans(
"Asset").
' - '.$langs->trans(
"Card");
169 if ($action ==
'create') {
170 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"Asset")),
'',
'object_'.$object->picto);
172 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
173 print
'<input type="hidden" name="token" value="'.newToken().
'">';
174 print
'<input type="hidden" name="action" value="add">';
176 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
178 if ($backtopageforcancel) {
179 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
182 $object->fields[
'supplier_invoice_id'] = array(
'type' =>
'integer:FactureFournisseur:fourn/class/fournisseur.facture.class.php:1:entity IN (__SHARED_ENTITIES__)',
'label' =>
'SupplierInvoice',
'enabled' =>
'1',
'noteditable' =>
'1',
'position' => 280,
'notnull' => 0,
'visible' => 1,
'index' => 1,
'validate' =>
'1',);
183 print
'<input type="hidden" name="supplier_invoice_id" value="' .
GETPOST(
'supplier_invoice_id',
'int') .
'">';
191 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
194 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
197 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
199 print
'</table>'.
"\n";
203 print
$form->buttonsSaveCancel(
"Create");
211 if (($id || $ref) && $action ==
'edit') {
212 print
load_fiche_titre($langs->trans(
"Asset"),
'',
'object_'.$object->picto);
214 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
215 print
'<input type="hidden" name="token" value="'.newToken().
'">';
216 print
'<input type="hidden" name="action" value="update">';
217 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
219 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
221 if ($backtopageforcancel) {
222 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
227 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
230 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_edit.tpl.php';
233 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
239 print
$form->buttonsSaveCancel();
245 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
246 $res = $object->fetch_optionals();
254 if ($action ==
'delete') {
255 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteAsset'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
256 } elseif ($action ==
'disposal') {
258 $langs->load(
'bills');
261 $disposal_amount =
GETPOST(
'disposal_amount',
'int');
262 $fk_disposal_type =
GETPOST(
'fk_disposal_type',
'int');
263 $disposal_invoice_id =
GETPOST(
'disposal_invoice_id',
'int');
264 $disposal_depreciated =
GETPOSTISSET(
'disposal_depreciated') ?
GETPOST(
'disposal_depreciated') : 1;
265 $disposal_depreciated = !empty($disposal_depreciated) ? 1 : 0;
266 $disposal_subject_to_vat =
GETPOSTISSET(
'disposal_subject_to_vat') ?
GETPOST(
'disposal_subject_to_vat') : 1;
267 $disposal_subject_to_vat = !empty($disposal_subject_to_vat) ? 1 : 0;
269 $object->fields[
'fk_disposal_type'][
'visible'] = 1;
270 $disposal_type_form = $object->showInputField(
null,
'fk_disposal_type', $fk_disposal_type,
'',
'',
'', 0);
271 $object->fields[
'fk_disposal_type'][
'visible'] = -2;
273 $object->fields[
'disposal_invoice_id'] = array(
'type' =>
'integer:Facture:compta/facture/class/facture.class.php::entity IN (__SHARED_ENTITIES__)',
'enabled' =>
'1',
'notnull' => 1,
'visible' => 1,
'index' => 1,
'validate' =>
'1',);
274 $disposal_invoice_form = $object->showInputField(
null,
'disposal_invoice_id', $disposal_invoice_id,
'',
'',
'', 0);
275 unset($object->fields[
'disposal_invoice_id']);
278 $formquestion = array(
279 array(
'type' =>
'date',
'name' =>
'disposal_date',
'tdclass' =>
'fieldrequired',
'label' => $langs->trans(
"AssetDisposalDate"),
'value' => $disposal_date),
280 array(
'type' =>
'text',
'name' =>
'disposal_amount',
'tdclass' =>
'fieldrequired',
'label' => $langs->trans(
"AssetDisposalAmount"),
'value' => $disposal_amount),
281 array(
'type' =>
'other',
'name' =>
'fk_disposal_type',
'tdclass' =>
'fieldrequired',
'label' => $langs->trans(
"AssetDisposalType"),
'value' => $disposal_type_form),
282 array(
'type' =>
'other',
'name' =>
'disposal_invoice_id',
'label' => $langs->trans(
"InvoiceCustomer"),
'value' => $disposal_invoice_form),
283 array(
'type' =>
'checkbox',
'name' =>
'disposal_depreciated',
'label' => $langs->trans(
"AssetDisposalDepreciated"),
'value' => $disposal_depreciated),
284 array(
'type' =>
'checkbox',
'name' =>
'disposal_subject_to_vat',
'label' => $langs->trans(
"AssetDisposalSubjectToVat"),
'value' => $disposal_subject_to_vat),
286 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' . $object->id, $langs->trans(
'AssetDisposal'), $langs->trans(
'AssetConfirmDisposalAsk', $object->ref .
' - ' . $object->label),
'confirm_disposal', $formquestion,
'yes', 1);
287 } elseif ($action ==
'reopen') {
290 $formquestion = array();
291 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ReOpen'), $langs->trans(
'AssetConfirmReOpenAsk', $object->ref),
'confirm_reopen', $formquestion,
'yes', 1);
302 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
303 if (empty($reshook)) {
305 } elseif ($reshook > 0) {
315 $linkback =
'<a href="'.DOL_URL_ROOT.
'/asset/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
317 $morehtmlref =
'<div class="refidno">';
318 $morehtmlref .=
'</div>';
321 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
324 print
'<div class="fichecenter">';
325 print
'<div class="fichehalfleft">';
326 print
'<div class="underbanner clearboth"></div>';
327 print
'<table class="border centpercent tableforfield">'.
"\n";
330 $keyforbreak=
'date_acquisition';
333 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
336 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
342 print
'<div class="clearboth"></div>';
347 if ($action !=
'presend' && $action !=
'editline') {
348 print
'<div class="tabsAction">' .
"\n";
350 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
355 if (empty($reshook)) {
357 if (empty($user->socid)) {
358 print
dolGetButtonAction($langs->trans(
'SendMail'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=presend&mode=init&token=' .
newToken() .
'#formmailbeforetitle');
361 if ($object->status == $object::STATUS_DRAFT) {
362 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=edit&token=' .
newToken(),
'', $permissiontoadd);
368 if ($object->status == $object::STATUS_DRAFT) {
369 print
dolGetButtonAction($langs->trans(
'AssetDisposal'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id .
'&action=disposal&token=' .
newToken(),
'', $permissiontoadd);
371 print
dolGetButtonAction($langs->trans(
'ReOpen'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id .
'&action=reopen&token=' .
newToken(),
'', $permissiontoadd);
375 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id .
'&action=delete&token=' .
newToken(),
'', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
377 print
'</div>' .
"\n";
381 if (
GETPOST(
'modelselected')) {
385 if ($action !=
'presend') {
386 print
'<div class="fichecenter"><div class="fichehalfleft">';
387 print
'<a name="builddoc"></a>';
389 $includedocgeneration = 0;
392 if ($includedocgeneration) {
394 $relativepath = $objref.
'/'.$objref.
'.pdf';
395 $filedir = $conf->asset->dir_output.
'/'.$objref;
396 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
397 $genallowed = $user->rights->asset->read;
398 $delallowed = $user->rights->asset->write;
399 print $formfile->showdocuments(
'asset:Asset', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $langs->defaultlang);
403 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'asset'));
404 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
407 print
'</div><div class="fichehalfright">';
411 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/asset/agenda.php?id='.$object->id);
414 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
416 $somethingshown =
$formactions->showactions($object, $object->element, 0, 1,
'', $MAXEVENT,
'', $morehtmlright);
418 print
'</div></div>';
422 if (
GETPOST(
'modelselected')) {
427 $modelmail =
'asset';
428 $defaulttopic =
'InformationMessage';
429 $diroutput = $conf->asset->dir_output;
430 $trackid =
'asset'.$object->id;
432 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';