Enneaegsed: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Jelken (talk | contribs)
Jelken (talk | contribs)
No edit summary
Line 24: Line 24:
== XML fail ==
== XML fail ==


Teemaks valisime arvete andmete hoidmise XML-is ning nende põhjal arvete nimekirja ja arvete endi genereerimise.
Teemaks valisime arvete andmete hoidmise XML-is ning nende põhjal arvete nimekirja kuvamise ja arvete trükiks sobivate kuvade genereerimise.


=== XML ===
=== XML ===

Revision as of 16:56, 13 March 2016


Meeskond "Enneaegsed"
Aine: Category:Võrgurakendused II: hajussüsteemide ehitamine
Liikmed: Jaan Elken
Margit Ool
Juhendajad: Mait Poska
Semester: 2016 kevad

XML fail

Teemaks valisime arvete andmete hoidmise XML-is ning nende põhjal arvete nimekirja kuvamise ja arvete trükiks sobivate kuvade genereerimise.

XML

<?xml version="1.0" encoding="utf-8" ?>
<invoices>
  <invoice ref="00001" issued="2016-02-24" type="B2C">
    <header>
      <title>Arve</title>
      <order-number>MF002412</order-number>
      <due-date>2016-03-24</due-date>
      <seller>
        <name>OÜ Naelutaja</name>
        <registration-code>10421629</registration-code>
        <contact-address>
          <street>Kalju</street>
          <house>12</house>
          <apartement>6</apartement>
          <city-county>Tallinn</city-county>
          <postal-code>10512</postal-code>
        </contact-address>
        <contact-phone>56000000</contact-phone>
        <bank-requisites>
          <requisite>
            <name>Swedbank</name>
            <iban>EE232200001180005555</iban>
          </requisite>
          <requisite>
            <name>LHV</name>
            <iban>EE232200001188972345</iban>
          </requisite>
        </bank-requisites>
      </seller>
      <buyer>
        <name>Peeter Ehitaja</name>
        <contact-address>
          <street>Kalda</street>
          <house>1</house>
          <apartement>1</apartement>
          <city-county>Tallinn</city-county>
          <postal-code>10512</postal-code>
        </contact-address>
      </buyer>
    </header>
    <body>
      <invoice-items>
        <item type="goods">
          <amount unit="tk">10</amount>
          <name>Nael</name>
          <price-vat currency="EUR">1.2</price-vat>
          <price currency="EUR">1</price>
        </item>
        <item type="service">
          <amount unit="h">1</amount>
          <name>Naelutamine</name>
          <price-vat currency="EUR">12</price-vat>
          <price currency="EUR">10</price>
        </item>
      </invoice-items>
    </body>
    <footer>
      <total-price-vat currency="EUR">13</total-price-vat>
      <total-price currency="EUR">11.2</total-price>
      <instructions>Naelutama tullakse 30.03.2016 kell 13.00</instructions>
    </footer>
  </invoice>
  
  <invoice ref="00002" issued="2016-02-24" type="B2B">
    <header>
      <title>Arve</title>
      <order-number>MF005432</order-number>
      <due-date>2016-04-24</due-date>
      <seller>
        <name>OÜ Naelutaja</name>
        <registration-code>10421629</registration-code>
        <contact-address>
          <street>Kalju</street>
          <house>12</house>
          <apartement>6</apartement>
          <city-county>Tallinn</city-county>
          <postal-code>10512</postal-code>
        </contact-address>
        <contact-phone>56000000</contact-phone>
        <bank-requisites>
          <requisite>
            <name>Swedbank</name>
            <iban>EE232200001180005555</iban>
          </requisite>
          <requisite>
            <name>LHV</name>
            <iban>EE232200001188972345</iban>
          </requisite>
        </bank-requisites>
      </seller>
      <buyer>
        <name>OÜ Oütaja</name>
        <contact-address>
          <street>Riidevarna</street>
          <house>3</house>
          <apartement>1</apartement>
          <city-county>Tallinn</city-county>
          <postal-code>43232</postal-code>
        </contact-address>
      </buyer>
    </header>
    <body>
      <invoice-items>
        <item type="goods">
          <amount unit="tk">1</amount>
          <name>Diivan</name>
          <price currency="EUR">1000</price>
        </item>
        <item type="goods">
          <amount unit="tk">2</amount>
          <name>Tool</name>
          <price currency="EUR">300</price>
        </item>
        <item type="service">
          <amount unit="hours">1</amount>
          <name>Tassimine</name>
          <price currency="EUR">50</price>
        </item>
      </invoice-items>
    </body>
    <footer>
      <total-price currency="EUR">1350</total-price>
      <instructions>Kohaletoimetamine kokkuleppel, helistada 23423432</instructions>
    </footer>
  </invoice>

  <invoice ref="00003" issued="2016-02-26" type="B2C">
    <header>
      <title>Arve</title>
      <order-number>MF005645</order-number>
      <due-date>2016-04-24</due-date>
      <seller>
        <name>OÜ Naelutaja</name>
        <registration-code>10421629</registration-code>
        <contact-address>
          <street>Kalju</street>
          <house>12</house>
          <apartement>6</apartement>
          <city-county>Tallinn</city-county>
          <postal-code>10512</postal-code>
        </contact-address>
        <contact-phone>56000000</contact-phone>
        <bank-requisites>
          <requisite>
            <name>Swedbank</name>
            <iban>EE232200001180005555</iban>
          </requisite>
          <requisite>
            <name>LHV</name>
            <iban>EE232200001188972345</iban>
          </requisite>
        </bank-requisites>
      </seller>
      <buyer>
        <name>Kahtlane tegelane</name>
        <contact-address>
          <street>Paldiski mnt</street>
          <house>123</house>
          <apartement>1</apartement>
          <city-county>Tallinn</city-county>
          <postal-code>54545</postal-code>
        </contact-address>
      </buyer>
    </header>
    <body>
      <invoice-items>
        <item type="goods">
          <amount unit="tk">1</amount>
          <name>Labidas</name>
          <price currency="USD">30</price>
          <price-vat currency="USD">36</price-vat>
        </item>
      </invoice-items>
    </body>
    <footer>
      <total-price currency="USD">30</total-price>
      <total-price-vat currency="USD">36</total-price-vat>
    </footer>
  </invoice>
