Missing extrafields management for order webservice

This commit is contained in:
jfefe 2014-11-27 12:56:10 +01:00
parent ab25b149c5
commit 1b35c5e77b

View File

@ -29,6 +29,7 @@ set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
require_once '../master.inc.php'; require_once '../master.inc.php';
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
require_once DOL_DOCUMENT_ROOT.'/core/lib/ws.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/ws.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php");
@ -84,14 +85,7 @@ $server->wsdl->addComplexType(
) )
); );
// Define other specific objects $line_fields = array(
$server->wsdl->addComplexType(
'line',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name'=>'id','type'=>'xsd:string'), 'id' => array('name'=>'id','type'=>'xsd:string'),
'type' => array('name'=>'type','type'=>'xsd:int'), 'type' => array('name'=>'type','type'=>'xsd:int'),
'fk_commande' => array('name'=>'fk_commande','type'=>'xsd:int'), 'fk_commande' => array('name'=>'fk_commande','type'=>'xsd:int'),
@ -117,7 +111,34 @@ $server->wsdl->addComplexType(
'product_ref' => array('name'=>'product_ref','type'=>'xsd:string'), 'product_ref' => array('name'=>'product_ref','type'=>'xsd:string'),
'product_label' => array('name'=>'product_label','type'=>'xsd:string'), 'product_label' => array('name'=>'product_label','type'=>'xsd:string'),
'product_desc' => array('name'=>'product_desc','type'=>'xsd:string') 'product_desc' => array('name'=>'product_desc','type'=>'xsd:string')
) );
//Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels
$extrafields=new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('commandedet',true);
if (count($extrafields)>0) {
$extrafield_line_array = array();
}
foreach($extrafields->attribute_label as $key=>$label)
{
//$value=$object->array_options["options_".$key];
$type =$extrafields->attribute_type[$key];
if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';}
else {$type='xsd:string';}
$extrafield_line_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type);
}
$line_fields=array_merge($line_fields,$extrafield_line_array);
// Define other specific objects
$server->wsdl->addComplexType(
'line',
'complexType',
'struct',
'all',
'',
$line_fields
); );
/*$server->wsdl->addComplexType( /*$server->wsdl->addComplexType(
@ -151,13 +172,7 @@ $server->wsdl->addComplexType(
) )
); );
$server->wsdl->addComplexType( $order_fields = array(
'order',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name'=>'id','type'=>'xsd:string'), 'id' => array('name'=>'id','type'=>'xsd:string'),
'ref' => array('name'=>'ref','type'=>'xsd:string'), 'ref' => array('name'=>'ref','type'=>'xsd:string'),
'ref_client' => array('name'=>'ref_client','type'=>'xsd:string'), 'ref_client' => array('name'=>'ref_client','type'=>'xsd:string'),
@ -196,8 +211,34 @@ $server->wsdl->addComplexType(
'demand_reason_id' => array('name'=>'demand_reason_id','type'=>'xsd:string'), 'demand_reason_id' => array('name'=>'demand_reason_id','type'=>'xsd:string'),
'lines' => array('name'=>'lines','type'=>'tns:LinesArray2') 'lines' => array('name'=>'lines','type'=>'tns:LinesArray2')
)
); );
//Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels
$extrafields=new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('commande',true);
if (count($extrafields)>0) {
$extrafield_array = array();
}
foreach($extrafields->attribute_label as $key=>$label)
{
//$value=$object->array_options["options_".$key];
$type =$extrafields->attribute_type[$key];
if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';}
else {$type='xsd:string';}
$extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type);
}
$order_fields=array_merge($order_fields,$extrafield_array);
$server->wsdl->addComplexType(
'order',
'complexType',
'struct',
'all',
'',
$order_fields
);
/* /*
$server->wsdl->addComplexType( $server->wsdl->addComplexType(
'OrdersArray', 'OrdersArray',
@ -644,6 +685,16 @@ function createOrder($authentication,$order)
$newobject->demand_reason_id=$order['demand_reason_id']; $newobject->demand_reason_id=$order['demand_reason_id'];
$newobject->date_creation=$now; $newobject->date_creation=$now;
// Retrieve all extrafield for order
// fetch optionals attributes and labels
$extrafields=new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('commandet',true);
foreach($extrafields->attribute_label as $key=>$label)
{
$key='options_'.$key;
$newobject->array_options[$key]=$order[$key];
}
// Trick because nusoap does not store data with same structure if there is one or several lines // Trick because nusoap does not store data with same structure if there is one or several lines
$arrayoflines=array(); $arrayoflines=array();
if (isset($order['lines']['line'][0])) $arrayoflines=$order['lines']['line']; if (isset($order['lines']['line'][0])) $arrayoflines=$order['lines']['line'];
@ -666,6 +717,17 @@ function createOrder($authentication,$order)
$newline->total_ttc=$line['total']; $newline->total_ttc=$line['total'];
$newline->date_start=$line['date_start']; $newline->date_start=$line['date_start'];
$newline->date_end=$line['date_end']; $newline->date_end=$line['date_end'];
// Retrieve all extrafield for lines
// fetch optionals attributes and labels
$extrafields=new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('commandedet',true);
foreach($extrafields->attribute_label as $key=>$label)
{
$key='options_'.$key;
$newline->array_options[$key]=$line[$key];
}
$newobject->lines[]=$newline; $newobject->lines[]=$newline;
} }