Fix: wrong entity with thirdparty sharing

This commit is contained in:
Regis Houssin 2018-01-10 13:30:57 +01:00
parent 4683a35532
commit 8c3b4f62db
2 changed files with 66 additions and 65 deletions

View File

@ -3,7 +3,7 @@
* Copyright (C) 2003 Brian Fraval <brian@fraval.org> * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net> * Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
* Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011-2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2011-2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
@ -56,9 +56,9 @@ if (! empty($conf->notification->enabled)) $langs->load("mails");
$mesg=''; $error=0; $errors=array(); $mesg=''; $error=0; $errors=array();
$action = (GETPOST('action','aZ09') ? GETPOST('action','aZ09') : 'view'); $action = (GETPOST('action','aZ09') ? GETPOST('action','aZ09') : 'view');
$cancel = GETPOST('cancel','alpha'); $cancel = GETPOST('cancel','alpha');
$backtopage = GETPOST('backtopage','alpha'); $backtopage = GETPOST('backtopage','alpha');
$confirm = GETPOST('confirm'); $confirm = GETPOST('confirm');
$socid = GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int'); $socid = GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
@ -351,82 +351,83 @@ if (empty($reshook))
if (! $error) if (! $error)
{ {
if ($action == 'update') if ($action == 'update')
{ {
$ret=$object->fetch($socid); $ret=$object->fetch($socid);
$object->oldcopy = clone $object; $object->oldcopy = clone $object;
} }
else $object->canvas=$canvas; else $object->canvas=$canvas;
if (GETPOST("private") == 1) // Ask to create a contact if (GETPOST("private") == 1) // Ask to create a contact
{ {
$object->particulier = GETPOST("private"); $object->particulier = GETPOST("private");
$object->name = dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha')); $object->name = dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
$object->civility_id = GETPOST('civility_id'); // Note: civility id is a code, not an int $object->civility_id = GETPOST('civility_id'); // Note: civility id is a code, not an int
// Add non official properties // Add non official properties
$object->name_bis = GETPOST('name','alpha'); $object->name_bis = GETPOST('name','alpha');
$object->firstname = GETPOST('firstname','alpha'); $object->firstname = GETPOST('firstname','alpha');
} }
else else
{ {
$object->name = GETPOST('name', 'alpha'); $object->name = GETPOST('name', 'alpha');
} }
$object->name_alias = GETPOST('name_alias'); $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
$object->address = GETPOST('address'); $object->name_alias = GETPOST('name_alias');
$object->zip = GETPOST('zipcode', 'alpha'); $object->address = GETPOST('address');
$object->town = GETPOST('town', 'alpha'); $object->zip = GETPOST('zipcode', 'alpha');
$object->country_id = GETPOST('country_id', 'int'); $object->town = GETPOST('town', 'alpha');
$object->state_id = GETPOST('state_id', 'int'); $object->country_id = GETPOST('country_id', 'int');
$object->skype = GETPOST('skype', 'alpha'); $object->state_id = GETPOST('state_id', 'int');
$object->phone = GETPOST('phone', 'alpha'); $object->skype = GETPOST('skype', 'alpha');
$object->fax = GETPOST('fax','alpha'); $object->phone = GETPOST('phone', 'alpha');
$object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)); $object->fax = GETPOST('fax','alpha');
$object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL)); $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
$object->idprof1 = trim(GETPOST('idprof1', 'alpha')); $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
$object->idprof2 = trim(GETPOST('idprof2', 'alpha')); $object->idprof1 = trim(GETPOST('idprof1', 'alpha'));
$object->idprof3 = trim(GETPOST('idprof3', 'alpha')); $object->idprof2 = trim(GETPOST('idprof2', 'alpha'));
$object->idprof4 = trim(GETPOST('idprof4', 'alpha')); $object->idprof3 = trim(GETPOST('idprof3', 'alpha'));
$object->idprof5 = trim(GETPOST('idprof5', 'alpha')); $object->idprof4 = trim(GETPOST('idprof4', 'alpha'));
$object->idprof6 = trim(GETPOST('idprof6', 'alpha')); $object->idprof5 = trim(GETPOST('idprof5', 'alpha'));
$object->prefix_comm = GETPOST('prefix_comm', 'alpha'); $object->idprof6 = trim(GETPOST('idprof6', 'alpha'));
$object->code_client = GETPOST('code_client', 'alpha'); $object->prefix_comm = GETPOST('prefix_comm', 'alpha');
$object->code_fournisseur = GETPOST('code_fournisseur', 'alpha'); $object->code_client = GETPOST('code_client', 'alpha');
$object->capital = GETPOST('capital', 'alpha'); $object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
$object->barcode = GETPOST('barcode', 'alpha'); $object->capital = GETPOST('capital', 'alpha');
$object->barcode = GETPOST('barcode', 'alpha');
$object->tva_intra = GETPOST('tva_intra', 'alpha'); $object->tva_intra = GETPOST('tva_intra', 'alpha');
$object->tva_assuj = GETPOST('assujtva_value', 'alpha'); $object->tva_assuj = GETPOST('assujtva_value', 'alpha');
$object->status = GETPOST('status', 'alpha'); $object->status = GETPOST('status', 'alpha');
// Local Taxes // Local Taxes
$object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha'); $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha');
$object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha'); $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha');
$object->localtax1_value = GETPOST('lt1', 'alpha'); $object->localtax1_value = GETPOST('lt1', 'alpha');
$object->localtax2_value = GETPOST('lt2', '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->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->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->fournisseur = GETPOST('fournisseur', 'int');
$object->commercial_id = GETPOST('commercial_id', 'int'); $object->commercial_id = GETPOST('commercial_id', 'int');
$object->default_lang = GETPOST('default_lang'); $object->default_lang = GETPOST('default_lang');
// Webservices url/key // Webservices url/key
$object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
$object->webservices_key = GETPOST('webservices_key', 'san_alpha'); $object->webservices_key = GETPOST('webservices_key', 'san_alpha');
// Incoterms // Incoterms
if (!empty($conf->incoterm->enabled)) if (!empty($conf->incoterm->enabled))
{ {
$object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
} }
// Multicurrency // Multicurrency
@ -499,17 +500,17 @@ if (empty($reshook))
$result = $object->create($user); $result = $object->create($user);
if ($result >= 0) if ($result >= 0)
{ {
if ($object->particulier) if ($object->particulier)
{ {
dol_syslog("We ask to create a contact/address too", LOG_DEBUG); dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
$result=$object->create_individual($user); $result=$object->create_individual($user);
if ($result < 0) if ($result < 0)
{ {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$error++; $error++;
} }
} }
// Customer categories association // Customer categories association
$custcats = GETPOST('custcats', 'array'); $custcats = GETPOST('custcats', 'array');

View File

@ -472,7 +472,7 @@ class Societe extends CommonObject
if ($result >= 0) if ($result >= 0)
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
$sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$conf->entity.", '".$this->db->idate($now)."'"; $sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->entity.", '".$this->db->idate($now)."'";
$sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null"); $sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
$sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null"); $sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
$sql.= ", ".$this->status; $sql.= ", ".$this->status;