</invoices>

XML schema (XSD)

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="currencyType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="EUR" />
      <xs:enumeration value="USD" />
      <xs:enumeration value="GBP" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="invoiceType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="B2C" />
      <xs:enumeration value="B2B" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="invoiceItemType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="goods" />
      <xs:enumeration value="service" />
      <xs:enumeration value="credit" />
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="invoices">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="invoice" maxOccurs="unbounded">
          <xs:complexType>
            <xs:all>
              <xs:element name="header">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="title" type="xs:string" />
                    <xs:element name="order-number" type="xs:string" />
                    <xs:element name="due-date" type="xs:date" />
                    <xs:element name="seller">
                      <xs:complexType>
                        <xs:all>
                          <xs:element name="name" type="xs:string" />
                          <xs:element name="registration-code" type="xs:string" />
                          <xs:element name="contact-address">
                            <xs:complexType>
                              <xs:all>
                                <xs:element name="street" type="xs:string" />
                                <xs:element name="house" type="xs:string" />
                                <xs:element minOccurs="0" name="apartement" type="xs:string" />
                                <xs:element name="city-county" type="xs:string" />
                                <xs:element minOccurs="0" name="municipality" type="xs:string" />
                                <xs:element name="postal-code" type="xs:integer" />
                              </xs:all>
                            </xs:complexType>
                          </xs:element>
                          <xs:element minOccurs="0" name="contact-phone" type="xs:string"></xs:element>
                          <xs:element name="bank-requisites">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element maxOccurs="unbounded" name="requisite">
                                  <xs:complexType>
                                    <xs:sequence>
                                      <xs:element name="name" type="xs:string" />
                                      <xs:element name="iban" type="xs:string" />
                                    </xs:sequence>
                                  </xs:complexType>
                                </xs:element>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                        </xs:all>
                      </xs:complexType>
                    </xs:element>
                    <xs:element name="buyer">
                      <xs:complexType>
                        <xs:all>
                          <xs:element name="name" type="xs:string" />
                          <xs:element name="contact-address">
                            <xs:complexType>
                              <xs:all>
                                <xs:element name="street" type="xs:string" />
                                <xs:element name="house" type="xs:string" />
                                <xs:element minOccurs="0" name="apartement" type="xs:string" />
                                <xs:element name="city-county" type="xs:string" />
                                <xs:element minOccurs="0" name="municipality" type="xs:string" />
                                <xs:element name="postal-code" type="xs:integer" />
                              </xs:all>
                            </xs:complexType>
                          </xs:element>
                          <xs:element minOccurs="0" name="contact-phone" type="xs:string"></xs:element>
                        </xs:all>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="body">
                <xs:complexType>
                  <xs:all>
                    <xs:element name="invoice-items">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element maxOccurs="unbounded" name="item">
                            <xs:complexType>
                              <xs:all>
                                <xs:element name="amount">
                                  <xs:complexType>
                                    <xs:simpleContent>
                                      <xs:extension base="xs:integer">
                                        <xs:attribute name="unit" type="xs:string" use="required" />
                                      </xs:extension>
                                    </xs:simpleContent>
                                  </xs:complexType>
                                </xs:element>
                                <xs:element name="name" type="xs:string" />
                                <xs:element minOccurs="0" name="price-vat">
                                  <xs:complexType>
                                    <xs:simpleContent>
                                      <xs:extension base="xs:decimal">
                                        <xs:attribute name="currency" type="xs:string" use="required" />
                                      </xs:extension>
                                    </xs:simpleContent>
                                  </xs:complexType>
                                </xs:element>
                                <xs:element name="price">
                                  <xs:complexType>
                                    <xs:simpleContent>
                                      <xs:extension base="xs:decimal">
                                        <xs:attribute name="currency" type="xs:string" use="required" />
                                      </xs:extension>
                                    </xs:simpleContent>
                                  </xs:complexType>
                                </xs:element>
                              </xs:all>
                              <xs:attribute name="type" type="invoiceItemType" use="required" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:all>
                </xs:complexType>
              </xs:element>
              <xs:element name="footer">
                <xs:complexType>
                  <xs:all>
                    <xs:element minOccurs="0" name="total-price-vat" >
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:decimal">
                            <xs:attribute name="currency" type="xs:string" use="required" />
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                    <xs:element name="total-price" minOccurs="1">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:decimal">
                            <xs:attribute name="currency" type="xs:string" use="required" />
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>                    
                    </xs:element>
                    <xs:element minOccurs="0" name="instructions" type="xs:string" />
                  </xs:all>
                </xs:complexType>
              </xs:element>
            </xs:all>
            <xs:attribute name="ref" type="xs:string" use="required" />
            <xs:attribute name="issued" type="xs:date" use="required" />
            <xs:attribute name="type" type="invoiceType" use="required"/>
          </xs:complexType>
        </xs:element> 
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

