* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/asset/type.php * \ingroup asset * \brief Asset's type setup */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php'; require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php'; require_once DOL_DOCUMENT_ROOT.'/asset/class/asset_type.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; // Load translation files required by the page $langs->load("assets"); $rowid = GETPOST('rowid', 'int'); $action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); $type = GETPOST('type', 'alpha'); $limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) { $sortorder="DESC"; } if (! $sortfield) { $sortfield="a.label"; } $label=GETPOST("label", "alpha"); $accountancy_code_asset=GETPOST('accountancy_code_asset', 'string'); $accountancy_code_depreciation_asset=GETPOST('accountancy_code_depreciation_asset', 'string'); $accountancy_code_depreciation_expense=GETPOST('accountancy_code_depreciation_expense', 'string'); $comment=GETPOST('comment', 'string'); // Security check $result=restrictedArea($user, 'asset', $rowid, 'asset_type'); $object = new AssetType($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label('asset_type'); if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { $type=""; $sall=""; } // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('assettypecard','globalcard')); /* * Actions */ if ($cancel) { $action=''; if (! empty($backtopage)) { header("Location: ".$backtopage); exit; } } if ($action == 'add' && $user->rights->asset->write) { $object->label = trim($label); $object->accountancy_code_asset = trim($accountancy_code_asset); $object->accountancy_code_depreciation_asset = trim($accountancy_code_depreciation_asset); $object->accountancy_code_depreciation_expense = trim($accountancy_code_depreciation_expense); $object->note = trim($comment); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) $error++; if (empty($object->label)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); } else { $sql = "SELECT label FROM ".MAIN_DB_PREFIX."asset_type WHERE label='".$db->escape($object->label)."'"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); } if ($num) { $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors'); } } if (! $error) { $id=$object->create($user); if ($id > 0) { header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); $action = 'create'; } } else { $action = 'create'; } } if ($action == 'update' && $user->rights->asset->write) { $object->fetch($rowid); $object->oldcopy = clone $object; $object->label = trim($label); $object->accountancy_code_asset = trim($accountancy_code_asset); $object->accountancy_code_depreciation_asset = trim($accountancy_code_depreciation_asset); $object->accountancy_code_depreciation_expense = trim($accountancy_code_depreciation_expense); $object->note = trim($comment); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) $error++; $ret=$object->update($user); if ($ret >= 0 && ! count($object->errors)) { setEventMessages($langs->trans("AssetsTypeModified"), null, 'mesgs'); } else { setEventMessages($object->error, $object->errors, 'errors'); } header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$object->id); exit; } if ($action == 'confirm_delete' && $user->rights->asset->write) { $object->fetch($rowid); $res=$object->delete(); if ($res > 0) { setEventMessages($langs->trans("AssetsTypeDeleted"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { setEventMessages($langs->trans("AssetsTypeCanNotBeDeleted"), null, 'errors'); $action=''; } } /* * View */ $form=new Form($db); $helpurl=''; llxHeader('', $langs->trans("AssetsTypeSetup"), $helpurl); // List of asset type if (! $rowid && $action != 'create' && $action != 'edit') { //dol_fiche_head(''); $sql = "SELECT d.rowid, d.label as label, d.accountancy_code_asset, d.accountancy_code_depreciation_asset, d.accountancy_code_depreciation_expense, d.note"; $sql.= " FROM ".MAIN_DB_PREFIX."asset_type as d"; $sql.= " WHERE d.entity IN (".getEntity('asset_type').")"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $nbtotalofrecords = $num; $i = 0; $param = ''; $newcardbutton=''; if ($user->rights->asset->configurer) { $newcardbutton=''.$langs->trans('NewAssetType').''; $newcardbutton.= ''; $newcardbutton.= ''; } print '
'; if ($optioncss != '') print ''; print ''; print ''; print ''; print ''; print ''; print ''; print_barre_liste($langs->trans("AssetsTypes"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_generic.png', 0, $newcardbutton, '', $limit); $moreforfilter = ''; print '
'; print ''."\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $assettype = new AssetType($db); while ($i < $num) { $objp = $db->fetch_object($result); $assettype->id = $objp->rowid; $assettype->ref = $objp->rowid; $assettype->label = $objp->rowid; print ''; print ''; print ''; print ''; print ''; print ''; if ($user->rights->asset->write) print ''; else print ''; print ""; $i++; } print "
'.$langs->trans("Ref").''.$langs->trans("Label").''.$langs->trans("AccountancyCodeAsset").''.$langs->trans("AccountancyCodeDepreciationAsset").''.$langs->trans("AccountancyCodeDepreciationExpense").' 
'; print $assettype->getNomUrl(1); //'.img_object($langs->trans("ShowType"),'group').' '.$objp->rowid.' print ''.dol_escape_htmltag($objp->label).''; if (! empty($conf->accounting->enabled)) { $accountingaccount = new AccountingAccount($db); $accountingaccount->fetch('', $objp->accountancy_code_asset, 1); print $accountingaccount->getNomUrl(0, 0, 0, '', 0); } else { print $objp->accountancy_code_asset; } print ''; if (! empty($conf->accounting->enabled)) { $accountingaccount2 = new AccountingAccount($db); $accountingaccount2->fetch('', $objp->accountancy_code_depreciation_asset, 1); print $accountingaccount2->getNomUrl(0, 0, 0, '', 0); } else { print $objp->accountancy_code_depreciation_asset; } print ''; if (! empty($conf->accounting->enabled)) { $accountingaccount3 = new AccountingAccount($db); $accountingaccount3->fetch('', $objp->accountancy_code_depreciation_expense, 1); print $accountingaccount3->getNomUrl(0, 0, 0, '', 0); } else { print $objp->accountancy_code_depreciation_expense; } print 'rowid.'">'.img_edit().' 
"; print '
'; print '
'; } else { dol_print_error($db); } } /* ************************************************************************** */ /* */ /* Creation mode */ /* */ /* ************************************************************************** */ if ($action == 'create') { $object = new AssetType($db); if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); print load_fiche_titre($langs->trans("NewAssetType")); print '
'; print ''; print ''; dol_fiche_head(''); print ''; print ''; print ''; if (! empty($conf->accounting->enabled)) { // Accountancy_code_asset print ''; print ''; // Accountancy_code_depreciation_expense print ''; print ''; // Accountancy_code_depreciation_expense print ''; print ''; } else // For external software { // Accountancy_code_asset print ''; print ''; // Accountancy_code_depreciation_asset print ''; print ''; // Accountancy_code_depreciation_expense print ''; print ''; } print ''; // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $act, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } print ''; print "
'.$langs->trans("Label").'
'.$langs->trans("AccountancyCodeAsset").''; print $formaccounting->select_account($object->accountancy_code_asset, 'accountancy_code_asset', 1, '', 1, 1); print '
'.$langs->trans("AccountancyCodeDepreciationAsset").''; print $formaccounting->select_account($object->accountancy_code_depreciation_asset, 'accountancy_code_depreciation_asset', 1, '', 1, 1); print '
'.$langs->trans("AccountancyCodeDepreciationExpense").''; print $formaccounting->select_account($object->accountancy_code_depreciation_expense, 'accountancy_code_depreciation_expense', 1, '', 1, 1); print '
'.$langs->trans("AccountancyCodeAsset").''; print '
'.$langs->trans("AccountancyCodeDepreciationAsset").''; print '
'.$langs->trans("AccountancyCodeDepreciationExpense").''; print '
'.$langs->trans("Description").''; print '
\n"; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print "
\n"; } /* ************************************************************************** */ /* */ /* View mode */ /* */ /* ************************************************************************** */ if ($rowid > 0) { if ($action != 'edit') { $object = new AssetType($db); $object->fetch($rowid); $object->fetch_optionals(); /* * Confirmation suppression */ if ($action == 'delete') { print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".$object->id, $langs->trans("DeleteAnAssetType"), $langs->trans("ConfirmDeleteAssetType", $object->label), "confirm_delete", '', 0, 1); } $head = asset_type_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("AssetType"), -1, 'setup'); $linkback = ''.$langs->trans("BackToList").''; $morehtmlref='
'; // Ref asset type $morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->asset->write, 'string', '', 0, 1); $morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, $user->rights->asset->write, 'string', '', null, null, '', 1); $morehtmlref.='
'; dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '"; // Other attributes include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print '
'; print $langs->trans("AccountancyCodeAsset"); print ''; if (! empty($conf->accounting->enabled)) { $accountingaccount = new AccountingAccount($db); $accountingaccount->fetch('', $object->accountancy_code_asset, 1); print $accountingaccount->getNomUrl(0, 1, 1, '', 1); } else { print $object->accountancy_code_asset; } print '
'; print $langs->trans("AccountancyCodeDepreciationAsset"); print ''; if (! empty($conf->accounting->enabled)) { $accountingaccount2 = new AccountingAccount($db); $accountingaccount2->fetch('', $object->accountancy_code_depreciation_asset, 1); print $accountingaccount2->getNomUrl(0, 1, 1, '', 1); } else { print $object->accountancy_code_depreciation_asset; } print '
'; print $langs->trans("AccountancyCodeDepreciationExpense"); print ''; if (! empty($conf->accounting->enabled)) { $accountingaccount3 = new AccountingAccount($db); $accountingaccount3->fetch('', $object->accountancy_code_depreciation_expense, 1); print $accountingaccount3->getNomUrl(0, 1, 1, '', 1); } else { print $object->accountancy_code_depreciation_expense; } print '
'.$langs->trans("Description").''; print nl2br($object->note)."
'; print '
'; dol_fiche_end(); /* * Buttons */ print '
'; // Edit if ($user->rights->asset->write) { print ''; } // Delete if ($user->rights->asset->write) { print ''; } print "
"; } /* ************************************************************************** */ /* */ /* Edition mode */ /* */ /* ************************************************************************** */ if ($action == 'edit') { $object = new AssetType($db); $object->fetch($rowid); $object->fetch_optionals(); if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); $head = asset_type_prepare_head($object); print '
'; print ''; print ''; print ''; dol_fiche_head($head, 'card', $langs->trans("AssetsType"), -1, 'setup'); print ''; print ''; print ''; if (! empty($conf->accounting->enabled)) { // Accountancy_code_asset print ''; print ''; // Accountancy_code_depreciation_expense print ''; print ''; // Accountancy_code_depreciation_expense print ''; print ''; } else // For external software { // Accountancy_code_asset print ''; print ''; // Accountancy_code_depreciation_asset print ''; print ''; // Accountancy_code_depreciation_expense print ''; print ''; } print ''; // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $act, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit'); } print '
'.$langs->trans("Ref").''.$object->id.'
'.$langs->trans("Label").'
'.$langs->trans("AccountancyCodeAsset").''; print $formaccounting->select_account($object->accountancy_code_asset, 'accountancy_code_asset', 1, '', 1, 1); print '
'.$langs->trans("AccountancyCodeDepreciationAsset").''; print $formaccounting->select_account($object->accountancy_code_depreciation_asset, 'accountancy_code_depreciation_asset', 1, '', 1, 1); print '
'.$langs->trans("AccountancyCodeDepreciationExpense").''; print $formaccounting->select_account($object->accountancy_code_depreciation_expense, 'accountancy_code_depreciation_expense', 1, '', 1, 1); print '
'.$langs->trans("AccountancyCodeAsset").''; print '
'.$langs->trans("AccountancyCodeDepreciationAsset").''; print '
'.$langs->trans("AccountancyCodeDepreciationExpense").''; print '
'.$langs->trans("Description").''; print '
'; // Extra field if (empty($reshook)) { print '

'; foreach($extrafields->attribute_label as $key=>$label) { if (isset($_POST["options_" . $key])) { if (is_array($_POST["options_" . $key])) { // $_POST["options"] is an array but following code expects a comma separated string $value = implode(",", $_POST["options_" . $key]); } else { $value = $_POST["options_" . $key]; } } else { $value = $adht->array_options["options_" . $key]; } print '\n"; } print '
'.$label.''; print $extrafields->showInputField($key, $value); print "


'; } dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print "
"; } } // End of page llxFooter(); $db->close();