Merge pull request #8047 from hregis/develop_multicompany

Fix: some bugs with multicompany sharing
This commit is contained in:
Laurent Destailleur 2018-01-11 01:07:17 +01:00 committed by GitHub
commit 4316793638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 165 additions and 146 deletions

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
@ -50,8 +50,8 @@ $langs->load("commercial");
$mesg=''; $error=0; $errors=array();
$action = (GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view');
$confirm = GETPOST('confirm','alpha');
$backtopage = GETPOST('backtopage','alpha');
$confirm = GETPOST('confirm','alpha');
$backtopage = GETPOST('backtopage','alpha');
$id = GETPOST('id','int');
$socid = GETPOST('socid','int');
@ -137,63 +137,64 @@ if (empty($reshook))
}
// Confirmation desactivation
if ($action == 'disable')
{
$object->fetch($id);
if ($object->setstatus(0)<0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
// Confirmation desactivation
if ($action == 'disable')
{
$object->fetch($id);
if ($object->setstatus(0)<0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
// Confirmation activation
if ($action == 'enable')
{
$object->fetch($id);
if ($object->setstatus(1)<0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
// Confirmation activation
if ($action == 'enable')
{
$object->fetch($id);
if ($object->setstatus(1)<0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
// Add contact
if ($action == 'add' && $user->rights->societe->contact->creer)
{
$db->begin();
// Add contact
if ($action == 'add' && $user->rights->societe->contact->creer)
{
$db->begin();
if ($canvas) $object->canvas=$canvas;
$object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
$object->socid = GETPOST("socid",'int');
$object->lastname = GETPOST("lastname");
$object->firstname = GETPOST("firstname");
$object->civility_id = GETPOST("civility_id",'alpha');
$object->civility_id = GETPOST("civility_id",'alpha');
$object->poste = GETPOST("poste");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->country_id = GETPOST("country_id",'int');
$object->state_id = GETPOST("state_id",'int');
$object->state_id = GETPOST("state_id",'int');
$object->skype = GETPOST("skype");
$object->email = GETPOST("email",'alpha');
$object->phone_pro = GETPOST("phone_pro");
$object->phone_perso = GETPOST("phone_perso");
$object->phone_perso = GETPOST("phone_perso");
$object->phone_mobile = GETPOST("phone_mobile");
$object->fax = GETPOST("fax");
$object->fax = GETPOST("fax");
$object->jabberid = GETPOST("jabberid",'alpha');
$object->no_email = GETPOST("no_email",'int');
$object->priv = GETPOST("priv",'int');
$object->note_public = GETPOST("note_public");
$object->note_public = GETPOST("note_public");
$object->note_private = GETPOST("note_private");
$object->statut = 1; //Defult status to Actif
@ -278,15 +279,13 @@ if (empty($reshook))
$action = 'edit';
}
if (! $error)
{
$contactid=GETPOST("contactid",'int');
$object->fetch($contactid);
if (! $error)
{
$contactid=GETPOST("contactid",'int');
$object->fetch($contactid);
// Photo save
$dir = $conf->societe->dir_output."/contact/".$object->id."/photos";
// Photo save
$dir = $conf->societe->multidir_output[$object->entity]."/contact/".$object->id."/photos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if (GETPOST('deletephoto') && $object->photo)
{
@ -347,26 +346,26 @@ if (empty($reshook))
$object->socid = GETPOST("socid",'int');
$object->lastname = GETPOST("lastname");
$object->firstname = GETPOST("firstname");
$object->civility_id = GETPOST("civility_id",'alpha');
$object->civility_id = GETPOST("civility_id",'alpha');
$object->poste = GETPOST("poste");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->state_id = GETPOST("state_id",'int');
$object->state_id = GETPOST("state_id",'int');
$object->fk_departement = GETPOST("state_id",'int'); // For backward compatibility
$object->country_id = GETPOST("country_id",'int');
$object->email = GETPOST("email",'alpha');
$object->skype = GETPOST("skype",'alpha');
$object->phone_pro = GETPOST("phone_pro");
$object->phone_perso = GETPOST("phone_perso");
$object->phone_perso = GETPOST("phone_perso");
$object->phone_mobile = GETPOST("phone_mobile");
$object->fax = GETPOST("fax");
$object->fax = GETPOST("fax");
$object->jabberid = GETPOST("jabberid",'alpha');
$object->no_email = GETPOST("no_email",'int');
$object->priv = GETPOST("priv",'int');
$object->note_public = GETPOST("note_public");
$object->note_public = GETPOST("note_public");
$object->note_private = GETPOST("note_private");
// Fill array 'array_options' with data from add form
@ -531,12 +530,14 @@ else
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if (! empty($objsoc)) {
print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
}
dol_fiche_head($head, 'card', '', 0, '');
print '<table class="border" width="100%">';
// Name
print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
print '<td><input name="lastname" id="lastname" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("lastname")?GETPOST("lastname"):$object->lastname).'" autofocus="autofocus"></td>';
@ -673,7 +674,7 @@ else
}
// Other attributes
$parameters=array('colspan' => ' colspan="3"','cols'=>3);
$parameters=array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook) && ! empty($extrafields->attribute_label))

View File

@ -187,7 +187,7 @@ class Contact extends CommonObject
$sql.= ", statut";
$sql.= ", canvas";
$sql.= ", entity";
$sql.= ",ref_ext";
$sql.= ", ref_ext";
$sql.= ", import_key";
$sql.= ") VALUES (";
$sql.= "'".$this->db->idate($now)."',";
@ -199,7 +199,7 @@ class Contact extends CommonObject
$sql.= " ".$this->priv.",";
$sql.= " ".$this->statut.",";
$sql.= " ".(! empty($this->canvas)?"'".$this->db->escape($this->canvas)."'":"null").",";
$sql.= " ".$conf->entity.",";
$sql.= " ".$this->entity.",";
$sql.= "'".$this->db->escape($this->ref_ext)."',";
$sql.= " ".(! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
$sql.= ")";
@ -642,7 +642,7 @@ class Contact extends CommonObject
$langs->load("companies");
$sql = "SELECT c.rowid, c.fk_soc, c.ref_ext, c.civility as civility_id, c.lastname, c.firstname,";
$sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_id, c.lastname, c.firstname,";
$sql.= " c.address, c.statut, c.zip, c.town,";
$sql.= " c.fk_pays as country_id,";
$sql.= " c.fk_departement,";
@ -671,41 +671,42 @@ class Contact extends CommonObject
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->entity = $obj->entity;
$this->ref = $obj->rowid;
$this->ref_ext = $obj->ref_ext;
$this->civility_id = $obj->civility_id;
$this->civility_code = $obj->civility_id;
$this->civility_code = $obj->civility_id;
$this->lastname = $obj->lastname;
$this->firstname = $obj->firstname;
$this->firstname = $obj->firstname;
$this->address = $obj->address;
$this->zip = $obj->zip;
$this->town = $obj->town;
$this->fk_departement = $obj->fk_departement; // deprecated
$this->state_id = $obj->fk_departement;
$this->departement_code = $obj->state_code; // deprecated
$this->state_code = $obj->state_code;
$this->departement_code = $obj->state_code; // deprecated
$this->state_code = $obj->state_code;
$this->departement = $obj->state; // deprecated
$this->state = $obj->state;
$this->state = $obj->state;
$this->country_id = $obj->country_id;
$this->country_code = $obj->country_id?$obj->country_code:'';
$this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
$this->socid = $obj->fk_soc;
$this->socid = $obj->fk_soc;
$this->socname = $obj->socname;
$this->poste = $obj->poste;
$this->poste = $obj->poste;
$this->statut = $obj->statut;
$this->phone_pro = trim($obj->phone);
$this->phone_pro = trim($obj->phone);
$this->fax = trim($obj->fax);
$this->phone_perso = trim($obj->phone_perso);
$this->phone_mobile = trim($obj->phone_mobile);
$this->email = $obj->email;
$this->email = $obj->email;
$this->jabberid = $obj->jabberid;
$this->skype = $obj->skype;
$this->photo = $obj->photo;
$this->skype = $obj->skype;
$this->photo = $obj->photo;
$this->priv = $obj->priv;
$this->mail = $obj->email;

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
/* Copyright (C) 2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
* Copyright (C) 2017 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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
@ -67,7 +68,7 @@ if (! $sortfield) $sortfield="name";
if ($id > 0) $object->fetch($id);
$upload_dir = $conf->societe->dir_output.'/contact/'.dol_sanitizeFileName($object->ref);
$upload_dir = $conf->societe->multidir_output[$object->entity].'/contact/'.dol_sanitizeFileName($object->ref);
$modulepart='contact';

View File

@ -3,7 +3,7 @@
* Copyright (C) 2003 Brian Fraval <brian@fraval.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* 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) 2010-2016 Juanjo Menent <jmenent@2byte.es>
* 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();
$action = (GETPOST('action','aZ09') ? GETPOST('action','aZ09') : 'view');
$cancel = GETPOST('cancel','alpha');
$backtopage = GETPOST('backtopage','alpha');
$confirm = GETPOST('confirm');
$cancel = GETPOST('cancel','alpha');
$backtopage = GETPOST('backtopage','alpha');
$confirm = GETPOST('confirm');
$socid = GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
if ($user->societe_id) $socid=$user->societe_id;
@ -351,82 +351,83 @@ if (empty($reshook))
if (! $error)
{
if ($action == 'update')
if ($action == 'update')
{
$ret=$object->fetch($socid);
$ret=$object->fetch($socid);
$object->oldcopy = clone $object;
}
else $object->canvas=$canvas;
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->civility_id = GETPOST('civility_id'); // Note: civility id is a code, not an int
$object->name = dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
$object->civility_id = GETPOST('civility_id'); // Note: civility id is a code, not an int
// Add non official properties
$object->name_bis = GETPOST('name','alpha');
$object->firstname = GETPOST('firstname','alpha');
$object->name_bis = GETPOST('name','alpha');
$object->firstname = GETPOST('firstname','alpha');
}
else
{
$object->name = GETPOST('name', 'alpha');
$object->name = GETPOST('name', 'alpha');
}
$object->name_alias = GETPOST('name_alias');
$object->address = GETPOST('address');
$object->zip = GETPOST('zipcode', 'alpha');
$object->town = GETPOST('town', 'alpha');
$object->country_id = GETPOST('country_id', 'int');
$object->state_id = GETPOST('state_id', 'int');
$object->skype = GETPOST('skype', 'alpha');
$object->phone = GETPOST('phone', 'alpha');
$object->fax = GETPOST('fax','alpha');
$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', 'alpha'));
$object->idprof2 = trim(GETPOST('idprof2', 'alpha'));
$object->idprof3 = trim(GETPOST('idprof3', 'alpha'));
$object->idprof4 = trim(GETPOST('idprof4', 'alpha'));
$object->idprof5 = trim(GETPOST('idprof5', 'alpha'));
$object->idprof6 = trim(GETPOST('idprof6', 'alpha'));
$object->prefix_comm = GETPOST('prefix_comm', 'alpha');
$object->code_client = GETPOST('code_client', 'alpha');
$object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
$object->capital = GETPOST('capital', 'alpha');
$object->barcode = GETPOST('barcode', 'alpha');
$object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
$object->name_alias = GETPOST('name_alias');
$object->address = GETPOST('address');
$object->zip = GETPOST('zipcode', 'alpha');
$object->town = GETPOST('town', 'alpha');
$object->country_id = GETPOST('country_id', 'int');
$object->state_id = GETPOST('state_id', 'int');
$object->skype = GETPOST('skype', 'alpha');
$object->phone = GETPOST('phone', 'alpha');
$object->fax = GETPOST('fax','alpha');
$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', 'alpha'));
$object->idprof2 = trim(GETPOST('idprof2', 'alpha'));
$object->idprof3 = trim(GETPOST('idprof3', 'alpha'));
$object->idprof4 = trim(GETPOST('idprof4', 'alpha'));
$object->idprof5 = trim(GETPOST('idprof5', 'alpha'));
$object->idprof6 = trim(GETPOST('idprof6', 'alpha'));
$object->prefix_comm = GETPOST('prefix_comm', 'alpha');
$object->code_client = GETPOST('code_client', 'alpha');
$object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
$object->capital = GETPOST('capital', 'alpha');
$object->barcode = GETPOST('barcode', 'alpha');
$object->tva_intra = GETPOST('tva_intra', 'alpha');
$object->tva_assuj = GETPOST('assujtva_value', 'alpha');
$object->status = GETPOST('status', 'alpha');
$object->tva_intra = GETPOST('tva_intra', 'alpha');
$object->tva_assuj = GETPOST('assujtva_value', 'alpha');
$object->status = GETPOST('status', 'alpha');
// Local Taxes
$object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha');
$object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha');
$object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha');
$object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha');
$object->localtax1_value = GETPOST('lt1', 'alpha');
$object->localtax2_value = GETPOST('lt2', 'alpha');
$object->localtax1_value = GETPOST('lt1', 'alpha');
$object->localtax2_value = GETPOST('lt2', 'alpha');
$object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
$object->effectif_id = GETPOST('effectif_id', 'int');
$object->typent_id = GETPOST('typent_id','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_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->fournisseur = GETPOST('fournisseur', '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');
$object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
$object->webservices_key = GETPOST('webservices_key', 'san_alpha');
// Incoterms
if (!empty($conf->incoterm->enabled))
{
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
}
// Multicurrency
@ -499,17 +500,17 @@ if (empty($reshook))
$result = $object->create($user);
if ($result >= 0)
{
if ($object->particulier)
{
dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
$result=$object->create_individual($user);
if ($result < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
{
if ($object->particulier)
{
dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
$result=$object->create_individual($user);
if ($result < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
// Customer categories association
$custcats = GETPOST('custcats', 'array');
@ -2477,11 +2478,11 @@ else
print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
}
// Subsidiaries list
if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
{
$result=show_subsidiaries($conf,$langs,$db,$object);
}
// Subsidiaries list
if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
{
$result=show_subsidiaries($conf,$langs,$db,$object);
}
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
@ -2497,6 +2498,21 @@ else
$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
print '</div></div></div>';
if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
{
// Contacts list
if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
{
$result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
}
// Addresses list
if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
{
$result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
}
}
}
// Presend form

View File

@ -472,7 +472,7 @@ class Societe extends CommonObject
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.= " 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($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
$sql.= ", ".$this->status;