23 if (!defined(
"NOCSRFCHECK")) {
24 define(
"NOCSRFCHECK",
'1');
27 require
'../master.inc.php';
28 require_once NUSOAP_PATH.
'/nusoap.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
34 dol_syslog(
"Call Dolibarr webservices interfaces");
39 if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
40 $langs->load(
"admin");
41 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
42 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
43 print $langs->trans(
"ToActivateModule");
48 $server =
new nusoap_server();
49 $server->soap_defencoding =
'UTF-8';
50 $server->decode_utf8 =
false;
51 $ns =
'http://www.dolibarr.org/ns/';
52 $server->configureWSDL(
'WebServicesDolibarrSupplierInvoice', $ns);
53 $server->wsdl->schemaTargetNamespace = $ns;
57 $server->wsdl->addComplexType(
64 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
65 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
66 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
67 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
68 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
72 $server->wsdl->addComplexType(
79 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
80 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
85 $server->wsdl->addComplexType(
92 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
93 'type' => array(
'name'=>
'type',
'type'=>
'xsd:int'),
94 'desc' => array(
'name'=>
'desc',
'type'=>
'xsd:string'),
95 'fk_product' => array(
'name'=>
'fk_product',
'type'=>
'xsd:int'),
96 'total_net' => array(
'name'=>
'total_net',
'type'=>
'xsd:double'),
97 'total_vat' => array(
'name'=>
'total_vat',
'type'=>
'xsd:double'),
98 'total' => array(
'name'=>
'total',
'type'=>
'xsd:double'),
99 'vat_rate' => array(
'name'=>
'vat_rate',
'type'=>
'xsd:double'),
100 'qty' => array(
'name'=>
'qty',
'type'=>
'xsd:double'),
101 'date_start' => array(
'name'=>
'date_start',
'type'=>
'xsd:date'),
102 'date_end' => array(
'name'=>
'date_end',
'type'=>
'xsd:date'),
104 'product_ref' => array(
'name'=>
'product_ref',
'type'=>
'xsd:string'),
105 'product_label' => array(
'name'=>
'product_label',
'type'=>
'xsd:string'),
106 'product_desc' => array(
'name'=>
'product_desc',
'type'=>
'xsd:string')
110 $server->wsdl->addComplexType(
118 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:line[]')
123 $server->wsdl->addComplexType(
130 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
131 'ref' => array(
'name'=>
'ref',
'type'=>
'xsd:string'),
132 'ref_ext' => array(
'name'=>
'ref_ext',
'type'=>
'xsd:string'),
133 'ref_supplier' => array(
'name'=>
'ref_supplier',
'type'=>
'xsd:string'),
134 'fk_user_author' => array(
'name'=>
'fk_user_author',
'type'=>
'xsd:int'),
135 'fk_user_valid' => array(
'name'=>
'fk_user_valid',
'type'=>
'xsd:int'),
136 'fk_thirdparty' => array(
'name'=>
'fk_thirdparty',
'type'=>
'xsd:int'),
137 'date_creation' => array(
'name'=>
'date_creation',
'type'=>
'xsd:dateTime'),
138 'date_validation' => array(
'name'=>
'date_validation',
'type'=>
'xsd:dateTime'),
139 'date_modification' => array(
'name'=>
'date_modification',
'type'=>
'xsd:dateTime'),
140 'date_invoice' => array(
'name'=>
'date_invoice',
'type'=>
'xsd:date'),
141 'date_term' => array(
'name'=>
'date_modification',
'type'=>
'xsd:date'),
142 'label' => array(
'name'=>
'label',
'type'=>
'xsd:date'),
143 'type' => array(
'name'=>
'type',
'type'=>
'xsd:int'),
144 'total_net' => array(
'name'=>
'type',
'type'=>
'xsd:double'),
145 'total_vat' => array(
'name'=>
'type',
'type'=>
'xsd:double'),
146 'total' => array(
'name'=>
'type',
'type'=>
'xsd:double'),
147 'note_private' => array(
'name'=>
'note_private',
'type'=>
'xsd:string'),
148 'note_public' => array(
'name'=>
'note_public',
'type'=>
'xsd:string'),
149 'status' => array(
'name'=>
'status',
'type'=>
'xsd:int'),
150 'close_code' => array(
'name'=>
'close_code',
'type'=>
'xsd:string'),
151 'close_note' => array(
'name'=>
'close_note',
'type'=>
'xsd:string'),
152 'lines' => array(
'name'=>
'lines',
'type'=>
'tns:LinesArray')
156 $server->wsdl->addComplexType(
164 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:invoice[]')
169 $server->wsdl->addComplexType(
177 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:invoice[]')
188 $styleuse =
'encoded';
193 'getSupplierInvoice',
195 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string',
'ref_ext'=>
'xsd:string'),
197 array(
'result'=>
'tns:result',
'invoice'=>
'tns:invoice'),
199 $ns.
'#getSupplierInvoice',
202 'WS to get SupplierInvoice'
205 'getSupplierInvoicesForThirdParty',
207 array(
'authentication'=>
'tns:authentication',
'idthirdparty'=>
'xsd:string'),
209 array(
'result'=>
'tns:result',
'invoices'=>
'tns:invoices'),
211 $ns.
'#getSupplierInvoicesForThirdParty',
214 'WS to get SupplierInvoicesForThirdParty'
231 dol_syslog(
"Function: getSupplierInvoice login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
233 if ($authentication[
'entity']) {
234 $conf->entity = $authentication[
'entity'];
238 $objectresp = array();
239 $errorcode =
''; $errorlabel =
'';
243 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
245 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
251 if ($fuser->rights->fournisseur->facture->lire) {
253 $result = $invoice->fetch($id, $ref, $ref_ext);
255 $linesresp = array();
257 foreach ($invoice->lines as $line) {
259 $linesresp[] = array(
261 'type'=>$line->product_type,
262 'total_net'=>$line->total_ht,
263 'total_vat'=>$line->total_tva,
264 'total'=>$line->total_ttc,
265 'vat_rate'=>$line->tva_tx,
273 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
275 'id' => $invoice->id,
276 'ref' => $invoice->ref,
277 'ref_supplier'=>$invoice->ref_supplier,
278 'ref_ext' => $invoice->ref_ext,
279 'fk_user_author' => $invoice->fk_user_author,
280 'fk_user_valid' => $invoice->fk_user_valid,
281 'fk_thirdparty' => $invoice->fk_soc,
282 'type'=>$invoice->type,
283 'status'=>$invoice->statut,
284 'total_net'=>$invoice->total_ht,
285 'total_vat'=>$invoice->total_tva,
286 'total'=>$invoice->total_ttc,
290 'date_term'=>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
291 'label'=>$invoice->label,
292 'paid'=>$invoice->paid,
293 'note_private'=>$invoice->note_private,
294 'note_public'=>$invoice->note_public,
295 'close_code'=>$invoice->close_code,
296 'close_note'=>$invoice->close_note,
298 'lines' => $linesresp,
305 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
309 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
314 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
332 dol_syslog(
"Function: getSupplierInvoicesForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
334 if ($authentication[
'entity']) {
335 $conf->entity = $authentication[
'entity'];
339 $objectresp = array();
340 $errorcode =
''; $errorlabel =
'';
345 if (!$error && empty($idthirdparty)) {
347 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
'Parameter id is not provided';
351 $linesinvoice = array();
353 $sql =
"SELECT f.rowid as facid";
354 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
355 $sql .=
" WHERE f.entity = ".((int) $conf->entity);
356 if ($idthirdparty !=
'all') {
357 $sql .=
" AND f.fk_soc = ".((int) $idthirdparty);
360 $resql = $db->query($sql);
362 $num = $db->num_rows(
$resql);
366 $obj = $db->fetch_object(
$resql);
369 $result = $invoice->fetch($obj->facid);
372 $errorcode = $result; $errorlabel = $invoice->error;
377 $linesresp = array();
378 foreach ($invoice->lines as $line) {
379 $linesresp[] = array(
381 'type'=>$line->product_type,
383 'total_net'=>$line->total_ht,
384 'total_vat'=>$line->total_tva,
385 'total'=>$line->total_ttc,
386 'vat_rate'=>$line->tva_tx,
388 'product_ref'=>$line->product_ref,
389 'product_label'=>$line->product_label,
390 'product_desc'=>$line->product_desc,
395 $linesinvoice[] = array(
397 'ref'=>$invoice->ref,
398 'ref_supplier'=>$invoice->ref_supplier,
399 'ref_ext'=>$invoice->ref_ext,
400 'fk_user_author' => $invoice->fk_user_author,
401 'fk_user_valid' => $invoice->fk_user_valid,
402 'fk_thirdparty' => $invoice->fk_soc,
403 'type'=>$invoice->type,
404 'status'=>$invoice->statut,
405 'total_net'=>$invoice->total_ht,
406 'total_vat'=>$invoice->total_tva,
407 'total'=>$invoice->total_ttc,
411 'date_term'=>
dol_print_date($invoice->date_echeance,
'dayhourrfc'),
412 'label'=>$invoice->label,
413 'paid'=>$invoice->paid,
414 'note_private'=>$invoice->note_private,
415 'note_public'=>$invoice->note_public,
416 'close_code'=>$invoice->close_code,
417 'close_note'=>$invoice->close_note,
419 'lines' => $linesresp
426 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
427 'invoices'=>$linesinvoice
432 $errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
437 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
444 $server->service(file_get_contents(
"php://input"));
Class to manage suppliers invoices.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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.