XSLT - arvete nimekirja kuvamine

Genereerib arvete nimekirja

XSLT

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>
          Arvete nimekiri:
        </title>
      </head>
      <body>
        <h2>Arvete nimekiri:</h2>
        <table border="1" style="width:100%">
          <tr>
            <th>Arve nr</th>
            <th>Arve tüüp</th>
            <th>Arve saaja</th>
            <th>Väljastamise kp</th>
            <th>Maksetähtaeg</th>
            <th>Kogusumma</th>
          </tr>
          <xsl:for-each select="/invoices/invoice" >
            <tr>
              <td>
                <xsl:value-of select="@ref"/>
              </td>
              <td>
                <xsl:value-of select="@type"/>
              </td>
              <td>
                <xsl:value-of select="header/buyer/name"/>
              </td>
              <td>
                <xsl:value-of select="@issued"/>
              </td>
              <td>
                <xsl:value-of select="header/due-date"/>
              </td>
              <td>
                <xsl:choose>
                  <xsl:when test="@type = 'B2B'">
                    <xsl:value-of select="footer/total-price"/>
                    <xsl:text> </xsl:text>
                    <xsl:value-of select="footer/total-price/@currency"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="footer/total-price-vat"/>
                    <xsl:text> </xsl:text>
                    <xsl:value-of select="footer/total-price/@currency"/>
                  </xsl:otherwise>
                </xsl:choose>
        
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>


Näidis

XSLT - arvete genereerimine

Genereerib kõik arved

