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();
405 $sql =
"(SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX.
"facturedet";
406 $sql .=
" WHERE fk_code_ventilation=".((int) $this->
id).
")";
408 $sql .=
" (SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX.
"facture_fourn_det";
409 $sql .=
" WHERE fk_code_ventilation=".((int) $this->
id).
")";
411 dol_syslog(get_class($this).
"::checkUsage", LOG_DEBUG);
412 $resql = $this->db->query(
$sql);
415 $num = $this->db->num_rows($resql);
417 $this->error = $langs->trans(
'ErrorAccountancyCodeIsAlreadyUse');
423 $this->error = $this->db->lasterror();
435 public function delete($user, $notrigger = 0)
445 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"accounting_account";
446 $sql .=
" WHERE rowid=" . ((int) $this->
id);
449 $resql = $this->db->query(
$sql);
452 $this->errors[] =
"Error " . $this->db->lasterror();
458 foreach ($this->errors as $errmsg) {
459 dol_syslog(get_class($this) .
"::delete " . $errmsg, LOG_ERR);
460 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
462 $this->db->rollback();
486 public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1, $withcompletelabel = 0, $option =
'')
488 global $langs, $conf, $hookmanager;
489 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
491 if (!empty($conf->dol_no_mouse_hover)) {
499 if (empty($option) || $option ==
'ledger') {
500 $url = DOL_URL_ROOT .
'/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start=' . urlencode($this->account_number) .
'&search_accountancy_code_end=' . urlencode($this->account_number);
501 $labelurl = $langs->trans(
"ShowAccountingAccountInLedger");
502 } elseif ($option ==
'journals') {
503 $url = DOL_URL_ROOT .
'/accountancy/bookkeeping/list.php?search_accountancy_code_start=' . urlencode($this->account_number) .
'&search_accountancy_code_end=' . urlencode($this->account_number);
504 $labelurl = $langs->trans(
"ShowAccountingAccountInJournals");
505 } elseif ($option ==
'accountcard') {
506 $url = DOL_URL_ROOT .
'/accountancy/admin/card.php?id=' . urlencode($this->
id);
507 $labelurl = $langs->trans(
"ShowAccountingAccount");
511 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
512 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
513 $add_save_lastsearch_values = 1;
515 if ($add_save_lastsearch_values) {
516 $url .=
'&save_lastsearch_values=1';
519 $picto =
'accounting_account';
522 if (empty($this->labelshort) || $withcompletelabel == 1) {
523 $labeltoshow = $this->label;
525 $labeltoshow = $this->labelshort;
528 $label =
'<u>' . $labelurl .
'</u>';
529 if (!empty($this->account_number)) {
530 $label .=
'<br><b>' . $langs->trans(
'AccountAccounting') .
':</b> ' .
length_accountg($this->account_number);
532 if (!empty($labeltoshow)) {
533 $label .=
'<br><b>' . $langs->trans(
'Label') .
':</b> ' . $labeltoshow;
536 $label .=
' - ' . $moretitle;
540 if (empty($notooltip)) {
541 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
546 $linkclose .=
' class="classfortooltip"';
549 $linkstart =
'<a href="' . $url .
'"';
550 $linkstart .= $linkclose .
'>';
561 $label_link .=
' - ' . ($nourl ?
'<span class="opacitymedium">' :
'') . $labeltoshow . ($nourl ?
'</span>' :
'');
565 $result .= ($linkstart .
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1) . $linkend);
567 if ($withpicto && $withpicto != 2) {
570 if ($withpicto != 2) {
571 $result .= $linkstart . $label_link . $linkend;
574 $hookmanager->initHooks(array($this->element .
'dao'));
575 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
576 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
578 $result = $hookmanager->resPrint;
580 $result .= $hookmanager->resPrint;
593 $sql =
'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms as date_modification';
594 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'accounting_account as a';
595 $sql .=
' WHERE a.rowid = ' . ((int) $id);
598 $resql = $this->db->query(
$sql);
601 if ($this->db->num_rows($resql)) {
602 $obj = $this->db->fetch_object($resql);
603 $this->
id = $obj->rowid;
605 $this->user_creation_id = $obj->fk_user_author;
606 $this->user_modification_id = $obj->fk_user_modif;
607 $this->date_creation = $this->db->jdate($obj->datec);
608 $this->date_modification = $this->db->jdate($obj->date_modification);
610 $this->db->free($resql);
627 $fieldtouse =
'active';
629 $fieldtouse =
'reconcilable';
635 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account ";
636 $sql .=
"SET ".$fieldtouse.
" = '0'";
637 $sql .=
" WHERE rowid = ".((int) $id);
639 dol_syslog(get_class($this).
"::accountDeactivate ".$fieldtouse, LOG_DEBUG);
640 $result = $this->db->query(
$sql);
646 $this->error = $this->db->lasterror();
647 $this->db->rollback();
668 $fieldtouse =
'active';
670 $fieldtouse =
'reconcilable';
673 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account";
674 $sql .=
" SET ".$fieldtouse.
" = '1'";
675 $sql .=
" WHERE rowid = ".((int) $id);
677 dol_syslog(get_class($this).
"::account_activate ".$fieldtouse, LOG_DEBUG);
678 $result = $this->db->query(
$sql);
683 $this->error = $this->db->lasterror();
684 $this->db->rollback();
697 return $this->
LibStatut($this->status, $mode);
711 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
713 $langs->load(
"users");
714 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
715 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
716 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
717 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
720 $statusType =
'status4';
721 if ($status == self::STATUS_DISABLED) {
722 $statusType =
'status5';
725 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
748 $hookmanager->initHooks(array(
'accountancyBindingCalculation'));
751 $parameters = array(
'buyer' => $buyer,
'seller' => $seller,
'product' => $product,
'facture' => $facture,
'factureDet' => $factureDet ,
'accountingAccount'=>$accountingAccount, $type);
752 $reshook = $hookmanager->executeHooks(
'accountancyBindingCalculation', $parameters);
754 if (empty($reshook)) {
756 if ($type ==
'customer') {
757 $const_name =
"SOLD";
758 } elseif ($type ==
'supplier') {
762 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
763 $isBuyerInEEC =
isInEEC($buyer);
764 $isSellerInEEC =
isInEEC($seller);
771 $suggestedaccountingaccountbydefaultfor =
'';
772 if ($factureDet->product_type == 1) {
773 if ($buyer->country_code == $seller->country_code || empty($buyer->country_code)) {
774 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'} :
'');
775 $suggestedaccountingaccountbydefaultfor =
'';
777 if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) {
778 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'} :
'');
779 $suggestedaccountingaccountbydefaultfor =
'eecwithvat';
780 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) {
781 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_ACCOUNT'} :
'');
782 $suggestedaccountingaccountbydefaultfor =
'eecwithoutvatnumber';
783 } elseif ($isSellerInEEC && $isBuyerInEEC) {
784 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_INTRA_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_INTRA_ACCOUNT'} :
'');
785 $suggestedaccountingaccountbydefaultfor =
'eec';
787 $code_l = (!empty($conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_EXPORT_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_SERVICE_' . $const_name .
'_EXPORT_ACCOUNT'} :
'');
788 $suggestedaccountingaccountbydefaultfor =
'export';
791 } elseif ($factureDet->product_type == 0) {
792 if ($buyer->country_code == $seller->country_code || empty($buyer->country_code)) {
793 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'} :
'');
794 $suggestedaccountingaccountbydefaultfor =
'';
796 if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) {
797 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'} :
'');
798 $suggestedaccountingaccountbydefaultfor =
'eecwithvat';
799 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) {
800 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_ACCOUNT'} :
'');
801 $suggestedaccountingaccountbydefaultfor =
'eecwithoutvatnumber';
802 } elseif ($isSellerInEEC && $isBuyerInEEC) {
803 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_INTRA_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_INTRA_ACCOUNT'} :
'');
804 $suggestedaccountingaccountbydefaultfor =
'eec';
806 $code_l = (!empty($conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_EXPORT_ACCOUNT'}) ? $conf->global->{
'ACCOUNTING_PRODUCT_' . $const_name .
'_EXPORT_ACCOUNT'} :
'');
807 $suggestedaccountingaccountbydefaultfor =
'export';
816 $suggestedaccountingaccountfor =
'';
817 if ((($buyer->country_code == $seller->country_code) || empty($buyer->country_code))) {
819 if ($type ==
'customer' && !empty($product->accountancy_code_sell)) {
820 $code_p = $product->accountancy_code_sell;
821 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy)) {
822 $code_p = $product->accountancy_code_buy;
824 $suggestedid = $accountingAccount[
'dom'];
825 $suggestedaccountingaccountfor =
'prodserv';
827 if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) {
829 if ($type ==
'customer' && !empty($product->accountancy_code_sell)) {
830 $code_p = $product->accountancy_code_sell;
831 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy)) {
832 $code_p = $product->accountancy_code_buy;
834 $suggestedid = $accountingAccount[
'dom'];
835 $suggestedaccountingaccountfor =
'eecwithvat';
836 } elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) {
838 if ($type ==
'customer' && !empty($product->accountancy_code_sell)) {
839 $code_p = $product->accountancy_code_sell;
840 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy)) {
841 $code_p = $product->accountancy_code_buy;
843 $suggestedid = $accountingAccount[
'dom'];
844 $suggestedaccountingaccountfor =
'eecwithoutvatnumber';
845 } elseif ($isSellerInEEC && $isBuyerInEEC) {
847 if ($type ==
'customer' && !empty($product->accountancy_code_sell_intra)) {
848 $code_p = $product->accountancy_code_sell_intra;
849 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy_intra)) {
850 $code_p = $product->accountancy_code_buy_intra;
852 $suggestedid = $accountingAccount[
'intra'];
853 $suggestedaccountingaccountfor =
'eec';
856 if ($type ==
'customer' && !empty($product->accountancy_code_sell_export)) {
857 $code_p = $product->accountancy_code_sell_export;
858 } elseif ($type ==
'supplier' && !empty($product->accountancy_code_buy_export)) {
859 $code_p = $product->accountancy_code_buy_export;
861 $suggestedid = $accountingAccount[
'export'];
862 $suggestedaccountingaccountfor =
'export';
867 if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
868 if ($type ==
'customer' && !empty($buyer->code_compta_product)) {
869 $code_t = $buyer->code_compta_product;
870 $suggestedid = $accountingAccount[
'thirdparty'];
871 $suggestedaccountingaccountfor =
'thirdparty';
872 } elseif ($type ==
'supplier' && !empty($seller->code_compta_product)) {
873 $code_t = $seller->code_compta_product;
874 $suggestedid = $accountingAccount[
'thirdparty'];
875 $suggestedaccountingaccountfor =
'thirdparty';
881 if ($factureDet->desc ==
"(DEPOSIT)" || $facture->type == $facture::TYPE_DEPOSIT) {
882 $accountdeposittoventilated =
new self($this->db);
883 if ($type ==
'customer') {
884 $result = $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1);
885 } elseif ($type ==
'supplier') {
886 $result = $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT, 1);
888 if (isset($result) && $result < 0) {
892 $code_l = $accountdeposittoventilated->ref;
895 $suggestedid = $accountdeposittoventilated->rowid;
896 $suggestedaccountingaccountfor =
'deposit';
900 if (!empty($facture->fk_facture_source)) {
901 $invoiceSource =
new $facture($this->db);
902 $invoiceSource->fetch($facture->fk_facture_source);
904 if ($facture->type == $facture::TYPE_CREDIT_NOTE && $invoiceSource->type == $facture::TYPE_DEPOSIT) {
905 $accountdeposittoventilated =
new self($this->db);
906 if ($type ==
'customer') {
907 $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1);
908 } elseif ($type ==
'supplier') {
909 $accountdeposittoventilated->fetch(
'', $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT, 1);
911 $code_l = $accountdeposittoventilated->ref;
914 $suggestedid = $accountdeposittoventilated->rowid;
915 $suggestedaccountingaccountfor =
'deposit';
921 if (empty($suggestedid) && empty($code_p) && !empty($code_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC)) {
922 if (empty($this->accountingaccount_codetotid_cache[$code_l])) {
923 $tmpaccount =
new self($this->db);
924 $result = $tmpaccount->fetch(0, $code_l, 1);
928 if ($tmpaccount->id > 0) {
929 $suggestedid = $tmpaccount->id;
931 $this->accountingaccount_codetotid_cache[$code_l] = $tmpaccount->id;
933 $suggestedid = $this->accountingaccount_codetotid_cache[$code_l];
937 'suggestedaccountingaccountbydefaultfor' => $suggestedaccountingaccountbydefaultfor,
938 'suggestedaccountingaccountfor' => $suggestedaccountingaccountfor,
939 'suggestedid' => $suggestedid,
945 if (is_array($hookmanager->resArray) && !empty($hookmanager->resArray)) {
946 return $hookmanager->resArray;
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Class to manage accounting accounts.
LibStatut($status, $mode=0)
Return the label of a given status.
accountDeactivate($id, $mode=0)
Deactivate an account (for status active or status reconcilable)
__construct($db)
Constructor.
checkUsage()
Check usage of accounting code.
update($user)
Update record.
getNomUrl($withpicto=0, $withlabel=0, $nourl=0, $moretitle='', $notooltip=0, $save_lastsearch_value=-1, $withcompletelabel=0, $option='')
Return clicable name (with picto eventually)
create($user, $notrigger=0)
Insert new accounting account in chart of accounts.
accountActivate($id, $mode=0)
Account activated.
info($id)
Information on record.
fetch($rowid=null, $account_number=null, $limittocurrentchart=0, $limittoachartaccount='')
Load record in memory.
getAccountingCodeToBind(Societe $buyer, Societe $seller, Product $product, $facture, $factureDet, $accountingAccount=array(), $type='')
Return a suggested account (from chart of accounts) to bind.
getLibStatut($mode=0)
Return the label of the status.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...