|
@@ -258,89 +258,89 @@ class Asset extends CommonObject
|
|
|
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
|
|
|
|
-// $object = new self($this->db);
|
|
|
-//
|
|
|
-// $this->db->begin();
|
|
|
-//
|
|
|
-// // Load source object
|
|
|
-// $result = $object->fetchCommon($fromid);
|
|
|
-// if ($result > 0 && !empty($object->table_element_line)) {
|
|
|
-// $object->fetchLines();
|
|
|
-// }
|
|
|
-//
|
|
|
-// // get lines so they will be clone
|
|
|
-// //foreach($this->lines as $line)
|
|
|
-// // $line->fetch_optionals();
|
|
|
-//
|
|
|
-// // Reset some properties
|
|
|
-// unset($object->id);
|
|
|
-// unset($object->fk_user_creat);
|
|
|
-// unset($object->import_key);
|
|
|
-//
|
|
|
-// // Clear fields
|
|
|
-// if (property_exists($object, 'ref')) {
|
|
|
-// $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
|
|
|
-// }
|
|
|
-// if (property_exists($object, 'label')) {
|
|
|
-// $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
|
|
|
-// }
|
|
|
-// if (property_exists($object, 'status')) {
|
|
|
-// $object->status = self::STATUS_DRAFT;
|
|
|
-// }
|
|
|
-// if (property_exists($object, 'date_creation')) {
|
|
|
-// $object->date_creation = dol_now();
|
|
|
-// }
|
|
|
-// if (property_exists($object, 'date_modification')) {
|
|
|
-// $object->date_modification = null;
|
|
|
-// }
|
|
|
-// // ...
|
|
|
-// // Clear extrafields that are unique
|
|
|
-// if (is_array($object->array_options) && count($object->array_options) > 0) {
|
|
|
-// $extrafields->fetch_name_optionals_label($this->table_element);
|
|
|
-// foreach ($object->array_options as $key => $option) {
|
|
|
-// $shortkey = preg_replace('/options_/', '', $key);
|
|
|
-// if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
|
|
|
-// //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
|
|
|
-// unset($object->array_options[$key]);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // Create clone
|
|
|
-// $object->context['createfromclone'] = 'createfromclone';
|
|
|
-// $result = $object->createCommon($user);
|
|
|
-// if ($result < 0) {
|
|
|
-// $error++;
|
|
|
-// $this->error = $object->error;
|
|
|
-// $this->errors = $object->errors;
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (!$error) {
|
|
|
-// // copy internal contacts
|
|
|
-// if ($this->copy_linked_contact($object, 'internal') < 0) {
|
|
|
-// $error++;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (!$error) {
|
|
|
-// // copy external contacts if same company
|
|
|
-// if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
|
|
|
-// if ($this->copy_linked_contact($object, 'external') < 0) {
|
|
|
-// $error++;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// unset($object->context['createfromclone']);
|
|
|
-//
|
|
|
-// // End
|
|
|
-// if (!$error) {
|
|
|
-// $this->db->commit();
|
|
|
-// return $object;
|
|
|
-// } else {
|
|
|
-// $this->db->rollback();
|
|
|
-// return -1;
|
|
|
-// }
|
|
|
+ // $object = new self($this->db);
|
|
|
+ //
|
|
|
+ // $this->db->begin();
|
|
|
+ //
|
|
|
+ // // Load source object
|
|
|
+ // $result = $object->fetchCommon($fromid);
|
|
|
+ // if ($result > 0 && !empty($object->table_element_line)) {
|
|
|
+ // $object->fetchLines();
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // get lines so they will be clone
|
|
|
+ // //foreach($this->lines as $line)
|
|
|
+ // // $line->fetch_optionals();
|
|
|
+ //
|
|
|
+ // // Reset some properties
|
|
|
+ // unset($object->id);
|
|
|
+ // unset($object->fk_user_creat);
|
|
|
+ // unset($object->import_key);
|
|
|
+ //
|
|
|
+ // // Clear fields
|
|
|
+ // if (property_exists($object, 'ref')) {
|
|
|
+ // $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
|
|
|
+ // }
|
|
|
+ // if (property_exists($object, 'label')) {
|
|
|
+ // $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
|
|
|
+ // }
|
|
|
+ // if (property_exists($object, 'status')) {
|
|
|
+ // $object->status = self::STATUS_DRAFT;
|
|
|
+ // }
|
|
|
+ // if (property_exists($object, 'date_creation')) {
|
|
|
+ // $object->date_creation = dol_now();
|
|
|
+ // }
|
|
|
+ // if (property_exists($object, 'date_modification')) {
|
|
|
+ // $object->date_modification = null;
|
|
|
+ // }
|
|
|
+ // // ...
|
|
|
+ // // Clear extrafields that are unique
|
|
|
+ // if (is_array($object->array_options) && count($object->array_options) > 0) {
|
|
|
+ // $extrafields->fetch_name_optionals_label($this->table_element);
|
|
|
+ // foreach ($object->array_options as $key => $option) {
|
|
|
+ // $shortkey = preg_replace('/options_/', '', $key);
|
|
|
+ // if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
|
|
|
+ // //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
|
|
|
+ // unset($object->array_options[$key]);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // Create clone
|
|
|
+ // $object->context['createfromclone'] = 'createfromclone';
|
|
|
+ // $result = $object->createCommon($user);
|
|
|
+ // if ($result < 0) {
|
|
|
+ // $error++;
|
|
|
+ // $this->error = $object->error;
|
|
|
+ // $this->errors = $object->errors;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if (!$error) {
|
|
|
+ // // copy internal contacts
|
|
|
+ // if ($this->copy_linked_contact($object, 'internal') < 0) {
|
|
|
+ // $error++;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if (!$error) {
|
|
|
+ // // copy external contacts if same company
|
|
|
+ // if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
|
|
|
+ // if ($this->copy_linked_contact($object, 'external') < 0) {
|
|
|
+ // $error++;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // unset($object->context['createfromclone']);
|
|
|
+ //
|
|
|
+ // // End
|
|
|
+ // if (!$error) {
|
|
|
+ // $this->db->commit();
|
|
|
+ // return $object;
|
|
|
+ // } else {
|
|
|
+ // $this->db->rollback();
|
|
|
+ // return -1;
|
|
|
+ // }
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -656,7 +656,7 @@ class Asset extends CommonObject
|
|
|
$sql .= " WHERE doc_type = 'asset'";
|
|
|
$sql .= ")";
|
|
|
$sql .= "SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht";
|
|
|
- $sql .= ", " . $this->db->ifsql('iab.fk_docdet IS NOT NULL', 1 , 0) . " AS bookkeeping";
|
|
|
+ $sql .= ", " . $this->db->ifsql('iab.fk_docdet IS NOT NULL', 1, 0) . " AS bookkeeping";
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad";
|
|
|
$sql .= " LEFT JOIN in_accounting_bookkeeping as iab ON iab.fk_docdet = ad.rowid";
|
|
|
$sql .= " WHERE ad.fk_asset = " . $this->id;
|
|
@@ -766,12 +766,12 @@ class Asset extends CommonObject
|
|
|
|
|
|
$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)";
|
|
|
$sql .= " VALUES ( ";
|
|
|
- $sql .= " " . (int)$this->id;
|
|
|
+ $sql .= " " . (int) $this->id;
|
|
|
$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 .= ", " . (double) $depreciation_ht;
|
|
|
+ $sql .= ", " . (double) $cumulative_depreciation_ht;
|
|
|
$sql .= ", '" . $this->db->escape($accountancy_code_debit) . "'";
|
|
|
$sql .= ", '" . $this->db->escape($accountancy_code_credit) . "'";
|
|
|
$sql .= ")";
|
|
@@ -919,18 +919,18 @@ class Asset extends CommonObject
|
|
|
$depreciation_date_start = $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition;
|
|
|
$depreciation_date_end = dol_time_plus_duree($depreciation_date_start, $fields['duration'], $fields['duration_type'] == 1 ? 'm' : ($fields['duration_type'] == 2 ? 'd' : 'y'));
|
|
|
$depreciation_amount = $fields['amount_base_depreciation_ht'];
|
|
|
- if ($fields['duration_type'] == 2) { // Daily
|
|
|
- $fiscal_period_start = $depreciation_date_start;
|
|
|
- $fiscal_period_end = $depreciation_date_start;
|
|
|
- } elseif ($fields['duration_type'] == 1) { // Monthly
|
|
|
- $date_temp = dol_getdate($depreciation_date_start);
|
|
|
- $fiscal_period_start = dol_get_first_day($date_temp['year'], $date_temp['mon'], false);
|
|
|
- $fiscal_period_end = dol_get_last_day($date_temp['year'], $date_temp['mon'], false);
|
|
|
- } else { // Annually
|
|
|
- $fiscal_period_start = $init_fiscal_period_start;
|
|
|
- $fiscal_period_end = $init_fiscal_period_end;
|
|
|
- }
|
|
|
- $cumulative_depreciation_ht = $last_cumulative_depreciation_ht;
|
|
|
+ if ($fields['duration_type'] == 2) { // Daily
|
|
|
+ $fiscal_period_start = $depreciation_date_start;
|
|
|
+ $fiscal_period_end = $depreciation_date_start;
|
|
|
+ } elseif ($fields['duration_type'] == 1) { // Monthly
|
|
|
+ $date_temp = dol_getdate($depreciation_date_start);
|
|
|
+ $fiscal_period_start = dol_get_first_day($date_temp['year'], $date_temp['mon'], false);
|
|
|
+ $fiscal_period_end = dol_get_last_day($date_temp['year'], $date_temp['mon'], false);
|
|
|
+ } else { // Annually
|
|
|
+ $fiscal_period_start = $init_fiscal_period_start;
|
|
|
+ $fiscal_period_end = $init_fiscal_period_end;
|
|
|
+ }
|
|
|
+ $cumulative_depreciation_ht = $last_cumulative_depreciation_ht;
|
|
|
$depreciation_period_amount = $depreciation_amount - $this->reversal_amount_ht;
|
|
|
$start_date = $depreciation_date_start;
|
|
|
$disposal_date = isset($this->disposal_date) && $this->disposal_date !== "" ? $this->disposal_date : "";
|
|
@@ -972,12 +972,12 @@ class Asset extends CommonObject
|
|
|
// futures depreciation lines
|
|
|
//-----------------------------------------------------
|
|
|
$nb_days_in_year = !empty($conf->global->ASSET_DEPRECIATION_DURATION_PER_YEAR) ? $conf->global->ASSET_DEPRECIATION_DURATION_PER_YEAR : 360;
|
|
|
- $nb_days_in_month = !empty($conf->global->ASSET_DEPRECIATION_DURATION_PER_MONTH) ? $conf->global->ASSET_DEPRECIATION_DURATION_PER_MONTH : 30;
|
|
|
- $period_amount = (double) price2num($depreciation_period_amount / $fields['duration'], 'MT');
|
|
|
- $first_period_found = false;
|
|
|
+ $nb_days_in_month = !empty($conf->global->ASSET_DEPRECIATION_DURATION_PER_MONTH) ? $conf->global->ASSET_DEPRECIATION_DURATION_PER_MONTH : 30;
|
|
|
+ $period_amount = (double) price2num($depreciation_period_amount / $fields['duration'], 'MT');
|
|
|
+ $first_period_found = false;
|
|
|
$first_period_date = isset($begin_period) && $begin_period > $fiscal_period_start ? $begin_period : $fiscal_period_start;
|
|
|
|
|
|
- $ref_date_format = "%Y" . ($fields['duration_type'] == 1 || $fields['duration_type'] == 2 ? '-%m' : '') . ($fields['duration_type'] == 2 ? '-%d' : '');
|
|
|
+ $ref_date_format = "%Y" . ($fields['duration_type'] == 1 || $fields['duration_type'] == 2 ? '-%m' : '') . ($fields['duration_type'] == 2 ? '-%d' : '');
|
|
|
|
|
|
// Loop security
|
|
|
$idx_loop = 0;
|
|
@@ -995,8 +995,8 @@ class Asset extends CommonObject
|
|
|
|
|
|
$first_period_found = true;
|
|
|
|
|
|
- $period_begin = dol_print_date($fiscal_period_start, $ref_date_format);
|
|
|
- $period_end = dol_print_date($fiscal_period_end, $ref_date_format);
|
|
|
+ $period_begin = dol_print_date($fiscal_period_start, $ref_date_format);
|
|
|
+ $period_end = dol_print_date($fiscal_period_end, $ref_date_format);
|
|
|
$ref = $period_begin . ($period_begin != $period_end ? ' - ' . $period_end : '');
|
|
|
if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end) {
|
|
|
$ref .= ' - ' . $langs->transnoentitiesnoconv('AssetDisposal');
|
|
@@ -1004,24 +1004,24 @@ class Asset extends CommonObject
|
|
|
|
|
|
$begin_date = $fiscal_period_start < $start_date && $start_date <= $fiscal_period_end ? $start_date : $fiscal_period_start;
|
|
|
$end_date = $fiscal_period_start < $finish_date && $finish_date <= $fiscal_period_end ? $finish_date : $fiscal_period_end;
|
|
|
- if ($fields['duration_type'] == 2) { // Daily
|
|
|
- $depreciation_ht = $period_amount;
|
|
|
- } elseif ($fields['duration_type'] == 1) { // Monthly
|
|
|
- $nb_days = min($nb_days_in_month, num_between_day($begin_date, $end_date, 1));
|
|
|
- if ($nb_days >= 28) {
|
|
|
- $date_temp = dol_getdate($begin_date);
|
|
|
- if ($date_temp['mon'] == 2) {
|
|
|
- $nb_days = 30;
|
|
|
- }
|
|
|
- }
|
|
|
- $depreciation_ht = (double) 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');
|
|
|
- }
|
|
|
-
|
|
|
- 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');
|
|
|
+ if ($fields['duration_type'] == 2) { // Daily
|
|
|
+ $depreciation_ht = $period_amount;
|
|
|
+ } elseif ($fields['duration_type'] == 1) { // Monthly
|
|
|
+ $nb_days = min($nb_days_in_month, num_between_day($begin_date, $end_date, 1));
|
|
|
+ if ($nb_days >= 28) {
|
|
|
+ $date_temp = dol_getdate($begin_date);
|
|
|
+ if ($date_temp['mon'] == 2) {
|
|
|
+ $nb_days = 30;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $depreciation_ht = (double) 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');
|
|
|
+ }
|
|
|
+
|
|
|
+ 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');
|
|
|
$cumulative_depreciation_ht = $depreciation_amount;
|
|
|
} else {
|
|
|
$cumulative_depreciation_ht += $depreciation_ht;
|
|
@@ -1034,15 +1034,15 @@ class Asset extends CommonObject
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Next fiscal period (+1 day/month/year)
|
|
|
+ // Next fiscal period (+1 day/month/year)
|
|
|
$fiscal_period_start = dol_time_plus_duree($fiscal_period_end, 1, 'd');
|
|
|
- if ($fields['duration_type'] == 2) { // Daily
|
|
|
- $fiscal_period_end = $fiscal_period_start;
|
|
|
- } elseif ($fields['duration_type'] == 1) { // Monthly
|
|
|
- $fiscal_period_end = dol_time_plus_duree(dol_time_plus_duree($fiscal_period_start, 1, 'm'), -1, 'd');
|
|
|
- } else { // Annually
|
|
|
- $fiscal_period_end = dol_time_plus_duree(dol_time_plus_duree($fiscal_period_start, 1, 'y'), -1, 'd');
|
|
|
- }
|
|
|
+ if ($fields['duration_type'] == 2) { // Daily
|
|
|
+ $fiscal_period_end = $fiscal_period_start;
|
|
|
+ } elseif ($fields['duration_type'] == 1) { // Monthly
|
|
|
+ $fiscal_period_end = dol_time_plus_duree(dol_time_plus_duree($fiscal_period_start, 1, 'm'), -1, 'd');
|
|
|
+ } else { // Annually
|
|
|
+ $fiscal_period_end = dol_time_plus_duree(dol_time_plus_duree($fiscal_period_start, 1, 'y'), -1, 'd');
|
|
|
+ }
|
|
|
$last_period_date = $disposal_date !== "" && $disposal_date < $depreciation_date_end ? $disposal_date : $depreciation_date_end;
|
|
|
} while ($fiscal_period_start < $last_period_date);
|
|
|
|
|
@@ -1561,31 +1561,31 @@ class Asset extends CommonObject
|
|
|
* @param null|array $moreparams Array to provide more information
|
|
|
* @return int 0 if KO, 1 if OK
|
|
|
*/
|
|
|
-// public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
|
|
|
-// {
|
|
|
-// global $conf, $langs;
|
|
|
-//
|
|
|
-// $result = 0;
|
|
|
-// $includedocgeneration = 1;
|
|
|
-//
|
|
|
-// $langs->load("asset@asset");
|
|
|
-//
|
|
|
-// if (!dol_strlen($modele)) {
|
|
|
-// $modele = 'standard_asset';
|
|
|
-//
|
|
|
-// if (!empty($this->model_pdf)) {
|
|
|
-// $modele = $this->model_pdf;
|
|
|
-// } elseif (!empty($conf->global->ASSET_ADDON_PDF)) {
|
|
|
-// $modele = $conf->global->ASSET_ADDON_PDF;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// $modelpath = "core/modules/asset/doc/";
|
|
|
-//
|
|
|
-// if ($includedocgeneration && !empty($modele)) {
|
|
|
-// $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return $result;
|
|
|
-// }
|
|
|
+ // public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
|
|
|
+ // {
|
|
|
+ // global $conf, $langs;
|
|
|
+ //
|
|
|
+ // $result = 0;
|
|
|
+ // $includedocgeneration = 1;
|
|
|
+ //
|
|
|
+ // $langs->load("asset@asset");
|
|
|
+ //
|
|
|
+ // if (!dol_strlen($modele)) {
|
|
|
+ // $modele = 'standard_asset';
|
|
|
+ //
|
|
|
+ // if (!empty($this->model_pdf)) {
|
|
|
+ // $modele = $this->model_pdf;
|
|
|
+ // } elseif (!empty($conf->global->ASSET_ADDON_PDF)) {
|
|
|
+ // $modele = $conf->global->ASSET_ADDON_PDF;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // $modelpath = "core/modules/asset/doc/";
|
|
|
+ //
|
|
|
+ // if ($includedocgeneration && !empty($modele)) {
|
|
|
+ // $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // return $result;
|
|
|
+ // }
|
|
|
}
|