XSLT

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>
          Arved
        </title>
      </head>
      <body>
        <xsl:for-each select="/invoices/invoice" >
          <xsl:variable name="invoiceType" select="@type"/>
          <table borders="0" width="100%">
            <tr>
              <td colspan="2" align="right">
                <xsl:text>Koostatud </xsl:text>
                <xsl:value-of select="@issued"/>
              </td>
            </tr>
            <tr>
              <td colspan="2" align="center">
                <h2>
                  <xsl:value-of select="header/title"/>
                  <xsl:text> nr: </xsl:text>
                  <xsl:value-of select="@ref"/>
                  <xsl:text> - tellimuse nr: </xsl:text>
                  <xsl:value-of select="header/order-number"/>
                </h2>
              </td>
            </tr>
            <tr>
              <td>
                <b>Arve saaja:</b>
                <br/>
                <xsl:value-of select="header/buyer/name"/>
                <br/>
                <xsl:value-of select="header/buyer/contact-address"/>
              </td>
              <td align="right">
                <b>Arve esitaja:</b>
                <br/>
                <xsl:value-of select="header/seller/name"/>
                <br/>
                <xsl:value-of select="header/seller/registration-code"/>
                <br/>
                <xsl:value-of select="header/seller/contact-address"/>
                <br/>
                <xsl:for-each select="header/seller/bank-requisites/requisite">
                  <xsl:value-of select="name"/>
                  <xsl:text>: </xsl:text>
                  <xsl:value-of select="iban"/>
                  <br/>
                </xsl:for-each>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <xsl:text>NB! Arve tasumise tähtaeg on </xsl:text>
                <xsl:value-of select="header/due-date"/>
              </td>
            </tr>
          </table>

          <table width="100%">
            <tr bgcolor="#dddddd">
              <th width="25%">Nimetus</th>
              <th width="25%">Kogus</th>
              <th width="25%">Hind</th>
              <xsl:if test="$invoiceType = 'B2C'">
                <th width="25%">Hind+KM</th>
              </xsl:if>
            </tr>

            <xsl:if test="count(body/invoice-items/item[@type='goods']) > 0">
                <tr bgcolor="#eeeeee">
                  <td align="left" colspan="100%">
                    <b>Esemed</b>
                  </td>
                </tr>
                <xsl:for-each select="body/invoice-items/item[@type='goods']">
                  <tr>
                    <td>
                      <xsl:value-of select="name"/>
                    </td>
                    <td>
                      <xsl:value-of select="amount"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="amount/@unit"/>
                    </td>
                    <td>
                      <xsl:value-of select="price"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="price/@currency"/>
                    </td>
                    <xsl:if test="$invoiceType = 'B2C'">
                      <td>
                        <xsl:value-of select="price-vat"/>
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="price-vat/@currency"/>
                      </td>
                    </xsl:if>
                  </tr>
                </xsl:for-each>
            </xsl:if>
          
            <xsl:if test="count(body/invoice-items/item[@type='service']) > 0">
                <tr bgcolor="#eeeeee">
                  <td align="left" colspan="100%">
                    <b>Teenused</b>
                  </td>
                </tr>
                <xsl:for-each select="body/invoice-items/item[@type='service']">
                  <tr>
                    <td>
                      <xsl:value-of select="name"/>
                    </td>
                    <td>
                      <xsl:value-of select="amount"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="amount/@unit"/>
                    </td>
                    <td>
                      <xsl:value-of select="price"/>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="price/@currency"/>
                    </td>
                    <xsl:if test="$invoiceType = 'B2C'">
                      <td>
                        <xsl:value-of select="price-vat"/>
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="price-vat/@currency"/>
                      </td>
                    </xsl:if>
                  </tr>
                </xsl:for-each>
            </xsl:if>
          </table>

          <br/>
          <table width="100%">
            <tr bgcolor="#cccccc">
              <th colspan="2" width="50%" align="left">Kokku</th>
              <th width="25%">
                <xsl:value-of select="footer/total-price"/>
                <xsl:text> </xsl:text>
                <xsl:value-of select="footer/total-price/@currency"/>
              </th>
              <xsl:if test="$invoiceType = 'B2C'">
                <th width="25%">
                  <xsl:value-of select="footer/total-price-vat"/>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="footer/total-price-vat/@currency"/>
                </th>
              </xsl:if>
            </tr>
            <tr rowspan="3">
              <td widht="100%">
                <br/>
                <xsl:text>Märkused: </xsl:text>
                <xsl:value-of select="footer/instructions"/>
              </td>
            </tr>
          </table>

          <br/>
          <hr/>
          <table style="font-size: 10pt;" width="100%">
            <tr>
              <td width="50%" align="left">
                <xsl:value-of select="header/seller/name"/>
                <br/>
                <xsl:value-of select="header/seller/registration-code"/>
                <br/>
                <xsl:value-of select="header/seller/contact-address"/>
                <br/>
                <xsl:if test="header/seller/contact-phone != ''">
                  Telefon:
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="header/seller/contact-phone"/>
                </xsl:if> 
              </td>
              <td width="50%" align="right">
                <xsl:for-each select="header/seller/bank-requisites/requisite">
                  <xsl:value-of select="name"/>
                  <xsl:text>: </xsl:text>
                  <xsl:value-of select="iban"/>
                  <br/>
                </xsl:for-each>
              </td>
            </tr>
          </table>
          <div style="width:100%;height:200px;"></div>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>


Näidis