Merge branch '3.7-webservices-fix' of https://github.com/aaujon/dolibarr into 3.7-webservices-fix

This commit is contained in:
Arnaud Aujon 2015-06-01 20:05:36 +02:00
commit 56a2942503
16 changed files with 635 additions and 216 deletions

View File

@ -480,7 +480,7 @@ class Categorie extends CommonObject
* Link an object to the category * Link an object to the category
* *
* @param Object $obj Object to link to category * @param Object $obj Object to link to category
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') * @param string $type Type of category ('societe', 'member', 'product', 'contact', 'fournisseur)
* @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked * @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked
*/ */
function add_type($obj,$type) function add_type($obj,$type)
@ -493,12 +493,22 @@ class Categorie extends CommonObject
// For backward compatibility // For backward compatibility
if ($type == 'company') $type='societe'; if ($type == 'company') $type='societe';
if ($type == 'customer') $type='societe'; elseif ($type == 'customer') $type='societe';
if ($type == 'supplier') $type='fournisseur'; elseif ($type == 'supplier') $type='fournisseur';
$column_name=$type; /**
if ($type=='contact') $column_name='socpeople'; * llx_categorie_contact => fk_socpeople
if ($type=='fournisseur') $column_name='societe'; * llx_categorie_fournisseur, llx_categorie_societe => fk_soc
* llx_categorie_member => fk_member
* llx_categorie_product => fk_product
*/
if ($type == 'contact') {
$column_name = 'socpeople';
} elseif ($type == 'fournisseur' || ($type == 'societe')) {
$column_name = 'soc';
} else {
$column_name = $type;
}
$this->db->begin(); $this->db->begin();

View File

