25if (!defined(
'NOCSRFCHECK')) {
26 define(
'NOCSRFCHECK',
'1');
28if (!defined(
'NOTOKENRENEWAL')) {
29 define(
'NOTOKENRENEWAL',
'1');
31if (!defined(
'NOREQUIREMENU')) {
32 define(
'NOREQUIREMENU',
'1');
34if (!defined(
'NOREQUIREHTML')) {
35 define(
'NOREQUIREHTML',
'1');
37if (!defined(
'NOREQUIREAJAX')) {
38 define(
'NOREQUIREAJAX',
'1');
40if (!defined(
"NOLOGIN")) {
41 define(
"NOLOGIN",
'1');
43if (!defined(
"NOSESSION")) {
44 define(
"NOSESSION",
'1');
47require
'../main.inc.php';
48require_once NUSOAP_PATH.
'/nusoap.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
50require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
58dol_syslog(
"Call Dolibarr webservices interfaces");
64 $langs->load(
"admin");
65 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
66 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
67 print $langs->trans(
"ToActivateModule");
72$server =
new nusoap_server();
73$server->soap_defencoding =
'UTF-8';
74$server->decode_utf8 =
false;
75$ns =
'http://www.dolibarr.org/ns/';
76$server->configureWSDL(
'WebServicesDolibarrSupplierInvoice', $ns);
77$server->wsdl->schemaTargetNamespace = $ns;
81$server->wsdl->addComplexType(
88 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
89 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
90 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
91 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
92 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
96$server->wsdl->addComplexType(
103 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
104 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
109$server->wsdl->addComplexType(
116 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
117 'type' => array(
'name' =>
'type',
'type' =>
'xsd:int'),
118 'desc' => array(
'name' =>
'desc',
'type' =>
'xsd:string'),
119 'fk_product' => array(
'name' =>
'fk_product',
'type' =>
'xsd:int'),
120 'total_net' => array(
'name' =>
'total_net',
'type' =>
'xsd:double'),
121 'total_vat' => array(
'name' =>
'total_vat',
'type' =>
'xsd:double'),
122 'total' => array(
'name' =>
'total',
'type' =>
'xsd:double'),
123 'vat_rate' => array(
'name' =>
'vat_rate',
'type' =>
'xsd:double'),
124 'qty' => array(
'name' =>
'qty',
'type' =>
'xsd:double'),
125 'date_start' => array(
'name' =>
'date_start',
'type' =>
'xsd:date'),
126 'date_end' => array(
'name' =>
'date_end',
'type' =>
'xsd:date'),
128 'product_ref' => array(
'name' =>
'product_ref',
'type' =>
'xsd:string'),
129 'product_label' => array(
'name' =>
'product_label',
'type' =>
'xsd:string'),
130 'product_desc' => array(
'name' =>
'product_desc',
'type' =>
'xsd:string')
134$server->wsdl->addComplexType(
142 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:line[]')
147$server->wsdl->addComplexType(
154 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
155 'ref' => array(
'name' =>
'ref',
'type' =>
'xsd:string'),
156 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
157 'ref_supplier' => array(
'name' =>
'ref_supplier',
'type' =>
'xsd:string'),
158 'fk_user_author' => array(
'name' =>
'fk_user_author',
'type' =>
'xsd:int'),
159 'fk_user_valid' => array(
'name' =>
'fk_user_valid',
'type' =>
'xsd:int'),
160 'fk_thirdparty' => array(
'name' =>
'fk_thirdparty',
'type' =>
'xsd:int'),
161 'date_creation' => array(
'name' =>
'date_creation',
'type' =>
'xsd:dateTime'),
162 'date_validation' => array(
'name' =>
'date_validation',
'type' =>
'xsd:dateTime'),
163 'date_modification' => array(
'name' =>
'date_modification',
'type' =>
'xsd:dateTime'),
164 'date_invoice' => array(
'name' =>
'date_invoice',
'type' =>
'xsd:date'),
165 'date_term' => array(
'name' =>
'date_modification',
'type' =>
'xsd:date'),
166 'label' => array(
'name' =>
'label',
'type' =>
'xsd:date'),
167 'type' => array(
'name' =>
'type',
'type' =>
'xsd:int'),
168 'total_net' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
169 'total_vat' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
170 'total' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
171 'note_private' => array(
'name' =>
'note_private',
'type' =>
'xsd:string'),
172 'note_public' => array(
'name' =>
'note_public',
'type' =>
'xsd:string'),
173 'status' => array(
'name' =>
'status',
'type' =>
'xsd:int'),
174 'close_code' => array(
'name' =>
'close_code',
'type' =>
'xsd:string'),
175 'close_note' => array(
'name' =>
'close_note',
'type' =>
'xsd:string'),
176 'lines' => array(
'name' =>
'lines',
'type' =>
'tns:LinesArray')
180$server->wsdl->addComplexType(
188 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:invoice[]')
193$server->wsdl->addComplexType(
201 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:invoice[]')
212$styleuse =
'encoded';
217 'getSupplierInvoice',
219 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
221 array(
'result' =>
'tns:result',
'invoice' =>
'tns:invoice'),
223 $ns.
'#getSupplierInvoice',
226 'WS to get SupplierInvoice'
229 'getSupplierInvoicesForThirdParty',
231 array(
'authentication' =>
'tns:authentication',
'idthirdparty' =>
'xsd:string'),
233 array(
'result' =>
'tns:result',
'invoices' =>
'tns:invoices'),
235 $ns.
'#getSupplierInvoicesForThirdParty',
238 'WS to get SupplierInvoicesForThirdParty'
255 dol_syslog(
"Function: getSupplierInvoice login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
257 if ($authentication[
'entity']) {
258 $conf->entity = $authentication[
'entity'];
262 $objectresp = array();
268 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
270 $errorcode =
'BAD_PARAMETERS';
271 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
275 $fuser->loadRights();
277 if ($fuser->hasRight(
'fournisseur',
'facture',
'lire')) {
279 $result = $invoice->fetch(
$id, $ref, $ref_ext);
281 $linesresp = array();
283 foreach ($invoice->lines as $line) {
285 $linesresp[] = array(
286 'id' => $line->rowid,
287 'type' => $line->product_type,
288 'total_net' => $line->total_ht,
289 'total_vat' => $line->total_tva,
290 'total' => $line->total_ttc,
291 'vat_rate' => $line->tva_tx,
299 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
301 'id' => $invoice->id,
302 'ref' => $invoice->ref,
303 'ref_supplier' => $invoice->ref_supplier,
304 'ref_ext' => $invoice->ref_ext,
305 'fk_user_author' => $invoice->fk_user_author,
306 'fk_user_valid' => $invoice->fk_user_valid,
307 'fk_thirdparty' => $invoice->fk_soc,
308 'type' => $invoice->type,
309 'status' => $invoice->status,
310 'total_net' => $invoice->total_ht,
311 'total_vat' => $invoice->total_tva,
312 'total' => $invoice->total_ttc,
314 'date_modification' =>
dol_print_date($invoice->tms,
'dayhourrfc'),
316 'date_term' =>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
317 'label' => $invoice->label,
318 'paid' => $invoice->paid,
319 'note_private' => $invoice->note_private,
320 'note_public' => $invoice->note_public,
321 'close_code' => $invoice->close_code,
322 'close_note' => $invoice->close_note,
324 'lines' => $linesresp,
331 $errorcode =
'NOT_FOUND';
332 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
336 $errorcode =
'PERMISSION_DENIED';
337 $errorlabel =
'User does not have permission for this request';
342 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
360 dol_syslog(
"Function: getSupplierInvoicesForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
362 if ($authentication[
'entity']) {
363 $conf->entity = $authentication[
'entity'];
367 $objectresp = array();
374 if (!$error && empty($idthirdparty)) {
376 $errorcode =
'BAD_PARAMETERS';
377 $errorlabel =
'Parameter id is not provided';
381 $linesinvoice = array();
383 $sql =
"SELECT f.rowid as facid";
384 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
385 $sql .=
" WHERE f.entity = ".((int)
$conf->entity);
386 if ($idthirdparty !=
'all') {
387 $sql .=
" AND f.fk_soc = ".((int) $idthirdparty);
390 $resql = $db->query($sql);
392 $num = $db->num_rows($resql);
396 $obj = $db->fetch_object($resql);
399 $result = $invoice->fetch($obj->facid);
402 $errorcode = $result;
403 $errorlabel = $invoice->error;
408 $linesresp = array();
409 foreach ($invoice->lines as $line) {
410 $linesresp[] = array(
411 'id' => $line->rowid,
412 'type' => $line->product_type,
414 'total_net' => $line->total_ht,
415 'total_vat' => $line->total_tva,
416 'total' => $line->total_ttc,
417 'vat_rate' => $line->tva_tx,
419 'product_ref' => $line->product_ref,
420 'product_label' => $line->product_label,
421 'product_desc' => $line->product_desc,
426 $linesinvoice[] = array(
427 'id' => $invoice->id,
428 'ref' => $invoice->ref,
429 'ref_supplier' => $invoice->ref_supplier,
430 'ref_ext' => $invoice->ref_ext,
431 'fk_user_author' => $invoice->user_creation_id,
432 'fk_user_valid' => $invoice->user_validation_id,
433 'fk_thirdparty' => $invoice->socid,
434 'type' => $invoice->type,
435 'status' => $invoice->status,
436 'total_net' => $invoice->total_ht,
437 'total_vat' => $invoice->total_tva,
438 'total' => $invoice->total_ttc,
440 'date_modification' =>
dol_print_date($invoice->tms,
'dayhourrfc'),
442 'date_term' =>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
443 'label' => $invoice->label,
444 'paid' => $invoice->paid,
445 'note_private' => $invoice->note_private,
446 'note_public' => $invoice->note_public,
447 'close_code' => $invoice->close_code,
448 'close_note' => $invoice->close_note,
450 'lines' => $linesresp
457 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
458 'invoices' => $linesinvoice
463 $errorcode = $db->lasterrno();
464 $errorlabel = $db->lasterror();
469 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
476$server->service(file_get_contents(
"php://input"));
Class to manage suppliers invoices.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
Get list of invoices for third party.
getSupplierInvoice($authentication, $id=0, $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.