Browse Source

First version of VIEW client code and glade

Frederic G. Marand 17 years ago
commit
e39a8f8c9b
2 changed files with 528 additions and 0 deletions
  1. 338 0
      vies.glade
  2. 190 0
      vies.phpw

+ 338 - 0
vies.glade

@@ -0,0 +1,338 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--Generated with glade3 3.0.2 on Sun Apr 08 23:35:51 2007 by Marand@PC-OSI-->
+<glade-interface>
+  <widget class="GtkWindow" id="w">
+    <property name="title" translatable="yes">Check EU VAT ID using VIES</property>
+    <property name="default_width">320</property>
+    <property name="default_height">300</property>
+    <signal name="destroy" handler="on_quit_action"/>
+    <child>
+      <widget class="GtkVBox" id="vb">
+        <property name="visible">True</property>
+        <property name="spacing">1</property>
+        <child>
+          <widget class="GtkHBox" id="hb">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkComboBox" id="cb_country">
+                <property name="visible">True</property>
+                <property name="items" translatable="yes">AT - Austria
+BE - Belgium
+BG - Bulgaria
+CY - Cyprus
+CZ - Czech Republic
+DE - Germany
+DK - Denmark
+EE - Estonia
+EL - Greece
+ES - Spain
+FI - Finland
+FR - France
+GB - United Kingdom
+HU - Hungary
+IE - Ireland
+IT - Italy
+LT - Lituhania
+LU - Luxembourg
+LV - Latvia
+MT - Malta
+NL - The Netherlands
+PL - Poland
+PT - Portugal
+RO - Romania
+SE - Sweden
+SI - Slovenia
+SK - Slovakia</property>
+              </widget>
+              <packing>
+                <property name="padding">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkEntry" id="en_vat">
+                <property name="visible">True</property>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkButton" id="btn">
+            <property name="visible">True</property>
+            <property name="border_width">1</property>
+            <property name="label" translatable="yes">_Check VAT number</property>
+            <property name="use_underline">True</property>
+            <signal name="clicked" handler="on_btn_clicked"/>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">2</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkNotebook" id="nb">
+            <property name="visible">True</property>
+            <property name="tab_pos">GTK_POS_BOTTOM</property>
+            <property name="show_tabs">False</property>
+            <property name="homogeneous">True</property>
+            <child>
+              <widget class="GtkScrolledWindow" id="sw">
+                <property name="visible">True</property>
+                <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <child>
+                  <widget class="GtkTextView" id="tv">
+                    <property name="visible">True</property>
+                    <property name="text" translatable="yes">This applet allows EU companies to check the validity of 
+EU VAT registrations according to the official EU VIES
+(VAT Information Exchange System) service.
+
+More detail about the service is available at 
+http://ec.europa.eu/taxation_customs/vies/en/vieshome.htm</property>
+                  </widget>
+                </child>
+              </widget>
+              <packing>
+                <property name="tab_expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+              <packing>
+                <property name="type">tab</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkTable" id="tbl">
+                <property name="visible">True</property>
+                <property name="border_width">1</property>
+                <property name="n_rows">6</property>
+                <property name="n_columns">2</property>
+                <property name="column_spacing">2</property>
+                <property name="row_spacing">2</property>
+                <child>
+                  <widget class="GtkImage" id="imgValid">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="stock">gtk-dialog-question</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbAddress">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="yalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Address</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbName">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Name</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbValid">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Valid ?</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbRequestDate">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Request Date</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbVatNumber">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">VAT number</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbAddressVal">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">---
+
+</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbNameVal">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">---</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbVatNumberVal">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">?</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbRequestDateVal">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">?</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbCountryCodeVal">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">?</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="lbCountryCode">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Country Code</property>
+                    <property name="single_line_mode">True</property>
+                  </widget>
+                  <packing>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+                <property name="tab_expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+              <packing>
+                <property name="type">tab</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkStatusbar" id="sb">
+            <property name="visible">True</property>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>

+ 190 - 0
vies.phpw