@ -28,6 +28,8 @@ require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php';
/** /**
* Class to manage Dolibarr database access for a MySQL database using the mysql extension * Class to manage Dolibarr database access for a MySQL database using the mysql extension
*
* @deprecated Use DoliDBMysqli
*/ */
class DoliDBMysql extends DoliDB class DoliDBMysql extends DoliDB
{ {

View File

@ -789,14 +789,15 @@ function dol_get_fiche_head($links=array(), $active='0', $title='', $notab=0, $p
if ($displaytab > $limittoshow) if ($displaytab > $limittoshow)
{ {
$out.='<div id="moretabs" class="inline-block tabsElem">'; $tabsname=str_replace ("@", "", $picto);
$out.='<div id="moretabs'.$tabsname.'" class="inline-block tabsElem">';
$out.='<a href="" data-role="button" style="background-color: #f0f0f0;" class="tab inline-block">'.$langs->trans("More").'...</a>'; $out.='<a href="" data-role="button" style="background-color: #f0f0f0;" class="tab inline-block">'.$langs->trans("More").'...</a>';
$out.='<div id="moretabsList" style="position: absolute; left: -999em;text-align: left;margin:0px;padding:2px">'.$outmore.'</div>'; $out.='<div id="moretabsList'.$tabsname.'" style="position: absolute; left: -999em;text-align: left;margin:0px;padding:2px">'.$outmore.'</div>';
$out.="</div>\n"; $out.="</div>\n";
$out.="<script>"; $out.="<script>";
$out.="$('#moretabs').mouseenter( function() { $('#moretabsList').css('left','auto');});"; $out.="$('#moretabs".$tabsname.").mouseenter( function() { $('#moretabsList".$tabsname.").css('left','auto');});";
$out.="$('#moretabs').mouseleave( function() { $('#moretabsList').css('left','-999em');});"; $out.="$('#moretabs".$tabsname.").mouseleave( function() { $('#moretabsList".$tabsname.").css('left','-999em');});";
$out.="</script>"; $out.="</script>";
} }

View File

@ -637,10 +637,21 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
//$date=dol_mktime(12, 0, 0, 1, 1, 1900); //$date=dol_mktime(12, 0, 0, 1, 1, 1900);
//$date=dol_stringtotime('20130101'); //$date=dol_stringtotime('20130101');
$hasglobalcounter=false;
// Extract value for mask counter, mask raz and mask offset // Extract value for mask counter, mask raz and mask offset
if (! preg_match('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$mask,$reg)) return 'ErrorBadMask'; if (preg_match('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$mask,$reg))
$masktri=$reg[1].(! empty($reg[2])?$reg[2]:'').(! empty($reg[3])?$reg[3]:''); {
$maskcounter=$reg[1]; $masktri=$reg[1].(! empty($reg[2])?$reg[2]:'').(! empty($reg[3])?$reg[3]:'');
$maskcounter=$reg[1];
$hasglobalcounter=true;
}
else
{
// setting some defaults so the rest of the code won't fail if there is a third party counter
$masktri='00000';
$maskcounter='00000';
}
$maskraz=-1; $maskraz=-1;
$maskoffset=0; $maskoffset=0;
$resetEveryMonth=false; $resetEveryMonth=false;
@ -660,6 +671,12 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
} }
else $maskrefclient=''; else $maskrefclient='';
// fail if there is neither a global nor a third party counter
if (! $hasglobalcounter && ($maskrefclient_maskcounter == ''))
{
return 'ErrorBadMask';
}
// Extract value for third party type // Extract value for third party type
if (preg_match('/\{(t+)\}/i',$mask,$regType)) if (preg_match('/\{(t+)\}/i',$mask,$regType))
{ {
@ -993,10 +1010,21 @@ function check_value($mask,$value)
{ {
$result=0; $result=0;
$hasglobalcounter=false;
// Extract value for mask counter, mask raz and mask offset // Extract value for mask counter, mask raz and mask offset
if (! preg_match('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i',$mask,$reg)) return 'ErrorBadMask'; if (preg_match('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i',$mask,$reg))
$masktri=$reg[1].(isset($reg[2])?$reg[2]:'').(isset($reg[3])?$reg[3]:''); {
$maskcounter=$reg[1]; $masktri=$reg[1].(isset($reg[2])?$reg[2]:'').(isset($reg[3])?$reg[3]:'');
$maskcounter=$reg[1];
$hasglobalcounter=true;
}
else
{
// setting some defaults so the rest of the code won't fail if there is a third party counter
$masktri='00000';
$maskcounter='00000';
}
$maskraz=-1; $maskraz=-1;
$maskoffset=0; $maskoffset=0;
if (dol_strlen($maskcounter) < 3) return 'ErrorCounterMustHaveMoreThan3Digits'; if (dol_strlen($maskcounter) < 3) return 'ErrorCounterMustHaveMoreThan3Digits';
@ -1015,6 +1043,12 @@ function check_value($mask,$value)
} }
else $maskrefclient=''; else $maskrefclient='';
// fail if there is neither a global nor a third party counter
if (! $hasglobalcounter && ($maskrefclient_maskcounter == ''))
{
return 'ErrorBadMask';
}
$maskwithonlyymcode=$mask; $maskwithonlyymcode=$mask;
$maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i',$maskcounter,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i',$maskcounter,$maskwithonlyymcode);
$maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode);

View File

@ -6,6 +6,7 @@
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2009-2011 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2009-2011 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr> * Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -90,6 +91,7 @@ class modAgenda extends DolibarrModules
$this->const[12] = array("MAIN_AGENDA_ACTIONAUTO_SHIPPING_VALIDATE","chaine","1"); $this->const[12] = array("MAIN_AGENDA_ACTIONAUTO_SHIPPING_VALIDATE","chaine","1");
$this->const[13] = array("MAIN_AGENDA_ACTIONAUTO_SHIPPING_SENTBYMAIL","chaine","1"); $this->const[13] = array("MAIN_AGENDA_ACTIONAUTO_SHIPPING_SENTBYMAIL","chaine","1");
$this->const[14] = array("MAIN_AGENDA_ACTIONAUTO_BILL_UNVALIDATE","chaine","1"); $this->const[14] = array("MAIN_AGENDA_ACTIONAUTO_BILL_UNVALIDATE","chaine","1");
$this->const[15] = array("MAIN_AGENDA_ACTIONAUTO_BILL_SUPPLIER_UNVALIDATE","chaine","1");
// New pages on tabs // New pages on tabs
// ----------------- // -----------------

View File

@ -4,6 +4,7 @@
* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr> * Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -493,6 +494,18 @@ class InterfaceActionsAuto extends DolibarrTriggers
$object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
}
elseif ($action == 'BILL_SUPPLIER_UNVALIDATE')
{
$langs->load("other");
$langs->load("bills");
$object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0; $object->sendtoid=0;
} }
elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL')

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -197,6 +198,7 @@ class InterfaceDemo extends DolibarrTriggers
case 'BILL_SUPPLIER_PAYED': case 'BILL_SUPPLIER_PAYED':
case 'BILL_SUPPLIER_UNPAYED': case 'BILL_SUPPLIER_UNPAYED':
case 'BILL_SUPPLIER_VALIDATE': case 'BILL_SUPPLIER_VALIDATE':
case 'BILL_SUPPLIER_UNVALIDATE':
case 'LINEBILL_SUPPLIER_CREATE': case 'LINEBILL_SUPPLIER_CREATE':
case 'LINEBILL_SUPPLIER_UPDATE': case 'LINEBILL_SUPPLIER_UPDATE':
case 'LINEBILL_SUPPLIER_DELETE': case 'LINEBILL_SUPPLIER_DELETE':

