Work on product webservice

This commit is contained in:
eldy
2011-10-01 01:30:32 +02:00
parent c1f5b2f3a1
commit f70b1894db
9 changed files with 828 additions and 179 deletions

View File

@@ -124,6 +124,10 @@ class Product extends CommonObject
//! Canevas a utiliser si le produit n'est pas un produit generique
var $canvas;
var $import_key;
var $date_creation;
var $date_modification;
//! Id du fournisseur
var $product_fourn_id;
@@ -997,21 +1001,21 @@ class Product extends CommonObject
/**
* Load a product in memory from database
*
* @param id Id of product/service to load
* @param ref Ref of product/service to load
* @return int <0 if KO, >0 if OK
* @param int $id Id of product/service to load
* @param string $ref Ref of product/service to load
* @param string $ref_ext Ref ext of product/service to load
* @return int <0 if KO, >0 if OK
*/
function fetch($id='',$ref='')
function fetch($id='',$ref='',$ref_ext='')
{
include_once(DOL_DOCUMENT_ROOT.'/lib/company.lib.php');
global $langs;
global $conf;
global $langs, $conf;
dol_syslog("Product::fetch id=$id ref=$ref");
dol_syslog("Product::fetch id=$id ref=$ref ref_ext=$ref_ext");
// Check parameters
if (! $id && ! $ref)
if (! $id && ! $ref && ! $ref_ext)
{
$this->error=$langs->trans('ErrorWrongParameters');
dol_print_error("Product::fetch ".$this->error, LOG_ERR);
@@ -1023,10 +1027,11 @@ class Product extends CommonObject
$sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas,";
$sql.= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,";
$sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,";
$sql.= " import_key";
$sql.= " datec, tms, import_key";
$sql.= " FROM ".MAIN_DB_PREFIX."product";
if ($id) $sql.= " WHERE rowid = '".$id."'";
else if ($ref) $sql.= " WHERE ref = '".$this->db->escape($ref)."'";
else if ($ref_ext) $sql.= " WHERE ref_ext = '".$this->db->escape($ref_ext)."'";
dol_syslog("Product::fetch sql=".$sql);
$resql = $this->db->query($sql);
@@ -1083,6 +1088,8 @@ class Product extends CommonObject
$this->stock_reel = $object->stock;
$this->pmp = $object->pmp;
$this->date_creation = $object->datec;
$this->date_modification = $object->tms;
$this->import_key = $object->import_key;
$this->db->free($resql);

View File

@@ -101,6 +101,11 @@ print '<br><br>';
print '<u>'.$langs->trans("WSDLCanBeDownloadedHere").':</u><br>';
$url=DOL_MAIN_URL_ROOT.'/webservices/server_other.php?wsdl';
print img_picto('','object_globe.png').' '.'<a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
if ($conf->product->enabled || $conf->service->enabled)
{
$url=DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php?wsdl';
print img_picto('','object_globe.png').' '.'<a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
}
if ($conf->societe->enabled)
{
$url=DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php?wsdl';
@@ -123,6 +128,11 @@ print '<br>';
print '<u>'.$langs->trans("EndPointIs").':</u><br>';
$url=DOL_MAIN_URL_ROOT.'/webservices/server_other.php';
print img_picto('','object_globe.png').' '.'<a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
if ($conf->product->enabled || $conf->service->enabled)
{
$url=DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
print img_picto('','object_globe.png').' '.'<a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
}
if ($conf->societe->enabled)
{
$url=DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';

View File

@@ -0,0 +1,140 @@
<?php
/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/webservices/demo_wsclient_productorservice.php
* \brief Demo page to make a client call to Dolibarr WebServices "server_product"
*/
// This is to make Dolibarr working with Plesk
set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
require_once("../master.inc.php");
require_once(NUSOAP_PATH.'/nusoap.php'); // Include SOAP
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
//$WS_DOL_URL = 'http://localhost:8080/'; // To test with Soapui mock. If not a page, should end with /
$WS_METHOD1 = 'createProductOrService';
$WS_METHOD2 = 'getProductOrService';
$ns='http://www.dolibarr.org/ns/';
// Set the WebService URL
dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
$soapclient1 = new nusoap_client($WS_DOL_URL);
if ($soapclient1)
{
$soapclient1->soap_defencoding='UTF-8';
$soapclient1->decodeUTF8(false);
}
$soapclient2 = new nusoap_client($WS_DOL_URL);
if ($soapclient2)
{
$soapclient2->soap_defencoding='UTF-8';
$soapclient2->decodeUTF8(false);
}
// Call the WebService method and store its result in $result.
$authentication=array(
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
'sourceapplication'=>'DEMO',
'login'=>'admin',
'password'=>'changeme',
'entity'=>'');
// Test url 1
if ($WS_METHOD1)
{
$parameters = array('authentication'=>$authentication,'id'=>1,'ref'=>'');
dol_syslog("Call method ".$WS_METHOD1);
$result1 = $soapclient1->call($WS_METHOD1,$parameters,$ns,'');
if (! $result1)
{
print $soapclient1->error_str;
print "<br>\n\n";
print $soapclient1->request;
print "<br>\n\n";
print $soapclient1->response;
exit;
}
}
// Test url 2
if ($WS_METHOD2)
{
$parameters = array('authentication'=>$authentication,'id'=>1,'ref'=>'');
dol_syslog("Call method ".$WS_METHOD2);
$result2 = $soapclient1->call($WS_METHOD2,$parameters,$ns,'');
if (! $result2)
{
print $soapclient1->error_str;
print "<br>\n\n";
print $soapclient1->request;
print "<br>\n\n";
print $soapclient1->response;
exit;
}
}
/*
* View
*/
header("Content-type: text/html; charset=utf8");
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
echo '<html>'."\n";
echo '<head>';
echo '<title>WebService Test: '.$WS_METHOD1.'</title>';
echo '</head>'."\n";
echo '<body>'."\n";
echo "<h2>Request:</h2>";
echo '<h4>Function</h4>';
echo $WS_METHOD1;
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient1->request, ENT_QUOTES) . '</pre>';
echo '<hr>';
echo "<h2>Response:</h2>";
echo '<h4>Result</h4>';
echo '<pre>';
print_r($result1);
echo '</pre>';
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient1->response, ENT_QUOTES) . '</pre>';
print '<hr>';
echo "<h2>Request:</h2>";
echo '<h4>Function</h4>';
echo $WS_METHOD2;
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient2->request, ENT_QUOTES) . '</pre>';
echo '<hr>';
echo "<h2>Response:</h2>";
echo '<h4>Result</h4>';
echo '<pre>';
print_r($result2);
echo '</pre>';
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient2->response, ENT_QUOTES) . '</pre>';
echo '</body>'."\n";;
echo '</html>'."\n";;
?>