@@ -0,0 +1,190 @@
+<?php
+/**
+ * A PHP-GTK2 UI for a SOAP client to the EU
+ * VAT Information Exchange System (VIES) database
+ * (c) 2007 Frederic G. MARAND
+ * Licensed under the CeCILL 2.0 license
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
+ *
+ * $Id: vies.phpw,v 1.1 2007-04-09 16:27:57 marand Exp $
+ */
+
+error_reporting(E_ALL|E_STRICT);
+
+/**
+ * Straight from the WSDL schema
+ */
+class checkVat
+  {
+  /**
+   * @var string
+   */
+  var $countryCode;
+  /**
+   * @var string
+   */
+  var $vatNumber;
+
+  function __construct($cc, $vat)
+    {
+    $this->countryCode = $cc;
+    $this->vatNumber = $vat;
+    }
+  }
+
+class UI
+  {
+  /**
+   * @var GladeXML
+   */
+  var $glade ;
+
+  function __construct()
+    {
+    $this->glade = new GladeXML('vies.glade');
+    $this->glade->signal_autoconnect_instance($this);
+    }
+
+  /**
+   * Return a widget from the loaded Glade file
+   *
+   * @param GtkWidget $name
+   */
+  function get_widget($name)
+    {
+    $ret = $this->glade->get_widget($name);
+    return $ret;
+    }
+
+  function on_quit_action()
+    {
+    Gtk::main_quit();
+    }
+
+  function on_btn_clicked()
+    {
+    $sb  = $this->get_widget('sb');
+    $cc  = $this->get_widget('cb_country');
+    $cc  = $cc->get_active_text();
+    $cc  = substr($cc, 0, 2);
+    $text_buffer = new GtkTextBuffer();
+    $text_buffer->set_text('');
+
+    $vat = $this->get_widget('en_vat');
+    $vat = $vat->get_text();
+    /* var_dump($cc);
+    var_dump($vat); */
+    if (empty($cc) || empty($vat))
+      {
+      $sb->push(0, 'You must choose a country and key in a VAT number.');
+      yield();
+      }
+    else
+      {
+      $nb = $this->get_widget('nb');
+      $nb->set_current_page(0);
+      $sb->push(0, 'Invoking VIES web service. Please wait.');
+      yield();
+      $ret = checkVat($cc, $vat);
+      $sb->pop(0);
+      yield();
+
+      if (!is_object($ret)) // An error occurred
+        {
+        $tv = $this->get_widget('tv');
+        $text_buffer->set_text($ret);
+        $tv->set_buffer($text_buffer);
+        }
+      else // We got a result
+        {
+        print_r($ret);
+        $val = $this->get_widget('lbCountryCodeVal');
+        $val->set_text($ret->countryCode);
+
+        $val = $this->get_widget('lbVatNumberVal');
+        $val->set_text($ret->vatNumber);
+
+        $val = $this->get_widget('lbRequestDateVal');
+        $val->set_text($ret->requestDate);
+
+        $val = $this->get_widget('imgValid');
+        if ($ret->valid)
+          {
+          $val->set_from_stock(Gtk::STOCK_YES, Gtk::ICON_SIZE_LARGE_TOOLBAR);
+          }
+        else
+          {
+          $val->set_from_stock(Gtk::STOCK_NO, Gtk::ICON_SIZE_LARGE_TOOLBAR);
+          }
+        $val = $this->get_widget('lbNameVal');
+        $val->set_text(empty($ret->name) ? '(not returned)' : $ret->name);
+
+        $val = $this->get_widget('lbAddressVal');
+        $val->set_text(empty($ret->address) ? '(not returned)' : $ret->address);
+
+        $nb->set_current_page(1);
+        }
+      yield();
+      }
+    }
+
+  function run()
+    {
+    $w = $this->get_widget('w');
+    $w->show_all();
+    Gtk::main();
+    }
+  }
+
+function yield()
+  {
+  while (Gtk::events_pending())
+    {
+    Gtk::main_iteration();
+    }
+  }
+
+/**
+ * Invoke the VIES service to check an EU VAT number
+ *
+ * @param string $cc Country Code
+ * @param string $vat VAT number
+ * @return mixed
+ */
+function checkVat($cc, $vat)
+{
+$wsdl = 'http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl';
+
+$vies = new SoapClient($wsdl);
+/*
+var_dump($vies->__getFunctions());
+var_dump($vies->__getTypes());
+*/
+$nii = new checkVat($cc, $vat);
+
+try
+  {
+  $ret = $vies->checkVat($nii);
+  }
+catch (SoapFault $e)
+  {
+  $ret = $e->faultstring;
+  $regex = '/\{ \'([A-Z_]*)\' \}/';
+  $n = preg_match($regex, $ret, $matches);
+  $ret = $matches[1];
+  $faults = array
+    (
+    'INVALID_INPUT'       => 'The provided CountryCode is invalid or the VAT number is empty',
+    'SERVICE_UNAVAILABLE' => 'The SOAP service is unavailable, try again later',
+    'MS_UNAVAILABLE'      => 'The Member State service is unavailable, try again later or with another Member State',
+    'TIMEOUT'             => 'The Member State service could not be reached in time, try again later or with another Member State',
+    'SERVER_BUSY'         => 'The service cannot process your request. Try again later.'
+    );
+  $ret = $faults[$ret];
+  }
+
+return $ret;
+}
+
+$ui = new UI();
+$ui->run();