diff --git a/composer.json b/composer.json index 691ceae..db421a1 100644 --- a/composer.json +++ b/composer.json @@ -33,13 +33,18 @@ "php": "^7.4 || ^8.0", "sabre/xml": "^4.0", "nesbot/carbon": "^2.72 || ^3.11", - "doctrine/collections": "^1.8 || ^2.0" + "doctrine/collections": "^1.8 || ^2.0", + "ext-fileinfo": "*", + "ext-libxml": "*" }, "require-dev": { "squizlabs/php_codesniffer": "^3.7", "phpstan/phpstan": "^1.10", "brianium/paratest": "^6.11", - "phpunit/phpunit": "^9.6" + "phpunit/phpunit": "^9.6", + "ext-dom": "*", + "ext-json": "*", + "ext-soap": "*" }, "autoload": { "psr-4": { diff --git a/src/AccountingParty.php b/src/AccountingParty.php index 4e251b9..8409f3f 100644 --- a/src/AccountingParty.php +++ b/src/AccountingParty.php @@ -11,12 +11,12 @@ class AccountingParty implements XmlSerializable, XmlDeserializable { - private $supplierAssignedAccountID; - private $party; - private $accountingContact; + private ?string $supplierAssignedAccountID = null; + private ?Party $party = null; + private ?Contact $accountingContact = null; /** - * @return string + * @return string|null */ public function getSupplierAssignedAccountId(): ?string { @@ -24,7 +24,7 @@ public function getSupplierAssignedAccountId(): ?string } /** - * @param string $supplierAssignedAccountID + * @param string|null $supplierAssignedAccountID * @return static */ public function setSupplierAssignedAccountId(?string $supplierAssignedAccountID) @@ -34,7 +34,7 @@ public function setSupplierAssignedAccountId(?string $supplierAssignedAccountID) } /** - * @return Party + * @return Party|null */ public function getParty(): ?Party { @@ -42,7 +42,7 @@ public function getParty(): ?Party } /** - * @param Party $party + * @param Party|null $party * @return static */ public function setParty(?Party $party) @@ -52,7 +52,7 @@ public function setParty(?Party $party) } /** - * @return ?Contact + * @return Contact|null */ public function getAccountingContact(): ?Contact { @@ -60,7 +60,7 @@ public function getAccountingContact(): ?Contact } /** - * @param Contact $accountingContact + * @param Contact|null $accountingContact * @return AccountingParty */ public function setAccountingContact(?Contact $accountingContact): AccountingParty @@ -99,7 +99,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -109,7 +109,6 @@ public static function xmlDeserialize(Reader $reader) return (new static()) ->setParty($keyValues[Schema::CAC . 'Party'] ?? null) ->setSupplierAssignedAccountId($keyValues[Schema::CBC . 'SupplierAssignedAccountID'] ?? null) - ->setAccountingContact($keyValues[Schema::CBC . 'AccountingContact'] ?? null) - ; + ->setAccountingContact($keyValues[Schema::CBC . 'AccountingContact'] ?? null); } } diff --git a/src/AdditionalDocumentReference.php b/src/AdditionalDocumentReference.php index 73d014a..88f50ad 100644 --- a/src/AdditionalDocumentReference.php +++ b/src/AdditionalDocumentReference.php @@ -11,14 +11,14 @@ class AdditionalDocumentReference implements XmlSerializable, XmlDeserializable { - private $id; - private $documentType; - private $documentTypeCode; - private $documentDescription; - private $attachment; + private ?string $id = null; + private ?string $documentType = null; + private $documentTypeCode = null; + private ?string $documentDescription = null; + private ?Attachment $attachment = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -26,7 +26,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -36,7 +36,7 @@ public function setId(?string $id) } /** - * @return string + * @return string|null */ public function getDocumentType(): ?string { @@ -44,7 +44,7 @@ public function getDocumentType(): ?string } /** - * @param string $documentType + * @param string|null $documentType * @return static */ public function setDocumentType(?string $documentType) @@ -62,7 +62,7 @@ public function getDocumentTypeCode() } /** - * @param int|string $documentTypeCode + * @param int|string|null $documentTypeCode * @return static */ public function setDocumentTypeCode($documentTypeCode) @@ -72,7 +72,7 @@ public function setDocumentTypeCode($documentTypeCode) } /** - * @return string + * @return string|null */ public function getDocumentDescription(): ?string { @@ -80,7 +80,7 @@ public function getDocumentDescription(): ?string } /** - * @param string $documentDescription + * @param string|null $documentDescription * @return static */ public function setDocumentDescription(?string $documentDescription) @@ -90,7 +90,7 @@ public function setDocumentDescription(?string $documentDescription) } /** - * @return Attachment + * @return Attachment|null */ public function getAttachment(): ?Attachment { @@ -98,7 +98,7 @@ public function getAttachment(): ?Attachment } /** - * @param Attachment $attachment + * @param Attachment|null $attachment * @return static */ public function setAttachment(?Attachment $attachment) @@ -144,7 +144,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -156,7 +156,6 @@ public static function xmlDeserialize(Reader $reader) ->setDocumentType($keyValues[Schema::CBC . 'DocumentType'] ?? null) ->setDocumentTypeCode($keyValues[Schema::CBC . 'DocumentTypeCode'] ?? null) ->setDocumentDescription($keyValues[Schema::CBC . 'DocumentDescription'] ?? null) - ->setAttachment($keyValues[Schema::CAC . 'Attachment'] ?? null) - ; + ->setAttachment($keyValues[Schema::CAC . 'Attachment'] ?? null); } } diff --git a/src/AdditionalItemProperty.php b/src/AdditionalItemProperty.php index 1902097..114578f 100644 --- a/src/AdditionalItemProperty.php +++ b/src/AdditionalItemProperty.php @@ -17,11 +17,11 @@ */ class AdditionalItemProperty implements XmlSerializable, XmlDeserializable { - private $name; - private $value; + private ?string $name = null; + private ?string $value = null; /** - * @return string + * @return string|null */ public function getName(): ?string { @@ -29,7 +29,7 @@ public function getName(): ?string } /** - * @param string $name + * @param string|null $name * @return static */ public function setName(?string $name) @@ -39,7 +39,7 @@ public function setName(?string $name) } /** - * @return string + * @return string|null */ public function getValue(): ?string { @@ -47,7 +47,7 @@ public function getValue(): ?string } /** - * @param string $value + * @param string|null $value * @return static */ public function setValue(?string $value) diff --git a/src/Address.php b/src/Address.php index 0f65433..e240d97 100644 --- a/src/Address.php +++ b/src/Address.php @@ -12,17 +12,17 @@ class Address implements XmlSerializable, XmlDeserializable { - private $streetName; - private $additionalStreetName; - private $buildingNumber; - private $cityName; - private $postalZone; - private $countrySubentity; - private $addressLines = []; - private $country; + private ?string $streetName = null; + private ?string $additionalStreetName = null; + private ?string $buildingNumber = null; + private ?string $cityName = null; + private ?string $postalZone = null; + private ?string $countrySubentity = null; + private array $addressLines = []; + private ?Country $country = null; /** - * @return string + * @return string|null */ public function getStreetName(): ?string { @@ -30,7 +30,7 @@ public function getStreetName(): ?string } /** - * @param string $streetName + * @param string|null $streetName * @return static */ public function setStreetName(?string $streetName) @@ -40,7 +40,7 @@ public function setStreetName(?string $streetName) } /** - * @return string + * @return string|null */ public function getAdditionalStreetName(): ?string { @@ -48,7 +48,7 @@ public function getAdditionalStreetName(): ?string } /** - * @param string $additionalStreetName + * @param string|null $additionalStreetName * @return static */ public function setAdditionalStreetName(?string $additionalStreetName) @@ -58,7 +58,7 @@ public function setAdditionalStreetName(?string $additionalStreetName) } /** - * @return string + * @return string|null */ public function getBuildingNumber(): ?string { @@ -66,7 +66,7 @@ public function getBuildingNumber(): ?string } /** - * @param string $buildingNumber + * @param string|null $buildingNumber * @return static */ public function setBuildingNumber(?string $buildingNumber) @@ -76,7 +76,7 @@ public function setBuildingNumber(?string $buildingNumber) } /** - * @return string + * @return string|null */ public function getCityName(): ?string { @@ -84,7 +84,7 @@ public function getCityName(): ?string } /** - * @param string $cityName + * @param string|null $cityName * @return static */ public function setCityName(?string $cityName) @@ -94,7 +94,7 @@ public function setCityName(?string $cityName) } /** - * @return string + * @return string|null */ public function getPostalZone(): ?string { @@ -102,7 +102,7 @@ public function getPostalZone(): ?string } /** - * @param string $postalZone + * @param string|null $postalZone * @return static */ public function setPostalZone(?string $postalZone) @@ -112,7 +112,7 @@ public function setPostalZone(?string $postalZone) } /** - * @return string + * @return string|null */ public function getCountrySubentity(): ?string { @@ -120,7 +120,7 @@ public function getCountrySubentity(): ?string } /** - * @param string $subentity + * @param string|null $countrySubentity * @return static */ public function setCountrySubentity(?string $countrySubentity) @@ -130,7 +130,7 @@ public function setCountrySubentity(?string $countrySubentity) } /** - * @return Country + * @return Country|null */ public function getCountry(): ?Country { @@ -138,7 +138,7 @@ public function getCountry(): ?Country } /** - * @param Country $country + * @param Country|null $country * @return static */ public function setCountry(?Country $country) @@ -179,7 +179,7 @@ public function addAddressLine(AddressLine $addressLine) * The xmlSerialize method is called during xml writing. * * @param Writer $writer - * @return static + * @return void */ public function xmlSerialize(Writer $writer): void { diff --git a/src/AddressLine.php b/src/AddressLine.php index f9d2dfc..fcc861c 100644 --- a/src/AddressLine.php +++ b/src/AddressLine.php @@ -11,7 +11,7 @@ class AddressLine implements XmlSerializable, XmlDeserializable { - private $line; + private ?string $line = null; /** * @return string|null diff --git a/src/AllowanceCharge.php b/src/AllowanceCharge.php index f379e51..9f3853c 100644 --- a/src/AllowanceCharge.php +++ b/src/AllowanceCharge.php @@ -12,13 +12,13 @@ class AllowanceCharge implements XmlSerializable, XmlDeserializable { - private $chargeIndicator; + private bool $chargeIndicator; private $allowanceChargeReasonCode; - private $allowanceChargeReason; - private $multiplierFactorNumeric; - private $baseAmount; - private $amount; - private $taxCategory; + private ?string $allowanceChargeReason = null; + private ?float $multiplierFactorNumeric = null; + private ?float $baseAmount = null; + private ?float $amount = null; + private ?TaxCategory $taxCategory = null; /** * @return bool @@ -57,7 +57,7 @@ public function setAllowanceChargeReasonCode($allowanceChargeReasonCode) } /** - * @return string + * @return string|null */ public function getAllowanceChargeReason(): ?string { @@ -65,7 +65,7 @@ public function getAllowanceChargeReason(): ?string } /** - * @param string $allowanceChargeReason + * @param string|null $allowanceChargeReason * @return static */ public function setAllowanceChargeReason(?string $allowanceChargeReason) @@ -75,7 +75,7 @@ public function setAllowanceChargeReason(?string $allowanceChargeReason) } /** - * @return float + * @return float|null */ public function getMultiplierFactorNumeric(): ?float { @@ -83,7 +83,7 @@ public function getMultiplierFactorNumeric(): ?float } /** - * @param float $multiplierFactorNumeric + * @param float|null $multiplierFactorNumeric * @return static */ public function setMultiplierFactorNumeric(?float $multiplierFactorNumeric) @@ -93,7 +93,7 @@ public function setMultiplierFactorNumeric(?float $multiplierFactorNumeric) } /** - * @return float + * @return float|null */ public function getBaseAmount(): ?float { @@ -101,7 +101,7 @@ public function getBaseAmount(): ?float } /** - * @param float $baseAmount + * @param float|null $baseAmount * @return static */ public function setBaseAmount(?float $baseAmount) @@ -111,7 +111,7 @@ public function setBaseAmount(?float $baseAmount) } /** - * @return float + * @return float|null */ public function getAmount(): ?float { @@ -119,7 +119,7 @@ public function getAmount(): ?float } /** - * @param float $amount + * @param float|null $amount * @return static */ public function setAmount(?float $amount) @@ -129,7 +129,7 @@ public function setAmount(?float $amount) } /** - * @return TaxCategory + * @return TaxCategory|null */ public function getTaxCategory(): ?TaxCategory { @@ -137,7 +137,7 @@ public function getTaxCategory(): ?TaxCategory } /** - * @param TaxCategory $taxCategory + * @param TaxCategory|null $taxCategory * @return static */ public function setTaxCategory(?TaxCategory $taxCategory) @@ -225,7 +225,7 @@ private static function parseAllowanceChargeReasonCode(?string $value) /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -233,13 +233,33 @@ public static function xmlDeserialize(Reader $reader) $mixedContent = mixedContent($reader); $collection = new ArrayCollection($mixedContent); + $allowanceChargeReasonCode = self::parseAllowanceChargeReasonCode( + ReaderHelper::getTagValue(Schema::CBC . 'AllowanceChargeReasonCode', $collection) + ); + + $multiplierFactorNumericTagValue = ReaderHelper::getTagValue( + Schema::CBC . 'MultiplierFactorNumeric', + $collection + ); + $multiplierFactorNumeric = $multiplierFactorNumericTagValue !== null + ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'MultiplierFactorNumeric', $collection)) + : null; + + $baseAmount = ReaderHelper::getTagValue(Schema::CBC . 'BaseAmount', $collection) !== null + ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'BaseAmount', $collection)) + : null; + + $amount = ReaderHelper::getTagValue(Schema::CBC . 'Amount', $collection) !== null + ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'Amount', $collection)) + : null; + return (new static()) ->setChargeIndicator(ReaderHelper::getTagValue(Schema::CBC . 'ChargeIndicator', $collection) === 'true') - ->setAllowanceChargeReasonCode(self::parseAllowanceChargeReasonCode(ReaderHelper::getTagValue(Schema::CBC . 'AllowanceChargeReasonCode', $collection))) + ->setAllowanceChargeReasonCode($allowanceChargeReasonCode) ->setAllowanceChargeReason(ReaderHelper::getTagValue(Schema::CBC . 'AllowanceChargeReason', $collection)) - ->setMultiplierFactorNumeric(ReaderHelper::getTagValue(Schema::CBC . 'MultiplierFactorNumeric', $collection) !== null ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'MultiplierFactorNumeric', $collection)) : null) - ->setBaseAmount(ReaderHelper::getTagValue(Schema::CBC . 'BaseAmount', $collection) !== null ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'BaseAmount', $collection)) : null) - ->setAmount(ReaderHelper::getTagValue(Schema::CBC . 'Amount', $collection) !== null ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'Amount', $collection)) : null) + ->setMultiplierFactorNumeric($multiplierFactorNumeric) + ->setBaseAmount($baseAmount) + ->setAmount($amount) ->setTaxCategory(ReaderHelper::getTagValue(Schema::CAC . 'TaxCategory', $collection)); } } diff --git a/src/Attachment.php b/src/Attachment.php index 4203dde..4d0e5ab 100644 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -15,15 +15,15 @@ class Attachment implements XmlSerializable, XmlDeserializable { - private $filePath; - private $externalReference; - private $base64Content; - private $fileName; - private $mimeType; + private ?string $filePath = null; + private ?string $externalReference = null; + private ?string $base64Content = null; + private ?string $fileName = null; + private ?string $mimeType = null; /** - * @throws Exception exception when the mime type cannot be determined * @return string + * @throws Exception exception when the mime type cannot be determined */ public function getFilePathMimeType(): string { @@ -35,7 +35,7 @@ public function getFilePathMimeType(): string } /** - * @return string + * @return string|null */ public function getFilePath(): ?string { @@ -53,7 +53,7 @@ public function setFilePath(string $filePath) } /** - * @return string + * @return string|null */ public function getExternalReference(): ?string { @@ -70,6 +70,9 @@ public function setExternalReference(string $externalReference) return $this; } + /** + * @return string|null + */ public function getBase64Content(): ?string { return $this->base64Content; @@ -91,7 +94,7 @@ public function setBase64Content(string $base64Content, ?string $fileName, ?stri } /** - * @return ?string + * @return string|null */ public function getFileName(): ?string { @@ -109,7 +112,7 @@ public function setFileName(?string $fileName) } /** - * @return ?string + * @return string|null */ public function getMimeType(): ?string { @@ -129,17 +132,19 @@ public function setMimeType(?string $mimeType) /** * The validate function that is called during xml writing to valid the data of the object. * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { if ($this->filePath === null && $this->externalReference === null && $this->base64Content === null) { - throw new InvalidArgumentException('Attachment must have a filePath, an externalReference, or a fileContent'); + $message = 'Attachment must have a filePath, an externalReference, or a fileContent'; + throw new InvalidArgumentException($message); } if ($this->base64Content !== null && $this->mimeType === null) { - throw new InvalidArgumentException('Using base64Content, you need to define a mimeType by also using setFileMimeType'); + $message = 'Using base64Content, you need to define a mimeType by also using setFileMimeType'; + throw new InvalidArgumentException($message); } if ($this->filePath !== null && !file_exists($this->filePath)) { @@ -152,6 +157,7 @@ public function validate() * * @param Writer $writer * @return void + * @throws Exception */ public function xmlSerialize(Writer $writer): void { @@ -188,7 +194,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) diff --git a/src/BillingReference.php b/src/BillingReference.php index bb28820..195dbe0 100644 --- a/src/BillingReference.php +++ b/src/BillingReference.php @@ -13,11 +13,11 @@ class BillingReference implements XmlSerializable, XmlDeserializable { - private $invoiceDocumentReference; + private ?InvoiceDocumentReference $invoiceDocumentReference = null; /** * - * @return ?InvoiceDocumentReference + * @return InvoiceDocumentReference|null */ public function getInvoiceDocumentReference(): ?InvoiceDocumentReference { @@ -37,8 +37,8 @@ public function setInvoiceDocumentReference($invoiceDocumentReference) /** * The validate function that is called during xml writing to valid the data of the object. * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { @@ -61,7 +61,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -69,7 +69,6 @@ public static function xmlDeserialize(Reader $reader) $keyValues = keyValue($reader); return (new static()) - ->setInvoiceDocumentReference($keyValues[Schema::CAC . 'InvoiceDocumentReference'] ?? null) - ; + ->setInvoiceDocumentReference($keyValues[Schema::CAC . 'InvoiceDocumentReference'] ?? null); } } diff --git a/src/ClassifiedTaxCategory.php b/src/ClassifiedTaxCategory.php index bac69cc..40b5108 100644 --- a/src/ClassifiedTaxCategory.php +++ b/src/ClassifiedTaxCategory.php @@ -14,17 +14,17 @@ class ClassifiedTaxCategory implements XmlSerializable, XmlDeserializable { - private $id; - private $name; - private $percent; - private $taxScheme; - private $taxExemptionReason; - private $taxExemptionReasonCode; - private $schemeID; - private $schemeName; + private ?string $id = null; + private ?string $name = null; + private ?float $percent = null; + private ?TaxScheme $taxScheme = null; + private ?string $taxExemptionReason = null; + private ?string $taxExemptionReasonCode = null; + private ?string $schemeID = null; + private ?string $schemeName = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -42,7 +42,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -52,7 +52,7 @@ public function setId(?string $id) } /** - * @return string + * @return string|null */ public function getName(): ?string { @@ -60,7 +60,7 @@ public function getName(): ?string } /** - * @param string $name + * @param string|null $name * @return static */ public function setName(?string $name) @@ -70,7 +70,7 @@ public function setName(?string $name) } /** - * @return float + * @return float|null */ public function getPercent(): ?float { @@ -78,7 +78,7 @@ public function getPercent(): ?float } /** - * @param float $percent + * @param float|null $percent * @return static */ public function setPercent(?float $percent) @@ -88,7 +88,7 @@ public function setPercent(?float $percent) } /** - * @return TaxScheme + * @return TaxScheme|null */ public function getTaxScheme(): ?TaxScheme { @@ -96,7 +96,7 @@ public function getTaxScheme(): ?TaxScheme } /** - * @param TaxScheme $taxScheme + * @param TaxScheme|null $taxScheme * @return static */ public function setTaxScheme(?TaxScheme $taxScheme) @@ -106,7 +106,7 @@ public function setTaxScheme(?TaxScheme $taxScheme) } /** - * @return string + * @return string|null */ public function getSchemeId(): ?string { @@ -114,7 +114,7 @@ public function getSchemeId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setSchemeId(?string $id) @@ -124,7 +124,7 @@ public function setSchemeId(?string $id) } /** - * @return string + * @return string|null */ public function getSchemeName(): ?string { @@ -132,7 +132,7 @@ public function getSchemeName(): ?string } /** - * @param string $name + * @param string|null $name * @return static */ public function setSchemeName(?string $name) @@ -142,7 +142,7 @@ public function setSchemeName(?string $name) } /** - * @return string + * @return string|null */ public function getTaxExemptionReason(): ?string { @@ -150,7 +150,7 @@ public function getTaxExemptionReason(): ?string } /** - * @param string $taxExemptionReason + * @param string|null $taxExemptionReason * @return static */ public function setTaxExemptionReason(?string $taxExemptionReason) @@ -160,7 +160,7 @@ public function setTaxExemptionReason(?string $taxExemptionReason) } /** - * @return string + * @return string|null */ public function getTaxExemptionReasonCode(): ?string { @@ -168,7 +168,7 @@ public function getTaxExemptionReasonCode(): ?string } /** - * @param string $taxExemptionReasonCode + * @param string|null $taxExemptionReasonCode * @return static */ public function setTaxExemptionReasonCode(?string $taxExemptionReasonCode) @@ -180,8 +180,8 @@ public function setTaxExemptionReasonCode(?string $taxExemptionReasonCode) /** * The validate function that is called during xml writing to valid the data of the object. * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { @@ -247,7 +247,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -270,7 +270,6 @@ public static function xmlDeserialize(Reader $reader) ->setTaxExemptionReason($taxExemptionReasonTag['value'] ?? null) ->setTaxExemptionReasonCode($taxExemptionReasonCodeTag['value'] ?? null) ->setSchemeId($idTag['attributes']['schemeID'] ?? null) - ->setSchemeName($idTag['attributes']['schemeName'] ?? null) - ; + ->setSchemeName($idTag['attributes']['schemeName'] ?? null); } } diff --git a/src/CommodityClassification.php b/src/CommodityClassification.php index a57a8b9..f5dc5fa 100644 --- a/src/CommodityClassification.php +++ b/src/CommodityClassification.php @@ -12,12 +12,12 @@ class CommodityClassification implements XmlSerializable, XmlDeserializable { - private $itemClassificationCode = null; - private $itemClassificationListId = null; - private $itemClassificationListVersionId = null; + private ?string $itemClassificationCode = null; + private ?string $itemClassificationListId = null; + private ?string $itemClassificationListVersionId = null; /** - * @return string + * @return string|null */ public function getItemClassificationCode(): ?string { @@ -25,7 +25,7 @@ public function getItemClassificationCode(): ?string } /** - * @param string $itemClassificationCode + * @param string|null $itemClassificationCode * @return static */ public function setItemClassificationCode(?string $itemClassificationCode) @@ -35,7 +35,7 @@ public function setItemClassificationCode(?string $itemClassificationCode) } /** - * @return ?string + * @return string|null */ public function getItemClassificationListId(): ?string { @@ -53,7 +53,7 @@ public function setItemClassificationListId(?string $itemClassificationListId) } /** - * @return ?string + * @return string|null */ public function getItemClassificationListVersionId(): ?string { @@ -97,14 +97,14 @@ public function xmlSerialize(Writer $writer): void * The xmlDeserialize method is called during xml reading. * * @param Reader $reader - * @return void + * @return CommodityClassification */ public static function xmlDeserialize(Reader $reader) { $mixedContent = mixedContent($reader); $collection = new ArrayCollection($mixedContent); - // UBL CommodityClassification kan zowel ItemClassificationCode als CommodityCode bevatten + // UBL CommodityClassification can contain both ItemClassificationCode and CommodityCode $classificationCode = ReaderHelper::getTag(Schema::CBC . 'ItemClassificationCode', $collection) ?? ReaderHelper::getTag(Schema::CBC . 'CommodityCode', $collection); diff --git a/src/Contact.php b/src/Contact.php index e3c9a8f..f2e4e8a 100644 --- a/src/Contact.php +++ b/src/Contact.php @@ -11,14 +11,14 @@ class Contact implements XmlSerializable, XmlDeserializable { - private $id; - private $name; - private $telephone; - private $telefax; - private $electronicMail; + private ?string $id = null; + private ?string $name = null; + private ?string $telephone = null; + private ?string $telefax = null; + private ?string $electronicMail = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -36,7 +36,7 @@ public function setId(string $id): Contact } /** - * @return string + * @return string|null */ public function getName(): ?string { @@ -54,7 +54,7 @@ public function setName($name) } /** - * @return mixed + * @return string|null */ public function getTelephone(): ?string { @@ -62,7 +62,7 @@ public function getTelephone(): ?string } /** - * @param string $telephone + * @param string|null $telephone * @return static */ public function setTelephone(?string $telephone) @@ -72,7 +72,7 @@ public function setTelephone(?string $telephone) } /** - * @return string + * @return string|null */ public function getTelefax(): ?string { @@ -80,7 +80,7 @@ public function getTelefax(): ?string } /** - * @param string $telefax + * @param string|null $telefax * @return static */ public function setTelefax(?string $telefax) @@ -90,7 +90,7 @@ public function setTelefax(?string $telefax) } /** - * @return string + * @return string|null */ public function getElectronicMail(): ?string { @@ -98,7 +98,7 @@ public function getElectronicMail(): ?string } /** - * @param string $electronicMail + * @param string|null $electronicMail * @return static */ public function setElectronicMail(?string $electronicMail) @@ -148,7 +148,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -160,6 +160,5 @@ public static function xmlDeserialize(Reader $reader) ->setTelephone($keyValues[Schema::CBC . 'Telephone'] ?? null) ->setTelefax($keyValues[Schema::CBC . 'Telefax'] ?? null) ->setElectronicMail($keyValues[Schema::CBC . 'ElectronicMail'] ?? null); - ; } } diff --git a/src/ContractDocumentReference.php b/src/ContractDocumentReference.php index 44de036..c80bccf 100644 --- a/src/ContractDocumentReference.php +++ b/src/ContractDocumentReference.php @@ -11,7 +11,7 @@ class ContractDocumentReference implements XmlSerializable, XmlDeserializable { - private $id; + private ?string $id = null; /** * @return string|null @@ -46,7 +46,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -54,7 +54,6 @@ public static function xmlDeserialize(Reader $reader) $mixedContent = keyValue($reader); return (new static()) - ->setId($mixedContent[Schema::CBC . 'ID'] ?? null) - ; + ->setId($mixedContent[Schema::CBC . 'ID'] ?? null); } } diff --git a/src/Country.php b/src/Country.php index e9a8315..0a75a7b 100644 --- a/src/Country.php +++ b/src/Country.php @@ -15,7 +15,7 @@ class Country implements XmlSerializable, XmlDeserializable private $listId; /** - * @return mixed + * @return string|null */ public function getIdentificationCode(): ?string { @@ -33,7 +33,7 @@ public function setIdentificationCode(?string $identificationCode) } /** - * @return mixed + * @return string|null */ public function getListId(): ?string { @@ -41,7 +41,7 @@ public function getListId(): ?string } /** - * @param mixed $listId + * @param string|null $listId * @return static */ public function setListId(?string $listId) @@ -73,7 +73,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -82,7 +82,6 @@ public static function xmlDeserialize(Reader $reader) return (new static()) ->setIdentificationCode($keyValues[Schema::CBC . 'IdentificationCode']) - ->setListId($keyValues[Schema::CBC . 'IdentificationCode']['attributes']['listID'] ?? null) - ; + ->setListId($keyValues[Schema::CBC . 'IdentificationCode']['attributes']['listID'] ?? null); } } diff --git a/src/CreditNote.php b/src/CreditNote.php index 90e3bb2..0c65b46 100644 --- a/src/CreditNote.php +++ b/src/CreditNote.php @@ -11,11 +11,11 @@ class CreditNote extends Invoice implements XmlSerializable, XmlDeserializable { - public $xmlTagName = 'CreditNote'; - protected $invoiceTypeCode = InvoiceTypeCode::CREDIT_NOTE; + public string $xmlTagName = 'CreditNote'; + protected ?int $invoiceTypeCode = InvoiceTypeCode::CREDIT_NOTE; /** - * @return CreditNoteLine[] + * @return CreditNoteLine[]|null */ public function getCreditNoteLines(): ?array { diff --git a/src/CreditNoteLine.php b/src/CreditNoteLine.php index 3f33ee5..9adbdd1 100644 --- a/src/CreditNoteLine.php +++ b/src/CreditNoteLine.php @@ -9,10 +9,10 @@ class CreditNoteLine extends InvoiceLine { - public $xmlTagName = 'CreditNoteLine'; + public string $xmlTagName = 'CreditNoteLine'; /** - * @return float + * @return float|null */ public function getCreditedQuantity(): ?float { @@ -31,7 +31,7 @@ public function setCreditedQuantity(?float $creditedQuantity) /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) diff --git a/src/DebitNote.php b/src/DebitNote.php index 0c93a5d..41280ea 100644 --- a/src/DebitNote.php +++ b/src/DebitNote.php @@ -11,11 +11,11 @@ class DebitNote extends Invoice implements XmlSerializable, XmlDeserializable { - public $xmlTagName = 'DebitNote'; - protected $invoiceTypeCode = InvoiceTypeCode::DEBIT_NOTE; + public string $xmlTagName = 'DebitNote'; + protected ?int $invoiceTypeCode = InvoiceTypeCode::DEBIT_NOTE; /** - * @return DebitNoteLine[] + * @return DebitNoteLine[]|null */ public function getDebitNoteLines(): ?array { diff --git a/src/DebitNoteLine.php b/src/DebitNoteLine.php index e9fdf70..79c4fe0 100644 --- a/src/DebitNoteLine.php +++ b/src/DebitNoteLine.php @@ -9,10 +9,10 @@ class DebitNoteLine extends InvoiceLine { - public $xmlTagName = 'DebitNoteLine'; + public string $xmlTagName = 'DebitNoteLine'; /** - * @return float + * @return float|null */ public function getDebitedQuantity(): ?float { @@ -31,7 +31,7 @@ public function setDebitedQuantity(?float $debitedQuantity) /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) diff --git a/src/Delivery.php b/src/Delivery.php index e944cab..1415b11 100644 --- a/src/Delivery.php +++ b/src/Delivery.php @@ -14,12 +14,12 @@ class Delivery implements XmlSerializable, XmlDeserializable { - private $actualDeliveryDate; - private $deliveryLocation; - private $deliveryParty; + private ?DateTime $actualDeliveryDate = null; + private ?Address $deliveryLocation = null; + private ?Party $deliveryParty = null; /** - * @return DateTime + * @return DateTime|null */ public function getActualDeliveryDate(): ?DateTime { @@ -27,7 +27,7 @@ public function getActualDeliveryDate(): ?DateTime } /** - * @param DateTime $actualDeliveryDate + * @param DateTime|null $actualDeliveryDate * @return static */ public function setActualDeliveryDate(?DateTime $actualDeliveryDate) @@ -37,7 +37,7 @@ public function setActualDeliveryDate(?DateTime $actualDeliveryDate) } /** - * @return Address + * @return Address|null */ public function getDeliveryLocation() { @@ -45,17 +45,17 @@ public function getDeliveryLocation() } /** - * @param Address $deliveryLocation + * @param Address|null $deliveryLocation * @return static */ - public function setDeliveryLocation($deliveryLocation) + public function setDeliveryLocation(?Address $deliveryLocation) { $this->deliveryLocation = $deliveryLocation; return $this; } /** - * @return Party + * @return Party|null */ public function getDeliveryParty() { @@ -63,10 +63,10 @@ public function getDeliveryParty() } /** - * @param Party $deliveryParty + * @param Party|null $deliveryParty * @return static */ - public function setDeliveryParty($deliveryParty) + public function setDeliveryParty(?Party $deliveryParty) { $this->deliveryParty = $deliveryParty; return $this; @@ -99,17 +99,20 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) { $keyValues = keyValue($reader); + $actualDeliveryDate = isset($keyValues[Schema::CBC . 'ActualDeliveryDate']) + ? Carbon::parse($keyValues[Schema::CBC . 'ActualDeliveryDate'])->toDateTime() + : null; + return (new static()) - ->setActualDeliveryDate(isset($keyValues[Schema::CBC . 'ActualDeliveryDate']) ? Carbon::parse($keyValues[Schema::CBC . 'ActualDeliveryDate'])->toDateTime() : null) + ->setActualDeliveryDate($actualDeliveryDate) ->setDeliveryLocation($keyValues[Schema::CAC . 'DeliveryLocation'] ?? null) - ->setDeliveryParty($keyValues[Schema::CAC . 'DeliveryParty'] ?? null) - ; + ->setDeliveryParty($keyValues[Schema::CAC . 'DeliveryParty'] ?? null); } } diff --git a/src/DespatchDocumentReference.php b/src/DespatchDocumentReference.php index 96d84ed..63ab1a7 100644 --- a/src/DespatchDocumentReference.php +++ b/src/DespatchDocumentReference.php @@ -11,10 +11,10 @@ class DespatchDocumentReference implements XmlSerializable, XmlDeserializable { - private $id; + private ?string $id = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -22,7 +22,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -46,7 +46,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) diff --git a/src/FinancialInstitutionBranch.php b/src/FinancialInstitutionBranch.php index 4fc27a8..ecadeb6 100644 --- a/src/FinancialInstitutionBranch.php +++ b/src/FinancialInstitutionBranch.php @@ -11,10 +11,10 @@ class FinancialInstitutionBranch implements XmlSerializable, XmlDeserializable { - private $id; + private ?string $id = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -22,7 +22,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -42,7 +42,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) diff --git a/src/Generator.php b/src/Generator.php index cd589f7..4761c8c 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -6,9 +6,9 @@ class Generator { - public static $currencyID; + public static string $currencyID; - public static function invoice(Invoice $invoice, $currencyId = 'EUR') + public static function invoice(Invoice $invoice, string $currencyId = 'EUR') { self::$currencyID = $currencyId; @@ -25,7 +25,7 @@ public static function invoice(Invoice $invoice, $currencyId = 'EUR') ]); } - public static function creditNote(CreditNote $creditNote, $currencyId = 'EUR') + public static function creditNote(CreditNote $creditNote, string $currencyId = 'EUR') { self::$currencyID = $currencyId; diff --git a/src/Invoice.php b/src/Invoice.php index c4aede7..2e0d36e 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -14,47 +14,47 @@ use function Sabre\Xml\Deserializer\mixedContent; class Invoice implements XmlSerializable, XmlDeserializable { - public $xmlTagName = "Invoice"; - private $UBLVersionID = "2.1"; - private $customizationID = "1.0"; - private $profileID; - private $id; - private $copyIndicator; - private $issueDate; - private ?DateTime $issueTime; - protected $invoiceTypeCode = InvoiceTypeCode::INVOICE; - private $note; - private $taxPointDate; - private $dueDate; - private $paymentTerms; - private $accountingSupplierParty; - private $accountingCustomerParty; - private $accountingCustomerPartyContact; - private $payeeParty; + public string $xmlTagName = "Invoice"; + private ?string $UBLVersionID = "2.1"; + private ?string $customizationID = "1.0"; + private ?string $profileID = null; + private ?string $id = null; + private ?bool $copyIndicator = null; + private ?DateTime $issueDate = null; + private ?DateTime $issueTime = null; + protected ?int $invoiceTypeCode = InvoiceTypeCode::INVOICE; + private ?string $note = null; + private ?DateTime $taxPointDate = null; + private ?DateTime $dueDate = null; + private ?PaymentTerms $paymentTerms = null; + private ?AccountingParty $accountingSupplierParty = null; + private ?AccountingParty $accountingCustomerParty = null; + private ?Contact $accountingCustomerPartyContact = null; + private ?PayeeParty $payeeParty = null; /** @var PaymentMeans[] $paymentMeans */ - private $paymentMeans; - private $taxTotal; - private $legalMonetaryTotal; + private ?array $paymentMeans = null; + private ?TaxTotal $taxTotal = null; + private ?LegalMonetaryTotal $legalMonetaryTotal = null; /** @var InvoiceLine[] $invoiceLines */ - protected $invoiceLines; - private $allowanceCharges; - private $additionalDocumentReferences = []; - private $projectReference; - private $documentCurrencyCode = "EUR"; - private $taxCurrencyCode; - private $buyerReference; - private $accountingCostCode; - private $invoicePeriod; - private $billingReference; - private $delivery; - private $orderReference; - private $contractDocumentReference; - private $despatchDocumentReference; - private $receiptDocumentReference; - private $originatorDocumentReference; - - /** - * @return string + protected array $invoiceLines = []; + private ?array $allowanceCharges = null; + private array $additionalDocumentReferences = []; + private ?ProjectReference $projectReference = null; + private ?string $documentCurrencyCode = "EUR"; + private ?string $taxCurrencyCode = null; + private ?string $buyerReference = null; + private ?string $accountingCostCode = null; + private ?InvoicePeriod $invoicePeriod = null; + private ?BillingReference $billingReference = null; + private ?Delivery $delivery = null; + private ?OrderReference $orderReference = null; + private ?ContractDocumentReference $contractDocumentReference = null; + private ?DespatchDocumentReference $despatchDocumentReference = null; + private ?ReceiptDocumentReference $receiptDocumentReference = null; + private ?OriginatorDocumentReference $originatorDocumentReference = null; + + /** + * @return string|null */ public function getUBLVersionId(): ?string { @@ -62,7 +62,7 @@ public function getUBLVersionId(): ?string } /** - * @param string $UBLVersionID + * @param string|null $UBLVersionID * eg. '2.0', '2.1', '2.2', ... * @return static */ @@ -73,7 +73,7 @@ public function setUBLVersionId(?string $UBLVersionID) } /** - * @return mixed + * @return string|null */ public function getId(): ?string { @@ -81,7 +81,7 @@ public function getId(): ?string } /** - * @param mixed $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -99,7 +99,7 @@ public function getCustomizationId(): ?string } /** - * @param mixed $customizationID + * @param string|null $customizationID * @return static */ public function setCustomizationId(?string $customizationID) @@ -145,7 +145,7 @@ public function setCopyIndicator(bool $copyIndicator) } /** - * @return DateTime + * @return DateTime|null */ public function getIssueDate(): ?DateTime { @@ -153,7 +153,7 @@ public function getIssueDate(): ?DateTime } /** - * @param DateTime $issueDate + * @param DateTime|null $issueDate * @return static */ public function setIssueDate(?DateTime $issueDate) @@ -171,7 +171,7 @@ public function getIssueTime() : ?DateTime } /** - * @param DateTime $issueTime + * @param DateTime|null $issueTime * @return static */ public function setIssueTime(?DateTime $issueTime = null) : self @@ -182,7 +182,7 @@ public function setIssueTime(?DateTime $issueTime = null) : self } /** - * @return DateTime + * @return DateTime|null */ public function getDueDate(): ?DateTime { @@ -200,7 +200,7 @@ public function setDueDate(?DateTime $dueDate) } /** - * @return string + * @return string|null */ public function getDocumentCurrencyCode(): ?string { @@ -208,7 +208,7 @@ public function getDocumentCurrencyCode(): ?string } /** - * @param mixed $currencyCode + * @param string|null $currencyCode * @return static */ public function setDocumentCurrencyCode(?string $currencyCode = "EUR") @@ -218,7 +218,7 @@ public function setDocumentCurrencyCode(?string $currencyCode = "EUR") } /** - * @return string + * @return string|null */ public function getTaxCurrencyCode(): ?string { @@ -236,7 +236,7 @@ public function setTaxCurrencyCode(?string $currencyCode) } /** - * @return int + * @return int|null */ public function getInvoiceTypeCode(): ?int { @@ -244,7 +244,7 @@ public function getInvoiceTypeCode(): ?int } /** - * @param int $invoiceTypeCode + * @param int|null $invoiceTypeCode * See also: src/InvoiceTypeCode.php * @return static */ @@ -255,7 +255,7 @@ public function setInvoiceTypeCode(?int $invoiceTypeCode) } /** - * @return string + * @return string|null */ public function getNote() { @@ -263,7 +263,7 @@ public function getNote() } /** - * @param ?string $note + * @param string|null $note * @return static */ public function setNote(?string $note) @@ -273,7 +273,7 @@ public function setNote(?string $note) } /** - * @return DateTime + * @return DateTime|null */ public function getTaxPointDate(): ?DateTime { @@ -291,7 +291,7 @@ public function setTaxPointDate(?DateTime $taxPointDate) } /** - * @return PaymentTerms + * @return PaymentTerms|null */ public function getPaymentTerms(): ?PaymentTerms { @@ -309,7 +309,7 @@ public function setPaymentTerms(?PaymentTerms $paymentTerms) } /** - * @return AccountingParty + * @return AccountingParty|null */ public function getAccountingSupplierParty(): ?AccountingParty { @@ -328,7 +328,7 @@ public function setAccountingSupplierParty( } /** - * @return AccountingParty + * @return AccountingParty|null */ public function getAccountingCustomerParty(): ?AccountingParty { @@ -347,7 +347,7 @@ public function setAccountingCustomerParty( } /** - * @return ?Contact + * @return Contact|null */ public function getAccountingCustomerPartyContact(): ?Contact { @@ -366,7 +366,7 @@ public function setAccountingCustomerPartyContact( } /** - * @return PayeeParty + * @return PayeeParty|null */ public function getPayeeParty(): ?PayeeParty { @@ -374,7 +374,7 @@ public function getPayeeParty(): ?PayeeParty } /** - * @param PayeeParty $payeeParty + * @param PayeeParty|null $payeeParty * @return static */ public function setPayeeParty(?PayeeParty $payeeParty) @@ -384,7 +384,7 @@ public function setPayeeParty(?PayeeParty $payeeParty) } /** - * @return PaymentMeans[] + * @return PaymentMeans[]|null */ public function getPaymentMeans(): ?array { @@ -392,17 +392,17 @@ public function getPaymentMeans(): ?array } /** - * @param PaymentMeans[] $paymentMeans + * @param PaymentMeans[]|null $paymentMeans * @return static */ - public function setPaymentMeans(array $paymentMeans) + public function setPaymentMeans(?array $paymentMeans) { $this->paymentMeans = $paymentMeans; return $this; } /** - * @return TaxTotal + * @return TaxTotal|null */ public function getTaxTotal(): ?TaxTotal { @@ -420,7 +420,7 @@ public function setTaxTotal(TaxTotal $taxTotal) } /** - * @return LegalMonetaryTotal + * @return LegalMonetaryTotal|null */ public function getLegalMonetaryTotal(): ?LegalMonetaryTotal { @@ -439,7 +439,7 @@ public function setLegalMonetaryTotal( } /** - * @return staticLine[] + * @return InvoiceLine[]|null */ public function getInvoiceLines(): ?array { @@ -457,7 +457,7 @@ public function setInvoiceLines(array $invoiceLines) } /** - * @return AllowanceCharge[] + * @return AllowanceCharge[]|null */ public function getAllowanceCharges(): ?array { @@ -475,7 +475,7 @@ public function setAllowanceCharges(array $allowanceCharges) } /** - * @return AdditionalDocumentReference + * @return AdditionalDocumentReference|null * @deprecated Deprecated since v1.16 - Replace implementation with setAdditionalDocumentReference or addAdditionalDocumentReference to add/set a single AdditionalDocumentReference */ public function getAdditionalDocumentReference(): ?AdditionalDocumentReference @@ -503,7 +503,7 @@ public function setAdditionalDocumentReference( } /** - * @param AdditionalDocumentReference $additionalDocumentReference + * @param array $additionalDocumentReference * @return static */ public function setAdditionalDocumentReferences( @@ -536,7 +536,7 @@ public function setProjectReference( } /** - * @return ProjectReference projectReference + * @return ProjectReference|null */ public function getProjectReference(): ?ProjectReference { @@ -544,7 +544,7 @@ public function getProjectReference(): ?ProjectReference } /** - * @param string $buyerReference + * @param string|null $buyerReference * @return static */ public function setBuyerReference(?string $buyerReference) @@ -554,7 +554,7 @@ public function setBuyerReference(?string $buyerReference) } /** - * @return string buyerReference + * @return string|null */ public function getBuyerReference(): ?string { @@ -562,7 +562,7 @@ public function getBuyerReference(): ?string } /** - * @return mixed + * @return string|null */ public function getAccountingCostCode(): ?string { @@ -570,7 +570,7 @@ public function getAccountingCostCode(): ?string } /** - * @param mixed $accountingCostCode + * @param string|null $accountingCostCode * @return static */ public function setAccountingCostCode(?string $accountingCostCode) @@ -580,7 +580,7 @@ public function setAccountingCostCode(?string $accountingCostCode) } /** - * @return staticPeriod + * @return InvoicePeriod|null */ public function getInvoicePeriod(): ?InvoicePeriod { @@ -588,7 +588,7 @@ public function getInvoicePeriod(): ?InvoicePeriod } /** - * @param InvoicePeriod $invoicePeriod + * @param InvoicePeriod|null $invoicePeriod * @return static */ public function setInvoicePeriod(?InvoicePeriod $invoicePeriod) @@ -600,7 +600,7 @@ public function setInvoicePeriod(?InvoicePeriod $invoicePeriod) /** * Get the reference to the invoice that is being credited * - * @return ?BillingReference + * @return BillingReference|null */ public function getBillingReference(): ?BillingReference { @@ -619,7 +619,7 @@ public function setBillingReference(?BillingReference $billingReference) } /** - * @return Delivery + * @return Delivery|null */ public function getDelivery(): ?Delivery { @@ -627,7 +627,7 @@ public function getDelivery(): ?Delivery } /** - * @param Delivery $delivery + * @param Delivery|null $delivery * @return static */ public function setDelivery(?Delivery $delivery) @@ -637,7 +637,7 @@ public function setDelivery(?Delivery $delivery) } /** - * @return OrderReference + * @return OrderReference|null */ public function getOrderReference(): ?OrderReference { @@ -645,7 +645,7 @@ public function getOrderReference(): ?OrderReference } /** - * @param OrderReference $orderReference + * @param OrderReference|null $orderReference * @return static */ public function setOrderReference(?OrderReference $orderReference) @@ -655,7 +655,7 @@ public function setOrderReference(?OrderReference $orderReference) } /** - * @return ContractDocumentReference + * @return ContractDocumentReference|null */ public function getContractDocumentReference(): ?ContractDocumentReference { @@ -663,18 +663,17 @@ public function getContractDocumentReference(): ?ContractDocumentReference } /** - * @param ContractDocumentReference $ContractDocumentReference + * @param ContractDocumentReference|null $contractDocumentReference * @return static */ - public function setContractDocumentReference( - ?ContractDocumentReference $contractDocumentReference - ) { + public function setContractDocumentReference(?ContractDocumentReference $contractDocumentReference) + { $this->contractDocumentReference = $contractDocumentReference; return $this; } /** - * @return DespatchDocumentReference + * @return DespatchDocumentReference|null */ public function getDespatchDocumentReference(): ?DespatchDocumentReference { @@ -682,7 +681,7 @@ public function getDespatchDocumentReference(): ?DespatchDocumentReference } /** - * @param DespatchDocumentReference $despatchDocumentReference + * @param DespatchDocumentReference|null $despatchDocumentReference * @return static */ public function setDespatchDocumentReference( @@ -693,7 +692,7 @@ public function setDespatchDocumentReference( } /** - * @return ReceiptDocumentReference + * @return ReceiptDocumentReference|null */ public function getReceiptDocumentReference(): ?ReceiptDocumentReference { @@ -701,7 +700,7 @@ public function getReceiptDocumentReference(): ?ReceiptDocumentReference } /** - * @param ReceiptDocumentReference $receiptDocumentReference + * @param ReceiptDocumentReference|null $receiptDocumentReference * @return static */ public function setReceiptDocumentReference( @@ -712,7 +711,7 @@ public function setReceiptDocumentReference( } /** - * @return OriginatorDocumentReference + * @return OriginatorDocumentReference|null */ public function getOriginatorDocumentReference(): ?OriginatorDocumentReference { @@ -720,7 +719,7 @@ public function getOriginatorDocumentReference(): ?OriginatorDocumentReference } /** - * @param OriginatorDocumentReference $originatorDocumentReference + * @param OriginatorDocumentReference|null $originatorDocumentReference * @return static */ public function setOriginatorDocumentReference( @@ -902,10 +901,7 @@ public function xmlSerialize(Writer $writer): void } if (!empty($this->additionalDocumentReferences)) { - foreach ( - $this->additionalDocumentReferences - as $additionalDocumentReference - ) { + foreach ($this->additionalDocumentReferences as $additionalDocumentReference) { $writer->write([ Schema::CAC . "AdditionalDocumentReference" => $additionalDocumentReference, @@ -988,7 +984,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) diff --git a/src/InvoiceDocumentReference.php b/src/InvoiceDocumentReference.php index ffccb62..0592d8f 100644 --- a/src/InvoiceDocumentReference.php +++ b/src/InvoiceDocumentReference.php @@ -2,6 +2,7 @@ namespace NumNum\UBL; +use Exception; use function Sabre\Xml\Deserializer\keyValue; use DateTime; @@ -13,12 +14,12 @@ class InvoiceDocumentReference implements XmlSerializable, XmlDeserializable { - private $originalInvoiceId; - private $issueDate; + private ?string $originalInvoiceId = null; + private ?DateTime $issueDate = null; /** * Get the id of the invoice that is being credited - * @return string + * @return string|null */ public function getOriginalInvoiceId(): ?string { @@ -40,7 +41,7 @@ public function setOriginalInvoiceId(?string $invoiceRef) /** * Get the issue date of the original invoice that is being credited * - * @return ?DateTime + * @return DateTime|null */ public function getIssueDate(): ?DateTime { @@ -61,8 +62,8 @@ public function setIssueDate(?DateTime $issueDate) /** * The validate function that is called during xml writing to valid the data of the object. * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { @@ -99,16 +100,20 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static + * @throws Exception */ public static function xmlDeserialize(Reader $reader) { $mixedContent = keyValue($reader); + $issueDate = isset($mixedContent[Schema::CBC . 'IssueDate']) + ? new DateTime($mixedContent[Schema::CBC . 'IssueDate']) + : null; + return (new static()) ->setOriginalInvoiceId($mixedContent[Schema::CBC . 'ID'] ?? null) - ->setIssueDate(isset($mixedContent[Schema::CBC . 'IssueDate']) ? new DateTime($mixedContent[Schema::CBC . 'IssueDate']) : null) - ; + ->setIssueDate($issueDate); } } diff --git a/src/InvoiceLine.php b/src/InvoiceLine.php index acb5407..aad6509 100644 --- a/src/InvoiceLine.php +++ b/src/InvoiceLine.php @@ -12,22 +12,22 @@ class InvoiceLine implements XmlSerializable, XmlDeserializable { - public $xmlTagName = 'InvoiceLine'; - private $id; - protected $invoicedQuantity; - private $lineExtensionAmount; - private $unitCode = UnitCode::UNIT; - private $unitCodeListId; - private $taxTotal; - private $invoicePeriod; - private $orderLineReference; - private $note; - private $item; - private $price; - private $accountingCostCode; - private $accountingCost; + public string $xmlTagName = 'InvoiceLine'; + private ?string $id = null; + protected ?float $invoicedQuantity = null; + private ?float $lineExtensionAmount = null; + private ?string $unitCode = UnitCode::UNIT; + private ?string $unitCodeListId = null; + private ?TaxTotal $taxTotal = null; + private ?InvoicePeriod $invoicePeriod = null; + private ?OrderLineReference $orderLineReference = null; + private ?string $note = null; + private ?Item $item = null; + private ?Price $price = null; + private ?string $accountingCostCode = null; + private ?string $accountingCost = null; /** @var AllowanceCharge[] $allowanceCharges */ - private $allowanceCharges; + private ?array $allowanceCharges = null; private function isCreditNoteLine(): bool { @@ -40,7 +40,7 @@ private function isDebitNoteLine(): bool } /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -48,7 +48,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -58,7 +58,7 @@ public function setId(?string $id) } /** - * @return float + * @return float|null */ public function getInvoicedQuantity(): ?float { @@ -76,7 +76,7 @@ public function setInvoicedQuantity(?float $invoicedQuantity) } /** - * @return float + * @return float|null */ public function getLineExtensionAmount(): ?float { @@ -84,7 +84,7 @@ public function getLineExtensionAmount(): ?float } /** - * @param float $lineExtensionAmount + * @param float|null $lineExtensionAmount * @return static */ public function setLineExtensionAmount(?float $lineExtensionAmount) @@ -94,7 +94,7 @@ public function setLineExtensionAmount(?float $lineExtensionAmount) } /** - * @return TaxTotal + * @return TaxTotal|null */ public function getTaxTotal(): ?TaxTotal { @@ -102,7 +102,7 @@ public function getTaxTotal(): ?TaxTotal } /** - * @param TaxTotal $taxTotal + * @param TaxTotal|null $taxTotal * @return static */ public function setTaxTotal(?TaxTotal $taxTotal) @@ -112,7 +112,7 @@ public function setTaxTotal(?TaxTotal $taxTotal) } /** - * @return string + * @return string|null */ public function getNote(): ?string { @@ -120,7 +120,7 @@ public function getNote(): ?string } /** - * @param string $note + * @param string|null $note * @return static */ public function setNote(?string $note) @@ -130,7 +130,7 @@ public function setNote(?string $note) } /** - * @return InvoicePeriod + * @return InvoicePeriod|null */ public function getInvoicePeriod(): ?InvoicePeriod { @@ -138,7 +138,7 @@ public function getInvoicePeriod(): ?InvoicePeriod } /** - * @param InvoicePeriod $invoicePeriod + * @param InvoicePeriod|null $invoicePeriod * @return static */ public function setInvoicePeriod(?InvoicePeriod $invoicePeriod) @@ -148,7 +148,7 @@ public function setInvoicePeriod(?InvoicePeriod $invoicePeriod) } /** - * @return string + * @return OrderLineReference|null */ public function getOrderLineReference(): ?OrderLineReference { @@ -156,7 +156,7 @@ public function getOrderLineReference(): ?OrderLineReference } /** - * @param ?string $orderLineReference + * @param OrderLineReference|null $orderLineReference * @return static */ public function setOrderLineReference(?OrderLineReference $orderLineReference) @@ -166,7 +166,7 @@ public function setOrderLineReference(?OrderLineReference $orderLineReference) } /** - * @return Item + * @return Item|null */ public function getItem(): ?Item { @@ -174,7 +174,7 @@ public function getItem(): ?Item } /** - * @param Item $item + * @param Item|null $item * @return static */ public function setItem(?Item $item) @@ -184,7 +184,7 @@ public function setItem(?Item $item) } /** - * @return Price + * @return Price|null */ public function getPrice(): ?Price { @@ -192,7 +192,7 @@ public function getPrice(): ?Price } /** - * @param Price $price + * @param Price|null $price * @return static */ public function setPrice(?Price $price) @@ -202,7 +202,7 @@ public function setPrice(?Price $price) } /** - * @return string + * @return string|null */ public function getUnitCode(): ?string { @@ -210,7 +210,7 @@ public function getUnitCode(): ?string } /** - * @param string $unitCode + * @param string|null $unitCode * @return static */ public function setUnitCode(?string $unitCode) @@ -220,7 +220,7 @@ public function setUnitCode(?string $unitCode) } /** - * @return string + * @return string|null */ public function getUnitCodeListId(): ?string { @@ -228,7 +228,7 @@ public function getUnitCodeListId(): ?string } /** - * @param string $unitCodeListId + * @param string|null $unitCodeListId * @return static */ public function setUnitCodeListId(?string $unitCodeListId) @@ -238,7 +238,7 @@ public function setUnitCodeListId(?string $unitCodeListId) } /** - * @return string + * @return string|null */ public function getAccountingCostCode(): ?string { @@ -246,7 +246,7 @@ public function getAccountingCostCode(): ?string } /** - * @param string $accountingCostCode + * @param string|null $accountingCostCode * @return static */ public function setAccountingCostCode(?string $accountingCostCode) @@ -256,7 +256,7 @@ public function setAccountingCostCode(?string $accountingCostCode) } /** - * @return string + * @return string|null */ public function getAccountingCost(): ?string { @@ -264,7 +264,7 @@ public function getAccountingCost(): ?string } /** - * @param string $accountingCost + * @param string|null $accountingCost * @return static */ public function setAccountingCost(?string $accountingCost) @@ -274,7 +274,7 @@ public function setAccountingCost(?string $accountingCost) } /** - * @return AllowanceCharge[] + * @return AllowanceCharge[]|null */ public function getAllowanceCharges(): ?array { @@ -403,13 +403,21 @@ protected static function deserializedTag(array $mixedContent) { $collection = new ArrayCollection($mixedContent); + $invoicedQuantity = ReaderHelper::getTagValue(Schema::CBC . 'InvoicedQuantity', $collection) !== null + ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'InvoicedQuantity', $collection)) + : null; + + $lineExtensionAmount = ReaderHelper::getTagValue(Schema::CBC . 'LineExtensionAmount', $collection) !== null + ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'LineExtensionAmount', $collection)) + : null; + /** @var ?AllowanceCharge[] ReaderHelper::getArrayValue */ $allowanceCharges = ReaderHelper::getArrayValue(Schema::CAC . 'AllowanceCharge', $collection); return (new static()) ->setId(ReaderHelper::getTagValue(Schema::CBC . 'ID', $collection)) - ->setInvoicedQuantity(ReaderHelper::getTagValue(Schema::CBC . 'InvoicedQuantity', $collection) !== null ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'InvoicedQuantity', $collection)) : null) - ->setLineExtensionAmount(ReaderHelper::getTagValue(Schema::CBC . 'LineExtensionAmount', $collection) !== null ? floatval(ReaderHelper::getTagValue(Schema::CBC . 'LineExtensionAmount', $collection)) : null) + ->setInvoicedQuantity($invoicedQuantity) + ->setLineExtensionAmount($lineExtensionAmount) ->setTaxTotal(ReaderHelper::getTagValue(Schema::CAC . 'TaxTotal', $collection)) ->setNote(ReaderHelper::getTagValue(Schema::CBC . 'Note', $collection)) ->setInvoicePeriod(ReaderHelper::getTagValue(Schema::CAC . 'InvoicePeriod', $collection)) diff --git a/src/InvoicePeriod.php b/src/InvoicePeriod.php index dbc28b6..bb6bfbb 100644 --- a/src/InvoicePeriod.php +++ b/src/InvoicePeriod.php @@ -15,12 +15,12 @@ class InvoicePeriod implements XmlSerializable, XmlDeserializable { - private $startDate; - private $endDate; - private $descriptionCode; + private ?DateTime $startDate = null; + private ?DateTime $endDate = null; + private ?int $descriptionCode = null; /** - * @return DateTime + * @return DateTime|null */ public function getStartDate(): ?DateTime { @@ -28,7 +28,7 @@ public function getStartDate(): ?DateTime } /** - * @param DateTime $startDate + * @param DateTime|null $startDate * @return static */ public function setStartDate(?DateTime $startDate) @@ -38,7 +38,7 @@ public function setStartDate(?DateTime $startDate) } /** - * @return DateTime + * @return DateTime|null */ public function getEndDate(): ?DateTime { @@ -46,7 +46,7 @@ public function getEndDate(): ?DateTime } /** - * @param DateTime $endDate + * @param DateTime|null $endDate * @return static */ public function setEndDate(?DateTime $endDate) @@ -56,7 +56,7 @@ public function setEndDate(?DateTime $endDate) } /** - * @return int + * @return int|null */ public function getDescriptionCode(): ?int { @@ -64,7 +64,7 @@ public function getDescriptionCode(): ?int } /** - * @param Integer $descriptionCode + * @param int|null $descriptionCode * @return static */ public function setDescriptionCode(?int $descriptionCode) @@ -76,8 +76,8 @@ public function setDescriptionCode(?int $descriptionCode) /** * The validate function that is called during xml writing to valid the data of the object. * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { @@ -115,17 +115,28 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) { $keyValues = keyValue($reader); + $startDate = isset($keyValues[Schema::CBC . 'StartDate']) + ? Carbon::parse($keyValues[Schema::CBC . 'StartDate'])->toDateTime() + : null; + + $endDate = isset($keyValues[Schema::CBC . 'EndDate']) + ? Carbon::parse($keyValues[Schema::CBC . 'EndDate'])->toDateTime() + : null; + + $descriptionCode = isset($keyValues[Schema::CBC . 'DescriptionCode']) + ? intval($keyValues[Schema::CBC . 'DescriptionCode']) + : null; + return (new static()) - ->setStartDate(isset($keyValues[Schema::CBC . 'StartDate']) ? Carbon::parse($keyValues[Schema::CBC . 'StartDate'])->toDateTime() : null) - ->setEndDate(isset($keyValues[Schema::CBC . 'EndDate']) ? Carbon::parse($keyValues[Schema::CBC . 'EndDate'])->toDateTime() : null) - ->setDescriptionCode(isset($keyValues[Schema::CBC . 'DescriptionCode']) ? intval($keyValues[Schema::CBC . 'DescriptionCode']) : null) - ; + ->setStartDate($startDate) + ->setEndDate($endDate) + ->setDescriptionCode($descriptionCode); } } diff --git a/src/Item.php b/src/Item.php index 957f01f..7519e9a 100644 --- a/src/Item.php +++ b/src/Item.php @@ -12,19 +12,19 @@ class Item implements XmlSerializable, XmlDeserializable { - private $description; - private $name; - private $buyersItemIdentification; - private $sellersItemIdentification; - private $standardItemIdentification; - private $standardItemIdentificationAttributes = []; - private $commodityClassification; - private $classifiedTaxCategory; - private $originCountry; - private $additionalItemProperties; + private ?string $description = null; + private ?string $name = null; + private ?string $buyersItemIdentification = null; + private ?string $sellersItemIdentification = null; + private ?string $standardItemIdentification = null; + private array $standardItemIdentificationAttributes = []; + private ?CommodityClassification $commodityClassification = null; + private ?ClassifiedTaxCategory $classifiedTaxCategory = null; + private ?Country $originCountry = null; + private ?array $additionalItemProperties = null; /** - * @return string + * @return string|null */ public function getDescription(): ?string { @@ -32,7 +32,7 @@ public function getDescription(): ?string } /** - * @param string $description + * @param string|null $description * @return static */ public function setDescription(?string $description) @@ -42,7 +42,7 @@ public function setDescription(?string $description) } /** - * @return mixed + * @return string|null */ public function getName(): ?string { @@ -50,7 +50,7 @@ public function getName(): ?string } /** - * @param mixed $name + * @param string|null $name * @return static */ public function setName(?string $name) @@ -60,7 +60,7 @@ public function setName(?string $name) } /** - * @return mixed + * @return string|null */ public function getSellersItemIdentification(): ?string { @@ -68,7 +68,7 @@ public function getSellersItemIdentification(): ?string } /** - * @param mixed $sellersItemIdentification + * @param string|null $sellersItemIdentification * @return static */ public function setSellersItemIdentification(?string $sellersItemIdentification) @@ -78,7 +78,7 @@ public function setSellersItemIdentification(?string $sellersItemIdentification) } /** - * @return mixed + * @return string|null */ public function getStandardItemIdentification(): ?string { @@ -86,10 +86,11 @@ public function getStandardItemIdentification(): ?string } /** - * @param mixed $standardItemIdentification + * @param string|null $standardItemIdentification + * @param array|null $attributes * @return static */ - public function setStandardItemIdentification(?string $standardItemIdentification, $attributes = null) + public function setStandardItemIdentification(?string $standardItemIdentification, array $attributes = null) { $this->standardItemIdentification = $standardItemIdentification; if (isset($attributes)) { @@ -99,7 +100,7 @@ public function setStandardItemIdentification(?string $standardItemIdentificatio } /** - * @return CommodityClassification + * @return CommodityClassification|null */ public function getCommodityClassification(): ?CommodityClassification { @@ -117,7 +118,7 @@ public function setCommodityClassification(?CommodityClassification $commodityCl } /** - * @return mixed + * @return string|null */ public function getBuyersItemIdentification(): ?string { @@ -125,7 +126,7 @@ public function getBuyersItemIdentification(): ?string } /** - * @param mixed $buyersItemIdentification + * @param string|null $buyersItemIdentification * @return static */ public function setBuyersItemIdentification(?string $buyersItemIdentification) @@ -135,7 +136,7 @@ public function setBuyersItemIdentification(?string $buyersItemIdentification) } /** - * @return ClassifiedTaxCategory + * @return ClassifiedTaxCategory|null */ public function getClassifiedTaxCategory(): ?ClassifiedTaxCategory { @@ -143,7 +144,7 @@ public function getClassifiedTaxCategory(): ?ClassifiedTaxCategory } /** - * @param ClassifiedTaxCategory $classifiedTaxCategory + * @param ClassifiedTaxCategory|null $classifiedTaxCategory * @return static */ public function setClassifiedTaxCategory(?ClassifiedTaxCategory $classifiedTaxCategory) @@ -153,7 +154,7 @@ public function setClassifiedTaxCategory(?ClassifiedTaxCategory $classifiedTaxCa } /** - * @return Country + * @return Country|null */ public function getOriginCountry(): ?Country { @@ -161,7 +162,7 @@ public function getOriginCountry(): ?Country } /** - * @param Country $originCountry + * @param Country|null $originCountry * @return Item */ public function setOriginCountry(?Country $originCountry): Item @@ -171,7 +172,7 @@ public function setOriginCountry(?Country $originCountry): Item } /** - * @return AdditionalItemProperty[] + * @return AdditionalItemProperty[]|null */ public function getAdditionalItemProperties(): ?array { @@ -262,7 +263,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -275,7 +276,10 @@ public static function xmlDeserialize(Reader $reader) $classifiedTaxCategoryTag = ReaderHelper::getTag(Schema::CAC . 'ClassifiedTaxCategory', $collection); $commodityClassification = ReaderHelper::getTag(Schema::CAC . 'CommodityClassification', $collection); $originCountryTag = ReaderHelper::getTag(Schema::CAC . 'OriginCountry', $collection); - $additionalItemPropertiesTags = ReaderHelper::getArrayValue(Schema::CAC . 'AdditionalItemProperty', $collection); + $additionalItemPropertiesTags = ReaderHelper::getArrayValue( + Schema::CAC . 'AdditionalItemProperty', + $collection + ); $buyersItemIdentificationTag = ReaderHelper::getTag(Schema::CAC . 'BuyersItemIdentification', $collection); $buyersItemIdentificationIdTag = ReaderHelper::getTag( @@ -295,16 +299,18 @@ public static function xmlDeserialize(Reader $reader) new ArrayCollection($standardItemIdentificationTag['value'] ?? []) ); + $standardItemIdentificationValue = $standardItemIdentificationIdTag['value'] ?? null; + $standardItemIdentificationAttributes = $standardItemIdentificationIdTag['attributes'] ?? null; + return (new static()) ->setDescription($descriptionTag['value'] ?? null) ->setName($nameTag['value'] ?? null) ->setBuyersItemIdentification($buyersItemIdentificationIdTag['value'] ?? null) ->setSellersItemIdentification($sellersItemIdentificationIdTag['value'] ?? null) - ->setStandardItemIdentification($standardItemIdentificationIdTag['value'] ?? null, $standardItemIdentificationIdTag['attributes'] ?? null) + ->setStandardItemIdentification($standardItemIdentificationValue, $standardItemIdentificationAttributes) ->setClassifiedTaxCategory($classifiedTaxCategoryTag['value'] ?? null) ->setCommodityClassification($commodityClassification['value'] ?? null) ->setOriginCountry($originCountryTag['value'] ?? null) - ->setAdditionalItemProperties($additionalItemPropertiesTags) - ; + ->setAdditionalItemProperties($additionalItemPropertiesTags); } } diff --git a/src/LegalEntity.php b/src/LegalEntity.php index 28bfe96..938a49a 100644 --- a/src/LegalEntity.php +++ b/src/LegalEntity.php @@ -12,14 +12,14 @@ class LegalEntity implements XmlSerializable, XmlDeserializable { - private $registrationName; - private $companyId; - private $companyIdAttributes; - private $companyLegalForm; - private $companyLegalFormAttributes; + private ?string $registrationName = null; + private ?string $companyId = null; + private ?array $companyIdAttributes = null; + private ?string $companyLegalForm = null; + private ?array $companyLegalFormAttributes = null; /** - * @return string + * @return string|null */ public function getRegistrationName(): ?string { @@ -27,7 +27,7 @@ public function getRegistrationName(): ?string } /** - * @param string $registrationName + * @param string|null $registrationName * @return static */ public function setRegistrationName(?string $registrationName) @@ -37,7 +37,7 @@ public function setRegistrationName(?string $registrationName) } /** - * @return string + * @return string|null */ public function getCompanyId(): ?string { @@ -45,10 +45,11 @@ public function getCompanyId(): ?string } /** - * @param string $companyId + * @param string|null $companyId + * @param array|null $attributes * @return static */ - public function setCompanyId(?string $companyId, $attributes = null) + public function setCompanyId(?string $companyId, array $attributes = null) { $this->companyId = $companyId; @@ -74,11 +75,11 @@ public function getCompanyIdSchemeId(): ?string } /** - * - * @param string $legalForm + * @param string|null $legalForm + * @param array|null $attributes * @return static - */ - public function setCompanyLegalForm(?string $legalForm, $attributes = null) + */ + public function setCompanyLegalForm(?string $legalForm, array $attributes = null) { $this->companyLegalForm = $legalForm; @@ -123,7 +124,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -144,7 +145,6 @@ public static function xmlDeserialize(Reader $reader) ->setCompanyLegalForm( $companyLegalForm['value'] ?? null, $companyLegalForm['attributes'] ?? null - ) - ; + ); } } diff --git a/src/LegalMonetaryTotal.php b/src/LegalMonetaryTotal.php index 4abcd76..f8d27d0 100644 --- a/src/LegalMonetaryTotal.php +++ b/src/LegalMonetaryTotal.php @@ -11,17 +11,17 @@ class LegalMonetaryTotal implements XmlSerializable, XmlDeserializable { - private $lineExtensionAmount = 0; - private $taxExclusiveAmount = 0; - private $taxInclusiveAmount = 0; - private $allowanceTotalAmount; - private $chargeTotalAmount; - private $prepaidAmount; - private $payableAmount = 0; - private $payableRoundingAmount; + private ?float $lineExtensionAmount = 0; + private ?float $taxExclusiveAmount = 0; + private ?float $taxInclusiveAmount = 0; + private ?float $allowanceTotalAmount = null; + private ?float $chargeTotalAmount = null; + private ?float $prepaidAmount = null; + private ?float $payableAmount = 0; + private ?float $payableRoundingAmount = null; /** - * @return float + * @return float|null */ public function getLineExtensionAmount(): ?float { @@ -29,7 +29,7 @@ public function getLineExtensionAmount(): ?float } /** - * @param float $lineExtensionAmount + * @param float|null $lineExtensionAmount * @return static */ public function setLineExtensionAmount(?float $lineExtensionAmount) @@ -39,7 +39,7 @@ public function setLineExtensionAmount(?float $lineExtensionAmount) } /** - * @return float + * @return float|null */ public function getTaxExclusiveAmount(): ?float { @@ -47,7 +47,7 @@ public function getTaxExclusiveAmount(): ?float } /** - * @param float $taxExclusiveAmount + * @param float|null $taxExclusiveAmount * @return static */ public function setTaxExclusiveAmount(?float $taxExclusiveAmount) @@ -57,7 +57,7 @@ public function setTaxExclusiveAmount(?float $taxExclusiveAmount) } /** - * @return float + * @return float|null */ public function getTaxInclusiveAmount(): ?float { @@ -65,7 +65,7 @@ public function getTaxInclusiveAmount(): ?float } /** - * @param float $taxInclusiveAmount + * @param float|null $taxInclusiveAmount * @return static */ public function setTaxInclusiveAmount(?float $taxInclusiveAmount) @@ -75,7 +75,7 @@ public function setTaxInclusiveAmount(?float $taxInclusiveAmount) } /** - * @return float + * @return float|null */ public function getAllowanceTotalAmount(): ?float { @@ -83,7 +83,7 @@ public function getAllowanceTotalAmount(): ?float } /** - * @param float $allowanceTotalAmount + * @param float|null $allowanceTotalAmount * @return static */ public function setAllowanceTotalAmount(?float $allowanceTotalAmount) @@ -93,7 +93,7 @@ public function setAllowanceTotalAmount(?float $allowanceTotalAmount) } /** - * @return float + * @return float|null */ public function getChargeTotalAmount(): ?float { @@ -101,7 +101,7 @@ public function getChargeTotalAmount(): ?float } /** - * @param float $chargeTotalAmount + * @param float|null $chargeTotalAmount * @return static */ public function setChargeTotalAmount(?float $chargeTotalAmount) @@ -111,7 +111,7 @@ public function setChargeTotalAmount(?float $chargeTotalAmount) } /** - * @return ?float + * @return float|null */ public function getPrepaidAmount(): ?float { @@ -129,7 +129,7 @@ public function setPrepaidAmount(?float $prepaidAmount) } /** - * @return float + * @return float|null */ public function getPayableAmount(): ?float { @@ -137,7 +137,7 @@ public function getPayableAmount(): ?float } /** - * @param float $payableAmount + * @param float|null $payableAmount * @return static */ public function setPayableAmount(?float $payableAmount) @@ -146,6 +146,9 @@ public function setPayableAmount(?float $payableAmount) return $this; } + /** + * @return float|null + */ public function getPayableRoundingAmount(): ?float { return $this->payableRoundingAmount; @@ -256,25 +259,51 @@ public function xmlSerialize(Writer $writer): void } - /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) { $keyValues = keyValue($reader); + $lineExtensionAmount = isset($keyValues[Schema::CBC . 'LineExtensionAmount']) + ? floatval($keyValues[Schema::CBC . 'LineExtensionAmount']) + : null; + + $taxExclusiveAmount = isset($keyValues[Schema::CBC . 'TaxExclusiveAmount']) + ? floatval($keyValues[Schema::CBC . 'TaxExclusiveAmount']) + : null; + + $taxInclusiveAmount = isset($keyValues[Schema::CBC . 'TaxInclusiveAmount']) + ? floatval($keyValues[Schema::CBC . 'TaxInclusiveAmount']) + : null; + + $allowanceTotalAmount = isset($keyValues[Schema::CBC . 'AllowanceTotalAmount']) + ? floatval($keyValues[Schema::CBC . 'AllowanceTotalAmount']) + : null; + + $chargeTotalAmount = isset($keyValues[Schema::CBC . 'ChargeTotalAmount']) + ? floatval($keyValues[Schema::CBC . 'ChargeTotalAmount']) + : null; + + $prepaidAmount = isset($keyValues[Schema::CBC . 'PrepaidAmount']) + ? floatval($keyValues[Schema::CBC . 'PrepaidAmount']) + : null; + + $payableAmount = isset($keyValues[Schema::CBC . 'PayableAmount']) + ? floatval($keyValues[Schema::CBC . 'PayableAmount']) + : null; + return (new static()) - ->setLineExtensionAmount(isset($keyValues[Schema::CBC . 'LineExtensionAmount']) ? floatval($keyValues[Schema::CBC . 'LineExtensionAmount']) : null) - ->setTaxExclusiveAmount(isset($keyValues[Schema::CBC . 'TaxExclusiveAmount']) ? floatval($keyValues[Schema::CBC . 'TaxExclusiveAmount']) : null) - ->setTaxInclusiveAmount(isset($keyValues[Schema::CBC . 'TaxInclusiveAmount']) ? floatval($keyValues[Schema::CBC . 'TaxInclusiveAmount']) : null) - ->setAllowanceTotalAmount(isset($keyValues[Schema::CBC . 'AllowanceTotalAmount']) ? floatval($keyValues[Schema::CBC . 'AllowanceTotalAmount']) : null) - ->setChargeTotalAmount(isset($keyValues[Schema::CBC . 'ChargeTotalAmount']) ? floatval($keyValues[Schema::CBC . 'ChargeTotalAmount']) : null) - ->setPrepaidAmount(isset($keyValues[Schema::CBC . 'PrepaidAmount']) ? floatval($keyValues[Schema::CBC . 'PrepaidAmount']) : null) - ->setPayableRoundingAmount(isset($keyValues[Schema::CBC . 'PayableAmount']) ? floatval($keyValues[Schema::CBC . 'PayableAmount']) : null) - ->setPayableAmount(isset($keyValues[Schema::CBC . 'PayableAmount']) ? floatval($keyValues[Schema::CBC . 'PayableAmount']) : null) - ; + ->setLineExtensionAmount($lineExtensionAmount) + ->setTaxExclusiveAmount($taxExclusiveAmount) + ->setTaxInclusiveAmount($taxInclusiveAmount) + ->setAllowanceTotalAmount($allowanceTotalAmount) + ->setChargeTotalAmount($chargeTotalAmount) + ->setPrepaidAmount($prepaidAmount) + ->setPayableRoundingAmount($payableAmount) + ->setPayableAmount($payableAmount); } } diff --git a/src/NumberFormatter.php b/src/NumberFormatter.php index 3fe3e6f..9e553c4 100644 --- a/src/NumberFormatter.php +++ b/src/NumberFormatter.php @@ -11,7 +11,7 @@ class NumberFormatter * @param int|null $decimals * @param string $decimalSeparator * @param string $thousandsSeparator - * @return void + * @return string */ public static function format( $number, @@ -32,13 +32,11 @@ public static function format( $decimals = isset($parts[1]) ? strlen(rtrim($parts[1], "0")) : 0; } - $value = number_format( + return number_format( $number, $decimals, $decimalSeparator, $thousandsSeparator ); - - return $value; } } diff --git a/src/OrderLineReference.php b/src/OrderLineReference.php index d5481bd..8b2e8a9 100644 --- a/src/OrderLineReference.php +++ b/src/OrderLineReference.php @@ -16,10 +16,10 @@ */ class OrderLineReference implements XmlSerializable, XmlDeserializable { - private $lineId; + private ?string $lineId = null; /** - * @return string + * @return string|null */ public function getLineId(): ?string { @@ -27,7 +27,7 @@ public function getLineId(): ?string } /** - * @param string $lineId + * @param string|null $lineId * @return static */ public function setLineId(?string $lineId) @@ -60,7 +60,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -68,7 +68,6 @@ public static function xmlDeserialize(Reader $reader) $keyValues = keyValue($reader); return (new static()) - ->setLineId($keyValues[Schema::CBC . 'LineID'] ?? null) - ; + ->setLineId($keyValues[Schema::CBC . 'LineID'] ?? null); } } diff --git a/src/OrderReference.php b/src/OrderReference.php index 099c25a..fa7e417 100644 --- a/src/OrderReference.php +++ b/src/OrderReference.php @@ -14,9 +14,9 @@ class OrderReference implements XmlSerializable, XmlDeserializable { - private $id; - private $salesOrderId; - private $issueDate; + private ?string $id = null; + private string $salesOrderId; + private ?DateTime $issueDate = null; /** * @return string|null @@ -45,7 +45,7 @@ public function getSalesOrderId(): string } /** - * @return DateTime + * @return DateTime|null */ public function getIssueDate(): ?DateTime { @@ -53,7 +53,7 @@ public function getIssueDate(): ?DateTime } /** - * @param DateTime $issueDate + * @param DateTime|null $issueDate * @return static */ public function setIssueDate(?DateTime $issueDate) @@ -63,7 +63,7 @@ public function setIssueDate(?DateTime $issueDate) } /** - * @param string $salesOrderId + * @param string|null $salesOrderId * @return static */ public function setSalesOrderId(?string $salesOrderId) @@ -95,17 +95,20 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) { $keyValues = keyValue($reader); + $issueDate = isset($keyValues[Schema::CBC . 'IssueDate']) + ? Carbon::parse($keyValues[Schema::CBC . 'IssueDate'])->toDateTime() + : null; + return (new static()) ->setId($keyValues[Schema::CBC . 'ID'] ?? null) - ->setIssueDate(isset($keyValues[Schema::CBC . 'IssueDate']) ? Carbon::parse($keyValues[Schema::CBC . 'IssueDate'])->toDateTime() : null) - ->setSalesOrderId($keyValues[Schema::CBC . 'SalesOrderID'] ?? null) - ; + ->setIssueDate($issueDate) + ->setSalesOrderId($keyValues[Schema::CBC . 'SalesOrderID'] ?? null); } } diff --git a/src/OriginatorDocumentReference.php b/src/OriginatorDocumentReference.php index ef51444..4738dba 100644 --- a/src/OriginatorDocumentReference.php +++ b/src/OriginatorDocumentReference.php @@ -17,10 +17,10 @@ */ class OriginatorDocumentReference implements XmlSerializable, XmlDeserializable { - private $id; + private ?string $id = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -28,7 +28,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) diff --git a/src/Party.php b/src/Party.php index 261b13c..779fce7 100644 --- a/src/Party.php +++ b/src/Party.php @@ -13,20 +13,20 @@ class Party implements XmlSerializable, XmlDeserializable { - private $name; - private $partyIdentificationId; - private $partyIdentificationSchemeId; - private $partyIdentificationSchemeName; - private $postalAddress; - private $physicalLocation; - private $contact; - private $partyTaxScheme; - private $legalEntity; - private $endpointID; - private $endpointID_schemeID; + private ?string $name = null; + private ?string $partyIdentificationId = null; + private ?string $partyIdentificationSchemeId = null; + private ?string $partyIdentificationSchemeName = null; + private ?Address $postalAddress = null; + private ?Address $physicalLocation = null; + private ?Contact $contact = null; + private ?PartyTaxScheme $partyTaxScheme = null; + private ?LegalEntity $legalEntity = null; + private ?string $endpointID = null; + private ?string $endpointID_schemeID = null; /** - * @return string + * @return string|null */ public function getName(): ?string { @@ -34,7 +34,7 @@ public function getName(): ?string } /** - * @param string $name + * @param string|null $name * @return static */ public function setName(?string $name) @@ -44,7 +44,7 @@ public function setName(?string $name) } /** - * @return string + * @return string|null */ public function getPartyIdentificationId(): ?string { @@ -52,7 +52,7 @@ public function getPartyIdentificationId(): ?string } /** - * @param string $partyIdentificationId + * @param string|null $partyIdentificationId * @return static */ public function setPartyIdentificationId(?string $partyIdentificationId) @@ -62,7 +62,7 @@ public function setPartyIdentificationId(?string $partyIdentificationId) } /** - * @return string + * @return string|null */ public function getPartyIdentificationSchemeId(): ?string { @@ -70,7 +70,7 @@ public function getPartyIdentificationSchemeId(): ?string } /** - * @param string $partyIdentificationSchemeId + * @param string|null $partyIdentificationSchemeId * @return static */ public function setPartyIdentificationSchemeId(?string $partyIdentificationSchemeId) @@ -80,7 +80,7 @@ public function setPartyIdentificationSchemeId(?string $partyIdentificationSchem } /** - * @return string + * @return string|null */ public function getPartyIdentificationSchemeName(): ?string { @@ -88,7 +88,7 @@ public function getPartyIdentificationSchemeName(): ?string } /** - * @param string $partyIdentificationSchemeName + * @param string|null $partyIdentificationSchemeName * @return static */ public function setPartyIdentificationSchemeName(?string $partyIdentificationSchemeName) @@ -98,7 +98,7 @@ public function setPartyIdentificationSchemeName(?string $partyIdentificationSch } /** - * @return Address + * @return Address|null */ public function getPostalAddress(): ?Address { @@ -106,7 +106,7 @@ public function getPostalAddress(): ?Address } /** - * @param Address $postalAddress + * @param Address|null $postalAddress * @return static */ public function setPostalAddress(?Address $postalAddress) @@ -116,7 +116,7 @@ public function setPostalAddress(?Address $postalAddress) } /** - * @return LegalEntity + * @return LegalEntity|null */ public function getLegalEntity(): ?LegalEntity { @@ -124,7 +124,7 @@ public function getLegalEntity(): ?LegalEntity } /** - * @param LegalEntity $legalEntity + * @param LegalEntity|null $legalEntity * @return static */ public function setLegalEntity(?LegalEntity $legalEntity) @@ -134,7 +134,7 @@ public function setLegalEntity(?LegalEntity $legalEntity) } /** - * @return Address + * @return Address|null */ public function getPhysicalLocation(): ?Address { @@ -142,7 +142,7 @@ public function getPhysicalLocation(): ?Address } /** - * @param Address $physicalLocation + * @param Address|null $physicalLocation * @return static */ public function setPhysicalLocation(?Address $physicalLocation) @@ -152,7 +152,7 @@ public function setPhysicalLocation(?Address $physicalLocation) } /** - * @return staticTaxScheme + * @return PartyTaxScheme|null */ public function getPartyTaxScheme(): ?PartyTaxScheme { @@ -160,7 +160,7 @@ public function getPartyTaxScheme(): ?PartyTaxScheme } /** - * @param PartyTaxScheme $partyTaxScheme + * @param PartyTaxScheme|null $partyTaxScheme * @return static */ public function setPartyTaxScheme(?PartyTaxScheme $partyTaxScheme) @@ -170,7 +170,7 @@ public function setPartyTaxScheme(?PartyTaxScheme $partyTaxScheme) } /** - * @return Contact + * @return Contact|null */ public function getContact(): ?Contact { @@ -178,7 +178,7 @@ public function getContact(): ?Contact } /** - * @param Contact $contact + * @param Contact|null $contact * @return static */ public function setContact(?Contact $contact) @@ -199,11 +199,17 @@ public function setEndpointId($endpointID, $schemeID) return $this; } + /** + * @return string|null + */ public function getEndpointId(): ?string { return $this->endpointID; } + /** + * @return string|null + */ public function getEndpointIDSchemeId(): ?string { return $this->endpointID_schemeID; @@ -287,7 +293,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -301,14 +307,20 @@ public static function xmlDeserialize(Reader $reader) $endpointId = ReaderHelper::getTag(Schema::CBC . 'EndpointID', $collection); $postalAddress = ReaderHelper::getTag(Schema::CAC . 'PostalAddress', $collection); $physicalLocation = ReaderHelper::getTag(Schema::CAC . 'PhysicalLocation', $collection); - $physicalLocationAddress = ReaderHelper::getTag(Schema::CAC . 'Address', new ArrayCollection($physicalLocation['value'] ?? [])); + $physicalLocationAddress = ReaderHelper::getTag( + Schema::CAC . 'Address', + new ArrayCollection($physicalLocation['value'] ?? []) + ); $partyTaxScheme = ReaderHelper::getTag(Schema::CAC . 'PartyTaxScheme', $collection); $partyLegalEntity = ReaderHelper::getTag(Schema::CAC . 'PartyLegalEntity', $collection); $partyContact = ReaderHelper::getTag(Schema::CAC . 'Contact', $collection); $partyIdentification = ReaderHelper::getTag(Schema::CAC . 'PartyIdentification', $collection); - $partyIdentificationId = ReaderHelper::getTag(Schema::CBC . 'ID', new ArrayCollection($partyIdentification['value'] ?? [])); + $partyIdentificationId = ReaderHelper::getTag( + Schema::CBC . 'ID', + new ArrayCollection($partyIdentification['value'] ?? []) + ); return (new static()) ->setName($partyNameName['value'] ?? null) @@ -320,7 +332,6 @@ public static function xmlDeserialize(Reader $reader) ->setEndpointId($endpointId['value'] ?? null, $endpointId['attributes']['schemeID'] ?? null) ->setPartyIdentificationId($partyIdentificationId['value'] ?? null) ->setPartyIdentificationSchemeId($partyIdentificationId['attributes']['schemeID'] ?? null) - ->setPartyIdentificationSchemeName($partyIdentificationId['attributes']['schemeName'] ?? null) - ; + ->setPartyIdentificationSchemeName($partyIdentificationId['attributes']['schemeName'] ?? null); } } diff --git a/src/PartyTaxScheme.php b/src/PartyTaxScheme.php index 6c5338f..b6e4623 100644 --- a/src/PartyTaxScheme.php +++ b/src/PartyTaxScheme.php @@ -13,12 +13,12 @@ class PartyTaxScheme implements XmlSerializable, XmlDeserializable { - private $registrationName; - private $companyId; - private $taxScheme; + private ?string $registrationName = null; + private ?string $companyId = null; + private ?TaxScheme $taxScheme = null; /** - * @return string + * @return string|null */ public function getRegistrationName(): ?string { @@ -29,14 +29,14 @@ public function getRegistrationName(): ?string * @param string $registrationName * @return static */ - public function setRegistrationName($registrationName) + public function setRegistrationName(string $registrationName) { $this->registrationName = $registrationName; return $this; } /** - * @return string + * @return string|null */ public function getCompanyId(): ?string { @@ -47,14 +47,14 @@ public function getCompanyId(): ?string * @param string $companyId * @return static */ - public function setCompanyId($companyId) + public function setCompanyId(string $companyId) { $this->companyId = $companyId; return $this; } /** - * @return ?TaxScheme + * @return TaxScheme|null */ public function getTaxScheme(): ?TaxScheme { @@ -62,7 +62,7 @@ public function getTaxScheme(): ?TaxScheme } /** - * @param TaxScheme $taxScheme + * @param TaxScheme|null $taxScheme * @return static */ public function setTaxScheme(?TaxScheme $taxScheme) @@ -111,7 +111,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -121,7 +121,6 @@ public static function xmlDeserialize(Reader $reader) return (new static()) ->setRegistrationName($keyValues[Schema::CBC . 'RegistrationName'] ?? null) ->setCompanyId($keyValues[Schema::CBC . 'CompanyID'] ?? null) - ->setTaxScheme($keyValues[Schema::CAC . 'TaxScheme'] ?? null) - ; + ->setTaxScheme($keyValues[Schema::CAC . 'TaxScheme'] ?? null); } } diff --git a/src/PayeeFinancialAccount.php b/src/PayeeFinancialAccount.php index 3e74c99..27b9e88 100644 --- a/src/PayeeFinancialAccount.php +++ b/src/PayeeFinancialAccount.php @@ -11,12 +11,12 @@ class PayeeFinancialAccount implements XmlSerializable, XmlDeserializable { - private $id; - private $name; - private $financialInstitutionBranch; + private ?string $id = null; + private ?string $name = null; + private ?FinancialInstitutionBranch $financialInstitutionBranch = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -24,7 +24,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -34,7 +34,7 @@ public function setId(?string $id) } /** - * @return string + * @return string|null */ public function getName(): ?string { @@ -42,7 +42,7 @@ public function getName(): ?string } /** - * @param string $name + * @param string|null $name * @return static */ public function setName(?string $name) @@ -52,7 +52,7 @@ public function setName(?string $name) } /** - * @return FinancialInstitutionBranch + * @return FinancialInstitutionBranch|null */ public function getFinancialInstitutionBranch(): ?FinancialInstitutionBranch { @@ -60,7 +60,7 @@ public function getFinancialInstitutionBranch(): ?FinancialInstitutionBranch } /** - * @param FinancialInstitutionBranch $financialInstitutionBranch + * @param FinancialInstitutionBranch|null $financialInstitutionBranch * @return static */ public function setFinancialInstitutionBranch(?FinancialInstitutionBranch $financialInstitutionBranch) @@ -94,7 +94,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) diff --git a/src/PayeeParty.php b/src/PayeeParty.php index ae3bfd0..bc6da10 100644 --- a/src/PayeeParty.php +++ b/src/PayeeParty.php @@ -12,14 +12,14 @@ class PayeeParty implements XmlSerializable, XmlDeserializable { - private $partyIdentificationId; - private $partyIdentificationSchemeId; - private $partyName; - private $partyLegalEntityCompanyId; - private $partyLegalEntityCompanySchemeId; + private ?string $partyIdentificationId = null; + private ?string $partyIdentificationSchemeId = null; + private ?string $partyName = null; + private ?string $partyLegalEntityCompanyId = null; + private ?string $partyLegalEntityCompanySchemeId = null; /** - * @return string + * @return string|null */ public function getPartyIdentificationId(): ?string { @@ -37,7 +37,7 @@ public function setPartyIdentificationId(?string $partyIdentificationId) } /** - * @return string + * @return string|null */ public function getPartyIdentificationSchemeId(): ?string { @@ -55,7 +55,7 @@ public function setPartyIdentificationSchemeId(?string $partyIdentificationSchem } /** - * @return string + * @return string|null */ public function getPartyName(): ?string { @@ -74,7 +74,7 @@ public function setPartyName(?string $partyName) } /** - * @return string + * @return string|null */ public function getPartyLegalEntityCompanyId(): ?string { @@ -92,7 +92,7 @@ public function setPartyLegalEntityCompanyId(?string $partyLegalEntityCompanyId) } /** - * @return string + * @return string|null */ public function getPartyLegalEntityCompanySchemeId(): ?string { @@ -161,7 +161,8 @@ public static function xmlDeserialize(Reader $reader) $collection = new ArrayCollection($mixedContent); $partyIdentification = ReaderHelper::getTag(Schema::CAC . 'PartyIdentification', $collection); - $partyIdentificationId = ReaderHelper::getTag(Schema::CBC . 'ID', new ArrayCollection($partyIdentification['value'] ?? [])); + $partyIdentificationCollection = new ArrayCollection($partyIdentification['value'] ?? []); + $partyIdentificationId = ReaderHelper::getTag(Schema::CBC . 'ID', $partyIdentificationCollection); $partyName = ReaderHelper::getTag(Schema::CAC . 'PartyName', $collection); $partyNameName = ReaderHelper::getTag(Schema::CBC . 'Name', new ArrayCollection($partyName['value'] ?? [])); diff --git a/src/PaymentMandate.php b/src/PaymentMandate.php index 8c1fd7d..03b5e27 100644 --- a/src/PaymentMandate.php +++ b/src/PaymentMandate.php @@ -11,13 +11,12 @@ class PaymentMandate implements XmlSerializable, XmlDeserializable { - public $xmlTagName = 'PaymentMandate'; - private $id; - private $payeeFinancialAccount; + private ?string $id = null; + private ?PayeeFinancialAccount $payeeFinancialAccount = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -25,7 +24,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -35,7 +34,7 @@ public function setId(?string $id) } /** - * @return PayeeFinancialAccount + * @return PayeeFinancialAccount|null */ public function getPayeeFinancialAccount(): ?PayeeFinancialAccount { @@ -43,7 +42,7 @@ public function getPayeeFinancialAccount(): ?PayeeFinancialAccount } /** - * @param PayeeFinancialAccount $payeeFinancialAccount + * @param PayeeFinancialAccount|null $payeeFinancialAccount * @return static */ public function setPayeeFinancialAccount(?PayeeFinancialAccount $payeeFinancialAccount) diff --git a/src/PaymentMeans.php b/src/PaymentMeans.php index 6e497d4..8bd5df8 100644 --- a/src/PaymentMeans.php +++ b/src/PaymentMeans.php @@ -14,21 +14,21 @@ class PaymentMeans implements XmlSerializable, XmlDeserializable { - public $xmlTagName = 'PaymentMeans'; - private $paymentMeansCode = UNCL4461::INSTRUMENT_NOT_DEFINED; - private $paymentMeansCodeAttributes = [ + public string $xmlTagName = 'PaymentMeans'; + private string $paymentMeansCode = UNCL4461::INSTRUMENT_NOT_DEFINED; + private array $paymentMeansCodeAttributes = [ 'listID' => 'UN/ECE 4461', 'listName' => 'Payment Means', 'listURI' => 'http://docs.oasis-open.org/ubl/os-UBL-2.0-update/cl/gc/default/PaymentMeansCode-2.0.gc']; - private $paymentDueDate; - private $instructionId; - private $instructionNote; - private $paymentId; - private $payeeFinancialAccount; - private $paymentMandate; + private ?DateTime $paymentDueDate = null; + private ?string $instructionId = null; + private ?string $instructionNote = null; + private ?string $paymentId = null; + private ?PayeeFinancialAccount $payeeFinancialAccount = null; + private ?PaymentMandate $paymentMandate = null; /** - * @return string + * @return string|null */ public function getPaymentMeansCode(): ?string { @@ -36,10 +36,11 @@ public function getPaymentMeansCode(): ?string } /** - * @param string $paymentMeansCode + * @param string|null $paymentMeansCode + * @param array|null $attributes * @return static */ - public function setPaymentMeansCode(?string $paymentMeansCode, $attributes = null) + public function setPaymentMeansCode(?string $paymentMeansCode, array $attributes = null) { $this->paymentMeansCode = $paymentMeansCode; if (isset($attributes)) { @@ -49,7 +50,7 @@ public function setPaymentMeansCode(?string $paymentMeansCode, $attributes = nul } /** - * @return DateTime + * @return DateTime|null */ public function getPaymentDueDate(): ?DateTime { @@ -57,7 +58,7 @@ public function getPaymentDueDate(): ?DateTime } /** - * @param DateTime $paymentDueDate + * @param DateTime|null $paymentDueDate * @return static */ public function setPaymentDueDate(?DateTime $paymentDueDate) @@ -67,7 +68,7 @@ public function setPaymentDueDate(?DateTime $paymentDueDate) } /** - * @return string + * @return string|null */ public function getInstructionId(): ?string { @@ -75,7 +76,7 @@ public function getInstructionId(): ?string } /** - * @param string $instructionId + * @param string|null $instructionId * @return static */ public function setInstructionId(?string $instructionId) @@ -85,7 +86,7 @@ public function setInstructionId(?string $instructionId) } /** - * @return string + * @return string|null */ public function getInstructionNote(): ?string { @@ -93,7 +94,7 @@ public function getInstructionNote(): ?string } /** - * @param string $instructionNote + * @param string|null $instructionNote * @return static */ public function setInstructionNote(?string $instructionNote) @@ -103,7 +104,7 @@ public function setInstructionNote(?string $instructionNote) } /** - * @return string + * @return string|null */ public function getPaymentId(): ?string { @@ -111,7 +112,7 @@ public function getPaymentId(): ?string } /** - * @param string $paymentId + * @param string|null $paymentId * @return static */ public function setPaymentId(?string $paymentId) @@ -121,7 +122,7 @@ public function setPaymentId(?string $paymentId) } /** - * @return mixed + * @return PayeeFinancialAccount|null */ public function getPayeeFinancialAccount(): ?PayeeFinancialAccount { @@ -129,7 +130,7 @@ public function getPayeeFinancialAccount(): ?PayeeFinancialAccount } /** - * @param mixed $payeeFinancialAccount + * @param PayeeFinancialAccount|null $payeeFinancialAccount * @return static */ public function setPayeeFinancialAccount(?PayeeFinancialAccount $payeeFinancialAccount) @@ -139,7 +140,7 @@ public function setPayeeFinancialAccount(?PayeeFinancialAccount $payeeFinancialA } /** - * @return PaymentMandate + * @return PaymentMandate|null */ public function getPaymentMandate(): ?PaymentMandate { @@ -147,7 +148,7 @@ public function getPaymentMandate(): ?PaymentMandate } /** - * @param PaymentMandate $paymentMandate + * @param PaymentMandate|null $paymentMandate * @return static */ public function setPaymentMandate(?PaymentMandate $paymentMandate) @@ -203,16 +204,20 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) { $keyValues = keyValue($reader); + $paymentDueDate = isset($keyValues[Schema::CBC . 'PaymentDueDate']) + ? Carbon::parse($keyValues[Schema::CBC . 'PaymentDueDate'])->toDateTime() + : null; + return (new static()) ->setPaymentMeansCode($keyValues[Schema::CBC . 'PaymentMeansCode'] ?? null) - ->setPaymentDueDate(isset($keyValues[Schema::CBC . 'PaymentDueDate']) ? Carbon::parse($keyValues[Schema::CBC . 'PaymentDueDate'])->toDateTime() : null) + ->setPaymentDueDate($paymentDueDate) ->setInstructionId($keyValues[Schema::CBC . 'InstructionID'] ?? null) ->setInstructionNote($keyValues[Schema::CBC . 'InstructionNote'] ?? null) ->setPaymentId($keyValues[Schema::CBC . 'PaymentID'] ?? null) diff --git a/src/PaymentTerms.php b/src/PaymentTerms.php index d6ae258..015e914 100644 --- a/src/PaymentTerms.php +++ b/src/PaymentTerms.php @@ -11,13 +11,13 @@ class PaymentTerms implements XmlSerializable, XmlDeserializable { - private $note; - private $settlementDiscountPercent; - private $amount; - private $settlementPeriod; + private ?string $note = null; + private ?float $settlementDiscountPercent = null; + private ?float $amount = null; + private ?SettlementPeriod $settlementPeriod = null; /** - * @return string + * @return string|null */ public function getNote(): ?string { @@ -25,7 +25,7 @@ public function getNote(): ?string } /** - * @param string $note + * @param string|null $note * @return static */ public function setNote(?string $note) @@ -35,7 +35,7 @@ public function setNote(?string $note) } /** - * @return float + * @return float|null */ public function getSettlementDiscountPercent(): ?float { @@ -43,7 +43,7 @@ public function getSettlementDiscountPercent(): ?float } /** - * @param float $settlementDiscountPercent + * @param float|null $settlementDiscountPercent * @return static */ public function setSettlementDiscountPercent(?float $settlementDiscountPercent) @@ -53,7 +53,7 @@ public function setSettlementDiscountPercent(?float $settlementDiscountPercent) } /** - * @return float + * @return float|null */ public function getAmount(): ?float { @@ -61,7 +61,7 @@ public function getAmount(): ?float } /** - * @param float $amount + * @param float|null $amount * @return static */ public function setAmount(?float $amount) @@ -71,7 +71,7 @@ public function setAmount(?float $amount) } /** - * @return SettlementPeriod + * @return SettlementPeriod|null */ public function getSettlementPeriod(): ?SettlementPeriod { @@ -79,7 +79,7 @@ public function getSettlementPeriod(): ?SettlementPeriod } /** - * @param SettlementPeriod $settlementPeriod + * @param SettlementPeriod|null $settlementPeriod * @return static */ public function setSettlementPeriod(?SettlementPeriod $settlementPeriod) @@ -117,7 +117,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -128,7 +128,6 @@ public static function xmlDeserialize(Reader $reader) ->setNote($keyValues[Schema::CBC . 'Note'] ?? null) ->setSettlementDiscountPercent($keyValues[Schema::CBC . 'SettlementDiscountPercent'] ?? null) ->setAmount($keyValues[Schema::CBC . 'Amount'] ?? null) - ->setSettlementPeriod($keyValues[Schema::CAC . 'SettlementPeriod'] ?? null) - ; + ->setSettlementPeriod($keyValues[Schema::CAC . 'SettlementPeriod'] ?? null); } } diff --git a/src/Price.php b/src/Price.php index 77c5d67..b0f72c3 100644 --- a/src/Price.php +++ b/src/Price.php @@ -12,14 +12,14 @@ class Price implements XmlSerializable, XmlDeserializable { - private $priceAmount; - private $baseQuantity; - private $unitCode = UnitCode::UNIT; - private $unitCodeListId; - private $allowanceCharge; + private ?float $priceAmount = null; + private ?float $baseQuantity = null; + private ?string $unitCode = UnitCode::UNIT; + private ?string $unitCodeListId = null; + private ?AllowanceCharge $allowanceCharge = null; /** - * @return float + * @return float|null */ public function getPriceAmount(): ?float { @@ -27,7 +27,7 @@ public function getPriceAmount(): ?float } /** - * @param float $priceAmount + * @param float|null $priceAmount * @return static */ public function setPriceAmount(?float $priceAmount) @@ -37,7 +37,7 @@ public function setPriceAmount(?float $priceAmount) } /** - * @return float + * @return float|null */ public function getBaseQuantity(): ?float { @@ -45,7 +45,7 @@ public function getBaseQuantity(): ?float } /** - * @param float $baseQuantity + * @param float|null $baseQuantity * @return static */ public function setBaseQuantity(?float $baseQuantity) @@ -55,7 +55,7 @@ public function setBaseQuantity(?float $baseQuantity) } /** - * @return string + * @return string|null */ public function getUnitCode(): ?string { @@ -63,7 +63,7 @@ public function getUnitCode(): ?string } /** - * @param string $unitCode + * @param string|null $unitCode * See also: src/UnitCode.php * @return static */ @@ -75,7 +75,7 @@ public function setUnitCode(?string $unitCode) /** - * @return string + * @return string|null */ public function getUnitCodeListId(): ?string { @@ -83,7 +83,7 @@ public function getUnitCodeListId(): ?string } /** - * @param string $unitCodeListId + * @param string|null $unitCodeListId * @return static */ public function setUnitCodeListId(?string $unitCodeListId) @@ -93,7 +93,7 @@ public function setUnitCodeListId(?string $unitCodeListId) } /** - * @return AllowanceCharge + * @return AllowanceCharge|null */ public function getAllowanceCharge(): ?AllowanceCharge { @@ -101,7 +101,7 @@ public function getAllowanceCharge(): ?AllowanceCharge } /** - * @param AllowanceCharge $allowanceCharge + * @param AllowanceCharge|null $allowanceCharge * @return static */ public function setAllowanceCharge(?AllowanceCharge $allowanceCharge) @@ -155,7 +155,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) diff --git a/src/ProjectReference.php b/src/ProjectReference.php index 51beb17..b66547b 100644 --- a/src/ProjectReference.php +++ b/src/ProjectReference.php @@ -11,7 +11,7 @@ class ProjectReference implements XmlSerializable, XmlDeserializable { - private $id; + private ?string $id = null; /** * @return string|null @@ -46,7 +46,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -54,7 +54,6 @@ public static function xmlDeserialize(Reader $reader) $mixedContent = keyValue($reader); return (new static()) - ->setId($mixedContent[Schema::CBC . 'ID'] ?? null) - ; + ->setId($mixedContent[Schema::CBC . 'ID'] ?? null); } } diff --git a/src/Reader.php b/src/Reader.php index 54e1d56..13de67c 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -6,9 +6,9 @@ class Reader { - public static $currencyID; + public static string $currencyID; - public static function ubl($currencyId = 'EUR'): Service + public static function ubl(string $currencyId = 'EUR'): Service { self::$currencyID = $currencyId; diff --git a/src/ReaderHelper.php b/src/ReaderHelper.php index 8ae2eed..d382af0 100644 --- a/src/ReaderHelper.php +++ b/src/ReaderHelper.php @@ -12,7 +12,7 @@ class ReaderHelper * * @param string $name * @param ArrayCollection $collection - * @return ?array + * @return array|null */ public static function getTag(string $name, ArrayCollection $collection) { @@ -30,7 +30,7 @@ public static function getTag(string $name, ArrayCollection $collection) * * @param string $name * @param ArrayCollection $collection - * @return ?string + * @return string|null */ public static function getTagValue(string $name, ArrayCollection $collection) { @@ -40,11 +40,12 @@ public static function getTagValue(string $name, ArrayCollection $collection) } /** - * Get the tags with a given name from a XML Reader mixedContent result + * Get the tags with a given name from an XML Reader mixedContent result * that was converted to ArrayCollection * * @param string $name * @param ArrayCollection $collection + * @return array */ public static function getArrayValue(string $name, ArrayCollection $collection) { diff --git a/src/ReceiptDocumentReference.php b/src/ReceiptDocumentReference.php index 6985984..9059ac3 100644 --- a/src/ReceiptDocumentReference.php +++ b/src/ReceiptDocumentReference.php @@ -17,10 +17,10 @@ */ class ReceiptDocumentReference implements XmlSerializable, XmlDeserializable { - private $id; + private ?string $id = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -28,7 +28,7 @@ public function getId(): ?string } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) diff --git a/src/SettlementPeriod.php b/src/SettlementPeriod.php index d123fd5..355db15 100644 --- a/src/SettlementPeriod.php +++ b/src/SettlementPeriod.php @@ -26,11 +26,11 @@ */ class SettlementPeriod implements XmlSerializable, XmlDeserializable { - private $startDate; - private $endDate; + private ?DateTime $startDate = null; + private ?DateTime $endDate = null; /** - * @return DateTime + * @return DateTime|null */ public function getStartDate(): ?DateTime { @@ -48,7 +48,7 @@ public function setStartDate(DateTime $startDate) } /** - * @return DateTime + * @return DateTime|null */ public function getEndDate(): ?DateTime { @@ -73,8 +73,8 @@ public function setEndDate(DateTime $endDate) * - EndDate (BT-74): 0..1 (optional) * - BR-CO-19: "If Invoicing period is used, the start date or end date shall be filled, or both." * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { diff --git a/src/TaxCategory.php b/src/TaxCategory.php index 7cd4130..23e9826 100644 --- a/src/TaxCategory.php +++ b/src/TaxCategory.php @@ -14,19 +14,19 @@ class TaxCategory implements XmlSerializable, XmlDeserializable { - private $id; - private $idAttributes = [ + private ?string $id = null; + private array $idAttributes = [ 'schemeID' => UNCL5305::UNCL5305, 'schemeName' => 'Duty or tax or fee category' ]; - private $name; - private $percent; - private $taxScheme; - private $taxExemptionReason; - private $taxExemptionReasonCode; + private ?string $name = null; + private ?float $percent = null; + private ?TaxScheme $taxScheme = null; + private ?string $taxExemptionReason = null; + private ?string $taxExemptionReasonCode = null; /** - * @return string + * @return string|null */ public function getId(): ?string { @@ -45,11 +45,11 @@ public function getId(): ?string } /** - * @param string $id - * @param array $attributes + * @param string|null $id + * @param array|null $attributes * @return static */ - public function setId(?string $id, $attributes = null) + public function setId(?string $id, array $attributes = null) { $this->id = $id; if (isset($attributes)) { @@ -59,7 +59,7 @@ public function setId(?string $id, $attributes = null) } /** - * @return string + * @return string|null */ public function getName(): ?string { @@ -67,7 +67,7 @@ public function getName(): ?string } /** - * @param string $name + * @param string|null $name * @return static */ public function setName(?string $name) @@ -77,7 +77,7 @@ public function setName(?string $name) } /** - * @return string + * @return float|null */ public function getPercent(): ?float { @@ -85,7 +85,7 @@ public function getPercent(): ?float } /** - * @param string $percent + * @param float|null $percent * @return static */ public function setPercent(?float $percent) @@ -95,7 +95,7 @@ public function setPercent(?float $percent) } /** - * @return string + * @return TaxScheme|null */ public function getTaxScheme(): ?TaxScheme { @@ -103,7 +103,7 @@ public function getTaxScheme(): ?TaxScheme } /** - * @param TaxScheme $taxScheme + * @param TaxScheme|null $taxScheme * @return static */ public function setTaxScheme(?TaxScheme $taxScheme) @@ -113,7 +113,7 @@ public function setTaxScheme(?TaxScheme $taxScheme) } /** - * @return string + * @return string|null */ public function getTaxExemptionReason(): ?string { @@ -121,7 +121,7 @@ public function getTaxExemptionReason(): ?string } /** - * @param string $taxExemptionReason + * @param string|null $taxExemptionReason * @return static */ public function setTaxExemptionReason(?string $taxExemptionReason) @@ -131,7 +131,7 @@ public function setTaxExemptionReason(?string $taxExemptionReason) } /** - * @return string + * @return string|null */ public function getTaxExemptionReasonCode(): ?string { @@ -139,7 +139,7 @@ public function getTaxExemptionReasonCode(): ?string } /** - * @param string $taxExemptionReason + * @param string|null $taxExemptionReasonCode * @return static */ public function setTaxExemptionReasonCode(?string $taxExemptionReasonCode) @@ -151,8 +151,8 @@ public function setTaxExemptionReasonCode(?string $taxExemptionReasonCode) /** * The validate function that is called during xml writing to valid the data of the object. * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { @@ -213,10 +213,9 @@ public function xmlSerialize(Writer $writer): void } - /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -235,9 +234,8 @@ public static function xmlDeserialize(Reader $reader) ->setId($idTag['value'] ?? null, $idTag['attributes'] ?? null) ->setName($nameTag['value'] ?? null) ->setPercent(isset($percentTag['value']) ? floatval($percentTag['value']) : null) - ->setTaxScheme(isset($taxSchemeTag['value']) ? $taxSchemeTag['value'] : null) + ->setTaxScheme($taxSchemeTag['value'] ?? null) ->setTaxExemptionReason($taxExemptionReasonTag['value'] ?? null) - ->setTaxExemptionReasonCode($taxExemptionReasonCodeTag['value'] ?? null) - ; + ->setTaxExemptionReasonCode($taxExemptionReasonCodeTag['value'] ?? null); } } diff --git a/src/TaxScheme.php b/src/TaxScheme.php index a5d64bd..e7f191d 100644 --- a/src/TaxScheme.php +++ b/src/TaxScheme.php @@ -11,13 +11,13 @@ class TaxScheme implements XmlSerializable, XmlDeserializable { - private $id; - private $name; - private $taxTypeCode; - private $currencyCode; + private ?string $id; + private ?string $name = null; + private ?string $taxTypeCode = null; + private ?string $currencyCode = null; /** - * @return string + * @return string|null */ public function getId() { @@ -25,7 +25,7 @@ public function getId() } /** - * @param string $id + * @param string|null $id * @return static */ public function setId(?string $id) @@ -35,7 +35,7 @@ public function setId(?string $id) } /** - * @return string + * @return string|null */ public function getName(): ?string { @@ -43,7 +43,7 @@ public function getName(): ?string } /** - * @param string $name + * @param string|null $name * @return static */ public function setName(?string $name) @@ -53,7 +53,7 @@ public function setName(?string $name) } /** - * @return string + * @return string|null */ public function getTaxTypeCode(): ?string { @@ -61,7 +61,7 @@ public function getTaxTypeCode(): ?string } /** - * @param string $taxTypeCode + * @param string|null $taxTypeCode * @return static */ public function setTaxTypeCode(?string $taxTypeCode) @@ -71,7 +71,7 @@ public function setTaxTypeCode(?string $taxTypeCode) } /** - * @return string + * @return string|null */ public function getCurrencyCode(): ?string { @@ -79,7 +79,7 @@ public function getCurrencyCode(): ?string } /** - * @param string $currencyCode + * @param string|null $currencyCode * @return static */ public function setCurrencyCode(?string $currencyCode) @@ -120,7 +120,7 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) @@ -131,7 +131,6 @@ public static function xmlDeserialize(Reader $reader) ->setId($keyValues[Schema::CBC . 'ID'] ?? null) ->setName($keyValues[Schema::CBC . 'Name'] ?? null) ->setTaxTypeCode($keyValues[Schema::CBC . 'TaxTypeCode'] ?? null) - ->setCurrencyCode($keyValues[Schema::CBC . 'CurrencyCode'] ?? null) - ; + ->setCurrencyCode($keyValues[Schema::CBC . 'CurrencyCode'] ?? null); } } diff --git a/src/TaxSubTotal.php b/src/TaxSubTotal.php index d46fa55..fb6259d 100644 --- a/src/TaxSubTotal.php +++ b/src/TaxSubTotal.php @@ -13,13 +13,13 @@ class TaxSubTotal implements XmlSerializable, XmlDeserializable { - private $taxableAmount; - private $taxAmount; - private $taxCategory; - private $percent; + private ?float $taxableAmount = null; + private ?float $taxAmount = null; + private ?TaxCategory $taxCategory = null; + private ?float $percent = null; /** - * @return mixed + * @return float|null */ public function getTaxableAmount(): ?float { @@ -27,7 +27,7 @@ public function getTaxableAmount(): ?float } /** - * @param mixed $taxableAmount + * @param float|null $taxableAmount * @return static */ public function setTaxableAmount(?float $taxableAmount) @@ -37,7 +37,7 @@ public function setTaxableAmount(?float $taxableAmount) } /** - * @return mixed + * @return float|null */ public function getTaxAmount(): ?float { @@ -45,7 +45,7 @@ public function getTaxAmount(): ?float } /** - * @param mixed $taxAmount + * @param float|null $taxAmount * @return static */ public function setTaxAmount(?float $taxAmount) @@ -55,7 +55,7 @@ public function setTaxAmount(?float $taxAmount) } /** - * @return TaxCategory + * @return TaxCategory|null */ public function getTaxCategory(): ?TaxCategory { @@ -63,7 +63,7 @@ public function getTaxCategory(): ?TaxCategory } /** - * @param TaxCategory $taxCategory + * @param TaxCategory|null $taxCategory * @return static */ public function setTaxCategory(?TaxCategory $taxCategory) @@ -73,7 +73,7 @@ public function setTaxCategory(?TaxCategory $taxCategory) } /** - * @return float + * @return float|null */ public function getPercent(): ?float { @@ -81,7 +81,7 @@ public function getPercent(): ?float } /** - * @param float $percent + * @param float|null $percent * @return static */ public function setPercent(?float $percent) @@ -93,8 +93,8 @@ public function setPercent(?float $percent) /** * The validate function that is called during xml writing to valid the data of the object. * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { @@ -150,18 +150,27 @@ public function xmlSerialize(Writer $writer): void /** * The xmlDeserialize method is called during xml reading. - * @param Reader $xml + * @param Reader $reader * @return static */ public static function xmlDeserialize(Reader $reader) { $keyValues = keyValue($reader); + $taxableAmount = isset($keyValues[Schema::CBC . 'TaxableAmount']) + ? floatval($keyValues[Schema::CBC . 'TaxableAmount']) + : null; + + $taxAmount = isset($keyValues[Schema::CBC . 'TaxAmount']) + ? floatval($keyValues[Schema::CBC . 'TaxAmount']) + : null; + + $percent = isset($keyValues[Schema::CBC . 'Percent']) ? floatval($keyValues[Schema::CBC . 'Percent']) : null; + return (new static()) - ->setTaxableAmount(isset($keyValues[Schema::CBC . 'TaxableAmount']) ? floatval($keyValues[Schema::CBC . 'TaxableAmount']) : null) - ->setTaxAmount(isset($keyValues[Schema::CBC . 'TaxAmount']) ? floatval($keyValues[Schema::CBC . 'TaxAmount']) : null) + ->setTaxableAmount($taxableAmount) + ->setTaxAmount($taxAmount) ->setTaxCategory($keyValues[Schema::CAC . 'TaxCategory'] ?? null) - ->setPercent(isset($keyValues[Schema::CBC . 'Percent']) ? floatval($keyValues[Schema::CBC . 'Percent']) : null) - ; + ->setPercent($percent); } } diff --git a/src/TaxTotal.php b/src/TaxTotal.php index 3abf236..96692b8 100644 --- a/src/TaxTotal.php +++ b/src/TaxTotal.php @@ -14,11 +14,11 @@ class TaxTotal implements XmlSerializable, XmlDeserializable { - private $taxAmount; - private $taxSubTotals = []; + private ?float $taxAmount = null; + private array $taxSubTotals = []; /** - * @return mixed + * @return float|null */ public function getTaxAmount(): ?float { @@ -26,7 +26,7 @@ public function getTaxAmount(): ?float } /** - * @param mixed $taxAmount + * @param float|null $taxAmount * @return static */ public function setTaxAmount(?float $taxAmount) @@ -44,7 +44,7 @@ public function getTaxSubTotals(): array } /** - * @param array $taxSubTotal + * @param array $taxSubTotals * @return static */ public function setTaxSubTotals(array $taxSubTotals) @@ -66,8 +66,8 @@ public function addTaxSubTotal(TaxSubTotal $taxSubTotal) /** * The validate function that is called during xml writing to valid the data of the object. * - * @throws InvalidArgumentException An error with information about required data that is missing to write the XML * @return void + * @throws InvalidArgumentException An error with information about required data that is missing to write the XML */ public function validate() { diff --git a/tests/NumberFormatterTest.php b/tests/NumberFormatterTest.php index c195c12..d4ad944 100644 --- a/tests/NumberFormatterTest.php +++ b/tests/NumberFormatterTest.php @@ -16,7 +16,7 @@ class NumberFormatterTest extends TestCase public function testNumberFormatterRounding($number, string $formattedNumber, ?int $decimals) { $result = NumberFormatter::format($number, $decimals); - return $this->assertEqualsCanonicalizing($formattedNumber, $result); + $this->assertEqualsCanonicalizing($formattedNumber, $result); } public function formattedNumbersProvider(): array diff --git a/tests/Read/AddressLineTest.php b/tests/Read/AddressLineTest.php index 3ffa3b6..6139daa 100644 --- a/tests/Read/AddressLineTest.php +++ b/tests/Read/AddressLineTest.php @@ -5,6 +5,7 @@ use NumNum\UBL\Address; use NumNum\UBL\AddressLine; use NumNum\UBL\Invoice; +use NumNum\UBL\Reader; use PHPUnit\Framework\TestCase; /** @@ -70,7 +71,7 @@ public function testAddressLineDeserializesFromXml() XML; - $ublReader = \NumNum\UBL\Reader::ubl(); + $ublReader = Reader::ubl(); $invoice = $ublReader->parse($xml); $this->assertInstanceOf(Invoice::class, $invoice); @@ -156,7 +157,7 @@ public function testSingleAddressLineDeserializes() XML; - $ublReader = \NumNum\UBL\Reader::ubl(); + $ublReader = Reader::ubl(); $invoice = $ublReader->parse($xml); $address = $invoice->getAccountingSupplierParty()->getParty()->getPostalAddress(); @@ -166,4 +167,3 @@ public function testSingleAddressLineDeserializes() $this->assertEquals('Only One Line', $addressLines[0]->getLine()); } } - diff --git a/tests/Read/DespatchDocumentReferenceTest.php b/tests/Read/DespatchDocumentReferenceTest.php index 1819214..5a250dc 100644 --- a/tests/Read/DespatchDocumentReferenceTest.php +++ b/tests/Read/DespatchDocumentReferenceTest.php @@ -26,4 +26,3 @@ public function testDespatchDocumentReferenceCanBeRead() $this->assertEquals('DESP-2024-001', $despatchDocumentReference->getId()); } } - diff --git a/tests/Read/ItemOriginCountryTest.php b/tests/Read/ItemOriginCountryTest.php index 7f0d19a..9decf05 100644 --- a/tests/Read/ItemOriginCountryTest.php +++ b/tests/Read/ItemOriginCountryTest.php @@ -4,6 +4,7 @@ use NumNum\UBL\Country; use NumNum\UBL\Invoice; +use NumNum\UBL\Reader; use PHPUnit\Framework\TestCase; /** @@ -55,7 +56,7 @@ public function testItemOriginCountryCanBeRead() XML; - $ublReader = \NumNum\UBL\Reader::ubl(); + $ublReader = Reader::ubl(); $invoice = $ublReader->parse($xml); $this->assertNotNull($invoice); @@ -115,7 +116,7 @@ public function testItemWithoutOriginCountryCanBeRead() XML; - $ublReader = \NumNum\UBL\Reader::ubl(); + $ublReader = Reader::ubl(); $invoice = $ublReader->parse($xml); $this->assertNotNull($invoice); @@ -133,4 +134,3 @@ public function testItemWithoutOriginCountryCanBeRead() $this->assertNull($originCountry); } } - diff --git a/tests/Read/PayeePartyTest.php b/tests/Read/PayeePartyTest.php index d8896a1..fc64e8c 100644 --- a/tests/Read/PayeePartyTest.php +++ b/tests/Read/PayeePartyTest.php @@ -4,6 +4,7 @@ use NumNum\UBL\Invoice; use NumNum\UBL\PayeeParty; +use NumNum\UBL\Reader; use PHPUnit\Framework\TestCase; /** @@ -80,7 +81,7 @@ public function testPayeePartyDeserializesFromXml() XML; - $ublReader = \NumNum\UBL\Reader::ubl(); + $ublReader = Reader::ubl(); $invoice = $ublReader->parse($xml); $this->assertInstanceOf(Invoice::class, $invoice); diff --git a/tests/Read/ReadUbl.php b/tests/Read/ReadUbl.php index f8c2f71..e3cff0a 100644 --- a/tests/Read/ReadUbl.php +++ b/tests/Read/ReadUbl.php @@ -4,6 +4,7 @@ use NumNum\UBL\CreditNote; use NumNum\UBL\Invoice; +use NumNum\UBL\Reader; use PHPUnit\Framework\TestCase; class ReadUbl extends TestCase @@ -14,7 +15,7 @@ class ReadUbl extends TestCase */ public function testIfInvoiceUblCanBeRead($fileName) { - $ublReader = \NumNum\UBL\Reader::ubl(); + $ublReader = Reader::ubl(); $invoice = $ublReader->parse(file_get_contents($fileName)); @@ -28,7 +29,7 @@ public function testIfInvoiceUblCanBeRead($fileName) */ public function testIfCreditNoteUblCanBeRead($fileName) { - $ublReader = \NumNum\UBL\Reader::ubl(); + $ublReader = Reader::ubl(); $invoice = $ublReader->parse(file_get_contents($fileName)); diff --git a/tests/Read/TaxTotalTest.php b/tests/Read/TaxTotalTest.php index 1e1fb79..1a3a711 100644 --- a/tests/Read/TaxTotalTest.php +++ b/tests/Read/TaxTotalTest.php @@ -132,4 +132,3 @@ public function testSingleTaxTotalDeserializes() $this->assertEquals(21, $taxCategory->getPercent()); } } - diff --git a/tests/Write/AddressLineTest.php b/tests/Write/AddressLineTest.php index dfbb08c..e9114f4 100644 --- a/tests/Write/AddressLineTest.php +++ b/tests/Write/AddressLineTest.php @@ -2,6 +2,8 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; use NumNum\UBL\Address; use NumNum\UBL\AddressLine; use NumNum\UBL\Country; @@ -25,7 +27,7 @@ */ class AddressLineTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testAddressLineSerializesToXml() @@ -112,7 +114,7 @@ public function testAddressLineSerializesToXml() $invoice = (new Invoice()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -129,7 +131,7 @@ public function testAddressLineSerializesToXml() $this->assertStringContainsString('Suite 5', $outputXMLString); // Create PHP Native DomDocument object for validation - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $this->assertEquals(true, $dom->schemaValidate($this->schema)); @@ -220,7 +222,7 @@ public function testAddressWithoutAddressLinesIsValid() $invoice = (new Invoice()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -235,7 +237,7 @@ public function testAddressWithoutAddressLinesIsValid() $this->assertStringNotContainsString('', $outputXMLString); // Create PHP Native DomDocument object for validation - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $this->assertEquals(true, $dom->schemaValidate($this->schema)); @@ -259,4 +261,3 @@ public function testSetAddressLinesReplacesExisting() $this->assertEquals('New Line', $address->getAddressLines()[0]->getLine()); } } - diff --git a/tests/Write/BillingReferenceCreditNoteTest.php b/tests/Write/BillingReferenceCreditNoteTest.php index 63f6e10..2674634 100644 --- a/tests/Write/BillingReferenceCreditNoteTest.php +++ b/tests/Write/BillingReferenceCreditNoteTest.php @@ -2,6 +2,26 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\BillingReference; +use NumNum\UBL\Country; +use NumNum\UBL\CreditNote; +use NumNum\UBL\CreditNoteLine; +use NumNum\UBL\Generator; +use NumNum\UBL\InvoiceDocumentReference; +use NumNum\UBL\InvoiceTypeCode; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +29,17 @@ */ class BillingReferenceCreditNoteTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-CreditNote-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-CreditNote-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,43 +47,43 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID') ->setBuyersItemIdentification('BUYERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Invoice Line(s) - $creditNoteLine = (new \NumNum\UBL\CreditNoteLine()) + $creditNoteLine = (new CreditNoteLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -73,53 +93,53 @@ public function testIfXMLIsValid() $creditNoteLines = [$creditNoteLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $billingReference = (new \NumNum\UBL\BillingReference()) - ->setInvoiceDocumentReference((new \NumNum\UBL\InvoiceDocumentReference()) + $billingReference = (new BillingReference()) + ->setInvoiceDocumentReference((new InvoiceDocumentReference()) ->setOriginalInvoiceId(1234) - ->setIssueDate(new \DateTime())); + ->setIssueDate(new DateTime())); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $creditNote = (new \NumNum\UBL\CreditNote()) + $creditNote = (new CreditNote()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setBillingReference($billingReference) ->setCreditNoteLines($creditNoteLines) ->setLegalMonetaryTotal($legalMonetaryTotal) ->setTaxTotal($taxTotal) - ->setInvoiceTypeCode(\NumNum\UBL\InvoiceTypeCode::CREDIT_NOTE); + ->setInvoiceTypeCode(InvoiceTypeCode::CREDIT_NOTE); // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->creditNote($creditNote); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/BillingReferenceTest.xml'); diff --git a/tests/Write/ContractDocumentReferenceTest.php b/tests/Write/ContractDocumentReferenceTest.php index c41a090..ba9a59e 100644 --- a/tests/Write/ContractDocumentReferenceTest.php +++ b/tests/Write/ContractDocumentReferenceTest.php @@ -2,6 +2,26 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\ContractDocumentReference; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\InvoiceTypeCode; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +29,17 @@ */ class ContractDocumentReferenceTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,41 +47,41 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Invoice Line(s) - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -71,42 +91,42 @@ public function testIfXMLIsValid() $invoiceLines = [$invoiceLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $contractDocumentReference = (new \NumNum\UBL\ContractDocumentReference()) + $contractDocumentReference = (new ContractDocumentReference()) ->setId("123Test"); - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime('-31 days')) - ->setEndDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime('-31 days')) + ->setEndDate(new DateTime()); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setUBLVersionId('2.2') ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) - ->setInvoiceTypeCode(\NumNum\UBL\InvoiceTypeCode::INVOICE) - ->setDueDate(new \DateTime()) + ->setIssueDate(new DateTime()) + ->setInvoiceTypeCode(InvoiceTypeCode::INVOICE) + ->setDueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -118,12 +138,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/ContractDocumentReferenceTest.xml'); diff --git a/tests/Write/DespatchDocumentReferenceTest.php b/tests/Write/DespatchDocumentReferenceTest.php index 93d392c..f18906d 100644 --- a/tests/Write/DespatchDocumentReferenceTest.php +++ b/tests/Write/DespatchDocumentReferenceTest.php @@ -2,6 +2,25 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\Country; +use NumNum\UBL\DespatchDocumentReference; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoiceTypeCode; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +28,17 @@ */ class DespatchDocumentReferenceTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,41 +46,41 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Invoice Line(s) - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -71,38 +90,38 @@ public function testIfXMLIsValid() $invoiceLines = [$invoiceLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $despatchDocumentReference = (new \NumNum\UBL\DespatchDocumentReference()) + $despatchDocumentReference = (new DespatchDocumentReference()) ->setId("DESP-2024-001"); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setUBLVersionId('2.2') ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) - ->setInvoiceTypeCode(\NumNum\UBL\InvoiceTypeCode::INVOICE) - ->setDueDate(new \DateTime()) + ->setIssueDate(new DateTime()) + ->setInvoiceTypeCode(InvoiceTypeCode::INVOICE) + ->setDueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -113,12 +132,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $this->assertEquals(true, $dom->schemaValidate($this->schema)); @@ -128,11 +147,11 @@ public function testIfXMLIsValid() public function testDespatchDocumentReferenceIsInOutput() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -140,59 +159,58 @@ public function testDespatchDocumentReferenceIsInOutput() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(12); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line(s) - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) ->setInvoicedQuantity(1); - $despatchDocumentReference = (new \NumNum\UBL\DespatchDocumentReference()) + $despatchDocumentReference = (new DespatchDocumentReference()) ->setId("DESP-2024-001"); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines([$invoiceLine]) ->setLegalMonetaryTotal($legalMonetaryTotal) ->setDespatchDocumentReference($despatchDocumentReference); - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); $this->assertStringContainsString('', $outputXMLString); $this->assertStringContainsString('DESP-2024-001', $outputXMLString); } } - diff --git a/tests/Write/DocumentTypeTest.php b/tests/Write/DocumentTypeTest.php index 7d3657d..f56d34d 100644 --- a/tests/Write/DocumentTypeTest.php +++ b/tests/Write/DocumentTypeTest.php @@ -2,6 +2,27 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\AdditionalDocumentReference; +use NumNum\UBL\Address; +use NumNum\UBL\Attachment; +use NumNum\UBL\Contact; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +30,17 @@ */ class DocumentTypeTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,56 +48,56 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client contact node - $clientContact = (new \NumNum\UBL\Contact()) + $clientContact = (new Contact()) ->setName('Client name') ->setElectronicMail('email@client.com') ->setTelephone('0032 472 123 456') ->setTelefax('0032 9 1234 567'); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address) ->setContact($clientContact); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) $invoiceLines = []; - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -84,7 +105,7 @@ public function testIfXMLIsValid() ->setTaxTotal($lineTaxTotal) ->setInvoicedQuantity(1); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -93,7 +114,7 @@ public function testIfXMLIsValid() ->setTaxTotal($lineTaxTotal) ->setInvoicedQuantity(1); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -104,42 +125,49 @@ public function testIfXMLIsValid() // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); // Attachment - $attachment = (new \NumNum\UBL\Attachment()) - ->setFilePath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Files'.DIRECTORY_SEPARATOR.'SampleInvoice.pdf'); - - $additionalDocumentReference = new \NumNum\UBL\AdditionalDocumentReference(); + $attachment_filepath = __DIR__ + .DIRECTORY_SEPARATOR + .'..' + .DIRECTORY_SEPARATOR + .'Files' + .DIRECTORY_SEPARATOR + .'SampleInvoice.pdf'; + $attachment = (new Attachment()) + ->setFilePath($attachment_filepath); + + $additionalDocumentReference = new AdditionalDocumentReference(); $additionalDocumentReference->setId('SomeID'); $additionalDocumentReference->setDocumentType("CommercialInvoice"); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -149,12 +177,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/EmptyAttachmentTest.xml'); diff --git a/tests/Write/DueDateTest.php b/tests/Write/DueDateTest.php index 559a478..7a07ccb 100644 --- a/tests/Write/DueDateTest.php +++ b/tests/Write/DueDateTest.php @@ -2,6 +2,24 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoiceTypeCode; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +27,17 @@ */ class DueDateTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,41 +45,41 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Invoice Line(s) - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -71,35 +89,35 @@ public function testIfXMLIsValid() $invoiceLines = [$invoiceLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setUBLVersionId('2.2') ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) - ->setInvoiceTypeCode(\NumNum\UBL\InvoiceTypeCode::INVOICE) - ->setDueDate(new \DateTime()) + ->setIssueDate(new DateTime()) + ->setInvoiceTypeCode(InvoiceTypeCode::INVOICE) + ->setDueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -108,12 +126,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/DueDateTest.xml'); diff --git a/tests/Write/EN16931Test.php b/tests/Write/EN16931Test.php index 1b8e82a..9b000b0 100644 --- a/tests/Write/EN16931Test.php +++ b/tests/Write/EN16931Test.php @@ -2,59 +2,84 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\ClassifiedTaxCategory; +use NumNum\UBL\Country; +use NumNum\UBL\Delivery; +use NumNum\UBL\FinancialInstitutionBranch; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalEntity; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\OrderReference; +use NumNum\UBL\Party; +use NumNum\UBL\PartyTaxScheme; +use NumNum\UBL\PayeeFinancialAccount; +use NumNum\UBL\PaymentMeans; +use NumNum\UBL\PaymentTerms; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; use NumNum\UBL\UNCL4461; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; +use SoapClient; /** * Test an UBL2.1 invoice document */ class EN16931Test extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; - private $xslfile = 'vendor/num-num/ubl-invoice/tests/EN16931-UBL-validation.xslt'; - /** @test */ public function testIfXMLIsValid() { // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId('VAT'); // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt 1') ->setAdditionalStreetName('Building A') ->setCityName('Gent') ->setPostalZone('9000') ->setCountry($country); - $financialInstitutionBranch = (new \NumNum\UBL\FinancialInstitutionBranch()) + $financialInstitutionBranch = (new FinancialInstitutionBranch()) ->setId('RABONL2U'); - $payeeFinancialAccount = (new \NumNum\UBL\PayeeFinancialAccount()) + $payeeFinancialAccount = (new PayeeFinancialAccount()) ->setFinancialInstitutionBranch($financialInstitutionBranch) ->setName('Customer Account Holder') ->setId('NL00RABO0000000000'); - $paymentMeans = (new \NumNum\UBL\PaymentMeans()) + $paymentMeans = (new PaymentMeans()) ->setPayeeFinancialAccount($payeeFinancialAccount) ->setPaymentMeansCode(UNCL4461::DEBIT_TRANSFER, []) ->setPaymentId('our invoice 1234'); // Supplier company node - $supplierLegalEntity = (new \NumNum\UBL\LegalEntity()) + $supplierLegalEntity = (new LegalEntity()) ->setRegistrationName('Supplier Company Name') ->setCompanyId('BE123456789'); - $supplierPartyTaxScheme = (new \NumNum\UBL\PartyTaxScheme()) + $supplierPartyTaxScheme = (new PartyTaxScheme()) ->setTaxScheme($taxScheme) ->setCompanyId('BE123456789'); - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setLegalEntity($supplierLegalEntity) ->setPartyTaxScheme($supplierPartyTaxScheme) @@ -62,55 +87,55 @@ public function testIfXMLIsValid() ->setPostalAddress($address); // Client company node - $clientLegalEntity = (new \NumNum\UBL\LegalEntity()) + $clientLegalEntity = (new LegalEntity()) ->setRegistrationName('Client Company Name') ->setCompanyId('Client Company Registration'); - $clientPartyTaxScheme = (new \NumNum\UBL\PartyTaxScheme()) + $clientPartyTaxScheme = (new PartyTaxScheme()) ->setTaxScheme($taxScheme) ->setCompanyId('BE123456789'); - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('Client Company Name') ->setLegalEntity($clientLegalEntity) ->setPartyTaxScheme($clientPartyTaxScheme) ->setPartyIdentificationId('BE123456789') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2.1) ->setPayableRoundingAmount(0) ->setTaxInclusiveAmount(10 + 2.1) ->setLineExtensionAmount(10) ->setTaxExclusiveAmount(10); - $classifiedTaxCategory = (new \NumNum\UBL\ClassifiedTaxCategory()) + $classifiedTaxCategory = (new ClassifiedTaxCategory()) ->setId('S') ->setPercent(21.00) ->setTaxScheme($taxScheme); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setClassifiedTaxCategory($classifiedTaxCategory) ->setDescription('Product Description'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -121,48 +146,48 @@ public function testIfXMLIsValid() $invoiceLines = [$invoiceLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId('S', []) ->setPercent(21.00) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); // Payment Terms - $paymentTerms = (new \NumNum\UBL\PaymentTerms()) + $paymentTerms = (new PaymentTerms()) ->setNote('30 days net'); // Delivery - $deliveryLocation = (new \NumNum\UBL\Address()) + $deliveryLocation = (new Address()) ->setCountry($country); - $delivery = (new \NumNum\UBL\Delivery()) - ->setActualDeliveryDate(new \DateTime()) + $delivery = (new Delivery()) + ->setActualDeliveryDate(new DateTime()) ->setDeliveryLocation($deliveryLocation); - $orderReference = (new \NumNum\UBL\OrderReference()) + $orderReference = (new OrderReference()) ->setId('5009567') ->setSalesOrderId('tRST-tKhM'); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setCustomizationId('urn:cen.eu:en16931:2017') ->setId(1234) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setNote('invoice note') ->setDelivery($delivery) ->setAccountingSupplierParty($accountingSupplierParty) @@ -178,21 +203,19 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/EN16931Test.xml'); - // $this->assertEquals(true, $dom->schemaValidate($this->schema)); - // Use webservice at peppol.helger.com to verify the result $wsdl = "http://peppol.helger.com/wsdvs?wsdl=1"; - $client = new \SoapClient($wsdl); + $client = new SoapClient($wsdl); $response = $client->validate(['XML' => $outputXMLString, 'VESID' => 'eu.cen.en16931:ubl:1.3.1']); // Output validation warnings if present diff --git a/tests/Write/EmptyAttachmentTest.php b/tests/Write/EmptyAttachmentTest.php index 9f95284..bc5745b 100644 --- a/tests/Write/EmptyAttachmentTest.php +++ b/tests/Write/EmptyAttachmentTest.php @@ -2,6 +2,27 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\AdditionalDocumentReference; +use NumNum\UBL\Address; +use NumNum\UBL\Attachment; +use NumNum\UBL\Contact; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +30,17 @@ */ class EmptyAttachmentTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,56 +48,56 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client contact node - $clientContact = (new \NumNum\UBL\Contact()) + $clientContact = (new Contact()) ->setName('Client name') ->setElectronicMail('email@client.com') ->setTelephone('0032 472 123 456') ->setTelefax('0032 9 1234 567'); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address) ->setContact($clientContact); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) $invoiceLines = []; - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -84,7 +105,7 @@ public function testIfXMLIsValid() ->setTaxTotal($lineTaxTotal) ->setInvoicedQuantity(1); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -93,7 +114,7 @@ public function testIfXMLIsValid() ->setTaxTotal($lineTaxTotal) ->setInvoicedQuantity(1); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -104,45 +125,52 @@ public function testIfXMLIsValid() // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); // Attachment - $attachment = (new \NumNum\UBL\Attachment()) - ->setFilePath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Files'.DIRECTORY_SEPARATOR.'SampleInvoice.pdf'); - - $additionalDocumentReference = new \NumNum\UBL\AdditionalDocumentReference(); + $attachment_filepath = __DIR__ + .DIRECTORY_SEPARATOR + .'..' + .DIRECTORY_SEPARATOR + .'Files' + .DIRECTORY_SEPARATOR + .'SampleInvoice.pdf'; + $attachment = (new Attachment()) + ->setFilePath($attachment_filepath); + + $additionalDocumentReference = new AdditionalDocumentReference(); $additionalDocumentReference->setId('SomeID'); $additionalDocumentReference->setDocumentTypeCode(130); // Not adding an attachment to AdditionalDocumentReference should not trigger an error // $additionalDocumentReference->setAttachment($attachment); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -152,12 +180,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/EmptyAttachmentTest.xml'); diff --git a/tests/Write/ExternalReferenceOnlyAttachmentTest.php b/tests/Write/ExternalReferenceOnlyAttachmentTest.php index 0e2e839..50a5c4f 100644 --- a/tests/Write/ExternalReferenceOnlyAttachmentTest.php +++ b/tests/Write/ExternalReferenceOnlyAttachmentTest.php @@ -2,6 +2,27 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\AdditionalDocumentReference; +use NumNum\UBL\Address; +use NumNum\UBL\Attachment; +use NumNum\UBL\Contact; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +30,17 @@ */ class ExternalReferenceOnlyAttachmentTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,56 +48,56 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client contact node - $clientContact = (new \NumNum\UBL\Contact()) + $clientContact = (new Contact()) ->setName('Client name') ->setElectronicMail('email@client.com') ->setTelephone('0032 472 123 456') ->setTelefax('0032 9 1234 567'); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address) ->setContact($clientContact); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) $invoiceLines = []; - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -85,42 +106,42 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1); // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); // Attachment with only external reference (no embedded binary object) - $attachment = (new \NumNum\UBL\Attachment()) + $attachment = (new Attachment()) ->setExternalReference('https://payment.quickpay.net/payments/abc123'); - $additionalDocumentReference = (new \NumNum\UBL\AdditionalDocumentReference()) + $additionalDocumentReference = (new AdditionalDocumentReference()) ->setId('PaymentLink') ->setDocumentDescription('Payment link for invoice') ->setAttachment($attachment); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -130,12 +151,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/ExternalReferenceOnlyAttachmentTest.xml'); @@ -147,57 +168,57 @@ public function testIfXMLIsValid() public function testExternalReferenceOnlyDoesNotContainEmbeddedDocument() { // Attachment with only external reference (no embedded binary object) - $attachment = (new \NumNum\UBL\Attachment()) + $attachment = (new Attachment()) ->setExternalReference('https://payment.quickpay.net/payments/abc123'); - $additionalDocumentReference = (new \NumNum\UBL\AdditionalDocumentReference()) + $additionalDocumentReference = (new AdditionalDocumentReference()) ->setId('PaymentLink') ->setAttachment($attachment); // Generate just the AdditionalDocumentReference XML - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); // Create a minimal invoice to test the attachment serialization - $country = (new \NumNum\UBL\Country())->setIdentificationCode('BE'); - $address = (new \NumNum\UBL\Address()) + $country = (new Country())->setIdentificationCode('BE'); + $address = (new Address()) ->setStreetName('Test') ->setCityName('Test') ->setCountry($country); - $party = (new \NumNum\UBL\Party()) + $party = (new Party()) ->setName('Test') ->setPostalAddress($address); - $accountingParty = (new \NumNum\UBL\AccountingParty()) + $accountingParty = (new AccountingParty()) ->setParty($party); - $taxScheme = (new \NumNum\UBL\TaxScheme())->setId(0); - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxScheme = (new TaxScheme())->setId(0); + $taxCategory = (new TaxCategory()) ->setId(0) ->setPercent(0) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(0) ->setTaxAmount(0) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(0); - $item = (new \NumNum\UBL\Item())->setName('Test'); - $price = (new \NumNum\UBL\Price())->setPriceAmount(0); - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $item = (new Item())->setName('Test'); + $price = (new Price())->setPriceAmount(0); + $invoiceLine = (new InvoiceLine()) ->setId(1) ->setItem($item) ->setPrice($price) ->setInvoicedQuantity(1); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(0); - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingParty) ->setAccountingCustomerParty($accountingParty) ->setInvoiceLines([$invoiceLine]) @@ -218,4 +239,3 @@ public function testExternalReferenceOnlyDoesNotContainEmbeddedDocument() $this->assertStringNotContainsString('EmbeddedDocumentBinaryObject', $outputXMLString); } } - diff --git a/tests/Write/ItemOriginCountryTest.php b/tests/Write/ItemOriginCountryTest.php index b6f4cd4..5c07bcc 100644 --- a/tests/Write/ItemOriginCountryTest.php +++ b/tests/Write/ItemOriginCountryTest.php @@ -2,6 +2,23 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +26,17 @@ */ class ItemOriginCountryTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testItemWithOriginCountryIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,49 +44,49 @@ public function testItemWithOriginCountryIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Origin country for the product - $originCountry = (new \NumNum\UBL\Country()) + $originCountry = (new Country()) ->setIdentificationCode('CN'); // Product with OriginCountry - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID') ->setOriginCountry($originCountry); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Invoice Line(s) $invoiceLines = []; - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -77,33 +94,33 @@ public function testItemWithOriginCountryIsValid() ->setInvoicedQuantity(1); // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -112,7 +129,7 @@ public function testItemWithOriginCountryIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Verify that the OriginCountry element is present in the XML @@ -121,7 +138,7 @@ public function testItemWithOriginCountryIsValid() // Create PHP Native DomDocument object, that can be // used to validate the generated XML - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/ItemOriginCountryTest.xml'); @@ -129,4 +146,3 @@ public function testItemWithOriginCountryIsValid() $this->assertEquals(true, $dom->schemaValidate($this->schema)); } } - diff --git a/tests/Write/MultiplePaymentMeansTest.php b/tests/Write/MultiplePaymentMeansTest.php index 7a32819..99cd58f 100644 --- a/tests/Write/MultiplePaymentMeansTest.php +++ b/tests/Write/MultiplePaymentMeansTest.php @@ -2,6 +2,28 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\CommodityClassification; +use NumNum\UBL\Contact; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\PayeeFinancialAccount; +use NumNum\UBL\PaymentMeans; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +31,17 @@ */ class MultiplePaymentMeansTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,39 +49,39 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client contact node - $clientContact = (new \NumNum\UBL\Contact()) + $clientContact = (new Contact()) ->setName('Client name') ->setElectronicMail('email@client.com') ->setTelephone('0032 472 123 456') ->setTelefax('0032 9 1234 567'); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address) ->setContact($clientContact); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); - $commodityClassification = (new \NumNum\UBL\CommodityClassification()) + $commodityClassification = (new CommodityClassification()) ->setItemClassificationCode('123456') ->setItemClassificationListId('urn:ean.ucc:eanucc:2:2') ->setItemClassificationListVersionId('16'); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID') @@ -67,23 +89,23 @@ public function testIfXMLIsValid() // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) $invoiceLines = []; - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -91,7 +113,7 @@ public function testIfXMLIsValid() ->setTaxTotal($lineTaxTotal) ->setInvoicedQuantity(1); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -100,7 +122,7 @@ public function testIfXMLIsValid() ->setTaxTotal($lineTaxTotal) ->setInvoicedQuantity(1); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -111,48 +133,48 @@ public function testIfXMLIsValid() // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); $paymentMeans = []; - $payeeFinancialAccount = (new \NumNum\UBL\PayeeFinancialAccount())->setId('RO123456789012345'); - $paymentMeans[] = (new \NumNum\UBL\PaymentMeans()) + $payeeFinancialAccount = (new PayeeFinancialAccount())->setId('RO123456789012345'); + $paymentMeans[] = (new PaymentMeans()) ->setPaymentMeansCode(31) - ->setPaymentDueDate(new \DateTime()) + ->setPaymentDueDate(new DateTime()) ->setPayeeFinancialAccount($payeeFinancialAccount); - $payeeFinancialAccount = (new \NumNum\UBL\PayeeFinancialAccount())->setId('RO544456789067890'); - $paymentMeans[] = (new \NumNum\UBL\PaymentMeans()) + $payeeFinancialAccount = (new PayeeFinancialAccount())->setId('RO544456789067890'); + $paymentMeans[] = (new PaymentMeans()) ->setPaymentMeansCode(31) - ->setPaymentDueDate(new \DateTime()) + ->setPaymentDueDate(new DateTime()) ->setPayeeFinancialAccount($payeeFinancialAccount); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setPaymentMeans($paymentMeans) @@ -162,12 +184,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/MultiplePaymentMeansTest.xml'); diff --git a/tests/Write/PartyIdentificationSchemeNameTest.php b/tests/Write/PartyIdentificationSchemeNameTest.php index 54ab7b1..752ae99 100644 --- a/tests/Write/PartyIdentificationSchemeNameTest.php +++ b/tests/Write/PartyIdentificationSchemeNameTest.php @@ -2,6 +2,26 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\ContractDocumentReference; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\InvoiceTypeCode; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +29,17 @@ */ class PartyIdentificationSchemeNameTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,42 +47,42 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address) ->setPartyIdentificationSchemeName("SomeScheme"); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Invoice Line(s) - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -72,42 +92,42 @@ public function testIfXMLIsValid() $invoiceLines = [$invoiceLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $contractDocumentReference = (new \NumNum\UBL\ContractDocumentReference()) + $contractDocumentReference = (new ContractDocumentReference()) ->setId("123Test"); - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime('-31 days')) - ->setEndDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime('-31 days')) + ->setEndDate(new DateTime()); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setUBLVersionId('2.2') ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) - ->setInvoiceTypeCode(\NumNum\UBL\InvoiceTypeCode::INVOICE) - ->setDueDate(new \DateTime()) + ->setIssueDate(new DateTime()) + ->setInvoiceTypeCode(InvoiceTypeCode::INVOICE) + ->setDueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -119,12 +139,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/PartyIdentificationSchemeNameTest.xml'); diff --git a/tests/Write/ProjectReferenceTest.php b/tests/Write/ProjectReferenceTest.php index b2daa54..313d281 100644 --- a/tests/Write/ProjectReferenceTest.php +++ b/tests/Write/ProjectReferenceTest.php @@ -2,7 +2,35 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\ClassifiedTaxCategory; +use NumNum\UBL\Country; +use NumNum\UBL\Delivery; +use NumNum\UBL\FinancialInstitutionBranch; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalEntity; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\OrderReference; +use NumNum\UBL\Party; +use NumNum\UBL\PartyTaxScheme; +use NumNum\UBL\PayeeFinancialAccount; +use NumNum\UBL\PaymentMeans; +use NumNum\UBL\PaymentTerms; +use NumNum\UBL\Price; +use NumNum\UBL\ProjectReference; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; use NumNum\UBL\UNCL4461; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -10,51 +38,50 @@ */ class ProjectReferenceTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; - private $xslfile = 'vendor/num-num/ubl-invoice/tests/EN16931-UBL-validation.xslt'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId('VAT'); // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt 1') ->setAdditionalStreetName('Building A') ->setCityName('Gent') ->setPostalZone('9000') ->setCountry($country); - $financialInstitutionBranch = (new \NumNum\UBL\FinancialInstitutionBranch()) + $financialInstitutionBranch = (new FinancialInstitutionBranch()) ->setId('RABONL2U'); - $payeeFinancialAccount = (new \NumNum\UBL\PayeeFinancialAccount()) + $payeeFinancialAccount = (new PayeeFinancialAccount()) ->setFinancialInstitutionBranch($financialInstitutionBranch) ->setName('Customer Account Holder') ->setId('NL00RABO0000000000'); - $paymentMeans = (new \NumNum\UBL\PaymentMeans()) + $paymentMeans = (new PaymentMeans()) ->setPayeeFinancialAccount($payeeFinancialAccount) ->setPaymentMeansCode(UNCL4461::DEBIT_TRANSFER, []) ->setPaymentId('our invoice 1234'); // Supplier company node - $supplierLegalEntity = (new \NumNum\UBL\LegalEntity()) + $supplierLegalEntity = (new LegalEntity()) ->setRegistrationName('Supplier Company Name') ->setCompanyId('BE123456789'); - $supplierPartyTaxScheme = (new \NumNum\UBL\PartyTaxScheme()) + $supplierPartyTaxScheme = (new PartyTaxScheme()) ->setTaxScheme($taxScheme) ->setCompanyId('BE123456789'); - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setLegalEntity($supplierLegalEntity) ->setPartyTaxScheme($supplierPartyTaxScheme) @@ -62,55 +89,55 @@ public function testIfXMLIsValid() ->setPostalAddress($address); // Client company node - $clientLegalEntity = (new \NumNum\UBL\LegalEntity()) + $clientLegalEntity = (new LegalEntity()) ->setRegistrationName('Client Company Name') ->setCompanyId('Client Company Registration'); - $clientPartyTaxScheme = (new \NumNum\UBL\PartyTaxScheme()) + $clientPartyTaxScheme = (new PartyTaxScheme()) ->setTaxScheme($taxScheme) ->setCompanyId('BE123456789'); - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('Client Company Name') ->setLegalEntity($clientLegalEntity) ->setPartyTaxScheme($clientPartyTaxScheme) ->setPartyIdentificationId('BE123456789') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2.1) ->setAllowanceTotalAmount(0) ->setTaxInclusiveAmount(10 + 2.1) ->setLineExtensionAmount(10) ->setTaxExclusiveAmount(10); - $classifiedTaxCategory = (new \NumNum\UBL\ClassifiedTaxCategory()) + $classifiedTaxCategory = (new ClassifiedTaxCategory()) ->setId('S') ->setPercent(21.00) ->setTaxScheme($taxScheme); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setClassifiedTaxCategory($classifiedTaxCategory) ->setDescription('Product Description'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -121,52 +148,52 @@ public function testIfXMLIsValid() $invoiceLines = [$invoiceLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId('S', []) ->setPercent(21.00) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); // Payment Terms - $paymentTerms = (new \NumNum\UBL\PaymentTerms()) + $paymentTerms = (new PaymentTerms()) ->setNote('30 days net'); // Delivery - $deliveryLocation = (new \NumNum\UBL\Address()) + $deliveryLocation = (new Address()) ->setCountry($country); - $delivery = (new \NumNum\UBL\Delivery()) - ->setActualDeliveryDate(new \DateTime()) + $delivery = (new Delivery()) + ->setActualDeliveryDate(new DateTime()) ->setDeliveryLocation($deliveryLocation); - $orderReference = (new \NumNum\UBL\OrderReference()) + $orderReference = (new OrderReference()) ->setId('5009567') ->setSalesOrderId('tRST-tKhM'); // Test Project Reference - $projectReference = (new \NumNum\UBL\ProjectReference()) + $projectReference = (new ProjectReference()) ->setId('Project1234'); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setCustomizationID('urn:cen.eu:en16931:2017') ->setId(1234) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setNote('invoice note') ->setDelivery($delivery) ->setAccountingSupplierParty($accountingSupplierParty) @@ -183,12 +210,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument; + // used to validate the generated XML + $dom = new DOMDocument; $dom->loadXML($outputXMLString); $dom->save('./tests/ProjectReferenceTest.xml'); diff --git a/tests/Write/SimpleCreditNoteTest.php b/tests/Write/SimpleCreditNoteTest.php index 8dc1d38..3768478 100644 --- a/tests/Write/SimpleCreditNoteTest.php +++ b/tests/Write/SimpleCreditNoteTest.php @@ -2,6 +2,24 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\Country; +use NumNum\UBL\CreditNote; +use NumNum\UBL\CreditNoteLine; +use NumNum\UBL\Generator; +use NumNum\UBL\InvoiceTypeCode; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +27,17 @@ */ class SimpleCreditNoteTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-CreditNote-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-CreditNote-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,43 +45,43 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID') ->setBuyersItemIdentification('BUYERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Invoice Line(s) - $creditNoteLine = (new \NumNum\UBL\CreditNoteLine()) + $creditNoteLine = (new CreditNoteLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -73,47 +91,47 @@ public function testIfXMLIsValid() $creditNoteLines = [$creditNoteLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $creditNote = (new \NumNum\UBL\CreditNote()) + $creditNote = (new CreditNote()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setCreditNoteLines($creditNoteLines) ->setLegalMonetaryTotal($legalMonetaryTotal) ->setTaxTotal($taxTotal) - ->setInvoiceTypeCode(\NumNum\UBL\InvoiceTypeCode::CREDIT_NOTE); + ->setInvoiceTypeCode(InvoiceTypeCode::CREDIT_NOTE); // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->creditNote($creditNote); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/SimpleCreditNoteTest.xml'); diff --git a/tests/Write/SimpleDebitNoteTest.php b/tests/Write/SimpleDebitNoteTest.php index 40c10bf..42d3efd 100644 --- a/tests/Write/SimpleDebitNoteTest.php +++ b/tests/Write/SimpleDebitNoteTest.php @@ -2,6 +2,23 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\Country; +use NumNum\UBL\DebitNote; +use NumNum\UBL\DebitNoteLine; +use NumNum\UBL\Generator; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +26,17 @@ */ class SimpleDebitNoteTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-DebitNote-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-DebitNote-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,43 +44,43 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID') ->setBuyersItemIdentification('BUYERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Debit Note Line(s) - $debitNoteLine = (new \NumNum\UBL\DebitNoteLine()) + $debitNoteLine = (new DebitNoteLine()) ->setId(0) ->setItem($productItem) ->setPrice($price) @@ -73,32 +90,32 @@ public function testIfXMLIsValid() $debitNoteLines = [$debitNoteLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Debit Note object - $debitNote = (new \NumNum\UBL\DebitNote()) + $debitNote = (new DebitNote()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setDebitNoteLines($debitNoteLines) @@ -107,12 +124,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->debitNote($debitNote); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/SimpleDebitNoteTest.xml'); diff --git a/tests/Write/SimpleInvoiceTest.php b/tests/Write/SimpleInvoiceTest.php index 5208312..1dfe0f2 100644 --- a/tests/Write/SimpleInvoiceTest.php +++ b/tests/Write/SimpleInvoiceTest.php @@ -2,6 +2,26 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\Contact; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\OrderLineReference; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +29,17 @@ */ class SimpleInvoiceTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,59 +47,59 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client contact node - $clientContact = (new \NumNum\UBL\Contact()) + $clientContact = (new Contact()) ->setName('Client name') ->setElectronicMail('email@client.com') ->setTelephone('0032 472 123 456') ->setTelefax('0032 9 1234 567'); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address) ->setContact($clientContact); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) $invoiceLines = []; - $orderLineReference = (new \NumNum\UBL\OrderLineReference()) + $orderLineReference = (new OrderLineReference()) ->setLineId('#ABC123'); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -88,7 +108,7 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1) ->setOrderLineReference($orderLineReference); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -98,7 +118,7 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1) ->setOrderLineReference($orderLineReference); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -110,35 +130,35 @@ public function testIfXMLIsValid() // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) - ->setIssueTime(new \DateTime()) + ->setIssueDate(new DateTime()) + ->setIssueTime(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -147,12 +167,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/SimpleInvoiceTest.xml'); diff --git a/tests/Write/SimpleInvoiceWithExternalReferenceTest.php b/tests/Write/SimpleInvoiceWithExternalReferenceTest.php index 093b4cd..a5e1a5e 100644 --- a/tests/Write/SimpleInvoiceWithExternalReferenceTest.php +++ b/tests/Write/SimpleInvoiceWithExternalReferenceTest.php @@ -2,6 +2,28 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\AdditionalDocumentReference; +use NumNum\UBL\Address; +use NumNum\UBL\Attachment; +use NumNum\UBL\Contact; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\OrderLineReference; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +31,17 @@ */ class SimpleInvoiceWithExternalReferenceTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,59 +49,59 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client contact node - $clientContact = (new \NumNum\UBL\Contact()) + $clientContact = (new Contact()) ->setName('Client name') ->setElectronicMail('email@client.com') ->setTelephone('0032 472 123 456') ->setTelefax('0032 9 1234 567'); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address) ->setContact($clientContact); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) $invoiceLines = []; - $orderLineReference = (new \NumNum\UBL\OrderLineReference()) + $orderLineReference = (new OrderLineReference()) ->setLineId('#ABC123'); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -88,7 +110,7 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1) ->setOrderLineReference($orderLineReference); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -98,7 +120,7 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1) ->setOrderLineReference($orderLineReference); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -110,43 +132,43 @@ public function testIfXMLIsValid() // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $attachment = (new \NumNum\UBL\Attachment()) + $attachment = (new Attachment()) ->setExternalReference('http://www.suppliersite.eu/sheet001.html'); - $additionalDocumentReference = (new \NumNum\UBL\AdditionalDocumentReference()) + $additionalDocumentReference = (new AdditionalDocumentReference()) ->setId('Doc1') ->setDocumentType('Timesheet') ->setAttachment($attachment); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setAdditionalDocumentReference($additionalDocumentReference) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -155,12 +177,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/SimpleInvoiceWithExternalReferenceTest.xml'); diff --git a/tests/Write/SimpleInvoiceWithFilePathPdfTest.php b/tests/Write/SimpleInvoiceWithFilePathPdfTest.php index 56b6efb..0346edb 100644 --- a/tests/Write/SimpleInvoiceWithFilePathPdfTest.php +++ b/tests/Write/SimpleInvoiceWithFilePathPdfTest.php @@ -2,6 +2,28 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\AdditionalDocumentReference; +use NumNum\UBL\Address; +use NumNum\UBL\Attachment; +use NumNum\UBL\Contact; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\OrderLineReference; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +31,17 @@ */ class SimpleInvoiceWithFilePathPdfTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,59 +49,59 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client contact node - $clientContact = (new \NumNum\UBL\Contact()) + $clientContact = (new Contact()) ->setName('Client name') ->setElectronicMail('email@client.com') ->setTelephone('0032 472 123 456') ->setTelefax('0032 9 1234 567'); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address) ->setContact($clientContact); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) $invoiceLines = []; - $orderLineReference = (new \NumNum\UBL\OrderLineReference()) + $orderLineReference = (new OrderLineReference()) ->setLineId('#ABC123'); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -88,7 +110,7 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1) ->setOrderLineReference($orderLineReference); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -98,7 +120,7 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1) ->setOrderLineReference($orderLineReference); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -110,41 +132,48 @@ public function testIfXMLIsValid() // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $attachment = (new \NumNum\UBL\Attachment()) - ->setFilePath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Files'.DIRECTORY_SEPARATOR.'SampleInvoice.pdf'); - - $additionalDocumentReference = (new \NumNum\UBL\AdditionalDocumentReference()) + $attachmentFilePath = __DIR__ + .DIRECTORY_SEPARATOR + .'..' + .DIRECTORY_SEPARATOR + .'Files' + .DIRECTORY_SEPARATOR + .'SampleInvoice.pdf'; + $attachment = (new Attachment()) + ->setFilePath($attachmentFilePath); + + $additionalDocumentReference = (new AdditionalDocumentReference()) ->setAttachment($attachment); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setAdditionalDocumentReference($additionalDocumentReference) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -153,12 +182,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/SimpleInvoiceWithFilePathPdfTest.xml'); diff --git a/tests/Write/SimpleInvoiceWithInlinePdfTest.php b/tests/Write/SimpleInvoiceWithInlinePdfTest.php index ca3e18c..9da7988 100644 --- a/tests/Write/SimpleInvoiceWithInlinePdfTest.php +++ b/tests/Write/SimpleInvoiceWithInlinePdfTest.php @@ -2,6 +2,28 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\AdditionalDocumentReference; +use NumNum\UBL\Address; +use NumNum\UBL\Attachment; +use NumNum\UBL\Contact; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\InvoicePeriod; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\OrderLineReference; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,17 +31,17 @@ */ class SimpleInvoiceWithInlinePdfTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -27,59 +49,59 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client contact node - $clientContact = (new \NumNum\UBL\Contact()) + $clientContact = (new Contact()) ->setName('Client name') ->setElectronicMail('email@client.com') ->setTelephone('0032 472 123 456') ->setTelefax('0032 9 1234 567'); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address) ->setContact($clientContact); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description') ->setSellersItemIdentification('SELLERID'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // InvoicePeriod - $invoicePeriod = (new \NumNum\UBL\InvoicePeriod()) - ->setStartDate(new \DateTime()); + $invoicePeriod = (new InvoicePeriod()) + ->setStartDate(new DateTime()); // Invoice Line(s) $invoiceLines = []; - $orderLineReference = (new \NumNum\UBL\OrderLineReference()) + $orderLineReference = (new OrderLineReference()) ->setLineId('#ABC123'); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -88,7 +110,7 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1) ->setOrderLineReference($orderLineReference); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -98,7 +120,7 @@ public function testIfXMLIsValid() ->setInvoicedQuantity(1) ->setOrderLineReference($orderLineReference); - $invoiceLines[] = (new \NumNum\UBL\InvoiceLine()) + $invoiceLines[] = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setInvoicePeriod($invoicePeriod) @@ -110,46 +132,53 @@ public function testIfXMLIsValid() // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); // Example if you have some inline or in-memory filestream/file contents - $fileStream = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Files'.DIRECTORY_SEPARATOR.'SampleInvoice.pdf'); // this would be your file contents + $fileStreamFileName = __DIR__ + .DIRECTORY_SEPARATOR + .'..' + .DIRECTORY_SEPARATOR + .'Files' + .DIRECTORY_SEPARATOR + .'SampleInvoice.pdf'; + $fileStream = file_get_contents($fileStreamFileName); // this would be your file contents $base64EncodedFileStream = base64_encode($fileStream); - $attachment = (new \NumNum\UBL\Attachment()) + $attachment = (new Attachment()) ->setBase64Content($base64EncodedFileStream, 'Invoice.pdf', 'application/pdf'); - $additionalDocumentReference = (new \NumNum\UBL\AdditionalDocumentReference()) + $additionalDocumentReference = (new AdditionalDocumentReference()) ->setAttachment($attachment); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setSupplierAssignedAccountId('10001') ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setId(1234) ->setAdditionalDocumentReference($additionalDocumentReference) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -158,12 +187,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/SimpleInvoiceWithInlinePdfTest.xml'); diff --git a/tests/Write/SimpleUBL22InvoiceTest.php b/tests/Write/SimpleUBL22InvoiceTest.php index 1c95e57..8c63ab4 100644 --- a/tests/Write/SimpleUBL22InvoiceTest.php +++ b/tests/Write/SimpleUBL22InvoiceTest.php @@ -2,6 +2,23 @@ namespace NumNum\UBL\Tests\Write; +use DateTime; +use DOMDocument; +use NumNum\UBL\AccountingParty; +use NumNum\UBL\Address; +use NumNum\UBL\Country; +use NumNum\UBL\Generator; +use NumNum\UBL\Invoice; +use NumNum\UBL\InvoiceLine; +use NumNum\UBL\Item; +use NumNum\UBL\LegalMonetaryTotal; +use NumNum\UBL\Party; +use NumNum\UBL\Price; +use NumNum\UBL\TaxCategory; +use NumNum\UBL\TaxScheme; +use NumNum\UBL\TaxSubTotal; +use NumNum\UBL\TaxTotal; +use NumNum\UBL\UnitCode; use PHPUnit\Framework\TestCase; /** @@ -9,18 +26,18 @@ */ class SimpleUBL22InvoiceTest extends TestCase { - private $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; + private string $schema = 'http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/UBL-Invoice-2.2.xsd'; /** @test */ public function testIfXMLIsValid() { // Address country - $country = (new \NumNum\UBL\Country()) + $country = (new Country()) ->setIdentificationCode('BE') ->setListId('ISO3166-1:Alpha2'); // Full address - $address = (new \NumNum\UBL\Address()) + $address = (new Address()) ->setStreetName('Korenmarkt') ->setBuildingNumber(1) ->setCityName('Gent') @@ -28,42 +45,42 @@ public function testIfXMLIsValid() ->setCountry($country); // Supplier company node - $supplierCompany = (new \NumNum\UBL\Party()) + $supplierCompany = (new Party()) ->setName('Supplier Company Name') ->setPhysicalLocation($address) ->setPostalAddress($address); // Client company node - $clientCompany = (new \NumNum\UBL\Party()) + $clientCompany = (new Party()) ->setName('My client') ->setPostalAddress($address); - $legalMonetaryTotal = (new \NumNum\UBL\LegalMonetaryTotal()) + $legalMonetaryTotal = (new LegalMonetaryTotal()) ->setPayableAmount(10 + 2) ->setAllowanceTotalAmount(0); // Tax scheme - $taxScheme = (new \NumNum\UBL\TaxScheme()) + $taxScheme = (new TaxScheme()) ->setId(0); // Product - $productItem = (new \NumNum\UBL\Item()) + $productItem = (new Item()) ->setName('Product Name') ->setDescription('Product Description'); // Price - $price = (new \NumNum\UBL\Price()) + $price = (new Price()) ->setBaseQuantity(1) - ->setUnitCode(\NumNum\UBL\UnitCode::UNIT) + ->setUnitCode(UnitCode::UNIT) ->setUnitCodeListId('UNECERec20') ->setPriceAmount(10); // Invoice Line tax totals - $lineTaxTotal = (new \NumNum\UBL\TaxTotal()) + $lineTaxTotal = (new TaxTotal()) ->setTaxAmount(2.1); // Invoice Line(s) - $invoiceLine = (new \NumNum\UBL\InvoiceLine()) + $invoiceLine = (new InvoiceLine()) ->setId(0) ->setItem($productItem) ->setUnitCode('C62') @@ -75,33 +92,33 @@ public function testIfXMLIsValid() $invoiceLines = [$invoiceLine]; // Total Taxes - $taxCategory = (new \NumNum\UBL\TaxCategory()) + $taxCategory = (new TaxCategory()) ->setId(0) ->setName('VAT21%') ->setPercent(.21) ->setTaxScheme($taxScheme); - $taxSubTotal = (new \NumNum\UBL\TaxSubTotal()) + $taxSubTotal = (new TaxSubTotal()) ->setTaxableAmount(10) ->setTaxAmount(2.1) ->setTaxCategory($taxCategory); - $taxTotal = (new \NumNum\UBL\TaxTotal()) + $taxTotal = (new TaxTotal()) ->addTaxSubTotal($taxSubTotal) ->setTaxAmount(2.1); - $accountingSupplierParty = (new \NumNum\UBL\AccountingParty()) + $accountingSupplierParty = (new AccountingParty()) ->setParty($supplierCompany); - $accountingCustomerParty = (new \NumNum\UBL\AccountingParty()) + $accountingCustomerParty = (new AccountingParty()) ->setParty($clientCompany); // Invoice object - $invoice = (new \NumNum\UBL\Invoice()) + $invoice = (new Invoice()) ->setUBLVersionId('2.2') ->setId(1234) ->setCopyIndicator(false) - ->setIssueDate(new \DateTime()) + ->setIssueDate(new DateTime()) ->setAccountingSupplierParty($accountingSupplierParty) ->setAccountingCustomerParty($accountingCustomerParty) ->setInvoiceLines($invoiceLines) @@ -110,12 +127,12 @@ public function testIfXMLIsValid() // Test created object // Use \NumNum\UBL\Generator to generate an XML string - $generator = new \NumNum\UBL\Generator(); + $generator = new Generator(); $outputXMLString = $generator->invoice($invoice); // Create PHP Native DomDocument object, that can be - // used to validate the generate XML - $dom = new \DOMDocument(); + // used to validate the generated XML + $dom = new DOMDocument(); $dom->loadXML($outputXMLString); $dom->save('./tests/SimpleUBL22InvoiceTest.xml');