Skip to content

Commit

Permalink
Support for UBL invoices e.g. Peppol, uses josemmo/einvoicing
Browse files Browse the repository at this point in the history
  • Loading branch information
yassiNebeL authored and rahal committed Jan 14, 2024
1 parent cb3db86 commit 9734f66
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ['8.1' , '8.2']
php-versions: ['8.1' , '8.2', '8.3']

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
.idea
.DS_Store
.vscode
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# Digital Invoice

Digital Invoice offers an effortless and unified interface for generating E-Invoices across various formats. It serves as a simplified wrapper around key libraries such as `easybill/zugferd-php`, `josemmo/einvoicing` (in a near future), and `atgp/factur-x`. Our objective is to streamline the process of E-Invoice generation by bringing together the capabilities of these established libraries into one easy-to-use package.
Digital Invoice offers an effortless and unified interface for generating E-Invoices across various formats. It serves as a simplified wrapper around key libraries such as `easybill/zugferd-php`, `josemmo/einvoicing`, and `atgp/factur-x`. Our objective is to streamline the process of E-Invoice generation by bringing together the capabilities of these established libraries into one easy-to-use package.

We extend our sincere appreciation to the developers of these libraries for their foundational contributions to the field.

## Supported Formats

Digital Invoice supports a range of formats, catering to diverse invoicing needs:

- **Factur-X PDF Invoice**:
- **Factur-X PDF Invoice**:
- Profiles: `MINIMUM`, `BASIC_WL`, `BASIC`, `EN16931`, `EXTENDED`

- **ZUGFeRD PDF Invoice**:
- **ZUGFeRD PDF Invoice**:
- Profiles: `CONFORT`, `BASIC`, `EXTENDED`

- **XRechnung XML Invoice**:
- **XRechnung XML Invoice**:
- A widely-used German XML format

### Upcoming Features:
- **UBL XML Invoices**:
- We are actively working to include support for UBL format invoices.
- **UBL XML Invoices**:
- Profiles: `Peppol`, `Nlcius`, `CiusRo`, `CiusIt`, `CiusEsFace`, `CiusAtNat`, `CiusAtGov`

## Getting Started

Expand All @@ -30,17 +29,17 @@ To integrate Digital Invoice into your PHP project:

Digital Invoice enables you to generate E-Invoices in the following formats with ease:

- **Factur-X PDF Invoice**:
- **Factur-X PDF Invoice**:
- Profiles: `MINIMUM`, `BASIC_WL`, `BASIC`, `EN16931`, `EXTENDED`
- **ZUGFeRD PDF Invoice**:

- **ZUGFeRD PDF Invoice**:
- Profiles: `CONFORT`, `BASIC`, `EXTENDED`

- **XRechnung XML Invoice**:
- **XRechnung XML Invoice**:
- A standard German XML format

- **UBL XML Invoices**:
- Conforming to the official UBL XML Schema Definition (coming soon)
- **UBL XML Invoices**:
- Profiles: `Peppol`, `Nlcius`, `CiusRo`, `CiusIt`, `CiusEsFace`, `CiusAtNat`, `CiusAtGov`


