Skip to content

Commit

Permalink
#25 Centralisation of profile recognition -> Use in ZugferdDocument a…
Browse files Browse the repository at this point in the history
…nd ZugferdObjectHelper
  • Loading branch information
HorstOeko committed Oct 12, 2023
1 parent e13d6e0 commit cc3bc1a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 56 deletions.
41 changes: 18 additions & 23 deletions src/ZugferdDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

namespace horstoeko\zugferd;

use \GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler;
use \GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
use \horstoeko\stringmanagement\PathUtils;
use \horstoeko\zugferd\entities\en16931\rsm\CrossIndustryInvoiceType;
use \horstoeko\zugferd\jms\ZugferdTypesHandler;
use \horstoeko\zugferd\ZugferdObjectHelper;
use \JMS\Serializer\Handler\HandlerRegistryInterface;
use \JMS\Serializer\SerializerBuilder;
use \JMS\Serializer\SerializerInterface;
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler;
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
use horstoeko\stringmanagement\PathUtils;
use horstoeko\zugferd\entities\en16931\rsm\CrossIndustryInvoiceType;
use horstoeko\zugferd\jms\ZugferdTypesHandler;
use horstoeko\zugferd\ZugferdObjectHelper;
use horstoeko\zugferd\ZugferdProfileResolver;
use JMS\Serializer\Handler\HandlerRegistryInterface;
use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\SerializerInterface;

/**
* Class representing the document basics
Expand All @@ -32,43 +33,37 @@ class ZugferdDocument
{
/**
* @internal
* Internal profile id (see ZugferdProfiles.php)
* @var integer
* @var integer Internal profile id
*/
public $profileId = -1;

/**
* @internal
* Internal profile definition (see ZugferdProfiles.php)
* @var array
* @var array Internal profile definition
*/
public $profileDefinition = [];

/**
* @internal
* Serializer builder
* @var SerializerBuilder
* @var SerializerBuilder Serializer builder
*/
protected $serializerBuilder;

/**
* @internal
* Serializer
* @var SerializerInterface
* @var SerializerInterface Serializer
*/
protected $serializer;

/**
* @internal
* The internal invoice object
* @var CrossIndustryInvoiceType
* @var CrossIndustryInvoiceType The internal invoice object
*/
protected $invoiceObject = null;

/**
* @internal
* Object Helper
* @var ZugferdObjectHelper
* @var ZugferdObjectHelper Object Helper
*/
protected $objectHelper = null;

Expand Down Expand Up @@ -126,14 +121,14 @@ public function getProfileDefinition(): array
* Sets the internal profile definitions
*
* @param integer $profile
* The internal id of the profile (see ZugferdProfiles.php)
* The internal id of the profile
*
* @return ZugferdDocument
*/
private function initProfile(int $profile): ZugferdDocument
{
$this->profileId = $profile;
$this->profileDefinition = ZugferdProfiles::PROFILEDEF[$profile];
$this->profileDefinition = ZugferdProfileResolver::resolveProfileDefById($profile);

return $this;
}
Expand Down
1 change: 1 addition & 0 deletions src/ZugferdDocumentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function initNewDocument(): ZugferdDocumentBuilder
$this->headerTradeDelivery = $this->invoiceObject->getSupplyChainTradeTransaction()->getApplicableHeaderTradeDelivery();
$this->headerTradeSettlement = $this->invoiceObject->getSupplyChainTradeTransaction()->getApplicableHeaderTradeSettlement();
$this->headerSupplyChainTradeTransaction = $this->invoiceObject->getSupplyChainTradeTransaction();

return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ZugferdDocumentJsonExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function toJsonString(): string

/**
* Returns the invoice object as a json object
*
*
* @return null|stdClass
* @throws ExceptionRuntimeException
*/
Expand Down
12 changes: 6 additions & 6 deletions src/ZugferdDocumentPdfBuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ protected function extractInvoiceInformations(): array
$docTypeCode = $docTypeXpath->item(0)->nodeValue;

switch ($docTypeCode) {
case ZugferdInvoiceType::CREDITNOTE:
$docTypeName = 'Credit Note';
break;
default:
$docTypeName = 'Invoice';
break;
case ZugferdInvoiceType::CREDITNOTE:
$docTypeName = 'Credit Note';
break;
default:
$docTypeName = 'Invoice';
break;
}

$invoiceInformation = array(
Expand Down
36 changes: 18 additions & 18 deletions src/ZugferdDocumentReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,6 @@ class ZugferdDocumentReader extends ZugferdDocument
*/
private $binarydatadirectory = "";

/**
* Set the directory where the attached binary data from
* additional referenced documents are temporary stored
*
* @param string $binarydatadirectory
* @return ZugferdDocumentReader
*/
public function setBinaryDataDirectory(string $binarydatadirectory): ZugferdDocumentReader
{
if ($binarydatadirectory) {
if (is_dir($binarydatadirectory)) {
$this->binarydatadirectory = $binarydatadirectory;
}
}

return $this;
}

/**
* Guess the profile type of a xml file
*
Expand Down Expand Up @@ -247,6 +229,24 @@ public static function readAndGuessFromContent(string $xmlcontent): ZugferdDocum
return (new self($profileId))->readContent($xmlcontent);
}

/**
* Set the directory where the attached binary data from
* additional referenced documents are temporary stored
*
* @param string $binarydatadirectory
* @return ZugferdDocumentReader
*/
public function setBinaryDataDirectory(string $binarydatadirectory): ZugferdDocumentReader
{
if ($binarydatadirectory) {
if (is_dir($binarydatadirectory)) {
$this->binarydatadirectory = $binarydatadirectory;
}
}

return $this;
}

/**
* Read content of a zuferd/xrechnung xml from a string
*
Expand Down
15 changes: 8 additions & 7 deletions src/ZugferdObjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
namespace horstoeko\zugferd;

use DateTime;
use \horstoeko\mimedb\MimeDb;
use \horstoeko\stringmanagement\FileUtils;
use \horstoeko\stringmanagement\StringUtils;
use \horstoeko\zugferd\exception\ZugferdUnknownDateFormat;
use horstoeko\mimedb\MimeDb;
use horstoeko\stringmanagement\FileUtils;
use horstoeko\stringmanagement\StringUtils;
use horstoeko\zugferd\exception\ZugferdUnknownDateFormat;
use horstoeko\zugferd\ZugferdProfileResolver;

/**
* Class representing a collection of common helpers and class factories
Expand All @@ -27,14 +28,14 @@
class ZugferdObjectHelper
{
/**
* Internal profile id (see ZugferdProfiles.php)
* Internal profile id
*
* @var integer
*/
public $profile = -1;

/**
* Internal profile definition (see ZugferdProfiles.php)
* Internal profile definition
*
* @var array
*/
Expand Down Expand Up @@ -63,7 +64,7 @@ class ZugferdObjectHelper
public function __construct(int $profile)
{
$this->profile = $profile;
$this->profiledef = ZugferdProfiles::PROFILEDEF[$profile];
$this->profiledef = ZugferdProfileResolver::resolveProfileDefById($profile);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ZugferdProfileResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ public static function resolveProfileDefById(int $profileId): array

return $resolved[1];
}
}
}

0 comments on commit cc3bc1a

Please sign in to comment.