Merge pull request #540 from FHenry/develop
Full standard extrafields management in Thirds Party Web service
This commit is contained in:
commit
fdc7d0b9d3
@ -117,7 +117,7 @@ class ActionComm extends CommonObject
|
||||
$this->note=dol_htmlcleanlastbr(trim($this->note));
|
||||
if (empty($this->percentage)) $this->percentage = 0;
|
||||
if (empty($this->priority)) $this->priority = 0;
|
||||
if (empty($this->fulldayevent)) $this->fuldayevent = 0;
|
||||
if (empty($this->fulldayevent)) $this->fulldayevent = 0;
|
||||
if (empty($this->punctual)) $this->punctual = 0;
|
||||
if ($this->percentage > 100) $this->percentage = 100;
|
||||
if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -28,9 +29,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);
|
||||
@ -51,11 +57,11 @@ $authentication=array(
|
||||
|
||||
|
||||
// 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 +73,54 @@ 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'=>'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'=>$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
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user