コード例 #1
0
ファイル: test-invoice.php プロジェクト: atanenl/twinfield
    /**
     * @test
     */
    public function matchRecordGeneratesProperXml()
    {
        $match = new Match();
        $match->setOffice('001');
        $match->setCode('170');
        // fixed
        $match->setDate('20160908');
        $i = 0;
        $line = new MatchLine();
        $line->setTransCode('INCASSO-OW');
        $line->setTransNumber('1000');
        // Twinfield generated ID for memorial transaction
        $line->setTransLine(2);
        $match->addLine($line);
        $line = new MatchLine();
        $line->setTransCode('VRK');
        $line->setTransNumber('20160001');
        // Twinfield generated ID for invoice transaction
        $line->setTransLine(1);
        $line->setMatchValue(100);
        $match->addLine($line);
        $matchDocument = new MatchDocument();
        $matchDocument->addMatch($match);
        $generatedXml = $matchDocument;
        $expectedXml = new DOMDocument();
        $expectedXml->loadXml('<match>
   <set>
      <office>001</office>
      <matchcode>170</matchcode>
      <matchdate>20160908</matchdate>
      <lines>
         <line>
            <transcode>INCASSO-OW</transcode>
            <transnumber>1000</transnumber>
            <transline>2</transline>
         </line>
         <line>
            <transcode>VRK</transcode>
            <transnumber>20160001</transnumber>
            <transline>1</transline>
            <matchvalue>100.00</matchvalue>
         </line>
      </lines>
   </set>
</match>');
        $this->assertEqualXMLStructure($expectedXml->documentElement, $generatedXml->documentElement);
        return $match;
    }
コード例 #2
0
ファイル: MatchMapper.php プロジェクト: atanenl/twinfield
 /**
  * Maps a Response object to a clean Match entity.
  * 
  * @access public
  * @param \Pronamic\Twinfield\Response\Response $response
  * @return \Pronamic\Twinfield\Match\Match
  */
 public static function map(Response $response)
 {
     // Generate new Match object
     $Match = new Match();
     // Gets the raw DOMDocument response.
     $responseDOM = $response->getResponseDocument();
     // Set the status attribute
     $dimensionElement = $responseDOM->getElementsByTagName('header')->item(0);
     $Match->setDate($dimensionElement->getAttribute('status'));
     // Match elements and their methods
     $MatchTags = ['code' => 'setCode', 'office' => 'setOffice', 'type' => 'setType', 'name' => 'setName', 'shortname' => 'setShortName', 'unitnamesingular' => 'setUnitNameSingular', 'unitnameplural' => 'setUnitNamePlural', 'vatcode' => 'setVatCode', 'allowchangevatcode' => 'setAllowChangeVatCode', 'performancetype' => 'setPerformanceType', 'allowchangeperformancetype' => 'setAllowChangePerformanceType', 'percentage' => 'setPercentage', 'allowdiscountorpremium' => 'setAllowDiscountorPremium', 'allowchangeunitsprice' => 'setAllowChangeUnitsPrice', 'allowdecimalquantity' => 'setAllowDecimalQuantity'];
     // Loop through all the tags
     foreach ($MatchTags as $tag => $method) {
         // Get the dom element
         $_tag = $responseDOM->getElementsByTagName($tag)->item(0);
         // If it has a value, set it to the associated method
         if (isset($_tag) && isset($_tag->textContent)) {
             $Match->{$method}($_tag->textContent);
         }
     }
     $linesDOMTag = $responseDOM->getElementsByTagName('lines');
     if (isset($linesDOMTag) && $linesDOMTag->length > 0) {
         // Element tags and their methods for lines
         $lineTags = ['unitspriceexcl' => 'setUnitsPriceExcl', 'unitspriceinc' => 'setUnitsPriceInc', 'units' => 'setUnits', 'name' => 'setName', 'shortname' => 'setShortName', 'subcode' => 'setSubCode', 'freetext1' => 'setFreeText1'];
         $linesDOM = $linesDOMTag->item(0);
         // Loop through each returned line for the Match
         foreach ($linesDOM->getElementsByTagName('line') as $lineDOM) {
             // Make a new tempory MatchLine class
             $MatchLine = new MatchLine();
             // Set the attributes ( id,status,inuse)
             $MatchLine->setID($lineDOM->getAttribute('id'))->setTransCode($lineDOM->getAttribute('status'))->setTransNumber($lineDOM->getAttribute('inuse'));
             // Loop through the element tags. Determine if it exists and set it if it does
             foreach ($lineTags as $tag => $method) {
                 // Get the dom element
                 $_tag = $lineDOM->getElementsByTagName($tag)->item(0);
                 // Check if the tag is set, and its content is set, to prevent DOMNode errors
                 if (isset($_tag) && isset($_tag->textContent)) {
                     $MatchLine->{$method}($_tag->textContent);
                 }
             }
             // Add the bank to the customer
             $Match->addLine($MatchLine);
             // Clean that memory!
             unset($MatchLine);
         }
     }
     return $Match;
 }
コード例 #3
0
ファイル: MatchDocument.php プロジェクト: atanenl/twinfield
 /**
  * Turns a passed Match class into the required markup for interacting
  * with Twinfield.
  *
  * This method doesn't return anything, instead just adds the Match to
  * this DOMDOcument instance for submission usage.
  *
  * @access public
  * @param \Pronamic\Twinfield\Match\Match $match
  * @return void | [Adds to this instance]
  */
 public function addMatch(Match $match)
 {
     // Match->header elements and their methods
     $matchTags = array('office' => 'getOffice', 'matchcode' => 'getCode', 'matchdate' => 'getDate');
     // Go through each Match element and use the assigned method
     foreach ($matchTags as $tag => $method) {
         // Make text node for method value
         $node = $this->createTextNode($match->{$method}());
         // Make the actual element and assign the node
         $element = $this->createElement($tag);
         $element->appendChild($node);
         // Add the full element
         $this->setElement->appendChild($element);
     }
     $lines = $match->getLines();
     if (!empty($lines)) {
         $linesElement = $this->createElement('lines');
         $this->setElement->appendChild($linesElement);
         // Element tags and their methods for lines
         $lineTags = ['transcode' => 'getTransCode', 'transnumber' => 'getTransNumber', 'transline' => 'getTransLine', 'matchvalue' => 'getMatchValue'];
         // Go through each line assigned to the Match
         foreach ($lines as $line) {
             // Makes new MatchLine element
             $lineElement = $this->createElement('line');
             $linesElement->appendChild($lineElement);
             // Go through each line element and use the assigned method
             foreach ($lineTags as $tag => $method) {
                 // Make the text node for the method value
                 $value = $line->{$method}();
                 if ($value === null) {
                     continue;
                 }
                 $node = $this->createTextNode($line->{$method}());
                 // Make the actual element and assign the text node
                 $element = $this->createElement($tag);
                 $element->appendChild($node);
                 // Add the completed element
                 $lineElement->appendChild($element);
             }
         }
     }
 }