From 272681724792b7da90076747f9d7d4f118b5465e Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 5 Oct 2024 07:57:11 +0200 Subject: [PATCH 01/13] NEW Accountancy - Add general account on thirdparty - SQL Part --- .../install/mysql/migration/20.0.0-21.0.0.sql | 12 ++++++++++++ htdocs/install/mysql/tables/llx_societe.sql | 8 ++++++-- .../llx_societe_perentity-multicompany.sql | 18 ++++++++++-------- htdocs/install/mysql/tables/llx_user.sql | 12 ++++++++---- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/htdocs/install/mysql/migration/20.0.0-21.0.0.sql b/htdocs/install/mysql/migration/20.0.0-21.0.0.sql index ba603342da794..07159bd1847ef 100644 --- a/htdocs/install/mysql/migration/20.0.0-21.0.0.sql +++ b/htdocs/install/mysql/migration/20.0.0-21.0.0.sql @@ -136,3 +136,15 @@ ALTER TABLE llx_recruitment_recruitmentcandidature MODIFY fk_user_creat integer ALTER TABLE llx_ecm_files ADD COLUMN agenda_id integer; +-- Add accountancy code general on user / customer / supplier subledger +ALTER TABLE llx_user ADD COLUMN accountancy_code_user_general varchar(32) DEFAULT NULL AFTER fk_barcode_type; +ALTER TABLE llx_societe ADD COLUMN accountancy_code_customer_general varchar(32) DEFAULT NULL AFTER code_fournisseur; +ALTER TABLE llx_societe ADD COLUMN accountancy_code_supplier_general varchar(32) DEFAULT NULL AFTER code_compta; +ALTER TABLE llx_societe_perentity ADD COLUMN accountancy_code_customer_general varchar(32) DEFAULT NULL AFTER entity; +ALTER TABLE llx_societe_perentity ADD COLUMN accountancy_code_supplier_general varchar(32) DEFAULT NULL AFTER accountancy_code_customer; + +-- Uniformize length of accountancy account +ALTER TABLE llx_societe MODIFY COLUMN code_compta varchar(32); +ALTER TABLE llx_societe MODIFY COLUMN code_compta_fournisseur varchar(32); +ALTER TABLE llx_societe_perentity MODIFY COLUMN accountancy_code_customer varchar(32); +ALTER TABLE llx_societe_perentity MODIFY COLUMN accountancy_code_supplier varchar(32); diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index ab5a3782ab683..a4ce431ada2eb 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -38,8 +38,12 @@ create table llx_societe code_client varchar(24), -- code client code_fournisseur varchar(24), -- code fournisseur - code_compta varchar(24), -- customer accountancy auxiliary account - code_compta_fournisseur varchar(24), -- supplier accountancy auxiliary account + + accountancy_code_customer_general varchar(32) DEFAULT NULL, -- customer accountancy general account + code_compta varchar(32), -- customer accountancy auxiliary account + accountancy_code_supplier_general varchar(32) DEFAULT NULL, -- supplier accountancy general account + code_compta_fournisseur varchar(32), -- supplier accountancy auxiliary account + address varchar(255), -- company address zip varchar(25), -- zipcode town varchar(50), -- town diff --git a/htdocs/install/mysql/tables/llx_societe_perentity-multicompany.sql b/htdocs/install/mysql/tables/llx_societe_perentity-multicompany.sql index 78943d8463512..a8d28fb6b22d7 100644 --- a/htdocs/install/mysql/tables/llx_societe_perentity-multicompany.sql +++ b/htdocs/install/mysql/tables/llx_societe_perentity-multicompany.sql @@ -19,12 +19,14 @@ create table llx_societe_perentity ( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_soc integer, - entity integer DEFAULT 1 NOT NULL, -- multi company id - accountancy_code_customer varchar(24), -- customer accountancy auxiliary account - accountancy_code_supplier varchar(24), -- supplier accountancy auxiliary account - accountancy_code_sell varchar(32), -- Selling accountancy code - accountancy_code_buy varchar(32), -- Buying accountancy code - vat_reverse_charge tinyint DEFAULT 0 -- VAT reverse charge + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_soc integer, + entity integer DEFAULT 1 NOT NULL, -- multi company id + accountancy_code_customer_general varchar(32) DEFAULT NULL, -- customer accountancy general account + accountancy_code_customer varchar(32), -- customer accountancy auxiliary account + accountancy_code_supplier_general varchar(32) DEFAULT NULL, -- supplier accountancy general account + accountancy_code_supplier varchar(32), -- supplier accountancy auxiliary account + accountancy_code_sell varchar(32), -- Selling accountancy code + accountancy_code_buy varchar(32), -- Buying accountancy code + vat_reverse_charge tinyint DEFAULT 0 -- VAT reverse charge )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_user.sql b/htdocs/install/mysql/tables/llx_user.sql index 06c8ad99a0b20..065c6bd4f0d85 100644 --- a/htdocs/install/mysql/tables/llx_user.sql +++ b/htdocs/install/mysql/tables/llx_user.sql @@ -1,7 +1,8 @@ -- ============================================================================ --- Copyright (C) 2001-2003 Rodolphe Quiedeville --- Copyright (C) 2006-2013 Laurent Destailleur --- Copyright (C) 2007-2013 Regis Houssin +-- Copyright (C) 2001-2003 Rodolphe Quiedeville +-- Copyright (C) 2006-2013 Laurent Destailleur +-- Copyright (C) 2007-2013 Regis Houssin +-- Copyright (C) 2024 Alexandre Spangaro -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -98,7 +99,10 @@ create table llx_user color varchar(6), barcode varchar(255) DEFAULT NULL, fk_barcode_type integer DEFAULT 0, - accountancy_code varchar(32) NULL, + + accountancy_code_user_general varchar(32) DEFAULT NULL, + accountancy_code varchar(32) NULL, + nb_holiday integer DEFAULT 0, thm double(24,8), tjm double(24,8), From 8d4c30867ce870a3b49a45e81efbaf0d1a6ff433 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 6 Oct 2024 06:46:08 +0200 Subject: [PATCH 02/13] NEW Accountancy - Add general account on thirdparty - Code customer part --- htdocs/societe/class/societe.class.php | 67 ++++++++++++++++---------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 7d7b9f47dd771..26bf907dd682f 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1,26 +1,26 @@ - * Copyright (C) 2004-2021 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2003 Brian Fraval - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2005-2017 Regis Houssin - * Copyright (C) 2008 Patrick Raguin - * Copyright (C) 2010-2018 Juanjo Menent - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2013-2023 Alexandre Spangaro - * Copyright (C) 2013 Peter Fontaine - * Copyright (C) 2014-2015 Marcos García - * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) 2017 Rui Strecht - * Copyright (C) 2018 Philippe Grand - * Copyright (C) 2019-2020 Josep Lluís Amador - * Copyright (C) 2019-2024 Frédéric France - * Copyright (C) 2020 Open-Dsi - * Copyright (C) 2022 ButterflyOfFire - * Copyright (C) 2023 Alexandre Janniaux - * Copyright (C) 2024 William Mead - * Copyright (C) 2024 MDW +/* Copyright (C) 2002-2006 Rodolphe Quiedeville + * Copyright (C) 2004-2021 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2003 Brian Fraval + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2005-2017 Regis Houssin + * Copyright (C) 2008 Patrick Raguin + * Copyright (C) 2010-2018 Juanjo Menent + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013-2024 Alexandre Spangaro + * Copyright (C) 2013 Peter Fontaine + * Copyright (C) 2014-2015 Marcos García + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2017 Rui Strecht + * Copyright (C) 2018 Philippe Grand + * Copyright (C) 2019-2020 Josep Lluís Amador + * Copyright (C) 2019-2024 Frédéric France + * Copyright (C) 2020 Open-Dsi + * Copyright (C) 2022 ButterflyOfFire + * Copyright (C) 2023 Alexandre Janniaux + * Copyright (C) 2024 William Mead + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -672,7 +672,13 @@ class Societe extends CommonObject public $code_compta; /** - * Accounting code for customer + * Accounting general account for customer + * @var string + */ + public $accountancy_code_customer_general; + + /** + * Accounting auxiliary account for customer * @var string */ public $accountancy_code_customer; @@ -974,6 +980,7 @@ public function create(User $user, $notrigger = 0) $this->code_compta_client = trim(empty($this->code_compta_client) ? $this->code_compta : $this->code_compta_client); + $this->accountancy_code_customer_general = trim($this->accountancy_code_customer_general); $this->accountancy_code_customer = trim((string) $this->code_compta_client); $this->accountancy_code_supplier = trim((string) $this->code_compta_fournisseur); $this->accountancy_code_buy = trim((string) $this->accountancy_code_buy); @@ -1073,6 +1080,7 @@ public function create(User $user, $notrigger = 0) $sql .= " fk_soc"; $sql .= ", entity"; $sql .= ", vat_reverse_charge"; + $sql .= ", accountancy_code_customer_general"; $sql .= ", accountancy_code_customer"; $sql .= ", accountancy_code_supplier"; $sql .= ", accountancy_code_buy"; @@ -1081,6 +1089,7 @@ public function create(User $user, $notrigger = 0) $sql .= $this->id; $sql .= ", ".((int) $conf->entity); $sql .= ", ".(empty($this->vat_reverse_charge) ? '0' : '1'); + $sql .= ", '".$this->db->escape($this->accountancy_code_customer_general)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_customer)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_supplier)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'"; @@ -1666,6 +1675,7 @@ public function update($id, User $user, $call_trigger = 1, $allowmodcodeclient = $sql .= ", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) . "'"; $sql .= ", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) . "'"; if ($customer) { + $sql .= ", accountancy_code_customer_general = ".(!empty($this->accountancy_code_customer_general) ? "'".$this->db->escape($this->accountancy_code_customer_general)."'" : "null"); $sql .= ", code_compta = ".(!empty($this->code_compta_client) ? "'".$this->db->escape($this->code_compta_client)."'" : "null"); } @@ -1761,6 +1771,7 @@ public function update($id, User $user, $call_trigger = 1, $allowmodcodeclient = $sql .= " fk_soc"; $sql .= ", entity"; $sql .= ", vat_reverse_charge"; + $sql .= ", accountancy_code_customer_general"; $sql .= ", accountancy_code_customer"; $sql .= ", accountancy_code_supplier"; $sql .= ", accountancy_code_buy"; @@ -1769,6 +1780,7 @@ public function update($id, User $user, $call_trigger = 1, $allowmodcodeclient = $sql .= $this->id; $sql .= ", ".$conf->entity; $sql .= ", ".(empty($this->vat_reverse_charge) ? '0' : '1'); + $sql .= ", '".$this->db->escape($this->accountancy_code_customer_general)."'"; $sql .= ", '".$this->db->escape($this->code_compta_client)."'"; $sql .= ", '".$this->db->escape($this->code_compta_fournisseur)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'"; @@ -1874,10 +1886,14 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 $sql .= ', s.fk_forme_juridique as forme_juridique_code'; $sql .= ', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc'; if (!getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { - $sql .= ', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell'; + $sql .= ', s.accountancy_code_customer_general, s.code_compta'; + $sql .= ', s.code_compta_fournisseur'; + $sql .= ', s.accountancy_code_buy, s.accountancy_code_sell'; $sql .= ', s.vat_reverse_charge as soc_vat_reverse_charge'; } else { - $sql .= ', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell'; + $sql .= ', spe.accountancy_code_customer_general, spe.accountancy_code_customer as code_compta'; + $sql .= ', spe.accountancy_code_supplier as code_compta_fournisseur'; + $sql .= ', spe.accountancy_code_buy, spe.accountancy_code_sell'; $sql .= ', spe.vat_reverse_charge as spe_vat_reverse_charge'; } $sql .= ', s.code_client, s.code_fournisseur, s.parent, s.barcode'; @@ -2034,6 +2050,7 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 $this->code_client = $obj->code_client; $this->code_fournisseur = $obj->code_fournisseur; + $this->accountancy_code_customer_general = $obj->accountancy_code_customer_general; $this->code_compta = $obj->code_compta; // For backward compatibility $this->code_compta_client = $obj->code_compta; $this->code_compta_fournisseur = $obj->code_compta_fournisseur; From 849df0f0d3a3e646694d10ea1fe30478aac2c005 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 6 Oct 2024 07:25:52 +0200 Subject: [PATCH 03/13] NEW Accountancy - Add general account on thirdparty - Code customer part --- htdocs/accountancy/journal/bankjournal.php | 35 +++++++++------- htdocs/accountancy/journal/sellsjournal.php | 35 +++++++++------- htdocs/comm/card.php | 46 +++++++++++++++------ htdocs/langs/en_US/accountancy.lang | 2 + 4 files changed, 77 insertions(+), 41 deletions(-) diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 8ec10ca961ebc..00d1c3320f555 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -1,18 +1,18 @@ - * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013 Christophe Battarel - * Copyright (C) 2013-2022 Open-DSI - * Copyright (C) 2013-2024 Alexandre Spangaro - * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2014 Olivier Geffroy - * Copyright (C) 2017-2024 Frédéric France - * Copyright (C) 2018 Ferran Marcet - * Copyright (C) 2018-2024 Eric Seigne - * Copyright (C) 2021 Gauthier VERDOL - * Copyright (C) 2024 MDW +/* Copyright (C) 2007-2010 Laurent Destailleur + * Copyright (C) 2007-2010 Jean Heimburger + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013 Christophe Battarel + * Copyright (C) 2013-2022 Open-DSI + * Copyright (C) 2013-2024 Alexandre Spangaro + * Copyright (C) 2013-2014 Florian Henry + * Copyright (C) 2013-2014 Olivier Geffroy + * Copyright (C) 2017-2024 Frédéric France + * Copyright (C) 2018 Ferran Marcet + * Copyright (C) 2018-2024 Eric Seigne + * Copyright (C) 2021 Gauthier VERDOL + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -140,9 +140,11 @@ $sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,"; $sql .= " soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,"; if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { + $sql .= " spe.accountancy_code_customer_general,"; $sql .= " spe.accountancy_code_customer as code_compta_client,"; $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; } else { + $sql .= " soc.accountancy_code_customer_general,"; $sql .= " soc.code_compta as code_compta_client,"; $sql .= " soc.code_compta_fournisseur,"; } @@ -283,6 +285,7 @@ $compta_soc = (($obj->code_compta_fournisseur != "") ? $obj->code_compta_fournisseur : $account_supplier); } if ($lineisasale > 0) { + $accountancy_code_general = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer; $compta_soc = (!empty($obj->code_compta_client) ? $obj->code_compta_client : $account_customer); } @@ -290,6 +293,7 @@ 'id' => $obj->socid, 'name' => $obj->name, 'code_compta' => $compta_soc, + 'accountancy_code_general' => $accountancy_code_general, 'email' => $obj->email ); @@ -1029,7 +1033,8 @@ if ($tabtype[$key] == 'payment_supplier') { print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER').'"'.$sep; } elseif ($tabtype[$key] == 'payment') { - print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER').'"'.$sep; + $account_ledger = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer; + print '"'.$account_ledger.'"'.$sep; } elseif ($tabtype[$key] == 'payment_expensereport') { print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT').'"'.$sep; } elseif ($tabtype[$key] == 'payment_salary') { diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index f0c0b1a894a60..ded0ab0c53bb6 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -1,15 +1,15 @@ - * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013 Christophe Battarel - * Copyright (C) 2013-2024 Alexandre Spangaro - * Copyright (C) 2013-2016 Florian Henry - * Copyright (C) 2013-2016 Olivier Geffroy - * Copyright (C) 2014 Raphaël Doursenaud - * Copyright (C) 2018-2021 Frédéric France - * Copyright (C) 2024 MDW +/* Copyright (C) 2007-2010 Laurent Destailleur + * Copyright (C) 2007-2010 Jean Heimburger + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013 Christophe Battarel + * Copyright (C) 2013-2024 Alexandre Spangaro + * Copyright (C) 2013-2016 Florian Henry + * Copyright (C) 2013-2016 Olivier Geffroy + * Copyright (C) 2014 Raphaël Doursenaud + * Copyright (C) 2018-2021 Frédéric France + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -133,9 +133,11 @@ $sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code, fd.info_bits,"; $sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,"; if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { + $sql .= " spe.accountancy_code_customer_general,"; $sql .= " spe.accountancy_code_customer as code_compta_client,"; $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; } else { + $sql .= " s.accountancy_code_customer_general,"; $sql .= " s.code_compta as code_compta_client,"; $sql .= " s.code_compta_fournisseur,"; } @@ -219,6 +221,7 @@ $obj = $db->fetch_object($result); // Controls + $accountancy_code_customer_general = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $cptcli; $compta_soc = (!empty($obj->code_compta_client)) ? $obj->code_compta_client : $cptcli; $compta_prod = $obj->compte; @@ -367,6 +370,7 @@ 'id' => $obj->socid, 'name' => $obj->name, 'code_client' => $obj->code_client, + 'accountancy_code_customer_general' => $accountancy_code_customer_general, 'code_compta' => $compta_soc ); @@ -474,6 +478,7 @@ $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; + $companystatic->accountancy_code_customer_general = $tabcompany[$key]['accountancy_code_customer_general']; $companystatic->code_compta = $tabcompany[$key]['code_compta']; $companystatic->code_compta_client = $tabcompany[$key]['code_compta']; $companystatic->code_client = $tabcompany[$key]['code_client']; @@ -576,7 +581,7 @@ $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; $bookkeeping->subledger_label = $tabcompany[$key]['name']; - $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'); + $bookkeeping->numero_compte = !empty($tabcompany[$key]['accountancy_code_customer_general']) ? $tabcompany[$key]['accountancy_code_customer_general'] : $cptcli; $bookkeeping->label_compte = $accountingaccountcustomer->label; $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$langs->trans("SubledgerAccount"); @@ -884,6 +889,7 @@ foreach ($tabfac as $key => $val) { $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; + $companystatic->accountancy_code_customer_general = !empty($tabcompany[$key]['accountancy_code_customer_general']) ? $tabcompany[$key]['accountancy_code_customer_general'] : $cptcli; $companystatic->code_compta = $tabcompany[$key]['code_compta']; // deprecated $companystatic->code_compta_client = $tabcompany[$key]['code_compta']; $companystatic->code_client = $tabcompany[$key]['code_client']; @@ -940,7 +946,7 @@ print '"'.$val["ref"].'"'.$sep; print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER')).'"'.$sep; + print '"'.length_accountg($companystatic->accountancy_code_customer_general).'"'.$sep; print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; print '"'.$langs->trans("Thirdparty").'"'.$sep; print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$invoicestatic->ref.' - '.$langs->trans("Thirdparty").'"'.$sep; @@ -1136,6 +1142,7 @@ function writebookkeeping() { foreach ($tabfac as $key => $val) { $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; + $companystatic->accountancy_code_customer_general = !empty($tabcompany[$key]['accountancy_code_customer_general']) ? $tabcompany[$key]['accountancy_code_customer_general'] : $cptcli; $companystatic->code_compta = $tabcompany[$key]['code_compta']; $companystatic->code_compta_client = $tabcompany[$key]['code_compta']; $companystatic->code_client = $tabcompany[$key]['code_client']; @@ -1241,7 +1248,7 @@ function writebookkeeping() { print "".$invoicestatic->getNomUrl(1).""; // Account print ""; - $accountoshow = length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER')); + $accountoshow = length_accountg($companystatic->accountancy_code_customer_general); if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("MainAccountForCustomersNotDefined").''; } else { diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 9936beaae5ff2..75f455d9a84e2 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -1,16 +1,16 @@ - * Copyright (C) 2004-2020 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2005-2017 Regis Houssin - * Copyright (C) 2008 Raphael Bertrand (Resultic) - * Copyright (C) 2010-2020 Juanjo Menent - * Copyright (C) 2013 Alexandre Spangaro - * Copyright (C) 2021-2024 Frédéric France - * Copyright (C) 2015 Marcos García - * Copyright (C) 2020 Open-Dsi - * Copyright (C) 2022 Anthony Berton +/* Copyright (C) 2001-2005 Rodolphe Quiedeville + * Copyright (C) 2004-2020 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2005-2017 Regis Houssin + * Copyright (C) 2008 Raphael Bertrand (Resultic) + * Copyright (C) 2010-2020 Juanjo Menent + * Copyright (C) 2013-2024 Alexandre Spangaro + * Copyright (C) 2021-2024 Frédéric France + * Copyright (C) 2015 Marcos García + * Copyright (C) 2020 Open-Dsi + * Copyright (C) 2022 Anthony Berton * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -161,6 +161,16 @@ $action = ""; } + // set accountancy code + if ($action == 'setcustomeraccountancycodegeneral') { + $result = $object->fetch($id); + $object->accountancy_code_customer_general = GETPOST("customeraccountancycodegeneral"); + $result = $object->update($object->id, $user, 1, 1, 0); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + // Set accountancy code if ($action == 'setcustomeraccountancycode' && $user->hasRight('societe', 'creer')) { $result = $object->fetch($id); @@ -362,6 +372,18 @@ } print ''; + if (!empty($conf->accounting->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + print ''; + print ''; + print $form->editfieldkey("CustomerAccountancyCodeGeneral", 'customeraccountancycodegeneral', length_accountg($object->accountancy_code_customer_general), $object, $user->hasRight('societe', 'creer')); + print ''; + print $form->editfieldval("CustomerAccountancyCodeGeneral", 'customeraccountancycodegeneral', length_accountg($object->accountancy_code_customer_general), $object, $user->hasRight('societe', 'creer')); + $accountingAccountByDefault = " (" . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER')) . ")"; + print (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') ? $accountingAccountByDefault : ''); + print ''; + } + print ''; print ''; print $form->editfieldkey("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta_client, $object, $user->hasRight('societe', 'creer')); diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index fdc99e5e71805..399a2efcc7921 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -56,6 +56,8 @@ ExportAccountancy=Export accountancy WarningDataDisappearsWhenDataIsExported=Warning, this list contains only the accounting entries that have not been already exported (Export date is empty). If you want to include the accounting entries already exported, click on the button above. VueByAccountAccounting=View by accounting account VueBySubAccountAccounting=View by accounting subaccount +AccountingAccountByDefault=Accounting account by default +AccountingAccountByDefaultShort=Account by default MainAccountForCustomersNotDefined=Main account (from the Chart of Account) for customers not defined in setup MainAccountForSuppliersNotDefined=Main account (from the Chart of Account) for vendors not defined in setup From 6e7eb480cde817ded89aa8428f1a4291c32b3fcc Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 6 Oct 2024 21:20:14 +0200 Subject: [PATCH 04/13] NEW Accountancy - Add general account on thirdparty - Code customer part --- htdocs/langs/en_US/compta.lang | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index d1fb40ce3d56e..685957d4a8c64 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -118,7 +118,9 @@ SocialContributionsPayments=Social/fiscal taxes payments ShowVatPayment=Show VAT payment TotalToPay=Total to pay BalanceVisibilityDependsOnSortAndFilters=Balance is visible in this list only if table is sorted on %s and filtered on 1 bank account (with no other filters) +CustomerAccountancyCodeGeneral=General accounting code CustomerAccountancyCode=Customer accounting code +SupplierAccountancyCodeGeneral=General accounting code SupplierAccountancyCode=Vendor accounting code CustomerAccountancyCodeShort=Cust. account. code SupplierAccountancyCodeShort=Sup. account. code From 5dc9c4b1c865f90ac71d8c6c5577e1e6742156f8 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 6 Oct 2024 22:50:42 +0200 Subject: [PATCH 05/13] Fix Phan --- htdocs/accountancy/journal/bankjournal.php | 3 +++ htdocs/accountancy/journal/sellsjournal.php | 1 + 2 files changed, 4 insertions(+) diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 00d1c3320f555..bbdc454b3a062 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -227,6 +227,8 @@ @phan-var-force array $tabtp '; +$account_customer = 'NotDefined'; + //print $sql; dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG); $result = $db->query($sql); @@ -281,6 +283,7 @@ // Set accountancy code for thirdparty (example: '411CU...' or '411' if no subledger account defined on customer) $compta_soc = 'NotDefined'; + $accountancy_code_general = 'NotDefined'; if ($lineisapurchase > 0) { $compta_soc = (($obj->code_compta_fournisseur != "") ? $obj->code_compta_fournisseur : $account_supplier); } diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index e9de3b6172201..c6347a4689c70 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -85,6 +85,7 @@ $tablocaltax1 = array(); $tablocaltax2 = array(); +$cptcli = 'NotDefined'; /* * Actions From 9ea593ae3c68b6ac84ee172f43fc34307f9db23f Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 7 Oct 2024 04:40:36 +0200 Subject: [PATCH 06/13] Use isModEnabled --- htdocs/comm/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 75f455d9a84e2..9eac5fed056bf 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -372,7 +372,7 @@ } print ''; - if (!empty($conf->accounting->enabled)) { + if (isModEnabled('accounting')) { require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; print ''; print ''; From b4dc0099dc2c298ca86f41a986550e6815ad7812 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 9 Oct 2024 06:19:10 +0200 Subject: [PATCH 07/13] NEW Accountancy - Add general account on thirdparty - Code supplier part --- htdocs/accountancy/journal/bankjournal.php | 7 ++- .../accountancy/journal/purchasesjournal.php | 15 ++++-- htdocs/accountancy/journal/sellsjournal.php | 3 ++ htdocs/fourn/card.php | 46 +++++++++++++++---- htdocs/societe/class/societe.class.php | 21 +++++++-- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index bbdc454b3a062..b80276bb527e1 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -142,10 +142,12 @@ if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { $sql .= " spe.accountancy_code_customer_general,"; $sql .= " spe.accountancy_code_customer as code_compta_client,"; + $sql .= " spe.accountancy_code_supplier_general,"; $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; } else { $sql .= " soc.accountancy_code_customer_general,"; $sql .= " soc.code_compta as code_compta_client,"; + $sql .= " soc.accountancy_code_supplier_general,"; $sql .= " soc.code_compta_fournisseur,"; } $sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,"; @@ -228,6 +230,7 @@ '; $account_customer = 'NotDefined'; +$account_supplier = 'NotDefined'; //print $sql; dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG); @@ -285,6 +288,7 @@ $compta_soc = 'NotDefined'; $accountancy_code_general = 'NotDefined'; if ($lineisapurchase > 0) { + $accountancy_code_general = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier; $compta_soc = (($obj->code_compta_fournisseur != "") ? $obj->code_compta_fournisseur : $account_supplier); } if ($lineisasale > 0) { @@ -1034,7 +1038,8 @@ print '"'.$val["type_payment"].'"'.$sep; print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; if ($tabtype[$key] == 'payment_supplier') { - print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER').'"'.$sep; + $account_ledger = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $account_supplier; + print '"'.$account_ledger.'"'.$sep; } elseif ($tabtype[$key] == 'payment') { $account_ledger = (!empty($obj->accountancy_code_customer_general)) ? $obj->accountancy_code_customer_general : $account_customer; print '"'.$account_ledger.'"'.$sep; diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 0652a6bfc5223..47734ed89795b 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -133,10 +133,14 @@ $sql .= " co.code as country_code, co.label as country_label,"; $sql .= " s.rowid as socid, s.nom as name, s.fournisseur, s.code_client, s.code_fournisseur, s.fk_pays,"; if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { + $sql .= " spe.accountancy_code_customer_general,"; $sql .= " spe.accountancy_code_customer as code_compta,"; + $sql .= " spe.accountancy_code_supplier_general,"; $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; } else { + $sql .= " s.accountancy_code_customer_general,"; $sql .= " s.code_compta as code_compta,"; + $sql .= " s.accountancy_code_supplier_general,"; $sql .= " s.code_compta_fournisseur,"; } if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { @@ -221,6 +225,7 @@ $obj = $db->fetch_object($result); // Controls + $accountancy_code_supplier_general = (!empty($obj->accountancy_code_supplier_general)) ? $obj->accountancy_code_supplier_general : $cptfour; $compta_soc = ($obj->code_compta_fournisseur != "") ? $obj->code_compta_fournisseur : $cptfour; $compta_prod = $obj->compte; @@ -339,6 +344,7 @@ 'id' => $obj->socid, 'name' => $obj->name, 'code_fournisseur' => $obj->code_fournisseur, + 'accountancy_code_supplier_general' => $accountancy_code_supplier_general, 'code_compta_fournisseur' => $compta_soc ); @@ -427,6 +433,7 @@ $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; + $companystatic->accountancy_code_supplier_general = $tabcompany[$key]['accountancy_code_supplier_customer']; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->fournisseur = 1; @@ -479,7 +486,7 @@ $bookkeeping->subledger_account = $tabcompany[$key]['code_compta_fournisseur']; $bookkeeping->subledger_label = $tabcompany[$key]['name']; - $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'); + $bookkeeping->numero_compte = $tabcompany[$key]['accountancy_code_supplier_general']; $bookkeeping->label_compte = $accountingaccountsupplier->label; $bookkeeping->label_operation = $bookkeepingstatic->accountingLabelForOperation($companystatic->name, $invoicestatic->ref_supplier, $langs->trans("SubledgerAccount")); @@ -803,6 +810,7 @@ foreach ($tabfac as $key => $val) { $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; + $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_customer_general'] : $cptfour; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->fournisseur = 1; @@ -839,7 +847,7 @@ print '"'.$val["refsologest"].'"'.$sep; print '"'.csvClean(dol_trunc($companystatic->name, 32)).'"'.$sep; print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')).'"'.$sep; + print '"'.length_accountg($companystatic->accountancy_code_supplier_general).'"'.$sep; print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; print '"'.$langs->trans("Thirdparty").'"'.$sep; print '"'.csvClean($bookkeepingstatic->accountingLabelForOperation($companystatic->name, $val["refsuppliersologest"], $langs->trans("Thirdparty"))).'"'.$sep; @@ -1057,6 +1065,7 @@ function writebookkeeping() { foreach ($tabfac as $key => $val) { $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; + $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->fournisseur = 1; @@ -1131,7 +1140,7 @@ function writebookkeeping() { print "".$invoicestatic->getNomUrl(1).""; // Account print ""; - $accountoshow = length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')); + $accountoshow = length_accountg(!empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour); if (($accountoshow == "") || $accountoshow == 'NotDefined') { print ''.$langs->trans("MainAccountForSuppliersNotDefined").''; } else { diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index c6347a4689c70..ce72be89a6d89 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -86,6 +86,7 @@ $tablocaltax2 = array(); $cptcli = 'NotDefined'; +$cptfourn = 'NotDefined'; /* * Actions @@ -136,10 +137,12 @@ if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { $sql .= " spe.accountancy_code_customer_general,"; $sql .= " spe.accountancy_code_customer as code_compta_client,"; + $sql .= " spe.accountancy_code_supplier_general,"; $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; } else { $sql .= " s.accountancy_code_customer_general,"; $sql .= " s.code_compta as code_compta_client,"; + $sql .= " s.accountancy_code_supplier_general,"; $sql .= " s.code_compta_fournisseur,"; } $sql .= " p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,"; diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 1044bfbb05ec2..17bd67eef502e 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -1,14 +1,15 @@ - * Copyright (C) 2003 Eric Seigne - * Copyright (C) 2004-2016 Laurent Destailleur - * Copyright (C) 2005-2010 Regis Houssin - * Copyright (C) 2010-2015 Juanjo Menent - * Copyright (C) 2014 Jean Heimburger - * Copyright (C) 2015 Marcos García - * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) 2021 Frédéric France +/* Copyright (C) 2001-2005 Rodolphe Quiedeville + * Copyright (C) 2003 Eric Seigne + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2010-2015 Juanjo Menent + * Copyright (C) 2014 Jean Heimburger + * Copyright (C) 2015 Marcos García + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2021 Frédéric France * Copyright (C) 2024 MDW + * Copyright (C) 2024 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -106,7 +107,18 @@ $action = ""; } - // Set supplier accounting account + // set general supplier accounting account + if ($action == 'setsupplieraccountancycodegeneral' && $user->hasRight('societe', 'creer')) { + $result = $object->fetch($id); + $object->accountancy_code_supplier_general = GETPOST("supplieraccountancycodegeneral"); + $result = $object->update($object->id, $user, 1, 0, 1); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $_GET['action'] = 'editsupplieraccountancycode'; + } + } + + // Set auxiliary supplier accounting account if ($action == 'setsupplieraccountancycode' && $user->hasRight('societe', 'creer')) { $result = $object->fetch($id); $object->code_compta_fournisseur = GETPOST("supplieraccountancycode"); @@ -248,6 +260,20 @@ print ''; print ''; + if (isModEnabled('accounting')) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + + print ''; + print ''; + print $form->editfieldkey("SupplierAccountancyCodeGeneral", 'supplieraccountancycodegeneral', length_accountg($object->accountancy_code_supplier_general), $object, $user->hasRight('societe', 'creer')); + print ''; + print $form->editfieldval("SupplierAccountancyCodeGeneral", 'supplieraccountancycodegeneral', length_accountg($object->accountancy_code_supplier_general), $object, $user->hasRight('societe', 'creer')); + $accountingAccountByDefault = " (" . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) . ")"; + print (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') ? $accountingAccountByDefault : ''); + print ''; + print ''; + } + $langs->load('compta'); print ''; print ''; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 12dcaffc3b5d8..adf71154eb661 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -690,7 +690,13 @@ class Societe extends CommonObject public $code_compta_fournisseur; /** - * Accounting code for supplier + * Accounting general account for supplier + * @var string + */ + public $accountancy_code_supplier_general; + + /** + * Accounting auxiliary account for supplier * @var string */ public $accountancy_code_supplier; @@ -982,6 +988,7 @@ public function create(User $user, $notrigger = 0) $this->accountancy_code_customer_general = trim($this->accountancy_code_customer_general); $this->accountancy_code_customer = trim((string) $this->code_compta_client); + $this->accountancy_code_supplier_general = trim($this->accountancy_code_supplier_general); $this->accountancy_code_supplier = trim((string) $this->code_compta_fournisseur); $this->accountancy_code_buy = trim((string) $this->accountancy_code_buy); $this->accountancy_code_sell = trim((string) $this->accountancy_code_sell); @@ -1082,6 +1089,7 @@ public function create(User $user, $notrigger = 0) $sql .= ", vat_reverse_charge"; $sql .= ", accountancy_code_customer_general"; $sql .= ", accountancy_code_customer"; + $sql .= ", accountancy_code_supplier_general"; $sql .= ", accountancy_code_supplier"; $sql .= ", accountancy_code_buy"; $sql .= ", accountancy_code_sell"; @@ -1091,6 +1099,7 @@ public function create(User $user, $notrigger = 0) $sql .= ", ".(empty($this->vat_reverse_charge) ? '0' : '1'); $sql .= ", '".$this->db->escape($this->accountancy_code_customer_general)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_customer)."'"; + $sql .= ", '".$this->db->escape($this->accountancy_code_supplier_general)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_supplier)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_sell)."'"; @@ -1496,8 +1505,10 @@ public function update($id, User $user, $call_trigger = 1, $allowmodcodeclient = $this->get_codefournisseur($this, 1); } + $this->accountancy_code_customer_general = trim($this->accountancy_code_customer_general); $this->code_compta_client = trim(empty($this->code_compta_client) ? $this->code_compta : $this->code_compta_client); $this->code_compta = $this->code_compta_client; // for backward compatibility + $this->accountancy_code_supplier_general = trim($this->accountancy_code_supplier_general); $this->code_compta_fournisseur = (empty($this->code_compta_fournisseur) ? '' : trim($this->code_compta_fournisseur)); // Check parameters. More tests are done later in the ->verify() @@ -1680,6 +1691,7 @@ public function update($id, User $user, $call_trigger = 1, $allowmodcodeclient = } if ($supplier) { + $sql .= ", accountancy_code_supplier_general = ".(!empty($this->accountancy_code_supplier_general) ? "'".$this->db->escape($this->accountancy_code_supplier_general)."'" : "null"); $sql .= ", code_compta_fournisseur = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); } } @@ -1773,6 +1785,7 @@ public function update($id, User $user, $call_trigger = 1, $allowmodcodeclient = $sql .= ", vat_reverse_charge"; $sql .= ", accountancy_code_customer_general"; $sql .= ", accountancy_code_customer"; + $sql .= ", accountancy_code_supplier_general"; $sql .= ", accountancy_code_supplier"; $sql .= ", accountancy_code_buy"; $sql .= ", accountancy_code_sell"; @@ -1782,6 +1795,7 @@ public function update($id, User $user, $call_trigger = 1, $allowmodcodeclient = $sql .= ", ".(empty($this->vat_reverse_charge) ? '0' : '1'); $sql .= ", '".$this->db->escape($this->accountancy_code_customer_general)."'"; $sql .= ", '".$this->db->escape($this->code_compta_client)."'"; + $sql .= ", '".$this->db->escape($this->accountancy_code_supplier_general)."'"; $sql .= ", '".$this->db->escape($this->code_compta_fournisseur)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_sell)."'"; @@ -1887,12 +1901,12 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 $sql .= ', s.webservices_url, s.webservices_key, s.model_pdf, s.last_main_doc'; if (!getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { $sql .= ', s.accountancy_code_customer_general, s.code_compta'; - $sql .= ', s.code_compta_fournisseur'; + $sql .= ', s.accountancy_code_supplier_general, s.code_compta_fournisseur'; $sql .= ', s.accountancy_code_buy, s.accountancy_code_sell'; $sql .= ', s.vat_reverse_charge as soc_vat_reverse_charge'; } else { $sql .= ', spe.accountancy_code_customer_general, spe.accountancy_code_customer as code_compta'; - $sql .= ', spe.accountancy_code_supplier as code_compta_fournisseur'; + $sql .= ', spe.accountancy_code_supplier_general, spe.accountancy_code_supplier as code_compta_fournisseur'; $sql .= ', spe.accountancy_code_buy, spe.accountancy_code_sell'; $sql .= ', spe.vat_reverse_charge as spe_vat_reverse_charge'; } @@ -2053,6 +2067,7 @@ public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 $this->accountancy_code_customer_general = $obj->accountancy_code_customer_general; $this->code_compta = $obj->code_compta; // For backward compatibility $this->code_compta_client = $obj->code_compta; + $this->accountancy_code_supplier_general = $obj->accountancy_code_supplier_general; $this->code_compta_fournisseur = $obj->code_compta_fournisseur; $this->barcode = $obj->barcode; From bb6ab89cee875f2367f755312c257bd4f8471ed1 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 9 Oct 2024 08:41:44 +0200 Subject: [PATCH 08/13] Fix phan --- htdocs/accountancy/journal/purchasesjournal.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 47734ed89795b..60555080da366 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -86,6 +86,8 @@ $tabrclocaltax2 = array(); $tabpay = array(); +$cptcli = 'NotDefined'; +$cptfourn = 'NotDefined'; /* * Actions @@ -433,7 +435,7 @@ $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; - $companystatic->accountancy_code_supplier_general = $tabcompany[$key]['accountancy_code_supplier_customer']; + $companystatic->accountancy_code_supplier_general = $tabcompany[$key]['accountancy_code_supplier_general']; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->fournisseur = 1; @@ -553,7 +555,7 @@ if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) { if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) { - $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; + $bookkeeping->subledger_account = $tabcompany[$key]['code_compta_fournisseur']; $bookkeeping->subledger_label = $tabcompany[$key]['name']; } else { $bookkeeping->subledger_account = ''; @@ -810,7 +812,7 @@ foreach ($tabfac as $key => $val) { $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; - $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_customer_general'] : $cptfour; + $companystatic->accountancy_code_supplier_general = !empty($tabcompany[$key]['accountancy_code_supplier_general']) ? $tabcompany[$key]['accountancy_code_supplier_general'] : $cptfour; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; $companystatic->fournisseur = 1; From 7907efde16550cc9a47e9b077be2377d0e96193a Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 9 Oct 2024 08:51:42 +0200 Subject: [PATCH 09/13] Fix phan --- htdocs/accountancy/journal/purchasesjournal.php | 2 +- htdocs/accountancy/journal/sellsjournal.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 60555080da366..a1c9cc7d0b88c 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -87,7 +87,7 @@ $tabpay = array(); $cptcli = 'NotDefined'; -$cptfourn = 'NotDefined'; +$cptfour = 'NotDefined'; /* * Actions diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index ce72be89a6d89..694cf1df68ff6 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -86,7 +86,6 @@ $tablocaltax2 = array(); $cptcli = 'NotDefined'; -$cptfourn = 'NotDefined'; /* * Actions From b5720dfacd4bfc3af2da19fe31699f3717fe9a5a Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 9 Oct 2024 09:52:09 +0200 Subject: [PATCH 10/13] Fix phan --- htdocs/accountancy/journal/purchasesjournal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index a1c9cc7d0b88c..d225daccce804 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -1193,7 +1193,7 @@ function writebookkeeping() { print ""; if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) { if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) { - print length_accounta($tabcompany[$key]['code_compta']); + print length_accounta($tabcompany[$key]['code_compta_fournisseur']); } } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') { print '' . $langs->trans("ThirdpartyAccountNotDefined") . ''; From 6aa9f13bd9f704a3499cdad5833f5376a33fc0a9 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 10 Oct 2024 22:22:24 +0200 Subject: [PATCH 11/13] Use list of account instead of simple input --- htdocs/fourn/card.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 17bd67eef502e..acfddf64ec3eb 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -35,7 +35,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; -require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture-rec.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture-rec.class.php'; require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; @@ -47,7 +47,8 @@ require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; } if (isModEnabled('accounting')) { - require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; } // Load translation files required by page @@ -261,14 +262,21 @@ print ''; if (isModEnabled('accounting')) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + $formaccounting = new FormAccounting($db); print ''; print ''; print $form->editfieldkey("SupplierAccountancyCodeGeneral", 'supplieraccountancycodegeneral', length_accountg($object->accountancy_code_supplier_general), $object, $user->hasRight('societe', 'creer')); print ''; - print $form->editfieldval("SupplierAccountancyCodeGeneral", 'supplieraccountancycodegeneral', length_accountg($object->accountancy_code_supplier_general), $object, $user->hasRight('societe', 'creer')); - $accountingAccountByDefault = " (" . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) . ")"; + if ($action == 'editsupplieraccountancycodegeneral' && $user->hasRight('societe', 'creer')) { + print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->accountancy_code_supplier_general, 'supplieraccountancycodegeneral', 0, 1, '', 1); + } else { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(0, $object->accountancy_code_supplier_general, 1); + + print $accountingaccount->getNomUrl(0, 1, 1, '', 1); + } + $accountingAccountByDefault = " (" . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) . ")"; print (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') ? $accountingAccountByDefault : ''); print ''; print ''; From afdd9323f0fba145fb0707b78bec3b3884478c21 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 10 Oct 2024 22:27:18 +0200 Subject: [PATCH 12/13] Use list of account instead of simple input --- htdocs/comm/card.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 6ad82fd03622e..e0cbadb55b4e0 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -66,6 +66,10 @@ if (isModEnabled('intervention')) { require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; } +if (isModEnabled('accounting')) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; +} // Load translation files required by the page $langs->loadLangs(array('companies', 'banks')); @@ -373,12 +377,20 @@ print ''; if (isModEnabled('accounting')) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + $formaccounting = new FormAccounting($db); + print ''; print ''; print $form->editfieldkey("CustomerAccountancyCodeGeneral", 'customeraccountancycodegeneral', length_accountg($object->accountancy_code_customer_general), $object, $user->hasRight('societe', 'creer')); print ''; - print $form->editfieldval("CustomerAccountancyCodeGeneral", 'customeraccountancycodegeneral', length_accountg($object->accountancy_code_customer_general), $object, $user->hasRight('societe', 'creer')); + if ($action == 'editcustomeraccountancycodegeneral' && $user->hasRight('societe', 'creer')) { + print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->accountancy_code_customer_general, 'customeraccountancycodegeneral', 0, 1, '', 1); + } else { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(0, $object->accountancy_code_customer_general, 1); + + print $accountingaccount->getNomUrl(0, 1, 1, '', 1); + } $accountingAccountByDefault = " (" . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER')) . ")"; print (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') ? $accountingAccountByDefault : ''); print ''; From 46985592a1c306e72f46ff37eb918f76fce417cb Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 10 Oct 2024 22:31:06 +0200 Subject: [PATCH 13/13] Tabs --- htdocs/fourn/card.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index acfddf64ec3eb..8d1f5be101641 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -48,7 +48,7 @@ } if (isModEnabled('accounting')) { require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; - require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; + require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; } // Load translation files required by page @@ -269,14 +269,14 @@ print $form->editfieldkey("SupplierAccountancyCodeGeneral", 'supplieraccountancycodegeneral', length_accountg($object->accountancy_code_supplier_general), $object, $user->hasRight('societe', 'creer')); print ''; if ($action == 'editsupplieraccountancycodegeneral' && $user->hasRight('societe', 'creer')) { - print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->accountancy_code_supplier_general, 'supplieraccountancycodegeneral', 0, 1, '', 1); - } else { - $accountingaccount = new AccountingAccount($db); - $accountingaccount->fetch(0, $object->accountancy_code_supplier_general, 1); - - print $accountingaccount->getNomUrl(0, 1, 1, '', 1); - } - $accountingAccountByDefault = " (" . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) . ")"; + print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->accountancy_code_supplier_general, 'supplieraccountancycodegeneral', 0, 1, '', 1); + } else { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(0, $object->accountancy_code_supplier_general, 1); + + print $accountingaccount->getNomUrl(0, 1, 1, '', 1); + } + $accountingAccountByDefault = " (" . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) . ")"; print (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') ? $accountingAccountByDefault : ''); print ''; print '';