diff --git a/htdocs/webservices/demo_wsclient_thirdparty.php-NORUN b/htdocs/webservices/demo_wsclient_thirdparty.php-NORUN
index 519d417edb3..70ee0b387e6 100755
--- a/htdocs/webservices/demo_wsclient_thirdparty.php-NORUN
+++ b/htdocs/webservices/demo_wsclient_thirdparty.php-NORUN
@@ -28,9 +28,14 @@ require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
//$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with /
-$WS_METHOD = 'getThirdParty';
+$WS_METHOD_GETTHIRDSPARTY = 'getThirdParty';
+$WS_METHOD_CREATETHIRDSPARTY = 'createThirdParty';
$ns='http://www.dolibarr.org/ns/';
+//Chosse action to do
+//$action='get';
+$action='create';
+
// Set the WebService URL
dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
@@ -45,17 +50,17 @@ if ($soapclient)
$authentication=array(
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
'sourceapplication'=>'DEMO',
- 'login'=>'admin',
- 'password'=>'changeme',
- 'entity'=>'');
+ 'login'=>'admin_dolibarDev',
+ 'password'=>'homedread',
+ 'entity'=>'1');
// Test URL
-if ($WS_METHOD)
+if ($action=='get')
{
- $parameters = array('authentication'=>$authentication,'id'=>0,'name'=>'aaa','ref_ext'=>'');
- dol_syslog("Call method ".$WS_METHOD);
- $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
+ $parameters = array('authentication'=>$authentication,'id'=>1,'name'=>'','ref_ext'=>'');
+ dol_syslog("Call method ".$WS_METHOD_GETTHIRDSPARTY);
+ $result = $soapclient->call($WS_METHOD_GETTHIRDSPARTY,$parameters,$ns,'');
if (! $result)
{
print $soapclient->error_str;
@@ -67,6 +72,53 @@ if ($WS_METHOD)
}
}
+// Test URL
+if ($action=='create')
+{
+ $newthirdparty=array(
+ 'ref'=>'Test WS Create Client',
+ 'ref_ext'=>'WS0001',
+ 'fk_user_author'=>'1',
+ 'status'=>'1',
+ 'client'=>'1',
+ 'supplier'=>'0',
+ 'address'=>'65 impasse des aulnes',
+ 'zip'=>'30129',
+ 'town'=>'Manduel',
+ 'country_id'=>'1',//France
+ 'customer_code'=>'-1',//Generate code regarding module configuration
+ 'supplier_code'=>'0',
+ 'phone'=>'0141414141',
+ 'fax'=>'0121212121',
+ 'email'=>'webtest1@open-concapt.pro',
+ 'url'=>' www.test1.fr',
+ 'profid1'=>'1111111',
+ 'profid2'=>'222222',
+ 'profid3'=>'333333',
+ 'profid4'=>'44444',
+ 'profid5'=>'55555',
+ 'profid6'=>'66666',
+ 'capital'=>'3000',
+ 'vat_used'=>'0',
+ 'vat_number'=>'',
+ 'options_attr1'=>'Attr1 balbal',
+ 'options_attr2'=>'Attr2 balbal');
+
+
+ $parameters = array('authentication'=>$authentication,'thirdparty'=>$newthirdparty);
+ dol_syslog("Call method ".$WS_METHOD_CREATETHIRDSPARTY);
+ $result = $soapclient->call($WS_METHOD_CREATETHIRDSPARTY,$parameters,$ns,'');
+ if (! $result)
+ {
+ print $soapclient->error_str;
+ print "
\n\n";
+ print $soapclient->request;
+ print "
\n\n";
+ print $soapclient->response;
+ exit;
+ }
+}
+
/*
* View
diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php
index ba9ec57fea1..ee76f7ac8c2 100755
--- a/htdocs/webservices/server_thirdparty.php
+++ b/htdocs/webservices/server_thirdparty.php
@@ -124,6 +124,9 @@ $thirdparty_fields= array(
// fetch optionals attributes and labels
$extrafields=new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('company');
+if (count($extrafields)>0) {
+ $extrafield_array = array();
+}
foreach($extrafields->attribute_label as $key=>$label)
{
//$value=$object->array_options["options_".$key];
@@ -131,9 +134,7 @@ foreach($extrafields->attribute_label as $key=>$label)
if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';}
else {$type='xsd:string';}
- $extrafield_array = array();
-
- $extrafield_array[$key]=array('name'=>$key,'type'=>$type);
+ $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type);
}
$thirdparty_fields=array_merge($thirdparty_fields,$extrafield_array);
@@ -273,10 +274,8 @@ function getThirdParty($authentication,$id='',$ref='',$ref_ext='')
$result=$thirdparty->fetch($id,$ref,$ref_ext);
if ($result > 0)
{
- // Create
- $objectresp = array(
- 'result'=>array('result_code'=>'OK', 'result_label'=>''),
- 'thirdparty'=>array(
+
+ $thirdparty_result_fields=array(
'id' => $thirdparty->id,
'ref' => $thirdparty->name,
'ref_ext' => $thirdparty->ref_ext,
@@ -310,8 +309,24 @@ function getThirdParty($authentication,$id='',$ref='',$ref_ext='')
'capital' => $thirdparty->capital,
'barcode' => $thirdparty->barcode,
'vat_used' => $thirdparty->tva_assuj,
- 'vat_number' => $thirdparty->tva_intra
- ));
+ 'vat_number' => $thirdparty->tva_intra);
+
+ //Retreive all extrafield for thirdsparty
+ // fetch optionals attributes and labels
+ $extrafields=new ExtraFields($db);
+ $extralabels=$extrafields->fetch_name_optionals_label('company');
+ //Get extrafield values
+ $thirdparty->fetch_optionals($thirdparty->id,$extralabels);
+
+ foreach($extrafields->attribute_label as $key=>$label)
+ {
+ $thirdparty_result_fields=array_merge($thirdparty_result_fields,array('options_'.$key => $thirdparty->array_options['options_'.$key]));
+ }
+
+ // Create
+ $objectresp = array(
+ 'result'=>array('result_code'=>'OK', 'result_label'=>''),
+ 'thirdparty'=>$thirdparty_result_fields);
}
else
{
@@ -409,6 +424,16 @@ function createThirdParty($authentication,$thirdparty)
$newobject->tva_intra=$thirdparty['vat_number'];
$newobject->canvas=$thirdparty['canvas'];
+
+ //Retreive all extrafield for thirdsparty
+ // fetch optionals attributes and labels
+ $extrafields=new ExtraFields($db);
+ $extralabels=$extrafields->fetch_name_optionals_label('company');
+ foreach($extrafields->attribute_label as $key=>$label)
+ {
+ $key='options_'.$key;
+ $newobject->array_options[$key]=$thirdparty[$key];
+ }
$db->begin();