From 24e3dd09920d05cc30e744c63eed4124693ac7f7 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 7 Oct 2021 06:05:36 +0200 Subject: [PATCH 1/5] Prepare sql --- htdocs/install/mysql/migration/14.0.0-15.0.0.sql | 4 ++++ htdocs/install/mysql/tables/llx_societe.sql | 6 +++--- htdocs/install/mysql/tables/llx_societe_perentity.sql | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql index 82a6bdec3dc..9a530147d9e 100644 --- a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql +++ b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql @@ -370,3 +370,7 @@ ALTER TABLE llx_hrm_skillrank ADD INDEX idx_hrm_skillrank_fk_skill (fk_skill); ALTER TABLE llx_hrm_skillrank ADD CONSTRAINT llx_hrm_skillrank_fk_user_creat FOREIGN KEY (fk_user_creat) REFERENCES llx_user(rowid); --END GRH/HRM MODULE + +-- Manage accountancy auxiliary account for thirdparties per entity +ALTER TABLE llx_societe_perentity ADD COLUMN accountancy_code_customer varchar(24) AFTER entity; -- equivalent to code_compta in llx_societe +ALTER TABLE llx_societe_perentity ADD COLUMN accountancy_code_supplier varchar(24) AFTER accountancy_code_supplier; -- equivalent to code_compta_supplier in llx_societe diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index 7112b6e93ea..011c82b65f7 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -37,9 +37,9 @@ create table llx_societe status tinyint DEFAULT 1, -- cessation d'activité ( 1 -- en activité, 0 -- cessation d'activité) code_client varchar(24), -- code client - code_fournisseur varchar(24), -- code founisseur - code_compta varchar(24), -- code compta client - code_compta_fournisseur varchar(24), -- code compta founisseur + code_fournisseur varchar(24), -- code fournisseur + code_compta varchar(24), -- customer accountancy auxiliary account + code_compta_fournisseur varchar(24), -- 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.sql b/htdocs/install/mysql/tables/llx_societe_perentity.sql index 408169476d9..800d4a10679 100644 --- a/htdocs/install/mysql/tables/llx_societe_perentity.sql +++ b/htdocs/install/mysql/tables/llx_societe_perentity.sql @@ -21,8 +21,8 @@ create table llx_societe_perentity rowid integer AUTO_INCREMENT PRIMARY KEY, fk_soc integer, entity integer DEFAULT 1 NOT NULL, -- multi company id --- code_compta varchar(24), -- code compta client --- code_compta_fournisseur varchar(24), -- code compta founisseur + 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 )ENGINE=innodb; From adfae3011228067d1c1137b869e050d95a394490 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 7 Oct 2021 06:18:39 +0200 Subject: [PATCH 2/5] NEW Societe - Add perentity functionality on customer/supplier accountancy auxiliary account --- htdocs/accountancy/supplier/list.php | 4 +++- htdocs/core/boxes/box_factures_imp.php | 17 +++++++++++++-- htdocs/societe/class/societe.class.php | 29 ++++++++++++++++++++------ htdocs/societe/index.php | 12 +++++++++-- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index ffdd5b6de57..13553358cf9 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -243,10 +243,12 @@ if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { $sql .= " p.tosell as status, p.tobuy as status_buy,"; $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,"; $sql .= " co.code as country_code, co.label as country_label,"; -$sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,"; +$sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur,"; if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= " spe.accountancy_code_customer as code_compta_client, spe.accountancy_code_supplier as code_compta_fournisseur,"; $sql .= " spe.accountancy_code_buy as company_code_buy"; } else { + $sql .= " s.code_compta as code_compta_client, s.code_compta_fournisseur,"; $sql .= " s.accountancy_code_buy as company_code_buy"; } $parameters = array(); diff --git a/htdocs/core/boxes/box_factures_imp.php b/htdocs/core/boxes/box_factures_imp.php index 3b6e857b058..434ebec2602 100644 --- a/htdocs/core/boxes/box_factures_imp.php +++ b/htdocs/core/boxes/box_factures_imp.php @@ -88,7 +88,12 @@ class box_factures_imp extends ModeleBoxes if ($user->rights->facture->lire) { $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias"; - $sql .= ", s.code_client, s.code_compta, s.client"; + $sql .= ", s.code_client, s.client"; + if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= ", spe.accountancy_code_customer as code_compta"; + } else { + $sql .= ", s.code_compta"; + } $sql .= ", s.logo, s.email, s.entity"; $sql .= ", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6"; $sql .= ", f.ref, f.date_lim_reglement as datelimite"; @@ -100,6 +105,9 @@ class box_factures_imp extends ModeleBoxes $sql .= ", f.paye, f.fk_statut as status, f.rowid as facid"; $sql .= ", sum(pf.amount) as am"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); + } if (!$user->rights->societe->client->voir && !$user->socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -115,7 +123,12 @@ class box_factures_imp extends ModeleBoxes if ($user->socid) { $sql .= " AND s.rowid = ".((int) $user->socid); } - $sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.code_compta, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,"; + $sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,"; + if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= " spe.accountancy_code_customer as code_compta"; + } else { + $sql .= " s.code_compta"; + } $sql .= " f.ref, f.date_lim_reglement,"; $sql .= " f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.rowid"; //$sql.= " ORDER BY f.datef DESC, f.ref DESC "; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 8c5ef8ca5ca..d83dd1f3d34 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1281,7 +1281,7 @@ class Societe extends CommonObject } $this->code_compta_client = trim(empty($this->code_compta) ? $this->code_compta_client : $this->code_compta); - $this->code_compta = $this->code_compta_client; // for backward compatbility + $this->code_compta = $this->code_compta_client; // for backward compatibility $this->code_compta_fournisseur = trim($this->code_compta_fournisseur); // Check parameters. More tests are done later in the ->verify() @@ -1451,6 +1451,14 @@ class Societe extends CommonObject if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { $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 .= ", code_compta = ".(!empty($this->code_compta_client) ? "'".$this->db->escape($this->code_compta_client)."'" : "null"); + } + + if ($supplier) { + $sql .= ", code_compta_fournisseur = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); + } } $sql .= ",webservices_url = ".(!empty($this->webservices_url) ? "'".$this->db->escape($this->webservices_url)."'" : "null"); $sql .= ",webservices_key = ".(!empty($this->webservices_key) ? "'".$this->db->escape($this->webservices_key)."'" : "null"); @@ -1461,12 +1469,10 @@ class Societe extends CommonObject if ($customer) { $sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null"); - $sql .= ", code_compta = ".(!empty($this->code_compta_client) ? "'".$this->db->escape($this->code_compta_client)."'" : "null"); } if ($supplier) { $sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null"); - $sql .= ", code_compta_fournisseur = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); } $sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id : "null"); $sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency; @@ -1540,12 +1546,23 @@ class Societe extends CommonObject $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_perentity ("; $sql .= " fk_soc"; $sql .= ", entity"; + $sql .= ", accountancy_code_customer"; + $sql .= ", accountancy_code_supplier"; $sql .= ", accountancy_code_buy"; $sql .= ", accountancy_code_sell"; $sql .= ") VALUES ("; $sql .= $this->id; $sql .= ", " . $conf->entity; $sql .= ", '" . $this->db->escape($this->accountancy_code_buy) . "'"; + + if ($customer) { + $sql .= ", accountancy_code_customer = ".(!empty($this->code_compta_client) ? "'".$this->db->escape($this->code_compta_client)."'" : "null"); + } + + if ($supplier) { + $sql .= ", accountancy_code_supplier = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); + } + $sql .= ", '" . $this->db->escape($this->accountancy_code_sell) . "'"; $sql .= ")"; $result = $this->db->query($sql); @@ -1646,11 +1663,11 @@ class Societe extends CommonObject $sql .= ', s.fk_forme_juridique as forme_juridique_code'; $sql .= ', s.webservices_url, s.webservices_key, s.model_pdf'; if (empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { - $sql .= ', s.accountancy_code_buy, s.accountancy_code_sell'; + $sql .= ', s.code_compta, s.code_compta_fournisseur, s.accountancy_code_buy, s.accountancy_code_sell'; } else { - $sql .= ', spe.accountancy_code_buy, spe.accountancy_code_sell'; + $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 .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode'; + $sql .= ', s.code_client, s.code_fournisseur, s.parent, s.barcode'; $sql .= ', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.mode_reglement, s.cond_reglement, s.transport_mode'; $sql .= ', s.fk_account, s.tva_assuj'; $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier'; diff --git a/htdocs/societe/index.php b/htdocs/societe/index.php index 3d645d41bf5..de3bae16627 100644 --- a/htdocs/societe/index.php +++ b/htdocs/societe/index.php @@ -263,12 +263,20 @@ $max = 15; $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur"; $sql .= ", s.code_client"; $sql .= ", s.code_fournisseur"; -$sql .= ", s.code_compta_fournisseur"; -$sql .= ", s.code_compta"; +if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur"; + $sql .= ", spe.accountancy_code_customer as code_compta"; +} else { + $sql .= ", s.code_compta_fournisseur"; + $sql .= ", s.code_compta"; +} $sql .= ", s.logo"; $sql .= ", s.entity"; $sql .= ", s.canvas, s.tms as date_modification, s.status as status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; +if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); +} if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } From e68d9dc73c8309de6d15621d0338ec577d74b6ef Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 7 Oct 2021 22:02:56 +0200 Subject: [PATCH 3/5] NEW Societe - Add perentity functionality on customer/supplier accountancy auxiliary account --- htdocs/accountancy/customer/lines.php | 14 ++++++++++-- htdocs/accountancy/customer/list.php | 6 ++++- htdocs/accountancy/journal/bankjournal.php | 14 ++++++++++-- .../accountancy/journal/purchasesjournal.php | 12 +++++++++- htdocs/accountancy/journal/sellsjournal.php | 12 +++++++++- htdocs/accountancy/supplier/lines.php | 12 +++++++++- htdocs/core/boxes/box_contacts.php | 12 +++++++++- htdocs/fourn/index.php | 10 ++++++++- .../accountancy/export-thirdpartyaccount.php | 22 ++++++++++++++++--- 9 files changed, 101 insertions(+), 13 deletions(-) diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index 1e7c38b2607..b833ca887e9 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -191,7 +191,14 @@ print ''; -$sql = "(SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta as compta , "; -$sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , f.datec , f.fk_soc , cp.label as country "; +$sql = "(SELECT s.rowid, s.nom as name , s.address, s.zip , s.town"; +if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= ", spe.accountancy_code_customer as compta"; +} else { + $sql .= ", s.code_compta"; +} +$sql .= ", s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , f.datec , f.fk_soc , cp.label as country "; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; +if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); +} $sql .= ", ".MAIN_DB_PREFIX."facture as f"; $sql .= ", ".MAIN_DB_PREFIX."c_country as cp"; $sql .= " WHERE f.fk_soc = s.rowid"; @@ -146,9 +154,17 @@ if ($socid > 0) { } $sql .= " GROUP BY name"; $sql .= ")"; -$sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , "; +$sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, , "; +if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= ", spe.accountancy_code_supplier as compta"; +} else { + $sql .= ", s.code_compta_fournisseur as compta"; +} $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , ff.datec , ff.fk_soc , cp.label as country "; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; +if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); +} $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as ff"; $sql .= ", ".MAIN_DB_PREFIX."c_country as cp"; $sql .= " WHERE ff.fk_soc = s.rowid"; From c7fd9328cd0ab47cd138530f719dc0830da05380 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 8 Oct 2021 06:29:22 +0200 Subject: [PATCH 4/5] NEW Societe - Add perentity functionality on customer/supplier accountancy auxiliary account --- htdocs/accountancy/customer/lines.php | 8 +++---- htdocs/accountancy/supplier/list.php | 6 +++-- htdocs/core/boxes/box_factures_imp.php | 4 ++-- .../societe/mod_codecompta_digitaria.php | 23 +++++++++++++++---- .../install/mysql/migration/14.0.0-15.0.0.sql | 2 +- htdocs/societe/card.php | 3 +++ htdocs/societe/class/societe.class.php | 21 ++++++++--------- 7 files changed, 43 insertions(+), 24 deletions(-) diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index b833ca887e9..7f09e111a23 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -193,11 +193,11 @@ $sql = "SELECT f.rowid as facid, f.ref as ref, f.type, f.datef, f.ref_client,"; $sql .= " fd.rowid, fd.description, fd.product_type as line_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.vat_src_code, fd.total_ttc,"; $sql .= " s.rowid as socid, s.nom as name, s.code_client,"; if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { - $sql .= ", spe.accountancy_code_customer as code_compta_client"; - $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur"; + $sql .= " spe.accountancy_code_customer as code_compta_client,"; + $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; } else { - $sql .= ", s.code_compta as code_compta_client"; - $sql .= ", s.code_compta_fournisseur"; + $sql .= " s.code_compta as code_compta_client,"; + $sql .= " s.code_compta_fournisseur,"; } $sql .= " p.rowid as product_id, p.fk_product_type as product_type, p.ref as product_ref, p.label as product_label,"; if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index 13553358cf9..b3cafa7e5fc 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -245,10 +245,12 @@ $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_ $sql .= " co.code as country_code, co.label as country_label,"; $sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur,"; if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { - $sql .= " spe.accountancy_code_customer as code_compta_client, spe.accountancy_code_supplier as code_compta_fournisseur,"; + $sql .= " spe.accountancy_code_customer as code_compta_client,"; + $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; $sql .= " spe.accountancy_code_buy as company_code_buy"; } else { - $sql .= " s.code_compta as code_compta_client, s.code_compta_fournisseur,"; + $sql .= " s.code_compta as code_compta_client,"; + $sql .= " s.code_compta_fournisseur,"; $sql .= " s.accountancy_code_buy as company_code_buy"; } $parameters = array(); diff --git a/htdocs/core/boxes/box_factures_imp.php b/htdocs/core/boxes/box_factures_imp.php index 434ebec2602..c78e5b7dec9 100644 --- a/htdocs/core/boxes/box_factures_imp.php +++ b/htdocs/core/boxes/box_factures_imp.php @@ -125,9 +125,9 @@ class box_factures_imp extends ModeleBoxes } $sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,"; if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { - $sql .= " spe.accountancy_code_customer as code_compta"; + $sql .= " spe.accountancy_code_customer as code_compta,"; } else { - $sql .= " s.code_compta"; + $sql .= " s.code_compta,"; } $sql .= " f.ref, f.date_lim_reglement,"; $sql .= " f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.rowid"; diff --git a/htdocs/core/modules/societe/mod_codecompta_digitaria.php b/htdocs/core/modules/societe/mod_codecompta_digitaria.php index c4887f01383..91f4bff07c4 100644 --- a/htdocs/core/modules/societe/mod_codecompta_digitaria.php +++ b/htdocs/core/modules/societe/mod_codecompta_digitaria.php @@ -252,17 +252,32 @@ class mod_codecompta_digitaria extends ModeleAccountancyCode */ public function checkIfAccountancyCodeIsAlreadyUsed($db, $code, $type = '') { + global $conf; + if ($type == 'supplier') { - $typethirdparty = 'code_compta_fournisseur'; + if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $typethirdparty = 'accountancy_code_supplier'; + } else { + $typethirdparty = 'code_compta_fournisseur'; + } } elseif ($type == 'customer') { - $typethirdparty = 'code_compta'; + if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $typethirdparty = 'accountancy_code_customer'; + } else { + $typethirdparty = 'code_compta'; + } } else { $this->error = 'Bad value for parameter type'; return -1; } - $sql = "SELECT ".$typethirdparty." FROM ".MAIN_DB_PREFIX."societe"; - $sql .= " WHERE ".$typethirdparty." = '".$db->escape($code)."'"; + if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql = "SELECT " . $typethirdparty . " FROM " . MAIN_DB_PREFIX . "societe_perentity"; + $sql .= " WHERE " . $typethirdparty . " = '" . $db->escape($code) . "'"; + } else { + $sql = "SELECT " . $typethirdparty . " FROM " . MAIN_DB_PREFIX . "societe"; + $sql .= " WHERE " . $typethirdparty . " = '" . $db->escape($code) . "'"; + } $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql index 9a530147d9e..56ac0290292 100644 --- a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql +++ b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql @@ -373,4 +373,4 @@ ALTER TABLE llx_hrm_skillrank ADD CONSTRAINT llx_hrm_skillrank_fk_user_creat FOR -- Manage accountancy auxiliary account for thirdparties per entity ALTER TABLE llx_societe_perentity ADD COLUMN accountancy_code_customer varchar(24) AFTER entity; -- equivalent to code_compta in llx_societe -ALTER TABLE llx_societe_perentity ADD COLUMN accountancy_code_supplier varchar(24) AFTER accountancy_code_supplier; -- equivalent to code_compta_supplier in llx_societe +ALTER TABLE llx_societe_perentity ADD COLUMN accountancy_code_supplier varchar(24) AFTER accountancy_code_customer; -- equivalent to code_compta_supplier in llx_societe diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 334793985f0..6399add1af3 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -75,6 +75,9 @@ if (!empty($conf->incoterm->enabled)) { if (!empty($conf->notification->enabled)) { $langs->load("mails"); } +if (!empty($conf->accounting->enabled)) { + $langs->load("products"); +} $error = 0; $errors = array(); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index d83dd1f3d34..a7db5c1b4bb 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -8,7 +8,7 @@ * Copyright (C) 2008 Patrick Raguin * Copyright (C) 2010-2018 Juanjo Menent * Copyright (C) 2013 Florian Henry - * Copyright (C) 2013 Alexandre Spangaro + * Copyright (C) 2013-2021 Alexandre Spangaro * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2014-2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud @@ -838,6 +838,8 @@ class Societe extends CommonObject } $this->import_key = trim($this->import_key); + $this->accountancy_code_customer = trim($this->accountancy_code_customer); + $this->accountancy_code_supplier = trim($this->accountancy_code_supplier); $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell= trim($this->accountancy_code_sell); @@ -922,11 +924,15 @@ class Societe extends CommonObject $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_perentity ("; $sql .= " fk_soc"; $sql .= ", entity"; + $sql .= ", accountancy_code_customer"; + $sql .= ", accountancy_code_supplier"; $sql .= ", accountancy_code_buy"; $sql .= ", accountancy_code_sell"; $sql .= ") VALUES ("; $sql .= $this->id; $sql .= ", " . $conf->entity; + $sql .= ", '" . $this->db->escape($this->accountancy_code_customer) . "'"; + $sql .= ", '" . $this->db->escape($this->accountancy_code_supplier) . "'"; $sql .= ", '" . $this->db->escape($this->accountancy_code_buy) . "'"; $sql .= ", '" . $this->db->escape($this->accountancy_code_sell) . "'"; $sql .= ")"; @@ -1553,16 +1559,9 @@ class Societe extends CommonObject $sql .= ") VALUES ("; $sql .= $this->id; $sql .= ", " . $conf->entity; + $sql .= ", '" . $this->db->escape($this->code_compta_client)."'"; + $sql .= ", '" . $this->db->escape($this->code_compta_fournisseur)."'"; $sql .= ", '" . $this->db->escape($this->accountancy_code_buy) . "'"; - - if ($customer) { - $sql .= ", accountancy_code_customer = ".(!empty($this->code_compta_client) ? "'".$this->db->escape($this->code_compta_client)."'" : "null"); - } - - if ($supplier) { - $sql .= ", accountancy_code_supplier = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); - } - $sql .= ", '" . $this->db->escape($this->accountancy_code_sell) . "'"; $sql .= ")"; $result = $this->db->query($sql); @@ -3353,7 +3352,7 @@ class Societe extends CommonObject } /** - * Define parent commany of current company + * Define parent company of current company * * @param int $id Id of thirdparty to set or '' to remove * @return int <0 if KO, >0 if OK From 00eafcb6e709c139ef9c2185595baa427ab6df27 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 8 Oct 2021 06:50:22 +0200 Subject: [PATCH 5/5] NEW Societe - Add perentity functionality on customer/supplier accountancy auxiliary account --- htdocs/societe/card.php | 40 +++++++++++++------------- htdocs/societe/class/societe.class.php | 27 +++++++++++++++-- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 6399add1af3..11cc7b55a4d 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -6,7 +6,7 @@ * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2008 Patrick Raguin * Copyright (C) 2010-2020 Juanjo Menent - * Copyright (C) 2011-2013 Alexandre Spangaro + * Copyright (C) 2011-2021 Alexandre Spangaro * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud @@ -446,19 +446,19 @@ if (empty($reshook)) { $object->name = dolGetFirstLastname(GETPOST('firstname', 'alphanohtml'), GETPOST('name', 'alphanohtml')); $object->civility_id = GETPOST('civility_id', 'alphanohtml'); // Note: civility id is a code, not an int // Add non official properties - $object->name_bis = GETPOST('name', 'alphanohtml'); - $object->firstname = GETPOST('firstname', 'alphanohtml'); + $object->name_bis = GETPOST('name', 'alphanohtml'); + $object->firstname = GETPOST('firstname', 'alphanohtml'); } else { - $object->name = GETPOST('name', 'alphanohtml'); + $object->name = GETPOST('name', 'alphanohtml'); } $object->entity = (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : $conf->entity); - $object->name_alias = GETPOST('name_alias', 'alphanohtml'); + $object->name_alias = GETPOST('name_alias', 'alphanohtml'); $object->address = GETPOST('address', 'alphanohtml'); - $object->zip = GETPOST('zipcode', 'alphanohtml'); - $object->town = GETPOST('town', 'alphanohtml'); - $object->country_id = GETPOST('country_id', 'int'); - $object->state_id = GETPOST('state_id', 'int'); - //$object->skype = GETPOST('skype', 'alpha'); + $object->zip = GETPOST('zipcode', 'alphanohtml'); + $object->town = GETPOST('town', 'alphanohtml'); + $object->country_id = GETPOST('country_id', 'int'); + $object->state_id = GETPOST('state_id', 'int'); + //$object->skype = GETPOST('skype', 'alpha'); //$object->twitter = GETPOST('twitter', 'alpha'); //$object->facebook = GETPOST('facebook', 'alpha'); //$object->linkedin = GETPOST('linkedin', 'alpha'); @@ -470,9 +470,9 @@ if (empty($reshook)) { } } } - $object->phone = GETPOST('phone', 'alpha'); + $object->phone = GETPOST('phone', 'alpha'); $object->fax = GETPOST('fax', 'alpha'); - $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)); + $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)); $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL)); $object->idprof1 = trim(GETPOST('idprof1', 'alphanohtml')); $object->idprof2 = trim(GETPOST('idprof2', 'alphanohtml')); @@ -482,7 +482,7 @@ if (empty($reshook)) { $object->idprof6 = trim(GETPOST('idprof6', 'alphanohtml')); $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml'); $object->code_client = GETPOSTISSET('customer_code') ?GETPOST('customer_code', 'alpha') : GETPOST('code_client', 'alpha'); - $object->code_fournisseur = GETPOSTISSET('supplier_code') ?GETPOST('supplier_code', 'alpha') : GETPOST('code_fournisseur', 'alpha'); + $object->code_fournisseur = GETPOSTISSET('supplier_code') ?GETPOST('supplier_code', 'alpha') : GETPOST('code_fournisseur', 'alpha'); $object->capital = GETPOST('capital', 'alphanohtml'); $object->barcode = GETPOST('barcode', 'alphanohtml'); @@ -497,24 +497,24 @@ if (empty($reshook)) { $object->localtax1_value = GETPOST('lt1', 'alpha'); $object->localtax2_value = GETPOST('lt2', 'alpha'); - $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int'); + $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int'); $object->effectif_id = GETPOST('effectif_id', 'int'); - $object->typent_id = GETPOST('typent_id', 'int'); + $object->typent_id = GETPOST('typent_id', 'int'); $object->typent_code = dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type - $object->client = GETPOST('client', 'int'); + $object->client = GETPOST('client', 'int'); $object->fournisseur = GETPOST('fournisseur', 'int'); - $object->commercial_id = GETPOST('commercial_id', 'int'); - $object->default_lang = GETPOST('default_lang'); + $object->commercial_id = GETPOST('commercial_id', 'int'); + $object->default_lang = GETPOST('default_lang'); // Webservices url/key $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); $object->webservices_key = GETPOST('webservices_key', 'san_alpha'); if (GETPOSTISSET('accountancy_code_sell')) { - $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha'); + $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha'); if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') { $object->accountancy_code_sell = ''; @@ -523,7 +523,7 @@ if (empty($reshook)) { } } if (GETPOSTISSET('accountancy_code_buy')) { - $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha'); + $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha'); if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') { $object->accountancy_code_buy = ''; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index a7db5c1b4bb..a1c1dae1ffb 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -563,11 +563,23 @@ class Societe extends CommonObject public $code_compta_client; /** - * Accounting code for suppliers + * Accounting code for customer + * @var string + */ + public $accountancy_code_customer; + + /** + * Accounting code for supplier * @var string */ public $code_compta_fournisseur; + /** + * Accounting code for supplier + * @var string + */ + public $accountancy_code_supplier; + /** * @var string * @deprecated Note is split in public and private notes @@ -838,8 +850,8 @@ class Societe extends CommonObject } $this->import_key = trim($this->import_key); - $this->accountancy_code_customer = trim($this->accountancy_code_customer); - $this->accountancy_code_supplier = trim($this->accountancy_code_supplier); + $this->accountancy_code_customer = trim($this->code_compta); + $this->accountancy_code_supplier = trim($this->code_compta_fournisseur); $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell= trim($this->accountancy_code_sell); @@ -2027,6 +2039,15 @@ class Societe extends CommonObject // Remove third party if (!$error) { + if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_perentity"; + $sql .= " WHERE fk_soc = ".((int) $id); + if (!$this->db->query($sql)) { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe"; $sql .= " WHERE rowid = ".((int) $id); if (!$this->db->query($sql)) {