Full standard extrafields management in Thirds Party Web service
This commit is contained in:
parent
57742b347a
commit
14c1616adb
@ -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 = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
|
||||||
//$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with /
|
//$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/';
|
$ns='http://www.dolibarr.org/ns/';
|
||||||
|
|
||||||
|
//Chosse action to do
|
||||||
|
//$action='get';
|
||||||
|
$action='create';
|
||||||
|
|
||||||
|
|
||||||
// Set the WebService URL
|
// Set the WebService URL
|
||||||
dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
|
dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
|
||||||
@ -45,17 +50,17 @@ if ($soapclient)
|
|||||||
$authentication=array(
|
$authentication=array(
|
||||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||||
'sourceapplication'=>'DEMO',
|
'sourceapplication'=>'DEMO',
|
||||||
'login'=>'admin',
|
'login'=>'admin_dolibarDev',
|
||||||
'password'=>'changeme',
|
'password'=>'homedread',
|
||||||
'entity'=>'');
|
'entity'=>'1');
|
||||||
|
|
||||||
|
|
||||||
// Test URL
|
// Test URL
|
||||||
if ($WS_METHOD)
|
if ($action=='get')
|
||||||
{
|
{
|
||||||
$parameters = array('authentication'=>$authentication,'id'=>0,'name'=>'aaa','ref_ext'=>'');
|
$parameters = array('authentication'=>$authentication,'id'=>1,'name'=>'','ref_ext'=>'');
|
||||||
dol_syslog("Call method ".$WS_METHOD);
|
dol_syslog("Call method ".$WS_METHOD_GETTHIRDSPARTY);
|
||||||
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
|
$result = $soapclient->call($WS_METHOD_GETTHIRDSPARTY,$parameters,$ns,'');
|
||||||
if (! $result)
|
if (! $result)
|
||||||
{
|
{
|
||||||
print $soapclient->error_str;
|
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 "<br>\n\n";
|
||||||
|
print $soapclient->request;
|
||||||
|
print "<br>\n\n";
|
||||||
|
print $soapclient->response;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* View
|
* View
|
||||||
|
|||||||
@ -124,6 +124,9 @@ $thirdparty_fields= array(
|
|||||||
// fetch optionals attributes and labels
|
// fetch optionals attributes and labels
|
||||||
$extrafields=new ExtraFields($db);
|
$extrafields=new ExtraFields($db);
|
||||||
$extralabels=$extrafields->fetch_name_optionals_label('company');
|
$extralabels=$extrafields->fetch_name_optionals_label('company');
|
||||||
|
if (count($extrafields)>0) {
|
||||||
|
$extrafield_array = array();
|
||||||
|
}
|
||||||
foreach($extrafields->attribute_label as $key=>$label)
|
foreach($extrafields->attribute_label as $key=>$label)
|
||||||
{
|
{
|
||||||
//$value=$object->array_options["options_".$key];
|
//$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';}
|
if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';}
|
||||||
else {$type='xsd:string';}
|
else {$type='xsd:string';}
|
||||||
|
|
||||||
$extrafield_array = array();
|
$extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type);
|
||||||
|
|
||||||
$extrafield_array[$key]=array('name'=>$key,'type'=>$type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$thirdparty_fields=array_merge($thirdparty_fields,$extrafield_array);
|
$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);
|
$result=$thirdparty->fetch($id,$ref,$ref_ext);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
// Create
|
|
||||||
$objectresp = array(
|
$thirdparty_result_fields=array(
|
||||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
|
||||||
'thirdparty'=>array(
|
|
||||||
'id' => $thirdparty->id,
|
'id' => $thirdparty->id,
|
||||||
'ref' => $thirdparty->name,
|
'ref' => $thirdparty->name,
|
||||||
'ref_ext' => $thirdparty->ref_ext,
|
'ref_ext' => $thirdparty->ref_ext,
|
||||||
@ -310,8 +309,24 @@ function getThirdParty($authentication,$id='',$ref='',$ref_ext='')
|
|||||||
'capital' => $thirdparty->capital,
|
'capital' => $thirdparty->capital,
|
||||||
'barcode' => $thirdparty->barcode,
|
'barcode' => $thirdparty->barcode,
|
||||||
'vat_used' => $thirdparty->tva_assuj,
|
'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
|
else
|
||||||
{
|
{
|
||||||
@ -410,6 +425,16 @@ function createThirdParty($authentication,$thirdparty)
|
|||||||
|
|
||||||
$newobject->canvas=$thirdparty['canvas'];
|
$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();
|
$db->begin();
|
||||||
|
|
||||||
$result=$newobject->create($fuser);
|
$result=$newobject->create($fuser);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user