23if (!defined(
'NOCSRFCHECK')) {
 
   24  define(
'NOCSRFCHECK', 
'1'); 
 
   26if (!defined(
'NOTOKENRENEWAL')) {
 
   27  define(
'NOTOKENRENEWAL', 
'1'); 
 
   29if (!defined(
'NOREQUIREMENU')) {
 
   30  define(
'NOREQUIREMENU', 
'1'); 
 
   32if (!defined(
'NOREQUIREHTML')) {
 
   33  define(
'NOREQUIREHTML', 
'1'); 
 
   35if (!defined(
'NOREQUIREAJAX')) {
 
   36  define(
'NOREQUIREAJAX', 
'1'); 
 
   38if (!defined(
"NOLOGIN")) {
 
   39  define(
"NOLOGIN", 
'1'); 
 
   41if (!defined(
"NOSESSION")) {
 
   42  define(
"NOSESSION", 
'1');
 
   45require 
'../main.inc.php';
 
   46require_once NUSOAP_PATH.
'/nusoap.php'; 
 
   47require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
 
   48require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
 
   49require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
 
   52dol_syslog(
"Call Dolibarr webservices interfaces");
 
   58  $langs->load(
"admin");
 
   59  dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
 
   60  print $langs->trans(
"WarningModuleNotActive", 
'WebServices').
'.<br><br>';
 
   61  print $langs->trans(
"ToActivateModule");
 
   66$server = 
new nusoap_server();
 
   67$server->soap_defencoding = 
'UTF-8';
 
   68$server->decode_utf8 = 
false;
 
   69$ns = 
'http://www.dolibarr.org/ns/';
 
   70$server->configureWSDL(
'WebServicesDolibarrSupplierInvoice', $ns);
 
   71$server->wsdl->schemaTargetNamespace = $ns;
 
   75$server->wsdl->addComplexType(
 
   82    'dolibarrkey' => array(
'name'=>
'dolibarrkey', 
'type'=>
'xsd:string'),
 
   83    'sourceapplication' => array(
'name'=>
'sourceapplication', 
'type'=>
'xsd:string'),
 
   84    'login' => array(
'name'=>
'login', 
'type'=>
'xsd:string'),
 
   85    'password' => array(
'name'=>
'password', 
'type'=>
'xsd:string'),
 
   86    'entity' => array(
'name'=>
'entity', 
'type'=>
'xsd:string'),
 
   90$server->wsdl->addComplexType(
 
   97    'result_code' => array(
'name'=>
'result_code', 
'type'=>
'xsd:string'),
 
   98    'result_label' => array(
'name'=>
'result_label', 
'type'=>
'xsd:string'),
 
  103$server->wsdl->addComplexType(
 
  110    'id' => array(
'name'=>
'id', 
'type'=>
'xsd:string'),
 
  111    'type' => array(
'name'=>
'type', 
'type'=>
'xsd:int'),
 
  112    'desc' => array(
'name'=>
'desc', 
'type'=>
'xsd:string'),
 
  113    'fk_product' => array(
'name'=>
'fk_product', 
'type'=>
'xsd:int'),
 
  114    'total_net' => array(
'name'=>
'total_net', 
'type'=>
'xsd:double'),
 
  115    'total_vat' => array(
'name'=>
'total_vat', 
'type'=>
'xsd:double'),
 
  116    'total' => array(
'name'=>
'total', 
'type'=>
'xsd:double'),
 
  117    'vat_rate' => array(
'name'=>
'vat_rate', 
'type'=>
'xsd:double'),
 
  118    'qty' => array(
'name'=>
'qty', 
'type'=>
'xsd:double'),
 
  119    'date_start' => array(
'name'=>
'date_start', 
'type'=>
'xsd:date'),
 
  120    'date_end' => array(
'name'=>
'date_end', 
'type'=>
'xsd:date'),
 
  122    'product_ref' => array(
'name'=>
'product_ref', 
'type'=>
'xsd:string'),
 
  123    'product_label' => array(
'name'=>
'product_label', 
'type'=>
'xsd:string'),
 
  124    'product_desc' => array(
'name'=>
'product_desc', 
'type'=>
'xsd:string')
 
  128$server->wsdl->addComplexType(
 
  136    array(
'ref'=>
'SOAP-ENC:arrayType', 
'wsdl:arrayType'=>
'tns:line[]')
 
  141$server->wsdl->addComplexType(
 
  148    'id' => array(
'name'=>
'id', 
'type'=>
'xsd:string'),
 
  149    'ref' => array(
'name'=>
'ref', 
'type'=>
'xsd:string'),
 
  150    'ref_ext' => array(
'name'=>
'ref_ext', 
'type'=>
'xsd:string'),
 
  151    'ref_supplier' => array(
'name'=>
'ref_supplier', 
'type'=>
'xsd:string'),
 
  152    'fk_user_author' => array(
'name'=>
'fk_user_author', 
'type'=>
'xsd:int'),
 
  153    'fk_user_valid' => array(
'name'=>
'fk_user_valid', 
'type'=>
'xsd:int'),
 
  154    'fk_thirdparty' => array(
'name'=>
'fk_thirdparty', 
'type'=>
'xsd:int'),
 
  155    'date_creation' => array(
'name'=>
'date_creation', 
'type'=>
'xsd:dateTime'),
 
  156    'date_validation' => array(
'name'=>
'date_validation', 
'type'=>
'xsd:dateTime'),
 
  157    'date_modification' => array(
'name'=>
'date_modification', 
'type'=>
'xsd:dateTime'),
 
  158    'date_invoice' => array(
'name'=>
'date_invoice', 
'type'=>
'xsd:date'),
 
  159    'date_term' => array(
'name'=>
'date_modification', 
'type'=>
'xsd:date'),
 
  160    'label' => array(
'name'=>
'label', 
'type'=>
'xsd:date'),
 
  161    'type' => array(
'name'=>
'type', 
'type'=>
'xsd:int'),
 
  162    'total_net' => array(
'name'=>
'type', 
'type'=>
'xsd:double'),
 
  163    'total_vat' => array(
'name'=>
'type', 
'type'=>
'xsd:double'),
 
  164    'total' => array(
'name'=>
'type', 
'type'=>
'xsd:double'),
 
  165    'note_private' => array(
'name'=>
'note_private', 
'type'=>
'xsd:string'),
 
  166    'note_public' => array(
'name'=>
'note_public', 
'type'=>
'xsd:string'),
 
  167    'status' => array(
'name'=>
'status', 
'type'=>
'xsd:int'),
 
  168    'close_code' => array(
'name'=>
'close_code', 
'type'=>
'xsd:string'),
 
  169    'close_note' => array(
'name'=>
'close_note', 
'type'=>
'xsd:string'),
 
  170    'lines' => array(
'name'=>
'lines', 
'type'=>
'tns:LinesArray')
 
  174$server->wsdl->addComplexType(
 
  182    array(
'ref'=>
'SOAP-ENC:arrayType', 
'wsdl:arrayType'=>
'tns:invoice[]')
 
  187$server->wsdl->addComplexType(
 
  195    array(
'ref'=>
'SOAP-ENC:arrayType', 
'wsdl:arrayType'=>
'tns:invoice[]')
 
  206$styleuse = 
'encoded'; 
 
  211  'getSupplierInvoice',
 
  213  array(
'authentication'=>
'tns:authentication', 
'id'=>
'xsd:string', 
'ref'=>
'xsd:string', 
'ref_ext'=>
'xsd:string'),
 
  215  array(
'result'=>
'tns:result', 
'invoice'=>
'tns:invoice'),
 
  217  $ns.
'#getSupplierInvoice',
 
  220  'WS to get SupplierInvoice' 
  223  'getSupplierInvoicesForThirdParty',
 
  225  array(
'authentication'=>
'tns:authentication', 
'idthirdparty'=>
'xsd:string'),
 
  227  array(
'result'=>
'tns:result', 
'invoices'=>
'tns:invoices'),
 
  229  $ns.
'#getSupplierInvoicesForThirdParty',
 
  232  'WS to get SupplierInvoicesForThirdParty' 
  249  dol_syslog(
"Function: getSupplierInvoice login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
 
  251  if ($authentication[
'entity']) {
 
  252    $conf->entity = $authentication[
'entity'];
 
  256  $objectresp = array();
 
  262  if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
 
  264    $errorcode = 
'BAD_PARAMETERS';
 
  265    $errorlabel = 
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
 
  271    if ($fuser->hasRight(
'fournisseur', 
'facture', 
'lire')) {
 
  273      $result = $invoice->fetch($id, $ref, $ref_ext);
 
  275        $linesresp = array();
 
  277        foreach ($invoice->lines as $line) {
 
  279          $linesresp[] = array(
 
  281            'type'=>$line->product_type,
 
  282            'total_net'=>$line->total_ht,
 
  283            'total_vat'=>$line->total_tva,
 
  284            'total'=>$line->total_ttc,
 
  285            'vat_rate'=>$line->tva_tx,
 
  293          'result'=>array(
'result_code'=>
'OK', 
'result_label'=>
''),
 
  295          'id' => $invoice->id,
 
  296          'ref' => $invoice->ref,
 
  297          'ref_supplier'=>$invoice->ref_supplier,
 
  298          'ref_ext' => $invoice->ref_ext,
 
  299          'fk_user_author' => $invoice->fk_user_author,
 
  300          'fk_user_valid' => $invoice->fk_user_valid,
 
  301          'fk_thirdparty' => $invoice->fk_soc,
 
  302          'type'=>$invoice->type,
 
  303          'status'=>$invoice->statut,
 
  304          'total_net'=>$invoice->total_ht,
 
  305          'total_vat'=>$invoice->total_tva,
 
  306          'total'=>$invoice->total_ttc,
 
  310          'date_term'=>
dol_print_date($invoice->date_echeance, 
'dayhourrfc'),
 
  311          'label'=>$invoice->label,
 
  312          'paid'=>$invoice->paid,
 
  313          'note_private'=>$invoice->note_private,
 
  314          'note_public'=>$invoice->note_public,
 
  315          'close_code'=>$invoice->close_code,
 
  316          'close_note'=>$invoice->close_note,
 
  318          'lines' => $linesresp,
 
  325        $errorcode = 
'NOT_FOUND';
 
  326        $errorlabel = 
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
 
  330      $errorcode = 
'PERMISSION_DENIED';
 
  331      $errorlabel = 
'User does not have permission for this request';
 
  336    $objectresp = array(
'result'=>array(
'result_code' => $errorcode, 
'result_label' => $errorlabel));
 
 
  354  dol_syslog(
"Function: getSupplierInvoicesForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
 
  356  if ($authentication[
'entity']) {
 
  357    $conf->entity = $authentication[
'entity'];
 
  361  $objectresp = array();
 
  368  if (!$error && empty($idthirdparty)) {
 
  370    $errorcode = 
'BAD_PARAMETERS';
 
  371    $errorlabel = 
'Parameter id is not provided';
 
  375    $linesinvoice = array();
 
  377    $sql = 
"SELECT f.rowid as facid";
 
  378    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
 
  379    $sql .= 
" WHERE f.entity = ".((int) $conf->entity);
 
  380    if ($idthirdparty != 
'all') {
 
  381      $sql .= 
" AND f.fk_soc = ".((int) $idthirdparty);
 
  384    $resql = $db->query($sql);
 
  386      $num = $db->num_rows($resql);
 
  390        $obj = $db->fetch_object($resql);
 
  393        $result = $invoice->fetch($obj->facid);
 
  396          $errorcode = $result;
 
  397          $errorlabel = $invoice->error;
 
  402        $linesresp = array();
 
  403        foreach ($invoice->lines as $line) {
 
  404          $linesresp[] = array(
 
  406            'type'=>$line->product_type,
 
  408            'total_net'=>$line->total_ht,
 
  409            'total_vat'=>$line->total_tva,
 
  410            'total'=>$line->total_ttc,
 
  411            'vat_rate'=>$line->tva_tx,
 
  413            'product_ref'=>$line->product_ref,
 
  414            'product_label'=>$line->product_label,
 
  415            'product_desc'=>$line->product_desc,
 
  420        $linesinvoice[] = array(
 
  422          'ref'=>$invoice->ref,
 
  423          'ref_supplier'=>$invoice->ref_supplier,
 
  424          'ref_ext'=>$invoice->ref_ext,
 
  425          'fk_user_author' => $invoice->user_creation_id,
 
  426          'fk_user_valid' => $invoice->user_validation_id,
 
  427          'fk_thirdparty' => $invoice->socid,
 
  428          'type'=>$invoice->type,
 
  429          'status'=>$invoice->status,
 
  430          'total_net'=>$invoice->total_ht,
 
  431          'total_vat'=>$invoice->total_tva,
 
  432          'total'=>$invoice->total_ttc,
 
  436          'date_term'=>
dol_print_date($invoice->date_echeance, 
'dayhourrfc'),
 
  437          'label'=>$invoice->label,
 
  438          'paid'=>$invoice->paid,
 
  439          'note_private'=>$invoice->note_private,
 
  440          'note_public'=>$invoice->note_public,
 
  441          'close_code'=>$invoice->close_code,
 
  442          'close_note'=>$invoice->close_note,
 
  444          'lines' => $linesresp
 
  451        'result'=>array(
'result_code'=>
'OK', 
'result_label'=>
''),
 
  452        'invoices'=>$linesinvoice
 
  457      $errorcode = $db->lasterrno();
 
  458      $errorlabel = $db->lasterror();
 
  463    $objectresp = array(
'result'=>array(
'result_code' => $errorcode, 
'result_label' => $errorlabel));
 
 
  470$server->service(file_get_contents(
"php://input"));
 
Class to manage suppliers invoices.
 
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.
 
getDolGlobalString($key, $default='')
Return 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.