-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Easybill\ZUGFeRD2\Tests; | ||
|
||
use Easybill\ZUGFeRD2\Builder; | ||
use Easybill\ZUGFeRD2\Model\CrossIndustryInvoice; | ||
use Easybill\ZUGFeRD2\Tests\Legacy\ReaderAndBuildTest; | ||
use Easybill\ZUGFeRD2\Validator; | ||
|
||
trait AssertXmlOutputTrait | ||
{ | ||
private function buildAndAssertXmlFromCII(CrossIndustryInvoice $invoice, string $referenceFilePath, string $validatorSchema): void | ||
{ | ||
$xml = Builder::create()->transform($invoice); | ||
self::assertNotEmpty($xml); | ||
|
||
$referenceFile = file_get_contents($referenceFilePath); | ||
$referenceFile = ReaderAndBuildTest::reformatXml($referenceFile); | ||
|
||
$xml = ReaderAndBuildTest::reformatXml($xml); | ||
self::assertEquals($referenceFile, $xml); | ||
|
||
$result = (new Validator())->validateAgainstXsd($xml, $validatorSchema); | ||
self::assertNull($result, $result ?? ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Easybill\ZUGFeRD2\Tests; | ||
|
||
use Easybill\ZUGFeRD2\Model\Amount; | ||
use Easybill\ZUGFeRD2\Model\CrossIndustryInvoice; | ||
use Easybill\ZUGFeRD2\Model\DateTime; | ||
use Easybill\ZUGFeRD2\Model\DocumentContextParameter; | ||
use Easybill\ZUGFeRD2\Model\DocumentLineDocument; | ||
use Easybill\ZUGFeRD2\Model\ExchangedDocument; | ||
use Easybill\ZUGFeRD2\Model\ExchangedDocumentContext; | ||
use Easybill\ZUGFeRD2\Model\HeaderTradeAgreement; | ||
use Easybill\ZUGFeRD2\Model\HeaderTradeDelivery; | ||
use Easybill\ZUGFeRD2\Model\HeaderTradeSettlement; | ||
use Easybill\ZUGFeRD2\Model\Id; | ||
use Easybill\ZUGFeRD2\Model\LineTradeAgreement; | ||
use Easybill\ZUGFeRD2\Model\LineTradeDelivery; | ||
use Easybill\ZUGFeRD2\Model\LineTradeSettlement; | ||
use Easybill\ZUGFeRD2\Model\Note; | ||
use Easybill\ZUGFeRD2\Model\Quantity; | ||
use Easybill\ZUGFeRD2\Model\SupplyChainEvent; | ||
use Easybill\ZUGFeRD2\Model\SupplyChainTradeLineItem; | ||
use Easybill\ZUGFeRD2\Model\SupplyChainTradeTransaction; | ||
use Easybill\ZUGFeRD2\Model\TaxRegistration; | ||
use Easybill\ZUGFeRD2\Model\TradeAddress; | ||
use Easybill\ZUGFeRD2\Model\TradeParty; | ||
use Easybill\ZUGFeRD2\Model\TradePaymentTerms; | ||
use Easybill\ZUGFeRD2\Model\TradePrice; | ||
use Easybill\ZUGFeRD2\Model\TradeProduct; | ||
use Easybill\ZUGFeRD2\Model\TradeSettlementHeaderMonetarySummation; | ||
use Easybill\ZUGFeRD2\Model\TradeSettlementLineMonetarySummation; | ||
use Easybill\ZUGFeRD2\Model\TradeTax; | ||
use Easybill\ZUGFeRD2\Validator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BuilderTest extends TestCase | ||
{ | ||
use AssertXmlOutputTrait; | ||
|
||
public function testBuildBASICEinfach(): void | ||
{ | ||
$invoice = new CrossIndustryInvoice(); | ||
$invoice->exchangedDocumentContext = new ExchangedDocumentContext(); | ||
$invoice->exchangedDocumentContext->documentContextParameter = new DocumentContextParameter(); | ||
$invoice->exchangedDocumentContext->documentContextParameter->id = 'urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic'; | ||
|
||
$invoice->exchangedDocument = new ExchangedDocument(); | ||
$invoice->exchangedDocument->id = '471102'; | ||
$invoice->exchangedDocument->issueDateTime = DateTime::create(102, '20200305'); | ||
$invoice->exchangedDocument->typeCode = '380'; | ||
$invoice->exchangedDocument->notes[] = Note::create('Rechnung gemäß Bestellung vom 01.03.2020.'); | ||
$invoice->exchangedDocument->notes[] = Note::create('Lieferant GmbH | ||
Lieferantenstraße 20 | ||
80333 München | ||
Deutschland | ||
Geschäftsführer: Hans Muster | ||
Handelsregisternummer: H A 123 | ||
'); | ||
$invoice->exchangedDocument->notes[] = Note::create('Unsere GLN: 4000001123452 | ||
Ihre GLN: 4000001987658 | ||
Ihre Kundennummer: GE2020211 | ||
Zahlbar innerhalb 30 Tagen netto bis 04.04.2020, 3% Skonto innerhalb 10 Tagen bis 15.03.2020. | ||
'); | ||
|
||
$invoice->supplyChainTradeTransaction = new SupplyChainTradeTransaction(); | ||
|
||
$item1 = new SupplyChainTradeLineItem(); | ||
$item1->associatedDocumentLineDocument = DocumentLineDocument::create('1'); | ||
$item1->specifiedTradeProduct = new TradeProduct(); | ||
$item1->specifiedTradeProduct->globalID = Id::create('4012345001235', '0160'); | ||
$item1->specifiedTradeProduct->name = 'GTIN: 4012345001235 | ||
Unsere Art.-Nr.: TB100A4 | ||
Trennblätter A4 | ||
'; | ||
$item1->tradeAgreement = new LineTradeAgreement(); | ||
$item1->tradeAgreement->netPrice = TradePrice::create('9.90'); | ||
|
||
$item1->delivery = new LineTradeDelivery(); | ||
$item1->delivery->billedQuantity = Quantity::create('20.0000', 'H87'); | ||
|
||
$item1->specifiedLineTradeSettlement = new LineTradeSettlement(); | ||
$item1->specifiedLineTradeSettlement->tradeTax[] = $item1tax = new TradeTax(); | ||
$item1tax->typeCode = 'VAT'; | ||
$item1tax->categoryCode = 'S'; | ||
$item1tax->rateApplicablePercent = '19'; | ||
$item1->specifiedLineTradeSettlement->monetarySummation = TradeSettlementLineMonetarySummation::create('198.00'); | ||
|
||
$invoice->supplyChainTradeTransaction->lineItems[] = $item1; | ||
|
||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeAgreement = new HeaderTradeAgreement(); | ||
|
||
// Buyer Trade Party | ||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeAgreement->buyerTradeParty = $buyerTradeParty = new TradeParty(); | ||
$buyerTradeParty->name = 'Kunden AG Mitte'; | ||
$buyerTradeParty->postalTradeAddress = new TradeAddress(); | ||
$buyerTradeParty->postalTradeAddress->postcode = '69876'; | ||
$buyerTradeParty->postalTradeAddress->lineOne = 'Hans Muster'; | ||
$buyerTradeParty->postalTradeAddress->lineTwo = 'Kundenstraße 15'; | ||
$buyerTradeParty->postalTradeAddress->city = 'Frankfurt'; | ||
$buyerTradeParty->postalTradeAddress->countryCode = 'DE'; | ||
|
||
// Seller Trade Party | ||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeAgreement->sellerTradeParty = $sellerTradeParty = new TradeParty(); | ||
$sellerTradeParty->name = 'Lieferant GmbH'; | ||
$sellerTradeParty->postalTradeAddress = new TradeAddress(); | ||
$sellerTradeParty->postalTradeAddress->postcode = '80333'; | ||
$sellerTradeParty->postalTradeAddress->lineOne = 'Lieferantenstraße 20'; | ||
$sellerTradeParty->postalTradeAddress->city = 'München'; | ||
$sellerTradeParty->postalTradeAddress->countryCode = 'DE'; | ||
$sellerTradeParty->taxRegistrations[] = TaxRegistration::create('201/113/40209', 'FC'); | ||
$sellerTradeParty->taxRegistrations[] = TaxRegistration::create('DE123456789', 'VA'); | ||
|
||
// Header Trade Delivery | ||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeDelivery = new HeaderTradeDelivery(); | ||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeDelivery->chainEvent = new SupplyChainEvent(); | ||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeDelivery->chainEvent->date = DateTime::create(102, '20200305'); | ||
|
||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeSettlement = new HeaderTradeSettlement(); | ||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeSettlement->currency = 'EUR'; | ||
|
||
// Tax | ||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeSettlement->tradeTaxes[] = $headerTax1 = new TradeTax(); | ||
$headerTax1->typeCode = 'VAT'; | ||
$headerTax1->categoryCode = 'S'; | ||
$headerTax1->basisAmount = Amount::create('198.00'); | ||
$headerTax1->calculatedAmount = Amount::create('37.62'); | ||
$headerTax1->rateApplicablePercent = '19.00'; | ||
|
||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeSettlement->specifiedTradePaymentTerms[] = $paymentTerms = new TradePaymentTerms(); | ||
$paymentTerms->dueDate = DateTime::create(102, '20200404'); | ||
|
||
// Summary | ||
$invoice->supplyChainTradeTransaction->applicableHeaderTradeSettlement->specifiedTradeSettlementHeaderMonetarySummation = $summation = new TradeSettlementHeaderMonetarySummation(); | ||
$summation->lineTotalAmount = Amount::create('198.00'); | ||
$summation->chargeTotalAmount = Amount::create('0.00'); | ||
$summation->allowanceTotalAmount = Amount::create('0.00'); | ||
$summation->taxBasisTotalAmount[] = Amount::create('198.00'); | ||
$summation->taxTotalAmount[] = Amount::create('37.62', 'EUR'); | ||
$summation->grandTotalAmount[] = Amount::create('235.62'); | ||
$summation->duePayableAmount = Amount::create('235.62'); | ||
|
||
$this->buildAndAssertXmlFromCII( | ||
$invoice, | ||
__DIR__ . '/Examples/BASIC/BASIC_Einfach.xml', | ||
Validator::SCHEMA_BASIC | ||
); | ||
} | ||
} |