2010-12-01 20:55:20 +01:00
< ? php
/* Copyright ( C ) 2006 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2010-12-01 20:55:20 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:19:04 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2010-12-01 20:55:20 +01:00
*/
/**
* \file htdocs / webservices / server_thirdparty . php
* \brief File that is entry point to call Dolibarr WebServices
*/
// This is to make Dolibarr working with Plesk
set_include_path ( $_SERVER [ 'DOCUMENT_ROOT' ] . '/htdocs' );
2012-08-22 23:11:24 +02:00
require_once '../master.inc.php' ;
require_once NUSOAP_PATH . '/nusoap.php' ; // Include SOAP
require_once DOL_DOCUMENT_ROOT . '/core/lib/ws.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2011-06-01 20:19:40 +02:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2012-12-08 13:30:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2010-12-01 20:55:20 +01:00
dol_syslog ( " Call Dolibarr webservices interfaces " );
2012-07-22 12:13:53 +02:00
$langs -> load ( " main " );
2010-12-01 20:55:20 +01:00
// Enable and test if module web services is enabled
if ( empty ( $conf -> global -> MAIN_MODULE_WEBSERVICES ))
{
$langs -> load ( " admin " );
dol_syslog ( " Call Dolibarr webservices interfaces with module webservices disabled " );
print $langs -> trans ( " WarningModuleNotActive " , 'WebServices' ) . '.<br><br>' ;
print $langs -> trans ( " ToActivateModule " );
exit ;
}
// Create the soap Object
2010-12-13 21:42:04 +01:00
$server = new nusoap_server ();
2010-12-01 20:55:20 +01:00
$server -> soap_defencoding = 'UTF-8' ;
2011-03-18 11:08:36 +01:00
$server -> decode_utf8 = false ;
2010-12-19 12:49:37 +01:00
$ns = 'http://www.dolibarr.org/ns/' ;
2010-12-01 20:55:20 +01:00
$server -> configureWSDL ( 'WebServicesDolibarrThirdParty' , $ns );
$server -> wsdl -> schemaTargetNamespace = $ns ;
2011-10-01 01:30:32 +02:00
// Define WSDL Authentication object
2010-12-01 20:55:20 +01:00
$server -> wsdl -> addComplexType (
2011-10-01 01:30:32 +02:00
'authentication' ,
'complexType' ,
'struct' ,
'all' ,
'' ,
array (
'dolibarrkey' => array ( 'name' => 'dolibarrkey' , 'type' => 'xsd:string' ),
'sourceapplication' => array ( 'name' => 'sourceapplication' , 'type' => 'xsd:string' ),
'login' => array ( 'name' => 'login' , 'type' => 'xsd:string' ),
'password' => array ( 'name' => 'password' , 'type' => 'xsd:string' ),
'entity' => array ( 'name' => 'entity' , 'type' => 'xsd:string' ),
)
);
// Define WSDL Return object
2010-12-01 20:55:20 +01:00
$server -> wsdl -> addComplexType (
2011-10-01 01:30:32 +02:00
'result' ,
'complexType' ,
'struct' ,
'all' ,
'' ,
array (
'result_code' => array ( 'name' => 'result_code' , 'type' => 'xsd:string' ),
'result_label' => array ( 'name' => 'result_label' , 'type' => 'xsd:string' ),
)
);
2010-12-01 20:55:20 +01:00
2012-12-08 13:30:39 +01:00
$thirdparty_fields = array (
2011-10-01 01:30:32 +02:00
'id' => array ( 'name' => 'id' , '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' ),
2012-11-05 03:45:54 +01:00
'status' => array ( 'name' => 'status' , 'type' => 'xsd:string' ),
2012-06-25 13:06:26 +02:00
'client' => array ( 'name' => 'client' , 'type' => 'xsd:string' ),
'supplier' => array ( 'name' => 'supplier' , 'type' => 'xsd:string' ),
'customer_code' => array ( 'name' => 'customer_code' , 'type' => 'xsd:string' ),
'supplier_code' => array ( 'name' => 'supplier_code' , 'type' => 'xsd:string' ),
'customer_code_accountancy' => array ( 'name' => 'customer_code_accountancy' , 'type' => 'xsd:string' ),
'supplier_code_accountancy' => array ( 'name' => 'supplier_code_accountancy' , 'type' => 'xsd:string' ),
2011-10-01 01:30:32 +02:00
'date_creation' => array ( 'name' => 'date_creation' , 'type' => 'xsd:dateTime' ),
'date_modification' => array ( 'name' => 'date_modification' , 'type' => 'xsd:dateTime' ),
2013-04-09 17:18:07 +02:00
'note_private' => array ( 'name' => 'note_private' , 'type' => 'xsd:string' ),
'note_public' => array ( 'name' => 'note_public' , 'type' => 'xsd:string' ),
2011-10-01 01:30:32 +02:00
'address' => array ( 'name' => 'address' , 'type' => 'xsd:string' ),
'zip' => array ( 'name' => 'zip' , 'type' => 'xsd:string' ),
'town' => array ( 'name' => 'town' , 'type' => 'xsd:string' ),
'province_id' => array ( 'name' => 'province_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' ),
2012-07-12 11:58:44 +02:00
'phone' => array ( 'name' => 'phone' , 'type' => 'xsd:string' ),
'fax' => array ( 'name' => 'fax' , 'type' => 'xsd:string' ),
'email' => array ( 'name' => 'email' , 'type' => 'xsd:string' ),
'url' => array ( 'name' => 'url' , 'type' => 'xsd:string' ),
2011-10-01 01:30:32 +02:00
'profid1' => array ( 'name' => 'profid1' , 'type' => 'xsd:string' ),
'profid2' => array ( 'name' => 'profid2' , 'type' => 'xsd:string' ),
'profid3' => array ( 'name' => 'profid3' , 'type' => 'xsd:string' ),
'profid4' => array ( 'name' => 'profid4' , 'type' => 'xsd:string' ),
2012-06-25 13:06:26 +02:00
'profid5' => array ( 'name' => 'profid5' , 'type' => 'xsd:string' ),
'profid6' => array ( 'name' => 'profid6' , 'type' => 'xsd:string' ),
'capital' => array ( 'name' => 'capital' , 'type' => 'xsd:string' ),
2011-10-01 01:30:32 +02:00
'vat_used' => array ( 'name' => 'vat_used' , 'type' => 'xsd:string' ),
2012-12-08 13:30:39 +01:00
'vat_number' => array ( 'name' => 'vat_number' , 'type' => 'xsd:string' ));
//Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels
$extrafields = new ExtraFields ( $db );
2013-04-26 10:29:14 +02:00
$extralabels = $extrafields -> fetch_name_optionals_label ( 'societe' , true );
2012-12-13 12:34:00 +01:00
if ( count ( $extrafields ) > 0 ) {
$extrafield_array = array ();
}
2012-12-08 13:30:39 +01:00
foreach ( $extrafields -> attribute_label as $key => $label )
{
//$value=$object->array_options["options_".$key];
$type = $extrafields -> attribute_type [ $key ];
if ( $type == 'date' || $type == 'datetime' ) { $type = 'xsd:dateTime' ;}
else { $type = 'xsd:string' ;}
2012-12-13 12:34:00 +01:00
$extrafield_array [ 'options_' . $key ] = array ( 'name' => 'options_' . $key , 'type' => $type );
2012-12-08 13:30:39 +01:00
}
$thirdparty_fields = array_merge ( $thirdparty_fields , $extrafield_array );
// Define other specific objects
$server -> wsdl -> addComplexType (
'thirdparty' ,
'complexType' ,
'struct' ,
'all' ,
'' ,
$thirdparty_fields
2011-10-01 01:30:32 +02:00
);
2010-12-01 20:55:20 +01:00
2012-07-02 19:30:37 +02:00
// Define other specific objects
$server -> wsdl -> addComplexType (
'filterthirdparty' ,
'complexType' ,
'struct' ,
'all' ,
'' ,
array (
//'limit' => array('name'=>'limit','type'=>'xsd:string'),
'client' => array ( 'name' => 'client' , 'type' => 'xsd:string' ),
2013-08-15 10:39:59 +02:00
'supplier' => array ( 'name' => 'supplier' , 'type' => 'xsd:string' ),
'category' => array ( 'name' => 'category' , 'type' => 'xsd:string' )
2012-07-02 19:30:37 +02:00
)
2012-06-25 13:06:26 +02:00
);
2012-07-02 19:30:37 +02:00
$server -> wsdl -> addComplexType (
'ThirdPartiesArray' ,
'complexType' ,
'array' ,
'' ,
'SOAP-ENC:Array' ,
array (),
array (
array ( 'ref' => 'SOAP-ENC:arrayType' , 'wsdl:arrayType' => 'tns:thirdparty[]' )
),
'tns:thirdparty'
);
$server -> wsdl -> addComplexType (
'ThirdPartiesArray2' ,
'complexType' ,
'array' ,
'sequence' ,
'' ,
array (
'thirdparty' => array (
'name' => 'thirdparty' ,
'type' => 'tns:thirdparty' ,
'minOccurs' => '0' ,
'maxOccurs' => 'unbounded'
)
)
2012-06-25 13:06:26 +02:00
);
2010-12-01 20:55:20 +01:00
2011-05-04 17:19:38 +02:00
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
$styledoc = 'rpc' ; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
$styleuse = 'encoded' ; // encoded/literal/literal wrapped
// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
2010-12-01 20:55:20 +01:00
// Register WSDL
2011-10-01 01:30:32 +02:00
$server -> register (
'getThirdParty' ,
// Entry values
array ( 'authentication' => 'tns:authentication' , 'id' => 'xsd:string' , 'ref' => 'xsd:string' , 'ref_ext' => 'xsd:string' ),
// Exit values
array ( 'result' => 'tns:result' , 'thirdparty' => 'tns:thirdparty' ),
$ns ,
2012-06-25 13:06:26 +02:00
$ns . '#getThirdParty' ,
2011-10-01 01:30:32 +02:00
$styledoc ,
$styleuse ,
2012-06-25 13:06:26 +02:00
'WS to get a thirdparty from its id, ref or ref_ext'
2010-12-01 20:55:20 +01:00
);
2012-07-02 19:30:37 +02:00
// Register WSDL
$server -> register (
'createThirdParty' ,
// Entry values
array ( 'authentication' => 'tns:authentication' , 'thirdparty' => 'tns:thirdparty' ),
// Exit values
2013-01-10 23:30:26 +01:00
array ( 'result' => 'tns:result' , 'id' => 'xsd:string' , 'ref' => 'xsd:string' ),
2012-07-02 19:30:37 +02:00
$ns ,
$ns . '#createThirdParty' ,
$styledoc ,
$styleuse ,
'WS to create a thirdparty'
2012-06-25 13:06:26 +02:00
);
2013-01-10 23:30:26 +01:00
// Register WSDL
$server -> register (
'updateThirdParty' ,
// Entry values
array ( 'authentication' => 'tns:authentication' , 'thirdparty' => 'tns:thirdparty' ),
// Exit values
2013-01-17 18:49:21 +01:00
array ( 'result' => 'tns:result' , 'id' => 'xsd:string' ),
2013-01-10 23:30:26 +01:00
$ns ,
$ns . '#updateThirdParty' ,
$styledoc ,
$styleuse ,
'WS to update a thirdparty'
);
2012-07-02 19:30:37 +02:00
// Register WSDL
$server -> register (
'getListOfThirdParties' ,
// Entry values
array ( 'authentication' => 'tns:authentication' , 'filterthirdparty' => 'tns:filterthirdparty' ),
// Exit values
array ( 'result' => 'tns:result' , 'thirdparties' => 'tns:ThirdPartiesArray2' ),
$ns ,
$ns . '#getListOfThirdParties' ,
$styledoc ,
$styleuse ,
'WS to get list of thirdparties id and ref'
2012-06-25 13:06:26 +02:00
);
2010-12-01 20:55:20 +01:00
2011-05-04 17:19:38 +02:00
2010-12-01 20:55:20 +01:00
// Full methods code
2011-03-18 11:08:36 +01:00
function getThirdParty ( $authentication , $id = '' , $ref = '' , $ref_ext = '' )
2010-12-01 20:55:20 +01:00
{
global $db , $conf , $langs ;
2010-12-07 09:36:50 +01:00
dol_syslog ( " Function: getThirdParty login= " . $authentication [ 'login' ] . " id= " . $id . " ref= " . $ref . " ref_ext= " . $ref_ext );
2010-12-01 20:55:20 +01:00
if ( $authentication [ 'entity' ]) $conf -> entity = $authentication [ 'entity' ];
2011-06-01 20:19:40 +02:00
// Init and check authentication
$objectresp = array ();
$errorcode = '' ; $errorlabel = '' ;
$error = 0 ;
2011-06-15 15:45:07 +02:00
$fuser = check_authentication ( $authentication , $error , $errorcode , $errorlabel );
2011-06-01 20:19:40 +02:00
// Check parameters
2010-12-07 09:36:50 +01:00
if ( ! $error && (( $id && $ref ) || ( $id && $ref_ext ) || ( $ref && $ref_ext )))
2010-12-01 20:55:20 +01:00
{
$error ++ ;
2010-12-07 09:36:50 +01:00
$errorcode = 'BAD_PARAMETERS' ; $errorlabel = " Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both. " ;
2010-12-01 20:55:20 +01:00
}
if ( ! $error )
{
$fuser -> getrights ();
2010-12-07 09:36:50 +01:00
if ( $fuser -> rights -> societe -> lire )
2010-12-01 20:55:20 +01:00
{
$thirdparty = new Societe ( $db );
2010-12-07 09:36:50 +01:00
$result = $thirdparty -> fetch ( $id , $ref , $ref_ext );
2010-12-01 20:55:20 +01:00
if ( $result > 0 )
{
2012-12-13 12:34:00 +01:00
$thirdparty_result_fields = array (
2010-12-01 20:55:20 +01:00
'id' => $thirdparty -> id ,
2010-12-07 09:36:50 +01:00
'ref' => $thirdparty -> name ,
'ref_ext' => $thirdparty -> ref_ext ,
2012-06-25 13:06:26 +02:00
'status' => $thirdparty -> status ,
'client' => $thirdparty -> client ,
'supplier' => $thirdparty -> fournisseur ,
'customer_code' => $thirdparty -> code_client ,
'supplier_code' => $thirdparty -> code_fournisseur ,
'customer_code_accountancy' => $thirdparty -> code_compta ,
'supplier_code_accountancy' => $thirdparty -> code_compta_fournisseur ,
'fk_user_author' => $thirdparty -> fk_user_author ,
2011-10-18 15:55:06 +02:00
'date_creation' => dol_print_date ( $thirdparty -> datec , 'dayhourrfc' ),
'date_modification' => dol_print_date ( $thirdparty -> date_update , 'dayhourrfc' ),
2010-12-01 20:55:20 +01:00
'address' => $thirdparty -> address ,
2011-08-19 00:25:46 +02:00
'zip' => $thirdparty -> zip ,
'town' => $thirdparty -> town ,
'province_id' => $thirdparty -> state_id ,
'country_id' => $thirdparty -> country_id ,
'country_code' => $thirdparty -> country_code ,
2010-12-07 09:36:50 +01:00
'country' => $thirdparty -> country ,
2013-09-25 19:58:22 +02:00
'phone' => $thirdparty -> phone ,
2010-12-01 20:55:20 +01:00
'fax' => $thirdparty -> fax ,
'email' => $thirdparty -> email ,
'url' => $thirdparty -> url ,
2011-12-28 17:30:30 +01:00
'profid1' => $thirdparty -> idprof1 ,
'profid2' => $thirdparty -> idprof2 ,
'profid3' => $thirdparty -> idprof3 ,
2010-12-01 20:55:20 +01:00
'profid4' => $thirdparty -> idprof4 ,
2012-06-25 13:06:26 +02:00
'profid5' => $thirdparty -> idprof5 ,
'profid6' => $thirdparty -> idprof6 ,
'capital' => $thirdparty -> capital ,
'barcode' => $thirdparty -> barcode ,
'vat_used' => $thirdparty -> tva_assuj ,
2013-04-09 17:18:07 +02:00
'vat_number' => $thirdparty -> tva_intra ,
'note_private' => $thirdparty -> note_private ,
'note_public' => $thirdparty -> note_public );
2012-12-13 12:34:00 +01:00
//Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels
$extrafields = new ExtraFields ( $db );
2013-04-26 10:29:14 +02:00
$extralabels = $extrafields -> fetch_name_optionals_label ( 'societe' , true );
2012-12-13 12:34:00 +01:00
//Get extrafield values
$thirdparty -> fetch_optionals ( $thirdparty -> id , $extralabels );
foreach ( $extrafields -> attribute_label as $key => $label )
{
$thirdparty_result_fields = array_merge ( $thirdparty_result_fields , array ( 'options_' . $key => $thirdparty -> array_options [ 'options_' . $key ]));
}
// Create
$objectresp = array (
'result' => array ( 'result_code' => 'OK' , 'result_label' => '' ),
'thirdparty' => $thirdparty_result_fields );
2010-12-01 20:55:20 +01:00
}
else
{
$error ++ ;
2010-12-07 09:36:50 +01:00
$errorcode = 'NOT_FOUND' ; $errorlabel = 'Object not found for id=' . $id . ' nor ref=' . $ref . ' nor ref_ext=' . $ref_ext ;
2010-12-01 20:55:20 +01:00
}
}
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 ;
}
2012-07-02 19:30:37 +02:00
/**
* Create a thirdparty
*
* @ param array $authentication Array of authentication information
* @ param Societe $thirdparty Thirdparty
* @ return array Array result
*/
function createThirdParty ( $authentication , $thirdparty )
{
global $db , $conf , $langs ;
$now = dol_now ();
dol_syslog ( " Function: createThirdParty login= " . $authentication [ 'login' ]);
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 ( $thirdparty [ 'ref' ]))
{
$error ++ ; $errorcode = 'KO' ; $errorlabel = " Name is mandatory. " ;
}
if ( ! $error )
{
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2012-07-02 19:30:37 +02:00
$newobject = new Societe ( $db );
$newobject -> ref = $thirdparty [ 'ref' ];
2012-06-25 13:06:26 +02:00
$newobject -> name = $thirdparty [ 'ref' ];
2012-07-02 19:30:37 +02:00
$newobject -> ref_ext = $thirdparty [ 'ref_ext' ];
2012-06-25 13:06:26 +02:00
$newobject -> status = $thirdparty [ 'status' ];
2012-07-02 19:30:37 +02:00
$newobject -> client = $thirdparty [ 'client' ];
2012-06-25 13:06:26 +02:00
$newobject -> fournisseur = $thirdparty [ 'supplier' ];
$newobject -> code_client = $thirdparty [ 'customer_code' ];
$newobject -> code_fournisseur = $thirdparty [ 'supplier_code' ];
$newobject -> code_compta = $thirdparty [ 'customer_code_accountancy' ];
$newobject -> code_compta_fournisseur = $thirdparty [ 'supplier_code_accountancy' ];
2012-07-02 19:30:37 +02:00
$newobject -> date_creation = $now ;
2013-04-09 17:18:07 +02:00
$newobject -> note_private = $thirdparty [ 'note_private' ];
$newobject -> note_public = $thirdparty [ 'note_public' ];
2012-07-02 19:30:37 +02:00
$newobject -> address = $thirdparty [ 'address' ];
$newobject -> zip = $thirdparty [ 'zip' ];
$newobject -> town = $thirdparty [ 'town' ];
$newobject -> country_id = $thirdparty [ 'country_id' ];
if ( $thirdparty [ 'country_code' ]) $newobject -> country_id = getCountry ( $thirdparty [ 'country_code' ], 3 );
$newobject -> province_id = $thirdparty [ 'province_id' ];
//if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3);
2012-06-25 13:06:26 +02:00
$newobject -> phone = $thirdparty [ 'phone' ];
$newobject -> fax = $thirdparty [ 'fax' ];
$newobject -> email = $thirdparty [ 'email' ];
$newobject -> url = $thirdparty [ 'url' ];
2012-07-02 19:30:37 +02:00
$newobject -> idprof1 = $thirdparty [ 'profid1' ];
$newobject -> idprof2 = $thirdparty [ 'profid2' ];
$newobject -> idprof3 = $thirdparty [ 'profid3' ];
$newobject -> idprof4 = $thirdparty [ 'profid4' ];
$newobject -> idprof5 = $thirdparty [ 'profid5' ];
$newobject -> idprof6 = $thirdparty [ 'profid6' ];
2012-06-25 13:06:26 +02:00
$newobject -> capital = $thirdparty [ 'capital' ];
$newobject -> barcode = $thirdparty [ 'barcode' ];
2012-07-02 19:30:37 +02:00
$newobject -> tva_assuj = $thirdparty [ 'vat_used' ];
$newobject -> tva_intra = $thirdparty [ 'vat_number' ];
$newobject -> canvas = $thirdparty [ 'canvas' ];
2013-12-20 17:03:24 +01:00
$newobject -> particulier = $thirdparty [ 'individual' ];
2012-12-13 12:34:00 +01:00
//Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels
$extrafields = new ExtraFields ( $db );
2013-04-26 10:29:14 +02:00
$extralabels = $extrafields -> fetch_name_optionals_label ( 'societe' , true );
2012-12-13 12:34:00 +01:00
foreach ( $extrafields -> attribute_label as $key => $label )
{
$key = 'options_' . $key ;
$newobject -> array_options [ $key ] = $thirdparty [ $key ];
}
2012-07-02 19:30:37 +02:00
$db -> begin ();
$result = $newobject -> create ( $fuser );
2013-12-20 17:03:24 +01:00
if ( $newobject -> particulier && $result > 0 ) {
$newobject -> firstname = $thirdparty [ 'firstname' ];
$newobject -> name_bis = $thirdparty [ 'ref' ];
$result = $newobject -> create_individual ( $fuser );
}
2012-07-02 19:30:37 +02:00
if ( $result <= 0 )
{
$error ++ ;
}
if ( ! $error )
{
$db -> commit ();
$objectresp = array ( 'result' => array ( 'result_code' => 'OK' , 'result_label' => '' ), 'id' => $newobject -> id , 'ref' => $newobject -> ref );
}
else
{
$db -> rollback ();
$error ++ ;
$errorcode = 'KO' ;
$errorlabel = $newobject -> error ;
}
}
if ( $error )
{
$objectresp = array ( 'result' => array ( 'result_code' => $errorcode , 'result_label' => $errorlabel ));
}
return $objectresp ;
}
2013-01-10 23:30:26 +01:00
/**
* Update a thirdparty
*
* @ param array $authentication Array of authentication information
* @ param Societe $thirdparty Thirdparty
* @ return array Array result
*/
function updateThirdParty ( $authentication , $thirdparty )
{
global $db , $conf , $langs ;
$now = dol_now ();
dol_syslog ( " Function: updateThirdParty login= " . $authentication [ 'login' ]);
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 ( $thirdparty [ 'id' ])) {
$error ++ ; $errorcode = 'KO' ; $errorlabel = " Thirdparty id is mandatory. " ;
}
if ( ! $error )
{
$objectfound = false ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
$object = new Societe ( $db );
2013-01-15 21:43:11 +01:00
$result = $object -> fetch ( $thirdparty [ 'id' ]);
2013-01-10 23:30:26 +01:00
2013-01-15 21:43:11 +01:00
if ( ! empty ( $object -> id )) {
2013-01-10 23:30:26 +01:00
$objectfound = true ;
$object -> ref = $thirdparty [ 'ref' ];
$object -> name = $thirdparty [ 'ref' ];
$object -> ref_ext = $thirdparty [ 'ref_ext' ];
$object -> status = $thirdparty [ 'status' ];
$object -> client = $thirdparty [ 'client' ];
$object -> fournisseur = $thirdparty [ 'supplier' ];
$object -> code_client = $thirdparty [ 'customer_code' ];
$object -> code_fournisseur = $thirdparty [ 'supplier_code' ];
$object -> code_compta = $thirdparty [ 'customer_code_accountancy' ];
$object -> code_compta_fournisseur = $thirdparty [ 'supplier_code_accountancy' ];
$object -> date_creation = $now ;
2013-04-09 17:18:07 +02:00
$object -> note_private = $thirdparty [ 'note_private' ];
$object -> note_public = $thirdparty [ 'note_public' ];
2013-01-10 23:30:26 +01:00
$object -> address = $thirdparty [ 'address' ];
$object -> zip = $thirdparty [ 'zip' ];
$object -> town = $thirdparty [ 'town' ];
$object -> country_id = $thirdparty [ 'country_id' ];
if ( $thirdparty [ 'country_code' ]) $object -> country_id = getCountry ( $thirdparty [ 'country_code' ], 3 );
$object -> province_id = $thirdparty [ 'province_id' ];
//if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3);
$object -> phone = $thirdparty [ 'phone' ];
$object -> fax = $thirdparty [ 'fax' ];
$object -> email = $thirdparty [ 'email' ];
$object -> url = $thirdparty [ 'url' ];
$object -> idprof1 = $thirdparty [ 'profid1' ];
$object -> idprof2 = $thirdparty [ 'profid2' ];
$object -> idprof3 = $thirdparty [ 'profid3' ];
$object -> idprof4 = $thirdparty [ 'profid4' ];
$object -> idprof5 = $thirdparty [ 'profid5' ];
$object -> idprof6 = $thirdparty [ 'profid6' ];
$object -> capital = $thirdparty [ 'capital' ];
$object -> barcode = $thirdparty [ 'barcode' ];
$object -> tva_assuj = $thirdparty [ 'vat_used' ];
$object -> tva_intra = $thirdparty [ 'vat_number' ];
$object -> canvas = $thirdparty [ 'canvas' ];
//Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels
$extrafields = new ExtraFields ( $db );
2013-04-26 10:29:14 +02:00
$extralabels = $extrafields -> fetch_name_optionals_label ( 'societe' , true );
2013-01-10 23:30:26 +01:00
foreach ( $extrafields -> attribute_label as $key => $label )
{
$key = 'options_' . $key ;
$object -> array_options [ $key ] = $thirdparty [ $key ];
}
$db -> begin ();
2013-01-17 18:03:10 +01:00
$result = $object -> update ( $thirdparty [ 'id' ], $fuser );
2013-01-10 23:30:26 +01:00
if ( $result <= 0 ) {
$error ++ ;
}
}
if (( ! $error ) && ( $objectfound ))
{
$db -> commit ();
2013-01-17 18:49:21 +01:00
$objectresp = array (
'result' => array ( 'result_code' => 'OK' , 'result_label' => '' ),
'id' => $object -> id
);
2013-01-10 23:30:26 +01:00
}
elseif ( $objectfound )
{
$db -> rollback ();
$error ++ ;
$errorcode = 'KO' ;
$errorlabel = $object -> error ;
} else {
$error ++ ;
$errorcode = 'NOT_FOUND' ;
$errorlabel = 'Thirdparty id=' . $thirdparty [ 'id' ] . ' cannot be found' ;
}
}
if ( $error )
{
$objectresp = array ( 'result' => array ( 'result_code' => $errorcode , 'result_label' => $errorlabel ));
}
return $objectresp ;
}
2012-07-02 19:30:37 +02:00
/**
* getListOfThirdParties
*
* @ param array $authentication Array of authentication information
* @ param array $filterthirdparty Filter fields
* @ return array Array result
*/
function getListOfThirdParties ( $authentication , $filterthirdparty )
{
global $db , $conf , $langs ;
$now = dol_now ();
dol_syslog ( " Function: getListOfThirdParties login= " . $authentication [ 'login' ]);
if ( $authentication [ 'entity' ]) $conf -> entity = $authentication [ 'entity' ];
// Init and check authentication
$objectresp = array ();
$arraythirdparties = array ();
$errorcode = '' ; $errorlabel = '' ;
$error = 0 ;
$fuser = check_authentication ( $authentication , $error , $errorcode , $errorlabel );
// Check parameters
if ( ! $error )
{
2013-08-15 10:39:59 +02:00
$sql = " SELECT s.rowid, s.nom as ref, s.ref_ext, s.address, s.zip, s.town, p.libelle as country, s.phone, s.fax, s.url " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_pays as p ON s.fk_pays = p.rowid' ;
2012-07-02 19:30:37 +02:00
$sql .= " WHERE entity= " . $conf -> entity ;
foreach ( $filterthirdparty as $key => $val )
{
2013-08-15 10:39:59 +02:00
if ( $key == 'client' && $val != '' ) $sql .= " AND s.client = " . $db -> escape ( $val );
2013-08-15 12:50:16 +02:00
if ( $key == 'supplier' && $val != '' ) $sql .= " AND s.fournisseur = " . $db -> escape ( $val );
2013-08-15 10:39:59 +02:00
if ( $key == 'category' && $val != '' ) $sql .= " AND s.rowid IN (SELECT fk_societe FROM " . MAIN_DB_PREFIX . " categorie_societe WHERE fk_categorie= " . $db -> escape ( $val ) . " ) " ;
2012-07-02 19:30:37 +02:00
}
2013-08-15 10:39:59 +02:00
dol_syslog ( " Function: getListOfThirdParties sql= " . $sql );
2012-07-02 19:30:37 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
2013-08-15 10:39:59 +02:00
$arraythirdparties [] = array ( 'id' => $obj -> rowid ,
'ref' => $obj -> ref ,
'ref_ext' => $obj -> ref_ext ,
'adress' => $obj -> adress ,
'zip' => $obj -> zip ,
'town' => $obj -> town ,
'country' => $obj -> country ,
'phone' => $obj -> phone ,
'fax' => $obj -> fax ,
'url' => $obj -> url
);
2012-07-02 19:30:37 +02:00
$i ++ ;
}
}
else
{
$error ++ ;
$errorcode = $db -> lasterrno ();
$errorlabel = $db -> lasterror ();
}
}
if ( $error )
{
$objectresp = array (
'result' => array ( 'result_code' => $errorcode , 'result_label' => $errorlabel ),
'thirdparties' => $arraythirdparties
);
}
else
{
$objectresp = array (
'result' => array ( 'result_code' => 'OK' , 'result_label' => '' ),
'thirdparties' => $arraythirdparties
);
}
return $objectresp ;
2012-06-25 13:06:26 +02:00
}
2012-07-02 19:30:37 +02:00
2010-12-01 20:55:20 +01:00
// Return the results.
$server -> service ( $HTTP_RAW_POST_DATA );