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);
78$server->wsdl->schemaTargetNamespace = $ns;
82$server->wsdl->addComplexType(
89 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
90 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
91 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
92 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
93 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
97$server->wsdl->addComplexType(
104 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
105 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
110$server->wsdl->addComplexType(
117 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
118 'type' => array(
'name' =>
'type',
'type' =>
'xsd:int'),
119 'desc' => array(
'name' =>
'desc',
'type' =>
'xsd:string'),
120 'fk_product' => array(
'name' =>
'fk_product',
'type' =>
'xsd:int'),
121 'total_net' => array(
'name' =>
'total_net',
'type' =>
'xsd:double'),
122 'total_vat' => array(
'name' =>
'total_vat',
'type' =>
'xsd:double'),
123 'total' => array(
'name' =>
'total',
'type' =>
'xsd:double'),
124 'vat_rate' => array(
'name' =>
'vat_rate',
'type' =>
'xsd:double'),
125 'qty' => array(
'name' =>
'qty',
'type' =>
'xsd:double'),
126 'date_start' => array(
'name' =>
'date_start',
'type' =>
'xsd:date'),
127 'date_end' => array(
'name' =>
'date_end',
'type' =>
'xsd:date'),
129 'product_ref' => array(
'name' =>
'product_ref',
'type' =>
'xsd:string'),
130 'product_label' => array(
'name' =>
'product_label',
'type' =>
'xsd:string'),
131 'product_desc' => array(
'name' =>
'product_desc',
'type' =>
'xsd:string')
135$server->wsdl->addComplexType(
143 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:line[]')
148$server->wsdl->addComplexType(
155 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
156 'ref' => array(
'name' =>
'ref',
'type' =>
'xsd:string'),
157 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
158 'ref_supplier' => array(
'name' =>
'ref_supplier',
'type' =>
'xsd:string'),
159 'fk_user_author' => array(
'name' =>
'fk_user_author',
'type' =>
'xsd:int'),
160 'fk_user_valid' => array(
'name' =>
'fk_user_valid',
'type' =>
'xsd:int'),
161 'fk_user_modif' => array(
'name' =>
'fk_user_modif',
'type' =>
'xsd:int'),
162 'fk_thirdparty' => array(
'name' =>
'fk_thirdparty',
'type' =>
'xsd:int'),
163 'date_creation' => array(
'name' =>
'date_creation',
'type' =>
'xsd:dateTime'),
164 'date_validation' => array(
'name' =>
'date_validation',
'type' =>
'xsd:dateTime'),
165 'date_modification' => array(
'name' =>
'date_modification',
'type' =>
'xsd:dateTime'),
166 'date_invoice' => array(
'name' =>
'date_invoice',
'type' =>
'xsd:date'),
167 'date_term' => array(
'name' =>
'date_modification',
'type' =>
'xsd:date'),
168 'label' => array(
'name' =>
'label',
'type' =>
'xsd:date'),
169 'type' => array(
'name' =>
'type',
'type' =>
'xsd:int'),
170 'total_net' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
171 'total_vat' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
172 'total' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
173 'note_private' => array(
'name' =>
'note_private',
'type' =>
'xsd:string'),
174 'note_public' => array(
'name' =>
'note_public',
'type' =>
'xsd:string'),
175 'status' => array(
'name' =>
'status',
'type' =>
'xsd:int'),
176 'close_code' => array(
'name' =>
'close_code',
'type' =>
'xsd:string'),
177 'close_note' => array(
'name' =>
'close_note',
'type' =>
'xsd:string'),
178 'lines' => array(
'name' =>
'lines',
'type' =>
'tns:LinesArray')
182$server->wsdl->addComplexType(
190 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:invoice[]')
195$server->wsdl->addComplexType(
203 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:invoice[]')
214$styleuse =
'encoded';
219 'getSupplierInvoice',
221 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
223 array(
'result' =>
'tns:result',
'invoice' =>
'tns:invoice'),
225 $ns.
'#getSupplierInvoice',
228 'WS to get SupplierInvoice'
231 'getSupplierInvoicesForThirdParty',
233 array(
'authentication' =>
'tns:authentication',
'idthirdparty' =>
'xsd:string'),
235 array(
'result' =>
'tns:result',
'invoices' =>
'tns:invoices'),
237 $ns.
'#getSupplierInvoicesForThirdParty',
240 'WS to get SupplierInvoicesForThirdParty'
257 dol_syslog(
"Function: getSupplierInvoice login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
259 if ($authentication[
'entity']) {
260 $conf->entity = $authentication[
'entity'];
264 $objectresp = array();
270 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
272 $errorcode =
'BAD_PARAMETERS';
273 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
277 $fuser->loadRights();
279 if ($fuser->hasRight(
'fournisseur',
'facture',
'lire')) {
281 $result = $invoice->fetch(
$id, $ref, $ref_ext);
283 $linesresp = array();
285 foreach ($invoice->lines as $line) {
287 $linesresp[] = array(
289 'type' => $line->product_type,
290 'total_net' => $line->total_ht,
291 'total_vat' => $line->total_tva,
292 'total' => $line->total_ttc,
293 'vat_rate' => $line->tva_tx,
301 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
303 'id' => $invoice->id,
304 'ref' => $invoice->ref,
305 'ref_supplier' => $invoice->ref_supplier,
306 'ref_ext' => $invoice->ref_ext,
307 'fk_user_author' => $invoice->user_creation_id,
308 'fk_user_valid' => $invoice->user_validation_id,
309 'fk_user_modif' => $invoice->user_modification_id,
310 'fk_thirdparty' => $invoice->socid,
311 'type' => $invoice->type,
312 'status' => $invoice->status,
313 'total_net' => $invoice->total_ht,
314 'total_vat' => $invoice->total_tva,
315 'total' => $invoice->total_ttc,
316 'date_creation' =>
dol_print_date($invoice->date_creation,
'dayhourrfc'),
317 'date_modification' =>
dol_print_date($invoice->date_modification,
'dayhourrfc'),
319 'date_term' =>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
320 'label' => $invoice->label,
321 'paid' => $invoice->paid,
322 'note_private' => $invoice->note_private,
323 'note_public' => $invoice->note_public,
324 'close_code' => $invoice->close_code,
325 'close_note' => $invoice->close_note,
327 'lines' => $linesresp,
334 $errorcode =
'NOT_FOUND';
335 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
339 $errorcode =
'PERMISSION_DENIED';
340 $errorlabel =
'User does not have permission for this request';
345 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
363 dol_syslog(
"Function: getSupplierInvoicesForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
365 if ($authentication[
'entity']) {
366 $conf->entity = $authentication[
'entity'];
370 $objectresp = array();
377 if (!$error && empty($idthirdparty)) {
379 $errorcode =
'BAD_PARAMETERS';
380 $errorlabel =
'Parameter id is not provided';
384 $linesinvoice = array();
386 $sql =
"SELECT f.rowid as facid";
387 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
388 $sql .=
" WHERE f.entity = ".((int) $conf->entity);
389 if ($idthirdparty !=
'all') {
390 $sql .=
" AND f.fk_soc = ".((int) $idthirdparty);
393 $resql = $db->query($sql);
395 $num = $db->num_rows($resql);
399 $obj = $db->fetch_object($resql);
402 $result = $invoice->fetch($obj->facid);
405 $errorcode = $result;
406 $errorlabel = $invoice->error;
411 $linesresp = array();
412 foreach ($invoice->lines as $line) {
413 $linesresp[] = array(
414 'id' => $line->rowid,
415 'type' => $line->product_type,
417 'total_net' => $line->total_ht,
418 'total_vat' => $line->total_tva,
419 'total' => $line->total_ttc,
420 'vat_rate' => $line->tva_tx,
422 'product_ref' => $line->product_ref,
423 'product_label' => $line->product_label,
424 'product_desc' => $line->product_desc,
429 $linesinvoice[] = array(
430 'id' => $invoice->id,
431 'ref' => $invoice->ref,
432 'ref_supplier' => $invoice->ref_supplier,
433 'ref_ext' => $invoice->ref_ext,
434 'fk_user_author' => $invoice->user_creation_id,
435 'fk_user_valid' => $invoice->user_validation_id,
436 'fk_thirdparty' => $invoice->socid,
437 'type' => $invoice->type,
438 'status' => $invoice->status,
439 'total_net' => $invoice->total_ht,
440 'total_vat' => $invoice->total_tva,
441 'total' => $invoice->total_ttc,
442 'date_creation' =>
dol_print_date($invoice->date_creation,
'dayhourrfc'),
443 'date_modification' =>
dol_print_date($invoice->date_modification,
'dayhourrfc'),
445 'date_term' =>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
446 'label' => $invoice->label,
447 'paid' => $invoice->paid,
448 'note_private' => $invoice->note_private,
449 'note_public' => $invoice->note_public,
450 'close_code' => $invoice->close_code,
451 'close_note' => $invoice->close_note,
453 'lines' => $linesresp
460 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
461 'invoices' => $linesinvoice
466 $errorcode = $db->lasterrno();
467 $errorlabel = $db->lasterror();
472 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
479$server->service(file_get_contents(
"php://input"));
$id
Support class for third parties, contacts, members, users or resources.
Class to manage suppliers invoices.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
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.