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(
|
$contact_result_fields =array(
|
||||||
'id' => $contact->id,
|
'id' => $contact->id,
|
||||||
'ref_ext' => $contact->ref_ext,
|
'ref_ext' => $contact->ref_ext,
|
||||||
'lastname' => $contact->lastname,
|
'lastname' => $contact->lastname,
|
||||||
'firstname' => $contact->firstname,
|
'firstname' => $contact->firstname,
|
||||||
'address' => $contact->address,
|
'address' => $contact->address,
|
||||||
@ -334,7 +334,7 @@ function getContact($authentication,$id,$ref_ext)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$error++;
|
$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;
|
$error=0;
|
||||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if (empty($contact['id'])) {
|
if (empty($contact['id']) && empty($contact['ref_ext'])) {
|
||||||
$error++; $errorcode='KO'; $errorlabel="Contact id is mandatory.";
|
$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)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@ -626,7 +632,7 @@ function updateContact($authentication,$contact)
|
|||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||||
|
|
||||||
$object=new Contact($db);
|
$object=new Contact($db);
|
||||||
$result=$object->fetch($contact['id']);
|
$result=$object->fetch($contact['id'],0,$contact['ref_ext']);
|
||||||
|
|
||||||
if (!empty($object->id)) {
|
if (!empty($object->id)) {
|
||||||
|
|
||||||
|
|||||||
@ -102,7 +102,6 @@ $server->wsdl->addComplexType(
|
|||||||
'total' => array('name'=>'total','type'=>'xsd:double'),
|
'total' => array('name'=>'total','type'=>'xsd:double'),
|
||||||
'date_start' => array('name'=>'date_start','type'=>'xsd:date'),
|
'date_start' => array('name'=>'date_start','type'=>'xsd:date'),
|
||||||
'date_end' => array('name'=>'date_end','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
|
// From product
|
||||||
'product_id' => array('name'=>'product_id','type'=>'xsd:int'),
|
'product_id' => array('name'=>'product_id','type'=>'xsd:int'),
|
||||||
'product_ref' => array('name'=>'product_ref','type'=>'xsd:string'),
|
'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_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'),
|
||||||
'date_validation' => array('name'=>'date_validation','type'=>'xsd:dateTime'),
|
'date_validation' => array('name'=>'date_validation','type'=>'xsd:dateTime'),
|
||||||
'date_modification' => array('name'=>'date_modification','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'),
|
'type' => array('name'=>'type','type'=>'xsd:int'),
|
||||||
'total_net' => array('name'=>'type','type'=>'xsd:double'),
|
'total_net' => array('name'=>'type','type'=>'xsd:double'),
|
||||||
'total_vat' => array('name'=>'type','type'=>'xsd:double'),
|
'total_vat' => array('name'=>'type','type'=>'xsd:double'),
|
||||||
@ -243,13 +243,37 @@ $server->register(
|
|||||||
// Entry values
|
// Entry values
|
||||||
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
|
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
|
||||||
// Exit values
|
// 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,
|
||||||
$ns.'#createInvoice',
|
$ns.'#createInvoice',
|
||||||
$styledoc,
|
$styledoc,
|
||||||
$styleuse,
|
$styleuse,
|
||||||
'WS to create an invoice'
|
'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(
|
$linesresp[]=array(
|
||||||
'id'=>$line->rowid,
|
'id'=>$line->rowid,
|
||||||
'type'=>$line->product_type,
|
'type'=>$line->product_type,
|
||||||
'desc'=>dol_htmlcleanlastbr($line->desc),
|
'desc'=>dol_htmlcleanlastbr($line->desc),
|
||||||
'total_net'=>$line->total_ht,
|
'total_net'=>$line->total_ht,
|
||||||
'total_vat'=>$line->total_tva,
|
'total_vat'=>$line->total_tva,
|
||||||
'total'=>$line->total_ttc,
|
'total'=>$line->total_ttc,
|
||||||
'vat_rate'=>$line->tva_tx,
|
'vat_rate'=>$line->tva_tx,
|
||||||
'qty'=>$line->qty,
|
'qty'=>$line->qty,
|
||||||
'product_ref'=>$line->product_ref,
|
'unitprice'=> $line->subprice,
|
||||||
'product_label'=>$line->product_label,
|
'date_start'=> $line->date_start?dol_print_date($line->date_start,'dayrfc'):'',
|
||||||
'product_desc'=>$line->product_desc,
|
'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++;
|
$i++;
|
||||||
}
|
}
|
||||||
@ -319,9 +347,11 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='')
|
|||||||
'id' => $invoice->id,
|
'id' => $invoice->id,
|
||||||
'ref' => $invoice->ref,
|
'ref' => $invoice->ref,
|
||||||
'ref_ext' => $invoice->ref_ext?$invoice->ref_ext:'', // If not defined, field is not added into soap
|
'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_author' => $invoice->user_author?$invoice->user_author:'',
|
||||||
'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'',
|
'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'',
|
||||||
'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'',
|
'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_validation' => $invoice->date_validation?dol_print_date($invoice->date_creation,'dayhourrfc'):'',
|
||||||
'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'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,
|
'total' => $invoice->total_ttc,
|
||||||
'note_private' => $invoice->note_private?$invoice->note_private:'',
|
'note_private' => $invoice->note_private?$invoice->note_private:'',
|
||||||
'note_public' => $invoice->note_public?$invoice->note_public:'',
|
'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_code' => $invoice->close_code?$invoice->close_code:'',
|
||||||
'close_note' => $invoice->close_note?$invoice->close_note:'',
|
'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:'',
|
||||||
@ -387,7 +418,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
|
|||||||
if (! $error && empty($idthirdparty))
|
if (! $error && empty($idthirdparty))
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
$errorcode='BAD_PARAMETERS'; $errorlabel='Parameter id is not provided';
|
$errorcode='BAD_PARAMETERS'; $errorlabel='Parameter idthirdparty is not provided';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
@ -433,6 +464,10 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
|
|||||||
'total'=>$line->total_ttc,
|
'total'=>$line->total_ttc,
|
||||||
'vat_rate'=>$line->tva_tx,
|
'vat_rate'=>$line->tva_tx,
|
||||||
'qty'=>$line->qty,
|
'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_ref'=>$line->product_ref,
|
||||||
'product_label'=>$line->product_label,
|
'product_label'=>$line->product_label,
|
||||||
'product_desc'=>$line->product_desc,
|
'product_desc'=>$line->product_desc,
|
||||||
@ -448,7 +483,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
|
|||||||
'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'',
|
'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'',
|
||||||
'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'',
|
'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'',
|
||||||
'date_due' => $invoice->date_lim_reglement?dol_print_date($invoice->date_lim_reglement,'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_validation' => $invoice->date_validation?dol_print_date($invoice->date_creation,'dayhourrfc'):'',
|
||||||
'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'dayhourrfc'):'',
|
'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'dayhourrfc'):'',
|
||||||
'type' => $invoice->type,
|
'type' => $invoice->type,
|
||||||
@ -458,9 +493,10 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
|
|||||||
'note_private' => $invoice->note_private?$invoice->note_private:'',
|
'note_private' => $invoice->note_private?$invoice->note_private:'',
|
||||||
'note_public' => $invoice->note_public?$invoice->note_public:'',
|
'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_code' => $invoice->close_code?$invoice->close_code:'',
|
||||||
'close_note' => $invoice->close_note?$invoice->close_note:'',
|
'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
|
'lines' => $linesresp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -503,7 +539,8 @@ function createInvoice($authentication,$invoice)
|
|||||||
|
|
||||||
$now=dol_now();
|
$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'];
|
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||||
|
|
||||||
@ -513,27 +550,32 @@ function createInvoice($authentication,$invoice)
|
|||||||
$error=0;
|
$error=0;
|
||||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
$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)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$newobject=new Facture($db);
|
$new_invoice=new Facture($db);
|
||||||
$newobject->socid=$invoice['thirdparty_id'];
|
$new_invoice->socid=$invoice['thirdparty_id'];
|
||||||
$newobject->type=$invoice['type'];
|
$new_invoice->type=$invoice['type'];
|
||||||
$newobject->ref_ext=$invoice['ref_ext'];
|
$new_invoice->ref_ext=$invoice['ref_ext'];
|
||||||
$newobject->date=dol_stringtotime($invoice['date'],'dayrfc');
|
$new_invoice->date=dol_stringtotime($invoice['date'],'dayrfc');
|
||||||
$newobject->note_private=$invoice['note_private'];
|
$new_invoice->note_private=$invoice['note_private'];
|
||||||
$newobject->note_public=$invoice['note_public'];
|
$new_invoice->note_public=$invoice['note_public'];
|
||||||
$newobject->statut= Facture::STATUS_DRAFT; // We start with status draft
|
$new_invoice->statut= Facture::STATUS_DRAFT; // We start with status draft
|
||||||
$newobject->fk_project=$invoice['project_id'];
|
$new_invoice->fk_project=$invoice['project_id'];
|
||||||
$newobject->date_creation=$now;
|
$new_invoice->date_creation=$now;
|
||||||
|
|
||||||
//take mode_reglement and cond_reglement from thirdparty
|
//take mode_reglement and cond_reglement from thirdparty
|
||||||
$soc = new Societe($db);
|
$soc = new Societe($db);
|
||||||
$res=$soc->fetch($newobject->socid);
|
$res=$soc->fetch($new_invoice->socid);
|
||||||
if ($res > 0) {
|
if ($res > 0) {
|
||||||
$newobject->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id;
|
$new_invoice->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->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
|
// Trick because nusoap does not store data with same structure if there is one or several lines
|
||||||
$arrayoflines=array();
|
$arrayoflines=array();
|
||||||
@ -556,22 +598,22 @@ function createInvoice($authentication,$invoice)
|
|||||||
$newline->date_start=dol_stringtotime($line['date_start']);
|
$newline->date_start=dol_stringtotime($line['date_start']);
|
||||||
$newline->date_end=dol_stringtotime($line['date_end']);
|
$newline->date_end=dol_stringtotime($line['date_end']);
|
||||||
$newline->fk_product=$line['product_id'];
|
$newline->fk_product=$line['product_id'];
|
||||||
$newobject->lines[]=$newline;
|
$new_invoice->lines[]=$newline;
|
||||||
}
|
}
|
||||||
//var_dump($newobject->date_lim_reglement); exit;
|
//var_dump($newobject->date_lim_reglement); exit;
|
||||||
//var_dump($invoice['lines'][0]['type']);
|
//var_dump($invoice['lines'][0]['type']);
|
||||||
|
|
||||||
$db->begin();
|
$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)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$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)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
@ -581,14 +623,16 @@ function createInvoice($authentication,$invoice)
|
|||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$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
|
else
|
||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
$error++;
|
$error++;
|
||||||
$errorcode='KO';
|
$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;
|
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.
|
// Return the results.
|
||||||
$server->service(file_get_contents("php://input"));
|
$server->service(file_get_contents("php://input"));
|
||||||
|
|||||||
@ -917,7 +917,17 @@ function updateOrder($authentication,$order)
|
|||||||
if (isset($order['status']))
|
if (isset($order['status']))
|
||||||
{
|
{
|
||||||
if ($order['status'] == -1) $result=$object->cancel($fuser);
|
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'] == 0) $result=$object->set_reopen($fuser);
|
||||||
if ($order['status'] == 3) $result=$object->cloture($fuser);
|
if ($order['status'] == 3) $result=$object->cloture($fuser);
|
||||||
}
|
}
|
||||||
@ -951,7 +961,9 @@ function updateOrder($authentication,$order)
|
|||||||
$db->commit();
|
$db->commit();
|
||||||
$objectresp=array(
|
$objectresp=array(
|
||||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||||
'id'=>$object->id
|
'id'=>$object->id,
|
||||||
|
'ref'=>$object->ref,
|
||||||
|
'ref_ext'=>$object->ref_ext
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
elseif ($objectfound)
|
elseif ($objectfound)
|
||||||
|
|||||||
@ -258,8 +258,31 @@ $server->register(
|
|||||||
'WS to get list of thirdparties id and ref'
|
'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
|
// 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='')
|
function getThirdParty($authentication,$id='',$ref='',$ref_ext='')
|
||||||
{
|
{
|
||||||
global $db,$conf,$langs;
|
global $db,$conf,$langs;
|
||||||
@ -728,5 +751,88 @@ function getListOfThirdParties($authentication,$filterthirdparty)
|
|||||||
return $objectresp;
|
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.
|
// Return the results.
|
||||||
$server->service(file_get_contents("php://input"));
|
$server->service(file_get_contents("php://input"));
|
||||||
|
|||||||
@ -18,9 +18,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \file test/phpunit/WebservicesInvoicesTest.php
|
* \file test/phpunit/WebservicesInvoicesTest.php
|
||||||
* \ingroup test
|
* \ingroup test
|
||||||
* \brief PHPUnit 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;
|
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
|
require_once(NUSOAP_PATH.'/nusoap.php'); // Include SOAP
|
||||||
|
|
||||||
|
|
||||||
if (empty($user->id)) {
|
if (empty($user->id))
|
||||||
print "Load permissions for admin user nb 1\n";
|
{
|
||||||
$user->fetch(1);
|
print "Load permissions for admin user nb 1\n";
|
||||||
$user->getrights();
|
$user->fetch(1);
|
||||||
|
$user->getrights();
|
||||||
}
|
}
|
||||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||||
|
|
||||||
@ -44,138 +45,369 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
|||||||
*
|
*
|
||||||
* @backupGlobals disabled
|
* @backupGlobals disabled
|
||||||
* @backupStaticAttributes enabled
|
* @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
|
class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected $savconf;
|
protected $savconf;
|
||||||
protected $savuser;
|
protected $savuser;
|
||||||
protected $savlangs;
|
protected $savlangs;
|
||||||
protected $savdb;
|
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";
|
||||||
|
|
||||||
/**
|
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||||
* Constructor
|
//print " - db ".$db->db;
|
||||||
* We save global variables into local variables
|
print "\n";
|
||||||
*
|
}
|
||||||
* @return DateLibTest
|
|
||||||
*/
|
// Static methods
|
||||||
function __construct()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
//$this->sharedFixture
|
global $conf,$user,$langs,$db;
|
||||||
global $conf,$user,$langs,$db;
|
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
|
||||||
$this->savconf=$conf;
|
|
||||||
$this->savuser=$user;
|
|
||||||
$this->savlangs=$langs;
|
|
||||||
$this->savdb=$db;
|
|
||||||
|
|
||||||
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
print __METHOD__."\n";
|
||||||
//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";
|
|
||||||
}
|
|
||||||
|
|
||||||
// tear down after class
|
|
||||||
public static function tearDownAfterClass()
|
public static function tearDownAfterClass()
|
||||||
{
|
{
|
||||||
global $conf,$user,$langs,$db;
|
global $conf,$user,$langs,$db;
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
|
|
||||||
print __METHOD__."\n";
|
print __METHOD__."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init phpunit tests
|
* Init phpunit tests
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
global $conf,$user,$langs,$db;
|
global $conf,$user,$langs,$db;
|
||||||
$conf=$this->savconf;
|
$conf=$this->savconf;
|
||||||
$user=$this->savuser;
|
$user=$this->savuser;
|
||||||
$langs=$this->savlangs;
|
$langs=$this->savlangs;
|
||||||
$db=$this->savdb;
|
$db=$this->savdb;
|
||||||
|
|
||||||
print __METHOD__."\n";
|
print __METHOD__."\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End phpunit tests
|
* End phpunit tests
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function tearDown()
|
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;
|
global $conf,$user,$langs,$db;
|
||||||
$conf=$this->savconf;
|
$conf=$this->savconf;
|
||||||
$user=$this->savuser;
|
$user=$this->savuser;
|
||||||
$langs=$this->savlangs;
|
$langs=$this->savlangs;
|
||||||
$db=$this->savdb;
|
$db=$this->savdb;
|
||||||
|
|
||||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
|
$WS_METHOD = 'createInvoice';
|
||||||
$WS_METHOD = 'getInvoice';
|
|
||||||
$ns='http://www.dolibarr.org/ns/';
|
|
||||||
|
|
||||||
// Set the WebService URL
|
// load societe first
|
||||||
print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
|
$societe=new Societe($db);
|
||||||
$soapclient = new nusoap_client($WS_DOL_URL);
|
$societe->fetch('', '', '209');
|
||||||
if ($soapclient) {
|
print __METHOD__." societe loaded id=".$societe->id."\n";
|
||||||
$soapclient->soap_defencoding='UTF-8';
|
|
||||||
$soapclient->decodeUTF8(false);
|
|
||||||
}
|
$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.
|
// Call the WebService method and store its result in $result.
|
||||||
$authentication=array(
|
$authentication=array(
|
||||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||||
'sourceapplication'=>'DEMO',
|
'sourceapplication'=>'DEMO',
|
||||||
'login'=>'admin',
|
'login'=>'admin',
|
||||||
'password'=>'admin',
|
'password'=>'admin',
|
||||||
'entity'=>''
|
'entity'=>'');
|
||||||
);
|
|
||||||
|
|
||||||
// Test URL
|
// Test URL
|
||||||
$result='';
|
$result='';
|
||||||
$parameters = array('authentication'=>$authentication,'id'=>1);
|
$parameters = array('authentication'=>$authentication,'invoice'=>$body);
|
||||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||||
try {
|
try {
|
||||||
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
|
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,'');
|
||||||
} catch(SoapFault $exception) {
|
}
|
||||||
echo $exception;
|
catch(SoapFault $exception)
|
||||||
$result=0;
|
{
|
||||||
}
|
echo $exception;
|
||||||
if (! $result || ! empty($result['faultstring'])) {
|
$result=0;
|
||||||
//var_dump($soapclient);
|
}
|
||||||
print $soapclient->error_str;
|
if (! $result || ! empty($result['faultstring']))
|
||||||
print "\n<br>\n";
|
{
|
||||||
print $soapclient->request;
|
//var_dump($soapclient);
|
||||||
print "\n<br>\n";
|
print $this->soapclient->error_str;
|
||||||
print $soapclient->response;
|
print "\n<br>\n";
|
||||||
print "\n";
|
print $this->soapclient->request;
|
||||||
}
|
print "\n<br>\n";
|
||||||
|
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('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 $savuser;
|
||||||
protected $savlangs;
|
protected $savlangs;
|
||||||
protected $savdb;
|
protected $savdb;
|
||||||
|
protected $soapclient;
|
||||||
|
|
||||||
|
private $_WS_DOL_URL;
|
||||||
|
private $_ns='http://www.dolibarr.org/ns/';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->savuser=$user;
|
$this->savuser=$user;
|
||||||
$this->savlangs=$langs;
|
$this->savlangs=$langs;
|
||||||
$this->savdb=$db;
|
$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 __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||||
//print " - db ".$db->db;
|
//print " - db ".$db->db;
|
||||||
@ -117,31 +134,114 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
|
|||||||
print __METHOD__."\n";
|
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
|
* testWSThirdpartygetThirdPartyById
|
||||||
*
|
*
|
||||||
* @return int
|
* 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;
|
global $conf,$user,$langs,$db;
|
||||||
$conf=$this->savconf;
|
$conf=$this->savconf;
|
||||||
$user=$this->savuser;
|
$user=$this->savuser;
|
||||||
$langs=$this->savlangs;
|
$langs=$this->savlangs;
|
||||||
$db=$this->savdb;
|
$db=$this->savdb;
|
||||||
|
$id = $result['id'];
|
||||||
|
|
||||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
|
|
||||||
$WS_METHOD = 'getThirdParty';
|
$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.
|
// Call the WebService method and store its result in $result.
|
||||||
$authentication=array(
|
$authentication=array(
|
||||||
@ -151,30 +251,150 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
|
|||||||
'password'=>'admin',
|
'password'=>'admin',
|
||||||
'entity'=>'');
|
'entity'=>'');
|
||||||
|
|
||||||
// Test URL
|
|
||||||
$result='';
|
$result='';
|
||||||
$parameters = array('authentication'=>$authentication, 'id'=>1);
|
$parameters = array('authentication'=>$authentication, 'id'=>$id);
|
||||||
print __METHOD__." call method ".$WS_METHOD."\n";
|
print __METHOD__." call method ".$WS_METHOD."\n";
|
||||||
try {
|
try {
|
||||||
$result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
|
$result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,'');
|
||||||
} catch(SoapFault $exception) {
|
} catch(SoapFault $exception) {
|
||||||
echo $exception;
|
echo $exception;
|
||||||
$result=0;
|
$result=0;
|
||||||
}
|
}
|
||||||
if (! $result || ! empty($result['faultstring'])) {
|
if (! $result || ! empty($result['faultstring'])) {
|
||||||
//var_dump($soapclient);
|
//var_dump($soapclient);
|
||||||
print $soapclient->error_str;
|
print $this->soapclient->error_str;
|
||||||
print "\n<br>\n";
|
print "\n<br>\n";
|
||||||
print $soapclient->request;
|
print $this->soapclient->request;
|
||||||
print "\n<br>\n";
|
print "\n<br>\n";
|
||||||
print $soapclient->response;
|
print $this->soapclient->response;
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result['result']['result_code']."\n";
|
||||||
$this->assertEquals('OK',$result['result']['result_code']);
|
$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;
|
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