Merge pull request #2784 from aaujon/3.7-webservices-fix
various fixes on webservices
This commit is contained in:
commit
1e0218bb9b
@ -272,7 +272,7 @@ function getContact($authentication,$id,$ref_ext)
|
||||
){
|
||||
$contact_result_fields =array(
|
||||
'id' => $contact->id,
|
||||
'ref_ext' => $contact->ref_ext,
|
||||
'ref_ext' => $contact->ref_ext,
|
||||
'lastname' => $contact->lastname,
|
||||
'firstname' => $contact->firstname,
|
||||
'address' => $contact->address,
|
||||
@ -334,7 +334,7 @@ function getContact($authentication,$id,$ref_ext)
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
$errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,9 +615,15 @@ function updateContact($authentication,$contact)
|
||||
$error=0;
|
||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||
// Check parameters
|
||||
if (empty($contact['id'])) {
|
||||
$error++; $errorcode='KO'; $errorlabel="Contact id is mandatory.";
|
||||
if (empty($contact['id']) && empty($contact['ref_ext'])) {
|
||||
$error++; $errorcode='KO'; $errorlabel="Contact id or ref_ext is mandatory.";
|
||||
}
|
||||
// Check parameters
|
||||
if (! $error && ($id && $ref_ext))
|
||||
{
|
||||
$error++;
|
||||
$errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id and ref_ext can't be all provided. You must choose one of them.";
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
@ -626,7 +632,7 @@ function updateContact($authentication,$contact)
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
|
||||
$object=new Contact($db);
|
||||
$result=$object->fetch($contact['id']);
|
||||
$result=$object->fetch($contact['id'],0,$contact['ref_ext']);
|
||||
|
||||
if (!empty($object->id)) {
|
||||
|
||||
|
||||
@ -102,7 +102,6 @@ $server->wsdl->addComplexType(
|
||||
'total' => array('name'=>'total','type'=>'xsd:double'),
|
||||
'date_start' => array('name'=>'date_start','type'=>'xsd:date'),
|
||||
'date_end' => array('name'=>'date_end','type'=>'xsd:date'),
|
||||
'payment_mode_id' => array('name'=>'payment_mode_id','type'=>'xsd:string'),
|
||||
// From product
|
||||
'product_id' => array('name'=>'product_id','type'=>'xsd:int'),
|
||||
'product_ref' => array('name'=>'product_ref','type'=>'xsd:string'),
|
||||
@ -160,6 +159,7 @@ $server->wsdl->addComplexType(
|
||||
'date_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'),
|
||||
'date_validation' => array('name'=>'date_validation','type'=>'xsd:dateTime'),
|
||||
'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'),
|
||||
'payment_mode_id' => array('name'=>'payment_mode_id','type'=>'xsd:string'),
|
||||
'type' => array('name'=>'type','type'=>'xsd:int'),
|
||||
'total_net' => array('name'=>'type','type'=>'xsd:double'),
|
||||
'total_vat' => array('name'=>'type','type'=>'xsd:double'),
|
||||
@ -243,13 +243,37 @@ $server->register(
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string'),
|
||||
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#createInvoice',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to create an invoice'
|
||||
);
|
||||
$server->register(
|
||||
'createInvoiceFromOrder',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','invoice'=>'tns:invoice'),
|
||||
$ns,
|
||||
$ns.'#createInvoiceFromOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to create an invoice from an order'
|
||||
);
|
||||
$server->register(
|
||||
'updateInvoice',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#updateInvoice',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to update an invoice'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
@ -299,15 +323,19 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='')
|
||||
$linesresp[]=array(
|
||||
'id'=>$line->rowid,
|
||||
'type'=>$line->product_type,
|
||||
'desc'=>dol_htmlcleanlastbr($line->desc),
|
||||
'total_net'=>$line->total_ht,
|
||||
'total_vat'=>$line->total_tva,
|
||||
'total'=>$line->total_ttc,
|
||||
'vat_rate'=>$line->tva_tx,
|
||||
'qty'=>$line->qty,
|
||||
'product_ref'=>$line->product_ref,
|
||||
'product_label'=>$line->product_label,
|
||||
'product_desc'=>$line->product_desc,
|
||||
'desc'=>dol_htmlcleanlastbr($line->desc),
|
||||
'total_net'=>$line->total_ht,
|
||||
'total_vat'=>$line->total_tva,
|
||||
'total'=>$line->total_ttc,
|
||||
'vat_rate'=>$line->tva_tx,
|
||||
'qty'=>$line->qty,
|
||||
'unitprice'=> $line->subprice,
|
||||
'date_start'=> $line->date_start?dol_print_date($line->date_start,'dayrfc'):'',
|
||||
'date_end'=> $line->date_end?dol_print_date($line->date_end,'dayrfc'):'',
|
||||
'product_id'=>$line->fk_product,
|
||||
'product_ref'=>$line->product_ref,
|
||||
'product_label'=>$line->product_label,
|
||||
'product_desc'=>$line->product_desc,
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
@ -319,9 +347,11 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='')
|
||||
'id' => $invoice->id,
|
||||
'ref' => $invoice->ref,
|
||||
'ref_ext' => $invoice->ref_ext?$invoice->ref_ext:'', // If not defined, field is not added into soap
|
||||
'thirdparty_id' => $invoice->socid,
|
||||
'fk_user_author' => $invoice->user_author?$invoice->user_author:'',
|
||||
'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'',
|
||||
'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'',
|
||||
'date_due' => $invoice->date_lim_reglement?dol_print_date($invoice->date_lim_reglement,'dayrfc'):'',
|
||||
'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'',
|
||||
'date_validation' => $invoice->date_validation?dol_print_date($invoice->date_creation,'dayhourrfc'):'',
|
||||
'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'dayhourrfc'):'',
|
||||
@ -331,7 +361,8 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='')
|
||||
'total' => $invoice->total_ttc,
|
||||
'note_private' => $invoice->note_private?$invoice->note_private:'',
|
||||
'note_public' => $invoice->note_public?$invoice->note_public:'',
|
||||
'status'=> $invoice->statut,
|
||||
'status' => $invoice->statut,
|
||||
'project_id' => $invoic->fk_project,
|
||||
'close_code' => $invoice->close_code?$invoice->close_code:'',
|
||||
'close_note' => $invoice->close_note?$invoice->close_note:'',
|
||||
'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'',
|
||||
@ -387,7 +418,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
|
||||
if (! $error && empty($idthirdparty))
|
||||
{
|
||||
$error++;
|
||||
$errorcode='BAD_PARAMETERS'; $errorlabel='Parameter id is not provided';
|
||||
$errorcode='BAD_PARAMETERS'; $errorlabel='Parameter idthirdparty is not provided';
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
@ -433,6 +464,10 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
|
||||
'total'=>$line->total_ttc,
|
||||
'vat_rate'=>$line->tva_tx,
|
||||
'qty'=>$line->qty,
|
||||
'unitprice'=> $line->subprice,
|
||||
'date_start'=> $line->date_start?dol_print_date($line->date_start,'dayrfc'):'',
|
||||
'date_end'=> $line->date_end?dol_print_date($line->date_end,'dayrfc'):'',
|
||||
'product_id'=>$line->fk_product,
|
||||
'product_ref'=>$line->product_ref,
|
||||
'product_label'=>$line->product_label,
|
||||
'product_desc'=>$line->product_desc,
|
||||
@ -448,7 +483,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
|
||||
'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'',
|
||||
'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'',
|
||||
'date_due' => $invoice->date_lim_reglement?dol_print_date($invoice->date_lim_reglement,'dayrfc'):'',
|
||||
'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'',
|
||||
'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'',
|
||||
'date_validation' => $invoice->date_validation?dol_print_date($invoice->date_creation,'dayhourrfc'):'',
|
||||
'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'dayhourrfc'):'',
|
||||
'type' => $invoice->type,
|
||||
@ -458,9 +493,10 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
|
||||
'note_private' => $invoice->note_private?$invoice->note_private:'',
|
||||
'note_public' => $invoice->note_public?$invoice->note_public:'',
|
||||
'status'=> $invoice->statut,
|
||||
'project_id' => $invoic->fk_project,
|
||||
'close_code' => $invoice->close_code?$invoice->close_code:'',
|
||||
'close_note' => $invoice->close_note?$invoice->close_note:'',
|
||||
'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'',
|
||||
'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'',
|
||||
'lines' => $linesresp
|
||||
);
|
||||
}
|
||||
@ -503,7 +539,8 @@ function createInvoice($authentication,$invoice)
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
dol_syslog("Function: createInvoiceForThirdParty login=".$authentication['login']);
|
||||
dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice->id.
|
||||
", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||
|
||||
@ -513,27 +550,32 @@ function createInvoice($authentication,$invoice)
|
||||
$error=0;
|
||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||
|
||||
// Check parameters
|
||||
if (empty($invoice['id']) && empty($invoice['ref']) && empty($invoice['ref_ext'])) {
|
||||
$error++; $errorcode='KO'; $errorlabel="Invoice id or ref or ref_ext is mandatory.";
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$newobject=new Facture($db);
|
||||
$newobject->socid=$invoice['thirdparty_id'];
|
||||
$newobject->type=$invoice['type'];
|
||||
$newobject->ref_ext=$invoice['ref_ext'];
|
||||
$newobject->date=dol_stringtotime($invoice['date'],'dayrfc');
|
||||
$newobject->note_private=$invoice['note_private'];
|
||||
$newobject->note_public=$invoice['note_public'];
|
||||
$newobject->statut= Facture::STATUS_DRAFT; // We start with status draft
|
||||
$newobject->fk_project=$invoice['project_id'];
|
||||
$newobject->date_creation=$now;
|
||||
$new_invoice=new Facture($db);
|
||||
$new_invoice->socid=$invoice['thirdparty_id'];
|
||||
$new_invoice->type=$invoice['type'];
|
||||
$new_invoice->ref_ext=$invoice['ref_ext'];
|
||||
$new_invoice->date=dol_stringtotime($invoice['date'],'dayrfc');
|
||||
$new_invoice->note_private=$invoice['note_private'];
|
||||
$new_invoice->note_public=$invoice['note_public'];
|
||||
$new_invoice->statut= Facture::STATUS_DRAFT; // We start with status draft
|
||||
$new_invoice->fk_project=$invoice['project_id'];
|
||||
$new_invoice->date_creation=$now;
|
||||
|
||||
//take mode_reglement and cond_reglement from thirdparty
|
||||
$soc = new Societe($db);
|
||||
$res=$soc->fetch($newobject->socid);
|
||||
$res=$soc->fetch($new_invoice->socid);
|
||||
if ($res > 0) {
|
||||
$newobject->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id;
|
||||
$newobject->cond_reglement_id = $soc->cond_reglement_id;
|
||||
$new_invoice->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id;
|
||||
$new_invoice->cond_reglement_id = $soc->cond_reglement_id;
|
||||
}
|
||||
else $newobject->mode_reglement_id = $invoice['payment_mode_id'];
|
||||
else $new_invoice->mode_reglement_id = $invoice['payment_mode_id'];
|
||||
|
||||
// Trick because nusoap does not store data with same structure if there is one or several lines
|
||||
$arrayoflines=array();
|
||||
@ -556,22 +598,22 @@ function createInvoice($authentication,$invoice)
|
||||
$newline->date_start=dol_stringtotime($line['date_start']);
|
||||
$newline->date_end=dol_stringtotime($line['date_end']);
|
||||
$newline->fk_product=$line['product_id'];
|
||||
$newobject->lines[]=$newline;
|
||||
$new_invoice->lines[]=$newline;
|
||||
}
|
||||
//var_dump($newobject->date_lim_reglement); exit;
|
||||
//var_dump($invoice['lines'][0]['type']);
|
||||
|
||||
$db->begin();
|
||||
|
||||
$result=$newobject->create($fuser,0,dol_stringtotime($invoice['date_due'],'dayrfc'));
|
||||
$result=$new_invoice->create($fuser,0,dol_stringtotime($invoice['date_due'],'dayrfc'));
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
|
||||
if ($invoice['status'] == 1) // We want invoice to have status validated
|
||||
if (!$error && $invoice['status'] == Facture::STATUS_VALIDATED) // We want invoice to have status validated
|
||||
{
|
||||
$result=$newobject->validate($fuser);
|
||||
$result=$new_invoice->validate($fuser);
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
@ -581,14 +623,16 @@ function createInvoice($authentication,$invoice)
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref);
|
||||
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$new_invoice->id,
|
||||
'ref'=>$new_invoice->ref,'ref_ext'=>$new_invoice->ref_ext);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode='KO';
|
||||
$errorlabel=$newobject->error;
|
||||
$errorlabel=$new_invoice->error;
|
||||
dol_syslog("Function: createInvoice error while creating".$errorlabel);
|
||||
}
|
||||
|
||||
}
|
||||
@ -601,5 +645,197 @@ function createInvoice($authentication,$invoice)
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an invoice from an order
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param string $id_order id of order to copy invoice from
|
||||
* @param string $ref_order ref of order to copy invoice from
|
||||
* @param string $ref_ext_order ref_ext of order to copy invoice from
|
||||
* @param string $id_invoice invoice id
|
||||
* @param string $ref_invoice invoice ref
|
||||
* @param string $ref_ext_invoice invoice ref_ext
|
||||
* @return array Array result
|
||||
*/
|
||||
function createInvoiceFromOrder($authentication,$id_order='', $ref_order='', $ref_ext_order='',
|
||||
$id_invoice='', $ref_invoice='', $ref_ext_invoice='')
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order.
|
||||
", ref=".$ref_order.", ref_ext=".$ref_ext_order);
|
||||
|
||||
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($id_order) && empty($ref_order) && empty($ref_ext_order)) {
|
||||
$error++; $errorcode='KO'; $errorlabel="order id or ref or ref_ext is mandatory.";
|
||||
} else if (empty($id_invoice) && empty($ref_invoice) && empty($ref_ext_invoice)) {
|
||||
$error++; $errorcode='KO'; $errorlabel="invoice id or ref or ref_ext is mandatory.";
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
if (! $error)
|
||||
{
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->commande->lire)
|
||||
{
|
||||
$order=new Commande($db);
|
||||
$result=$order->fetch($id,$ref,$ref_ext);
|
||||
if ($result > 0)
|
||||
{
|
||||
// Security for external user
|
||||
if( $socid && ( $socid != $order->socid) )
|
||||
{
|
||||
$error++;
|
||||
$errorcode='PERMISSION_DENIED'; $errorlabel=$order->socid.'User does not have permission for this request';
|
||||
}
|
||||
|
||||
if(!$error)
|
||||
{
|
||||
|
||||
$newobject=new Facture($db);
|
||||
$result = $newobject->createFromOrder($order);
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
dol_syslog("Webservice server_invoice:: invoice creation from order failed", LOG_ERR);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id_order.' nor ref='.$ref_order.' nor ref_ext='.$ref_ext_order;
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''),'invoice'=>$newobject);
|
||||
|
||||
}
|
||||
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uddate an invoice, only change the state of an invoice
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param Facture $invoice Invoice
|
||||
* @return array Array result
|
||||
*/
|
||||
function updateInvoice($authentication,$invoice)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice['id'].
|
||||
", ref=".$invoice['ref'].", ref_ext=".$invoice['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 (empty($invoice['id']) && empty($invoice['ref']) && empty($invoice['ref_ext'])) {
|
||||
$error++; $errorcode='KO'; $errorlabel="Invoice id or ref or ref_ext is mandatory.";
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$objectfound=false;
|
||||
|
||||
$object=new Facture($db);
|
||||
$result=$object->fetch($invoice['id'],$invoice['ref'],$invoice['ref_ext'], '');
|
||||
|
||||
if (!empty($object->id)) {
|
||||
|
||||
$objectfound=true;
|
||||
|
||||
$db->begin();
|
||||
|
||||
if (isset($invoice['status']))
|
||||
{
|
||||
if ($invoice['status'] == Facture::STATUS_DRAFT)
|
||||
{
|
||||
$result = $object->set_draft($fuser);
|
||||
}
|
||||
if ($invoice['status'] == Facture::STATUS_VALIDATED)
|
||||
{
|
||||
$result = $object->validate($fuser);
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$order->generateDocument($invoice->modelpdf, $outputlangs);
|
||||
}
|
||||
}
|
||||
if ($invoice['status'] == Facture::STATUS_CLOSED)
|
||||
{
|
||||
$result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note);
|
||||
}
|
||||
if ($invoice['status'] == Facture::STATUS_ABANDONED)
|
||||
$result = $object->set_canceled($fuser,$invoice->close_code,$invoice->close_note);
|
||||
}
|
||||
}
|
||||
|
||||
if ((! $error) && ($objectfound))
|
||||
{
|
||||
$db->commit();
|
||||
$objectresp=array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'id'=>$object->id,
|
||||
'ref'=>$object->ref,
|
||||
'ref_ext'=>$object->ref_ext
|
||||
);
|
||||
}
|
||||
elseif ($objectfound)
|
||||
{
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode='KO';
|
||||
$errorlabel=$object->error;
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode='NOT_FOUND';
|
||||
$errorlabel='Invoice id='.$invoice['id'].' ref='.$invoice['ref'].' ref_ext='.$invoice['ref_ext'].' cannot be found';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
// Return the results.
|
||||
$server->service(file_get_contents("php://input"));
|
||||
|
||||
@ -917,7 +917,17 @@ function updateOrder($authentication,$order)
|
||||
if (isset($order['status']))
|
||||
{
|
||||
if ($order['status'] == -1) $result=$object->cancel($fuser);
|
||||
if ($order['status'] == 1) $result=$object->valid($fuser);
|
||||
if ($order['status'] == 1)
|
||||
{
|
||||
$result=$object->valid($fuser);
|
||||
if ($result >= 0)
|
||||
{
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$order->generateDocument($order->modelpdf, $outputlangs);
|
||||
|
||||
}
|
||||
}
|
||||
if ($order['status'] == 0) $result=$object->set_reopen($fuser);
|
||||
if ($order['status'] == 3) $result=$object->cloture($fuser);
|
||||
}
|
||||
@ -951,7 +961,9 @@ function updateOrder($authentication,$order)
|
||||
$db->commit();
|
||||
$objectresp=array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'id'=>$object->id
|
||||
'id'=>$object->id,
|
||||
'ref'=>$object->ref,
|
||||
'ref_ext'=>$object->ref_ext
|
||||
);
|
||||
}
|
||||
elseif ($objectfound)
|
||||
|
||||
@ -258,8 +258,31 @@ $server->register(
|
||||
'WS to get list of thirdparties id and ref'
|
||||
);
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'deleteThirdParty',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','id'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#deleteThirdParty',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to delete a thirdparty from its id, ref or ref_ext'
|
||||
);
|
||||
|
||||
|
||||
// Full methods code
|
||||
/**
|
||||
* Get a thirdparty
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param string $id internal id
|
||||
* @param string $ref internal reference
|
||||
* @param string $ref_ext external reference
|
||||
* @return array Array result
|
||||
*/
|
||||
function getThirdParty($authentication,$id='',$ref='',$ref_ext='')
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
@ -728,5 +751,88 @@ function getListOfThirdParties($authentication,$filterthirdparty)
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a thirdparty
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param string $id internal id
|
||||
* @param string $ref internal reference
|
||||
* @param string $ref_ext external reference
|
||||
* @return array Array result
|
||||
*/
|
||||
function deleteThirdParty($authentication,$id='',$ref='',$ref_ext='')
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
dol_syslog("Function: deleteThirdParty 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)))
|
||||
{
|
||||
dol_syslog("Function: deleteThirdParty checkparam");
|
||||
$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.";
|
||||
}
|
||||
dol_syslog("Function: deleteThirdParty 1");
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->societe->lire && $fuser->rights->societe->supprimer)
|
||||
{
|
||||
$thirdparty=new Societe($db);
|
||||
$result=$thirdparty->fetch($id,$ref,$ref_ext);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
$result=$thirdparty->delete($thirdparty->id, $fuser);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$db->commit();
|
||||
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''));
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode='KO';
|
||||
$errorlabel=$thirdparty->error;
|
||||
dol_syslog("Function: deleteThirdParty cant delete");
|
||||
}
|
||||
}
|
||||
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(file_get_contents("php://input"));
|
||||
|
||||
@ -18,9 +18,9 @@
|
||||
|
||||
/**
|
||||
* \file test/phpunit/WebservicesInvoicesTest.php
|
||||
* \ingroup test
|
||||
* \ingroup test
|
||||
* \brief PHPUnit test
|
||||
* \remarks To run this script as CLI: phpunit filename.php
|
||||
* \remarks To run this script as CLI: phpunit filename.php
|
||||
*/
|
||||
|
||||
global $conf,$user,$langs,$db;
|
||||
@ -31,10 +31,11 @@ require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php';
|
||||
require_once(NUSOAP_PATH.'/nusoap.php'); // Include SOAP
|
||||
|
||||
|
||||
if (empty($user->id)) {
|
||||
print "Load permissions for admin user nb 1\n";
|
||||
$user->fetch(1);
|
||||
$user->getrights();
|
||||
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;
|
||||
|
||||
@ -44,138 +45,369 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
||||
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
||||
*/
|
||||
class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $savconf;
|
||||
protected $savuser;
|
||||
protected $savlangs;
|
||||
protected $savdb;
|
||||
protected $savconf;
|
||||
protected $savuser;
|
||||
protected $savlangs;
|
||||
protected $savdb;
|
||||
protected $soapclient;
|
||||
protected $socid;
|
||||
|
||||
protected $ns = 'http://www.dolibarr.org/ns/';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* We save global variables into local variables
|
||||
*
|
||||
* @return DateLibTest
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
//$this->sharedFixture
|
||||
global $conf,$user,$langs,$db;
|
||||
$this->savconf=$conf;
|
||||
$this->savuser=$user;
|
||||
$this->savlangs=$langs;
|
||||
$this->savdb=$db;
|
||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
||||
|
||||
|
||||
// Set the WebService URL
|
||||
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
|
||||
$this->soapclient = new nusoap_client($WS_DOL_URL);
|
||||
if ($this->soapclient)
|
||||
{
|
||||
$this->soapclient->soap_defencoding='UTF-8';
|
||||
$this->soapclient->decodeUTF8(false);
|
||||
}
|
||||
|
||||
// create a third_party, needed to create an invoice
|
||||
$societe=new Societe($db);
|
||||
$societe->ref='';
|
||||
$societe->name='name';
|
||||
$societe->ref_ext='209';
|
||||
$societe->status=1;
|
||||
$societe->client=1;
|
||||
$societe->fournisseur=0;
|
||||
$societe->date_creation=$now;
|
||||
$societe->tva_assuj=0;
|
||||
$societe->particulier=0;
|
||||
|
||||
$societe->create($user);
|
||||
|
||||
$this->socid = $societe->id;
|
||||
|
||||
print __METHOD__." societe created id=".$societe->id."\n";
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* We save global variables into local variables
|
||||
*
|
||||
* @return DateLibTest
|
||||
*/
|
||||
function __construct()
|
||||
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||
//print " - db ".$db->db;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
// Static methods
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
//$this->sharedFixture
|
||||
global $conf,$user,$langs,$db;
|
||||
$this->savconf=$conf;
|
||||
$this->savuser=$user;
|
||||
$this->savlangs=$langs;
|
||||
$this->savdb=$db;
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
|
||||
|
||||
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||
//print " - db ".$db->db;
|
||||
print "\n";
|
||||
print __METHOD__."\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";
|
||||
}
|
||||
|
||||
// tear down after class
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->rollback();
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->rollback();
|
||||
|
||||
print __METHOD__."\n";
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Init phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* Init phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
print __METHOD__."\n";
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
print __METHOD__."\n";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* End phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* End phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
print __METHOD__."\n";
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* testWSInvoicesXxx
|
||||
* testWSInvoicesCreateInvoice
|
||||
*
|
||||
* @return int
|
||||
* @return int invoice created
|
||||
*/
|
||||
public function testWSInvoicesXxx()
|
||||
public function testWSInvoicesCreateInvoice()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
||||
$WS_METHOD = 'getInvoice';
|
||||
$ns='http://www.dolibarr.org/ns/';
|
||||
$WS_METHOD = 'createInvoice';
|
||||
|
||||
// Set the WebService URL
|
||||
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
|
||||
$soapclient = new nusoap_client($WS_DOL_URL);
|
||||
if ($soapclient) {
|
||||
$soapclient->soap_defencoding='UTF-8';
|
||||
$soapclient->decodeUTF8(false);
|
||||
}
|
||||
// load societe first
|
||||
$societe=new Societe($db);
|
||||
$societe->fetch('', '', '209');
|
||||
print __METHOD__." societe loaded id=".$societe->id."\n";
|
||||
|
||||
|
||||
$body = array (
|
||||
"id" => NULL,
|
||||
"ref" => NULL,
|
||||
"ref_ext" => "165",
|
||||
"thirdparty_id" => $societe->id,
|
||||
"fk_user_author" => NULL,
|
||||
"fk_user_valid" => NULL,
|
||||
"date" => "2015-04-19 20:16:53",
|
||||
"date_due" => "",
|
||||
"date_creation" => "",
|
||||
"date_validation" => "",
|
||||
"date_modification" => "",
|
||||
"type" => "",
|
||||
"total_net" => "36.30",
|
||||
"total_vat" => "6.00",
|
||||
"total" => "42.30",
|
||||
"payment_mode_id" => 50,
|
||||
"note_private" => "Synchronised from Prestashop",
|
||||
"note_public" => "",
|
||||
"status" => "1",
|
||||
"close_code" => NULL ,
|
||||
"close_note" => NULL,
|
||||
"project_id" => NULL,
|
||||
"lines" => array(
|
||||
array("id" => NULL,
|
||||
"type" => 0,
|
||||
"desc" => "Horloge Vinyle Serge",
|
||||
"vat_rate" => 20,
|
||||
"qty" => 1,
|
||||
"unitprice" => "30.000000",
|
||||
"total_net" => "30.000000",
|
||||
"total_vat" => "6.00",
|
||||
"total" => "36.000000",
|
||||
"date_start" => "",
|
||||
"date_end" => "",
|
||||
"payment_mode_id" => "",
|
||||
"product_id" => "",
|
||||
"product_ref" => "",
|
||||
"product_label" => "",
|
||||
"product_desc" => "" ))
|
||||
);
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||
'sourceapplication'=>'DEMO',
|
||||
'login'=>'admin',
|
||||
'password'=>'admin',
|
||||
'entity'=>''
|
||||
);
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||
'sourceapplication'=>'DEMO',
|
||||
'login'=>'admin',
|
||||
'password'=>'admin',
|
||||
'entity'=>'');
|
||||
|
||||
// Test URL
|
||||
$result='';
|
||||
$parameters = array('authentication'=>$authentication,'id'=>1);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
|
||||
} catch(SoapFault $exception) {
|
||||
echo $exception;
|
||||
$result=0;
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring'])) {
|
||||
//var_dump($soapclient);
|
||||
print $soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
// Test URL
|
||||
$result='';
|
||||
$parameters = array('authentication'=>$authentication,'invoice'=>$body);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
|
||||
}
|
||||
catch(SoapFault $exception)
|
||||
{
|
||||
echo $exception;
|
||||
$result=0;
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring']))
|
||||
{
|
||||
//var_dump($soapclient);
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
print __METHOD__." result=".$result['result']['result_code']."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
$this->assertEquals('165', $result['ref_ext']);
|
||||
|
||||
return $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testWSInvoicesGetInvoiceByRefExt
|
||||
*
|
||||
* Retrieve an invoice using ref_ext
|
||||
* @depends testWSInvoicesCreateInvoice
|
||||
*
|
||||
* @param array $result Invoice created by create method
|
||||
* @return array Invoice
|
||||
*/
|
||||
public function testWSInvoicesGetInvoiceByRefExt($result)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$WS_METHOD = 'getInvoice';
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||
'sourceapplication'=>'DEMO',
|
||||
'login'=>'admin',
|
||||
'password'=>'admin',
|
||||
'entity'=>'');
|
||||
|
||||
// Test URL
|
||||
$result='';
|
||||
$parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
|
||||
}
|
||||
catch(SoapFault $exception)
|
||||
{
|
||||
echo $exception;
|
||||
$result=0;
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring']))
|
||||
{
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
print __METHOD__." result=".$result['result']['result_code']."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
$this->assertEquals('165', $result['invoice']['ref_ext']);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testWSInvoicesUpdateInvoiceByRefExt
|
||||
*
|
||||
* Update an invoice using ref_ext
|
||||
* @depends testWSInvoicesCreateInvoice
|
||||
*
|
||||
* @param array $result invoice created by create method
|
||||
* @return array Invoice
|
||||
*/
|
||||
public function testWSInvoicesUpdateInvoiceByRefExt($result)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$WS_METHOD = 'updateInvoice';
|
||||
|
||||
// update status to 2
|
||||
$body = array (
|
||||
"id" => NULL,
|
||||
"ref" => NULL,
|
||||
"ref_ext" => "165",
|
||||
"thirdparty_id" => "209",
|
||||
"fk_user_author" => NULL,
|
||||
"fk_user_valid" => NULL,
|
||||
"date" => "2015-04-19 20:16:53",
|
||||
"date_due" => "",
|
||||
"date_creation" => "",
|
||||
"date_validation" => "",
|
||||
"date_modification" => "",
|
||||
"type" => "",
|
||||
"total_net" => "36.30",
|
||||
"total_vat" => "6.00",
|
||||
"total" => "42.30",
|
||||
"payment_mode_id" => 50,
|
||||
"note_private" => "Synchronised from Prestashop",
|
||||
"note_public" => "",
|
||||
"status" => "2",
|
||||
"close_code" => NULL ,
|
||||
"close_note" => NULL,
|
||||
"project_id" => NULL,
|
||||
"lines" => array(
|
||||
array(
|
||||
"id" => NULL,
|
||||
"type" => 0,
|
||||
"desc" => "Horloge Vinyle Serge",
|
||||
"vat_rate" => 20,
|
||||
"qty" => "1",
|
||||
"unitprice" => "30.000000",
|
||||
"total_net" => "30.000000",
|
||||
"total_vat" => "6.00",
|
||||
"total" => "36.000000",
|
||||
"date_start" => "",
|
||||
"date_end" => "",
|
||||
"payment_mode_id" => "",
|
||||
"product_id" => "",
|
||||
"product_ref" => "",
|
||||
"product_label" => "",
|
||||
"product_desc" => "" ))
|
||||
);
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||
'sourceapplication'=>'DEMO',
|
||||
'login'=>'admin',
|
||||
'password'=>'admin',
|
||||
'entity'=>'');
|
||||
|
||||
// Test URL
|
||||
$result='';
|
||||
$parameters = array('authentication'=>$authentication,'invoice'=>$body);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
|
||||
}
|
||||
catch(SoapFault $exception)
|
||||
{
|
||||
echo $exception;
|
||||
$result=0;
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring']))
|
||||
{
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
print __METHOD__." result=".$result['result']['result_code'].$result['result']['result_label']."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
$this->assertEquals('165', $result['ref_ext']);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -52,6 +52,13 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
|
||||
protected $savuser;
|
||||
protected $savlangs;
|
||||
protected $savdb;
|
||||
protected $soapclient;
|
||||
|
||||
private $_WS_DOL_URL;
|
||||
private $_ns='http://www.dolibarr.org/ns/';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
|
||||
$this->savuser=$user;
|
||||
$this->savlangs=$langs;
|
||||
$this->savdb=$db;
|
||||
|
||||
$this->_WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
|
||||
|
||||
// Set the WebService URL
|
||||
print __METHOD__." create nusoap_client for URL=".$this->_WS_DOL_URL."\n";
|
||||
$this->soapclient = new nusoap_client($this->_WS_DOL_URL);
|
||||
if ($this->soapclient) {
|
||||
$this->soapclient->soap_defencoding='UTF-8';
|
||||
$this->soapclient->decodeUTF8(false);
|
||||
}
|
||||
|
||||
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||
//print " - db ".$db->db;
|
||||
@ -117,31 +134,114 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* testWSThirdpartycreateThirdParty
|
||||
*
|
||||
* @return array thirdparty created
|
||||
*/
|
||||
public function testWSThirdpartycreateThirdParty()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$WS_METHOD = 'createThirdParty';
|
||||
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||
'sourceapplication'=>'DEMO',
|
||||
'login'=>'admin',
|
||||
'password'=>'admin',
|
||||
'entity'=>'');
|
||||
|
||||
$body = array (
|
||||
"id" => NULL,
|
||||
"ref" => "name",
|
||||
"ref_ext" => "12",
|
||||
"fk_user_author" => NULL,
|
||||
"status" => NULL,
|
||||
"client" => 1,
|
||||
"supplier" => 0,
|
||||
"customer_code" => "",
|
||||
"supplier_code" => "",
|
||||
"customer_code_accountancy" => "",
|
||||
"supplier_code_accountancy" => "",
|
||||
"date_creation" => "", // dateTime
|
||||
"date_modification" => "", // dateTime
|
||||
"note_private" => "",
|
||||
"note_public" => "",
|
||||
"address" => "",
|
||||
"zip" => "",
|
||||
"town" => "",
|
||||
"province_id" => "",
|
||||
"country_id" => "",
|
||||
"country_code" => "",
|
||||
"country" => "",
|
||||
"phone" => "",
|
||||
"fax" => "",
|
||||
"email" => "",
|
||||
"url" => "",
|
||||
"profid1" => "",
|
||||
"profid2" => "",
|
||||
"profid3" => "",
|
||||
"profid4" => "",
|
||||
"profid5" => "",
|
||||
"profid6" => "",
|
||||
"capital" => "",
|
||||
"vat_used" => "",
|
||||
"vat_number" => ""
|
||||
);
|
||||
|
||||
// Test URL
|
||||
$result='';
|
||||
$parameters = array('authentication'=>$authentication, 'thirdparty'=>$body);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$thid->ns,'');
|
||||
} catch(SoapFault $exception) {
|
||||
echo $exception;
|
||||
$result=0;
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring'])) {
|
||||
//var_dump($soapclient);
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
print __METHOD__." result=".$result['result']['result_code']."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
$this->assertEquals('name',$result['ref']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testWSThirdpartygetThirdParty
|
||||
*
|
||||
* @return int
|
||||
* testWSThirdpartygetThirdPartyById
|
||||
*
|
||||
* Use id to retrieve thirdparty
|
||||
* @depends testWSThirdpartycreateThirdParty
|
||||
*
|
||||
* @param array $result thirdparty created by create method
|
||||
* @return array thirpdarty updated
|
||||
*/
|
||||
public function testWSThirdpartygetThirdParty()
|
||||
public function testWSThirdpartygetThirdPartyById($result)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
$id = $result['id'];
|
||||
|
||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
|
||||
$WS_METHOD = 'getThirdParty';
|
||||
$ns='http://www.dolibarr.org/ns/';
|
||||
|
||||
// Set the WebService URL
|
||||
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
|
||||
$soapclient = new nusoap_client($WS_DOL_URL);
|
||||
if ($soapclient) {
|
||||
$soapclient->soap_defencoding='UTF-8';
|
||||
$soapclient->decodeUTF8(false);
|
||||
}
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
@ -151,30 +251,150 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
|
||||
'password'=>'admin',
|
||||
'entity'=>'');
|
||||
|
||||
// Test URL
|
||||
$result='';
|
||||
$parameters = array('authentication'=>$authentication, 'id'=>1);
|
||||
$parameters = array('authentication'=>$authentication, 'id'=>$id);
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,'');
|
||||
} catch(SoapFault $exception) {
|
||||
echo $exception;
|
||||
$result=0;
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring'])) {
|
||||
//var_dump($soapclient);
|
||||
print $soapclient->error_str;
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->request;
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $soapclient->response;
|
||||
print $this->soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
print __METHOD__." result=".$result."\n";
|
||||
print __METHOD__." result=".$result['result']['result_code']."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
|
||||
$this->assertEquals($id, $result['thirdparty']['id']);
|
||||
$this->assertEquals('name', $result['thirdparty']['ref']);
|
||||
$this->assertEquals('12', $result['thirdparty']['ref_ext']);
|
||||
$this->assertEquals('0', $result['thirdparty']['status']);
|
||||
$this->assertEquals('1', $result['thirdparty']['client']);
|
||||
$this->assertEquals('0', $result['thirdparty']['supplier']);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testWSThirdpartygetThirdPartyByRefExt
|
||||
*
|
||||
* Use ref_ext to retrieve thirdparty
|
||||
*
|
||||
* @depends testWSThirdpartycreateThirdParty
|
||||
*
|
||||
* @param array $result thirdparty created by create method
|
||||
* @return array thirdparty
|
||||
*/
|
||||
public function testWSThirdpartygetThirdPartyByRefExt($result)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
$id = $result['id'];
|
||||
|
||||
$WS_METHOD = 'getThirdParty';
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||
'sourceapplication'=>'DEMO',
|
||||
'login'=>'admin',
|
||||
'password'=>'admin',
|
||||
'entity'=>'');
|
||||
|
||||
// Test URL
|
||||
$result='';
|
||||
$parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12');
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,'');
|
||||
} catch(SoapFault $exception) {
|
||||
echo $exception;
|
||||
$result=0;
|
||||
}
|
||||
print $this->soapclient->response;
|
||||
if (! $result || ! empty($result['faultstring'])) {
|
||||
//var_dump($soapclient);
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
print __METHOD__." result=".$result['result']['result_code']."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
$this->assertEquals($id, $result['thirdparty']['id']);
|
||||
$this->assertEquals('name', $result['thirdparty']['ref']);
|
||||
$this->assertEquals('12', $result['thirdparty']['ref_ext']);
|
||||
$this->assertEquals('0', $result['thirdparty']['status']);
|
||||
$this->assertEquals('1', $result['thirdparty']['client']);
|
||||
$this->assertEquals('0', $result['thirdparty']['supplier']);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testWSThirdpartydeleteThirdParty
|
||||
*
|
||||
* @depends testWSThirdpartycreateThirdParty
|
||||
*
|
||||
* @param array $result thirdparty created by create method
|
||||
* @return array thirdparty
|
||||
*/
|
||||
public function testWSThirdpartydeleteThirdPartyById($result)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
$id = $result['id'];
|
||||
|
||||
$WS_METHOD = 'deleteThirdParty';
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||
'sourceapplication'=>'DEMO',
|
||||
'login'=>'admin',
|
||||
'password'=>'admin',
|
||||
'entity'=>'');
|
||||
|
||||
$result='';
|
||||
$parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>'');
|
||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||
try {
|
||||
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,'');
|
||||
} catch(SoapFault $exception) {
|
||||
echo $exception;
|
||||
$result=0;
|
||||
}
|
||||
if (! $result || ! empty($result['faultstring'])) {
|
||||
print $this->soapclient->error_str;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->request;
|
||||
print "\n<br>\n";
|
||||
print $this->soapclient->response;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
print __METHOD__." result=".$result['result']['result_code']."\n";
|
||||
$this->assertEquals('OK',$result['result']['result_code']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user