@@ -29,16 +29,28 @@ discard block |
||
| 29 | 29 | // Load Dolibarr environment |
| 30 | 30 | $res = 0; |
| 31 | 31 | // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) |
| 32 | -if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; |
|
| 32 | +if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { |
|
| 33 | + $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; |
|
| 34 | +} |
|
| 33 | 35 | // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME |
| 34 | 36 | $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; |
| 35 | 37 | while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } |
| 36 | -if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; |
|
| 37 | -if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; |
|
| 38 | +if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { |
|
| 39 | + $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; |
|
| 40 | +} |
|
| 41 | +if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { |
|
| 42 | + $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; |
|
| 43 | +} |
|
| 38 | 44 | // Try main.inc.php using relative path |
| 39 | -if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php"; |
|
| 40 | -if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php"; |
|
| 41 | -if (!$res) die("Include of main fails"); |
|
| 45 | +if (!$res && file_exists("../../main.inc.php")) { |
|
| 46 | + $res = @include "../../main.inc.php"; |
|
| 47 | +} |
|
| 48 | +if (!$res && file_exists("../../../main.inc.php")) { |
|
| 49 | + $res = @include "../../../main.inc.php"; |
|
| 50 | +} |
|
| 51 | +if (!$res) { |
|
| 52 | + die("Include of main fails"); |
|
| 53 | +} |
|
| 42 | 54 | |
| 43 | 55 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 44 | 56 | require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php'; |
@@ -52,13 +64,17 @@ discard block |
||
| 52 | 64 | // List of supported format |
| 53 | 65 | $tmptype2label = ExtraFields::$type2label; |
| 54 | 66 | $type2label = array(''); |
| 55 | -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); |
|
| 67 | +foreach ($tmptype2label as $key => $val) { |
|
| 68 | + $type2label[$key] = $langs->transnoentitiesnoconv($val); |
|
| 69 | +} |
|
| 56 | 70 | |
| 57 | 71 | $action = GETPOST('action', 'aZ09'); |
| 58 | 72 | $attrname = GETPOST('attrname', 'alpha'); |
| 59 | 73 | $elementtype = 'inventory'; //Must be the $table_element of the class that manage extrafield |
| 60 | 74 | |
| 61 | -if (!$user->admin) accessforbidden(); |
|
| 75 | +if (!$user->admin) { |
|
| 76 | + accessforbidden(); |
|
| 77 | +} |
|
| 62 | 78 | |
| 63 | 79 | |
| 64 | 80 | /* |
@@ -38,9 +38,9 @@ |
||
| 38 | 38 | // Only works if you are not in safe_mode. / Ne fonctionne que si on est pas en safe_mode. |
| 39 | 39 | |
| 40 | 40 | $err = error_reporting(); |
| 41 | -error_reporting(0); // Disable all errors |
|
| 41 | +error_reporting(0); // Disable all errors |
|
| 42 | 42 | //error_reporting(E_ALL); |
| 43 | -@set_time_limit(1800); // Need 1800 on some very slow OS like Windows 7/64 |
|
| 43 | +@set_time_limit(1800); // Need 1800 on some very slow OS like Windows 7/64 |
|
| 44 | 44 | error_reporting($err); |
| 45 | 45 | |
| 46 | 46 | $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : (empty($argv[1]) ? '' : $argv[1]); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | // Object card |
| 93 | 93 | // ------------------------------------------------------------ |
| 94 | - $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; |
|
| 94 | + $linkback = '<a href="'.DOL_URL_ROOT.'/asset/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; |
|
| 95 | 95 | |
| 96 | 96 | $morehtmlref = '<div class="refidno">'; |
| 97 | 97 | $morehtmlref .= '</div>'; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | $cssclass = "titlefield"; |
| 108 | - include DOL_DOCUMENT_ROOT . '/core/tpl/notes.tpl.php'; |
|
| 108 | + include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; |
|
| 109 | 109 | |
| 110 | 110 | print '</div>'; |
| 111 | 111 | |
@@ -55,10 +55,14 @@ |
||
| 55 | 55 | $permissiontoadd = $user->hasRight('asset', 'write'); // Used by the include of actions_addupdatedelete.inc.php |
| 56 | 56 | |
| 57 | 57 | // Security check (enable the most restrictive one) |
| 58 | -if ($user->socid > 0) accessforbidden(); |
|
| 58 | +if ($user->socid > 0) { |
|
| 59 | + accessforbidden(); |
|
| 60 | +} |
|
| 59 | 61 | $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
| 60 | 62 | restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); |
| 61 | -if (!isModEnabled('asset')) accessforbidden(); |
|
| 63 | +if (!isModEnabled('asset')) { |
|
| 64 | + accessforbidden(); |
|
| 65 | +} |
|
| 62 | 66 | |
| 63 | 67 | |
| 64 | 68 | /* |
@@ -91,7 +91,7 @@ |
||
| 91 | 91 | |
| 92 | 92 | // Object card |
| 93 | 93 | // ------------------------------------------------------------ |
| 94 | - $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; |
|
| 94 | + $linkback = '<a href="'.DOL_URL_ROOT.'/asset/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; |
|
| 95 | 95 | |
| 96 | 96 | $morehtmlref = '<div class="refidno">'; |
| 97 | 97 | $morehtmlref .= '</div>'; |
@@ -55,11 +55,17 @@ |
||
| 55 | 55 | $permissiontoadd = $user->hasRight('asset', 'write'); // Used by the include of actions_addupdatedelete.inc.php |
| 56 | 56 | |
| 57 | 57 | // Security check (enable the most restrictive one) |
| 58 | -if ($user->socid > 0) accessforbidden(); |
|
| 58 | +if ($user->socid > 0) { |
|
| 59 | + accessforbidden(); |
|
| 60 | +} |
|
| 59 | 61 | $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
| 60 | 62 | restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); |
| 61 | -if (!isModEnabled('asset')) accessforbidden(); |
|
| 62 | -if (!isset($object->disposal_date) || $object->disposal_date === "") accessforbidden(); |
|
| 63 | +if (!isModEnabled('asset')) { |
|
| 64 | + accessforbidden(); |
|
| 65 | +} |
|
| 66 | +if (!isset($object->disposal_date) || $object->disposal_date === "") { |
|
| 67 | + accessforbidden(); |
|
| 68 | +} |
|
| 63 | 69 | |
| 64 | 70 | |
| 65 | 71 | /* |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? |
| 38 | 38 | $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation |
| 39 | 39 | $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button |
| 40 | -$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list |
|
| 40 | +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list |
|
| 41 | 41 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'assetmodellist'; // To manage different context of search |
| 42 | 42 | $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page |
| 43 | -$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') |
|
| 43 | +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') |
|
| 44 | 44 | |
| 45 | 45 | $id = GETPOST('id', 'int'); |
| 46 | 46 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | // Default sort order (if not yet defined by previous GETPOST) |
| 72 | 72 | if (!$sortfield) { |
| 73 | - reset($object->fields); // Reset is required to avoid key() to return null. |
|
| 73 | + reset($object->fields); // Reset is required to avoid key() to return null. |
|
| 74 | 74 | $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. |
| 75 | 75 | } |
| 76 | 76 | if (!$sortorder) { |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | $sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'"; |
| 255 | 255 | } |
| 256 | 256 | if (preg_match('/_dtend$/', $key)) { |
| 257 | - $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'"; |
|
| 257 | + $sql .= " AND t.".$columnName." <= '".$db->idate($search[$key])."'"; |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | } |
@@ -140,8 +140,12 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
| 142 | 142 | restrictedArea($user, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); |
| 143 | -if (!isModEnabled('asset')) accessforbidden(); |
|
| 144 | -if (!$permissiontoread) accessforbidden(); |
|
| 143 | +if (!isModEnabled('asset')) { |
|
| 144 | + accessforbidden(); |
|
| 145 | +} |
|
| 146 | +if (!$permissiontoread) { |
|
| 147 | + accessforbidden(); |
|
| 148 | +} |
|
| 145 | 149 | |
| 146 | 150 | /* |
| 147 | 151 | * Actions |
@@ -169,7 +173,9 @@ discard block |
||
| 169 | 173 | 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 |
| 170 | 174 | foreach ($object->fields as $key => $val) { |
| 171 | 175 | $search[$key] = ''; |
| 172 | - if ($key == 'fk_pays') $search[$key] = $mysoc->country_id; |
|
| 176 | + if ($key == 'fk_pays') { |
|
| 177 | + $search[$key] = $mysoc->country_id; |
|
| 178 | + } |
|
| 173 | 179 | if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { |
| 174 | 180 | $search[$key.'_dtstart'] = ''; |
| 175 | 181 | $search[$key.'_dtend'] = ''; |
@@ -55,12 +55,20 @@ |
||
| 55 | 55 | $permissionnote = $permissiontoadd; // Used by the include of actions_setnotes.inc.php |
| 56 | 56 | |
| 57 | 57 | // Security check (enable the most restrictive one) |
| 58 | -if ($user->socid > 0) accessforbidden(); |
|
| 59 | -if ($user->socid > 0) $socid = $user->socid; |
|
| 58 | +if ($user->socid > 0) { |
|
| 59 | + accessforbidden(); |
|
| 60 | +} |
|
| 61 | +if ($user->socid > 0) { |
|
| 62 | + $socid = $user->socid; |
|
| 63 | +} |
|
| 60 | 64 | $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
| 61 | 65 | restrictedArea($user, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); |
| 62 | -if (empty($conf->asset->enabled)) accessforbidden(); |
|
| 63 | -if (!$permissiontoread) accessforbidden(); |
|
| 66 | +if (empty($conf->asset->enabled)) { |
|
| 67 | + accessforbidden(); |
|
| 68 | +} |
|
| 69 | +if (!$permissiontoread) { |
|
| 70 | + accessforbidden(); |
|
| 71 | +} |
|
| 64 | 72 | |
| 65 | 73 | |
| 66 | 74 | /* |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | // Load Dolibarr environment |
| 26 | 26 | require '../../main.inc.php'; |
| 27 | -require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php'; |
|
| 28 | -require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php'; |
|
| 27 | +require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php'; |
|
| 28 | +require_once DOL_DOCUMENT_ROOT.'/asset/class/assetmodel.class.php'; |
|
| 29 | 29 | |
| 30 | 30 | // Load translation files required by the page |
| 31 | 31 | $langs->loadLangs(array("assets", "companies")); |
@@ -40,15 +40,15 @@ discard block |
||
| 40 | 40 | // Initialize technical objects |
| 41 | 41 | $object = new AssetModel($db); |
| 42 | 42 | $extrafields = new ExtraFields($db); |
| 43 | -$diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id; |
|
| 43 | +$diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id; |
|
| 44 | 44 | $hookmanager->initHooks(array('assetmodelnote', 'globalcard')); // Note that conf->hooks_modules contains array |
| 45 | 45 | // Fetch optionals attributes and labels |
| 46 | 46 | $extrafields->fetch_name_optionals_label($object->table_element); |
| 47 | 47 | |
| 48 | 48 | // Load object |
| 49 | -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 |
|
| 49 | +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 |
|
| 50 | 50 | if ($id > 0 || !empty($ref)) { |
| 51 | - $upload_dir = $conf->asset->multidir_output[$object->entity] . "/" . $object->id; |
|
| 51 | + $upload_dir = $conf->asset->multidir_output[$object->entity]."/".$object->id; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $permissiontoread = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'read')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'read'))); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
| 75 | 75 | } |
| 76 | 76 | if (empty($reshook)) { |
| 77 | - include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not include_once |
|
| 77 | + include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | // Object card |
| 98 | 98 | // ------------------------------------------------------------ |
| 99 | - $linkback = '<a href="' . DOL_URL_ROOT . '/asset/model/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; |
|
| 99 | + $linkback = '<a href="'.DOL_URL_ROOT.'/asset/model/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; |
|
| 100 | 100 | |
| 101 | 101 | $morehtmlref = '<div class="refidno">'; |
| 102 | 102 | $morehtmlref .= '</div>'; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | $cssclass = "titlefield"; |
| 113 | - include DOL_DOCUMENT_ROOT . '/core/tpl/notes.tpl.php'; |
|
| 113 | + include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; |
|
| 114 | 114 | |
| 115 | 115 | print '</div>'; |
| 116 | 116 | |
@@ -225,14 +225,20 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public function create(User $user, $notrigger = false) |
| 227 | 227 | { |
| 228 | - if (!isset($this->date_start) || $this->date_start === "") $this->date_start = $this->date_acquisition; |
|
| 228 | + if (!isset($this->date_start) || $this->date_start === "") { |
|
| 229 | + $this->date_start = $this->date_acquisition; |
|
| 230 | + } |
|
| 229 | 231 | |
| 230 | 232 | $this->db->begin(); |
| 231 | 233 | |
| 232 | 234 | $result = $result_create = $this->createCommon($user, $notrigger); |
| 233 | - if ($result > 0 && $this->fk_asset_model > 0) $result = $this->setDataFromAssetModel($user, $notrigger); |
|
| 235 | + if ($result > 0 && $this->fk_asset_model > 0) { |
|
| 236 | + $result = $this->setDataFromAssetModel($user, $notrigger); |
|
| 237 | + } |
|
| 234 | 238 | if ($result > 0) { |
| 235 | - if ($this->supplier_invoice_id > 0) $this->add_object_linked('invoice_supplier', $this->supplier_invoice_id); |
|
| 239 | + if ($this->supplier_invoice_id > 0) { |
|
| 240 | + $this->add_object_linked('invoice_supplier', $this->supplier_invoice_id); |
|
| 241 | + } |
|
| 236 | 242 | } |
| 237 | 243 | |
| 238 | 244 | if ($result < 0) { |
@@ -355,7 +361,9 @@ discard block |
||
| 355 | 361 | { |
| 356 | 362 | $result = $this->fetchCommon($id, $ref); |
| 357 | 363 | if ($result > 0) { |
| 358 | - if (!empty($this->table_element_line)) $this->fetchLines(); |
|
| 364 | + if (!empty($this->table_element_line)) { |
|
| 365 | + $this->fetchLines(); |
|
| 366 | + } |
|
| 359 | 367 | |
| 360 | 368 | $res = $this->hasDepreciationLinesInBookkeeping(); |
| 361 | 369 | if ($res < 0) { |
@@ -474,7 +482,9 @@ discard block |
||
| 474 | 482 | */ |
| 475 | 483 | public function update(User $user, $notrigger = false) |
| 476 | 484 | { |
| 477 | - if (!isset($this->date_start) || $this->date_start === "") $this->date_start = $this->date_acquisition; |
|
| 485 | + if (!isset($this->date_start) || $this->date_start === "") { |
|
| 486 | + $this->date_start = $this->date_acquisition; |
|
| 487 | + } |
|
| 478 | 488 | |
| 479 | 489 | $this->db->begin(); |
| 480 | 490 | |
@@ -669,7 +679,9 @@ discard block |
||
| 669 | 679 | } |
| 670 | 680 | |
| 671 | 681 | while ($obj = $this->db->fetch_object($resql)) { |
| 672 | - if (!isset($this->depreciation_lines[$obj->depreciation_mode])) $this->depreciation_lines[$obj->depreciation_mode] = array(); |
|
| 682 | + if (!isset($this->depreciation_lines[$obj->depreciation_mode])) { |
|
| 683 | + $this->depreciation_lines[$obj->depreciation_mode] = array(); |
|
| 684 | + } |
|
| 673 | 685 | $this->depreciation_lines[$obj->depreciation_mode][] = array( |
| 674 | 686 | 'id' => $obj->rowid, |
| 675 | 687 | 'ref' => $obj->ref, |
@@ -907,7 +919,9 @@ discard block |
||
| 907 | 919 | $sql .= " WHERE " . MAIN_DB_PREFIX . "asset_depreciation.fk_asset = " . (int) $this->id; |
| 908 | 920 | $sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.depreciation_mode = '" . $this->db->escape($mode_key) . "'"; |
| 909 | 921 | $sql .= " AND ab.fk_docdet IS NULL"; |
| 910 | - if ($last_depreciation_date !== "") $sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.ref != ''"; |
|
| 922 | + if ($last_depreciation_date !== "") { |
|
| 923 | + $sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.ref != ''"; |
|
| 924 | + } |
|
| 911 | 925 | $resql = $this->db->query($sql); |
| 912 | 926 | if (!$resql) { |
| 913 | 927 | $this->errors[] = $langs->trans('AssetErrorClearDepreciationLines') . ': ' . $this->db->lasterror(); |
@@ -985,7 +999,9 @@ discard block |
||
| 985 | 999 | do { |
| 986 | 1000 | // Loop security |
| 987 | 1001 | $idx_loop++; |
| 988 | - if ($idx_loop > $max_loop) break; |
|
| 1002 | + if ($idx_loop > $max_loop) { |
|
| 1003 | + break; |
|
| 1004 | + } |
|
| 989 | 1005 | |
| 990 | 1006 | if ($last_depreciation_date < $fiscal_period_end && ($first_period_date <= $start_date || $first_period_found)) { |
| 991 | 1007 | // Disposal not depreciated |
@@ -1152,10 +1168,14 @@ discard block |
||
| 1152 | 1168 | $this->fields[$field]['notnull'] = 0; |
| 1153 | 1169 | } |
| 1154 | 1170 | if ($result > 0) { |
| 1155 | - if ($disposal_invoice_id > 0) $this->add_object_linked('facture', $disposal_invoice_id); |
|
| 1171 | + if ($disposal_invoice_id > 0) { |
|
| 1172 | + $this->add_object_linked('facture', $disposal_invoice_id); |
|
| 1173 | + } |
|
| 1156 | 1174 | $result = $this->setStatusCommon($user, self::STATUS_DISPOSED, $notrigger, 'ASSET_DISPOSED'); |
| 1157 | 1175 | } |
| 1158 | - if ($result > 0) $result = $this->calculationDepreciation(); |
|
| 1176 | + if ($result > 0) { |
|
| 1177 | + $result = $this->calculationDepreciation(); |
|
| 1178 | + } |
|
| 1159 | 1179 | |
| 1160 | 1180 | if ($result < 0) { |
| 1161 | 1181 | $this->db->rollback(); |
@@ -1218,7 +1238,9 @@ discard block |
||
| 1218 | 1238 | $this->deleteObjectLinked(null, 'facture'); |
| 1219 | 1239 | $result = $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'ASSET_REOPEN'); |
| 1220 | 1240 | } |
| 1221 | - if ($result > 0) $result = $this->calculationDepreciation(); |
|
| 1241 | + if ($result > 0) { |
|
| 1242 | + $result = $this->calculationDepreciation(); |
|
| 1243 | + } |
|
| 1222 | 1244 | |
| 1223 | 1245 | if ($result < 0) { |
| 1224 | 1246 | $this->db->rollback(); |
@@ -1352,8 +1374,11 @@ discard block |
||
| 1352 | 1374 | |
| 1353 | 1375 | if ($withpicto != 2) { |
| 1354 | 1376 | $name = $this->ref; |
| 1355 | - if ($option == 'label') $name = $this->label; |
|
| 1356 | - elseif ($option == 'with_label') $name .= ' - ' . $this->label; |
|
| 1377 | + if ($option == 'label') { |
|
| 1378 | + $name = $this->label; |
|
| 1379 | + } elseif ($option == 'with_label') { |
|
| 1380 | + $name .= ' - ' . $this->label; |
|
| 1381 | + } |
|
| 1357 | 1382 | $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name); |
| 1358 | 1383 | } |
| 1359 | 1384 | |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public $picto = 'asset'; |
| 62 | 62 | |
| 63 | - const STATUS_DRAFT = 0; // In progress |
|
| 64 | - const STATUS_DISPOSED = 9; // Disposed |
|
| 63 | + const STATUS_DRAFT = 0; // In progress |
|
| 64 | + const STATUS_DISPOSED = 9; // Disposed |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | /** |
| 95 | 95 | * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. |
| 96 | 96 | */ |
| 97 | - public $fields=array( |
|
| 97 | + public $fields = array( |
|
| 98 | 98 | 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"), |
| 99 | 99 | 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'noteditable'=>'0', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'validate'=>'1', 'comment'=>"Reference of object"), |
| 100 | 100 | 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'showoncombobox'=>'2', 'validate'=>'1',), |
@@ -526,11 +526,11 @@ discard block |
||
| 526 | 526 | // Check parameters |
| 527 | 527 | $error = 0; |
| 528 | 528 | if (empty($this->id)) { |
| 529 | - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')'); |
|
| 529 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset").' ('.$langs->transnoentitiesnoconv("TechnicalID").')'); |
|
| 530 | 530 | $error++; |
| 531 | 531 | } |
| 532 | 532 | if (empty($this->fk_asset_model)) { |
| 533 | - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AssetModel") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')'); |
|
| 533 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AssetModel").' ('.$langs->transnoentitiesnoconv("TechnicalID").')'); |
|
| 534 | 534 | $error++; |
| 535 | 535 | } |
| 536 | 536 | if ($error) { |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | |
| 542 | 542 | // Get depreciation options |
| 543 | 543 | //--------------------------- |
| 544 | - require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php'; |
|
| 544 | + require_once DOL_DOCUMENT_ROOT.'/asset/class/assetdepreciationoptions.class.php'; |
|
| 545 | 545 | $options_model = new AssetDepreciationOptions($this->db); |
| 546 | 546 | $result = $options_model->fetchDeprecationOptions(0, $this->fk_asset_model); |
| 547 | 547 | if ($result < 0) { |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | // Get accountancy codes |
| 577 | 577 | //--------------------------- |
| 578 | 578 | if (!$error) { |
| 579 | - require_once DOL_DOCUMENT_ROOT . '/asset/class/assetaccountancycodes.class.php'; |
|
| 579 | + require_once DOL_DOCUMENT_ROOT.'/asset/class/assetaccountancycodes.class.php'; |
|
| 580 | 580 | $accountancy_codes_model = new AssetAccountancyCodes($this->db); |
| 581 | 581 | $result = $accountancy_codes_model->fetchAccountancyCodes(0, $this->fk_asset_model); |
| 582 | 582 | if ($result < 0) { |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | // Check parameters |
| 636 | 636 | $error = 0; |
| 637 | 637 | if (empty($this->id)) { |
| 638 | - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')'); |
|
| 638 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset").' ('.$langs->transnoentitiesnoconv("TechnicalID").')'); |
|
| 639 | 639 | $error++; |
| 640 | 640 | } |
| 641 | 641 | if ($error) { |
@@ -658,15 +658,15 @@ discard block |
||
| 658 | 658 | */ |
| 659 | 659 | |
| 660 | 660 | $sql = "SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht"; |
| 661 | - $sql .= ", " . $this->db->ifsql('iab.fk_docdet IS NOT NULL', 1, 0) . " AS bookkeeping"; |
|
| 662 | - $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad"; |
|
| 663 | - $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid"; |
|
| 664 | - $sql .= " WHERE ad.fk_asset = " . (int) $this->id; |
|
| 661 | + $sql .= ", ".$this->db->ifsql('iab.fk_docdet IS NOT NULL', 1, 0)." AS bookkeeping"; |
|
| 662 | + $sql .= " FROM ".MAIN_DB_PREFIX."asset_depreciation AS ad"; |
|
| 663 | + $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid"; |
|
| 664 | + $sql .= " WHERE ad.fk_asset = ".(int) $this->id; |
|
| 665 | 665 | $sql .= " ORDER BY ad.depreciation_date ASC"; |
| 666 | 666 | |
| 667 | 667 | $resql = $this->db->query($sql); |
| 668 | 668 | if (!$resql) { |
| 669 | - $this->errors[] = $langs->trans('AssetErrorFetchDepreciationLines') . ': ' . $this->db->lasterror(); |
|
| 669 | + $this->errors[] = $langs->trans('AssetErrorFetchDepreciationLines').': '.$this->db->lasterror(); |
|
| 670 | 670 | return -1; |
| 671 | 671 | } |
| 672 | 672 | |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | // Check parameters |
| 702 | 702 | $error = 0; |
| 703 | 703 | if (empty($this->id)) { |
| 704 | - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')'); |
|
| 704 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset").' ('.$langs->transnoentitiesnoconv("TechnicalID").')'); |
|
| 705 | 705 | $error++; |
| 706 | 706 | } |
| 707 | 707 | if ($error) { |
@@ -723,14 +723,14 @@ discard block |
||
| 723 | 723 | */ |
| 724 | 724 | |
| 725 | 725 | $sql = "SELECT COUNT(*) AS has_bookkeeping"; |
| 726 | - $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad"; |
|
| 727 | - $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid"; |
|
| 728 | - $sql .= " WHERE ad.fk_asset = " . (int) $this->id; |
|
| 726 | + $sql .= " FROM ".MAIN_DB_PREFIX."asset_depreciation AS ad"; |
|
| 727 | + $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid"; |
|
| 728 | + $sql .= " WHERE ad.fk_asset = ".(int) $this->id; |
|
| 729 | 729 | $sql .= " AND iab.fk_docdet IS NOT NULL"; |
| 730 | 730 | |
| 731 | 731 | $resql = $this->db->query($sql); |
| 732 | 732 | if (!$resql) { |
| 733 | - $this->errors[] = $langs->trans('AssetErrorFetchDepreciationLines') . ': ' . $this->db->lasterror(); |
|
| 733 | + $this->errors[] = $langs->trans('AssetErrorFetchDepreciationLines').': '.$this->db->lasterror(); |
|
| 734 | 734 | return -1; |
| 735 | 735 | } |
| 736 | 736 | |
@@ -768,28 +768,28 @@ discard block |
||
| 768 | 768 | // Check parameters |
| 769 | 769 | $error = 0; |
| 770 | 770 | if (empty($this->id)) { |
| 771 | - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')'); |
|
| 771 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset").' ('.$langs->transnoentitiesnoconv("TechnicalID").')'); |
|
| 772 | 772 | $error++; |
| 773 | 773 | } |
| 774 | 774 | if ($error) { |
| 775 | 775 | return -1; |
| 776 | 776 | } |
| 777 | 777 | |
| 778 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "asset_depreciation(fk_asset, depreciation_mode, ref, depreciation_date, depreciation_ht, cumulative_depreciation_ht, accountancy_code_debit, accountancy_code_credit)"; |
|
| 778 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."asset_depreciation(fk_asset, depreciation_mode, ref, depreciation_date, depreciation_ht, cumulative_depreciation_ht, accountancy_code_debit, accountancy_code_credit)"; |
|
| 779 | 779 | $sql .= " VALUES ( "; |
| 780 | - $sql .= " " . (int) $this->id; |
|
| 781 | - $sql .= ", '" . $this->db->escape($mode) . "'"; |
|
| 782 | - $sql .= ", '" . $this->db->escape($ref) . "'"; |
|
| 783 | - $sql .= ", '" . $this->db->idate($depreciation_date) . "'"; |
|
| 784 | - $sql .= ", " . (double) $depreciation_ht; |
|
| 785 | - $sql .= ", " . (double) $cumulative_depreciation_ht; |
|
| 786 | - $sql .= ", '" . $this->db->escape($accountancy_code_debit) . "'"; |
|
| 787 | - $sql .= ", '" . $this->db->escape($accountancy_code_credit) . "'"; |
|
| 780 | + $sql .= " ".(int) $this->id; |
|
| 781 | + $sql .= ", '".$this->db->escape($mode)."'"; |
|
| 782 | + $sql .= ", '".$this->db->escape($ref)."'"; |
|
| 783 | + $sql .= ", '".$this->db->idate($depreciation_date)."'"; |
|
| 784 | + $sql .= ", ".(double) $depreciation_ht; |
|
| 785 | + $sql .= ", ".(double) $cumulative_depreciation_ht; |
|
| 786 | + $sql .= ", '".$this->db->escape($accountancy_code_debit)."'"; |
|
| 787 | + $sql .= ", '".$this->db->escape($accountancy_code_credit)."'"; |
|
| 788 | 788 | $sql .= ")"; |
| 789 | 789 | |
| 790 | 790 | $resql = $this->db->query($sql); |
| 791 | 791 | if (!$resql) { |
| 792 | - $this->errors[] = $langs->trans('AssetErrorAddDepreciationLine') . ': ' . $this->db->lasterror(); |
|
| 792 | + $this->errors[] = $langs->trans('AssetErrorAddDepreciationLine').': '.$this->db->lasterror(); |
|
| 793 | 793 | return -1; |
| 794 | 794 | } |
| 795 | 795 | |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | // Check parameters |
| 813 | 813 | $error = 0; |
| 814 | 814 | if (empty($this->id)) { |
| 815 | - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')'); |
|
| 815 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset").' ('.$langs->transnoentitiesnoconv("TechnicalID").')'); |
|
| 816 | 816 | $error++; |
| 817 | 817 | } |
| 818 | 818 | if ($error) { |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | |
| 822 | 822 | // Get depreciation options |
| 823 | 823 | //--------------------------- |
| 824 | - require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php'; |
|
| 824 | + require_once DOL_DOCUMENT_ROOT.'/asset/class/assetdepreciationoptions.class.php'; |
|
| 825 | 825 | $options = new AssetDepreciationOptions($this->db); |
| 826 | 826 | $result = $options->fetchDeprecationOptions($this->id); |
| 827 | 827 | if ($result < 0) { |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | |
| 833 | 833 | // Get accountancy codes |
| 834 | 834 | //--------------------------- |
| 835 | - require_once DOL_DOCUMENT_ROOT . '/asset/class/assetaccountancycodes.class.php'; |
|
| 835 | + require_once DOL_DOCUMENT_ROOT.'/asset/class/assetaccountancycodes.class.php'; |
|
| 836 | 836 | $accountancy_codes = new AssetAccountancyCodes($this->db); |
| 837 | 837 | $result = $accountancy_codes->fetchAccountancyCodes($this->id); |
| 838 | 838 | if ($result < 0) { |
@@ -848,20 +848,20 @@ discard block |
||
| 848 | 848 | foreach ($options->deprecation_options as $mode_key => $fields) { |
| 849 | 849 | $modes[$mode_key] = $this->db->escape($mode_key); |
| 850 | 850 | } |
| 851 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "asset_depreciation"; |
|
| 852 | - $sql .= " WHERE fk_asset = " . (int) $this->id; |
|
| 853 | - $sql .= " AND depreciation_mode NOT IN ('" . $this->db->sanitize(implode("', '", $modes)) . "')"; |
|
| 851 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."asset_depreciation"; |
|
| 852 | + $sql .= " WHERE fk_asset = ".(int) $this->id; |
|
| 853 | + $sql .= " AND depreciation_mode NOT IN ('".$this->db->sanitize(implode("', '", $modes))."')"; |
|
| 854 | 854 | |
| 855 | 855 | $resql = $this->db->query($sql); |
| 856 | 856 | if (!$resql) { |
| 857 | - $this->errors[] = $langs->trans('AssetErrorClearDepreciationLines') . ': ' . $this->db->lasterror(); |
|
| 857 | + $this->errors[] = $langs->trans('AssetErrorClearDepreciationLines').': '.$this->db->lasterror(); |
|
| 858 | 858 | $error++; |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | if (!$error) { |
| 862 | 862 | // Get fiscal period |
| 863 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; |
|
| 864 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; |
|
| 863 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
|
| 864 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; |
|
| 865 | 865 | $dates = getDefaultDatesForTransfer(); |
| 866 | 866 | $init_fiscal_period_start = $dates['date_start']; |
| 867 | 867 | $init_fiscal_period_end = $dates['date_end']; |
@@ -894,17 +894,17 @@ discard block |
||
| 894 | 894 | */ |
| 895 | 895 | |
| 896 | 896 | $sql = "SELECT ad.depreciation_date, ad.cumulative_depreciation_ht"; |
| 897 | - $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad"; |
|
| 898 | - $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid"; |
|
| 899 | - $sql .= " WHERE ad.fk_asset = " . (int) $this->id; |
|
| 900 | - $sql .= " AND ad.depreciation_mode = '" . $this->db->escape($mode_key) . "'"; |
|
| 897 | + $sql .= " FROM ".MAIN_DB_PREFIX."asset_depreciation AS ad"; |
|
| 898 | + $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid"; |
|
| 899 | + $sql .= " WHERE ad.fk_asset = ".(int) $this->id; |
|
| 900 | + $sql .= " AND ad.depreciation_mode = '".$this->db->escape($mode_key)."'"; |
|
| 901 | 901 | $sql .= " AND iab.fk_docdet IS NOT NULL"; |
| 902 | 902 | $sql .= " ORDER BY ad.depreciation_date DESC"; |
| 903 | 903 | $sql .= " LIMIT 1"; |
| 904 | 904 | |
| 905 | 905 | $resql = $this->db->query($sql); |
| 906 | 906 | if (!$resql) { |
| 907 | - $this->errors[] = $langs->trans('AssetErrorFetchMaxDepreciationDateForMode', $mode_key) . ': ' . $this->db->lasterror(); |
|
| 907 | + $this->errors[] = $langs->trans('AssetErrorFetchMaxDepreciationDateForMode', $mode_key).': '.$this->db->lasterror(); |
|
| 908 | 908 | $error++; |
| 909 | 909 | break; |
| 910 | 910 | } |
@@ -916,26 +916,26 @@ discard block |
||
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | // Set last cumulative depreciation |
| 919 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key]['table']; |
|
| 920 | - $sql .= " SET total_amount_last_depreciation_ht = " . (empty($last_cumulative_depreciation_ht) ? 0 : $last_cumulative_depreciation_ht); |
|
| 921 | - $sql .= " WHERE fk_asset = " . (int) $this->id; |
|
| 919 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$options->deprecation_options_fields[$mode_key]['table']; |
|
| 920 | + $sql .= " SET total_amount_last_depreciation_ht = ".(empty($last_cumulative_depreciation_ht) ? 0 : $last_cumulative_depreciation_ht); |
|
| 921 | + $sql .= " WHERE fk_asset = ".(int) $this->id; |
|
| 922 | 922 | $resql = $this->db->query($sql); |
| 923 | 923 | if (!$resql) { |
| 924 | - $this->errors[] = $langs->trans('AssetErrorSetLastCumulativeDepreciation') . ': ' . $this->db->lasterror(); |
|
| 924 | + $this->errors[] = $langs->trans('AssetErrorSetLastCumulativeDepreciation').': '.$this->db->lasterror(); |
|
| 925 | 925 | $error++; |
| 926 | 926 | break; |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | // Delete old lines |
| 930 | - $sql = "DELETE " . MAIN_DB_PREFIX . "asset_depreciation FROM " . MAIN_DB_PREFIX . "asset_depreciation"; |
|
| 931 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab ON ab.doc_type = 'asset' AND ab.fk_docdet = " . MAIN_DB_PREFIX . "asset_depreciation.rowid"; |
|
| 932 | - $sql .= " WHERE " . MAIN_DB_PREFIX . "asset_depreciation.fk_asset = " . (int) $this->id; |
|
| 933 | - $sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.depreciation_mode = '" . $this->db->escape($mode_key) . "'"; |
|
| 930 | + $sql = "DELETE ".MAIN_DB_PREFIX."asset_depreciation FROM ".MAIN_DB_PREFIX."asset_depreciation"; |
|
| 931 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_bookkeeping as ab ON ab.doc_type = 'asset' AND ab.fk_docdet = ".MAIN_DB_PREFIX."asset_depreciation.rowid"; |
|
| 932 | + $sql .= " WHERE ".MAIN_DB_PREFIX."asset_depreciation.fk_asset = ".(int) $this->id; |
|
| 933 | + $sql .= " AND ".MAIN_DB_PREFIX."asset_depreciation.depreciation_mode = '".$this->db->escape($mode_key)."'"; |
|
| 934 | 934 | $sql .= " AND ab.fk_docdet IS NULL"; |
| 935 | - if ($last_depreciation_date !== "") $sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.ref != ''"; |
|
| 935 | + if ($last_depreciation_date !== "") $sql .= " AND ".MAIN_DB_PREFIX."asset_depreciation.ref != ''"; |
|
| 936 | 936 | $resql = $this->db->query($sql); |
| 937 | 937 | if (!$resql) { |
| 938 | - $this->errors[] = $langs->trans('AssetErrorClearDepreciationLines') . ': ' . $this->db->lasterror(); |
|
| 938 | + $this->errors[] = $langs->trans('AssetErrorClearDepreciationLines').': '.$this->db->lasterror(); |
|
| 939 | 939 | $error++; |
| 940 | 940 | break; |
| 941 | 941 | } |
@@ -1002,7 +1002,7 @@ discard block |
||
| 1002 | 1002 | $first_period_found = false; |
| 1003 | 1003 | $first_period_date = isset($begin_period) && $begin_period > $fiscal_period_start ? $begin_period : $fiscal_period_start; |
| 1004 | 1004 | |
| 1005 | - $ref_date_format = "%Y" . ($fields['duration_type'] == 1 || $fields['duration_type'] == 2 ? '-%m' : '') . ($fields['duration_type'] == 2 ? '-%d' : ''); |
|
| 1005 | + $ref_date_format = "%Y".($fields['duration_type'] == 1 || $fields['duration_type'] == 2 ? '-%m' : '').($fields['duration_type'] == 2 ? '-%d' : ''); |
|
| 1006 | 1006 | |
| 1007 | 1007 | // Loop security |
| 1008 | 1008 | $idx_loop = 0; |
@@ -1022,9 +1022,9 @@ discard block |
||
| 1022 | 1022 | |
| 1023 | 1023 | $period_begin = dol_print_date($fiscal_period_start, $ref_date_format); |
| 1024 | 1024 | $period_end = dol_print_date($fiscal_period_end, $ref_date_format); |
| 1025 | - $ref = $period_begin . ($period_begin != $period_end ? ' - ' . $period_end : ''); |
|
| 1025 | + $ref = $period_begin.($period_begin != $period_end ? ' - '.$period_end : ''); |
|
| 1026 | 1026 | if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end) { |
| 1027 | - $ref .= ' - ' . $langs->transnoentitiesnoconv('AssetDisposal'); |
|
| 1027 | + $ref .= ' - '.$langs->transnoentitiesnoconv('AssetDisposal'); |
|
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | $begin_date = $fiscal_period_start < $start_date && $start_date <= $fiscal_period_end ? $start_date : $fiscal_period_start; |
@@ -1103,7 +1103,7 @@ discard block |
||
| 1103 | 1103 | // Check parameters |
| 1104 | 1104 | $error = 0; |
| 1105 | 1105 | if (empty($asset_depreciation_id)) { |
| 1106 | - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AssetDepreciation") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')'); |
|
| 1106 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AssetDepreciation").' ('.$langs->transnoentitiesnoconv("TechnicalID").')'); |
|
| 1107 | 1107 | $error++; |
| 1108 | 1108 | } |
| 1109 | 1109 | if ($error) { |
@@ -1112,28 +1112,28 @@ discard block |
||
| 1112 | 1112 | |
| 1113 | 1113 | $this->db->begin(); |
| 1114 | 1114 | |
| 1115 | - require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php'; |
|
| 1115 | + require_once DOL_DOCUMENT_ROOT.'/asset/class/assetdepreciationoptions.class.php'; |
|
| 1116 | 1116 | $options = new AssetDepreciationOptions($this->db); |
| 1117 | 1117 | |
| 1118 | 1118 | // Get last depreciation lines save in bookkeeping |
| 1119 | 1119 | //----------------------------------------------------- |
| 1120 | 1120 | $sql = "SELECT fk_asset, depreciation_mode, cumulative_depreciation_ht"; |
| 1121 | - $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation"; |
|
| 1122 | - $sql .= " WHERE rowid = " . (int) $asset_depreciation_id; |
|
| 1121 | + $sql .= " FROM ".MAIN_DB_PREFIX."asset_depreciation"; |
|
| 1122 | + $sql .= " WHERE rowid = ".(int) $asset_depreciation_id; |
|
| 1123 | 1123 | $resql = $this->db->query($sql); |
| 1124 | 1124 | if (!$resql) { |
| 1125 | - $this->errors[] = $langs->trans('AssetErrorFetchCumulativeDepreciation') . ': ' . $this->db->lasterror(); |
|
| 1125 | + $this->errors[] = $langs->trans('AssetErrorFetchCumulativeDepreciation').': '.$this->db->lasterror(); |
|
| 1126 | 1126 | $error++; |
| 1127 | 1127 | } else { |
| 1128 | 1128 | if ($obj = $this->db->fetch_object($resql)) { |
| 1129 | 1129 | $mode_key = $obj->depreciation_mode; |
| 1130 | 1130 | if (!empty($options->deprecation_options_fields[$mode_key])) { |
| 1131 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key]['table']; |
|
| 1132 | - $sql .= " SET total_amount_last_depreciation_ht = " . $obj->cumulative_depreciation_ht; |
|
| 1133 | - $sql .= " WHERE fk_asset = " . (int) $obj->fk_asset; |
|
| 1131 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$options->deprecation_options_fields[$mode_key]['table']; |
|
| 1132 | + $sql .= " SET total_amount_last_depreciation_ht = ".$obj->cumulative_depreciation_ht; |
|
| 1133 | + $sql .= " WHERE fk_asset = ".(int) $obj->fk_asset; |
|
| 1134 | 1134 | $resql = $this->db->query($sql); |
| 1135 | 1135 | if (!$resql) { |
| 1136 | - $this->errors[] = $langs->trans('AssetErrorSetLastCumulativeDepreciation') . ': ' . $this->db->lasterror(); |
|
| 1136 | + $this->errors[] = $langs->trans('AssetErrorSetLastCumulativeDepreciation').': '.$this->db->lasterror(); |
|
| 1137 | 1137 | $error++; |
| 1138 | 1138 | } |
| 1139 | 1139 | } |
@@ -1378,7 +1378,7 @@ discard block |
||
| 1378 | 1378 | if ($withpicto != 2) { |
| 1379 | 1379 | $name = $this->ref; |
| 1380 | 1380 | if ($option == 'label') $name = $this->label; |
| 1381 | - elseif ($option == 'with_label') $name .= ' - ' . $this->label; |
|
| 1381 | + elseif ($option == 'with_label') $name .= ' - '.$this->label; |
|
| 1382 | 1382 | $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name); |
| 1383 | 1383 | } |
| 1384 | 1384 | |
@@ -1386,7 +1386,7 @@ discard block |
||
| 1386 | 1386 | //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); |
| 1387 | 1387 | |
| 1388 | 1388 | global $action; |
| 1389 | - $hookmanager->initHooks(array($this->element . 'dao')); |
|
| 1389 | + $hookmanager->initHooks(array($this->element.'dao')); |
|
| 1390 | 1390 | $parameters = array('id'=>$this->id, 'getnomurl' => &$result); |
| 1391 | 1391 | $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 1392 | 1392 | if ($reshook > 0) { |
@@ -1524,7 +1524,7 @@ discard block |
||
| 1524 | 1524 | if (getDolGlobalString('ASSET_ASSET_ADDON')) { |
| 1525 | 1525 | $mybool = false; |
| 1526 | 1526 | |
| 1527 | - $file = getDolGlobalString('ASSET_ASSET_ADDON') . ".php"; |
|
| 1527 | + $file = getDolGlobalString('ASSET_ASSET_ADDON').".php"; |
|
| 1528 | 1528 | $classname = $conf->global->ASSET_ASSET_ADDON; |
| 1529 | 1529 | |
| 1530 | 1530 | // Include file with class |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | /** |
| 101 | 101 | * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. |
| 102 | 102 | */ |
| 103 | - public $fields=array( |
|
| 103 | + public $fields = array( |
|
| 104 | 104 | 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"), |
| 105 | 105 | 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'validate'=>'1'), |
| 106 | 106 | 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'showoncombobox'=>'2', 'validate'=>'1',), |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | |
| 447 | 447 | // Protection |
| 448 | 448 | if ($this->status == self::STATUS_VALIDATED) { |
| 449 | - dol_syslog(get_class($this) . "::validate action abandonned: already validated", LOG_WARNING); |
|
| 449 | + dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING); |
|
| 450 | 450 | return 0; |
| 451 | 451 | } |
| 452 | 452 | |
@@ -455,17 +455,17 @@ discard block |
||
| 455 | 455 | $this->db->begin(); |
| 456 | 456 | |
| 457 | 457 | // Validate |
| 458 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element; |
|
| 459 | - $sql .= " SET status = " . self::STATUS_VALIDATED; |
|
| 458 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 459 | + $sql .= " SET status = ".self::STATUS_VALIDATED; |
|
| 460 | 460 | if (!empty($this->fields['date_validation'])) { |
| 461 | - $sql .= ", date_validation = '" . $this->db->idate($now) . "'"; |
|
| 461 | + $sql .= ", date_validation = '".$this->db->idate($now)."'"; |
|
| 462 | 462 | } |
| 463 | 463 | if (!empty($this->fields['fk_user_valid'])) { |
| 464 | - $sql .= ", fk_user_valid = " . ((int) $user->id); |
|
| 464 | + $sql .= ", fk_user_valid = ".((int) $user->id); |
|
| 465 | 465 | } |
| 466 | - $sql .= " WHERE rowid = " . ((int) $this->id); |
|
| 466 | + $sql .= " WHERE rowid = ".((int) $this->id); |
|
| 467 | 467 | |
| 468 | - dol_syslog(get_class($this) . "::validate()", LOG_DEBUG); |
|
| 468 | + dol_syslog(get_class($this)."::validate()", LOG_DEBUG); |
|
| 469 | 469 | $resql = $this->db->query($sql); |
| 470 | 470 | if (!$resql) { |
| 471 | 471 | dol_print_error($this->db); |
@@ -90,7 +90,9 @@ discard block |
||
| 90 | 90 | $this->accountancy_codes[$mode_key] = array(); |
| 91 | 91 | foreach ($mode_info['fields'] as $field_key => $field_info) { |
| 92 | 92 | $accountancy_code = GETPOST($mode_key . '_' . $field_key, 'aZ09'); |
| 93 | - if (empty($accountancy_code) || $accountancy_code == '-1') $accountancy_code = ''; |
|
| 93 | + if (empty($accountancy_code) || $accountancy_code == '-1') { |
|
| 94 | + $accountancy_code = ''; |
|
| 95 | + } |
|
| 94 | 96 | $this->accountancy_codes[$mode_key][$field_key] = $accountancy_code; |
| 95 | 97 | } |
| 96 | 98 | } |
@@ -251,7 +253,9 @@ discard block |
||
| 251 | 253 | require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php'; |
| 252 | 254 | $asset = new Asset($this->db); |
| 253 | 255 | $result = $asset->fetch($asset_id); |
| 254 | - if ($result > 0) $result = $asset->calculationDepreciation(); |
|
| 256 | + if ($result > 0) { |
|
| 257 | + $result = $asset->calculationDepreciation(); |
|
| 258 | + } |
|
| 255 | 259 | if ($result < 0) { |
| 256 | 260 | $this->errors[] = $langs->trans('AssetErrorCalculationDepreciationLines'); |
| 257 | 261 | $this->errors[] = $asset->errorsToString(); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | foreach ($this->accountancy_codes_fields as $mode_key => $mode_info) { |
| 90 | 90 | $this->accountancy_codes[$mode_key] = array(); |
| 91 | 91 | foreach ($mode_info['fields'] as $field_key => $field_info) { |
| 92 | - $accountancy_code = GETPOST($mode_key . '_' . $field_key, 'aZ09'); |
|
| 92 | + $accountancy_code = GETPOST($mode_key.'_'.$field_key, 'aZ09'); |
|
| 93 | 93 | if (empty($accountancy_code) || $accountancy_code == '-1') $accountancy_code = ''; |
| 94 | 94 | $this->accountancy_codes[$mode_key][$field_key] = $accountancy_code; |
| 95 | 95 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | public function fetchAccountancyCodes($asset_id = 0, $asset_model_id = 0) |
| 108 | 108 | { |
| 109 | 109 | global $langs, $hookmanager; |
| 110 | - dol_syslog(__METHOD__ . " asset_id=$asset_id, asset_model_id=$asset_model_id"); |
|
| 110 | + dol_syslog(__METHOD__." asset_id=$asset_id, asset_model_id=$asset_model_id"); |
|
| 111 | 111 | |
| 112 | 112 | $error = 0; |
| 113 | 113 | $this->errors = array(); |
@@ -130,15 +130,15 @@ discard block |
||
| 130 | 130 | $error++; |
| 131 | 131 | } |
| 132 | 132 | if ($error) { |
| 133 | - dol_syslog(__METHOD__ . " Error check parameters: " . $this->errorsToString(), LOG_ERR); |
|
| 133 | + dol_syslog(__METHOD__." Error check parameters: ".$this->errorsToString(), LOG_ERR); |
|
| 134 | 134 | return -1; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $accountancy_codes = array(); |
| 138 | 138 | foreach ($this->accountancy_codes_fields as $mode_key => $mode_info) { |
| 139 | - $sql = "SELECT " . implode(',', array_keys($mode_info['fields'])); |
|
| 140 | - $sql .= " FROM " . MAIN_DB_PREFIX . $mode_info['table']; |
|
| 141 | - $sql .= " WHERE " . ($asset_id > 0 ? " fk_asset = " . (int) $asset_id : " fk_asset_model = " . (int) $asset_model_id); |
|
| 139 | + $sql = "SELECT ".implode(',', array_keys($mode_info['fields'])); |
|
| 140 | + $sql .= " FROM ".MAIN_DB_PREFIX.$mode_info['table']; |
|
| 141 | + $sql .= " WHERE ".($asset_id > 0 ? " fk_asset = ".(int) $asset_id : " fk_asset_model = ".(int) $asset_model_id); |
|
| 142 | 142 | |
| 143 | 143 | $resql = $this->db->query($sql); |
| 144 | 144 | if ($resql) { |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | } else { |
| 152 | - $this->errors[] = $langs->trans('AssetErrorFetchAccountancyCodesForMode', $mode_key) . ': ' . $this->db->lasterror(); |
|
| 152 | + $this->errors[] = $langs->trans('AssetErrorFetchAccountancyCodesForMode', $mode_key).': '.$this->db->lasterror(); |
|
| 153 | 153 | $error++; |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if ($error) { |
| 158 | - dol_syslog(__METHOD__ . " Error fetch accountancy codes: " . $this->errorsToString(), LOG_ERR); |
|
| 158 | + dol_syslog(__METHOD__." Error fetch accountancy codes: ".$this->errorsToString(), LOG_ERR); |
|
| 159 | 159 | return -1; |
| 160 | 160 | } else { |
| 161 | 161 | $this->accountancy_codes = $accountancy_codes; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | public function updateAccountancyCodes($user, $asset_id = 0, $asset_model_id = 0, $notrigger = 0) |
| 176 | 176 | { |
| 177 | 177 | global $langs, $hookmanager; |
| 178 | - dol_syslog(__METHOD__ . " user_id=".$user->id.", asset_id=".$asset_id.", asset_model_id=".$asset_model_id.", notrigger=".$notrigger); |
|
| 178 | + dol_syslog(__METHOD__." user_id=".$user->id.", asset_id=".$asset_id.", asset_model_id=".$asset_model_id.", notrigger=".$notrigger); |
|
| 179 | 179 | |
| 180 | 180 | $error = 0; |
| 181 | 181 | $this->errors = array(); |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $error++; |
| 198 | 198 | } |
| 199 | 199 | if ($error) { |
| 200 | - dol_syslog(__METHOD__ . " Error check parameters: " . $this->errorsToString(), LOG_ERR); |
|
| 200 | + dol_syslog(__METHOD__." Error check parameters: ".$this->errorsToString(), LOG_ERR); |
|
| 201 | 201 | return -1; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -206,32 +206,32 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | foreach ($this->accountancy_codes_fields as $mode_key => $mode_info) { |
| 208 | 208 | // Delete old accountancy codes |
| 209 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $mode_info['table']; |
|
| 210 | - $sql .= " WHERE " . ($asset_id > 0 ? " fk_asset = " . (int) $asset_id : " fk_asset_model = " . (int) $asset_model_id); |
|
| 209 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$mode_info['table']; |
|
| 210 | + $sql .= " WHERE ".($asset_id > 0 ? " fk_asset = ".(int) $asset_id : " fk_asset_model = ".(int) $asset_model_id); |
|
| 211 | 211 | $resql = $this->db->query($sql); |
| 212 | 212 | if (!$resql) { |
| 213 | - $this->errors[] = $langs->trans('AssetErrorDeleteAccountancyCodesForMode', $mode_key) . ': ' . $this->db->lasterror(); |
|
| 213 | + $this->errors[] = $langs->trans('AssetErrorDeleteAccountancyCodesForMode', $mode_key).': '.$this->db->lasterror(); |
|
| 214 | 214 | $error++; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | if (!$error && !empty($this->accountancy_codes[$mode_key])) { |
| 218 | 218 | // Insert accountancy codes |
| 219 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . $mode_info['table'] . "("; |
|
| 219 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$mode_info['table']."("; |
|
| 220 | 220 | $sql .= $asset_id > 0 ? "fk_asset," : "fk_asset_model,"; |
| 221 | 221 | $sql .= implode(',', array_keys($mode_info['fields'])); |
| 222 | 222 | $sql .= ", tms, fk_user_modif"; |
| 223 | 223 | $sql .= ") VALUES("; |
| 224 | 224 | $sql .= $asset_id > 0 ? $asset_id : $asset_model_id; |
| 225 | 225 | foreach ($mode_info['fields'] as $field_key => $field_info) { |
| 226 | - $sql .= ', ' . (empty($this->accountancy_codes[$mode_key][$field_key]) ? 'NULL' : "'" . $this->db->escape($this->accountancy_codes[$mode_key][$field_key]) . "'"); |
|
| 226 | + $sql .= ', '.(empty($this->accountancy_codes[$mode_key][$field_key]) ? 'NULL' : "'".$this->db->escape($this->accountancy_codes[$mode_key][$field_key])."'"); |
|
| 227 | 227 | } |
| 228 | - $sql .= ", '" . $this->db->idate($now) . "'"; |
|
| 229 | - $sql .= ", " . $user->id; |
|
| 228 | + $sql .= ", '".$this->db->idate($now)."'"; |
|
| 229 | + $sql .= ", ".$user->id; |
|
| 230 | 230 | $sql .= ")"; |
| 231 | 231 | |
| 232 | 232 | $resql = $this->db->query($sql); |
| 233 | 233 | if (!$resql) { |
| 234 | - $this->errors[] = $langs->trans('AssetErrorInsertAccountancyCodesForMode', $mode_key) . ': ' . $this->db->lasterror(); |
|
| 234 | + $this->errors[] = $langs->trans('AssetErrorInsertAccountancyCodesForMode', $mode_key).': '.$this->db->lasterror(); |
|
| 235 | 235 | $error++; |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | if (!$error && $asset_id > 0) { |
| 241 | 241 | // Calculation of depreciation lines (reversal and future) |
| 242 | - require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php'; |
|
| 242 | + require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php'; |
|
| 243 | 243 | $asset = new Asset($this->db); |
| 244 | 244 | $result = $asset->fetch($asset_id); |
| 245 | 245 | if ($result > 0) $result = $asset->calculationDepreciation(); |