Merge branch 'develop' into patch-7

This commit is contained in:
Frédéric FRANCE
2023-12-04 12:53:26 +01:00
committed by GitHub
843 changed files with 6461 additions and 4652 deletions

View File

@@ -217,14 +217,20 @@ class Asset extends CommonObject
*/
public function create(User $user, $notrigger = false)
{
if (!isset($this->date_start) || $this->date_start === "") $this->date_start = $this->date_acquisition;
if (!isset($this->date_start) || $this->date_start === "") {
$this->date_start = $this->date_acquisition;
}
$this->db->begin();
$result = $result_create = $this->createCommon($user, $notrigger);
if ($result > 0 && $this->fk_asset_model > 0) $result = $this->setDataFromAssetModel($user, $notrigger);
if ($result > 0 && $this->fk_asset_model > 0) {
$result = $this->setDataFromAssetModel($user, $notrigger);
}
if ($result > 0) {
if ($this->supplier_invoice_id > 0) $this->add_object_linked('invoice_supplier', $this->supplier_invoice_id);
if ($this->supplier_invoice_id > 0) {
$this->add_object_linked('invoice_supplier', $this->supplier_invoice_id);
}
}
if ($result < 0) {
@@ -347,7 +353,9 @@ class Asset extends CommonObject
{
$result = $this->fetchCommon($id, $ref);
if ($result > 0) {
if (!empty($this->table_element_line)) $this->fetchLines();
if (!empty($this->table_element_line)) {
$this->fetchLines();
}
$res = $this->hasDepreciationLinesInBookkeeping();
if ($res < 0) {
@@ -466,7 +474,9 @@ class Asset extends CommonObject
*/
public function update(User $user, $notrigger = false)
{
if (!isset($this->date_start) || $this->date_start === "") $this->date_start = $this->date_acquisition;
if (!isset($this->date_start) || $this->date_start === "") {
$this->date_start = $this->date_acquisition;
}
$this->db->begin();
@@ -475,12 +485,12 @@ class Asset extends CommonObject
$result = $this->setDataFromAssetModel($user, $notrigger);
}
if ($result > 0 && (
$this->date_start != $this->oldcopy->date_start ||
$this->date_start != $this->oldcopy->date_start ||
$this->acquisition_value_ht != $this->oldcopy->acquisition_value_ht ||
$this->reversal_date != $this->oldcopy->reversal_date ||
$this->reversal_amount_ht != $this->oldcopy->reversal_amount_ht ||
($this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model)
)
)
) {
$result = $this->calculationDepreciation();
}
@@ -671,7 +681,9 @@ class Asset extends CommonObject
}
while ($obj = $this->db->fetch_object($resql)) {
if (!isset($this->depreciation_lines[$obj->depreciation_mode])) $this->depreciation_lines[$obj->depreciation_mode] = array();
if (!isset($this->depreciation_lines[$obj->depreciation_mode])) {
$this->depreciation_lines[$obj->depreciation_mode] = array();
}
$this->depreciation_lines[$obj->depreciation_mode][] = array(
'id' => $obj->rowid,
'ref' => $obj->ref,
@@ -781,8 +793,8 @@ class Asset extends CommonObject
$sql .= ", '" . $this->db->escape($mode) . "'";
$sql .= ", '" . $this->db->escape($ref) . "'";
$sql .= ", '" . $this->db->idate($depreciation_date) . "'";
$sql .= ", " . (double) $depreciation_ht;
$sql .= ", " . (double) $cumulative_depreciation_ht;
$sql .= ", " . (float) $depreciation_ht;
$sql .= ", " . (float) $cumulative_depreciation_ht;
$sql .= ", '" . $this->db->escape($accountancy_code_debit) . "'";
$sql .= ", '" . $this->db->escape($accountancy_code_credit) . "'";
$sql .= ")";
@@ -932,7 +944,9 @@ class Asset extends CommonObject
$sql .= " WHERE " . MAIN_DB_PREFIX . "asset_depreciation.fk_asset = " . (int) $this->id;
$sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.depreciation_mode = '" . $this->db->escape($mode_key) . "'";
$sql .= " AND ab.fk_docdet IS NULL";
if ($last_depreciation_date !== "") $sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.ref != ''";
if ($last_depreciation_date !== "") {
$sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.ref != ''";
}
$resql = $this->db->query($sql);
if (!$resql) {
$this->errors[] = $langs->trans('AssetErrorClearDepreciationLines') . ': ' . $this->db->lasterror();
@@ -998,7 +1012,7 @@ class Asset extends CommonObject
//-----------------------------------------------------
$nb_days_in_year = getDolGlobalString('ASSET_DEPRECIATION_DURATION_PER_YEAR') ? $conf->global->ASSET_DEPRECIATION_DURATION_PER_YEAR : 365;
$nb_days_in_month = getDolGlobalString('ASSET_DEPRECIATION_DURATION_PER_MONTH') ? $conf->global->ASSET_DEPRECIATION_DURATION_PER_MONTH : 30;
$period_amount = (double) price2num($depreciation_period_amount / $fields['duration'], 'MT');
$period_amount = (float) price2num($depreciation_period_amount / $fields['duration'], 'MT');
$first_period_found = false;
// TODO fix declaration of $begin_period
// @phpstan-ignore-next-line
@@ -1012,7 +1026,9 @@ class Asset extends CommonObject
do {
// Loop security
$idx_loop++;
if ($idx_loop > $max_loop) break;
if ($idx_loop > $max_loop) {
break;
}
if ($last_depreciation_date < $fiscal_period_end && ($first_period_date <= $start_date || $first_period_found)) {
// Disposal not depreciated
@@ -1041,14 +1057,14 @@ class Asset extends CommonObject
$nb_days = 30;
}
}
$depreciation_ht = (double) price2num($period_amount * $nb_days / $nb_days_in_month, 'MT');
$depreciation_ht = (float) price2num($period_amount * $nb_days / $nb_days_in_month, 'MT');
} else { // Annually
$nb_days = min($nb_days_in_year, num_between_day($begin_date, $end_date, 1));
$depreciation_ht = (double) price2num($period_amount * $nb_days / $nb_days_in_year, 'MT');
$depreciation_ht = (float) price2num($period_amount * $nb_days / $nb_days_in_year, 'MT');
}
if ($fiscal_period_start <= $depreciation_date_end && $depreciation_date_end <= $fiscal_period_end) { // last period
$depreciation_ht = (double) price2num($depreciation_amount - $cumulative_depreciation_ht, 'MT');
$depreciation_ht = (float) price2num($depreciation_amount - $cumulative_depreciation_ht, 'MT');
$cumulative_depreciation_ht = $depreciation_amount;
} else {
$cumulative_depreciation_ht += $depreciation_ht;
@@ -1179,10 +1195,14 @@ class Asset extends CommonObject
$this->fields[$field]['notnull'] = 0;
}
if ($result > 0) {
if ($disposal_invoice_id > 0) $this->add_object_linked('facture', $disposal_invoice_id);
if ($disposal_invoice_id > 0) {
$this->add_object_linked('facture', $disposal_invoice_id);
}
$result = $this->setStatusCommon($user, self::STATUS_DISPOSED, $notrigger, 'ASSET_DISPOSED');
}
if ($result > 0) $result = $this->calculationDepreciation();
if ($result > 0) {
$result = $this->calculationDepreciation();
}
if ($result < 0) {
$this->db->rollback();
@@ -1245,7 +1265,9 @@ class Asset extends CommonObject
$this->deleteObjectLinked(null, 'facture');
$result = $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'ASSET_REOPEN');
}
if ($result > 0) $result = $this->calculationDepreciation();
if ($result > 0) {
$result = $this->calculationDepreciation();
}
if ($result < 0) {
$this->db->rollback();
@@ -1379,8 +1401,11 @@ class Asset extends CommonObject
if ($withpicto != 2) {
$name = $this->ref;
if ($option == 'label') $name = $this->label;
elseif ($option == 'with_label') $name .= ' - ' . $this->label;
if ($option == 'label') {
$name = $this->label;
} elseif ($option == 'with_label') {
$name .= ' - ' . $this->label;
}
$result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name);
}