From f50738c69ded7ef428017fc7a35f70858e92801c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Dec 2010 08:36:50 +0000 Subject: [PATCH] Work on web services --- htdocs/compta/facture/class/facture.class.php | 18 +++--- htdocs/societe/class/societe.class.php | 56 ++++++++++--------- htdocs/webservices/server_invoice.php | 25 +++++---- htdocs/webservices/server_thirdparty.php | 33 ++++++----- 4 files changed, 76 insertions(+), 56 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index d745b486caf..3bcb7794e68 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -605,15 +605,18 @@ class Facture extends CommonObject /** * Get object and lines from database - * @param rowid id of object to load - * @param ref Ref of invoice + * @param rowid Id of object to load + * @param ref Reference of invoice + * @param ref External reference of invoice * @return int >0 if OK, <0 if KO */ - function fetch($rowid,$ref='') + function fetch($rowid, $ref='', $ref_ext='') { global $conf; - $sql = 'SELECT f.rowid,f.facnumber,f.ref_client,f.type,f.fk_soc,f.amount,f.tva, f.localtax1, f.localtax2, f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise'; + if (empty($rowid) && empty($ref) && empty($ref_ext)) return -1; + + $sql = 'SELECT f.rowid,f.facnumber,f.ref_client,f.type,f.fk_soc,f.amount,f.tva, f.localtax1, f.localtax2, f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise'; $sql.= ', f.datef as df'; $sql.= ', f.date_lim_reglement as dlr'; $sql.= ', f.datec as datec'; @@ -630,9 +633,10 @@ class Facture extends CommonObject $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = '".$this->element."'"; $sql.= ' WHERE f.entity = '.$conf->entity; - if ($ref) $sql.= " AND f.facnumber='".$this->db->escape($ref)."'"; - else $sql.= " AND f.rowid=".$rowid; - + if ($rowid) $sql.= " AND f.rowid=".$rowid; + if ($ref) $sql.= " AND f.facnumber='".$this->db->escape($ref)."'"; + if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'"; + dol_syslog("Facture::Fetch sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index d4b289a2629..fd8344f8596 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -539,25 +539,26 @@ class Societe extends CommonObject /** * Load a third party from database into memory - * @param socid Id third party to load - * @param ref Name of third party (Warning, this can return several records) + * @param rowid Id of third party to load + * @param ref Reference of third party, name (Warning, this can return several records) + * @param ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) * @param idprof1 Prof id 1 of third party (Warning, this can return several records) * @param idprof2 Prof id 2 of third party (Warning, this can return several records) * @param idprof3 Prof id 3 of third party (Warning, this can return several records) * @param idprof4 Prof id 4 of third party (Warning, this can return several records) * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof. */ - function fetch($socid, $ref='',$idprof1='',$idprof2='',$idprof3='',$idprof4='') + function fetch($rowid, $ref='', $ref_ext='', $idprof1='',$idprof2='',$idprof3='',$idprof4='') { global $langs; global $conf; - if (empty($socid) && empty($ref)) return -1; + if (empty($rowid) && empty($ref) && empty($ref_ext)) return -1; - $sql = 'SELECT s.rowid, s.nom, s.entity, s.address, s.datec as dc, s.prefix_comm'; + $sql = 'SELECT s.rowid, s.nom, s.entity, s.ref_ext, s.address, s.datec as dc, s.prefix_comm'; $sql .= ', s.price_level'; $sql .= ', s.tms as date_update'; - $sql .= ', s.tel, s.fax, s.email, s.url, s.cp, s.ville, s.note, s.client, s.fournisseur'; + $sql .= ', s.tel, s.fax, s.email, s.url, s.cp as zip, s.ville as town, s.note, s.client, s.fournisseur'; $sql .= ', s.siren, s.siret, s.ape, s.idprof4'; $sql .= ', s.capital, s.tva_intra'; $sql .= ', s.fk_typent as typent_id'; @@ -580,12 +581,13 @@ class Societe extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id'; - if ($socid) $sql .= ' WHERE s.rowid = '.$socid; - if ($ref) $sql .= " WHERE s.nom = '".addslashes($ref)."' AND s.entity = ".$conf->entity; - if ($idprof1) $sql .= " WHERE s.siren = '".addslashes($siren)."' AND s.entity = ".$conf->entity; - if ($idprof2) $sql .= " WHERE s.siret = '".addslashes($siret)."' AND s.entity = ".$conf->entity; - if ($idprof3) $sql .= " WHERE s.ape = '".addslashes($ape)."' AND s.entity = ".$conf->entity; - if ($idprof4) $sql .= " WHERE s.idprof4 = '".addslashes($idprof4)."' AND s.entity = ".$conf->entity; + if ($rowid) $sql .= ' WHERE s.rowid = '.$rowid; + if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity = ".$conf->entity; + if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity = ".$conf->entity; + if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($siren)."' AND s.entity = ".$conf->entity; + if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($siret)."' AND s.entity = ".$conf->entity; + if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($ape)."' AND s.entity = ".$conf->entity; + if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity = ".$conf->entity; $resql=$this->db->query($sql); dol_syslog("Societe::fetch ".$sql); @@ -602,24 +604,28 @@ class Societe extends CommonObject { $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->entity = $obj->entity; + $this->id = $obj->rowid; + $this->entity = $obj->entity; + + $this->ref = $obj->rowid; + $this->nom = $obj->nom; // TODO obsolete + $this->name = $obj->nom; + $this->ref_ext = $obj->ref_ext; $this->datec = $this->db->jdate($obj->datec); $this->date_update = $this->db->jdate($obj->date_update); - $this->nom = $obj->nom; // TODO obsolete - $this->name = $obj->nom; - $this->address = $obj->address; $this->adresse = $obj->address; // TODO obsolete - $this->cp = $obj->cp; // TODO obsolete - $this->zip = $obj->cp; - $this->ville = $obj->ville;// TODO obsolete - $this->town = $obj->ville; + $this->address = $obj->address; + $this->cp = $obj->zip; // TODO obsolete + $this->zip = $obj->zip; + $this->ville = $obj->town;// TODO obsolete + $this->town = $obj->town; - $this->pays_id = $obj->fk_pays; - $this->pays_code = $obj->fk_pays?$obj->pays_code:''; + $this->pays_id = $obj->fk_pays; // TODO obsolete + $this->country_id = $obj->fk_pays; + $this->pays_code = $obj->fk_pays?$obj->pays_code:''; // TODO obsolete + $this->country_code = $obj->fk_pays?$obj->pays_code:''; $this->pays = $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):''; // TODO obsolete $this->country = $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):''; @@ -700,7 +706,7 @@ class Societe extends CommonObject } else { - $this->error='Societe::Fetch no third party found for id='.$socid; + $this->error='Societe::Fetch no third party found for id='.$rowid; dol_syslog($this->error, LOG_ERR); $result = -2; } diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index a0801fa78e4..f4bbe9b08b7 100755 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -112,6 +112,7 @@ $server->wsdl->addComplexType( array( 'id' => array('name'=>'id','type'=>'xsd:string'), 'ref' => array('name'=>'ref','type'=>'xsd:string'), + 'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'), 'fk_user_author' => array('name'=>'fk_user_author','type'=>'xsd:string'), 'fk_user_valid' => array('name'=>'fk_user_valid','type'=>'xsd:string'), 'date' => array('name'=>'date','type'=>'xsd:date'), @@ -172,7 +173,7 @@ $server->wsdl->addComplexType( // Register WSDL $server->register('getInvoice', // Entry values -array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string'), +array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), // Exit values array('result'=>'tns:result','invoice'=>'tns:invoice'), $ns @@ -187,13 +188,13 @@ $ns /** - * Get invoice from id + * Get invoice from id, ref or ref_ext */ -function getInvoice($authentication,$id,$ref) +function getInvoice($authentication,$id,$ref,$ref_ext) { global $db,$conf,$langs; - dol_syslog("Function: getInvoice login=".$authentication['login']." id=".$id." ref=".$ref); + dol_syslog("Function: getInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); if ($authentication['entity']) $conf->entity=$authentication['entity']; @@ -212,10 +213,10 @@ function getInvoice($authentication,$id,$ref) $errorcode='BAD_VALUE_FOR_SECURITY_KEY'; $errorlabel='Value provided into dolibarrkey entry field does not match security key defined in Webservice module setup'; } - if (! $error && $id && $ref) + if (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) { $error++; - $errorcode='BAD_PARAMETERS'; $errorlabel='Parameter id and ref can\'t be both provided. You must choose one or other but not both.'; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; } if (! $error) @@ -241,7 +242,7 @@ function getInvoice($authentication,$id,$ref) if ($fuser->rights->facture->lire) { $invoice=new Facture($db); - $result=$invoice->fetch($id,$ref); + $result=$invoice->fetch($id,$ref,$ref_ext); if ($result > 0) { $linesresp=array(); @@ -267,7 +268,8 @@ function getInvoice($authentication,$id,$ref) 'invoice'=>array( 'id' => $invoice->id, 'ref' => $invoice->ref, - 'status'=>$invoice->statut, + 'ref_ext' => $invoice->ref_ext, + 'status'=>$invoice->statut, 'fk_user_author' => $invoice->fk_user_author, 'fk_user_valid' => $invoice->fk_user_valid, 'lines' => $linesresp @@ -279,7 +281,7 @@ function getInvoice($authentication,$id,$ref) else { $error++; - $errorcode='FAILED_TO_READ'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; } } else @@ -329,7 +331,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) { $linesinvoice=array(); - $sql.='SELECT f.rowid as facid, facnumber as ref, type, fk_statut as status, total_ttc, total, tva'; + $sql.='SELECT f.rowid as facid, facnumber as ref, ref_ext, type, fk_statut as status, total_ttc, total, tva'; $sql.=' FROM '.MAIN_DB_PREFIX.'facture as f'; //$sql.=', '.MAIN_DB_PREFIX.'societe as s'; //$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid'; @@ -373,7 +375,8 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) $linesinvoice[]=array( 'id'=>$invoice->id, 'ref'=>$invoice->ref, - 'type'=>$invoice->type, + 'ref_ext'=>$invoice->ref_ext, + 'type'=>$invoice->type, 'status'=>$invoice->statut, 'total_net'=>$invoice->total_ht, 'total_vat'=>$invoice->total_tva, diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index a905e57599d..d642690fd1d 100755 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -74,7 +74,8 @@ $server->wsdl->addComplexType( '', array( 'id' => array('name'=>'id','type'=>'xsd:string'), - 'name' => array('name'=>'name','type'=>'xsd:string'), + 'ref' => array('name'=>'name','type'=>'xsd:string'), + 'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'), 'fk_user_author' => array('name'=>'fk_user_author','type'=>'xsd:string'), 'date' => array('name'=>'date','type'=>'xsd:date'), 'date_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'), @@ -84,7 +85,10 @@ $server->wsdl->addComplexType( 'zip' => array('name'=>'zip','type'=>'xsd:string'), 'town' => array('name'=>'town','type'=>'xsd:string'), 'province_id' => array('name'=>'province_id','type'=>'xsd:string'), - 'phone' => array('name'=>'country_id','type'=>'xsd:string'), + 'country_id' => array('name'=>'country_id','type'=>'xsd:string'), + 'country_code' => array('name'=>'country_code','type'=>'xsd:string'), + 'country' => array('name'=>'country','type'=>'xsd:string'), + 'phone' => array('name'=>'country_id','type'=>'xsd:string'), 'fax' => array('name'=>'country_id','type'=>'xsd:string'), 'email' => array('name'=>'country_id','type'=>'xsd:string'), 'url' => array('name'=>'country_id','type'=>'xsd:string'), @@ -113,7 +117,7 @@ $server->wsdl->addComplexType( // Register WSDL $server->register('getThirdParty', // Entry values -array('authentication'=>'tns:authentication','id'=>'xsd:string','name'=>'xsd:string'), +array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), // Exit values array('result'=>'tns:result','thirdparty'=>'tns:thirdparty'), $ns @@ -121,11 +125,11 @@ $ns // Full methods code -function getThirdParty($authentication,$id,$name) +function getThirdParty($authentication,$id,$ref,$ref_ext) { global $db,$conf,$langs; - dol_syslog("Function: getThirdParty login=".$authentication['login']." id=".$id." name=".$name); + dol_syslog("Function: getThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); if ($authentication['entity']) $conf->entity=$authentication['entity']; @@ -144,10 +148,10 @@ function getThirdParty($authentication,$id,$name) $errorcode='BAD_VALUE_FOR_SECURITY_KEY'; $errorlabel='Value provided into dolibarrkey entry field does not match security key defined in Webservice module setup'; } - if (! $error && $id && $name) + if (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) { $error++; - $errorcode='BAD_PARAMETERS'; $errorlabel='Parameter id and ref can\'t be both provided. You must choose one or other but not both.'; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; } if (! $error) @@ -170,10 +174,10 @@ function getThirdParty($authentication,$id,$name) { $fuser->getrights(); - if ($fuser->rights->facture->lire) + if ($fuser->rights->societe->lire) { $thirdparty=new Societe($db); - $result=$thirdparty->fetch($id,$name); + $result=$thirdparty->fetch($id,$ref,$ref_ext); if ($result > 0) { // Create @@ -181,8 +185,9 @@ function getThirdParty($authentication,$id,$name) 'result'=>array('result_code'=>'', 'result_label'=>''), 'thirdparty'=>array( 'id' => $thirdparty->id, - 'name' => $thirdparty->name, - 'fk_user_author' => $thirdparty->fk_user_author, + 'ref' => $thirdparty->name, + 'ref_ext' => $thirdparty->ref_ext, + 'fk_user_author' => $thirdparty->fk_user_author, // 'date_creation' => $thirdparty-> // 'date_modification' => $thirdparty-> 'address' => $thirdparty->address, @@ -190,7 +195,9 @@ function getThirdParty($authentication,$id,$name) 'town' => $thirdparty->ville, 'province_id' => $thirdparty->departement_id, 'country_id' => $thirdparty->pays_id, - 'phone' => $thirdparty->tel, + 'country_code' => $thirdparty->pays_code, + 'country' => $thirdparty->country, + 'phone' => $thirdparty->tel, 'fax' => $thirdparty->fax, 'email' => $thirdparty->email, 'url' => $thirdparty->url, @@ -206,7 +213,7 @@ function getThirdParty($authentication,$id,$name) else { $error++; - $errorcode='FAILED_TO_READ'; $errorlabel='Object not found for id='.$id.' nor name='.$name; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; } } else