23if (!defined(
'NOCSRFCHECK')) {
24 define(
'NOCSRFCHECK',
'1');
26if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL',
'1');
29if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32if (!defined(
'NOREQUIREHTML')) {
33 define(
'NOREQUIREHTML',
'1');
35if (!defined(
'NOREQUIREAJAX')) {
36 define(
'NOREQUIREAJAX',
'1');
38if (!defined(
"NOLOGIN")) {
39 define(
"NOLOGIN",
'1');
41if (!defined(
"NOSESSION")) {
42 define(
"NOSESSION",
'1');
45require
'../main.inc.php';
46require_once NUSOAP_PATH.
'/nusoap.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
52dol_syslog(
"Call Dolibarr webservices interfaces");
57if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
58 $langs->load(
"admin");
59 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
60 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
61 print $langs->trans(
"ToActivateModule");
66$server =
new nusoap_server();
67$server->soap_defencoding =
'UTF-8';
68$server->decode_utf8 =
false;
69$ns =
'http://www.dolibarr.org/ns/';
70$server->configureWSDL(
'WebServicesDolibarrSupplierInvoice', $ns);
71$server->wsdl->schemaTargetNamespace = $ns;
75$server->wsdl->addComplexType(
82 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
83 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
84 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
85 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
86 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
90$server->wsdl->addComplexType(
97 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
98 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
103$server->wsdl->addComplexType(
110 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
111 'type' => array(
'name'=>
'type',
'type'=>
'xsd:int'),
112 'desc' => array(
'name'=>
'desc',
'type'=>
'xsd:string'),
113 'fk_product' => array(
'name'=>
'fk_product',
'type'=>
'xsd:int'),
114 'total_net' => array(
'name'=>
'total_net',
'type'=>
'xsd:double'),
115 'total_vat' => array(
'name'=>
'total_vat',
'type'=>
'xsd:double'),
116 'total' => array(
'name'=>
'total',
'type'=>
'xsd:double'),
117 'vat_rate' => array(
'name'=>
'vat_rate',
'type'=>
'xsd:double'),
118 'qty' => array(
'name'=>
'qty',
'type'=>
'xsd:double'),
119 'date_start' => array(
'name'=>
'date_start',
'type'=>
'xsd:date'),
120 'date_end' => array(
'name'=>
'date_end',
'type'=>
'xsd:date'),
122 'product_ref' => array(
'name'=>
'product_ref',
'type'=>
'xsd:string'),
123 'product_label' => array(
'name'=>
'product_label',
'type'=>
'xsd:string'),
124 'product_desc' => array(
'name'=>
'product_desc',
'type'=>
'xsd:string')
128$server->wsdl->addComplexType(
136 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:line[]')
141$server->wsdl->addComplexType(
148 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
149 'ref' => array(
'name'=>
'ref',
'type'=>
'xsd:string'),
150 'ref_ext' => array(
'name'=>
'ref_ext',
'type'=>
'xsd:string'),
151 'ref_supplier' => array(
'name'=>
'ref_supplier',
'type'=>
'xsd:string'),
152 'fk_user_author' => array(
'name'=>
'fk_user_author',
'type'=>
'xsd:int'),
153 'fk_user_valid' => array(
'name'=>
'fk_user_valid',
'type'=>
'xsd:int'),
154 'fk_thirdparty' => array(
'name'=>
'fk_thirdparty',
'type'=>
'xsd:int'),
155 'date_creation' => array(
'name'=>
'date_creation',
'type'=>
'xsd:dateTime'),
156 'date_validation' => array(
'name'=>
'date_validation',
'type'=>
'xsd:dateTime'),
157 'date_modification' => array(
'name'=>
'date_modification',
'type'=>
'xsd:dateTime'),
158 'date_invoice' => array(
'name'=>
'date_invoice',
'type'=>
'xsd:date'),
159 'date_term' => array(
'name'=>
'date_modification',
'type'=>
'xsd:date'),
160 'label' => array(
'name'=>
'label',
'type'=>
'xsd:date'),
161 'type' => array(
'name'=>
'type',
'type'=>
'xsd:int'),
162 'total_net' => array(
'name'=>
'type',
'type'=>
'xsd:double'),
163 'total_vat' => array(
'name'=>
'type',
'type'=>
'xsd:double'),
164 'total' => array(
'name'=>
'type',
'type'=>
'xsd:double'),
165 'note_private' => array(
'name'=>
'note_private',
'type'=>
'xsd:string'),
166 'note_public' => array(
'name'=>
'note_public',
'type'=>
'xsd:string'),
167 'status' => array(
'name'=>
'status',
'type'=>
'xsd:int'),
168 'close_code' => array(
'name'=>
'close_code',
'type'=>
'xsd:string'),
169 'close_note' => array(
'name'=>
'close_note',
'type'=>
'xsd:string'),
170 'lines' => array(
'name'=>
'lines',
'type'=>
'tns:LinesArray')
174$server->wsdl->addComplexType(
182 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:invoice[]')
187$server->wsdl->addComplexType(
195 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:invoice[]')
206$styleuse =
'encoded';
211 'getSupplierInvoice',
213 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string',
'ref_ext'=>
'xsd:string'),
215 array(
'result'=>
'tns:result',
'invoice'=>
'tns:invoice'),
217 $ns.
'#getSupplierInvoice',
220 'WS to get SupplierInvoice'
223 'getSupplierInvoicesForThirdParty',
225 array(
'authentication'=>
'tns:authentication',
'idthirdparty'=>
'xsd:string'),
227 array(
'result'=>
'tns:result',
'invoices'=>
'tns:invoices'),
229 $ns.
'#getSupplierInvoicesForThirdParty',
232 'WS to get SupplierInvoicesForThirdParty'
249 dol_syslog(
"Function: getSupplierInvoice login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
251 if ($authentication[
'entity']) {
252 $conf->entity = $authentication[
'entity'];
256 $objectresp = array();
257 $errorcode =
''; $errorlabel =
'';
261 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
263 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
269 if ($fuser->rights->fournisseur->facture->lire) {
271 $result = $invoice->fetch($id, $ref, $ref_ext);
273 $linesresp = array();
275 foreach ($invoice->lines as $line) {
277 $linesresp[] = array(
279 'type'=>$line->product_type,
280 'total_net'=>$line->total_ht,
281 'total_vat'=>$line->total_tva,
282 'total'=>$line->total_ttc,
283 'vat_rate'=>$line->tva_tx,
291 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
293 'id' => $invoice->id,
294 'ref' => $invoice->ref,
295 'ref_supplier'=>$invoice->ref_supplier,
296 'ref_ext' => $invoice->ref_ext,
297 'fk_user_author' => $invoice->fk_user_author,
298 'fk_user_valid' => $invoice->fk_user_valid,
299 'fk_thirdparty' => $invoice->fk_soc,
300 'type'=>$invoice->type,
301 'status'=>$invoice->statut,
302 'total_net'=>$invoice->total_ht,
303 'total_vat'=>$invoice->total_tva,
304 'total'=>$invoice->total_ttc,
308 'date_term'=>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
309 'label'=>$invoice->label,
310 'paid'=>$invoice->paid,
311 'note_private'=>$invoice->note_private,
312 'note_public'=>$invoice->note_public,
313 'close_code'=>$invoice->close_code,
314 'close_note'=>$invoice->close_note,
316 'lines' => $linesresp,
323 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
327 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
332 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
350 dol_syslog(
"Function: getSupplierInvoicesForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
352 if ($authentication[
'entity']) {
353 $conf->entity = $authentication[
'entity'];
357 $objectresp = array();
358 $errorcode =
''; $errorlabel =
'';
363 if (!$error && empty($idthirdparty)) {
365 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
'Parameter id is not provided';
369 $linesinvoice = array();
371 $sql =
"SELECT f.rowid as facid";
372 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
373 $sql .=
" WHERE f.entity = ".((int) $conf->entity);
374 if ($idthirdparty !=
'all') {
375 $sql .=
" AND f.fk_soc = ".((int) $idthirdparty);
378 $resql = $db->query($sql);
380 $num = $db->num_rows($resql);
384 $obj = $db->fetch_object($resql);
387 $result = $invoice->fetch($obj->facid);
390 $errorcode = $result; $errorlabel = $invoice->error;
395 $linesresp = array();
396 foreach ($invoice->lines as $line) {
397 $linesresp[] = array(
399 'type'=>$line->product_type,
401 'total_net'=>$line->total_ht,
402 'total_vat'=>$line->total_tva,
403 'total'=>$line->total_ttc,
404 'vat_rate'=>$line->tva_tx,
406 'product_ref'=>$line->product_ref,
407 'product_label'=>$line->product_label,
408 'product_desc'=>$line->product_desc,
413 $linesinvoice[] = array(
415 'ref'=>$invoice->ref,
416 'ref_supplier'=>$invoice->ref_supplier,
417 'ref_ext'=>$invoice->ref_ext,
418 'fk_user_author' => $invoice->fk_user_author,
419 'fk_user_valid' => $invoice->fk_user_valid,
420 'fk_thirdparty' => $invoice->fk_soc,
421 'type'=>$invoice->type,
422 'status'=>$invoice->statut,
423 'total_net'=>$invoice->total_ht,
424 'total_vat'=>$invoice->total_tva,
425 'total'=>$invoice->total_ttc,
429 'date_term'=>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
430 'label'=>$invoice->label,
431 'paid'=>$invoice->paid,
432 'note_private'=>$invoice->note_private,
433 'note_public'=>$invoice->note_public,
434 'close_code'=>$invoice->close_code,
435 'close_note'=>$invoice->close_note,
437 'lines' => $linesresp
444 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
445 'invoices'=>$linesinvoice
450 $errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
455 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
462$server->service(file_get_contents(
"php://input"));
Class to manage suppliers invoices.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
Get list of invoices for third party.
getSupplierInvoice($authentication, $id='', $ref='', $ref_ext='')
Get invoice from id, ref or ref_ext.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.