diff --git a/html/js/ajax_fiche.js b/html/js/ajax_fiche.js index b603d121f..63144c87d 100644 --- a/html/js/ajax_fiche.js +++ b/html/js/ajax_fiche.js @@ -428,9 +428,14 @@ category_card.display_search_peppol = function (p_domid) { var dgbox = "peppol_id_search_div"; waiting_box(); + let peppol_id=id$(p_domid).value; var queryString = { op:'search_peppol' ,ctl:p_domid + ,query:peppol_id + } + if ( peppol_id != "") { + queryString['filter']='peppolid'; } if (id$("peppol_id_search_div_frm")) { queryString['query']=$F("query"); diff --git a/include/XMLDocument/invoiceubl21.class.php b/include/XMLDocument/invoiceubl21.class.php index 6f8db429f..d97629f20 100644 --- a/include/XMLDocument/invoiceubl21.class.php +++ b/include/XMLDocument/invoiceubl21.class.php @@ -83,6 +83,9 @@ class InvoiceUBL21 extends XMLInvoice { $a_error[]=$item; } } + /** + * check that PEPPOL ID is valid + */ return $a_error; } /** @@ -100,11 +103,23 @@ class InvoiceUBL21 extends XMLInvoice { ]; foreach ($a_needed as $item=>$value) { - if ( $this->data['customer'][$value]=="") { + if ( trim($this->data['customer'][$value])=="") { $a_error[]=$value; } } - + if ( $this->data['customer'][ATTR_DEF_PEPPOLID] != "") + { + // check if peppol id has the form 9999:9999... + list($scheme_id,$peppol)=explode(":", $this->data['customer'][$value]); + if (preg_replace('/[0-9]/', '', $scheme_id) != "") + { + $a_error[]=ATTR_DEF_PEPPOLID; + }elseif(\noalyss_trim($peppol) =="") + { + $a_error[]=ATTR_DEF_PEPPOLID; + + } + } return $a_error; } @@ -130,9 +145,10 @@ class InvoiceUBL21 extends XMLInvoice { $customer=$this->createElement('cac:AccountingCustomerParty'); $customer_party=$customer->appendChild($this->createElement('cac:Party')); - ///@todo EndPointID doit être dans les paramètres (voir upgrade.sql) - $customer_party->appendChild($this->createElement('cbc:EndpointID',$this->data['customer']['endpoint_id'])) - ->setAttribute('schemeID', 9925); + list($scheme_id,$peppol)=explode( ":",$this->data['customer']['endpoint_id']); + $customer_party->appendChild($this->createElement('cbc:EndpointID',$peppol)) + ->setAttribute('schemeID', $scheme_id); + $party_name=$this->createElement('cac:PartyName'); $party_name->appendChild($this->createElement("cbc:Name", $this->data['customer']['name'])); $customer_party->appendChild($party_name); @@ -210,7 +226,11 @@ class InvoiceUBL21 extends XMLInvoice { $supplier=$this->createElement('cac:AccountingSupplierParty'); $supplier_party=$supplier->appendChild($this->createElement('cac:Party')); - $supplier_party->appendChild($this->createElement('cbc:EndpointID',$this->data["supplier"]['supplier_vat_id']))->setAttribute('schemeID', 9925); + list($scheme_id,$peppol)=explode( ":",$company['COMPANY_UBL_ID']); + $supplier_party->appendChild($this->createElement('cbc:EndpointID',$peppol)) + ->setAttribute('schemeID', $scheme_id); + + //$supplier_party->appendChild($this->createElement('cbc:EndpointID',$this->data["supplier"]['supplier_vat_id']))->setAttribute('schemeID', 9925); $party_name=$this->createElement('cac:PartyName'); $party_name->appendChild($this->createElement('cbc:Name', $this->data['supplier']['name'])); $supplier_party->appendChild($party_name); diff --git a/include/XMLDocument/xmlinvoice.class.php b/include/XMLDocument/xmlinvoice.class.php index 47fb983e2..b5b7ec125 100644 --- a/include/XMLDocument/xmlinvoice.class.php +++ b/include/XMLDocument/xmlinvoice.class.php @@ -452,8 +452,9 @@ abstract class XMLInvoice extends \DOMDocument { $result['country']=substr($result['customer_vat_id'],0,2); } - // $result['endpoint_id']=$customer->get_attribute(ATTR_DEF_PEPPOLID,0); - $result['endpoint_id']= $result['customer_vat_id']; + $result['endpoint_id']=$customer->get_attribute(ATTR_DEF_PEPPOLID,0); + + return $result; } /** diff --git a/include/ajax/ajax_search_peppol.php b/include/ajax/ajax_search_peppol.php index be5ad08b5..47fd92e9c 100644 --- a/include/ajax/ajax_search_peppol.php +++ b/include/ajax/ajax_search_peppol.php @@ -78,7 +78,11 @@ echo \HtmlInput::title_box(_("Recherche PEPPOL Directory"), 'peppol_id_search_di $input_query = new IText("query", $query); $select_filter = new ISelect("filter"); - $select_filter->transform(["vatid" => _("Numéro de TVA"), "entid" => _("Numéro entreprise"), "name" => _("Nom")]); + $select_filter->transform(["vatid" => _("Numéro de TVA") + , "entid" => _("Numéro entreprise") + , "peppolid" => _("Endpoint (PEPPOL ID)") + , "name" => _("Nom") + ]); $select_filter->selected = $filter ?> input() ?> @@ -97,7 +101,7 @@ echo \HtmlInput::title_box(_("Recherche PEPPOL Directory"), 'peppol_id_search_di '; // div class content return; @@ -127,6 +131,9 @@ switch ($filter) } $search = http_build_query(["participant" => 'iso6523-actorid-upis::0208:' . $query]); break; + case 'peppolid': + $search = http_build_query(["participant" => 'iso6523-actorid-upis::' . $query]); + break; default: throw new \Exception("ASP129 unknown filter",129); } diff --git a/include/lib/ipeppol_id.class.php b/include/lib/ipeppol_id.class.php index 368752a49..ce82d43d6 100644 --- a/include/lib/ipeppol_id.class.php +++ b/include/lib/ipeppol_id.class.php @@ -76,11 +76,4 @@ class IPEPPOL_ID extends HtmlInput return $this->itext->display(); } - - static function testme() - { - $ivatnumber=new IPEPPOL_ID("av_text13"); - - echo $ivatnumber->input(); - } } \ No newline at end of file