Skip to content
Snippets Groups Projects
Commit ee0db5f6 authored by Regis Houssin's avatar Regis Houssin
Browse files

Merge pull request #597 from FHenry/develop

Update method in thirdparty web service
parents 5b4f1d39 10ed8c14
Branches
Tags
No related merge requests found
...@@ -31,11 +31,13 @@ $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; ...@@ -31,11 +31,13 @@ $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_GETTHIRDSPARTY = 'getThirdParty'; $WS_METHOD_GETTHIRDSPARTY = 'getThirdParty';
$WS_METHOD_CREATETHIRDSPARTY = 'createThirdParty'; $WS_METHOD_CREATETHIRDSPARTY = 'createThirdParty';
$WS_METHOD_UPDATETHIRDSPARTY = 'updateThirdParty';
$ns='http://www.dolibarr.org/ns/'; $ns='http://www.dolibarr.org/ns/';
//Chosse action to do //Chosse action to do
//$action='get'; //$action='get';
$action='create'; $action='create';
//$action='update';
// Set the WebService URL // Set the WebService URL
...@@ -121,6 +123,55 @@ if ($action=='create') ...@@ -121,6 +123,55 @@ if ($action=='create')
} }
} }
// Test URL
if ($action=='update')
{
$thirdparty=array(
'id'=>'1',
'ref'=>'Test WS Create Client',
'ref_ext'=>'WS0001',
'fk_user_mod'=>'1',
'status'=>'1',
'client'=>'1',
'supplier'=>'0',
'address'=>'Adresse customer',
'zip'=>'75000',
'town'=>'Paris',
'country_id'=>'1',//France
'customer_code'=>'-1',//Generate code regarding module configuration
'supplier_code'=>'0',
'phone'=>'0141414141',
'fax'=>'0121212121',
'email'=>'webtest1@test.fr',
'url'=>' www.test.fr',
'profid1'=>'1111111',
'profid2'=>'222222',
'profid3'=>'333333',
'profid4'=>'44444',
'profid5'=>'55555',
'profid6'=>'66666',
'capital'=>'3000',
'vat_used'=>'0',
'vat_number'=>''
//,'options_attr1'=>'Attr1 balbal', //Extra field exemple where field code is attr1
//'options_attr2'=>'Attr2 balbal' //Extra field exemple where field code is attr2
);
$parameters = array('authentication'=>$authentication,'thirdparty'=>$thirdparty);
dol_syslog("Call method ".$WS_METHOD_UPDATETHIRDSPARTY);
$result = $soapclient->call($WS_METHOD_UPDATETHIRDSPARTY,$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
......
...@@ -219,7 +219,7 @@ $server->register( ...@@ -219,7 +219,7 @@ $server->register(
// Entry values // Entry values
array('authentication'=>'tns:authentication','thirdparty'=>'tns:thirdparty'), array('authentication'=>'tns:authentication','thirdparty'=>'tns:thirdparty'),
// Exit values // Exit values
array('result'=>'tns:result','id'=>'xsd:string'), array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string'),
$ns, $ns,
$ns.'#createThirdParty', $ns.'#createThirdParty',
$styledoc, $styledoc,
...@@ -227,6 +227,20 @@ $server->register( ...@@ -227,6 +227,20 @@ $server->register(
'WS to create a thirdparty' 'WS to create a thirdparty'
); );
// Register WSDL
$server->register(
'updateThirdParty',
// Entry values
array('authentication'=>'tns:authentication','thirdparty'=>'tns:thirdparty'),
// Exit values
array('result'=>'tns:result'),
$ns,
$ns.'#updateThirdParty',
$styledoc,
$styleuse,
'WS to update a thirdparty'
);
// Register WSDL // Register WSDL
$server->register( $server->register(
...@@ -465,6 +479,131 @@ function createThirdParty($authentication,$thirdparty) ...@@ -465,6 +479,131 @@ function createThirdParty($authentication,$thirdparty)
return $objectresp; return $objectresp;
} }
/**
* Update a thirdparty
*
* @param array $authentication Array of authentication information
* @param Societe $thirdparty Thirdparty
* @return array Array result
*/
function updateThirdParty($authentication,$thirdparty)
{
global $db,$conf,$langs;
$now=dol_now();
dol_syslog("Function: updateThirdParty login=".$authentication['login']);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
// Init and check authentication
$objectresp=array();
$errorcode='';$errorlabel='';
$error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
// Check parameters
if (empty($thirdparty['id'])) {
$error++; $errorcode='KO'; $errorlabel="Thirdparty id is mandatory.";
}
if (! $error)
{
$objectfound=false;
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$object=new Societe($db);
$result=$object->fetch($id);
if (!empty($thirdparty['id'])) {
$objectfound=true;
$object->ref=$thirdparty['ref'];
$object->name=$thirdparty['ref'];
$object->ref_ext=$thirdparty['ref_ext'];
$object->status=$thirdparty['status'];
$object->client=$thirdparty['client'];
$object->fournisseur=$thirdparty['supplier'];
$object->code_client=$thirdparty['customer_code'];
$object->code_fournisseur=$thirdparty['supplier_code'];
$object->code_compta=$thirdparty['customer_code_accountancy'];
$object->code_compta_fournisseur=$thirdparty['supplier_code_accountancy'];
$object->date_creation=$now;
$object->note=$thirdparty['note'];
$object->address=$thirdparty['address'];
$object->zip=$thirdparty['zip'];
$object->town=$thirdparty['town'];
$object->country_id=$thirdparty['country_id'];
if ($thirdparty['country_code']) $object->country_id=getCountry($thirdparty['country_code'],3);
$object->province_id=$thirdparty['province_id'];
//if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3);
$object->phone=$thirdparty['phone'];
$object->fax=$thirdparty['fax'];
$object->email=$thirdparty['email'];
$object->url=$thirdparty['url'];
$object->idprof1=$thirdparty['profid1'];
$object->idprof2=$thirdparty['profid2'];
$object->idprof3=$thirdparty['profid3'];
$object->idprof4=$thirdparty['profid4'];
$object->idprof5=$thirdparty['profid5'];
$object->idprof6=$thirdparty['profid6'];
$object->capital=$thirdparty['capital'];
$object->barcode=$thirdparty['barcode'];
$object->tva_assuj=$thirdparty['vat_used'];
$object->tva_intra=$thirdparty['vat_number'];
$object->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;
$object->array_options[$key]=$thirdparty[$key];
}
$db->begin();
$result=$object->update($fuser);
if ($result <= 0) {
$error++;
}
}
if ((! $error) && ($objectfound))
{
$db->commit();
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''));
}
elseif ($objectfound)
{
$db->rollback();
$error++;
$errorcode='KO';
$errorlabel=$object->error;
} else {
$error++;
$errorcode='NOT_FOUND';
$errorlabel='Thirdparty id='.$thirdparty['id'].' cannot be found';
}
}
if ($error)
{
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
return $objectresp;
}
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment