2018-04-02 06:22:26 +00:00
< ? php
2019-01-28 20:39:22 +00:00
/* Copyright ( C ) 2018 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2018-04-02 06:22:26 +00:00
*
* 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
2019-09-23 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-04-02 06:22:26 +00:00
*/
/**
2018-04-29 17:52:14 +00:00
* \file htdocs / asset / type . php
* \ingroup asset
2018-04-05 18:40:41 +00:00
* \brief Asset ' s type setup
2018-04-02 06:22:26 +00:00
*/
require '../main.inc.php' ;
2018-04-29 17:52:14 +00:00
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' ;
2018-04-02 06:22:26 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2019-11-13 18:35:02 +00:00
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' ;
2018-04-02 06:22:26 +00:00
2018-05-26 16:41:16 +00:00
// Load translation files required by the page
2018-04-05 18:40:41 +00:00
$langs -> load ( " assets " );
2018-04-02 06:22:26 +00:00
2019-01-27 10:55:16 +00:00
$rowid = GETPOST ( 'rowid' , 'int' );
$action = GETPOST ( 'action' , 'alpha' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
2018-04-02 06:22:26 +00:00
2019-01-27 10:55:16 +00:00
$type = GETPOST ( 'type' , 'alpha' );
2018-04-02 06:22:26 +00:00
2019-11-13 18:35:02 +00:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2019-01-27 10:55:16 +00:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2020-03-13 12:07:11 +00:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2018-04-02 06:22:26 +00:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2019-11-13 18:35:02 +00:00
$offset = $limit * $page ;
2018-04-02 06:22:26 +00:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2019-11-13 18:35:02 +00:00
if ( ! $sortorder ) { $sortorder = " DESC " ; }
if ( ! $sortfield ) { $sortfield = " a.label " ; }
2018-04-02 06:22:26 +00:00
2019-11-13 18:35:02 +00:00
$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' );
2018-04-02 06:22:26 +00:00
// Security check
2019-11-13 18:35:02 +00:00
$result = restrictedArea ( $user , 'asset' , $rowid , 'asset_type' );
2018-04-02 06:22:26 +00:00
2018-04-06 04:04:03 +00:00
$object = new AssetType ( $db );
2018-04-02 06:22:26 +00:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 12:41:52 +00:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2018-04-02 06:22:26 +00:00
2019-01-27 10:55:16 +00:00
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
2018-04-02 06:22:26 +00:00
{
2019-11-13 18:35:02 +00:00
$type = " " ;
$sall = " " ;
2018-04-02 06:22:26 +00:00
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-13 18:35:02 +00:00
$hookmanager -> initHooks ( array ( 'assettypecard' , 'globalcard' ));
2018-04-02 06:22:26 +00:00
/*
* Actions
*/
if ( $cancel ) {
2019-11-13 18:35:02 +00:00
$action = '' ;
2018-04-02 06:22:26 +00:00
2019-11-13 18:35:02 +00:00
if ( ! empty ( $backtopage ))
2018-04-02 06:22:26 +00:00
{
header ( " Location: " . $backtopage );
exit ;
}
}
2018-04-29 17:52:14 +00:00
if ( $action == 'add' && $user -> rights -> asset -> write )
2018-04-02 06:22:26 +00:00
{
2019-11-13 18:35:02 +00:00
$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 );
2018-04-02 06:22:26 +00:00
// Fill array 'array_options' with data from add form
2019-10-06 12:41:52 +00:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2018-04-02 06:22:26 +00:00
if ( $ret < 0 ) $error ++ ;
if ( empty ( $object -> label )) {
$error ++ ;
2019-01-27 10:55:16 +00:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Label " )), null , 'errors' );
2018-04-02 06:22:26 +00:00
}
else {
2018-04-06 04:04:03 +00:00
$sql = " SELECT label FROM " . MAIN_DB_PREFIX . " asset_type WHERE label=' " . $db -> escape ( $object -> label ) . " ' " ;
2018-04-02 06:22:26 +00:00
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ( $result );
}
if ( $num ) {
$error ++ ;
$langs -> load ( " errors " );
2019-01-27 10:55:16 +00:00
setEventMessages ( $langs -> trans ( " ErrorLabelAlreadyExists " , $login ), null , 'errors' );
2018-04-02 06:22:26 +00:00
}
}
2019-11-13 18:35:02 +00:00
if ( ! $error )
2018-04-02 06:22:26 +00:00
{
2019-11-13 18:35:02 +00:00
$id = $object -> create ( $user );
2018-04-02 06:22:26 +00:00
if ( $id > 0 )
{
header ( " Location: " . $_SERVER [ " PHP_SELF " ]);
exit ;
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'create' ;
}
}
else
{
$action = 'create' ;
}
}
2018-04-29 17:52:14 +00:00
if ( $action == 'update' && $user -> rights -> asset -> write )
2018-04-02 06:22:26 +00:00
{
$object -> fetch ( $rowid );
$object -> oldcopy = clone $object ;
2019-11-13 18:35:02 +00:00
$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 );
2018-04-02 06:22:26 +00:00
// Fill array 'array_options' with data from add form
2019-10-06 12:41:52 +00:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2018-04-02 06:22:26 +00:00
if ( $ret < 0 ) $error ++ ;
2019-11-13 18:35:02 +00:00
$ret = $object -> update ( $user );
2018-04-02 06:22:26 +00:00
2019-11-13 18:35:02 +00:00
if ( $ret >= 0 && ! count ( $object -> errors ))
2018-04-02 06:22:26 +00:00
{
2018-04-05 18:40:41 +00:00
setEventMessages ( $langs -> trans ( " AssetsTypeModified " ), null , 'mesgs' );
2018-04-02 06:22:26 +00:00
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?rowid= " . $object -> id );
exit ;
}
2018-04-29 17:52:14 +00:00
if ( $action == 'confirm_delete' && $user -> rights -> asset -> write )
2018-04-02 06:22:26 +00:00
{
$object -> fetch ( $rowid );
2019-11-13 18:35:02 +00:00
$res = $object -> delete ();
2018-04-02 06:22:26 +00:00
if ( $res > 0 )
{
2018-04-05 18:40:41 +00:00
setEventMessages ( $langs -> trans ( " AssetsTypeDeleted " ), null , 'mesgs' );
2018-04-02 06:22:26 +00:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ]);
exit ;
}
else
{
2018-04-05 18:40:41 +00:00
setEventMessages ( $langs -> trans ( " AssetsTypeCanNotBeDeleted " ), null , 'errors' );
2019-11-13 18:35:02 +00:00
$action = '' ;
2018-04-02 06:22:26 +00:00
}
}
/*
* View
*/
2019-11-13 18:35:02 +00:00
$form = new Form ( $db );
2019-10-02 16:14:41 +00:00
2019-11-13 18:35:02 +00:00
$helpurl = '' ;
2019-01-27 10:55:16 +00:00
llxHeader ( '' , $langs -> trans ( " AssetsTypeSetup " ), $helpurl );
2018-04-02 06:22:26 +00:00
2018-04-06 04:04:03 +00:00
// List of asset type
2019-11-13 18:35:02 +00:00
if ( ! $rowid && $action != 'create' && $action != 'edit' )
2018-04-02 06:22:26 +00:00
{
//dol_fiche_head('');
2018-04-05 18:40:41 +00:00
$sql = " SELECT d.rowid, d.label as label, d.accountancy_code_asset, d.accountancy_code_depreciation_asset, d.accountancy_code_depreciation_expense, d.note " ;
2019-11-13 18:35:02 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " asset_type as d " ;
$sql .= " WHERE d.entity IN ( " . getEntity ( 'asset_type' ) . " ) " ;
2018-04-02 06:22:26 +00:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
$nbtotalofrecords = $num ;
$i = 0 ;
$param = '' ;
2019-11-13 18:35:02 +00:00
$newcardbutton = '' ;
2019-04-18 12:13:48 +00:00
if ( $user -> rights -> asset -> configurer )
{
2019-11-13 18:35:02 +00:00
$newcardbutton = '<a class="butActionNew" href="' . DOL_URL_ROOT . '/asset/type.php?action=create"><span class="valignmiddle text-plus-circle">' . $langs -> trans ( 'NewAssetType' ) . '</span>' ;
$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>' ;
$newcardbutton .= '</a>' ;
2019-04-18 12:13:48 +00:00
}
2018-04-02 06:22:26 +00:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
2019-12-18 22:12:31 +00:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-04-02 06:22:26 +00:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
2018-04-06 04:04:03 +00:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2018-04-02 06:22:26 +00:00
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
2019-10-02 16:14:41 +00:00
print_barre_liste ( $langs -> trans ( " AssetsTypes " ), $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $nbtotalofrecords , 'accountancy' , 0 , $newcardbutton , '' , $limit );
2018-04-02 06:22:26 +00:00
$moreforfilter = '' ;
print '<div class="div-table-responsive">' ;
2019-11-13 18:35:02 +00:00
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2018-04-02 06:22:26 +00:00
print '<tr class="liste_titre">' ;
print '<th>' . $langs -> trans ( " Ref " ) . '</th>' ;
print '<th>' . $langs -> trans ( " Label " ) . '</th>' ;
2018-05-11 19:48:22 +00:00
print '<th align="center">' . $langs -> trans ( " AccountancyCodeAsset " ) . '</th>' ;
print '<th align="center">' . $langs -> trans ( " AccountancyCodeDepreciationAsset " ) . '</th>' ;
print '<th align="center">' . $langs -> trans ( " AccountancyCodeDepreciationExpense " ) . '</th>' ;
2018-04-02 06:22:26 +00:00
print '<th> </th>' ;
print " </tr> \n " ;
2018-04-06 04:04:03 +00:00
$assettype = new AssetType ( $db );
2018-04-02 06:22:26 +00:00
while ( $i < $num )
{
$objp = $db -> fetch_object ( $result );
2018-04-06 04:04:03 +00:00
$assettype -> id = $objp -> rowid ;
$assettype -> ref = $objp -> rowid ;
$assettype -> label = $objp -> rowid ;
2018-04-02 06:22:26 +00:00
print '<tr class="oddeven">' ;
print '<td>' ;
2018-04-06 04:04:03 +00:00
print $assettype -> getNomUrl ( 1 );
2018-04-02 06:22:26 +00:00
//<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$objp->rowid.'">'.img_object($langs->trans("ShowType"),'group').' '.$objp->rowid.'</a>
print '</td>' ;
print '<td>' . dol_escape_htmltag ( $objp -> label ) . '</td>' ;
2018-05-11 19:48:22 +00:00
2018-11-01 21:32:33 +00:00
print '<td class="center">' ;
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled ))
2018-05-11 19:48:22 +00:00
{
$accountingaccount = new AccountingAccount ( $db );
2019-01-27 10:55:16 +00:00
$accountingaccount -> fetch ( '' , $objp -> accountancy_code_asset , 1 );
2018-05-11 19:48:22 +00:00
2019-01-27 10:55:16 +00:00
print $accountingaccount -> getNomUrl ( 0 , 0 , 0 , '' , 0 );
2018-05-11 19:48:22 +00:00
} else {
2018-11-01 21:32:33 +00:00
print $objp -> accountancy_code_asset ;
2018-05-11 19:48:22 +00:00
}
print '</td>' ;
2018-11-01 21:32:33 +00:00
print '<td class="center">' ;
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled ))
2018-05-11 19:48:22 +00:00
{
$accountingaccount2 = new AccountingAccount ( $db );
2019-01-27 10:55:16 +00:00
$accountingaccount2 -> fetch ( '' , $objp -> accountancy_code_depreciation_asset , 1 );
2018-05-11 19:48:22 +00:00
2019-01-27 10:55:16 +00:00
print $accountingaccount2 -> getNomUrl ( 0 , 0 , 0 , '' , 0 );
2018-05-11 19:48:22 +00:00
} else {
2018-11-01 21:32:33 +00:00
print $objp -> accountancy_code_depreciation_asset ;
2018-05-11 19:48:22 +00:00
}
print '</td>' ;
2018-11-01 21:32:33 +00:00
print '<td class="center">' ;
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled ))
2018-05-11 19:48:22 +00:00
{
$accountingaccount3 = new AccountingAccount ( $db );
2019-01-27 10:55:16 +00:00
$accountingaccount3 -> fetch ( '' , $objp -> accountancy_code_depreciation_expense , 1 );
2018-05-11 19:48:22 +00:00
2019-01-27 10:55:16 +00:00
print $accountingaccount3 -> getNomUrl ( 0 , 0 , 0 , '' , 0 );
2018-05-11 19:48:22 +00:00
} else {
2018-11-01 21:32:33 +00:00
print $objp -> accountancy_code_depreciation_expense ;
2018-05-11 19:48:22 +00:00
}
print '</td>' ;
if ( $user -> rights -> asset -> write )
2019-01-22 12:54:04 +00:00
print '<td class="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit&rowid=' . $objp -> rowid . '">' . img_edit () . '</a></td>' ;
2018-04-02 06:22:26 +00:00
else
2019-01-22 12:54:04 +00:00
print '<td class="right"> </td>' ;
2018-04-02 06:22:26 +00:00
print " </tr> " ;
$i ++ ;
}
print " </table> " ;
print '</div>' ;
print '</form>' ;
}
else
{
dol_print_error ( $db );
}
}
/* ************************************************************************** */
/* */
/* Creation mode */
/* */
/* ************************************************************************** */
if ( $action == 'create' )
{
2018-04-29 17:52:14 +00:00
$object = new AssetType ( $db );
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled )) $formaccounting = new FormAccounting ( $db );
2018-04-02 06:22:26 +00:00
2018-05-11 19:48:22 +00:00
print load_fiche_titre ( $langs -> trans ( " NewAssetType " ));
2018-04-02 06:22:26 +00:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '" method="POST">' ;
2019-12-18 22:12:31 +00:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-04-02 06:22:26 +00:00
print '<input type="hidden" name="action" value="add">' ;
2018-04-06 04:04:03 +00:00
dol_fiche_head ( '' );
2018-04-02 06:22:26 +00:00
2019-11-05 20:24:41 +00:00
print '<table class="border centpercent">' ;
2018-04-02 06:22:26 +00:00
print '<tbody>' ;
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( " Label " ) . '</td><td><input type="text" name="label" size="40"></td></tr>' ;
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled ))
2018-05-11 19:48:22 +00:00
{
// Accountancy_code_asset
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeAsset " ) . '</td>' ;
print '<td>' ;
print $formaccounting -> select_account ( $object -> accountancy_code_asset , 'accountancy_code_asset' , 1 , '' , 1 , 1 );
print '</td></tr>' ;
// Accountancy_code_depreciation_expense
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeDepreciationAsset " ) . '</td>' ;
print '<td>' ;
print $formaccounting -> select_account ( $object -> accountancy_code_depreciation_asset , 'accountancy_code_depreciation_asset' , 1 , '' , 1 , 1 );
print '</td></tr>' ;
// Accountancy_code_depreciation_expense
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeDepreciationExpense " ) . '</td>' ;
print '<td>' ;
print $formaccounting -> select_account ( $object -> accountancy_code_depreciation_expense , 'accountancy_code_depreciation_expense' , 1 , '' , 1 , 1 );
print '</td></tr>' ;
}
else // For external software
{
// Accountancy_code_asset
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeAsset " ) . '</td>' ;
print '<td><input name="accountancy_code_asset" class="maxwidth200" value="' . $object -> accountancy_code_asset . '">' ;
print '</td></tr>' ;
2018-04-02 06:22:26 +00:00
2018-05-11 19:48:22 +00:00
// Accountancy_code_depreciation_asset
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeDepreciationAsset " ) . '</td>' ;
print '<td><input name="accountancy_code_depreciation_asset" class="maxwidth200" value="' . $object -> accountancy_code_depreciation_asset . '">' ;
print '</td></tr>' ;
// Accountancy_code_depreciation_expense
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeDepreciationExpense " ) . '</td>' ;
print '<td><input name="accountancy_code_depreciation_expense" class="maxwidth200" value="' . $object -> accountancy_code_depreciation_expense . '">' ;
print '</td></tr>' ;
}
2018-04-02 06:22:26 +00:00
print '<tr><td class="tdtop">' . $langs -> trans ( " Description " ) . '</td><td>' ;
print '<textarea name="comment" wrap="soft" class="centpercent" rows="3"></textarea></td></tr>' ;
// Other attributes
2019-11-13 18:35:02 +00:00
$parameters = array ();
2019-11-16 13:38:05 +00:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2018-04-06 04:04:03 +00:00
print $hookmanager -> resPrint ;
2018-04-13 11:28:48 +00:00
if ( empty ( $reshook ))
2018-04-02 06:22:26 +00:00
{
2019-11-16 13:38:05 +00:00
print $object -> showOptionals ( $extrafields , 'edit' , $parameters );
2018-04-02 06:22:26 +00:00
}
print '<tbody>' ;
print " </table> \n " ;
dol_fiche_end ();
print '<div class="center">' ;
print '<input type="submit" name="button" class="button" value="' . $langs -> trans ( " Add " ) . '">' ;
print ' ' ;
print '<input type="submit" name="cancel" class="button" value="' . $langs -> trans ( " Cancel " ) . '" onclick="history.go(-1)" />' ;
print '</div>' ;
print " </form> \n " ;
}
/* ************************************************************************** */
/* */
/* View mode */
/* */
/* ************************************************************************** */
if ( $rowid > 0 )
{
if ( $action != 'edit' )
{
2018-04-29 17:52:14 +00:00
$object = new AssetType ( $db );
2018-04-02 06:22:26 +00:00
$object -> fetch ( $rowid );
$object -> fetch_optionals ();
/*
* Confirmation suppression
*/
if ( $action == 'delete' )
{
2019-01-27 10:55:16 +00:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?rowid= " . $object -> id , $langs -> trans ( " DeleteAnAssetType " ), $langs -> trans ( " ConfirmDeleteAssetType " , $object -> label ), " confirm_delete " , '' , 0 , 1 );
2018-04-02 06:22:26 +00:00
}
2018-05-11 19:48:22 +00:00
$head = asset_type_prepare_head ( $object );
2018-04-02 06:22:26 +00:00
2018-05-11 19:48:22 +00:00
dol_fiche_head ( $head , 'card' , $langs -> trans ( " AssetType " ), - 1 , 'setup' );
2018-04-02 06:22:26 +00:00
2018-04-29 17:52:14 +00:00
$linkback = '<a href="' . DOL_URL_ROOT . '/asset/type.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2018-04-02 06:22:26 +00:00
2019-11-13 18:35:02 +00:00
$morehtmlref = '<div class="refidno">' ;
2018-11-01 21:32:33 +00:00
// Ref asset type
2019-11-13 18:35:02 +00:00
$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 .= '</div>' ;
2018-11-01 21:32:33 +00:00
dol_banner_tab ( $object , 'rowid' , $linkback , 1 , 'rowid' , 'ref' , $morehtmlref , '' , 0 , '' , $morehtmlright );
2018-04-02 06:22:26 +00:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2019-11-05 20:24:41 +00:00
print '<table class="border centpercent">' ;
2018-04-02 06:22:26 +00:00
2018-11-01 21:32:33 +00:00
print '<tr>' ;
print '<td class="nowrap">' ;
print $langs -> trans ( " AccountancyCodeAsset " );
print '</td><td>' ;
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled ))
2018-05-11 19:48:22 +00:00
{
$accountingaccount = new AccountingAccount ( $db );
2019-01-27 10:55:16 +00:00
$accountingaccount -> fetch ( '' , $object -> accountancy_code_asset , 1 );
2018-05-11 19:48:22 +00:00
2019-01-27 10:55:16 +00:00
print $accountingaccount -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2018-05-11 19:48:22 +00:00
} else {
print $object -> accountancy_code_asset ;
}
print '</td>' ;
2018-11-01 21:32:33 +00:00
print '</tr>' ;
2018-05-11 19:48:22 +00:00
2018-11-01 21:32:33 +00:00
print '<tr>' ;
print '<td class="nowrap">' ;
print $langs -> trans ( " AccountancyCodeDepreciationAsset " );
print '</td><td>' ;
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled ))
2018-05-11 19:48:22 +00:00
{
$accountingaccount2 = new AccountingAccount ( $db );
2019-01-27 10:55:16 +00:00
$accountingaccount2 -> fetch ( '' , $object -> accountancy_code_depreciation_asset , 1 );
2018-05-11 19:48:22 +00:00
2019-01-27 10:55:16 +00:00
print $accountingaccount2 -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2018-05-11 19:48:22 +00:00
} else {
print $object -> accountancy_code_depreciation_asset ;
}
print '</td>' ;
2018-11-01 21:32:33 +00:00
print '</tr>' ;
2018-05-11 19:48:22 +00:00
2018-11-01 21:32:33 +00:00
print '<tr>' ;
print '<td class="nowrap">' ;
print $langs -> trans ( " AccountancyCodeDepreciationExpense " );
print '</td><td>' ;
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled ))
2018-05-11 19:48:22 +00:00
{
$accountingaccount3 = new AccountingAccount ( $db );
2019-01-27 10:55:16 +00:00
$accountingaccount3 -> fetch ( '' , $object -> accountancy_code_depreciation_expense , 1 );
2018-04-02 06:22:26 +00:00
2019-01-27 10:55:16 +00:00
print $accountingaccount3 -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2018-05-11 19:48:22 +00:00
} else {
print $object -> accountancy_code_depreciation_expense ;
}
2018-11-01 21:32:33 +00:00
print '</td>' ;
2018-04-02 06:22:26 +00:00
print '</tr>' ;
print '<tr><td class="tdtop">' . $langs -> trans ( " Description " ) . '</td><td>' ;
print nl2br ( $object -> note ) . " </td></tr> " ;
// Other attributes
2019-11-13 18:35:02 +00:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2018-04-02 06:22:26 +00:00
print '</table>' ;
print '</div>' ;
dol_fiche_end ();
/*
* Buttons
*/
print '<div class="tabsAction">' ;
// Edit
2018-05-13 05:50:24 +00:00
if ( $user -> rights -> asset -> write )
2018-04-02 06:22:26 +00:00
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit&rowid=' . $object -> id . '">' . $langs -> trans ( " Modify " ) . '</a></div>' ;
}
// Delete
2018-05-13 05:50:24 +00:00
if ( $user -> rights -> asset -> write )
2018-04-02 06:22:26 +00:00
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=delete&rowid=' . $object -> id . '">' . $langs -> trans ( " DeleteType " ) . '</a></div>' ;
}
print " </div> " ;
}
/* ************************************************************************** */
/* */
/* Edition mode */
/* */
/* ************************************************************************** */
if ( $action == 'edit' )
{
2018-04-29 17:52:14 +00:00
$object = new AssetType ( $db );
2018-04-02 06:22:26 +00:00
$object -> fetch ( $rowid );
$object -> fetch_optionals ();
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled )) $formaccounting = new FormAccounting ( $db );
2018-04-02 06:22:26 +00:00
2018-05-11 19:48:22 +00:00
$head = asset_type_prepare_head ( $object );
2018-04-02 06:22:26 +00:00
print '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . '?rowid=' . $object -> id . '">' ;
2019-12-18 22:12:31 +00:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-04-02 06:22:26 +00:00
print '<input type="hidden" name="rowid" value="' . $object -> id . '">' ;
print '<input type="hidden" name="action" value="update">' ;
2018-05-11 19:48:22 +00:00
dol_fiche_head ( $head , 'card' , $langs -> trans ( " AssetsType " ), - 1 , 'setup' );
2018-04-02 06:22:26 +00:00
2019-11-05 20:24:41 +00:00
print '<table class="border centpercent">' ;
2018-04-02 06:22:26 +00:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Ref " ) . '</td><td>' . $object -> id . '</td></tr>' ;
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Label " ) . '</td><td><input type="text" name="label" size="40" value="' . dol_escape_htmltag ( $object -> label ) . '"></td></tr>' ;
2019-11-13 18:35:02 +00:00
if ( ! empty ( $conf -> accounting -> enabled ))
2018-05-11 19:48:22 +00:00
{
// Accountancy_code_asset
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeAsset " ) . '</td>' ;
print '<td>' ;
print $formaccounting -> select_account ( $object -> accountancy_code_asset , 'accountancy_code_asset' , 1 , '' , 1 , 1 );
print '</td></tr>' ;
2018-04-02 06:22:26 +00:00
2018-05-11 19:48:22 +00:00
// Accountancy_code_depreciation_expense
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeDepreciationAsset " ) . '</td>' ;
print '<td>' ;
print $formaccounting -> select_account ( $object -> accountancy_code_depreciation_asset , 'accountancy_code_depreciation_asset' , 1 , '' , 1 , 1 );
print '</td></tr>' ;
// Accountancy_code_depreciation_expense
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeDepreciationExpense " ) . '</td>' ;
print '<td>' ;
print $formaccounting -> select_account ( $object -> accountancy_code_depreciation_expense , 'accountancy_code_depreciation_expense' , 1 , '' , 1 , 1 );
print '</td></tr>' ;
}
else // For external software
{
// Accountancy_code_asset
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeAsset " ) . '</td>' ;
print '<td><input name="accountancy_code_asset" class="maxwidth200" value="' . $object -> accountancy_code_asset . '">' ;
print '</td></tr>' ;
// Accountancy_code_depreciation_asset
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeDepreciationAsset " ) . '</td>' ;
print '<td><input name="accountancy_code_depreciation_asset" class="maxwidth200" value="' . $object -> accountancy_code_depreciation_asset . '">' ;
print '</td></tr>' ;
// Accountancy_code_depreciation_expense
print '<tr><td class="titlefield">' . $langs -> trans ( " AccountancyCodeDepreciationExpense " ) . '</td>' ;
print '<td><input name="accountancy_code_depreciation_expense" class="maxwidth200" value="' . $object -> accountancy_code_depreciation_expense . '">' ;
print '</td></tr>' ;
}
2018-04-02 06:22:26 +00:00
print '<tr><td class="tdtop">' . $langs -> trans ( " Description " ) . '</td><td>' ;
print '<textarea name="comment" wrap="soft" class="centpercent" rows="3">' . $object -> note . '</textarea></td></tr>' ;
// Other attributes
2019-11-13 18:35:02 +00:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $act , $action ); // Note that $action and $object may have been modified by hook
2018-04-06 04:04:03 +00:00
print $hookmanager -> resPrint ;
2018-04-13 11:28:48 +00:00
if ( empty ( $reshook ))
2018-04-02 06:22:26 +00:00
{
2019-11-16 13:38:05 +00:00
print $object -> showOptionals ( $extrafields , 'edit' , $parameters );
2018-04-02 06:22:26 +00:00
}
2020-02-16 18:33:58 +00:00
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php' ;
2018-04-02 06:22:26 +00:00
2020-02-16 18:33:58 +00:00
print '</table>' ;
2018-04-02 06:22:26 +00:00
dol_fiche_end ();
2020-02-16 18:33:58 +00:00
print '<div class="center"><input type="submit" class="button" name="save" value="' . $langs -> trans ( " Save " ) . '">' ;
print ' <input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2018-04-02 06:22:26 +00:00
print '</div>' ;
print " </form> " ;
}
}
2018-07-29 09:33:52 +00:00
// End of page
2018-04-02 06:22:26 +00:00
llxFooter ();
$db -> close ();