NEW Asset Module - make asset model creation in a single step (#26982)

* make asset model creation in a single step

* fix test unit issue

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Mohamed DAOUD 2024-02-01 16:26:25 +01:00 committed by GitHub
parent 2877a7dd90
commit a99e44b6c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 231 additions and 95 deletions

View File

@ -27,6 +27,7 @@ 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/assetaccountancycodes.class.php';
require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
// Load translation files required by the page
$langs->loadLangs(array("assets", "companies"));
@ -37,10 +38,12 @@ $ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
// Initialize technical objects
$object = new Asset($db);
$assetaccountancycodes = new AssetAccountancyCodes($db);
$assetdepreciationoptions = new AssetDepreciationOptions($db);
$extrafields = new ExtraFields($db);
$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
$hookmanager->initHooks(array('assetaccountancycodes', 'globalcard')); // Note that conf->hooks_modules contains array
@ -50,7 +53,7 @@ $extrafields->fetch_name_optionals_label($object->table_element);
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1] . "/" . $object->id;
}
$permissiontoadd = $user->hasRight('asset', 'write'); // Used by the include of actions_addupdatedelete.inc.php
@ -65,9 +68,18 @@ if (!isModEnabled('asset')) {
accessforbidden();
}
$result = $assetaccountancycodes->fetchAccountancyCodes($object->id);
if ($result < 0) {
setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors, 'errors');
$object->asset_depreciation_options = &$assetdepreciationoptions;
$object->asset_accountancy_codes = &$assetaccountancycodes;
if (!empty($id)) {
$depreciationoptionserrors = $assetdepreciationoptions->fetchDeprecationOptions($object->id, 0);
$accountancycodeserrors = $assetaccountancycodes->fetchAccountancyCodes($object->id, 0);
if ($depreciationoptionserrors < 0) {
setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
}
if ($accountancycodeserrors < 0) {
setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors, 'errors');
}
}

View File

@ -166,6 +166,7 @@ class Asset extends CommonObject
* @var AssetDepreciationOptions Used for computed fields of depreciation options class.
*/
public $asset_depreciation_options;
public $asset_accountancy_codes;
/**
* @var array List of depreciation lines for each mode (sort by depreciation date).
*/

View File