View File

@@ -52,7 +52,7 @@ $server->configureWSDL('WebServicesDolibarrInvoice',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
// Define WSDL content
// Define WSDL Authentication object
$server->wsdl->addComplexType(
'authentication',
'complexType',
@@ -67,7 +67,20 @@ $server->wsdl->addComplexType(
'entity' => array('name'=>'entity','type'=>'xsd:string'),
)
);
// Define WSDL Return object
$server->wsdl->addComplexType(
'result',
'complexType',
'struct',
'all',
'',
array(
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
)
);
// Define other specific objects
$server->wsdl->addComplexType(
'line',
'complexType',
@@ -183,19 +196,6 @@ $server->wsdl->addComplexType(
);
$server->wsdl->addComplexType(
'result',
'complexType',
'struct',
'all',
'',
array(
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
)
);
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
@@ -205,43 +205,49 @@ $styleuse='encoded'; // encoded/literal/literal wrapped
// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
// Register WSDL
$server->register('getInvoice',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','invoice'=>'tns:invoice'),
$ns,
$ns.'#getInvoice',
$styledoc,
$styleuse,
'WS to get a particular invoice'
$server->register(
'getInvoice',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','invoice'=>'tns:invoice'),
$ns,
$ns.'#getInvoice',
$styledoc,
$styleuse,
'WS to get a particular invoice'
);
$server->register('getInvoicesForThirdParty',
// Entry values
array('authentication'=>'tns:authentication','idthirdparty'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','invoices'=>'tns:InvoicesArray2'),
$ns,
$ns.'#getInvoicesForThirdParty',
$styledoc,
$styleuse,
'WS to get all invoices of a third party'
$server->register(
'getInvoicesForThirdParty',
// Entry values
array('authentication'=>'tns:authentication','idthirdparty'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','invoices'=>'tns:InvoicesArray2'),
$ns,
$ns.'#getInvoicesForThirdParty',
$styledoc,
$styleuse,
'WS to get all invoices of a third party'
);
$server->register('createInvoice',
// Entry values
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
// Exit values
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string'),
$ns,
$ns.'#createInvoice',
$styledoc,
$styleuse,
'WS to create an invoice'
$server->register(
'createInvoice',
// Entry values
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
// Exit values
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string'),
$ns,
$ns.'#createInvoice',
$styledoc,
$styleuse,
'WS to create an invoice'
);
/**
* Get invoice from id, ref or ref_ext
*
* @param object $authentication
*
*/
function getInvoice($authentication,$id='',$ref='',$ref_ext='')
{

View File

@@ -52,21 +52,22 @@ $server->configureWSDL('WebServicesDolibarrOther',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
// Define WSDL content
// Define WSDL Authentication object
$server->wsdl->addComplexType(
'authentication',
'complexType',
'struct',
'all',
'',
array(
'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
'login' => array('name'=>'login','type'=>'xsd:string'),
'password' => array('name'=>'password','type'=>'xsd:string'),
'entity' => array('name'=>'entity','type'=>'xsd:string'),
));
'authentication',
'complexType',
'struct',
'all',
'',
array(
'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
'login' => array('name'=>'login','type'=>'xsd:string'),
'password' => array('name'=>'password','type'=>'xsd:string'),
'entity' => array('name'=>'entity','type'=>'xsd:string'),
)
);
// Define WSDL Return object
$server->wsdl->addComplexType(
'result',
'complexType',
@@ -76,7 +77,11 @@ $server->wsdl->addComplexType(
array(
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
));
)
);
// Define other specific objects
// None
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped

View File

@@ -0,0 +1,221 @@
<?php
/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/webservices/server_productorservice.php
* \brief File that is entry point to call Dolibarr WebServices
*/
// This is to make Dolibarr working with Plesk
set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
require_once("../master.inc.php");
require_once(NUSOAP_PATH.'/nusoap.php'); // Include SOAP
require_once(DOL_DOCUMENT_ROOT."/lib/ws.lib.php");
require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
dol_syslog("Call Dolibarr webservices interfaces");
// Enable and test if module web services is enabled
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
{
$langs->load("admin");
dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
print $langs->trans("WarningModuleNotActive",'WebServices').'.<br><br>';
print $langs->trans("ToActivateModule");
exit;
}
// Create the soap Object
$server = new nusoap_server();
$server->soap_defencoding='UTF-8';
$server->decode_utf8=false;
$ns='http://www.dolibarr.org/ns/';
$server->configureWSDL('WebServicesDolibarrProductOrService',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
// Define WSDL Authentication object
$server->wsdl->addComplexType(
'authentication',
'complexType',
'struct',
'all',
'',
array(
'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
'login' => array('name'=>'login','type'=>'xsd:string'),
'password' => array('name'=>'password','type'=>'xsd:string'),
'entity' => array('name'=>'entity','type'=>'xsd:string'),
)
);
// Define WSDL Return object
$server->wsdl->addComplexType(
'result',
'complexType',
'struct',
'all',
'',
array(
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
)
);
// Define other specific objects
$server->wsdl->addComplexType(
'product',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name'=>'id','type'=>'xsd:string'),
'ref' => array('name'=>'name','type'=>'xsd:string'),
'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'),
'label' => array('name'=>'label','type'=>'xsd:string'),
'description' => array('name'=>'description','type'=>'xsd:string'),
'date_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'),
'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'),
'note' => array('name'=>'note','type'=>'xsd:string'),
'tobuy' => array('name'=>'tobuy','type'=>'xsd:string'),
'tosell' => array('name'=>'tosell','type'=>'xsd:string'),
'type' => array('name'=>'type','type'=>'xsd:string'),
'barcode' => array('name'=>'barcode','type'=>'xsd:string'),
'country_id' => array('name'=>'country_id','type'=>'xsd:string')
)
);
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
$styledoc='rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
$styleuse='encoded'; // encoded/literal/literal wrapped
// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
// Register WSDL
$server->register(
'createProductOrService',
// Entry values
array('authentication'=>'tns:authentication','product'=>'tns:product'),
// Exit values
array('result'=>'tns:result','id'=>'xsd:string'),
$ns,
$ns.'#createProductOrService',
$styledoc,
$styleuse,
'WS to create a product or service'
);
// Register WSDL
$server->register(
'getProductOrService',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','product'=>'tns:product'),
$ns,
$ns.'#getProductOrService',
$styledoc,
$styleuse,
'WS to get product or service'
);
// Full methods code
function getProductOrService($authentication,$id='',$ref='',$ref_ext='')
{
global $db,$conf,$langs;
dol_syslog("Function: getProductOrService login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
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 (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
{
$error++;
$errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
}
if (! $error)
{
$fuser->getrights();
if ($fuser->rights->produit->lire || $fuser->rights->service->lire)
{
$product=new Product($db);
$result=$product->fetch($id,$ref,$ref_ext);
if ($result > 0)
{
// Create
$objectresp = array(
'result'=>array('result_code'=>'OK', 'result_label'=>''),
'product'=>array(
'id' => $product->id,
'ref' => $product->name,
'ref_ext' => $product->ref_ext,
'label' => $product->label,
'description' => $product->description,
'date_creation' => $product->date_creation,
'date_modification' => $product->date_modification,
'note' => $product->note,
'tobuy' => $product->tobuy,
'tosell' => $product->tosell,
'type' => $product->type,
'barcode' => $product->barcode,
'country_id' => $product->country_id
));
}
else
{
$error++;
$errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
}
}
else
{
$error++;
$errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request';
}
}
if ($error)
{
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
return $objectresp;
}
// Return the results.
$server->service($HTTP_RAW_POST_DATA);
?>

View File

@@ -52,21 +52,35 @@ $server->configureWSDL('WebServicesDolibarrSupplierInvoice',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
// Define WSDL content
// Define WSDL Authentication object
$server->wsdl->addComplexType(
'authentication',
'complexType',
'struct',
'all',
'',
array(
'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
'login' => array('name'=>'login','type'=>'xsd:string'),
'password' => array('name'=>'password','type'=>'xsd:string'),
'entity' => array('name'=>'entity','type'=>'xsd:string'),
));
'authentication',
'complexType',
'struct',
'all',
'',
array(
'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
'login' => array('name'=>'login','type'=>'xsd:string'),
'password' => array('name'=>'password','type'=>'xsd:string'),
'entity' => array('name'=>'entity','type'=>'xsd:string'),
)
);
// Define WSDL Return object
$server->wsdl->addComplexType(
'result',
'complexType',
'struct',
'all',
'',
array(
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
)
);
// Define other specific objects
$server->wsdl->addComplexType(
'line',
'element',
@@ -163,16 +177,6 @@ $server->wsdl->addComplexType(
'tns:invoice'
);
$server->wsdl->addComplexType(
'result',
'complexType',
'struct',
'all',
'',
array(
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
));
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
@@ -183,27 +187,29 @@ $styleuse='encoded'; // encoded/literal/literal wrapped
// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
// Register WSDL
$server->register('getSupplierInvoice',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','invoice'=>'tns:invoice'),
$ns,
$ns.'#getSupplierInvoice',
$styledoc,
$styleuse,
'WS to get SupplierInvoice'
$server->register(
'getSupplierInvoice',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','invoice'=>'tns:invoice'),
$ns,
$ns.'#getSupplierInvoice',
$styledoc,
$styleuse,
'WS to get SupplierInvoice'
);
$server->register('getSupplierInvoicesForThirdParty',
// Entry values
array('authentication'=>'tns:authentication','idthirdparty'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','invoices'=>'tns:invoices'),
$ns,
$ns.'#getSupplierInvoicesForThirdParty',
$styledoc,
$styleuse,
'WS to get SupplierInvoicesForThirdParty'
$server->register(
'getSupplierInvoicesForThirdParty',
// Entry values
array('authentication'=>'tns:authentication','idthirdparty'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','invoices'=>'tns:invoices'),
$ns,
$ns.'#getSupplierInvoicesForThirdParty',
$styledoc,
$styleuse,
'WS to get SupplierInvoicesForThirdParty'
);

View File

@@ -52,67 +52,70 @@ $server->configureWSDL('WebServicesDolibarrThirdParty',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
// Define WSDL content
// Define WSDL Authentication object
$server->wsdl->addComplexType(
'authentication',
'complexType',
'struct',
'all',
'',
array(
'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
'login' => array('name'=>'login','type'=>'xsd:string'),
'password' => array('name'=>'password','type'=>'xsd:string'),
'entity' => array('name'=>'entity','type'=>'xsd:string'),
));
'authentication',
'complexType',
'struct',
'all',
'',
array(
'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
'login' => array('name'=>'login','type'=>'xsd:string'),
'password' => array('name'=>'password','type'=>'xsd:string'),
'entity' => array('name'=>'entity','type'=>'xsd:string'),
)
);
// Define WSDL Return object
$server->wsdl->addComplexType(
'result',
'complexType',
'struct',
'all',
'',
array(
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
)
);
// Define other specific objects
$server->wsdl->addComplexType(
'thirdparty',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name'=>'id','type'=>'xsd:string'),
'ref' => array('name'=>'name','type'=>'xsd:string'),
'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'),
'fk_user_author' => array('name'=>'fk_user_author','type'=>'xsd:string'),
'date' => array('name'=>'date','type'=>'xsd:date'),
'date_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'),
'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'),
'note' => array('name'=>'note','type'=>'xsd:string'),
'address' => array('name'=>'address','type'=>'xsd:string'),
'zip' => array('name'=>'zip','type'=>'xsd:string'),
'town' => array('name'=>'town','type'=>'xsd:string'),
'province_id' => array('name'=>'province_id','type'=>'xsd:string'),
'country_id' => array('name'=>'country_id','type'=>'xsd:string'),
'country_code' => array('name'=>'country_code','type'=>'xsd:string'),
'country' => array('name'=>'country','type'=>'xsd:string'),
'phone' => array('name'=>'country_id','type'=>'xsd:string'),
'fax' => array('name'=>'country_id','type'=>'xsd:string'),
'email' => array('name'=>'country_id','type'=>'xsd:string'),
'url' => array('name'=>'country_id','type'=>'xsd:string'),
'profid1' => array('name'=>'profid1','type'=>'xsd:string'),
'profid2' => array('name'=>'profid2','type'=>'xsd:string'),
'profid3' => array('name'=>'profid3','type'=>'xsd:string'),
'profid4' => array('name'=>'profid4','type'=>'xsd:string'),
'prefix' => array('name'=>'prefix','type'=>'xsd:string'),
'vat_used' => array('name'=>'vat_used','type'=>'xsd:string'),
'vat_number' => array('name'=>'vat_number','type'=>'xsd:string')
)
);
$server->wsdl->addComplexType(
'result',
'complexType',
'struct',
'all',
'',
array(
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
));
'thirdparty',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name'=>'id','type'=>'xsd:string'),
'ref' => array('name'=>'name','type'=>'xsd:string'),
'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'),
'fk_user_author' => array('name'=>'fk_user_author','type'=>'xsd:string'),
'date' => array('name'=>'date','type'=>'xsd:date'),
'date_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'),
'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'),
'note' => array('name'=>'note','type'=>'xsd:string'),
'address' => array('name'=>'address','type'=>'xsd:string'),
'zip' => array('name'=>'zip','type'=>'xsd:string'),
'town' => array('name'=>'town','type'=>'xsd:string'),
'province_id' => array('name'=>'province_id','type'=>'xsd:string'),
'country_id' => array('name'=>'country_id','type'=>'xsd:string'),
'country_code' => array('name'=>'country_code','type'=>'xsd:string'),
'country' => array('name'=>'country','type'=>'xsd:string'),
'phone' => array('name'=>'country_id','type'=>'xsd:string'),
'fax' => array('name'=>'country_id','type'=>'xsd:string'),
'email' => array('name'=>'country_id','type'=>'xsd:string'),
'url' => array('name'=>'country_id','type'=>'xsd:string'),
'profid1' => array('name'=>'profid1','type'=>'xsd:string'),
'profid2' => array('name'=>'profid2','type'=>'xsd:string'),
'profid3' => array('name'=>'profid3','type'=>'xsd:string'),
'profid4' => array('name'=>'profid4','type'=>'xsd:string'),
'prefix' => array('name'=>'prefix','type'=>'xsd:string'),
'vat_used' => array('name'=>'vat_used','type'=>'xsd:string'),
'vat_number' => array('name'=>'vat_number','type'=>'xsd:string')
)
);
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
@@ -123,16 +126,17 @@ $styleuse='encoded'; // encoded/literal/literal wrapped
// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
// Register WSDL
$server->register('getThirdParty',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','thirdparty'=>'tns:thirdparty'),
$ns,
$ns.'#getVersions',
$styledoc,
$styleuse,
'WS to get Versions'
$server->register(
'getThirdParty',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','thirdparty'=>'tns:thirdparty'),
$ns,
$ns.'#getVersions',
$styledoc,
$styleuse,
'WS to get Versions'
);

250
test/phpunit/ProductTest.php Executable file
View File

@@ -0,0 +1,250 @@
<?php
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file test/phpunit/ProductTest.php
* \ingroup test
* \brief PHPUnit test
* \remarks To run this script as CLI: phpunit filename.php
*/
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/product/class/product.class.php';
if (empty($user->id))
{
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
/**
* Class for PHPUnit tests
*
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class ProductTest extends PHPUnit_Framework_TestCase
{
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
/**
* Constructor
* We save global variables into local variables
*
* @return ProductTest
*/
function ProductTest()
{
//$this->sharedFixture
global $conf,$user,$langs,$db;
$this->savconf=$conf;
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
print "\n";
}
// Static methods
public static function setUpBeforeClass()
{
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
print __METHOD__."\n";
}
public static function tearDownAfterClass()
{
global $conf,$user,$langs,$db;
$db->rollback();
print __METHOD__."\n";
}
/**
*/
protected function setUp()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
print __METHOD__."\n";
}
/**
*/
protected function tearDown()
{
print __METHOD__."\n";
}
/**
*/
public function testProductCreate()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Product($this->savdb);
$localobject->initAsSpecimen();
$result=$localobject->create($user);
print __METHOD__." result=".$result."\n";
$this->assertLessThanOrEqual($result, 0);
return $result;
}
/**
* @depends testProductCreate
* The depends says test is run only if previous is ok
*/
public function testProductFetch($id)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Product($this->savdb);
$result=$localobject->fetch($id);
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0);
$result=$localobject->verify();
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertEquals($result, 0);
return $localobject;
}
/**
* @depends testProductFetch
* The depends says test is run only if previous is ok
*/
public function testProductUpdate($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject->note='New note after update';
$result=$localobject->update($localobject->id,$user);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $localobject;
}
/**
* @depends testProductUpdate
* The depends says test is run only if previous is ok
*/
public function testProductOther($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
return $localobject->id;
}
/**
* @depends testProductOther
* The depends says test is run only if previous is ok
*/
public function testProductDelete($id)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Product($this->savdb);
$result=$localobject->fetch($id);
$result=$localobject->delete($id);
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $result;
}
/**
*
*/
/*public function testVerifyNumRef()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Adherent($this->savdb);
$result=$localobject->ref='refthatdoesnotexists';
$result=$localobject->VerifyNumRef();
print __METHOD__." result=".$result."\n";
$this->assertEquals($result, 0);
return $result;
}*/
/**
*/
public function testProductStatic()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Product($db);
return;
}
}
?>