示例#1
0
 /**
  * Turns a passed Invoice class into the required markup for interacting
  * with Twinfield.
  * 
  * This method doesn't return anything, instead just adds the invoice
  * to this DOMDocument instance for submission usage.
  * 
  * @access public
  * @param \Pronamic\Twinfield\Invoice\Invoice $invoice
  * @return void | [Adds to this instance]
  */
 public function addInvoice(Invoice $invoice)
 {
     // Make a new <salesinvoice> element
     $invoiceElement = $this->getNewInvoice();
     // Makes a child header element
     $headerElement = $this->createElement('header');
     $invoiceElement->appendChild($headerElement);
     // Set customer element
     $customer = $invoice->getCustomer();
     // <customer>
     $customerNode = $this->createTextNode($customer->getCode());
     $customerElement = $this->createElement('customer');
     $customerElement->appendChild($customerNode);
     $headerElement->appendChild($customerElement);
     // Elements and their associated methods for invoice
     $headerTags = array('invoicetype' => 'getInvoiceType', 'invoicenumber' => 'getInvoiceNumber', 'status' => 'getStatus', 'currency' => 'getCurrency', 'period' => 'getPeriod', 'invoicedate' => 'getInvoiceDate', 'duedate' => 'getDueDate', 'bank' => 'getBank', 'invoiceaddressnumber' => 'getInvoiceAddressNumber', 'deliveraddressnumber' => 'getDeliverAddressNumber', 'headertext' => 'getHeaderText', 'footertext' => 'getFooterText');
     // Go through each element and use the assigned method
     foreach ($headerTags as $tag => $method) {
         // Make text node for method value
         $node = $this->createTextNode($invoice->{$method}());
         // Make the actual element and assign the node
         $element = $this->createElement($tag);
         $element->appendChild($node);
         // Add the full element
         $headerElement->appendChild($element);
     }
     // Add orders
     $linesElement = $this->createElement('lines');
     $invoiceElement->appendChild($linesElement);
     // Elements and their associated methods for lines
     $lineTags = array('quantity' => 'getQuantity', 'article' => 'getArticle', 'subarticle' => 'getSubArticle', 'description' => 'getDescription', 'unitspriceexcl' => 'getUnitsPriceExcl', 'units' => 'getUnits', 'vatcode' => 'getVatCode', 'freetext1' => 'getFreeText1', 'freetext2' => 'getFreeText2', 'freetext3' => 'getFreeText3', 'performancedate' => 'getPerformanceDate');
     // Loop through all orders, and add those elements
     foreach ($invoice->getLines() as $line) {
         // Make a new line element, and add to <lines>
         $lineElement = $this->createElement('line');
         $lineElement->setAttribute('id', $line->getID());
         $linesElement->appendChild($lineElement);
         // Go through each element and use the assigned method
         foreach ($lineTags as $tag => $method) {
             // Make text node for method value
             $node = $this->createTextNode($line->{$method}());
             // Make the actual element with tag
             $element = $this->createElement($tag);
             $element->appendChild($node);
             // Add the full element
             $lineElement->appendChild($element);
         }
     }
 }
示例#2
0
 public static function map(Response $response)
 {
     $responseDOM = $response->getResponseDocument();
     $invoiceTags = array('office' => 'setOffice', 'invoicetype' => 'setInvoiceType', 'invoicenumber' => 'setInvoiceNumber', 'status' => 'setStatus', 'currency' => 'setCurrency', 'period' => 'setPeriod', 'invoicedate' => 'setInvoiceDate', 'duedate' => 'setDueDate', 'performancedate' => 'setPerformanceDate', 'paymentmethod' => 'setPaymentMethod', 'bank' => 'setBank', 'invoiceaddressnumber' => 'setInvoiceAddressNumber', 'deliveraddressnumber' => 'setDeliverAddressNumber', 'headertext' => 'setHeaderText', 'footertext' => 'setFooterText');
     $customerTags = array('customer' => 'setCode');
     $totalsTags = array('valueexcl' => 'setValueExcl', 'valueinc' => 'setValueInc');
     // Generate new Invoice
     $invoice = new Invoice();
     // Loop through all invoice tags
     foreach ($invoiceTags as $tag => $method) {
         $_tag = $responseDOM->getElementsByTagName($tag)->item(0);
         if (isset($_tag) && isset($_tag->textContent)) {
             $invoice->{$method}($_tag->textContent);
         }
     }
     // Make a custom, and loop through custom tags
     $customer = new Customer();
     foreach ($customerTags as $tag => $method) {
         $_tag = $responseDOM->getElementsByTagName($tag)->item(0);
         if (isset($_tag) && isset($_tag->textContent)) {
             $customer->{$method}($_tag->textContent);
         }
     }
     // Make an InvoiceTotals and loop through custom tags
     $invoiceTotals = new InvoiceTotals();
     foreach ($totalsTags as $tag => $method) {
         $_tag = $responseDOM->getElementsByTagName($tag)->item(0);
         if (isset($_tag) && isset($_tag->textContent)) {
             $invoiceTotals->{$method}($_tag->textContent);
         }
     }
     // Set the custom classes to the invoice
     $invoice->setCustomer($customer);
     $invoice->setTotals($invoiceTotals);
     $lineTags = array('article' => 'setArticle', 'subarticle' => 'setSubArticle', 'quantity' => 'setQuantity', 'units' => 'setUnits', 'allowdiscountorpremium' => 'setAllowDiscountOrPremium', 'description' => 'setDescription', 'valueexcl' => 'setValueExcl', 'vatvalue' => 'setVatValue', 'valueinc' => 'setValueInc', 'unitspriceexcl' => 'setUnitsPriceExcl', 'unitspriceinc' => 'setUnitsPriceInc', 'freetext1' => 'setFreeText1', 'freetext2' => 'setFreeText2', 'freetext3' => 'setFreeText3', 'performancedate' => 'setPerformanceDate');
     foreach ($responseDOM->getElementsByTagName('line') as $lineDOM) {
         $temp_line = new InvoiceLine();
         $temp_line->setID($lineDOM->getAttribute('id'));
         foreach ($lineTags as $tag => $method) {
             $_tag = $lineDOM->getElementsByTagName($tag)->item(0);
             if (isset($_tag) && isset($_tag->textContent)) {
                 $temp_line->{$method}($_tag->textContent);
             }
         }
         $invoice->addLine($temp_line);
         unset($temp_line);
     }
     return $invoice;
 }