@ -47,7 +47,7 @@ class AssetAccountancyCodes extends CommonObject
'receivable_on_assignment' => array('label' => 'AssetAccountancyCodeReceivableOnAssignment'),
'proceeds_from_sales' => array('label' => 'AssetAccountancyCodeProceedsFromSales'),
'vat_collected' => array('label' => 'AssetAccountancyCodeVatCollected'),
'vat_deductible' => array('label' => 'AssetAccountancyCodeVatDeductible'),
'vat_deductible' => array('label' => 'AssetAccountancyCodeVatDeductible','column_break' => true),
),
),
'accelerated_depreciation' => array(

View File

@ -114,6 +114,12 @@ class AssetDepreciationOptions extends CommonObject
*/
public $deprecation_options = array();
public $depreciation_type;
public $degressive_coefficient;
public $duration;
public $duration_type;
public $accelerated_depreciation_option;
/**
* Constructor
*
@ -165,12 +171,12 @@ class AssetDepreciationOptions extends CommonObject
// Unset required option (notnull) if field disabled
if (!empty($field_info['enabled_field'])) {
$info = explode(':', $field_info['enabled_field']);
if ($this->deprecation_options[$info[0]][$info[1]] != $info[2] && isset($this->fields[$field_key]['notnull'])) {
if (!empty($this->deprecation_options[$info[0]][$info[1]]) && $this->deprecation_options[$info[0]][$info[1]] != $info[2] && isset($this->fields[$field_key]['notnull'])) {
unset($this->fields[$field_key]['notnull']);
}
}
// Set value of the field in the object (for createCommon and setDeprecationOptionsFromPost functions)
$this->{$field_key} = $this->deprecation_options[$mode][$field_key];
$this->{$field_key} = $this->deprecation_options[$mode][$field_key] ?? null;
}
$this->fields['rowid'] = array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id");
@ -358,7 +364,7 @@ class AssetDepreciationOptions extends CommonObject
foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
if (!empty($mode_info['enabled_field'])) {
$info = explode(':', $mode_info['enabled_field']);
if ($deprecation_options[$info[0]][$info[1]] != $info[2]) {
if (isset($deprecation_options[$info[0]][$info[1]]) && $deprecation_options[$info[0]][$info[1]] != $info[2]) {
unset($deprecation_options[$info[0]][$info[1]]);
}
}
@ -527,8 +533,8 @@ class AssetDepreciationOptions extends CommonObject
*/
public function getRate($mode)
{
$duration = $this->deprecation_options[$mode]["duration"] > 0 ? $this->deprecation_options[$mode]["duration"] : 0;
$duration_type = $this->deprecation_options[$mode]["duration_type"] > 0 ? $this->deprecation_options[$mode]["duration_type"] : 0;
$duration = (isset($this->deprecation_options[$mode]["duration"]) && $this->deprecation_options[$mode]["duration"] > 0) ? $this->deprecation_options[$mode]["duration"] : 0;
$duration_type = (isset($this->deprecation_options[$mode]["duration_type"]) && $this->deprecation_options[$mode]["duration_type"] > 0) ? $this->deprecation_options[$mode]["duration_type"] : 0;
return price(price2num($duration > 0 ? (100 * ($duration_type == 1 ? 12 : 1) / $duration) : 0, 2));
}

View File

@ -112,7 +112,7 @@ class AssetModel extends CommonObject
'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'default'=>'0', 'visible'=>2, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Enabled', '9'=>'Disabled'), 'validate'=>'1',),
'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'default'=>'1', 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Enabled', '9'=>'Disabled'), 'validate'=>'1',),
);
public $rowid;
public $ref;
@ -129,6 +129,7 @@ class AssetModel extends CommonObject
public $model_pdf;
public $status;
public $asset_depreciation_options;
public $asset_accountancy_codes;
// /**
// * @var string Field with ID of parent key if this object has a parent
@ -194,6 +195,16 @@ class AssetModel extends CommonObject
{
$resultcreate = $this->createCommon($user, $notrigger);
if ($resultcreate > 0 && !empty($this->asset_depreciation_options)) {
$this->asset_depreciation_options->setDeprecationOptionsFromPost(1);
$this->asset_depreciation_options->updateDeprecationOptions($user, 0, $resultcreate);
}
if ($resultcreate > 0 && !empty($this->asset_accountancy_codes)) {
$this->asset_accountancy_codes->setAccountancyCodesFromPost();
$this->asset_accountancy_codes->updateAccountancyCodes($user, 0, $resultcreate);
}
return $resultcreate;
}
@ -414,7 +425,19 @@ class AssetModel extends CommonObject
*/
public function update(User $user, $notrigger = 0)
{
return $this->updateCommon($user, $notrigger);
$resultupdate = $this->updateCommon($user, $notrigger);
if ($resultupdate > 0 && !empty($this->asset_depreciation_options)) {
$this->asset_depreciation_options->setDeprecationOptionsFromPost(1);
$this->asset_depreciation_options->updateDeprecationOptions($user, 0, $resultupdate);
}
if ($resultupdate > 0 && !empty($this->asset_accountancy_codes)) {
$this->asset_accountancy_codes->setAccountancyCodesFromPost();
$this->asset_accountancy_codes->updateAccountancyCodes($user, 0, $resultupdate);
}
return $resultupdate;
}
/**

View File

@ -37,6 +37,7 @@ $ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
// Initialize technical objects
$object = new Asset($db);
@ -50,7 +51,7 @@ $extrafields->fetch_name_optionals_label($object->table_element);
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1] . "/" . $object->id;
}
$permissiontoadd = $user->hasRight('asset', 'write'); // Used by the include of actions_addupdatedelete.inc.php

View File

@ -50,7 +50,7 @@ $extrafields->fetch_name_optionals_label($object->table_element);
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1] . "/" . $object->id;
}
$permissiontoread = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'read')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'read')));

View File

@ -79,7 +79,7 @@ $extrafields->fetch_name_optionals_label($object->table_element);
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->asset->multidir_output[$object->entity] . "/model/" . $object->id;
$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1] . "/model/" . $object->id;
}
$permissiontoread = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'read')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'read')));

View File

@ -28,6 +28,8 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
require_once DOL_DOCUMENT_ROOT . '/asset/class/assetaccountancycodes.class.php';
// Load translation files required by the page
$langs->loadLangs(array("assets", "other"));
@ -44,6 +46,8 @@ $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
// Initialize technical objects
$object = new AssetModel($db);
$assetdepreciationoptions = new AssetDepreciationOptions($db);
$assetaccountancycodes = new AssetAccountancyCodes($db);
$extrafields = new ExtraFields($db);
$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
$hookmanager->initHooks(array('assetmodelcard', 'globalcard')); // Note that conf->hooks_modules contains array
@ -92,6 +96,20 @@ if (!$permissiontoread) {
accessforbidden();
}
// Model depreciation options and accountancy codes
$object->asset_depreciation_options = &$assetdepreciationoptions;
$object->asset_accountancy_codes = &$assetaccountancycodes;
if (!empty($id)) {
$depreciationoptionserrors = $assetdepreciationoptions->fetchDeprecationOptions(0, $object->id);
$accountancycodeserrors = $assetaccountancycodes->fetchAccountancyCodes(0, $object->id);
if ($depreciationoptionserrors < 0) {
setEventMessages($assetdepreciationoptions->error, $assetdepreciationoptions->errors, 'errors');
}
if ($accountancycodeserrors < 0) {
setEventMessages($assetaccountancycodes->error, $assetaccountancycodes->errors, 'errors');
}
}
/*
* Actions
@ -173,6 +191,14 @@ if ($action == 'create') {
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
// Depreciation options
include DOL_DOCUMENT_ROOT . '/asset/tpl/depreciation_options_edit.tpl.php';
// Accountancy codes
print '<div class="clearboth"></div>';
print '<hr>';
include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_edit.tpl.php';
print '</table>' . "\n";
print dol_get_fiche_end();
@ -209,6 +235,14 @@ if (($id || $ref) && $action == 'edit') {
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
// Depreciation options
include DOL_DOCUMENT_ROOT . '/asset/tpl/depreciation_options_edit.tpl.php';
// Accountancy codes
print '<div class="clearboth"></div>';
print '<hr>';
include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_edit.tpl.php';
print '</table>';
print dol_get_fiche_end();
@ -262,20 +296,111 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">' . "\n";
// Common attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
$object->fields = dol_sort_array($object->fields, 'position');
foreach ($object->fields as $key => $val) {
if (!empty($keyforbreak) && $key == $keyforbreak) {
break; // key used for break on second column
}
// Discard if extrafield is a hidden field on form
if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
continue;
}
if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
continue; // We don't want this field
}
if (in_array($key, array('ref', 'status'))) {
continue; // Ref and status are already in dol_banner
}
$value = $object->$key;
print '<tr class="field_'.$key.'"><td';
print ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
//if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired on the view output
if ($val['type'] == 'text' || $val['type'] == 'html') {
print ' tdtop';
}
print '">';
$labeltoshow = '';
if (!empty($val['help'])) {
$labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
} else {
if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
$labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
} else {
$labeltoshow .= $langs->trans($val['label']);
}
}
if (empty($val['alwayseditable'])) {
print $labeltoshow;
} else {
print $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
}
print '</td>';
print '<td class="valuefield fieldname_'.$key;
if ($val['type'] == 'text') {
print ' wordbreak';
}
if (!empty($val['cssview'])) {
print ' '.$val['cssview'];
}
print '">';
if (empty($val['alwayseditable'])) {
if (preg_match('/^(text|html)/', $val['type'])) {
print '<div class="longmessagecut">';
}
if ($key == 'lang') {
$langs->load("languages");
$labellang = ($value ? $langs->trans('Language_'.$value) : '');
print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
print $labellang;
} else {
if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
$out = $object->showOutputField($val, $key, $value, '', '', '', 0);
print showValueWithClipboardCPButton($out, 0, $out);
} else {
print $object->showOutputField($val, $key, $value, '', '', '', 0);
}
}
//print dol_escape_htmltag($object->$key, 1, 1);
if (preg_match('/^(text|html)/', $val['type'])) {
print '</div>';
}
} else {
print $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
}
print '</td>';
print '</tr>';
}
// Other attributes. Fields from hook formObjectOptions and Extrafields.
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '</table>';
// Depreciation options attributes
print '<div class="fichehalfleft">';
print '<table class="border centpercent tableforfield">';
include DOL_DOCUMENT_ROOT . '/asset/tpl/depreciation_options_view.tpl.php';
print '</table>';
print '</div>';
// Accountancy codes attributes
print '<div class="fichehalfright">';
print '<table class="border centpercent tableforfield">';
include DOL_DOCUMENT_ROOT . '/asset/tpl/accountancy_codes_view.tpl.php';
print '</table>';
print '</div>';
print '</div>';
print '<div class="clearboth"></div>';
print dol_get_fiche_end();

View File

@ -37,6 +37,7 @@ $ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
// Initialize technical objects
$object = new AssetModel($db);
@ -50,7 +51,7 @@ $extrafields->fetch_name_optionals_label($object->table_element);
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1] . "/" . $object->id;
}
$permissiontoread = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'read')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'read')));

View File

@ -48,7 +48,7 @@ $extrafields->fetch_name_optionals_label($object->table_element);
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id > 0 || !empty($ref)) {
$upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id;
$upload_dir = $conf->asset->multidir_output[isset($object->entity) ? $object->entity : 1] . "/" . $object->id;
}
$permissiontoread = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'read')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'read')));

View File

@ -34,6 +34,7 @@ if (!is_object($form)) {
$form = new Form($db);
}
global $formaccounting;
if (isModEnabled('accounting') && !is_object($formaccounting)) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
$formaccounting = new FormAccounting($db);
@ -57,25 +58,24 @@ if ($reshook < 0) {
if (empty($reshook)) {
foreach ($assetaccountancycodes->accountancy_codes_fields as $mode_key => $mode_info) {
//if (empty($object->enabled_modes[$mode_key])) continue;
print load_fiche_titre($langs->trans($mode_info['label']), '', '');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
$width = ($mode_key == "economic")? "width50p pull-left" : "width50p";
print '<table class="border '. $width .'" id="block_' . $mode_key . '">';
print '<tr><td class="info-box-title">'.$langs->trans($mode_info['label']).'</td></tr>';
foreach ($mode_info['fields'] as $field_key => $field_info) {
$html_name = $mode_key . '_' . $field_key;
print '<tr><td class="titlefieldcreate">' . $langs->trans($field_info['label']) . '</td><td colspan="3">';
print '<tr><td class="width40p">' . $langs->trans($field_info['label']) . '</td><td>';
$accountancy_code = GETPOSTISSET($html_name) ? GETPOST($html_name, 'aZ09') : (!empty($assetaccountancycodes->accountancy_codes[$mode_key][$field_key]) ? $assetaccountancycodes->accountancy_codes[$mode_key][$field_key] : '');
if (isModEnabled('accounting')) {
print $formaccounting->select_account($accountancy_code, $html_name, 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
print $formaccounting->select_account($accountancy_code, $html_name, 1, null, 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 1);
} else {
print '<input name="' . $html_name . '" class="maxwidth200" value="' . dol_escape_htmltag($accountancy_code) . '">';
print '<input name="' . $html_name . '" class="maxwidth200 " value="' . dol_escape_htmltag($accountancy_code) . '">';
}
print '</td></tr>';
}
print '</table>';
print '</div>';
}
print '<div class="clearboth"></div>';
}
?>
<!-- END PHP TEMPLATE accountancy_code_edit.tpl.php -->

View File

@ -55,14 +55,15 @@ if (empty($reshook)) {
}
foreach ($assetaccountancycodes->accountancy_codes_fields as $mode_key => $mode_info) {
//if (empty($object->enabled_modes[$mode_key])) continue;
print load_fiche_titre($langs->trans($mode_info['label']), '', '');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
if (empty($assetdepreciationoptions->deprecation_options[$mode_key]) && $mode_key == "accelerated_depreciation") {
continue;
}
$width = ($mode_key == "economic")? "pull-left" : "pull-left";
print '<table class="liste centpercent '. $width .'" id="block_' . $mode_key . '">' . "\n";
print '<tr class="liste_titre"><td colspan="5">'.$langs->trans($mode_info['label']).'</td></tr>';
foreach ($mode_info['fields'] as $field_key => $field_info) {
print '<tr><td class="titlefieldcreate">' . $langs->trans($field_info['label']) . '</td><td colspan="3">';
$key = $mode_key . '_' . $field_key;
print '<tr class="field_' . $key . '" id="block_' . $mode_key . '"><td class="titlefieldmiddle">' . $langs->trans($field_info['label']) . '</td><td colspan="3">';
if (!empty($assetaccountancycodes->accountancy_codes[$mode_key][$field_key])) {
$accountancy_code = $assetaccountancycodes->accountancy_codes[$mode_key][$field_key];
if (isModEnabled('accounting')) {
@ -77,8 +78,10 @@ if (empty($reshook)) {
print '</td></tr>';
}
print '</table>';
print '</div>';
print '<div class="clearboth"></div>';
print '<br>';
}
print '<div class="clearboth"></div>';
}
?>
<!-- END PHP TEMPLATE accountancy_code_view.tpl.php -->

View File

@ -34,7 +34,7 @@ if (!is_object($form)) {
$form = new Form($db);
}
if (!is_object($formadmin)) {
if (!isset($formadmin) || !is_object($formadmin)) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
$formadmin = new FormAdmin($db);
}
@ -75,13 +75,12 @@ if (empty($reshook)) {
$assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
$prefix_html_name = $mode_key . '_';
print '<div id="block_' . $mode_key . '">';
print load_fiche_titre($langs->trans($mode_info['label']), '', '');
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">' . "\n";
$width = ($mode_key == "economic")? "width50p pull-left" : "width50p";
print '<table class="border '. $width .'" id="block_' . $mode_key . '">' . "\n";
print '<tr><td class="info-box-title">'.$langs->trans($mode_info['label']).'</td></tr>';
if ($mode_key == "economic") {
print '<hr>';
}
$mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
foreach ($mode_info['fields'] as $field_key => $field_info) {
// Discard if extrafield is a hidden field on form
@ -91,16 +90,7 @@ if (empty($reshook)) {
if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
continue; // We don't want this field
}
if (!empty($field_info['column_break'])) {
print '</table>';
// We close div and reopen for second column
print '</div>';
print '<div class="fichehalfright">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
}
$html_name = $prefix_html_name . $field_key;
if (!empty($field_info['enabled_field'])) {
@ -114,15 +104,15 @@ if (empty($reshook)) {
}
$more_class = '';
if (!empty($field_info['required']) || (isset($field_info['notnull']) && $field_info['notnull'] > 0)) {
$more_class .= ' fieldrequired';
if (!empty($field_info['required'])) {
$more_class .= 'width40p fieldrequired';
}
if (preg_match('/^(text|html)/', $val['type'])) {
if (isset($val['type']) && preg_match('/^(text|html)/', $val['type'])) {
$more_class .= ' tdtop';
}
print '<tr class="field_' . $html_name . '" id="field_' . $html_name . '"><td';
print ' class="titlefieldcreate' . $more_class . '">';
print ' class="' . $more_class . '">';
if (!empty($field_info['help'])) {
print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
} else {
@ -166,11 +156,8 @@ if (empty($reshook)) {
print '</tr>';
}
print '</table>';
print '</div>';
print '</div>';
print '<div class="clearboth"></div>';
print '</div>';
}
print '<div class="clearboth"></div>';
}
if (!empty($enabled_field_info)) {
@ -200,7 +187,7 @@ if (!empty($enabled_field_info)) {
var target_name = _this.attr('data-asset-enabled-field-target');
// for block mode
var target = $('div#' + target_name);
var target = $('table#' + target_name);
// for field
if (!(target.length > 0)) {

View File

@ -53,26 +53,25 @@ if ($reshook < 0) {
if (empty($reshook)) {
$class_type = get_class($object) == 'Asset' ? 0 : 1;
print '<br>';
foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
if (!empty($mode_info['enabled_field'])) {
$info = explode(':', $mode_info['enabled_field']);
if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
if (empty($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]]) || $assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
continue;
}
}
$assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
print load_fiche_titre($langs->trans($mode_info['label']), '', '');
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">' . "\n";
$width = ($mode_key == "economic")? "pull-left" : "pull-left";
print '<table class="liste centpercent '. $width .'" id="block_' . $mode_key . '">' . "\n";
print '<tr class="liste_titre"><td colspan="5">'.$langs->trans($mode_info['label']).'</td></tr>';
$mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
foreach ($mode_info['fields'] as $field_key => $field_info) {
if (!empty($field_info['enabled_field'])) {
$info = explode(':', $field_info['enabled_field']);
if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
if (empty($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]]) || $assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
continue;
}
}
@ -83,22 +82,11 @@ if (empty($reshook)) {
if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
continue; // We don't want this field
}
if (!empty($field_info['column_break'])) {
print '</table>';
// We close div and reopen for second column
print '</div>';
print '<div class="fichehalfright">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
}
$key = $mode_key . '_' . $field_key;
$value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key];
$value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key] ?? null;
print '<tr class="field_' . $key . '"><td';
print ' class="' . (empty($field_info['tdcss']) ? 'titlefield' : $field_info['tdcss']) . ' fieldname_' . $key;
print '<tr class="field_' . $key . '" id="block_' . $mode_key . '"><td';
print ' class="' . (empty($field_info['tdcss']) ? 'titlefieldmiddle' : $field_info['tdcss']) . ' fieldname_' . $key;
if ($field_info['type'] == 'text' || $field_info['type'] == 'html') {
print ' tdtop';
}
@ -144,9 +132,8 @@ if (empty($reshook)) {
print '</tr>';
}
print '</table>';
print '</div>';
print '</div>';
print '<div class="clearboth"></div>';
print '<br>';
}
}

View File

@ -194,16 +194,6 @@ function assetModelPrepareHead($object)
$head[$h][2] = 'card';
$h++;
$head[$h][0] = DOL_URL_ROOT . '/asset/model/depreciation_options.php?id=' . $object->id;
$head[$h][1] = $langs->trans("AssetDepreciationOptions");
$head[$h][2] = 'depreciation_options';
$h++;
$head[$h][0] = DOL_URL_ROOT . '/asset/model/accountancy_codes.php?id=' . $object->id;
$head[$h][1] = $langs->trans("AssetAccountancyCodes");
$head[$h][2] = 'accountancy_codes';
$h++;
if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {