29 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
41 public $element =
'accounting_account';
46 public $table_element =
'accounting_account';
51 public $picto =
'billr';
57 public $ismultientitymanaged = 1;
63 public $restrictiononfksoc = 1;
90 public $fk_pcg_version;
100 public $account_number;
105 public $account_parent;
110 public $account_category;
115 public $account_category_label;
135 public $fk_user_author;
140 public $fk_user_modif;
150 public $reconcilable;
155 private $accountingaccount_codetotid_cache = array();
158 const STATUS_ENABLED = 1;
159 const STATUS_DISABLED = 0;
172 $this->next_prev_filter =
"fk_pcg_version IN (SELECT pcg_version FROM ".MAIN_DB_PREFIX.
"accounting_system WHERE rowid = ".((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
")";
184 public function fetch($rowid =
null, $account_number =
null, $limittocurrentchart = 0, $limittoachartaccount =
'')
188 if ($rowid || $account_number) {
189 $sql =
"SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active, a.reconcilable";
190 $sql .=
", ca.label as category_label";
191 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as a";
192 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_accounting_category as ca ON a.fk_accounting_category = ca.rowid";
195 $sql .=
" a.rowid = ".(int) $rowid;
196 } elseif ($account_number) {
197 $sql .=
" a.account_number = '".$this->db->escape($account_number).
"'";
198 $sql .=
" AND a.entity = ".$conf->entity;
200 if (!empty($limittocurrentchart)) {
201 $sql .=
' AND a.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
203 if (!empty($limittoachartaccount)) {
204 $sql .=
" AND a.fk_pcg_version = '".$this->db->escape($limittoachartaccount).
"'";
207 dol_syslog(get_class($this).
"::fetch rowid=".$rowid.
" account_number=".$account_number, LOG_DEBUG);
209 $result = $this->db->query(
$sql);
211 $obj = $this->db->fetch_object($result);
214 $this->
id = $obj->rowid;
215 $this->
rowid = $obj->rowid;
216 $this->
ref = $obj->account_number;
217 $this->datec = $this->db->jdate($obj->datec);
218 $this->date_creation = $this->db->jdate($obj->datec);
219 $this->date_modification = $this->db->jdate($obj->tms);
221 $this->fk_pcg_version = $obj->fk_pcg_version;
222 $this->pcg_type = $obj->pcg_type;
223 $this->account_number = $obj->account_number;
224 $this->account_parent = $obj->account_parent;
225 $this->label = $obj->label;
226 $this->labelshort = $obj->labelshort;
227 $this->account_category = $obj->fk_accounting_category;
228 $this->account_category_label = $obj->category_label;
229 $this->fk_user_author = $obj->fk_user_author;
230 $this->fk_user_modif = $obj->fk_user_modif;
231 $this->active = $obj->active;
232 $this->status = $obj->active;
233 $this->reconcilable = $obj->reconcilable;
240 $this->error =
"Error ".$this->db->lasterror();
241 $this->errors[] =
"Error ".$this->db->lasterror();
254 public function create($user, $notrigger = 0)
261 if (isset($this->fk_pcg_version)) {
262 $this->fk_pcg_version = trim($this->fk_pcg_version);
264 if (isset($this->pcg_type)) {
265 $this->pcg_type = trim($this->pcg_type);
267 if (isset($this->account_number)) {
268 $this->account_number = trim($this->account_number);
270 if (isset($this->label)) {
271 $this->label = trim($this->label);
273 if (isset($this->labelshort)) {
274 $this->labelshort = trim($this->labelshort);
277 if (empty($this->pcg_type) || $this->pcg_type ==
'-1') {
278 $this->pcg_type =
'XXXXXX';
284 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"accounting_account(";
287 $sql .=
", fk_pcg_version";
288 $sql .=
", pcg_type";
289 $sql .=
", account_number";
290 $sql .=
", account_parent";
292 $sql .=
", labelshort";
293 $sql .=
", fk_accounting_category";
294 $sql .=
", fk_user_author";
296 $sql .=
", reconcilable";
297 $sql .=
") VALUES (";
298 $sql .=
" '".$this->db->idate($now).
"'";
299 $sql .=
", ".((int) $conf->entity);
300 $sql .=
", ".(empty($this->fk_pcg_version) ?
'NULL' :
"'".$this->db->escape($this->fk_pcg_version).
"'");
301 $sql .=
", ".(empty($this->pcg_type) ?
'NULL' :
"'".$this->db->escape($this->pcg_type).
"'");
302 $sql .=
", ".(empty($this->account_number) ?
'NULL' :
"'".$this->db->escape($this->account_number).
"'");
303 $sql .=
", ".(empty($this->account_parent) ? 0 : (int) $this->account_parent);
304 $sql .=
", ".(empty($this->label) ?
"''" :
"'".$this->db->escape($this->label).
"'");
305 $sql .=
", ".(empty($this->labelshort) ?
"''" :
"'".$this->db->escape($this->labelshort).
"'");
306 $sql .=
", ".(empty($this->account_category) ? 0 : (int) $this->account_category);
307 $sql .=
", ".((int) $user->id);
308 $sql .=
", ".(int) $this->active;
309 $sql .=
", ".(int) $this->reconcilable;
314 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
315 $resql = $this->db->query(
$sql);
318 $this->errors[] =
"Error " . $this->db->lasterror();
322 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"accounting_account");
337 foreach ($this->errors as $errmsg) {
338 dol_syslog(get_class($this) .
"::create " . $errmsg, LOG_ERR);
339 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
341 $this->db->rollback();
358 if (empty($this->pcg_type) || $this->pcg_type ==
'-1') {
359 $this->pcg_type =
'XXXXXX';
364 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"accounting_account ";
365 $sql .=
" SET fk_pcg_version = " . ($this->fk_pcg_version ?
"'" . $this->db->escape($this->fk_pcg_version) .
"'" :
"null");
366 $sql .=
" , pcg_type = " . ($this->pcg_type ?
"'" . $this->db->escape($this->pcg_type) .
"'" :
"null");
367 $sql .=
" , account_number = '" . $this->db->escape($this->account_number) .
"'";
368 $sql .=
" , account_parent = " . (int) $this->account_parent;
369 $sql .=
" , label = " . ($this->label ?
"'" . $this->db->escape($this->label) .
"'" :
"''");
370 $sql .=
" , labelshort = " . ($this->labelshort ?
"'" . $this->db->escape($this->labelshort) .
"'" :
"''");
371 $sql .=
" , fk_accounting_category = " . (empty($this->account_category) ? 0 : (int) $this->account_category);
372 $sql .=
" , fk_user_modif = " . ((int) $user->id);
373 $sql .=
" , active = " . (int) $this->active;
374 $sql .=
" , reconcilable = " . (int) $this->reconcilable;
375 $sql .=
" WHERE rowid = " . ((int) $this->
id);
377 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
378 $result = $this->db->query(
$sql);
383 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
384 $this->error = $this->db->lasterror();
385 $this->db->rollback();
389 $this->error = $this->db->lasterror();
390 $this->db->rollback();
404 $sql =
"(SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX.
"facturedet";
405 $sql .=
" WHERE fk_code_ventilation=".((int) $this->
id).
")";
407 $sql .=
" (SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX.
"facture_fourn_det";
408 $sql .=
" WHERE fk_code_ventilation=".((int) $this->
id).
")";
410 dol_syslog(get_class($this).
"::checkUsage", LOG_DEBUG);
411 $resql = $this->db->query(
$sql);
414 $num = $this->db->num_rows($resql);
416 $this->error = $langs->trans(
'ErrorAccountancyCodeIsAlreadyUse');
422 $this->error = $this->db->lasterror();
434 public function delete($user, $notrigger = 0)
444 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"accounting_account";
445 $sql .=
" WHERE rowid=" . ((int) $this->
id);
448 $resql = $this->db->query(
$sql);
451 $this->errors[] =
"Error " . $this->db->lasterror();
457 foreach ($this->errors as $errmsg) {
458 dol_syslog(get_class($this) .
"::delete " . $errmsg, LOG_ERR);
459 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
461 $this->db->rollback();
485 public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1, $withcompletelabel = 0, $option =
'')
487 global $langs, $conf, $hookmanager;
488 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
490 if (!empty($conf->dol_no_mouse_hover)) {
498 if (empty($option) || $option ==
'ledger') {
499 $url = DOL_URL_ROOT .
'/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start=' . urlencode($this->account_number) .
'&search_accountancy_code_end=' . urlencode($this->account_number);
500 $labelurl = $langs->trans(
"ShowAccountingAccountInLedger");
501 } elseif ($option ==
'journals') {
502 $url = DOL_URL_ROOT .
'/accountancy/bookkeeping/list.php?search_accountancy_code_start=' . urlencode($this->account_number) .
'&search_accountancy_code_end=' . urlencode($this->account_number);
503 $labelurl = $langs->trans(
"ShowAccountingAccountInJournals");
504 } elseif ($option ==
'accountcard') {
505 $url = DOL_URL_ROOT .
'/accountancy/admin/card.php?id=' . urlencode($this->
id);
506 $labelurl = $langs->trans(
"ShowAccountingAccount");
510 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
511 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
512 $add_save_lastsearch_values = 1;
514 if ($add_save_lastsearch_values) {
515 $url .=
'&save_lastsearch_values=1';
518 $picto =
'accounting_account';
521 if (empty($this->labelshort) || $withcompletelabel == 1) {
522 $labeltoshow = $this->label;
524 $labeltoshow = $this->labelshort;
527 $label =
'<u>' . $labelurl .
'</u>';
528 if (!empty($this->account_number)) {
529 $label .=
'<br><b>' . $langs->trans(
'AccountAccounting') .
':</b> ' .
length_accountg($this->account_number);
531 if (!empty($labeltoshow)) {
532 $label .=
'<br><b>' . $langs->trans(
'Label') .
':</b> ' . $labeltoshow;
535 $label .=
' - ' . $moretitle;
539 if (empty($notooltip)) {
540 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
545 $linkclose .=
' class="classfortooltip"';
548 $linkstart =
'<a href="' . $url .
'"';
549 $linkstart .= $linkclose .
'>';
560 $label_link .=
' - ' . ($nourl ?
'<span class="opacitymedium">' :
'') . $labeltoshow . ($nourl ?
'</span>' :
'');
564 $result .= ($linkstart .
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1) . $linkend);
566 if ($withpicto && $withpicto != 2) {
569 if ($withpicto != 2) {
570 $result .= $linkstart . $label_link . $linkend;
573 $hookmanager->initHooks(array($this->element .
'dao'));
574 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
575 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
577 $result = $hookmanager->resPrint;
579 $result .= $hookmanager->resPrint;
592 $sql =
'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms as date_modification';
593 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'accounting_account as a';
594 $sql .=
' WHERE a.rowid = ' . ((int) $id);
597 $resql = $this->db->query(
$sql);
600 if ($this->db->num_rows($resql)) {
601 $obj = $this->db->fetch_object($resql);
602 $this->
id = $obj->rowid;
604 $this->user_creation_id = $obj->fk_user_author;
605 $this->user_modification_id = $obj->fk_user_modif;
606 $this->date_creation = $this->db->jdate($obj->datec);
607 $this->date_modification = $this->db->jdate($obj->date_modification);
609 $this->db->free($resql);
626 $fieldtouse =
'active';
628 $fieldtouse =
'reconcilable';
634 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account ";
635 $sql .=
"SET ".$fieldtouse.
" = '0'";
636 $sql .=
" WHERE rowid = ".((int) $id);
638 dol_syslog(get_class($this).
"::accountDeactivate ".$fieldtouse, LOG_DEBUG);
639 $result = $this->db->query(
$sql);
645 $this->error = $this->db->lasterror();
646 $this->db->rollback();
667 $fieldtouse =
'active';
669 $fieldtouse =
'reconcilable';
672 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account";
673 $sql .=
" SET ".$fieldtouse.
" = '1'";
674 $sql .=
" WHERE rowid = ".((int) $id);
676 dol_syslog(get_class($this).
"::account_activate ".$fieldtouse, LOG_DEBUG);
677 $result = $this->db->query(
$sql);
682 $this->error = $this->db->lasterror();
683 $this->db->rollback();
696 return $this->
LibStatut($this->status, $mode);
710 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
712 $langs->load(
"users");
713 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
714 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
715 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
716 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
719 $statusType =
'status4';
720 if ($status == self::STATUS_DISABLED) {
721 $statusType =
'status5';
724 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
747 $hookmanager->initHooks(array(
'accountancyBindingCalculation'));
750 $parameters = array(
'buyer' => $buyer,
'seller' => $seller,
'product' => $product,
'facture' => $facture,
'factureDet' => $factureDet ,
'accountingAccount'=>$accountingAccount, $type);
751 $reshook = $hookmanager->executeHooks(
'accountancyBindingCalculation', $parameters);
753 if (empty($reshook)) {
755 if ($type ==
'customer') {
756 $const_name =
"SOLD";
757 } elseif ($type ==
'supplier') {
761 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
762 $isBuyerInEEC =
isInEEC($buyer);
763 $isSellerInEEC =
isInEEC($seller);
770 $suggestedaccountingaccountbydefaultfor =
'';
771 if ($factureDet->product_type == 1) {
772 if ($buyer->country_code == $seller->country_code || empty($buyer->country_code)) {
773 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'} :
'');
774 $suggestedaccountingaccountbydefaultfor =
'';
776 if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) {
777 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'} :
'');
778 $suggestedaccountingaccountbydefaultfor =
'eecwithvat';
779 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) {
780 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'} :
'');
781 $suggestedaccountingaccountbydefaultfor =
'eecwithoutvatnumber';
782 } elseif ($isSellerInEEC && $isBuyerInEEC) {
783 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_INTRA_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_INTRA_ACCOUNT'} :
'');
784 $suggestedaccountingaccountbydefaultfor =
'eec';
786 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_EXPORT_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_EXPORT_ACCOUNT'} :
'');
787 $suggestedaccountingaccountbydefaultfor =
'export';
790 } elseif ($factureDet->product_type == 0) {
791 if ($buyer->country_code == $seller->country_code || empty($buyer->country_code)) {
792 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'} :
'');
793 $suggestedaccountingaccountbydefaultfor =
'';
795 if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) {
796 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'} :
'');
797 $suggestedaccountingaccountbydefaultfor =
'eecwithvat';
798 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) {
799 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'} :
'');
800 $suggestedaccountingaccountbydefaultfor =
'eecwithoutvatnumber';
801 } elseif ($isSellerInEEC && $isBuyerInEEC) {
802 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_INTRA_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_INTRA_ACCOUNT'} :
'');
803 $suggestedaccountingaccountbydefaultfor =
'eec';
805 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_EXPORT_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_EXPORT_ACCOUNT'} :
'');
806 $suggestedaccountingaccountbydefaultfor =
'export';
815 $suggestedaccountingaccountfor =
'';
816 if ((($buyer->country_code == $seller->country_code) || empty($buyer->country_code))) {
818 if ($type ==
'customer' && !empty($product->accountancy_code_sell)) {
819 $code_p = $product->accountancy_code_sell;
820 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy)) {
821 $code_p = $product->accountancy_code_buy;
823 $suggestedid = $accountingAccount[
'dom'];
824 $suggestedaccountingaccountfor =
'prodserv';
826 if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) {
828 if ($type ==
'customer' && !empty($product->accountancy_code_sell)) {
829 $code_p = $product->accountancy_code_sell;
830 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy)) {
831 $code_p = $product->accountancy_code_buy;
833 $suggestedid = $accountingAccount[
'dom'];
834 $suggestedaccountingaccountfor =
'eecwithvat';
835 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) {
837 if ($type ==
'customer' && !empty($product->accountancy_code_sell)) {
838 $code_p = $product->accountancy_code_sell;
839 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy)) {
840 $code_p = $product->accountancy_code_buy;
842 $suggestedid = $accountingAccount[
'dom'];
843 $suggestedaccountingaccountfor =
'eecwithoutvatnumber';
844 } elseif ($isSellerInEEC && $isBuyerInEEC && !empty($product->accountancy_code_sell_intra)) {
846 if ($type ==
'customer' && !empty($product->accountancy_code_sell_intra)) {
847 $code_p = $product->accountancy_code_sell_intra;
848 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy_intra)) {
849 $code_p = $product->accountancy_code_buy_intra;
851 $suggestedid = $accountingAccount[
'intra'];
852 $suggestedaccountingaccountfor =
'eec';
855 if ($type ==
'customer' && !empty($product->accountancy_code_sell_export)) {
856 $code_p = $product->accountancy_code_sell_export;
857 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy_export)) {
858 $code_p = $product->accountancy_code_buy_export;
860 $suggestedid = $accountingAccount[
'export'];
861 $suggestedaccountingaccountfor =
'export';
866 if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
867 if (!empty($buyer->code_compta_product)) {
868 $code_t = $buyer->code_compta_product;
869 $suggestedid = $accountingAccount[
'thirdparty'];
870 $suggestedaccountingaccountfor =
'thirdparty';
876 if ($factureDet->desc ==
"(DEPOSIT)" || $facture->type == $facture::TYPE_DEPOSIT) {
877 $accountdeposittoventilated =
new self($this->db);
878 if ($type ==
'customer') {
879 $result = $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1);
880 } elseif ($type ==
'supplier') {
881 $result = $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT, 1);
883 if (isset($result) && $result < 0) {
887 $code_l = $accountdeposittoventilated->ref;
890 $suggestedid = $accountdeposittoventilated->rowid;
891 $suggestedaccountingaccountfor =
'deposit';
895 if (!empty($facture->fk_facture_source)) {
896 $invoiceSource =
new $facture($this->db);
897 $invoiceSource->fetch($facture->fk_facture_source);
899 if ($facture->type == $facture::TYPE_CREDIT_NOTE && $invoiceSource->type == $facture::TYPE_DEPOSIT) {
900 $accountdeposittoventilated =
new self($this->db);
901 if ($type ==
'customer') {
902 $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1);
903 } elseif ($type ==
'supplier') {
904 $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT, 1);
906 $code_l = $accountdeposittoventilated->ref;
909 $suggestedid = $accountdeposittoventilated->rowid;
910 $suggestedaccountingaccountfor =
'deposit';
916 if (empty($suggestedid) && empty($code_p) && !empty($code_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC)) {
917 if (empty($this->accountingaccount_codetotid_cache[$code_l])) {
918 $tmpaccount =
new self($this->db);
919 $result = $tmpaccount->fetch(0, $code_l, 1);
923 if ($tmpaccount->id > 0) {
924 $suggestedid = $tmpaccount->id;
926 $this->accountingaccount_codetotid_cache[$code_l] = $tmpaccount->id;
928 $suggestedid = $this->accountingaccount_codetotid_cache[$code_l];
932 'suggestedaccountingaccountbydefaultfor' => $suggestedaccountingaccountbydefaultfor,
933 'suggestedaccountingaccountfor' => $suggestedaccountingaccountfor,
934 'suggestedid' => $suggestedid,
940 if (is_array($hookmanager->resArray) && !empty($hookmanager->resArray)) {
941 return $hookmanager->resArray;