View File

@ -8,6 +8,7 @@
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com> * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -1073,7 +1074,14 @@ class FactureFournisseur extends CommonInvoice
} }
} }
} }
// Triggers call
if (! $error && empty($notrigger))
{
// Call trigger
$result=$this->call_trigger('BILL_SUPPLIER_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if ($error == 0) if ($error == 0)
{ {
$this->db->commit(); $this->db->commit();

View File

@ -328,8 +328,9 @@ if (! empty($force_install_message))
$option.='>'; $option.='>';
$option.=$type.'&nbsp; &nbsp;'; $option.=$type.'&nbsp; &nbsp;';
if ($note) $option.=' '.$note; if ($note) $option.=' '.$note;
// Experimental // Deprecated and experimental
if ($type=='mssql') $option.=' '.$langs->trans("Experimental"); if ($type=='mysql') $option.=' ' . $langs->trans("Deprecated");
elseif ($type=='mssql') $option.=' '.$langs->trans("Experimental");
elseif ($type=='sqlite') $option.=' '.$langs->trans("Experimental"); elseif ($type=='sqlite') $option.=' '.$langs->trans("Experimental");
elseif ($type=='sqlite3') $option.=' '.$langs->trans("Experimental"); elseif ($type=='sqlite3') $option.=' '.$langs->trans("Experimental");
// No available // No available

View File

@ -8,6 +8,7 @@
-- Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es> -- Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr> -- Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr>
-- Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> -- Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
-- Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
-- --
-- This program is free software; you can redistribute it and/or modify -- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
@ -74,3 +75,4 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_CREATE','Task created','Executed when a project task is created','project',35); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_CREATE','Task created','Executed when a project task is created','project',35);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_MODIFY','Task modified','Executed when a project task is modified','project',36); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_MODIFY','Task modified','Executed when a project task is modified','project',36);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_DELETE','Task deleted','Executed when a project task is deleted','project',37); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_DELETE','Task deleted','Executed when a project task is deleted','project',37);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_SUPPLIER_UNVALIDATE', 'Supplier invoice unvalidated', 'Executed when a supplier invoice status is set back to draft', 'invoice_supplier',15);

View File

@ -644,4 +644,5 @@ ALTER TABLE llx_actioncomm ADD COLUMN recurdateend datetime;
ALTER TABLE llx_stcomm ADD COLUMN picto varchar(128); ALTER TABLE llx_stcomm ADD COLUMN picto varchar(128);
-- New trigger for Supplier invoice unvalidation
INSERT INTO llx_c_action_trigger (code, label, description, elementtype, rang) VALUES ('BILL_SUPPLIER_UNVALIDATE','Supplier invoice unvalidated','Executed when a supplier invoice status is set back to draft','invoice_supplier',15);

View File

@ -64,6 +64,7 @@ DatabaseSuperUserAccess=Database server - Superuser access
CheckToCreateDatabase=Check box if database does not exist and must be created.<br>In this case, you must fill the login/password for superuser account at the bottom of this page. CheckToCreateDatabase=Check box if database does not exist and must be created.<br>In this case, you must fill the login/password for superuser account at the bottom of this page.
CheckToCreateUser=Check box if database owner does not exist and must be created.<br>In this case, you must choose its login and password and also fill the login/password for the superuser account at the bottom of this page. If this box is unchecked, owner database and its passwords must exists. CheckToCreateUser=Check box if database owner does not exist and must be created.<br>In this case, you must choose its login and password and also fill the login/password for the superuser account at the bottom of this page. If this box is unchecked, owner database and its passwords must exists.
Experimental=(experimental) Experimental=(experimental)
Deprecated=(deprecated)
DatabaseRootLoginDescription=Login of the user allowed to create new databases or new users, mandatory if your database or its owner does not already exists. DatabaseRootLoginDescription=Login of the user allowed to create new databases or new users, mandatory if your database or its owner does not already exists.
KeepEmptyIfNoPassword=Leave empty if user has no password (avoid this) KeepEmptyIfNoPassword=Leave empty if user has no password (avoid this)
SaveConfigurationFile=Save values SaveConfigurationFile=Save values

View File

@ -557,25 +557,25 @@ function createInvoice($authentication,$invoice)
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();
@ -598,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++;
@ -623,15 +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, $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$new_invoice->id,
'ref'=>$newobject->ref,'ref_ext'=>$newobject->ref_ext); '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);
} }
} }
@ -750,8 +751,8 @@ function updateInvoice($authentication,$invoice)
{ {
global $db,$conf,$langs; global $db,$conf,$langs;
dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice->id. dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice['id'].
", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext); ", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']);
if ($authentication['entity']) $conf->entity=$authentication['entity']; if ($authentication['entity']) $conf->entity=$authentication['entity'];
@ -781,10 +782,13 @@ function updateInvoice($authentication,$invoice)
if (isset($invoice['status'])) if (isset($invoice['status']))
{ {
if ($invoice['status'] == 0) $result=$object->set_draft($fuser); if ($invoice['status'] == Facture::STATUS_DRAFT)
if ($invoice['status'] == 1)
{ {
$result=$object->validate($fuser); $result = $object->set_draft($fuser);
}
if ($invoice['status'] == Facture::STATUS_VALIDATED)
{
$result = $object->validate($fuser);
if ($result >= 0) if ($result >= 0)
{ {
@ -793,11 +797,12 @@ function updateInvoice($authentication,$invoice)
$order->generateDocument($invoice->modelpdf, $outputlangs); $order->generateDocument($invoice->modelpdf, $outputlangs);
} }
} }
if ($invoice['status'] == 2) if ($invoice['status'] == Facture::STATUS_CLOSED)
{ {
$result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note);
} }
if ($invoice['status'] == 3) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); if ($invoice['status'] == Facture::STATUS_ABANDONED)
$result = $object->set_canceled($fuser,$invoice->close_code,$invoice->close_note);
} }
} }

