diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index d36b563f671..e796ad51467 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -50,462 +50,1982 @@ $socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'societe', $socid);
-// For canvas usage
-if (empty($_GET["canvas"]))
+
+
+if (! GETPOST("canvas"))
{
- $_GET["canvas"] = 'default';
- if ($_REQUEST["private"]==1) $_GET["canvas"] = 'individual';
-
- // Get object canvas
- $socstatic = new Societe($db);
- if (!empty($socid)) $socstatic->getCanvas($socid);
-}
+ // -----------------------------------------
+ // When used in standard mode
+ // -----------------------------------------
-// Initialization Company Canvas
-$canvas = (!empty($socstatic->canvas)?$socstatic->canvas:$_GET["canvas"]);
-$soc = new Canvas($db);
-$soc->load_canvas('thirdparty@societe',$canvas);
+ // Initialization Company Object
+ $soc = new Societe($db);
-/*
- * Actions
- */
-if ($_POST["getcustomercode"])
-{
- // We defined value code_client
- $_POST["code_client"]="Acompleter";
-}
+ /*
+ * Actions
+ */
-if ($_POST["getsuppliercode"])
-{
- // We defined value code_fournisseur
- $_POST["code_fournisseur"]="Acompleter";
-}
-
-// Add new third party
-if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
-&& ($_POST["action"] == 'add' || $_POST["action"] == 'update') && $user->rights->societe->creer)
-{
- require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
- $error=0;
-
- if ($_POST["action"] == 'update')
+ if ($_POST["getcustomercode"])
{
- // Load properties of company
- $soc->fetch($socid);
+ // We defined value code_client
+ $_POST["code_client"]="Acompleter";
}
- if ($_REQUEST["private"] == 1)
+ if ($_POST["getsuppliercode"])
{
- $soc->object->particulier = $_REQUEST["private"];
-
- $soc->object->nom = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
- $soc->object->nom_particulier = $_POST["nom"];
- $soc->object->prenom = $_POST["prenom"];
- $soc->object->civilite_id = $_POST["civilite_id"];
+ // We defined value code_fournisseur
+ $_POST["code_fournisseur"]="Acompleter";
}
- else
+
+ // Add new third party
+ if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
+ && ($_POST["action"] == 'add' || $_POST["action"] == 'update') && $user->rights->societe->creer)
{
- $soc->object->nom = $_POST["nom"];
- }
- $soc->object->address = $_POST["adresse"];
- $soc->object->adresse = $_POST["adresse"]; // TODO obsolete
- $soc->object->cp = $_POST["cp"];
- $soc->object->ville = $_POST["ville"];
- $soc->object->pays_id = $_POST["pays_id"];
- $soc->object->departement_id = $_POST["departement_id"];
- $soc->object->tel = $_POST["tel"];
- $soc->object->fax = $_POST["fax"];
- $soc->object->email = trim($_POST["email"]);
- $soc->object->url = $_POST["url"];
- $soc->object->siren = $_POST["idprof1"];
- $soc->object->siret = $_POST["idprof2"];
- $soc->object->ape = $_POST["idprof3"];
- $soc->object->idprof4 = $_POST["idprof4"];
- $soc->object->prefix_comm = $_POST["prefix_comm"];
- $soc->object->code_client = $_POST["code_client"];
- $soc->object->code_fournisseur = $_POST["code_fournisseur"];
- $soc->object->capital = $_POST["capital"];
- $soc->object->gencod = $_POST["gencod"];
- $soc->object->canvas = $_GET["canvas"];
+ require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
+ $error=0;
- $soc->object->tva_assuj = $_POST["assujtva_value"];
-
- // Local Taxes
- $soc->object->localtax1_assuj = $_POST["localtax1assuj_value"];
- $soc->object->localtax2_assuj = $_POST["localtax2assuj_value"];
-
- $soc->object->tva_intra = $_POST["tva_intra"];
-
- $soc->object->forme_juridique_code = $_POST["forme_juridique_code"];
- $soc->object->effectif_id = $_POST["effectif_id"];
- if ($_REQUEST["private"] == 1)
- {
- $soc->object->typent_id = 8; // TODO predict another method if the field "special" change of rowid
- }
- else
- {
- $soc->object->typent_id = $_POST["typent_id"];
- }
- $soc->object->client = $_POST["client"];
- $soc->object->fournisseur = $_POST["fournisseur"];
- $soc->object->fournisseur_categorie = $_POST["fournisseur_categorie"];
-
- $soc->object->commercial_id = $_POST["commercial_id"];
- $soc->object->default_lang = $_POST["default_lang"];
-
- // Check parameters
- if (empty($_POST["cancel"]))
- {
- if (! empty($soc->object->email) && ! isValidEMail($soc->object->email))
+ if ($_POST["action"] == 'update')
{
- $error = 1;
- $langs->load("errors");
- $soc->object->error = $langs->trans("ErrorBadEMail",$soc->object->email);
- $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
+ // Load properties of company
+ $soc->fetch($socid);
}
- if (! empty($soc->object->url) && ! isValidUrl($soc->object->url))
+
+ if ($_REQUEST["private"] == 1)
{
- $error = 1;
- $langs->load("errors");
- $soc->object->error = $langs->trans("ErrorBadUrl",$soc->object->url);
- $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
+ $soc->particulier = $_REQUEST["private"];
+
+ $soc->nom = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
+ $soc->nom_particulier = $_POST["nom"];
+ $soc->prenom = $_POST["prenom"];
+ $soc->civilite_id = $_POST["civilite_id"];
}
- if ($soc->object->fournisseur && ! $conf->fournisseur->enabled)
+ else
{
- $error = 1;
- $langs->load("errors");
- $soc->object->error = $langs->trans("ErrorSupplierModuleNotEnabled");
- $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
+ $soc->nom = $_POST["nom"];
}
- }
+ $soc->address = $_POST["adresse"];
+ $soc->adresse = $_POST["adresse"]; // TODO obsolete
+ $soc->cp = $_POST["cp"];
+ $soc->ville = $_POST["ville"];
+ $soc->pays_id = $_POST["pays_id"];
+ $soc->departement_id = $_POST["departement_id"];
+ $soc->tel = $_POST["tel"];
+ $soc->fax = $_POST["fax"];
+ $soc->email = trim($_POST["email"]);
+ $soc->url = $_POST["url"];
+ $soc->siren = $_POST["idprof1"];
+ $soc->siret = $_POST["idprof2"];
+ $soc->ape = $_POST["idprof3"];
+ $soc->idprof4 = $_POST["idprof4"];
+ $soc->prefix_comm = $_POST["prefix_comm"];
+ $soc->code_client = $_POST["code_client"];
+ $soc->code_fournisseur = $_POST["code_fournisseur"];
+ $soc->capital = $_POST["capital"];
+ $soc->gencod = $_POST["gencod"];
- if (! $error)
- {
- if ($_POST["action"] == 'add')
+ $soc->tva_assuj = $_POST["assujtva_value"];
+
+ // Local Taxes
+ $soc->localtax1_assuj = $_POST["localtax1assuj_value"];
+ $soc->localtax2_assuj = $_POST["localtax2assuj_value"];
+
+ $soc->tva_intra = $_POST["tva_intra"];
+
+ $soc->forme_juridique_code = $_POST["forme_juridique_code"];
+ $soc->effectif_id = $_POST["effectif_id"];
+ if ($_REQUEST["private"] == 1)
{
- $db->begin();
+ $soc->typent_id = 8; // TODO predict another method if the field "special" change of rowid
+ }
+ else
+ {
+ $soc->typent_id = $_POST["typent_id"];
+ }
+ $soc->client = $_POST["client"];
+ $soc->fournisseur = $_POST["fournisseur"];
+ $soc->fournisseur_categorie = $_POST["fournisseur_categorie"];
- if (empty($soc->object->client)) $soc->object->code_client='';
- if (empty($soc->object->fournisseur)) $soc->object->code_fournisseur='';
+ $soc->commercial_id = $_POST["commercial_id"];
+ $soc->default_lang = $_POST["default_lang"];
- $result = $soc->object->create($user);
- if ($result >= 0)
+ // Check parameters
+ if (empty($_POST["cancel"]))
+ {
+ if (! empty($soc->email) && ! isValidEMail($soc->email))
{
- if ($soc->object->particulier)
- {
- dol_syslog("This thirdparty is a personal people",LOG_DEBUG);
- $contact=new Contact($db);
-
- $contact->civilite_id = $soc->object->civilite_id;
- $contact->name=$soc->object->nom_particulier;
- $contact->firstname=$soc->object->prenom;
- $contact->address=$soc->object->address;
- $contact->cp=$soc->object->cp;
- $contact->ville=$soc->object->ville;
- $contact->fk_pays=$soc->object->fk_pays;
- $contact->socid=$soc->object->id; // fk_soc
- $contact->status=1;
- $contact->email=$soc->object->email;
- $contact->priv=0;
-
- $result=$contact->create($user);
- }
+ $error = 1;
+ $langs->load("errors");
+ $soc->error = $langs->trans("ErrorBadEMail",$soc->email);
+ $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
}
- else
+ if (! empty($soc->url) && ! isValidUrl($soc->url))
{
- $mesg=$soc->object->error;
+ $error = 1;
+ $langs->load("errors");
+ $soc->error = $langs->trans("ErrorBadUrl",$soc->url);
+ $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
}
-
- if ($result >= 0)
+ if ($soc->fournisseur && ! $conf->fournisseur->enabled)
{
- $db->commit();
+ $error = 1;
+ $langs->load("errors");
+ $soc->error = $langs->trans("ErrorSupplierModuleNotEnabled");
+ $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
+ }
+ }
- if ( $soc->object->client == 1 )
+ if (! $error)
+ {
+ if ($_POST["action"] == 'add')
+ {
+ $db->begin();
+
+ if (empty($soc->client)) $soc->code_client='';
+ if (empty($soc->fournisseur)) $soc->code_fournisseur='';
+
+ $result = $soc->create($user);
+ if ($result >= 0)
{
- Header("Location: ".DOL_URL_ROOT."/comm/fiche.php?socid=".$soc->object->id);
- return;
+ if ($soc->particulier)
+ {
+ dol_syslog("This thirdparty is a personal people",LOG_DEBUG);
+ $contact=new Contact($db);
+
+ $contact->civilite_id = $soc->civilite_id;
+ $contact->name=$soc->nom_particulier;
+ $contact->firstname=$soc->prenom;
+ $contact->address=$soc->address;
+ $contact->cp=$soc->cp;
+ $contact->ville=$soc->ville;
+ $contact->fk_pays=$soc->fk_pays;
+ $contact->socid=$soc->id; // fk_soc
+ $contact->status=1;
+ $contact->email=$soc->email;
+ $contact->priv=0;
+
+ $result=$contact->create($user);
+ }
}
else
{
- if ( $soc->object->fournisseur == 1 )
+ $mesg=$soc->error;
+ }
+
+ if ($result >= 0)
+ {
+ $db->commit();
+
+ if ( $soc->client == 1 )
{
- Header("Location: ".DOL_URL_ROOT."/fourn/fiche.php?socid=".$soc->object->id);
+ Header("Location: ".DOL_URL_ROOT."/comm/fiche.php?socid=".$soc->id);
return;
}
else
{
- Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$soc->object->id);
- return;
+ if ( $soc->fournisseur == 1 )
+ {
+ Header("Location: ".DOL_URL_ROOT."/fourn/fiche.php?socid=".$soc->id);
+ return;
+ }
+ else
+ {
+ Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$soc->id);
+ return;
+ }
}
+ exit;
}
- exit;
- }
- else
- {
- $db->rollback();
+ else
+ {
+ $db->rollback();
- $langs->load("errors");
- $mesg=$langs->trans($soc->object->error);
- $_GET["action"]='create';
- }
- }
-
- if ($_POST["action"] == 'update')
- {
- if ($_POST["cancel"])
- {
- Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
- exit;
+ $langs->load("errors");
+ $mesg=$langs->trans($soc->error);
+ $_GET["action"]='create';
+ }
}
- $oldsoc = new Canvas($db);
- $oldsoc->load_canvas('thirdparty@societe',$canvas);
- $result=$oldsoc->fetch($socid);
-
- // To not set code if third party is not concerned. But if it had values, we keep them.
- if (empty($soc->object->client) && empty($oldsoc->code_client)) $soc->object->code_client='';
- if (empty($soc->object->fournisseur)&& empty($oldsoc->code_fournisseur)) $soc->object->code_fournisseur='';
- //var_dump($soc);exit;
-
- $result = $soc->object->update($socid,$user,1,$oldsoc->object->codeclient_modifiable(),$oldsoc->object->codefournisseur_modifiable());
- if ($result >= 0)
+ if ($_POST["action"] == 'update')
{
- Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
- exit;
- }
- else
- {
- $soc->object->id = $socid;
- $reload = 0;
+ if ($_POST["cancel"])
+ {
+ Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
+ exit;
+ }
- $mesg = $soc->object->error;
- $_GET["action"]= "edit";
+ $oldsoc=new Societe($db);
+ $result=$oldsoc->fetch($socid);
+
+ // To not set code if third party is not concerned. But if it had values, we keep them.
+ if (empty($soc->client) && empty($oldsoc->code_client)) $soc->code_client='';
+ if (empty($soc->fournisseur)&& empty($oldsoc->code_fournisseur)) $soc->code_fournisseur='';
+ //var_dump($soc);exit;
+
+ $result = $soc->update($socid,$user,1,$oldsoc->codeclient_modifiable(),$oldsoc->codefournisseur_modifiable());
+ if ($result >= 0)
+ {
+ Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
+ exit;
+ }
+ else
+ {
+ $soc->id = $socid;
+ $reload = 0;
+
+ $mesg = $soc->error;
+ $_GET["action"]= "edit";
+ }
}
}
}
-}
-if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->societe->supprimer)
-{
- $soc = new Societe($db);
- $soc->fetch($socid);
- $result = $soc->delete($socid);
-
- if ($result >= 0)
+ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->societe->supprimer)
{
- Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$soc->nom."");
- exit;
- }
- else
- {
- $reload = 0;
- $langs->load("errors");
- $mesg=$langs->trans($soc->error);
- $_GET["action"]='';
- }
-}
-
-
-/*
- * Generate document
- */
-if ($_REQUEST['action'] == 'builddoc') // En get ou en post
-{
- if (is_numeric($_REQUEST['model']))
- {
- $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
- }
- else
- {
- require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php');
-
$soc = new Societe($db);
$soc->fetch($socid);
- $soc->fetch_thirdparty();
+ $result = $soc->delete($socid);
- /*if ($_REQUEST['model'])
- {
- $fac->setDocModel($user, $_REQUEST['model']);
- }
+ if ($result >= 0)
+ {
+ Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$soc->nom."");
+ exit;
+ }
+ else
+ {
+ $reload = 0;
+ $langs->load("errors");
+ $mesg=$langs->trans($soc->error);
+ $_GET["action"]='';
+ }
+ }
+
+
+ /*
+ * Generate document
+ */
+ if ($_REQUEST['action'] == 'builddoc') // En get ou en post
+ {
+ if (is_numeric($_REQUEST['model']))
+ {
+ $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
+ }
+ else
+ {
+ require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php');
+
+ $soc = new Societe($db);
+ $soc->fetch($socid);
+ $soc->fetch_thirdparty();
+
+ // Define output language
+ $outputlangs = $langs;
+ $newlang='';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$fac->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $result=thirdparty_doc_create($db, $soc->id, '', $_REQUEST['model'], $outputlangs);
+ if ($result <= 0)
+ {
+ dol_print_error($db,$result);
+ exit;
+ }
+ else
+ {
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?socid='.$soc->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
+ exit;
+ }
+ }
+ }
+
+
+ /*
+ * View
+ */
+
+ $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
+ llxHeader('','',$help_url);
+
+ $form = new Form($db);
+ $formfile = new FormFile($db);
+ $formadmin = new FormAdmin($db);
+ $formcompany = new FormCompany($db);
+
+ $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
+
+
+ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] ||
+ $_GET["action"] == 'create' || $_POST["action"] == 'create')
+ {
+ /*
+ * Sheet mode creation
*/
+ if ($user->rights->societe->creer)
+ {
+ // Load object modCodeTiers
+ $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
+ if (! $module) dolibarr_error('',$langs->trans("ErrorModuleThirdPartyCodeInCompanyModuleNotDefined"));
+ if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
+ {
+ $module = substr($module, 0, dol_strlen($module)-4);
+ }
+ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$module.".php");
+ $modCodeClient = new $module;
+ $module=$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON;
+ if (! $module) $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
+ if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
+ {
+ $module = substr($module, 0, dol_strlen($module)-4);
+ }
+ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$module.".php");
+ $modCodeFournisseur = new $module;
+
+ /*
+ * Company Fact creation mode
+ */
+ if ($_GET["type"]=='f') { $soc->fournisseur=1; }
+ if ($_GET["type"]=='c') { $soc->client=1; }
+ if ($_GET["type"]=='p') { $soc->client=2; }
+ if ($_GET["type"]=='cp') { $soc->client=3; }
+ if ($_REQUEST["private"]==1) { $soc->particulier=1; }
+
+ $soc->nom=$_POST["nom"];
+ $soc->prenom=$_POST["prenom"];
+ $soc->particulier=$_REQUEST["private"];
+ $soc->prefix_comm=$_POST["prefix_comm"];
+ $soc->client=$_POST["client"]?$_POST["client"]:$soc->client;
+ $soc->code_client=$_POST["code_client"];
+ $soc->fournisseur=$_POST["fournisseur"]?$_POST["fournisseur"]:$soc->fournisseur;
+ $soc->code_fournisseur=$_POST["code_fournisseur"];
+ $soc->adresse=$_POST["adresse"];
+ $soc->address=$_POST["adresse"]; // TODO obsolete
+ $soc->cp=$_POST["cp"];
+ $soc->ville=$_POST["ville"];
+ $soc->departement_id=$_POST["departement_id"];
+ $soc->tel=$_POST["tel"];
+ $soc->fax=$_POST["fax"];
+ $soc->email=$_POST["email"];
+ $soc->url=$_POST["url"];
+ $soc->capital=$_POST["capital"];
+ $soc->gencod=$_POST["gencod"];
+ $soc->siren=$_POST["idprof1"];
+ $soc->siret=$_POST["idprof2"];
+ $soc->ape=$_POST["idprof3"];
+ $soc->idprof4=$_POST["idprof4"];
+ $soc->typent_id=($_POST["typent_id"]&&!$_POST["cleartype"])?$_POST["typent_id"]:($_REQUEST["private"]?'TE_PRIVATE':'');
+ $soc->effectif_id=($_POST["effectif_id"]&&!$_POST["cleartype"])?$_POST["effectif_id_id"]:($_REQUEST["private"]?'EF1-5':'');
+
+ $soc->tva_assuj = $_POST["assujtva_value"];
+
+ //Local Taxes
+ $soc->localtax1_assuj = $_POST["localtax1assuj_value"];
+ $soc->localtax2_assuj = $_POST["localtax2assuj_value"];
+
+ $soc->tva_intra=$_POST["tva_intra"];
+
+ $soc->commercial_id=$_POST["commercial_id"];
+ $soc->default_lang=$_POST["default_lang"];
+
+ // We set pays_id, pays_code and label for the selected country
+ $soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
+ if ($soc->pays_id)
+ {
+ $sql = "SELECT code, libelle";
+ $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
+ $sql.= " WHERE rowid = ".$soc->pays_id;
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $obj = $db->fetch_object($resql);
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+ $soc->pays_code=$obj->code;
+ $soc->pays=$obj->libelle;
+ }
+
+ print_fiche_titre($langs->trans("NewCompany"));
+
+ if ($conf->use_javascript_ajax)
+ {
+ print "\n".''."\n";
+
+ print "
\n";
+ print $langs->trans("ThirdPartyType").': ';
+ print ' '.$langs->trans("Company/Fundation");
+ print ' ';
+ print ' '.$langs->trans("Individual");
+ print ' ('.$langs->trans("ToCreateContactWithSameName").')';
+ print "
\n";
+ print "
\n";
+ }
+
+ dol_htmloutput_errors($soc->error,$soc->errors);
+
+ print '