From 18b163c6db9edcbc8eb9e93b8398c95bd6c20af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 20 Dec 2013 17:03:24 +0100 Subject: [PATCH] allow the webservice to create a private individual --- htdocs/societe/class/societe.class.php | 19 +++++++++++++++++++ htdocs/societe/soc.php | 22 ++-------------------- htdocs/webservices/server_thirdparty.php | 6 ++++++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index d0d28bf2cee..f2f737cdbdb 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -297,6 +297,25 @@ class Societe extends CommonObject } } + function create_individual($user) { + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + $contact=new Contact($this->db); + + $contact->name = $this->name_bis; + $contact->firstname = $this->firstname; + $contact->socid = $this->id; // fk_soc + $contact->statut = 1; + $contact->priv = 0; + $result = $contact->create($user); + if ($result < 0) { + $this->error = $contact->error; + $this->errors = $contact->errors; + dol_syslog("Societe::create_individual ERROR:" . $this->error, LOG_ERR); + } + + return $result; + } + /** * Check properties of third party are ok (like name, third party codes, ...) * diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 881fce7b2b5..864b42b86a9 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -255,28 +255,10 @@ if (empty($reshook)) if ($object->particulier) { dol_syslog("This thirdparty is a personal people",LOG_DEBUG); - $contact=new Contact($db); - - $contact->civilite_id = $object->civilite_id; - $contact->name = $object->name_bis; - $contact->firstname = $object->firstname; - $contact->address = $object->address; - $contact->zip = $object->zip; - $contact->town = $object->town; - $contact->state_id = $object->state_id; - $contact->country_id = $object->country_id; - $contact->socid = $object->id; // fk_soc - $contact->statut = 1; - $contact->email = $object->email; - $contact->skype = $object->skype; - $contact->phone_pro = $object->phone; - $contact->fax = $object->fax; - $contact->priv = 0; - - $result=$contact->create($user); + $result=$object->create_individual($user); if (! $result >= 0) { - $error=$contact->error; $errors=$contact->errors; + $error=$object->error; $errors=$object->errors; } } diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 152a28053fa..ccc05902dca 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -443,6 +443,7 @@ function createThirdParty($authentication,$thirdparty) $newobject->tva_intra=$thirdparty['vat_number']; $newobject->canvas=$thirdparty['canvas']; + $newobject->particulier=$thirdparty['individual']; //Retreive all extrafield for thirdsparty // fetch optionals attributes and labels @@ -457,6 +458,11 @@ function createThirdParty($authentication,$thirdparty) $db->begin(); $result=$newobject->create($fuser); + if ($newobject->particulier && $result > 0) { + $newobject->firstname = $thirdparty['firstname']; + $newobject->name_bis = $thirdparty['ref']; + $result = $newobject->create_individual($fuser); + } if ($result <= 0) { $error++;