NEW Societe - Add perentity functionality on customer/supplier accountancy auxiliary account

This commit is contained in:
Alexandre SPANGARO 2021-10-08 06:29:22 +02:00
parent e68d9dc73c
commit c7fd9328cd
7 changed files with 43 additions and 24 deletions

View File

@ -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)) {

View File

@ -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();

View File

@ -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";

View File

@ -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) {

View File

@ -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

View File

@ -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();

View File

@ -8,7 +8,7 @@
* Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
* Copyright (C) 2010-2018 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
@ -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