24if (!defined(
'NOCSRFCHECK')) {
25 define(
'NOCSRFCHECK',
'1');
27if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
30if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
36if (!defined(
'NOREQUIREAJAX')) {
37 define(
'NOREQUIREAJAX',
'1');
39if (!defined(
"NOLOGIN")) {
40 define(
"NOLOGIN",
'1');
42if (!defined(
"NOSESSION")) {
43 define(
"NOSESSION",
'1');
46require
'../main.inc.php';
47require_once NUSOAP_PATH.
'/nusoap.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
53dol_syslog(
"Call Dolibarr webservices interfaces");
59 $langs->load(
"admin");
60 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
61 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
62 print $langs->trans(
"ToActivateModule");
67$server =
new nusoap_server();
68$server->soap_defencoding =
'UTF-8';
69$server->decode_utf8 =
false;
70$ns =
'http://www.dolibarr.org/ns/';
71$server->configureWSDL(
'WebServicesDolibarrSupplierInvoice', $ns);
72$server->wsdl->schemaTargetNamespace = $ns;
76$server->wsdl->addComplexType(
83 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
84 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
85 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
86 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
87 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
91$server->wsdl->addComplexType(
98 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
99 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
104$server->wsdl->addComplexType(
111 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
112 'type' => array(
'name' =>
'type',
'type' =>
'xsd:int'),
113 'desc' => array(
'name' =>
'desc',
'type' =>
'xsd:string'),
114 'fk_product' => array(
'name' =>
'fk_product',
'type' =>
'xsd:int'),
115 'total_net' => array(
'name' =>
'total_net',
'type' =>
'xsd:double'),
116 'total_vat' => array(
'name' =>
'total_vat',
'type' =>
'xsd:double'),
117 'total' => array(
'name' =>
'total',
'type' =>
'xsd:double'),
118 'vat_rate' => array(
'name' =>
'vat_rate',
'type' =>
'xsd:double'),
119 'qty' => array(
'name' =>
'qty',
'type' =>
'xsd:double'),
120 'date_start' => array(
'name' =>
'date_start',
'type' =>
'xsd:date'),
121 'date_end' => array(
'name' =>
'date_end',
'type' =>
'xsd:date'),
123 'product_ref' => array(
'name' =>
'product_ref',
'type' =>
'xsd:string'),
124 'product_label' => array(
'name' =>
'product_label',
'type' =>
'xsd:string'),
125 'product_desc' => array(
'name' =>
'product_desc',
'type' =>
'xsd:string')
129$server->wsdl->addComplexType(
137 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:line[]')
142$server->wsdl->addComplexType(
149 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
150 'ref' => array(
'name' =>
'ref',
'type' =>
'xsd:string'),
151 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
152 'ref_supplier' => array(
'name' =>
'ref_supplier',
'type' =>
'xsd:string'),
153 'fk_user_author' => array(
'name' =>
'fk_user_author',
'type' =>
'xsd:int'),
154 'fk_user_valid' => array(
'name' =>
'fk_user_valid',
'type' =>
'xsd:int'),
155 'fk_thirdparty' => array(
'name' =>
'fk_thirdparty',
'type' =>
'xsd:int'),
156 'date_creation' => array(
'name' =>
'date_creation',
'type' =>
'xsd:dateTime'),
157 'date_validation' => array(
'name' =>
'date_validation',
'type' =>
'xsd:dateTime'),
158 'date_modification' => array(
'name' =>
'date_modification',
'type' =>
'xsd:dateTime'),
159 'date_invoice' => array(
'name' =>
'date_invoice',
'type' =>
'xsd:date'),
160 'date_term' => array(
'name' =>
'date_modification',
'type' =>
'xsd:date'),
161 'label' => array(
'name' =>
'label',
'type' =>
'xsd:date'),
162 'type' => array(
'name' =>
'type',
'type' =>
'xsd:int'),
163 'total_net' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
164 'total_vat' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
165 'total' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
166 'note_private' => array(
'name' =>
'note_private',
'type' =>
'xsd:string'),
167 'note_public' => array(
'name' =>
'note_public',
'type' =>
'xsd:string'),
168 'status' => array(
'name' =>
'status',
'type' =>
'xsd:int'),
169 'close_code' => array(
'name' =>
'close_code',
'type' =>
'xsd:string'),
170 'close_note' => array(
'name' =>
'close_note',
'type' =>
'xsd:string'),
171 'lines' => array(
'name' =>
'lines',
'type' =>
'tns:LinesArray')
175$server->wsdl->addComplexType(
183 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:invoice[]')
188$server->wsdl->addComplexType(
196 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:invoice[]')
207$styleuse =
'encoded';
212 'getSupplierInvoice',
214 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
216 array(
'result' =>
'tns:result',
'invoice' =>
'tns:invoice'),
218 $ns.
'#getSupplierInvoice',
221 'WS to get SupplierInvoice'
224 'getSupplierInvoicesForThirdParty',
226 array(
'authentication' =>
'tns:authentication',
'idthirdparty' =>
'xsd:string'),
228 array(
'result' =>
'tns:result',
'invoices' =>
'tns:invoices'),
230 $ns.
'#getSupplierInvoicesForThirdParty',
233 'WS to get SupplierInvoicesForThirdParty'
250 dol_syslog(
"Function: getSupplierInvoice login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
252 if ($authentication[
'entity']) {
253 $conf->entity = $authentication[
'entity'];
257 $objectresp = array();
263 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
265 $errorcode =
'BAD_PARAMETERS';
266 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
270 $fuser->loadRights();
272 if ($fuser->hasRight(
'fournisseur',
'facture',
'lire')) {
274 $result = $invoice->fetch(
$id, $ref, $ref_ext);
276 $linesresp = array();
278 foreach ($invoice->lines as $line) {
280 $linesresp[] = array(
281 'id' => $line->rowid,
282 'type' => $line->product_type,
283 'total_net' => $line->total_ht,
284 'total_vat' => $line->total_tva,
285 'total' => $line->total_ttc,
286 'vat_rate' => $line->tva_tx,
294 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
296 'id' => $invoice->id,
297 'ref' => $invoice->ref,
298 'ref_supplier' => $invoice->ref_supplier,
299 'ref_ext' => $invoice->ref_ext,
300 'fk_user_author' => $invoice->fk_user_author,
301 'fk_user_valid' => $invoice->fk_user_valid,
302 'fk_thirdparty' => $invoice->fk_soc,
303 'type' => $invoice->type,
304 'status' => $invoice->status,
305 'total_net' => $invoice->total_ht,
306 'total_vat' => $invoice->total_tva,
307 'total' => $invoice->total_ttc,
309 'date_modification' =>
dol_print_date($invoice->tms,
'dayhourrfc'),
311 'date_term' =>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
312 'label' => $invoice->label,
313 'paid' => $invoice->paid,
314 'note_private' => $invoice->note_private,
315 'note_public' => $invoice->note_public,
316 'close_code' => $invoice->close_code,
317 'close_note' => $invoice->close_note,
319 'lines' => $linesresp,
326 $errorcode =
'NOT_FOUND';
327 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
331 $errorcode =
'PERMISSION_DENIED';
332 $errorlabel =
'User does not have permission for this request';
337 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
355 dol_syslog(
"Function: getSupplierInvoicesForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
357 if ($authentication[
'entity']) {
358 $conf->entity = $authentication[
'entity'];
362 $objectresp = array();
369 if (!$error && empty($idthirdparty)) {
371 $errorcode =
'BAD_PARAMETERS';
372 $errorlabel =
'Parameter id is not provided';
376 $linesinvoice = array();
378 $sql =
"SELECT f.rowid as facid";
379 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
380 $sql .=
" WHERE f.entity = ".((int) $conf->entity);
381 if ($idthirdparty !=
'all') {
382 $sql .=
" AND f.fk_soc = ".((int) $idthirdparty);
385 $resql = $db->query($sql);
387 $num = $db->num_rows($resql);
391 $obj = $db->fetch_object($resql);
394 $result = $invoice->fetch($obj->facid);
397 $errorcode = $result;
398 $errorlabel = $invoice->error;
403 $linesresp = array();
404 foreach ($invoice->lines as $line) {
405 $linesresp[] = array(
406 'id' => $line->rowid,
407 'type' => $line->product_type,
409 'total_net' => $line->total_ht,
410 'total_vat' => $line->total_tva,
411 'total' => $line->total_ttc,
412 'vat_rate' => $line->tva_tx,
414 'product_ref' => $line->product_ref,
415 'product_label' => $line->product_label,
416 'product_desc' => $line->product_desc,
421 $linesinvoice[] = array(
422 'id' => $invoice->id,
423 'ref' => $invoice->ref,
424 'ref_supplier' => $invoice->ref_supplier,
425 'ref_ext' => $invoice->ref_ext,
426 'fk_user_author' => $invoice->user_creation_id,
427 'fk_user_valid' => $invoice->user_validation_id,
428 'fk_thirdparty' => $invoice->socid,
429 'type' => $invoice->type,
430 'status' => $invoice->status,
431 'total_net' => $invoice->total_ht,
432 'total_vat' => $invoice->total_tva,
433 'total' => $invoice->total_ttc,
435 'date_modification' =>
dol_print_date($invoice->tms,
'dayhourrfc'),
437 'date_term' =>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
438 'label' => $invoice->label,
439 'paid' => $invoice->paid,
440 'note_private' => $invoice->note_private,
441 'note_public' => $invoice->note_public,
442 'close_code' => $invoice->close_code,
443 'close_note' => $invoice->close_note,
445 'lines' => $linesresp
452 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
453 'invoices' => $linesinvoice
458 $errorcode = $db->lasterrno();
459 $errorlabel = $db->lasterror();
464 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
471$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.
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.