24 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $accountancy_codes_fields = array(
38 'label' =>
'AssetAccountancyCodeDepreciationEconomic',
39 'table' =>
'asset_accountancy_codes_economic',
40 'depreciation_debit' =>
'depreciation_asset',
41 'depreciation_credit' =>
'depreciation_expense',
43 'asset' => array(
'label' =>
'AssetAccountancyCodeAsset'),
44 'depreciation_asset' => array(
'label' =>
'AssetAccountancyCodeDepreciationAsset'),
45 'depreciation_expense' => array(
'label' =>
'AssetAccountancyCodeDepreciationExpense'),
46 'value_asset_sold' => array(
'label' =>
'AssetAccountancyCodeValueAssetSold'),
47 'receivable_on_assignment' => array(
'label' =>
'AssetAccountancyCodeReceivableOnAssignment'),
48 'proceeds_from_sales' => array(
'label' =>
'AssetAccountancyCodeProceedsFromSales'),
49 'vat_collected' => array(
'label' =>
'AssetAccountancyCodeVatCollected'),
50 'vat_deductible' => array(
'label' =>
'AssetAccountancyCodeVatDeductible'),
53 'accelerated_depreciation' => array(
54 'label' =>
'AssetAccountancyCodeDepreciationAcceleratedDepreciation',
55 'table' =>
'asset_accountancy_codes_fiscal',
56 'depreciation_debit' =>
'accelerated_depreciation',
57 'depreciation_credit' =>
'endowment_accelerated_depreciation',
59 'accelerated_depreciation' => array(
'label' =>
'AssetAccountancyCodeAcceleratedDepreciation'),
60 'endowment_accelerated_depreciation' => array(
'label' =>
'AssetAccountancyCodeEndowmentAcceleratedDepreciation'),
61 'provision_accelerated_depreciation' => array(
'label' =>
'AssetAccountancyCodeProvisionAcceleratedDepreciation'),
69 public $accountancy_codes = array();
88 $this->accountancy_codes = array();
89 foreach ($this->accountancy_codes_fields as $mode_key => $mode_info) {
90 $this->accountancy_codes[$mode_key] = array();
91 foreach ($mode_info[
'fields'] as $field_key => $field_info) {
92 $accountancy_code =
GETPOST($mode_key .
'_' . $field_key,
'aZ09');
93 if (empty($accountancy_code) || $accountancy_code ==
'-1') $accountancy_code =
'';
94 $this->accountancy_codes[$mode_key][$field_key] = $accountancy_code;
108 global $langs, $hookmanager;
109 dol_syslog(__METHOD__ .
" asset_id=$asset_id, asset_model_id=$asset_model_id");
112 $this->errors = array();
113 $this->accountancy_codes = array();
116 $asset_id = $asset_id > 0 ? $asset_id : 0;
117 $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0;
119 if (!is_object($hookmanager)) {
120 require_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
124 $hookmanager->initHooks(array(
'assetaccountancycodesdao'));
125 $parameters = array(
'asset_id' => $asset_id,
'asset_model_id' => $asset_model_id);
126 $reshook = $hookmanager->executeHooks(
'fetchAccountancyCodes', $parameters, $this);
127 if (!empty($reshook)) {
132 if (empty($asset_id) && empty($asset_model_id)) {
133 $this->errors[] = $langs->trans(
'AssetErrorAssetOrAssetModelIDNotProvide');
141 $accountancy_codes = array();
142 foreach ($this->accountancy_codes_fields as $mode_key => $mode_info) {
143 $sql =
"SELECT " . implode(
',', array_keys($mode_info[
'fields']));
144 $sql .=
" FROM " . MAIN_DB_PREFIX . $mode_info[
'table'];
145 $sql .=
" WHERE " . ($asset_id > 0 ?
" fk_asset = " . (int) $asset_id :
" fk_asset_model = " . (
int) $asset_model_id);
149 if ($obj = $this->
db->fetch_object(
$resql)) {
150 $accountancy_codes[$mode_key] = array();
151 foreach ($mode_info[
'fields'] as $field_key => $field_info) {
152 $accountancy_codes[$mode_key][$field_key] = $obj->$field_key;
156 $this->errors[] = $langs->trans(
'AssetErrorFetchAccountancyCodesForMode', $mode_key) .
': ' . $this->
db->lasterror();
165 $this->accountancy_codes = $accountancy_codes;
181 global $langs, $hookmanager;
182 dol_syslog(__METHOD__ .
" user_id={$user->id}, asset_id=$asset_id, asset_model_id=$asset_model_id, notrigger=$notrigger");
185 $this->errors = array();
188 $asset_id = $asset_id > 0 ? $asset_id : 0;
189 $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0;
191 if (!is_object($hookmanager)) {
192 require_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
196 $hookmanager->initHooks(array(
'assetaccountancycodesdao'));
197 $parameters = array(
'user' => $user,
'asset_id' => $asset_id,
'asset_model_id' => $asset_model_id);
198 $reshook = $hookmanager->executeHooks(
'updateAccountancyCodes', $parameters, $this);
199 if (!empty($reshook)) {
204 if (empty($asset_id) && empty($asset_model_id)) {
205 $this->errors[] = $langs->trans(
'AssetErrorAssetOrAssetModelIDNotProvide');
216 foreach ($this->accountancy_codes_fields as $mode_key => $mode_info) {
218 $sql =
"DELETE FROM " . MAIN_DB_PREFIX . $mode_info[
'table'];
219 $sql .=
" WHERE " . ($asset_id > 0 ?
" fk_asset = " . (int) $asset_id :
" fk_asset_model = " . (
int) $asset_model_id);
222 $this->errors[] = $langs->trans(
'AssetErrorDeleteAccountancyCodesForMode', $mode_key) .
': ' . $this->
db->lasterror();
226 if (!$error && !empty($this->accountancy_codes[$mode_key])) {
228 $sql =
"INSERT INTO " . MAIN_DB_PREFIX . $mode_info[
'table'] .
"(";
229 $sql .= $asset_id > 0 ?
"fk_asset," :
"fk_asset_model,";
230 $sql .= implode(
',', array_keys($mode_info[
'fields']));
231 $sql .=
", tms, fk_user_modif";
233 $sql .= $asset_id > 0 ? $asset_id : $asset_model_id;
234 foreach ($mode_info[
'fields'] as $field_key => $field_info) {
235 $sql .=
', ' . (empty($this->accountancy_codes[$mode_key][$field_key]) ?
'NULL' :
"'" . $this->
db->escape($this->accountancy_codes[$mode_key][$field_key]) .
"'");
237 $sql .=
", '" . $this->
db->idate($now) .
"'";
238 $sql .=
", " . $user->id;
243 $this->errors[] = $langs->trans(
'AssetErrorInsertAccountancyCodesForMode', $mode_key) .
': ' . $this->
db->lasterror();
249 if (!$error && $asset_id > 0) {
251 require_once DOL_DOCUMENT_ROOT .
'/asset/class/asset.class.php';
253 $result = $asset->fetch($asset_id);
254 if ($result > 0) $result = $asset->calculationDepreciation();
256 $this->errors[] = $langs->trans(
'AssetErrorCalculationDepreciationLines');
257 $this->errors[] = $asset->errorsToString();
262 if (!$error && !$notrigger) {
264 $result = $this->
call_trigger(
'ASSET_ACCOUNTANCY_CODES_MODIFY', $user);
275 $this->
db->rollback();
Class for AssetAccountancyCodes.
updateAccountancyCodes($user, $asset_id=0, $asset_model_id=0, $notrigger=0)
Update accountancy codes of a asset or a asset model.
setAccountancyCodesFromPost()
Fill accountancy_codes property of object (using for data sent by forms)
__construct(DoliDB $db)
Constructor.
fetchAccountancyCodes($asset_id=0, $asset_model_id=0)
Load accountancy codes of a asset or a asset model.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
errorsToString()
Method to output saved errors.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.