View File

@ -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"));

View File

@ -53,6 +53,10 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
protected $savuser; protected $savuser;
protected $savlangs; protected $savlangs;
protected $savdb; protected $savdb;
protected $soapclient;
protected $socid;
protected $ns = 'http://www.dolibarr.org/ns/';
/** /**
* Constructor * Constructor
@ -68,6 +72,35 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$this->savuser=$user; $this->savuser=$user;
$this->savlangs=$langs; $this->savlangs=$langs;
$this->savdb=$db; $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; print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db; //print " - db ".$db->db;
@ -103,9 +136,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$langs=$this->savlangs; $langs=$this->savlangs;
$db=$this->savdb; $db=$this->savdb;
// create a third_party, needed to create an invoice
print __METHOD__."\n"; print __METHOD__."\n";
} }
/** /**
@ -132,60 +164,55 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$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 = 'createInvoice';
$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 ( $body = array (
["id"] => NULL, "id" => NULL,
["ref"]=> NULL, "ref" => NULL,
["ref_ext"]=> "165", "ref_ext" => "165",
["thirdparty_id"]=> "209", "thirdparty_id" => $societe->id,
["fk_user_author"] => NULL, "fk_user_author" => NULL,
["fk_user_valid"] => NULL, "fk_user_valid" => NULL,
["date"]=> "2015-04-19 20:16:53", "date" => "2015-04-19 20:16:53",
["date_due"]=> "", "date_due" => "",
["date_creation"]=> "", "date_creation" => "",
["date_validation"]=> "", "date_validation" => "",
["date_modification"]=> "", "date_modification" => "",
["type"]=> "", "type" => "",
["total_net"]=> "36.30", "total_net" => "36.30",
["total_vat"]=> "6.00", "total_vat" => "6.00",
["total"]=> "42.30", "total" => "42.30",
["payment_mode_id"]=> 50, "payment_mode_id" => 50,
["note_private"]=> "Synchronised from Prestashop", "note_private" => "Synchronised from Prestashop",
["note_public"]=> "", "note_public" => "",
["status"]=> "1", "status" => "1",
["close_code"]=> NULL , "close_code" => NULL ,
["close_note"]=> NULL, "close_note" => NULL,
["project_id"]=> NULL, "project_id" => NULL,
["lines"] => array( "lines" => array(
["id"] => NULL, array("id" => NULL,
["type"]=> 0, "type" => 0,
["desc"]=> "Horloge Vinyle Serge", "desc" => "Horloge Vinyle Serge",
["vat_rate"]=> 20, "vat_rate" => 20,
["qty"]=> "1", "qty" => 1,
["unitprice"]=> "30.000000", "unitprice" => "30.000000",
["total_net"]=> "30.000000", "total_net" => "30.000000",
["total_vat"]=> "6.00", "total_vat" => "6.00",
["total"]=> "36.000000", "total" => "36.000000",
["date_start"]=> "", "date_start" => "",
["date_end"]=> "", "date_end" => "",
["payment_mode_id"]=> "", "payment_mode_id" => "",
["product_id"]=> "", "product_id" => "",
["product_ref"]=> "", "product_ref" => "",
["product_label"]=> "", "product_label" => "",
["product_desc"]=> "" ) "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(
@ -200,7 +227,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$parameters = array('authentication'=>$authentication,'invoice'=>$body); $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) catch(SoapFault $exception)
{ {
@ -210,15 +237,15 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
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('165', $result['ref_ext']); $this->assertEquals('165', $result['ref_ext']);
@ -227,11 +254,15 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
} }
/** /**
* testWSInvoicesGetInvoice * testWSInvoicesGetInvoiceByRefExt
* *
* @return int * Retrieve an invoice using ref_ext
* @depends testWSInvoicesCreateInvoice
*
* @param result invoice created by create method
* @return array Invoice
*/ */
public function testWSInvoicesGetInvoice() public function testWSInvoicesGetInvoiceByRefExt($result)
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
$conf=$this->savconf; $conf=$this->savconf;
@ -239,18 +270,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$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 = 'getInvoice'; $WS_METHOD = 'getInvoice';
$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(
@ -265,7 +285,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165); $parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165);
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)
{ {
@ -274,29 +294,31 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
} }
if (! $result || ! empty($result['faultstring'])) if (! $result || ! empty($result['faultstring']))
{ {
//var_dump($soapclient); print $this->soapclient->error_str;
print $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['result']['result_code']."\n";
print __METHOD__." result=".$result."\n";
$this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('OK',$result['result']['result_code']);
$this->assertEquals('165', $result['result']['invoice']->ref_ext); $this->assertEquals('165', $result['invoice']['ref_ext']);
return $result; return $result;
} }
/** /**
* testWSInvoicesUpdateInvoice * testWSInvoicesUpdateInvoiceByRefExt
* *
* @return int * Update an invoice using ref_ext
* @depends testWSInvoicesCreateInvoice
*
* @param result invoice created by create method
* @return array Invoice
*/ */
public function testWSInvoicesUpdateInvoice() public function testWSInvoicesUpdateInvoiceByRefExt($result)
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
$conf=$this->savconf; $conf=$this->savconf;
@ -304,61 +326,51 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$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 = 'updateInvoice'; $WS_METHOD = 'updateInvoice';
$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);
}
// update status to 2 // update status to 2
$body = array ( $body = array (
["id"] => NULL, "id" => NULL,
["ref"]=> NULL, "ref" => NULL,
["ref_ext"]=> "165", "ref_ext" => "165",
["thirdparty_id"]=> "209", "thirdparty_id" => "209",
["fk_user_author"] => NULL, "fk_user_author" => NULL,
["fk_user_valid"] => NULL, "fk_user_valid" => NULL,
["date"]=> "2015-04-19 20:16:53", "date" => "2015-04-19 20:16:53",
["date_due"]=> "", "date_due" => "",
["date_creation"]=> "", "date_creation" => "",
["date_validation"]=> "", "date_validation" => "",
["date_modification"]=> "", "date_modification" => "",
["type"]=> "", "type" => "",
["total_net"]=> "36.30", "total_net" => "36.30",
["total_vat"]=> "6.00", "total_vat" => "6.00",
["total"]=> "42.30", "total" => "42.30",
["payment_mode_id"]=> 50, "payment_mode_id" => 50,
["note_private"]=> "Synchronised from Prestashop", "note_private" => "Synchronised from Prestashop",
["note_public"]=> "", "note_public" => "",
["status"]=> "2", "status" => "2",
["close_code"]=> NULL , "close_code" => NULL ,
["close_note"]=> NULL, "close_note" => NULL,
["project_id"]=> NULL, "project_id" => NULL,
["lines"] => array( "lines" => array(
["id"] => NULL, array(
["type"]=> 0, "id" => NULL,
["desc"]=> "Horloge Vinyle Serge", "type" => 0,
["vat_rate"]=> 20, "desc" => "Horloge Vinyle Serge",
["qty"]=> "1", "vat_rate" => 20,
["unitprice"]=> "30.000000", "qty" => "1",
["total_net"]=> "30.000000", "unitprice" => "30.000000",
["total_vat"]=> "6.00", "total_net" => "30.000000",
["total"]=> "36.000000", "total_vat" => "6.00",
["date_start"]=> "", "total" => "36.000000",
["date_end"]=> "", "date_start" => "",
["payment_mode_id"]=> "", "date_end" => "",
["product_id"]=> "", "payment_mode_id" => "",
["product_ref"]=> "", "product_id" => "",
["product_label"]=> "", "product_ref" => "",
["product_desc"]=> "" ) "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(
@ -373,7 +385,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
$parameters = array('authentication'=>$authentication,'invoice'=>$body); $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) catch(SoapFault $exception)
{ {
@ -382,18 +394,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
} }
if (! $result || ! empty($result['faultstring'])) if (! $result || ! empty($result['faultstring']))
{ {
//var_dump($soapclient); print $this->soapclient->error_str;
print $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'].$result['result']['result_label']."\n";
$this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('OK',$result['result']['result_code']);
$this->assertEquals('2', $result['result']['invoice']->status); $this->assertEquals('165', $result['ref_ext']);
return $result; return $result;

View File

@ -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
@ -68,6 +75,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
$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;
print "\n"; print "\n";
@ -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 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 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 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;
}
} }