## Development Status and Collaboration
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"require": {
"easybill/zugferd-php": "dev-master",
"atgp/factur-x": "^1.0",
"milo/schematron": "dev-master"
"milo/schematron": "dev-master",
"josemmo/einvoicing": "^0.2.7"
},
"require-dev": {
"phpunit/phpunit": "^8 || ^9"
Expand Down
108 changes: 107 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions src/FacturX.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FacturX extends XmlGenerator {
public const EN16931 = 'urn:cen.eu:en16931:2017';
public const EXTENDED = 'urn:cen.eu:en16931:2017#conformant#urn:zugferd.de:2p1:extended';
public const XRECHNUNG = 'urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_1.2';

public const LEVEL_MINIMUM = 0;
public const LEVEL_BASIC_WL = 1;
public const LEVEL_BASIC = 2;
Expand Down Expand Up @@ -118,14 +118,14 @@ public function setSeller(string $id, InternationalCodeDesignator $idType, strin

$this->seller->name = $name;


}

public function setPayee(){
// Pas de payeeTradeParty dans le minimum
if ($this->getProfileLevel() > self::LEVEL_MINIMUM) {
// The Payee name (BT-59) shall be provided in the Invoice, if the Payee (BG-10) is different from the Seller (BG-4).

$this->invoice->supplyChainTradeTransaction->applicableHeaderTradeSettlement->payeeTradeParty = $this->seller;
}
}
Expand All @@ -151,10 +151,10 @@ public function setSellerContact(?string $personName = null, ?string $department

public function addPaymentMean(PaymentMeansCode $typeCode , ?string $ibanId = null,?string $accountName = null, ?string $bicId = null){
if($this->getProfileLevel() >= self::LEVEL_BASIC_WL ){

$mean = new TradeSettlementPaymentMeans();
$mean->typeCode = $typeCode->value ;

// $mean->information = 'get info from type code??';
$mean->payeePartyCreditorFinancialAccount = new CreditorFinancialAccount();
$mean->payeePartyCreditorFinancialAccount->ibanId = Id::create($ibanId);
Expand All @@ -176,7 +176,7 @@ public function setSellerAddress(string $lineOne, string $postCode, string $city
}



public function setBuyerAddress(string $lineOne, string $postCode, string $city, string $countryCode, ?string $lineTwo = null, ?string $lineThree = null)
{
$this->invoice->supplyChainTradeTransaction->applicableHeaderTradeAgreement->buyerTradeParty->postalTradeAddress = $this->createAddress($postCode, $city, $countryCode, $lineOne, $lineTwo, $lineThree);
Expand All @@ -190,7 +190,7 @@ public function setSellerTaxRegistration(string $id, string $schemeID)

public function setBuyer(string $buyerReference, string $name, string $id = null)
{

$this->invoice->supplyChainTradeTransaction->applicableHeaderTradeAgreement->buyerReference = $buyerReference;
$this->invoice->supplyChainTradeTransaction->applicableHeaderTradeAgreement->buyerTradeParty = $buyerTradeParty = new TradeParty();
if ($this->getProfileLevel() > self::LEVEL_MINIMUM && $id) {
Expand Down Expand Up @@ -274,7 +274,7 @@ public function getXml()
$this->calculateTotals();
return Builder::create()->transform($this->invoice);
}



public function validate(string $xml, $schematron) {
Expand Down Expand Up @@ -313,7 +313,7 @@ public function validate(string $xml, $schematron) {
return (new Validator())->validateAgainstXsd($xml, $against);
}


public function addItem(string $name, float $price, float $taxRatePercent, float $quantity , UnitOfMeasurement $unit , ?string $globalID = null, string $globalIDCode = null) : float
{

Expand Down Expand Up @@ -359,7 +359,7 @@ public function addItem(string $name, float $price, float $taxRatePercent, float
}

return $totalLineBasis;

}

public function addNote(string $content, ?string $subjectCode = null, ?string $contentCode = null)
Expand Down
25 changes: 18 additions & 7 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ class Invoice
public const ZUGFERD_BASIC = Zugferd::ZUGFERD_BASIC;
public const ZUGFERD_CONFORT = Zugferd::ZUGFERD_CONFORT;
public const ZUGFERD_EXTENDED = Zugferd::ZUGFERD_EXTENDED;

public const UBL_PEPOOL = Ubl::PEPPOL;
public const UBL_NLCIUS = Ubl::NLCIUS;
public const UBL_CIUS_RO = Ubl::CIUS_RO;
public const UBL_CIUS_IT = Ubl::CIUS_IT;
public const UBL_CIUS_ES_FACE = Ubl::CIUS_ES_FACE;
public const UBL_CIUS_AT_GOV = Ubl::CIUS_AT_GOV;
public const UBL_CIUS_AT_NAT = Ubl::CIUS_AT_NAT;




protected $profile;
Expand Down Expand Up @@ -54,7 +62,10 @@ public function __construct(
}
}
$this->profile = $profile;
if ( in_array($profile , [FacturX::MINIMUM , FacturX::BASIC_WL, FacturX::BASIC, FacturX::EN16931, FacturX::EXTENDED, FacturX::XRECHNUNG] ) ){
if ( in_array($profile, [Ubl::PEPPOL, Ubl::NLCIUS, Ubl::CIUS_RO, Ubl::CIUS_IT, Ubl::CIUS_ES_FACE, Ubl::CIUS_AT_GOV, Ubl::CIUS_AT_NAT] ) ){
$this->xmlGenerator = new Ubl($profile, $currency);
$this->profile = (new $profile)->getSpecification();
} elseif ( in_array($profile , [FacturX::MINIMUM , FacturX::BASIC_WL, FacturX::BASIC, FacturX::EN16931, FacturX::EXTENDED, FacturX::XRECHNUNG] ) ){
$this->xmlGenerator = new FacturX($profile, $currency);
} else {
$this->xmlGenerator = new Zugferd($profile , $currency);
Expand All @@ -64,7 +75,7 @@ public function __construct(
$this->invoiceInformations['date'] = $issueDate->format('Y-m-d');
$this->invoiceInformations['docTypeName'] = $invoiceType->value;
$this->xmlGenerator->initDocument( $invoiceId , $issueDate, $invoiceType, $deliveryDate);

}

public function getProfileLevel()
Expand Down Expand Up @@ -93,16 +104,16 @@ protected static function convertDate(\DateTime $date)
public function setBuyer(string $buyerReference, string $name, string $id = null)
{
$this->xmlGenerator->setBuyer( $buyerReference, $name, $id);

}

public function createAddress(string $postCode, string $city, string $countryCode, string $lineOne, ?string $lineTwo = null, ?string $lineThree = null)
{

return $this->xmlGenerator->createAddress( $postCode, $city, $countryCode, $lineOne, $lineTwo, $lineThree);
}


public function setBuyerAddress(string $lineOne, string $postCode, string $city, string $countryCode, ?string $lineTwo = null, ?string $lineThree = null)
{
$this->xmlGenerator->setBuyerAddress( $lineOne, $postCode, $city, $countryCode, $lineTwo, $lineThree);
Expand Down Expand Up @@ -158,7 +169,7 @@ public function addPaymentMean(string $typeCode, ?string $ibanId = null,?string
}

$this->xmlGenerator->addPaymentMean($typeCode, $ibanId , $accountName, $bicId);

}

public function addNote(string $content, ?string $subjectCode = null, ?string $contentCode = null)
Expand Down
Loading

0 comments on commit 9734f66

Please sign in to comment.