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/date.lib.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
51require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
57dol_syslog(
"Call Dolibarr webservices interfaces");
63 $langs->load(
"admin");
64 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
65 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
66 print $langs->trans(
"ToActivateModule");
71$server =
new nusoap_server();
72$server->soap_defencoding =
'UTF-8';
73$server->decode_utf8 =
false;
74$ns =
'http://www.dolibarr.org/ns/';
75$server->configureWSDL(
'WebServicesDolibarrInvoice', $ns);
76$server->wsdl->schemaTargetNamespace = $ns;
80$server->wsdl->addComplexType(
87 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
88 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
89 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
90 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
91 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string')
95$server->wsdl->addComplexType(
102 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
103 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
108$server->wsdl->addComplexType(
115 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
116 'type' => array(
'name' =>
'type',
'type' =>
'xsd:int'),
117 'desc' => array(
'name' =>
'desc',
'type' =>
'xsd:string'),
118 'vat_rate' => array(
'name' =>
'vat_rate',
'type' =>
'xsd:double'),
119 'qty' => array(
'name' =>
'qty',
'type' =>
'xsd:double'),
120 'unitprice' => array(
'name' =>
'unitprice',
'type' =>
'xsd:double'),
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 'date_start' => array(
'name' =>
'date_start',
'type' =>
'xsd:date'),
125 'date_end' => array(
'name' =>
'date_end',
'type' =>
'xsd:date'),
127 'product_id' => array(
'name' =>
'product_id',
'type' =>
'xsd:int'),
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')
146$server->wsdl->addComplexType(
155 'type' =>
'tns:line',
157 'maxOccurs' =>
'unbounded'
165$server->wsdl->addComplexType(
172 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
173 'ref' => array(
'name' =>
'ref',
'type' =>
'xsd:string'),
174 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
175 'thirdparty_id' => array(
'name' =>
'thirdparty_id',
'type' =>
'xsd:int'),
176 'fk_user_author' => array(
'name' =>
'fk_user_author',
'type' =>
'xsd:string'),
177 'fk_user_valid' => array(
'name' =>
'fk_user_valid',
'type' =>
'xsd:string'),
178 'date' => array(
'name' =>
'date',
'type' =>
'xsd:date'),
179 'date_due' => array(
'name' =>
'date_due',
'type' =>
'xsd:date'),
180 'date_creation' => array(
'name' =>
'date_creation',
'type' =>
'xsd:dateTime'),
181 'date_validation' => array(
'name' =>
'date_validation',
'type' =>
'xsd:dateTime'),
182 'date_modification' => array(
'name' =>
'date_modification',
'type' =>
'xsd:dateTime'),
183 'payment_mode_id' => array(
'name' =>
'payment_mode_id',
'type' =>
'xsd:string'),
184 'type' => array(
'name' =>
'type',
'type' =>
'xsd:int'),
185 'total_net' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
186 'total_vat' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
187 'total' => array(
'name' =>
'type',
'type' =>
'xsd:double'),
188 'note_private' => array(
'name' =>
'note_private',
'type' =>
'xsd:string'),
189 'note_public' => array(
'name' =>
'note_public',
'type' =>
'xsd:string'),
190 'status' => array(
'name' =>
'status',
'type' =>
'xsd:int'),
191 'close_code' => array(
'name' =>
'close_code',
'type' =>
'xsd:string'),
192 'close_note' => array(
'name' =>
'close_note',
'type' =>
'xsd:string'),
193 'project_id' => array(
'name' =>
'project_id',
'type' =>
'xsd:string'),
194 'lines' => array(
'name' =>
'lines',
'type' =>
'tns:LinesArray2')
210$server->wsdl->addComplexType(
219 'type' =>
'tns:invoice',
221 'maxOccurs' =>
'unbounded'
234$styleuse =
'encoded';
241 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
243 array(
'result' =>
'tns:result',
'invoice' =>
'tns:invoice'),
248 'WS to get a particular invoice'
251 'getInvoicesForThirdParty',
253 array(
'authentication' =>
'tns:authentication',
'idthirdparty' =>
'xsd:string'),
255 array(
'result' =>
'tns:result',
'invoices' =>
'tns:InvoicesArray2'),
257 $ns.
'#getInvoicesForThirdParty',
260 'WS to get all invoices of a third party'
265 array(
'authentication' =>
'tns:authentication',
'invoice' =>
'tns:invoice'),
267 array(
'result' =>
'tns:result',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
269 $ns.
'#createInvoice',
272 'WS to create an invoice'
275 'createInvoiceFromOrder',
277 array(
'authentication' =>
'tns:authentication',
'id_order' =>
'xsd:string',
'ref_order' =>
'xsd:string',
'ref_ext_order' =>
'xsd:string'),
279 array(
'result' =>
'tns:result',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
281 $ns.
'#createInvoiceFromOrder',
284 'WS to create an invoice from an order'
289 array(
'authentication' =>
'tns:authentication',
'invoice' =>
'tns:invoice'),
291 array(
'result' =>
'tns:result',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
293 $ns.
'#updateInvoice',
296 'WS to update an invoice'
313 dol_syslog(
"Function: getInvoice login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
315 if ($authentication[
'entity']) {
316 $conf->entity = $authentication[
'entity'];
320 $objectresp = array();
326 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
328 $errorcode =
'BAD_PARAMETERS';
329 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
333 $fuser->loadRights();
335 if ($fuser->hasRight(
'facture',
'lire')) {
337 $result = $invoice->fetch(
$id, $ref, $ref_ext);
339 $linesresp = array();
341 foreach ($invoice->lines as $line) {
343 $linesresp[] = array(
345 'type' => $line->product_type,
347 'total_net' => $line->total_ht,
348 'total_vat' => $line->total_tva,
349 'total' => $line->total_ttc,
350 'vat_rate' => $line->tva_tx,
352 'unitprice' => $line->subprice,
353 'date_start' => $line->date_start ?
dol_print_date($line->date_start,
'dayrfc') :
'',
354 'date_end' => $line->date_end ?
dol_print_date($line->date_end,
'dayrfc') :
'',
355 'product_id' => $line->fk_product,
356 'product_ref' => $line->product_ref,
357 'product_label' => $line->product_label,
358 'product_desc' => $line->product_desc,
365 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
367 'id' => $invoice->id,
368 'ref' => $invoice->ref,
369 'ref_ext' => $invoice->ref_ext ? $invoice->ref_ext :
'',
370 'thirdparty_id' => $invoice->socid,
371 'fk_user_author' => $invoice->fk_user_author ? $invoice->fk_user_author :
'',
372 'fk_user_valid' => $invoice->user_validation_id ? $invoice->user_validation_id :
'',
373 'date' => $invoice->date ?
dol_print_date($invoice->date,
'dayrfc') :
'',
374 'date_due' => $invoice->date_lim_reglement ?
dol_print_date($invoice->date_lim_reglement,
'dayrfc') :
'',
375 'date_creation' => $invoice->date_creation ?
dol_print_date($invoice->date_creation,
'dayhourrfc') :
'',
376 'date_validation' => $invoice->date_validation ?
dol_print_date($invoice->date_creation,
'dayhourrfc') :
'',
377 'date_modification' => $invoice->datem ?
dol_print_date($invoice->datem,
'dayhourrfc') :
'',
378 'type' => $invoice->type,
379 'total_net' => $invoice->total_ht,
380 'total_vat' => $invoice->total_tva,
381 'total' => $invoice->total_ttc,
382 'note_private' => $invoice->note_private ? $invoice->note_private :
'',
383 'note_public' => $invoice->note_public ? $invoice->note_public :
'',
384 'status' => $invoice->statut,
385 'project_id' => $invoice->fk_project,
386 'close_code' => $invoice->close_code ? $invoice->close_code :
'',
387 'close_note' => $invoice->close_note ? $invoice->close_note :
'',
388 'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id :
'',
389 'lines' => $linesresp
393 $errorcode =
'NOT_FOUND';
394 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
398 $errorcode =
'PERMISSION_DENIED';
399 $errorlabel =
'User does not have permission for this request';
404 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
422 dol_syslog(
"Function: getInvoicesForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
424 if ($authentication[
'entity']) {
425 $conf->entity = $authentication[
'entity'];
429 $objectresp = array();
436 $socid = $fuser->socid;
440 if (!$error && empty($idthirdparty)) {
442 $errorcode =
'BAD_PARAMETERS';
443 $errorlabel =
'Parameter idthirdparty is not provided';
447 $linesinvoice = array();
449 $sql =
'SELECT f.rowid as facid, ref as ref, ref_ext, type, fk_statut as status, total_ttc, total, tva';
450 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture as f';
451 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
452 if ($idthirdparty !=
'all') {
453 $sql .=
" AND f.fk_soc = ".((int) $idthirdparty);
456 $resql = $db->query($sql);
458 $num = $db->num_rows($resql);
462 $obj = $db->fetch_object($resql);
465 $invoice->fetch($obj->facid);
468 if ($socid && ($socid != $invoice->socid)) {
470 $errorcode =
'PERMISSION_DENIED';
471 $errorlabel = $invoice->socid.
' User does not have permission for this request';
476 $linesresp = array();
477 foreach ($invoice->lines as $line) {
478 $linesresp[] = array(
480 'type' => $line->product_type,
481 'total_net' => $line->total_ht,
482 'total_vat' => $line->total_tva,
483 'total' => $line->total_ttc,
484 'vat_rate' => $line->tva_tx,
486 'unitprice' => $line->subprice,
487 'date_start' => $line->date_start ?
dol_print_date($line->date_start,
'dayrfc') :
'',
488 'date_end' => $line->date_end ?
dol_print_date($line->date_end,
'dayrfc') :
'',
489 'product_id' => $line->fk_product,
490 'product_ref' => $line->product_ref,
491 'product_label' => $line->product_label,
492 'product_desc' => $line->product_desc,
497 $linesinvoice[] = array(
498 'id' => $invoice->id,
499 'ref' => $invoice->ref,
500 'ref_ext' => $invoice->ref_ext ? $invoice->ref_ext :
'',
501 'fk_user_author' => $invoice->fk_user_author ? $invoice->fk_user_author :
'',
502 'fk_user_valid' => $invoice->user_validation_id ? $invoice->user_validation_id :
'',
503 'date' => $invoice->date ?
dol_print_date($invoice->date,
'dayrfc') :
'',
504 'date_due' => $invoice->date_lim_reglement ?
dol_print_date($invoice->date_lim_reglement,
'dayrfc') :
'',
505 'date_creation' => $invoice->date_creation ?
dol_print_date($invoice->date_creation,
'dayhourrfc') :
'',
506 'date_validation' => $invoice->date_validation ?
dol_print_date($invoice->date_creation,
'dayhourrfc') :
'',
507 'date_modification' => $invoice->datem ?
dol_print_date($invoice->datem,
'dayhourrfc') :
'',
508 'type' => $invoice->type,
509 'total_net' => $invoice->total_ht,
510 'total_vat' => $invoice->total_tva,
511 'total' => $invoice->total_ttc,
512 'note_private' => $invoice->note_private ? $invoice->note_private :
'',
513 'note_public' => $invoice->note_public ? $invoice->note_public :
'',
514 'status' => $invoice->statut,
515 'project_id' => $invoice->fk_project,
516 'close_code' => $invoice->close_code ? $invoice->close_code :
'',
517 'close_note' => $invoice->close_note ? $invoice->close_note :
'',
518 'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id :
'',
519 'lines' => $linesresp
527 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
528 'invoices' => $linesinvoice
533 $errorcode = $db->lasterrno();
534 $errorlabel = $db->lasterror();
539 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
559 dol_syslog(
"Function: createInvoice login=".$authentication[
'login'].
" id=".$invoice[
'id'].
", ref=".$invoice[
'ref'].
", ref_ext=".$invoice[
'ref_ext']);
561 if ($authentication[
'entity']) {
562 $conf->entity = $authentication[
'entity'];
566 $objectresp = array();
573 if (empty($invoice[
'id']) && empty($invoice[
'ref']) && empty($invoice[
'ref_ext'])) {
576 $errorlabel =
"Invoice id or ref or ref_ext is mandatory.";
580 $new_invoice =
new Facture($db);
581 $new_invoice->socid = $invoice[
'thirdparty_id'];
582 $new_invoice->type = $invoice[
'type'];
583 $new_invoice->ref_ext = $invoice[
'ref_ext'];
585 $new_invoice->note_private = $invoice[
'note_private'];
586 $new_invoice->note_public = $invoice[
'note_public'];
588 $new_invoice->fk_project = $invoice[
'project_id'];
589 $new_invoice->date_creation = $now;
593 $res = $soc->fetch($new_invoice->socid);
595 $new_invoice->mode_reglement_id = !empty($invoice[
'payment_mode_id']) ? $invoice[
'payment_mode_id'] : $soc->mode_reglement_id;
596 $new_invoice->cond_reglement_id = $soc->cond_reglement_id;
598 $new_invoice->mode_reglement_id = $invoice[
'payment_mode_id'];
602 $arrayoflines = array();
603 if (isset($invoice[
'lines'][
'line'][0])) {
604 $arrayoflines = $invoice[
'lines'][
'line'];
606 $arrayoflines = $invoice[
'lines'];
609 foreach ($arrayoflines as $line) {
612 $newline->product_type = $line[
'type'];
613 $newline->desc = $line[
'desc'];
614 $newline->fk_product = $line[
'product_id'];
615 $newline->tva_tx = isset($line[
'vat_rate']) ? $line[
'vat_rate'] : 0;
616 $newline->qty = $line[
'qty'];
617 $newline->subprice = isset($line[
'unitprice']) ? $line[
'unitprice'] :
null;
618 $newline->total_ht = $line[
'total_net'];
619 $newline->total_tva = $line[
'total_vat'];
620 $newline->total_ttc = $line[
'total'];
624 $new_invoice->lines[] = $newline;
631 $result = $new_invoice->create($fuser, 0,
dol_stringtotime($invoice[
'date_due'],
'dayrfc'));
637 $result = $new_invoice->validate($fuser);
645 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $new_invoice->id,
646 'ref' => $new_invoice->ref,
'ref_ext' => $new_invoice->ref_ext);
651 $errorlabel = $new_invoice->error;
652 dol_syslog(
"Function: createInvoice error while creating".$errorlabel);
657 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
676 dol_syslog(
"Function: createInvoiceFromOrder login=".$authentication[
'login'].
" id=".$id_order.
", ref=".$ref_order.
", ref_ext=".$ref_ext_order);
678 if ($authentication[
'entity']) {
679 $conf->entity = $authentication[
'entity'];
683 $objectresp = array();
689 $socid = $fuser->socid;
693 if (empty($id_order) && empty($ref_order) && empty($ref_ext_order)) {
696 $errorlabel =
"order id or ref or ref_ext is mandatory.";
701 $fuser->loadRights();
703 if ($fuser->hasRight(
'commande',
'lire')) {
705 $result = $order->fetch($id_order, $ref_order, $ref_ext_order);
708 if ($socid && ($socid != $order->socid)) {
710 $errorcode =
'PERMISSION_DENIED';
711 $errorlabel = $order->socid.
'User does not have permission for this request';
716 $result = $newobject->createFromOrder($order, $fuser);
720 dol_syslog(
"Webservice server_invoice:: invoice creation from order failed", LOG_ERR);
725 $errorcode =
'NOT_FOUND';
726 $errorlabel =
'Object not found for id='.$id_order.
' nor ref='.$ref_order.
' nor ref_ext='.$ref_ext_order;
730 $errorcode =
'PERMISSION_DENIED';
731 $errorlabel =
'User does not have permission for this request';
736 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
738 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $newobject->id,
'ref' => $newobject->ref,
'ref_ext' => $newobject->ref_ext);
753 global $db, $conf, $langs;
755 dol_syslog(
"Function: updateInvoice login=".$authentication[
'login'].
" id=".$invoice[
'id'].
756 ", ref=".$invoice[
'ref'].
", ref_ext=".$invoice[
'ref_ext']);
758 if ($authentication[
'entity']) {
759 $conf->entity = $authentication[
'entity'];
763 $objectresp = array();
770 if (empty($invoice[
'id']) && empty($invoice[
'ref']) && empty($invoice[
'ref_ext'])) {
773 $errorlabel =
"Invoice id or ref or ref_ext is mandatory.";
777 $objectfound =
false;
780 $result =
$object->fetch($invoice[
'id'], $invoice[
'ref'], $invoice[
'ref_ext'],
'');
787 if (isset($invoice[
'status'])) {
789 $result =
$object->setDraft($fuser);
792 $result =
$object->validate($fuser);
796 $outputlangs = $langs;
801 $result =
$object->setPaid($fuser, $invoice[
'close_code'], $invoice[
'close_note']);
804 $result =
$object->setCanceled($fuser, $invoice[
'close_code'], $invoice[
'close_note']);
809 if ((!$error) && ($objectfound)) {
812 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
817 } elseif ($objectfound) {
824 $errorcode =
'NOT_FOUND';
825 $errorlabel =
'Invoice id='.$invoice[
'id'].
' ref='.$invoice[
'ref'].
' ref_ext='.$invoice[
'ref_ext'].
' cannot be found';
830 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
837$server->service(file_get_contents(
"php://input"));
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage customers orders.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated (need to be paid)
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice lines.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
dol_now($mode='auto')
Return date for now.
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.
createInvoiceFromOrder($authentication, $id_order='', $ref_order='', $ref_ext_order='')
Create an invoice from an order.
getInvoice($authentication, $id=0, $ref='', $ref_ext='')
Get invoice from id, ref or ref_ext.
createInvoice($authentication, $invoice)
Create an invoice.
getInvoicesForThirdParty($authentication, $idthirdparty)
Get list of invoices for third party.
updateInvoice($authentication, $invoice)
Update an invoice, only change the state of an invoice.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.