diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php
index 38d8c333749..0783f330843 100644
--- a/htdocs/partnership/class/partnership.class.php
+++ b/htdocs/partnership/class/partnership.class.php
@@ -248,7 +248,70 @@ class Partnership extends CommonObject
}
$this->status = 0;
- return $this->createCommon($user, $notrigger);
+
+ global $conf, $langs;
+
+ $error = 0;
+
+ $now = dol_now();
+
+ // Clean parameters
+ $this->import_key = trim($this->import_key);
+
+ if (!$this->date_creation) {
+ $this->date_creation = $now;
+ }
+
+
+ $this->db->begin();
+
+ // Insert partnership
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."partnership";
+ $sql .= " (ref, date_creation,fk_user_creat,fk_user_modif,fk_type,entity,import_key)";
+ $sql .= " VALUES (";
+ $sql .= " '(PROV)'";
+ $sql .= ", '".$this->db->idate($this->datec)."'";
+ $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because partnership can be created by a guest or a script
+ $sql .= ", null ";
+ $sql .= ", ".((int) $this->fk_type);
+ $sql .= ", ".$conf->entity;
+ $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
+ $sql .= ")";
+
+ dol_syslog(get_class($this)."::create", LOG_DEBUG);
+ $result = $this->db->query($sql);
+ if ($result) {
+ $id = $this->db->last_insert_id(MAIN_DB_PREFIX."partnership");
+ if ($id > 0) {
+ $this->id = $id;
+ $this->ref = (string) $id;
+
+ // Update minor fields
+ $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
+ if ($result < 0) {
+ $this->db->rollback();
+ return -1;
+ }
+
+ if (count($this->errors)) {
+ dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
+ $this->db->rollback();
+ return -3;
+ } else {
+ $this->db->commit();
+ return $this->id;
+ }
+ } else {
+ $this->error = 'Failed to get last insert id';
+ dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
+ $this->db->rollback();
+ return -2;
+ }
+ } else {
+ $this->error = $this->db->error();
+ $this->db->rollback();
+ return -1;
+ }
}
/**
diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php
index 14c921d2254..38660fbcdfd 100644
--- a/htdocs/public/partnership/new.php
+++ b/htdocs/public/partnership/new.php
@@ -236,6 +236,28 @@ if (empty($reshook) && $action == 'add') {
$error++;
}
+ $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'";
+ $result = $db->query($sql);
+ if ($result) {
+ $num = $db->num_rows($result);
+ }
+ if ($num = 0) {
+ //create thirdparty
+ $company = new Societe($db);
+ $resultat=$company->create($user);
+ if ($result < 0) {
+ $error++;
+ $errmsg .= join('
', $company->errors);
+ }
+ $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
+ $sql .= " SET name = ".(GETPOST('societe')).", email = ".(GETPOST('email'));
+ $sql .= ", address = ".(($GETPOSTISSET('address') ? GETPOST('address') : "null")).", zip = ".(($GETPOSTISSET('zipcode') ? GETPOST('zipcode') : "null"));
+ $sql .= ", town = ".(($GETPOSTISSET('town') ? GETPOST('town') : "null")).", fk_pays = ".(($GETPOSTISSET('country_id') ? GETPOST('country_id') : "null"));
+ $sql .= ", fk_departement = ".(($GETPOSTISSET('state_id') ? GETPOST('state_id') : "null")).", note_private = ".(($GETPOSTISSET('note_private') ? GETPOST('note_private') : "null"));
+ $sql .= " WHERE rowid = ".((int) $company->id);
+ $resql = $db->query($sql);
+ $partnership->fk_soc = $company->id;
+ }
$result = $partnership->create($user);
if ($result > 0) {
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
@@ -324,29 +346,7 @@ if (empty($reshook) && $action == 'add') {
}*/
// test if societe or email already exist
- $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'";
- $result = $db->query($sql);
- if ($result) {
- $num = $db->num_rows($result);
- }
- if ($num = 0) {
- //create thirdparty
- $company = new Societe($db);
- $resultat=$company->create($user);
- if ($result < 0) {
- $error++;
- $errmsg .= join('
', $company->errors);
- }
- $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
- $sql .= " SET name = ".(GETPOST('societe')).", email = ".(GETPOST('email'));
- $sql .= ", address = ".(($GETPOSTISSET('address') ? GETPOST('address') : "null")).", zip = ".(($GETPOSTISSET('zipcode') ? GETPOST('zipcode') : "null"));
- $sql .= ", town = ".(($GETPOSTISSET('town') ? GETPOST('town') : "null")).", fk_pays = ".(($GETPOSTISSET('country_id') ? GETPOST('country_id') : "null"));
- $sql .= ", fk_departement = ".(($GETPOSTISSET('state_id') ? GETPOST('state_id') : "null")).", note_private = ".(($GETPOSTISSET('note_private') ? GETPOST('note_private') : "null"));
- $sql .= " WHERE rowid = ".((int) $company->id);
- $resql = $db->query($sql);
-
- $object->fk_soc = $company->id;
- }
+
if (!empty($backtopage)) {