diff --git a/Makefile b/Makefile index 3ccc4653f733ee4031ca11a78eab600d39f54e85..6f9c680bb9f68356eee3b4ccbaaec659e7227e15 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,8 @@ MVCFILES=controllers/ models/ views/ SYSTRANSLATIONS=$(call wildcard,language/*/*.plg_$(PLUGINTYPE)_$(BASE).*sys.ini) NONSYSTRANSLATIONS=${SYSTRANSLATIONS:%.sys.ini=%.ini} TRANSLATIONS=$(SYSTRANSLATIONS) $(NONSYSTRANSLATIONS) $(call wildcard,language/*/index.html) language/index.html -FIELDS=$(call wildcard,fields/*.php) +FIELDS=fields/ +ELEMENTS=elements/ ZIPFILE=plg_$(PLUGINTYPE)_$(BASE)_v$(VERSION).zip @@ -20,7 +21,7 @@ $(NONSYSTRANSLATIONS): %.ini: %.sys.ini zip: $(PLUGINFILES) $(TRANSLATIONS) $(SYSTRANSLATIONS) $(NONSYSTRANSLATIONS) @echo "Packing all files into distribution file $(ZIPFILE):" - @zip -r $(ZIPFILE) $(PLUGINFILES) $(MVCFILES) $(TRANSLATIONS) $(FIELDS) + @zip -r $(ZIPFILE) $(PLUGINFILES) $(MVCFILES) $(TRANSLATIONS) $(FIELDS) $(ELEMENTS) clean: rm -f $(ZIPFILE) diff --git a/controllers/eurecap.php b/controllers/eurecap.php index d70b8d598af83dd99f2c8c75afdf844496416eb3..617b308f67206fcda46f2107391427a8b67cf430 100644 --- a/controllers/eurecap.php +++ b/controllers/eurecap.php @@ -38,6 +38,11 @@ class VirtuemartControllerEuRecap extends VmController { $this->addViewPath(JPATH_PLUGINS.DS . 'vmextended' . DS . 'eurecap' . DS . 'views'); } + public function cancel(){ + $msg = vmText::_('VMEXT_EU_RECAP_CANCELLED'); + $this->setRedirect($this->redirectPath, $msg, 'message'); + } + function settings($layout='settings'){ vRequest::setVar('controller', $this->_cname); @@ -53,18 +58,17 @@ class VirtuemartControllerEuRecap extends VmController { $this->display(); } - function export($layout='csv'){ + function export(){ vRequest::setVar('controller', $this->_cname); vRequest::setVar('view', $this->_cname); - vRequest::setVar('layout', $layout); +// vRequest::setVar('layout', $layout); -// $this->addViewPath(VMPATH_ADMIN . DS . 'views'); $document = JFactory::getDocument(); $viewType = $document->getType(); $view = $this->getView($this->_cname, $viewType); - $view->setLayout($layout); +// $view->setLayout($layout); $this->display(); } diff --git a/elements/eucountries.php b/elements/eucountries.php new file mode 100644 index 0000000000000000000000000000000000000000..7a274eae5ec690942a32f2e19b68090e1c0faeaf --- /dev/null +++ b/elements/eucountries.php @@ -0,0 +1,49 @@ +<?php +defined('_JEXEC') or die(); + +/** + * + * @package VirtueMart + * @subpackage Plugins - Elements + * @author Valérie Isaksen, adapted by Reinhold Kainhofer for EU countries + * @link http://www.virtuemart.net + * @copyright Copyright (c) 2004 - 2011 VirtueMart Team. All rights reserved. + * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php + * VirtueMart is free software. This version may have been modified pursuant + * to the GNU General Public License, and as distributed it includes or + * is derivative of works licensed under the GNU General Public License or + * other free or open source software licenses. + * @version $Id: $ + */ +/* + * This class is used by VirtueMart Payment or Shipment Plugins + * which uses JParameter + * So It should be an extension of JElement + * Those plugins cannot be configured througth the Plugin Manager anyway. + */ +class JElementEUCountries extends JElement { + + /** + * Element name + * @access protected + * @var string + */ + var $_name = 'euCountries'; + + function fetchElement($name, $value, &$node, $control_name) { + + $db = JFactory::getDBO(); + + $query = 'SELECT `virtuemart_country_id` AS value, `country_name` AS text FROM `#__virtuemart_countries` + WHERE `published` = 1 AND `country_2_code` IN ("AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SI", "SK", "ES", "SE", "GB") ORDER BY `country_name` ASC '; + + $db->setQuery($query); + $fields = $db->loadObjectList(); + $class = ($node->attributes('class') ? 'class="' . $node->attributes('class') . '"' : ''); + + + $class = 'multiple="true" size="10" '; + return JHTML::_('select.genericlist', $fields, $control_name . '[' . $name . '][]', $class, 'value', 'text', $value, $control_name . $name); + } + +} \ No newline at end of file diff --git a/elements/vmorderstates.php b/elements/vmorderstates.php new file mode 100644 index 0000000000000000000000000000000000000000..25798b9fa8de35f7e14e0c807670ab1f01ec1a9c --- /dev/null +++ b/elements/vmorderstates.php @@ -0,0 +1,43 @@ +<?php +defined ('_JEXEC') or die(); +/** + * + * @package VirtueMart + * @subpackage Plugins - Elements + * @author Valérie Isaksen + * @link http://www.virtuemart.net + * @copyright Copyright (c) 2004 - 2011 VirtueMart Team. All rights reserved. + * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php + * VirtueMart is free software. This version may have been modified pursuant + * to the GNU General Public License, and as distributed it includes or + * is derivative of works licensed under the GNU General Public License or + * other free or open source software licenses. + * @version $Id:$ + */ +if (!class_exists('VmConfig')) require(JPATH_VM_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php'); +if(!class_exists('VmModel')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmmodel.php'); + +/* + * This class is used by VirtueMart Payment or Shipment Plugins + * which uses JParameter + * So It should be an extension of JElement + * Those plugins cannot be configured througth the Plugin Manager anyway. + */ +class JElementVmOrderStates extends JElement { + + /** + * Element name + * + * @access protected + * @var string + */ + var $_name = 'OrderStates'; + + function fetchElement ($name, $value, &$node, $control_name) { + $statusModel = VmModel::getModel('OrderStatus'); + $fields = $statusModel->getOrderStatusNames(); + $class = 'class="inputbox" multiple="multiple" size="6" '; + + return JHTML::_ ('select.genericlist', $fields, $control_name . '[' . $name . '][]', $class, 'order_status_code', 'order_status_name', $value, $control_name . $name, true); + } +} diff --git a/elements/vmshoppergroups.php b/elements/vmshoppergroups.php new file mode 100644 index 0000000000000000000000000000000000000000..2cda4c2a7c763a23e8a102d6beb60b88b31daf68 --- /dev/null +++ b/elements/vmshoppergroups.php @@ -0,0 +1,43 @@ +<?php +defined('_JEXEC') or die(); +/** + * + * @package VirtueMart + * @subpackage Plugins - Elements + * @author Valérie Isaksen + * @link http://www.virtuemart.net + * @copyright ${PHING.VM.COPYRIGHT} + * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php + * VirtueMart is free software. This version may have been modified pursuant + * to the GNU General Public License, and as distributed it includes or + * is derivative of works licensed under the GNU General Public License or + * other free or open source software licenses. + * @version $Id$ + */ +if (!class_exists('JElementList')) require_once(JPATH_LIBRARIES.DS.'joomla'.DS.'html'.DS.'parameter'.DS.'element'.DS.'list.php'); + +class JELementVmShopperGroups extends JElementList { + + var $_name = 'vmShopperGroups'; + + protected function _getOptions(&$node) { + VmConfig::loadJLang('com_virtuemart_orders', TRUE); + + $options = array(); + $db = JFactory::getDBO(); + + $query = 'SELECT `virtuemart_shoppergroup_id` AS value, `shopper_group_name` AS text + FROM `#__virtuemart_shoppergroups` + WHERE `virtuemart_vendor_id` = 1 + ORDER BY `ordering` ASC, `virtuemart_shoppergroup_id` ASC '; + + $db->setQuery($query); + $values = $db->loadObjectList(); + foreach ($values as $value) { + $options[] = JHtml::_('select.option', $value->value, vmText::_($value->text)); + } + + return $options; + } + +} \ No newline at end of file diff --git a/elements/vmuserfields.php b/elements/vmuserfields.php new file mode 100644 index 0000000000000000000000000000000000000000..3df5433312c89ab7591791cd029e6818b8f7ae3f --- /dev/null +++ b/elements/vmuserfields.php @@ -0,0 +1,35 @@ +<?php +defined('_JEXEC') or die(); +/** + * + * @package VirtueMart + * @subpackage Plugins - Userfields Form Field + * @author Reinhold Kainhofer, Open Tools + * @link http://www.open-tools.net + * @copyright Copyright (c) 2015 Reinhold Kainhofer. All rights reserved. + * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php + * VirtueMart is free software. This version may have been modified pursuant + * to the GNU General Public License, and as distributed it includes or + * is derivative of works licensed under the GNU General Public License or + * other free or open source software licenses. + */ + +if (!class_exists('JElementList')) require_once(JPATH_LIBRARIES.DS.'joomla'.DS.'html'.DS.'parameter'.DS.'element'.DS.'list.php'); + +class JELementVmUserFields extends JElementList { + + var $_name = 'vmUserFields'; + + protected function _getOptions(&$node) { + $model = VmModel::getModel('userfields'); + $userfields = $model->getUserfieldsList(); + $options = array(); + foreach ($userfields as $field) { + if ($field->published) { + $options[] = JHtml::_ ('select.option', $field->name, JText::_($field->title) . " (" . $field->name . ")"); + } + } + return $options; + } + +} \ No newline at end of file diff --git a/eurecap.php b/eurecap.php index 3442a4c0b0bf4a15fdf1675460e84866789a69d3..e7aa1c072d03490260e3d1913d67468291885029 100644 --- a/eurecap.php +++ b/eurecap.php @@ -73,5 +73,32 @@ class plgVmExtendedEuRecap extends vmExtendedPlugin { ), ); } + + /** + * A helper function for the plugin installer: In VM 3.0.? the onVmAdminMenuItems trigger was added, which allows to dynamically + * add admin menu items to the the backend. In earlier versions, we need to hardcode the menu item to the database. This function + * decides whether the database entry is needed and if so, it adds it (otherwise it removes it, just in case). + */ + public function onInstallCheckAdminMenuEntries() { + $vmver = vmVersion::$RELEASE; + $db = JFactory::getDBO(); + $db->setQuery("SELECT `id` FROM `#__virtuemart_adminmenuentries` WHERE `view` = 'eurecap'"); + $exists = $db->loadResult(); + if (version_compare($vmver, '3.0.3', 'lt')) { + if (!$exists) { + // Before VM 3.0.3 => Need database entry (in the "Orders" section): + $q = "INSERT INTO `#__virtuemart_adminmenuentries` (`module_id`, `name`, `link`, `depends`, `icon_class`, `ordering`, `published`, `tooltip`, `view`, `task`) VALUES +(2, '" . vmText::_('COM_VIRTUEMART_EU_RECAP') . "', '', '', 'vmicon vmicon-16-report', 25, 1, '', 'eurecap', '')"; + $db->setQuery($q); + $db->query(); + } + } else { + if ($exists) { + $q = "DELETE FROM `#__virtuemart_adminmenuentries` WHERE `view` = 'eurecap' AND `task` = '' AND `module_id` = 2"; + $db->setQuery($q); + $db->query(); + } + } + } } \ No newline at end of file diff --git a/eurecap.script.php b/eurecap.script.php index c1a1bc1acafc4166deb3d9e845c5d510d052c40b..665af7775f16290c1c9c6070267e9069ea13df03 100644 --- a/eurecap.script.php +++ b/eurecap.script.php @@ -38,13 +38,12 @@ class plgVmExtendedEuRecapInstallerScript * @return boolean True on success */ public function postflight ($type, $parent = null) { -// if(!class_exists( 'vmPlugin' )) -// require JPATH_VM_ADMINISTRATOR.DS.'plugins'.DS.'vmplugin.php'; -// if(!class_exists( 'plgVmShopperOrdernumber' )) -// require JPATH_ROOT.DS.'plugins'.DS.'vmextended'.DS.'eurecap'.DS.'eurecap.php'; -// $dispatcher = new JDispatcher(); -// $config = array('name' => 'eurecap', 'type' => 'vmextended'); -// $plugin = new plgVmExtendedEuRecap($dispatcher, $config); + if(!class_exists( 'plgVmExtendedEuRecap' )) + require JPATH_ROOT.DS.'plugins'.DS.'vmextended'.DS.'eurecap'.DS.'eurecap.php'; + $dispatcher = new JDispatcher(); + $config = array('name' => 'eurecap', 'type' => 'vmextended'); + $plugin = new plgVmExtendedEuRecap($dispatcher, $config); + $plugin->onInstallCheckAdminMenuEntries(); // $plugin->plgVmOnStoreInstallPluginTable('extended'); // // $dispatcher->trigger("plgVmOnStoreInstallPluginTable", array('vmshopper')); } diff --git a/eurecap.xml b/eurecap.xml index 7db6032d5ac95d8a012a6890107f32ccafdc1ee3..9be45069cb6156be307c96107a555aea10e9c226 100644 --- a/eurecap.xml +++ b/eurecap.xml @@ -22,6 +22,7 @@ <folder>controllers</folder> <folder>models</folder> <folder>views</folder> + <folder>helpers</folder> </files> <scriptfile>eurecap.script.php</scriptfile> <languages folder="language"> @@ -29,13 +30,19 @@ <language tag="en-GB">en-GB/en-GB.plg_vmextended_eurecap.sys.ini</language> </languages> +<!-- VM 3.x: Fields --> <vmconfig> <fields name="settings" addfieldpath="/administrator/components/com_virtuemart/fields"> <fieldset name="order_properties" addfieldpath="/plugins/vmextended/eurecap/fields" label="VMEXT_EU_RECAP_ORDERPROPERTIES"> + <field name="countries" type="eucountries" multiple="true" scope="com_virtuemart" default="" label="VMEXT_EU_RECAP_COUNTRIES" description="VMEXT_EU_RECAP_COUNTRIES_DESC"/> <field name="order_status" type="orderstatus" default="C,S" multiple="multiple" label="VMEXT_EU_RECAP_ORDERSTATUS" description="VMEXT_EU_RECAP_ORDERSTATUS_DESC "/> <field name="shopper_groups" type="vmshoppergroups" multiple="multiple" label="VMEXT_EU_RECAP_SHOPPERGROUP" description="VMEXT_EU_RECAP_SHOPPERGROUP_DESC" /> <field name="vatid_userfield" type="vmuserfields" label="VMEXT_EU_RECAP_VATID_USERFIELD" multiple="multiple" default="opc_vat" description="VMEXT_EU_RECAP_VATID_USERFIELD_DESC" /> - <field name="only_untaxed" type="radio" default="1" class="btn-group btn-group-yesno" label="VMEXT_EU_RECAP_UNTAXED" description="VMEXT_EU_RECAP_UNTAXED_DESC" > + <field name="include_taxed_orders" type="radio" default="0" class="btn-group btn-group-yesno" label="VMEXT_EU_RECAP_INCLUDE_TAXED" description="VMEXT_EU_RECAP_INCLUDE_TAXED_DESC" > + <option value="1">JYES</option> + <option value="0">JNO</option> + </field> + <field name="include_free" type="radio" default="0" class="btn-group btn-group-yesno" label="VMEXT_EU_RECAP_INCLUDE_FREE" description="VMEXT_EU_RECAP_INCLUDE_FREE_DESC" > <option value="1">JYES</option> <option value="0">JNO</option> </field> @@ -46,15 +53,58 @@ <option value="3">VMEXT_EU_RECAP_FREQUENCY_QUARTERLY</option> <option value="12">VMEXT_EU_RECAP_FREQUENCY_YEARLY</option> </field> - <field name="countries" type="vmcountries" multiple="true" scope="com_virtuemart" default="" label="VMEXT_EU_RECAP_COUNTRIES" description="VMEXT_EU_RECAP_COUNTRIES_DESC"/> - <field name="taxation_moment" type="list" default="status" label="VMEXT_EU_RECAP_TAXATION_MOMENT" description="VMEXT_EU_RECAP_TAXATION_MOMENT_DESC" > + <field name="taxation_moment" type="list" default="placement" label="VMEXT_EU_RECAP_TAXATION_MOMENT" description="VMEXT_EU_RECAP_TAXATION_MOMENT_DESC" > <option value="placement">VMEXT_EU_RECAP_TAXATION_MOMENT_PLACEMENT</option> <!-- <option value="status">VMEXT_EU_RECAP_TAXATION_MOMENT_STATUSCHANGE</option> --> <!-- <option value="payment">VMEXT_EU_RECAP_TAXATION_MOMENT_PAYMENT</option> --> <option value="invoice">VMEXT_EU_RECAP_TAXATION_MOMENT_INVOICE</option> </field> + <field name="export_format" type="list" default="full" label="VMEXT_EU_RECAP_EXPORT_FORMAT" description="VMEXT_EU_RECAP_EXPORT_FORMAT_DESC" > + <option value="full">VMEXT_EU_RECAP_EXPORT_FULL</option> + <option value="AT_xml">VMEXT_EU_RECAP_EXPORT_AT_XML</option> + <option value="DE_csv">VMEXT_EU_RECAP_EXPORT_DE_CSV</option> + </field> + <field name="vendor_vatid" type="text" scope="com_virtuemart" default="" label="VMEXT_EU_RECAP_VENDOR_VATID" description="VMEXT_EU_RECAP_VENDOR_VATID_DESC"/> <field name="taxnr" type="text" scope="com_virtuemart" default="" label="VMEXT_EU_RECAP_TAXNR" description="VMEXT_EU_RECAP_TAXNR_DESC"/> </fieldset> </fields> </vmconfig> + + + <!-- VM 2.0 support (params rather than fields): --> + <params addpath="/plugins/vmextended/eurecap/elements" /> + <params addpath="/administrator/components/com_virtuemart/elements" > + <param type="vmjpluginwarning" /> + <param name="order_status" type="vmorderstates" default="C,S" multiple="multiple" label="VMEXT_EU_RECAP_ORDERSTATUS" description="VMEXT_EU_RECAP_ORDERSTATUS_DESC "/> + <param name="shopper_groups" type="vmshoppergroups" multiple="multiple" label="VMEXT_EU_RECAP_SHOPPERGROUP" description="VMEXT_EU_RECAP_SHOPPERGROUP_DESC" /> + <param name="vatid_userfield" type="vmuserfields" label="VMEXT_EU_RECAP_VATID_USERFIELD" multiple="multiple" default="opc_vat" description="VMEXT_EU_RECAP_VATID_USERFIELD_DESC" /> + <param name="include_taxed_orders" type="radio" default="0" class="btn-group btn-group-yesno" label="VMEXT_EU_RECAP_INCLUDE_TAXED" description="VMEXT_EU_RECAP_INCLUDE_TAXED_DESC" > + <option value="1">JYES</option> + <option value="0">JNO</option> + </param> + <param name="include_free" type="radio" default="0" class="btn-group btn-group-yesno" label="VMEXT_EU_RECAP_INCLUDE_FREE" description="VMEXT_EU_RECAP_INCLUDE_FREE_DESC" > + <option value="1">JYES</option> + <option value="0">JNO</option> + </param> + <param name="frequency" type="list" default="1" label="VMEXT_EU_RECAP_FREQUENCY" description="VMEXT_EU_RECAP_FREQUENCY_DESC" > + <option value="1">VMEXT_EU_RECAP_FREQUENCY_MONTHLY</option> + <option value="3">VMEXT_EU_RECAP_FREQUENCY_QUARTERLY</option> + <option value="12">VMEXT_EU_RECAP_FREQUENCY_YEARLY</option> + </param> + <param name="countries" type="eucountries" multiple="true" scope="com_virtuemart" default="" label="VMEXT_EU_RECAP_COUNTRIES" description="VMEXT_EU_RECAP_COUNTRIES_DESC"/> + <param name="taxation_moment" type="list" default="placement" label="VMEXT_EU_RECAP_TAXATION_MOMENT" description="VMEXT_EU_RECAP_TAXATION_MOMENT_DESC" > + <option value="placement">VMEXT_EU_RECAP_TAXATION_MOMENT_PLACEMENT</option> +<!-- <option value="status">VMEXT_EU_RECAP_TAXATION_MOMENT_STATUSCHANGE</option> --> +<!-- <option value="payment">VMEXT_EU_RECAP_TAXATION_MOMENT_PAYMENT</option> --> + <option value="invoice">VMEXT_EU_RECAP_TAXATION_MOMENT_INVOICE</option> + </param> + <param name="export_format" type="list" default="full" label="VMEXT_EU_RECAP_EXPORT_FORMAT" description="VMEXT_EU_RECAP_EXPORT_FORMAT_DESC" > + <option value="full">VMEXT_EU_RECAP_EXPORT_FULL</option> + <option value="AT_xml">VMEXT_EU_RECAP_EXPORT_AT_XML</option> + <option value="DE_csv">VMEXT_EU_RECAP_EXPORT_DE_CSV</option> + </param> + <param name="vendor_vatid" type="text" scope="com_virtuemart" default="" label="VMEXT_EU_RECAP_VENDOR_VATID" description="VMEXT_EU_RECAP_VENDOR_VATID_DESC"/> + <param name="taxnr" type="text" scope="com_virtuemart" default="" label="VMEXT_EU_RECAP_TAXNR" description="VMEXT_EU_RECAP_TAXNR_DESC"/> + </params> + </extension> diff --git a/fields/eucountries.php b/fields/eucountries.php new file mode 100644 index 0000000000000000000000000000000000000000..f884064cf5947a40831db03c9c8d387f8bbd9929 --- /dev/null +++ b/fields/eucountries.php @@ -0,0 +1,54 @@ +<?php +defined('_JEXEC') or die(); + +/** + * + * @package VirtueMart + * @subpackage Plugins - Elements + * @author Valérie Isaksen, Adapted by Reinhold Kainhofer for EU countries + * @link http://www.virtuemart.net + * @copyright Copyright (c) 2004 - 2011 VirtueMart Team. All rights reserved. + * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php + * VirtueMart is free software. This version may have been modified pursuant + * to the GNU General Public License, and as distributed it includes or + * is derivative of works licensed under the GNU General Public License or + * other free or open source software licenses. + * @version $Id: $ + */ + +JFormHelper::loadFieldClass('list'); +jimport('joomla.form.formfield'); + +class JFormFieldEUCountries extends JFormFieldList { + + /** + * Element name + * @access protected + * @var string + */ + var $type = 'euCountries'; + + protected function getInput() { + $this->multiple=true; + return parent::getInput(); + } + protected function getOptions() { + $options = array(); + $this->multiple=true; + + $query = 'SELECT `virtuemart_country_id` AS value, `country_name` AS text FROM `#__virtuemart_countries` + WHERE `published` = 1 AND `country_2_code` IN ("AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SI", "SK", "ES", "SE", "GB") ORDER BY `country_name` ASC '; + $db = JFactory::getDBO(); + $db->setQuery($query); + $values = $db->loadObjectList(); + foreach ($values as $v) { + $options[] = JHtml::_('select.option', $v->value, $v->text); + } + + //BAD $class = 'multiple="true" size="10"'; + // Merge any additional options in the XML definition. + $options = array_merge(parent::getOptions(), $options); + + return $options; + } +} \ No newline at end of file diff --git a/fields/vmuserfields.php b/fields/vmuserfields.php index 88d6e54e50c7d23dae736093cab768ca55cf602d..f80f5e7c3fd387fa314a5e2e929541909d52394c 100644 --- a/fields/vmuserfields.php +++ b/fields/vmuserfields.php @@ -24,7 +24,9 @@ class JFormFieldVmUserFields extends JFormFieldList { $userfields = $model->getUserfieldsList(); $options = array(); foreach ($userfields as $field) { - $options[] = JHtml::_ ('select.option', $field->name, JText::_($field->title) . " (" . $field->name . ")"); + if ($field->published) { + $options[] = JHtml::_ ('select.option', $field->name, JText::_($field->title) . " (" . $field->name . ")"); + } } return $options; } diff --git a/language/en-GB/en-GB.plg_vmextended_eurecap.ini b/language/en-GB/en-GB.plg_vmextended_eurecap.ini index 50df327d190392283557062fe6f82f955b488221..3f94fa89dac5d5e97d17e71f49aa54cc846a5ded 100644 --- a/language/en-GB/en-GB.plg_vmextended_eurecap.ini +++ b/language/en-GB/en-GB.plg_vmextended_eurecap.ini @@ -1,38 +1,51 @@ -VMEXT_EU_RECAP="EU Recapitulative Statement" -VMEXT_EU_RECAP_DESC="A plugin to automatically create EU Recapitulative Statements for untaxed cross-border EU sales to businesses with a valid EU VAT ID." +VMEXT_EU_RECAP="EU Sales Report" +VMEXT_EU_RECAP_DESC="A plugin to automatically create EU Sales Reports (a.k.a. EU Recapitulative Statements) for untaxed cross-border EU sales to businesses with a valid EU VAT ID." COM_VIRTUEMART_REPORT_MOD="Reports" -COM_VIRTUEMART_EU_RECAP="EU Recapitulative Statement" +COM_VIRTUEMART_EU_RECAP="EU Sales Report" ; COM_VIRTUEMART_EU_RECAP="EU Recapitulative Statement" -VMEXT_EU_RECAP_SETTINGS_TITLE="Configuration of the EU Recapitulative Statement" -VMEXT_EU_RECAP_VIEW_TITLE_DATE="EU Recapitulative Statement for the period from %s to %s" +VMEXT_EU_RECAP_SETTINGS_TITLE="Configuration of the EU Sales Report" +VMEXT_EU_RECAP_VIEW_TITLE_DATE="EU Sales Report for the period from %s to %s" VMEXT_EU_RECAP_LIST_MONTH="Period" VMEXT_EU_RECAP_LIST_YEAR="Year" -VMEXT_EU_RECAP_RECHECK_EUVATID="(Re-)Check EU VAT IDs" +; VMEXT_EU_RECAP_RECHECK_EUVATID="(Re-)Check EU VAT IDs" VMEXT_EU_RECAP_SETTINGS="Settings" +COM_VIRTUEMART_EU_RECAP_SETTINGS="Settings" +COM_VIRTUEMART_EU_RECAP_LIST="Report" VMEXT_EU_RECAP_EXPORT="Export" +VMEXT_EU_RECAP_EXPORT_FULL="Full dataset (country-independend), CSV format" +VMEXT_EU_RECAP_EXPORT_AT_XML="Austrian XML format" +VMEXT_EU_RECAP_EXPORT_DE_CSV="German CSV format" + +VMEXT_EU_RECAP_EXPORT_TB_FULL="Export (full, csv)" +VMEXT_EU_RECAP_EXPORT_TB_AT_XML="Export (AT, xml)" +VMEXT_EU_RECAP_EXPORT_TB_DE_CSV="Export (DE, csv)" VMEXT_EU_RECAP_FORM_NOTFOUND="Configuration form not available" VMEXT_EU_RECAP_ORDERPROPERTIES="Order Properties for Inclusion in the Report" VMEXT_EU_RECAP_ORDERSTATUS="Order Status" -VMEXT_EU_RECAP_ORDERSTATUS_DESC="Only orders with one of the selected statuses will be included in the recapitulative statement. If none are selected, all orders will possibly be included, depending on the other required properties." +VMEXT_EU_RECAP_ORDERSTATUS_DESC="Only orders with one of the selected statuses will be included in the EU Sales Report. If none are selected, all orders will possibly be included, depending on the other required properties." VMEXT_EU_RECAP_SHOPPERGROUP="Shopper Groups" -VMEXT_EU_RECAP_SHOPPERGROUP_DESC="Only orders by users of the selected shopper groups will be included in the recapitulative statement. If none are selected, all orders will possibly be included, depending on the other required properties." +VMEXT_EU_RECAP_SHOPPERGROUP_DESC="Only orders by users of the selected shopper groups will be included in the EU Sales Report. If none are selected, all orders will possibly be included, depending on the other required properties." VMEXT_EU_RECAP_VATID_USERFIELD="The user field(s) that holds the EU VAT ID of the customer." VMEXT_EU_RECAP_VATID_USERFIELD_DESC="An order can only be included if the customer is a EU-based business with a valid EU VAT ID. This number will usually be stored in a configurable user field. If the plugin to handle EU VAT IDs has changed in the past, select all user fields that were used." -VMEXT_EU_RECAP_UNTAXED="Include only untaxed sales." -VMEXT_EU_RECAP_UNTAXED_DESC="Select whether all orders are included or only orders where no tax (neither at product-level nor at order-level) was charged." -VMEXT_EU_RECAP_REPORTSETTINGS="General Settings for the Recapitulative Report" +VMEXT_EU_RECAP_INCLUDE_TAXED="Include sales that were taxed" +VMEXT_EU_RECAP_INCLUDE_TAXED_DESC="Select whether to also include sales where VAT was charged, even though a (possibly invalid) VATID was given." +VMEXT_EU_RECAP_INCLUDE_FREE="Include free orders" +VMEXT_EU_RECAP_INCLUDE_FREE_DESC="Select whether all orders are included or only orders with an order total larger than 0. In the first case, all free orders will also be included." +VMEXT_EU_RECAP_EXPORT_FORMAT="Export format" +VMEXT_EU_RECAP_EXPORT_FORMAT_DESC="Select the format for the data export. Several countries have their own custom format that needs to be used to import the report into the official tax rporting system." +VMEXT_EU_RECAP_REPORTSETTINGS="General Settings for the EU Sales Report" VMEXT_EU_RECAP_FREQUENCY="Frequency of the Report" -VMEXT_EU_RECAP_FREQUENCY_DESC="Select how often you are required to submit a recapitulative report. Only time periods for the selected frequency will be offered in the report page." +VMEXT_EU_RECAP_FREQUENCY_DESC="Select how often you are required to submit a EU Sales Report. Only time periods for the selected frequency will be offered in the report page." VMEXT_EU_RECAP_FREQUENCY_MONTHLY="Monthly" VMEXT_EU_RECAP_FREQUENCY_QUARTERLY="Quarterly" VMEXT_EU_RECAP_FREQUENCY_YEARLY="Yearly" VMEXT_EU_RECAP_COUNTRIES="Countries" -VMEXT_EU_RECAP_COUNTRIES_DESC="Only orders by customers from of the selected countries will be included in the recapitulative statement. Typically, all EU countries except your home country should be selected." +VMEXT_EU_RECAP_COUNTRIES_DESC="Only orders by customers from of the selected countries will be included in the EU Sales Report. Typically, all EU countries except your home country should be selected." VMEXT_EU_RECAP_TAXATION_MOMENT="Moment of taxation" VMEXT_EU_RECAP_TAXATION_MOMENT_DESC="Select the point in time when a new order actually causes a tax liability." VMEXT_EU_RECAP_TAXATION_MOMENT_PLACEMENT="When the order is initially created in VirtueMart." @@ -40,8 +53,11 @@ VMEXT_EU_RECAP_TAXATION_MOMENT_STATUSCHANGE="When the order is first changed to VMEXT_EU_RECAP_TAXATION_MOMENT_PAYMENT="When payment is made." VMEXT_EU_RECAP_TAXATION_MOMENT_INVOICE="When the invoice is created." -VMEXT_EU_RECAP_TAXNR="Your tax number" -VMEXT_EU_RECAP_TAXNR_DESC="When exporting to xml or csv, some countries require the tax number of the vendor to be included in the file. If this is the case for your tax authority, please enter your tax number here so the generated files can be automatically processed by your tax authority." +VMEXT_EU_RECAP_VENDOR_VATID="Your EU VAT ID number" +VMEXT_EU_RECAP_VENDOR_VATID_DESC="When exporting to xml or csv, some countries require the EU VAT ID number of the vendor to be included in the file. If this is the case for your tax authority, please enter your tax number here so the generated files can be automatically processed by your tax authority." +VMEXT_EU_RECAP_TAXNR="Your local tax number" +VMEXT_EU_RECAP_TAXNR_DESC="When exporting to xml or csv, some countries require the local tax number of the vendor to be included in the file. If this is the case for your tax authority, please enter your tax number here so the generated files can be automatically processed by your tax authority." + VMEXT_EU_RECAP_VATID="EU VAT ID" VMEXT_EU_RECAP_COUNTRYCODE="Billing Country" @@ -49,4 +65,6 @@ VMEXT_EU_RECAP_COMPANY="Company Name" VMEXT_EU_RECAP_NAME="Person" VMEXT_EU_RECAP_ORDERS="Orders" VMEXT_EU_RECAP_ORDERTOTALS="Total revenue" -VMEXT_EU_RECAP_ORDERTAXES="Taxes" \ No newline at end of file +VMEXT_EU_RECAP_ORDERTAXES="Taxes" + +VMEXT_EU_RECAP_CANCELLED="EU Sales Report settings cancelled." \ No newline at end of file diff --git a/language/en-GB/en-GB.plg_vmextended_eurecap.sys.ini b/language/en-GB/en-GB.plg_vmextended_eurecap.sys.ini index 50df327d190392283557062fe6f82f955b488221..3f94fa89dac5d5e97d17e71f49aa54cc846a5ded 100644 --- a/language/en-GB/en-GB.plg_vmextended_eurecap.sys.ini +++ b/language/en-GB/en-GB.plg_vmextended_eurecap.sys.ini @@ -1,38 +1,51 @@ -VMEXT_EU_RECAP="EU Recapitulative Statement" -VMEXT_EU_RECAP_DESC="A plugin to automatically create EU Recapitulative Statements for untaxed cross-border EU sales to businesses with a valid EU VAT ID." +VMEXT_EU_RECAP="EU Sales Report" +VMEXT_EU_RECAP_DESC="A plugin to automatically create EU Sales Reports (a.k.a. EU Recapitulative Statements) for untaxed cross-border EU sales to businesses with a valid EU VAT ID." COM_VIRTUEMART_REPORT_MOD="Reports" -COM_VIRTUEMART_EU_RECAP="EU Recapitulative Statement" +COM_VIRTUEMART_EU_RECAP="EU Sales Report" ; COM_VIRTUEMART_EU_RECAP="EU Recapitulative Statement" -VMEXT_EU_RECAP_SETTINGS_TITLE="Configuration of the EU Recapitulative Statement" -VMEXT_EU_RECAP_VIEW_TITLE_DATE="EU Recapitulative Statement for the period from %s to %s" +VMEXT_EU_RECAP_SETTINGS_TITLE="Configuration of the EU Sales Report" +VMEXT_EU_RECAP_VIEW_TITLE_DATE="EU Sales Report for the period from %s to %s" VMEXT_EU_RECAP_LIST_MONTH="Period" VMEXT_EU_RECAP_LIST_YEAR="Year" -VMEXT_EU_RECAP_RECHECK_EUVATID="(Re-)Check EU VAT IDs" +; VMEXT_EU_RECAP_RECHECK_EUVATID="(Re-)Check EU VAT IDs" VMEXT_EU_RECAP_SETTINGS="Settings" +COM_VIRTUEMART_EU_RECAP_SETTINGS="Settings" +COM_VIRTUEMART_EU_RECAP_LIST="Report" VMEXT_EU_RECAP_EXPORT="Export" +VMEXT_EU_RECAP_EXPORT_FULL="Full dataset (country-independend), CSV format" +VMEXT_EU_RECAP_EXPORT_AT_XML="Austrian XML format" +VMEXT_EU_RECAP_EXPORT_DE_CSV="German CSV format" + +VMEXT_EU_RECAP_EXPORT_TB_FULL="Export (full, csv)" +VMEXT_EU_RECAP_EXPORT_TB_AT_XML="Export (AT, xml)" +VMEXT_EU_RECAP_EXPORT_TB_DE_CSV="Export (DE, csv)" VMEXT_EU_RECAP_FORM_NOTFOUND="Configuration form not available" VMEXT_EU_RECAP_ORDERPROPERTIES="Order Properties for Inclusion in the Report" VMEXT_EU_RECAP_ORDERSTATUS="Order Status" -VMEXT_EU_RECAP_ORDERSTATUS_DESC="Only orders with one of the selected statuses will be included in the recapitulative statement. If none are selected, all orders will possibly be included, depending on the other required properties." +VMEXT_EU_RECAP_ORDERSTATUS_DESC="Only orders with one of the selected statuses will be included in the EU Sales Report. If none are selected, all orders will possibly be included, depending on the other required properties." VMEXT_EU_RECAP_SHOPPERGROUP="Shopper Groups" -VMEXT_EU_RECAP_SHOPPERGROUP_DESC="Only orders by users of the selected shopper groups will be included in the recapitulative statement. If none are selected, all orders will possibly be included, depending on the other required properties." +VMEXT_EU_RECAP_SHOPPERGROUP_DESC="Only orders by users of the selected shopper groups will be included in the EU Sales Report. If none are selected, all orders will possibly be included, depending on the other required properties." VMEXT_EU_RECAP_VATID_USERFIELD="The user field(s) that holds the EU VAT ID of the customer." VMEXT_EU_RECAP_VATID_USERFIELD_DESC="An order can only be included if the customer is a EU-based business with a valid EU VAT ID. This number will usually be stored in a configurable user field. If the plugin to handle EU VAT IDs has changed in the past, select all user fields that were used." -VMEXT_EU_RECAP_UNTAXED="Include only untaxed sales." -VMEXT_EU_RECAP_UNTAXED_DESC="Select whether all orders are included or only orders where no tax (neither at product-level nor at order-level) was charged." -VMEXT_EU_RECAP_REPORTSETTINGS="General Settings for the Recapitulative Report" +VMEXT_EU_RECAP_INCLUDE_TAXED="Include sales that were taxed" +VMEXT_EU_RECAP_INCLUDE_TAXED_DESC="Select whether to also include sales where VAT was charged, even though a (possibly invalid) VATID was given." +VMEXT_EU_RECAP_INCLUDE_FREE="Include free orders" +VMEXT_EU_RECAP_INCLUDE_FREE_DESC="Select whether all orders are included or only orders with an order total larger than 0. In the first case, all free orders will also be included." +VMEXT_EU_RECAP_EXPORT_FORMAT="Export format" +VMEXT_EU_RECAP_EXPORT_FORMAT_DESC="Select the format for the data export. Several countries have their own custom format that needs to be used to import the report into the official tax rporting system." +VMEXT_EU_RECAP_REPORTSETTINGS="General Settings for the EU Sales Report" VMEXT_EU_RECAP_FREQUENCY="Frequency of the Report" -VMEXT_EU_RECAP_FREQUENCY_DESC="Select how often you are required to submit a recapitulative report. Only time periods for the selected frequency will be offered in the report page." +VMEXT_EU_RECAP_FREQUENCY_DESC="Select how often you are required to submit a EU Sales Report. Only time periods for the selected frequency will be offered in the report page." VMEXT_EU_RECAP_FREQUENCY_MONTHLY="Monthly" VMEXT_EU_RECAP_FREQUENCY_QUARTERLY="Quarterly" VMEXT_EU_RECAP_FREQUENCY_YEARLY="Yearly" VMEXT_EU_RECAP_COUNTRIES="Countries" -VMEXT_EU_RECAP_COUNTRIES_DESC="Only orders by customers from of the selected countries will be included in the recapitulative statement. Typically, all EU countries except your home country should be selected." +VMEXT_EU_RECAP_COUNTRIES_DESC="Only orders by customers from of the selected countries will be included in the EU Sales Report. Typically, all EU countries except your home country should be selected." VMEXT_EU_RECAP_TAXATION_MOMENT="Moment of taxation" VMEXT_EU_RECAP_TAXATION_MOMENT_DESC="Select the point in time when a new order actually causes a tax liability." VMEXT_EU_RECAP_TAXATION_MOMENT_PLACEMENT="When the order is initially created in VirtueMart." @@ -40,8 +53,11 @@ VMEXT_EU_RECAP_TAXATION_MOMENT_STATUSCHANGE="When the order is first changed to VMEXT_EU_RECAP_TAXATION_MOMENT_PAYMENT="When payment is made." VMEXT_EU_RECAP_TAXATION_MOMENT_INVOICE="When the invoice is created." -VMEXT_EU_RECAP_TAXNR="Your tax number" -VMEXT_EU_RECAP_TAXNR_DESC="When exporting to xml or csv, some countries require the tax number of the vendor to be included in the file. If this is the case for your tax authority, please enter your tax number here so the generated files can be automatically processed by your tax authority." +VMEXT_EU_RECAP_VENDOR_VATID="Your EU VAT ID number" +VMEXT_EU_RECAP_VENDOR_VATID_DESC="When exporting to xml or csv, some countries require the EU VAT ID number of the vendor to be included in the file. If this is the case for your tax authority, please enter your tax number here so the generated files can be automatically processed by your tax authority." +VMEXT_EU_RECAP_TAXNR="Your local tax number" +VMEXT_EU_RECAP_TAXNR_DESC="When exporting to xml or csv, some countries require the local tax number of the vendor to be included in the file. If this is the case for your tax authority, please enter your tax number here so the generated files can be automatically processed by your tax authority." + VMEXT_EU_RECAP_VATID="EU VAT ID" VMEXT_EU_RECAP_COUNTRYCODE="Billing Country" @@ -49,4 +65,6 @@ VMEXT_EU_RECAP_COMPANY="Company Name" VMEXT_EU_RECAP_NAME="Person" VMEXT_EU_RECAP_ORDERS="Orders" VMEXT_EU_RECAP_ORDERTOTALS="Total revenue" -VMEXT_EU_RECAP_ORDERTAXES="Taxes" \ No newline at end of file +VMEXT_EU_RECAP_ORDERTAXES="Taxes" + +VMEXT_EU_RECAP_CANCELLED="EU Sales Report settings cancelled." \ No newline at end of file diff --git a/models/eurecap.php b/models/eurecap.php index 0d6343be7879cd3574c53fc8086d86a26d3666b0..81db64db09ec9629c89200c782be9137bbfdbc31 100644 --- a/models/eurecap.php +++ b/models/eurecap.php @@ -30,6 +30,8 @@ class VirtuemartModelEuRecap extends VmModel { public $from_date = ''; public $until_date = ''; + public $from = ''; + public $until = ''; protected $frequency = 3; function __construct () { @@ -70,12 +72,12 @@ class VirtuemartModelEuRecap extends VmModel { */ function setPeriod ($year, $month, $frequency) { $this->setFrequency($frequency); - - $fromtime = mktime(0,0,0, $month, 1, $year); -// JFactory::getApplication()->enqueueMessage("<pre>year: $year, month: $month, frequency: $frequency, fromtime: ".print_r($fromtime,1)."</pre>", 'message'); - $this->from_date = date ('Y-m-d', $fromtime); - $this->until_date = date ('Y-m-d', strtotime('+'.$this->frequency.' months -1 day', $fromtime)); + $this->from = mktime(0,0,0, $month, 1, $year); + $this->until = strtotime('+'.$this->frequency.' months -1 day', $this->from); + + $this->from_date = date ('Y-m-d', $this->from); + $this->until_date = date ('Y-m-d', $this->until); $config = JFactory::getConfig(); $siteOffset = $config->get('offset'); @@ -95,13 +97,13 @@ class VirtuemartModelEuRecap extends VmModel { } $settingsModel = VmModel::getModel("eurecap_config"); $settings = $settingsModel->getConfig(); - + $freq = $settings['frequency']; $month = floor( (date("m")-1)/$freq)*$freq+1; $year = vRequest::getVar ('year', date("Y")); $month = vRequest::getVar ('month', $month); $this->setPeriod($year, $month, $freq); - + $mainTable = "`#__virtuemart_orders` AS `o`"; $joins = array(); $joins[] = "LEFT JOIN `#__virtuemart_order_userinfos` AS `ui` ON (`o`.`virtuemart_order_id` = `ui`.`virtuemart_order_id` )"; @@ -109,7 +111,7 @@ class VirtuemartModelEuRecap extends VmModel { $vatfields = array(); foreach ($settings['vatid_userfield'] as $vatfield) { - $vatfields[] = "`$vatfield`"; + $vatfields[] = "`ui`.`$vatfield`"; } $vatfields[] = "''"; // <= To make sure we have at least one entry! $select = array(); @@ -122,68 +124,71 @@ class VirtuemartModelEuRecap extends VmModel { $select[] = "`first_name`"; $select[] = "`last_name`"; $select[] = "`ctr`.`country_2_code` AS `countrycode`"; - + $select[] = 'SUM( `order_total` ) AS `sum_order_total`'; - - $select[] = 'SUM( `order_billTax` ) AS `sum_order_tax`'; - - + + $select[] = 'SUM( `order_tax` ) AS `sum_order_tax`'; + + $where = array(); $where[] = $vatidexpr . " <> ''"; - if ($settings['only_untaxed']>0) { + if ($settings['include_free']==0) { + $where[] = "`o`.`order_total` > 0"; + } + if ($settings['include_taxed_orders']==0) { $where[] = "`o`.`order_tax` = 0"; } $where[] = '`ui`.`address_type` = "BT"'; - + // Order status: $ostatus = array(); foreach ($settings['order_status'] as $s) { - $ostatus[] = '`order_status` = "' . $s . '"'; + $ostatus[] = '`o`.`order_status` = "' . $s . '"'; } if ($ostatus) { $where[] = "(" . join(" OR ", $ostatus) . ")"; } - + // Countries: - if ($settings['countries']) { + if (!empty($settings['countries'])) { $where[] = '`ui`.`virtuemart_country_id` IN (' . join(",", $settings['countries']) . ')'; } - + // Shopper group: if ($settings['shopper_groups']) { -// $where[] = +// $where[] = } - + // TODO: Handle vendorId if (VmConfig::get ('multix', 'none') != 'none') { if ($vendorId != 0) { $where[] = '`o`.`virtuemart_vendor_id` = "' . $vendorId . '" '; } } - + // TODO: Handle creation date! switch($settings['taxation_moment']) { case 'status': // TODO: Handle first status change: $tax_moment = "`o`.`created_on`"; -JFactory::getApplication()->enqueueMessage("Taxation moment 'First status change to any of the selected statuses' not yet implemented", 'message'); + JFactory::getApplication()->enqueueMessage("Taxation moment 'First status change to any of the selected statuses' not yet implemented", 'warning'); break; case 'payment': // TODO: Handle payment: $tax_moment = "`o`.`created_on`"; -// 'o.virtuemart_paymentmethod_id' -JFactory::getApplication()->enqueueMessage("Taxation moment 'When payment is made' not yet implemented", 'message'); + // 'o.virtuemart_paymentmethod_id' + JFactory::getApplication()->enqueueMessage("Taxation moment 'When payment is made' not yet implemented", 'warning'); break; case 'invoice': $tax_moment = "`inv`.`created_on`"; - $joins[] = "LEFT JOIN `#__virtuemart_invoices` AS `inv` ON ( `o`.`virtuemart_order_id` = `inv.virtuemart_order_id` )"; + $joins[] = "LEFT JOIN `#__virtuemart_invoices` AS `inv` ON ( `o`.`virtuemart_order_id` = `inv`.`virtuemart_order_id` )"; break; case 'placement': default: $tax_moment = "`o`.`created_on`"; break; } - + $where[] = ' DATE( ' . $tax_moment . ' ) BETWEEN "' . $this->from_date . '" AND "' . $this->until_date . '" '; $selectString = join(', ', $select) . ' FROM ' . $mainTable; @@ -191,188 +196,11 @@ JFactory::getApplication()->enqueueMessage("Taxation moment 'When payment is mad $whereString = 'WHERE ' . join(' AND ', $where); $groupBy = "GROUP BY `vatid`"; $orderBy = $this->_getOrdering (); - - return $this->exeSortSearchListQuery (1, $selectString, $joinedTables, $whereString, $groupBy, $orderBy); - } - - function getRevenue ($cache = 0) { -return null; - $user = JFactory::getUser(); - if($user->authorise('core.admin', 'com_virtuemart') or $user->authorise('core.manager', 'com_virtuemart')){ - $vendorId = vRequest::getInt('virtuemart_vendor_id'); - } else { - $vendorId = VmConfig::isSuperVendor(); - } - - $orderstates = vRequest::getVar ('order_status_code', array('C','S')); - $intervals = vRequest::getCmd ('intervals', 'day'); - $filterorders = vRequest::getvar ('filter_order', 'intervals'); - $orderdir = (vRequest::getCmd ('filter_order_Dir', NULL) == 'desc') ? 'desc' : ''; - $virtuemart_product_id = vRequest::getInt ('virtuemart_product_id', FALSE); - - if($cache){ - $c = JFactory::getCache ('com_virtuemart_revenue'); - $c->setCaching (1); - $c->setLifeTime($cache); - return $c->call (array('VirtuemartModelReport', 'getRevenueDiag'),$vendorId,$orderstates,$intervals,$filterorders,$orderdir,$virtuemart_product_id,$this->from_date,$this->until_date); - } else { - return $this->getRevenueSortListOrderQuery ($vendorId,$orderstates,$intervals,$filterorders,$orderdir,$virtuemart_product_id); - } - - } - - function getRevenueSortListOrderQuery ($vendorId,$orderstates,$intervals,$filterorders,$orderdir,$virtuemart_product_id) { -return null; - $selectFields = array(); - $mainTable = ''; - $joinTables = array(); - $joinedTables = ''; - $where = array(); - - // group always by intervals (day,week, ... or ID) and set grouping and defaut ordering - switch ($intervals) { - - case 'day': - $this->intervals = 'DATE( o.created_on )'; - break; - case 'week': - $this->intervals = 'WEEK( o.created_on )'; - break; - case 'month': - $this->intervals = 'MONTH( o.created_on )'; - break; - case 'year': - $this->intervals = 'YEAR( o.created_on )'; - break; - default: - // invidual grouping - $this->intervals = 'o.created_on'; - break; - } -// if(!empty($this->intervals)){ -// $orderBy = $this->_getOrdering('o.`created_on`'); -// } - $selectFields['intervals'] = $this->intervals . ' AS intervals, CAST( o.`created_on` AS DATE ) AS created_on'; - - if($intervals=='product_s'){ - - $selectFields[] = '`order_item_name`'; - $selectFields[] = '`virtuemart_product_id`'; - $groupBy = 'GROUP BY `virtuemart_product_id` '; - } else { - $groupBy = 'GROUP BY intervals '; - } - - //$selectFields[] = 'COUNT(virtuemart_order_id) as number_of_orders'; - //with tax => brutto - //$selectFields[] = 'SUM(product_subtotal_with_tax) as order_total'; - - //without tax => netto - //$selectFields[] = 'SUM(product_item_price) as order_subtotal'; - $selectFields[] = 'SUM(product_discountedPriceWithoutTax * product_quantity) as order_subtotal_netto'; - $selectFields[] = 'SUM(product_subtotal_with_tax) as order_subtotal_brutto'; - - $this->dates = ' DATE( o.created_on ) BETWEEN "' . $this->from_date . '" AND "' . $this->until_date . '" '; - - $statusList = array(); - // Filter by status - if ($orderstates) { - $query = 'SELECT `order_status_code` - FROM `#__virtuemart_orderstates` - WHERE published=1 '; - $db = JFactory::getDBO(); - $db->setQuery ($query); - $list = $db->loadColumn (); - foreach ($orderstates as $val) { - if (in_array ($val, $list)) { - $statusList[] = '`i`.`order_status` = "' . $val . '"'; - } - } - if ($statusList) { - $where[] = '(' . implode (' OR ', $statusList) . ')'; - } - } - //getRevenue - // select wich table to order sum ordered - - switch ($filterorders) { - - case 'o.virtuemart_order_id': - $orderBy = ' ORDER BY count_order_id ' . $orderdir; - $groupBy = 'GROUP BY intervals '; - break; - case 'product_quantity' : - // GROUP BY product_quantity, intervals - // ORDER BY `product_quantity` ASC - // TODO grouping and ordering - $orderBy = ' ORDER BY product_quantity ' . $orderdir; - $groupBy = 'GROUP BY intervals '; - - //$selectFields['intervals'] = $this->intervals.' AS intervals, i.`created_on` '; - break; - case 'o.order_subtotal' : - $orderBy = ' ORDER BY order_subtotal'; - break; - //getOrderItemsSumGrouped($this->intervals , $filterorders); - break; - default: - // invidual grouping - $orderBy = $this->_getOrdering (); - vmdebug ('default case', $orderBy); - //$this->intervals= '`o`.`created_on`'; -// $orderBy = ' ORDER BY '.$filterorders.' '.$orderdir; - break; - } - - $selectFields[] = 'COUNT(DISTINCT o.virtuemart_order_id) as count_order_id'; - $selectFields[] = 'SUM(product_quantity) as product_quantity'; - - $mainTable = '`#__virtuemart_order_items` as i'; - - $joinTables['orders'] = ' LEFT JOIN `#__virtuemart_orders` as o ON o.virtuemart_order_id=i.virtuemart_order_id '; - - if (count ($selectFields) > 0) { - - $select = implode (', ', $selectFields) . ' FROM ' . $mainTable; - //$selectFindRows = 'SELECT COUNT(*) FROM '.$mainTable; - if (count ($joinTables) > 0) { - foreach ($joinTables as $table) { - $joinedTables .= $table; - } - } - } - else { - vmError ('No select fields given in getRevenueSortListOrderQuery', 'No select fields given'); - return FALSE; - } - - - if ($virtuemart_product_id) { - $where[] = 'i.virtuemart_product_id = "' . $virtuemart_product_id . '" '; - } - - if (VmConfig::get ('multix', 'none') != 'none') { - if ($vendorId != 0) { - $where[] = 'i.virtuemart_vendor_id = "' . $vendorId . '" '; - } - } - if (count ($where) > 0) { - $this->whereItem = ' WHERE ' . implode (' AND ', $where) . ' AND '; - } - else { - $this->whereItem = ' WHERE '; - } - -// $this->whereItem; - /* WHERE differences with orders and items from orders are only date periods and ordering */ - $whereString = $this->whereItem . $this->dates; - vmdebug('getRevenueSortListOrderQuery '.$select,$whereString); - return $this->exeSortSearchListQuery (1, $select, $joinedTables, $whereString, $groupBy, $orderBy); + return $this->exeSortSearchListQuery (1, $selectString, $joinedTables, $whereString, $groupBy, $orderBy); } - public function renderMonthSelectList ($frequency, $selected='') { $vals = array(); switch ($frequency) { @@ -390,14 +218,14 @@ return null; $vals[11] = vmText::_('November'); $vals[12] = vmText::_('December'); break; - + case 3: // quartely $vals[1] = vmText::_('First Quarter'); $vals[3] = vmText::_('Second Quarter'); $vals[6] = vmText::_('Third Quarter'); $vals[9] = vmText::_('Forth Quarter'); break; - + case 12: // yearly $vals[1] = vmText::_('Year'); break; diff --git a/models/eurecap_config.php b/models/eurecap_config.php index 62a392cfbc3dd27d1ece675a44c7d49e8bdf587c..427c044374c4e7dfa43b5aded1bf6b9a99d6505a 100644 --- a/models/eurecap_config.php +++ b/models/eurecap_config.php @@ -36,8 +36,58 @@ class VirtuemartModelEuRecap_config extends VmModel { parent::__construct (); } + /** + * Process the passed settings array and load all missing values from the xml file + */ + function loadDefaults($settings_str) { + $path = VMPATH_ROOT .DS. 'plugins' .DS. 'vmextended' . DS . 'eurecap' . DS . 'eurecap' . '.xml'; + if(!defined('VM_VERSION') or VM_VERSION < 3){ + if (!class_exists('vmParameters')) + require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'parameterparser.php'); + $parameters = new vmParameters($settings_str, 'eurecap', 'plugin', 'vmextended'); +// $parameters->loadString($settings_str); + + $settings = array(); + // The getParams returns the rendered representation, but also the value, including the default given in the XML. + // AFAICS, this is the only way to correctly handle the default, apart from manually parsing the xml file. + foreach ($parameters->getParams() as $param) { + if (!empty($param[5])) + $settings[$param[5]] = $param[4]; + } + + } else { + // VM 3.x uses JForm + $defaults = array(); + + $registry = new JRegistry; + $registry->loadString($settings_str); + // Take the settings and load all missing values from the defaults in the xml file: + $settings = $registry->toArray(); + + $form = vmPlugin::loadConfigForm($path, 'eurecap'); + $form->bind(array('settings'=>$settings)); + $fieldSets = $form->getFieldsets(); + foreach ($fieldSets as $name => $fieldSet) { + foreach ($form->getFieldset($name) as $field) { + $fieldname = (string)$field->fieldname; + $settings[$fieldname] = $field->value; + } + } + } + // Manually convert all default values for list params to lists (not handled automatically) + if (!is_array($settings['order_status'])) + $settings['order_status'] = array_filter(explode(',', $settings['order_status'])); + if (!is_array($settings['vatid_userfield'])) + $settings['vatid_userfield'] = array_filter(explode(',', $settings['vatid_userfield'])); + if (!is_array($settings['countries'])) + $settings['countries'] = array_filter(explode(',', $settings['countries'])); + + return $settings; + } + function getConfig() { if (!$this->_settings) { + $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('custom_data')) @@ -48,19 +98,23 @@ class VirtuemartModelEuRecap_config extends VmModel { $db->setQuery($query); $config_str = $db->loadResult(); - $registry = new JRegistry; - $registry->loadString($config_str); - $this->_settings = $registry->toArray(); + // Take the settings and load all missing values from the defaults in the xml file: + $this->_settings = $this->loadDefaults($config_str); } return $this->_settings; } function saveConfig($data) { - $params = array_merge ($this->getConfig(), $data['settings']); - $this->_settings = $params; + $settings = array(); + if (isset($data['params'])) + $settings = $data['params']; + if (isset($data['settings'])) + $settings = $data['settings']; + $settings = array_merge ($this->getConfig(), $settings); + $this->_settings = $settings; $registry = new JRegistry(); - $registry->loadArray($params); + $registry->loadArray($settings); $db = JFactory::getDbo(); $query = $db->getQuery(true) diff --git a/releases/plg_vmextended_eurecap_v0.1.zip b/releases/plg_vmextended_eurecap_v0.1.zip new file mode 100644 index 0000000000000000000000000000000000000000..7e4d929a142a575b91713fd855419915ec6142f3 Binary files /dev/null and b/releases/plg_vmextended_eurecap_v0.1.zip differ diff --git a/views/eurecap/tmpl/default.php b/views/eurecap/tmpl/default.php index 8ef017b765ec81865742742d78de6674fde019c9..b9e5845ca5b823a02afe826e0103d8ba0335206a 100644 --- a/views/eurecap/tmpl/default.php +++ b/views/eurecap/tmpl/default.php @@ -20,6 +20,11 @@ if( !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not AdminUIHelper::startAdminArea($this); JHtml::_('behavior.framework', true); +if (!class_exists('CurrencyDisplay')) + require(VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php'); +$myCurrencyDisplay = CurrencyDisplay::getInstance(); + + ?> <form action="index.php" method="post" name="adminForm" id="adminForm"> <div id="header"> @@ -29,9 +34,9 @@ JHtml::_('behavior.framework', true); <tr> <td align="left" width="100%"> <?php if ($this->frequency<12) { - echo vmText::_('VMEXT_EU_RECAP_LIST_MONTH') . $this->lists['month_list']; + echo vmText::_('VMEXT_EU_RECAP_LIST_MONTH') . $this->period_lists['month_list']; } ?> - <?php echo vmText::_('VMEXT_EU_RECAP_LIST_YEAR') . $this->lists['year_list']; + <?php echo vmText::_('VMEXT_EU_RECAP_LIST_YEAR') . $this->period_lists['year_list']; if(VmConfig::get('multix','none')!='none'){ $vendorId = vRequest::getInt('virtuemart_vendor_id',1); @@ -44,7 +49,7 @@ JHtml::_('behavior.framework', true); </table> </div> <div id="resultscounter"> - <?php echo $this->pagination->getResultsCounter();?> + <?php if ($this->pagination) echo $this->pagination->getResultsCounter();?> </div> </div> @@ -85,7 +90,13 @@ JHtml::_('behavior.framework', true); <td align="center"> <?php echo $r['vatid']; ?> </td> - <td align="center"> + <?php + $vatidcc = substr(trim($r['vatid']), 0, 2); + if ($vatidcc=="EL") $vatidcc="GR"; + if ($vatidcc=="UK") $vatidcc="GB"; + $countrymatch = ($vatidcc == $r['countrycode']); + ?> + <td align="center" <?php if (!$countrymatch) { echo "style=\"background: #FFBFBF;\""; }; ?>> <?php echo $r['countrycode'];?> </td> <td align="left"> @@ -117,10 +128,10 @@ JHtml::_('behavior.framework', true); ?> </td> <td align="right"> - <?php echo $r['sum_order_total'];?> + <?php echo $myCurrencyDisplay->priceDisplay($r['sum_order_total']); ?> </td> <td align="right"> - <?php echo $r['sum_order_tax'];?> + <?php echo $myCurrencyDisplay->priceDisplay($r['sum_order_tax']); ?> </td> </tr> <?php @@ -131,7 +142,7 @@ JHtml::_('behavior.framework', true); <tfoot> <tr> <td colspan="10"> - <?php echo $this->pagination->getListFooter(); ?> + <?php if ($this->pagination) echo $this->pagination->getListFooter(); ?> </td> </tr> </tfoot> diff --git a/views/eurecap/tmpl/export.php b/views/eurecap/tmpl/export.php new file mode 100644 index 0000000000000000000000000000000000000000..3ccd555b5241e84f7aadb43c563b60964355b21a --- /dev/null +++ b/views/eurecap/tmpl/export.php @@ -0,0 +1,20 @@ +<?php +if( !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); + +/** +* +* @version $Id$ +* @package VirtueMart +* @subpackage Report +* @copyright Copyright (C) Open Tools, Reinhold Kainhofer +* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php +* VirtueMart is free software. This version may have been modified pursuant +* to the GNU General Public License, and as distributed it includes or +* is derivative of works licensed under the GNU General Public License or +* other free or open source software licenses. +* +* http://www.open-tools.net/ +*/ + +// Load the sub-template as selected in the export format setting: +echo $this->loadTemplate($this->export_format); diff --git a/views/eurecap/tmpl/export_at_xml.php b/views/eurecap/tmpl/export_at_xml.php new file mode 100644 index 0000000000000000000000000000000000000000..2d51b62684ac7bd7fdc0c43f0b99155063483a03 --- /dev/null +++ b/views/eurecap/tmpl/export_at_xml.php @@ -0,0 +1,65 @@ +<?php +if( !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); + +/** +* +* @version $Id$ +* @package VirtueMart +* @subpackage Report +* @copyright Copyright (C) Open Tools, Reinhold Kainhofer +* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php +* VirtueMart is free software. This version may have been modified pursuant +* to the GNU General Public License, and as distributed it includes or +* is derivative of works licensed under the GNU General Public License or +* other free or open source software licenses. +* +* http://www.open-tools.net/ +*/ + +$from_month=date("Y-m", $this->from); +$until_month=date("Y-m", $this->until); +$fastnr = preg_replace('/[^0-9]/', '', $this->settings['taxnr']); + +header("Content-Type: text/xml"); +header("Content-Disposition: attachment; filename=\"EU_Zusammenfassende_Meldung_${from_month}_${until_month}.AT.xml\""); + +?><?xml version="1.0" encoding="iso-8859-1"?> +<!-- Zusammenfassende Meldung - Stand: 10.01.2013 --> +<ERKLAERUNGS_UEBERMITTLUNG> + <INFO_DATEN> + <ART_IDENTIFIKATIONSBEGRIFF>FASTNR</ART_IDENTIFIKATIONSBEGRIFF> + <IDENTIFIKATIONSBEGRIFF><?php echo $fastnr; ?></IDENTIFIKATIONSBEGRIFF> + <PAKET_NR><?php echo rand(1, 999999999);?></PAKET_NR> + <DATUM_ERSTELLUNG type="datum"><?php echo date("Y-m-d"); ?></DATUM_ERSTELLUNG> + <UHRZEIT_ERSTELLUNG type="uhrzeit"><?php echo date("H:i:s"); ?></UHRZEIT_ERSTELLUNG> + <ANZAHL_ERKLAERUNGEN>1</ANZAHL_ERKLAERUNGEN> + </INFO_DATEN> + <ERKLAERUNG art="U13"> + <SATZNR><?php echo rand(1, 999999999);?></SATZNR> + <ALLGEMEINE_DATEN> + <ANBRINGEN>U13</ANBRINGEN> + <ZRVON type="jahrmonat"><?php echo $from_month; ?></ZRVON> + <ZRBIS type="jahrmonat"><?php echo $until_month; ?></ZRBIS> + <FASTNR><?php echo $fastnr; ?></FASTNR> + <KUNDENINFO></KUNDENINFO> + </ALLGEMEINE_DATEN> +<?php +foreach ($this->report as $r) { + $vatid = preg_replace('/[^A-Z0-9]/', '', strtoupper(trim($r['vatid']))); +?> + <ZM> + <UID_MS><?php echo $vatid; ?></UID_MS> + <SUM_BGL type="kz"><?php echo $r['sum_order_total']; ?></SUM_BGL> +<?php // <DREIECK>0</DREIECK> ?> + <SOLEI>1</SOLEI> + </ZM> +<?php +} +?> +<?php /* + <GESAMTRUECKZIEHUNG> + <GESAMTRUECK>J</GESAMTRUECK> + </GESAMTRUECKZIEHUNG> +*/ ?> + </ERKLAERUNG> +</ERKLAERUNGS_UEBERMITTLUNG> diff --git a/views/eurecap/tmpl/export_de_csv.php b/views/eurecap/tmpl/export_de_csv.php new file mode 100644 index 0000000000000000000000000000000000000000..5c35ee7fec6f220bdcd4579bf8ad9146ec42ad83 --- /dev/null +++ b/views/eurecap/tmpl/export_de_csv.php @@ -0,0 +1,33 @@ +<?php +if( !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); + +/** +* +* @version $Id$ +* @package VirtueMart +* @subpackage Report +* @copyright Copyright (C) Open Tools, Reinhold Kainhofer +* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php +* VirtueMart is free software. This version may have been modified pursuant +* to the GNU General Public License, and as distributed it includes or +* is derivative of works licensed under the GNU General Public License or +* other free or open source software licenses. +* +* http://www.open-tools.net/ +*/ + +$from_month=date("Y-m", $this->from); +$until_month=date("Y-m", $this->until); + + +header("Content-Type: text/csv"); +header("Content-Disposition: attachment; filename=\"EU_Zusammenfassende_Meldung_${from_month}_${until_month}.DE.csv\""); +?>Laenderkennzeichen,USt-IdNr.,Betrag(EUR),Art der Leistung +<?php +foreach ($this->report as $r) { + $vatid = preg_replace('/[^A-Z0-9]/', '', strtoupper(trim($r['vatid']))); + $vatidcc = substr($vatid, 0, 2); + // TODO: Check whether $vatidcc is a valid country code. If not, use $r['countrycode'] and interpret $vatid as the rest + echo $vatidcc . ',' . substr($vatid, 2) . ',' . $r['sum_order_total'] . ',S +'; +} diff --git a/views/eurecap/tmpl/export_full.php b/views/eurecap/tmpl/export_full.php new file mode 100644 index 0000000000000000000000000000000000000000..dc7e209a9f31e5413278fc373f3966ce44eda121 --- /dev/null +++ b/views/eurecap/tmpl/export_full.php @@ -0,0 +1,33 @@ +<?php +if( !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); + +/** +* +* @version $Id$ +* @package VirtueMart +* @subpackage Report +* @copyright Copyright (C) Open Tools, Reinhold Kainhofer +* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php +* VirtueMart is free software. This version may have been modified pursuant +* to the GNU General Public License, and as distributed it includes or +* is derivative of works licensed under the GNU General Public License or +* other free or open source software licenses. +* +* http://www.open-tools.net/ +*/ + +$from_month=date("Y-m", $this->from); +$until_month=date("Y-m", $this->until); + +header("Content-Type: text/csv"); +header("Content-Disposition: attachment; filename=\"EU_Recap_Statement_${from_month}_${until_month}.csv\""); + +$keys = array_keys($this->report[0]); +if ($this->report) { + echo '"' . join('","', $keys) . '" +'; +} +foreach ($this->report as $r) { + echo '"' . join('","', array_values($r)) . '" +'; +} diff --git a/views/eurecap/tmpl/settings.php b/views/eurecap/tmpl/settings.php index 601805342a1ede605facd1fb8ba9d939ae737fd6..66974ccfbd8842b971472909f83869779d981759 100644 --- a/views/eurecap/tmpl/settings.php +++ b/views/eurecap/tmpl/settings.php @@ -23,11 +23,16 @@ JHtml::_('behavior.framework', true); ?> <form name="adminForm" id="adminForm" method="post" action=""> + <?php AdminUIHelper::imitateTabs('start'); ?> <fieldset> <legend><?php echo vmText::_('VMEXT_EU_RECAP_SETTINGS_TITLE'); ?></legend> -<?php if ($this->config_form) { +<?php if (isset($this->config_form)) { + // VM 3 uses JForm and the formrenderer.php $form = $this->config_form; - include(VMPATH_ADMIN.DS.'fields'.DS.'formrenderer.php'); + include (VMPATH_ADMIN.DS.'fields'.DS.'formrenderer.php'); +} elseif ($this->config_params) { + // VM 2 uses vmParameters + echo $this->config_params->render(); } else { ?> <p><?php echo vmText::_('VMEXT_EU_RECAP_FORM_NOTFOUND'); ?></p> <?php @@ -35,6 +40,7 @@ JHtml::_('behavior.framework', true); ?> </fieldset> <?php echo $this->addStandardHiddenToForm(); ?> + <?php AdminUIHelper::imitateTabs('end'); ?> </form> diff --git a/views/eurecap/view.html.php b/views/eurecap/view.html.php index bb5373eb12e9442600badbb9ace60045e492e831..09d6ac1dc062f27ba683ef78142d690ee7e9e79e 100644 --- a/views/eurecap/view.html.php +++ b/views/eurecap/view.html.php @@ -48,8 +48,6 @@ class VirtuemartViewEuRecap extends VmViewAdmin { if (!class_exists('VmHTML')) require(VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php'); - if (!class_exists('CurrencyDisplay')) - require(VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php'); $model = VmModel::getModel(); $this->addStandardDefaultViewLists($model); @@ -57,16 +55,21 @@ class VirtuemartViewEuRecap extends VmViewAdmin { vRequest::setvar('task',''); $this->SetViewTitle('EU_RECAP'); - $myCurrencyDisplay = CurrencyDisplay::getInstance(); - $layoutName = vRequest::getCmd('layout', 'default'); if ($layoutName == 'settings') { JToolBarHelper::divider(); JToolBarHelper::save(); JToolBarHelper::apply(); JToolBarHelper::cancel(); - $form = $this->renderPluginSettings(); - $this->assignRef('config_form', $form); + if(!defined('VM_VERSION') or VM_VERSION < 3){ + // VM 2.x uses vmParameters + $form = $this->renderPluginSettingsVM2(); + $this->assignRef('config_params', $form); + } else { + // VM 3.x uses JForm + $form = $this->renderPluginSettingsVM3(); + $this->assignRef('config_form', $form); + } // TODO } else { $this->setupListView($model); @@ -75,50 +78,81 @@ class VirtuemartViewEuRecap extends VmViewAdmin { parent::display($tpl); } - function setupListView ($model) { - JToolBarHelper::custom('settings', 'options', 'options','VMEXT_EU_RECAP_SETTINGS', false); - JToolBarHelper::custom('check_eu_vatid', 'recheck', 'recheck', 'VMEXT_EU_RECAP_RECHECK_EUVATID', true); - JToolBarHelper::custom('export', 'export', 'export', 'VMEXT_EU_RECAP_EXPORT', false); + /** + * Copied from VmView(Admin). Only change is the inserted $name in JText::_('COM_VIRTUEMART_'. $name . '_' . $task) + */ + function SetViewTitle($name ='', $msg ='',$icon ='') { + + $view = JRequest::getWord('view', JRequest::getWord('controller')); + if ($name == '') + $name = strtoupper($view); + if ($icon == '') + $icon = strtolower($view); + if (!$task = JRequest::getWord('task')) + $task = 'list'; + + if (!empty($msg)) { + $msg = ' <span style="color: #666666; font-size: large;">' . $msg . '</span>'; + } + $viewText = JText::_('COM_VIRTUEMART_' . strtoupper($name)); + + $taskName = ' <small><small>[ ' . JText::_('COM_VIRTUEMART_'. $name . '_' . $task) . ' ]</small></small>'; + + JToolBarHelper::title($viewText . ' ' . $taskName . $msg, 'head vm_' . $icon . '_48'); + $this->assignRef('viewName',$viewText); //was $viewName? + $app = JFactory::getApplication(); + $doc = JFactory::getDocument(); + $doc->setTitle($app->getCfg('sitename'). ' - ' .JText::_('JADMINISTRATION').' - '.strip_tags($msg)); + } + + function setupListView ($model) { $month = vRequest::getVar('month', '1'); $year = vRequest::getVar('year', date("Y")); - + $settingsModel = VmModel::getModel("eurecap_config"); $settings = $settingsModel->getConfig(); + + $bar = JToolbar::getInstance('toolbar'); + JToolBarHelper::custom('settings', 'options', 'options','VMEXT_EU_RECAP_SETTINGS', false); +// JToolBarHelper::custom('check_eu_vatid', 'recheck', 'recheck', 'VMEXT_EU_RECAP_RECHECK_EUVATID', true); +// $bar->appendButton('Link', 'export', 'VMEXT_EU_RECAP_FULLEXPORT', 'index.php?option=com_virtuemart&view=eurecap&task=export&format=raw&layout=export_full&month='.$month.'&year='.$year); + $bar->appendButton('Link', 'export', 'VMEXT_EU_RECAP_EXPORT_TB_' . $settings['export_format'], 'index.php?option=com_virtuemart&view=eurecap&task=export&format=raw&layout=export&month='.$month.'&year='.$year); + + $this->frequency = $settings['frequency']; - $this->lists['month_list'] = $model->renderMonthSelectList($this->frequency, $month); - $this->lists['year_list'] = $model->renderYearSelectList($year); + $period_list = array(); + $period_list['month_list'] = $model->renderMonthSelectList($this->frequency, $month); + $period_list['year_list'] = $model->renderYearSelectList($year); + $this->assignRef('period_lists', $period_list); $this->assignRef('from_period', $model->from_date); $this->assignRef('until_period', $model->until_date); - $myCurrencyDisplay = CurrencyDisplay::getInstance(); - + $this->assignRef('from', $model->from); + $this->assignRef('until', $model->until); + $this->addStandardDefaultViewLists($model); $euIntracommunityRevenue = $model->getEuRecap(); - foreach ($euIntracommunityRevenue as &$r) { - $r['sum_order_total'] = $myCurrencyDisplay->priceDisplay($r['sum_order_total']); - $r['sum_order_tax'] = $myCurrencyDisplay->priceDisplay($r['sum_order_tax']); - } $this->assignRef('report', $euIntracommunityRevenue); + + $this->assignRef('export_format', $settings['export_format']); $pagination = $model->getPagination(); $this->assignRef('pagination', $pagination); - + } - function renderPluginSettings(){ + function renderPluginSettingsVM3(){ if (!class_exists('vmExtendedPlugin')) require(VMPATH_PLUGINLIBS . DS . 'vmextendedplugin.php'); JForm::addFieldPath(VMPATH_ADMIN . DS . 'fields'); $path = VMPATH_ROOT .DS. 'plugins' .DS. 'vmextended' . DS . $this->getName() . DS . $this->getName() . '.xml'; - // Get the payment XML. - $formFile = vRequest::filterPath( $path ); - if (file_exists($formFile)){ + if (file_exists($path)){ - $form = vmPlugin::loadConfigForm($formFile, $this->getName()); + $form = vmPlugin::loadConfigForm($path, $this->getName()); // load config $eurecapSettingsModel = VmModel::getModel("eurecap_config"); @@ -126,14 +160,22 @@ class VirtuemartViewEuRecap extends VmViewAdmin { $form->bind(array('settings'=>$settings)); } else { $form = false; - vmdebug('renderUserfieldPlugin could not find xml for ' . $this->getName() . ' at ' . $path); + vmdebug('renderPluginSettingsVM3: Unable to find xml for ' . $this->getName() . ' at ' . $path); } - //vmdebug('renderUserfieldPlugin ',$this->userField->form); return $form; } + function renderPluginSettingsVM2(){ + if (!class_exists('vmParameters')) + require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'parameterparser.php'); + // load config + $eurecapSettingsModel = VmModel::getModel("eurecap_config"); + $settings = $eurecapSettingsModel->getConfig(); + $parameters = new vmParameters($settings, 'eurecap', 'plugin', 'vmextended'); + return $parameters; + } } diff --git a/views/eurecap/view.raw.php b/views/eurecap/view.raw.php new file mode 100644 index 0000000000000000000000000000000000000000..e6d9de8ba9c595352b9761335fdee33fa6c5254a --- /dev/null +++ b/views/eurecap/view.raw.php @@ -0,0 +1,73 @@ +<?php +if( !defined( '_JEXEC' ) ) die('Restricted access'); + +/** +* +* @version $Id$ +* @package VirtueMart +* @subpackage EU Recapitulative Statement +* @copyright Copyright (C) Open Tools, Reinhold Kainhofer +* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php +* VirtueMart is free software. This version may have been modified pursuant +* to the GNU General Public License, and as distributed it includes or +* is derivative of works licensed under the GNU General Public License or +* other free or open source software licenses. +*/ + +if(!defined('VM_VERSION') or VM_VERSION < 3){ + // VM2 has class VmView instead of VmViewAdmin: + if(!class_exists('VmView')) require(VMPATH_ADMIN.DS.'helpers'.DS.'vmview.php'); + class VmViewAdmin extends VmView {} +} else { + if(!class_exists('VmViewAdmin')) require(VMPATH_ADMIN.DS.'helpers'.DS.'vmviewadmin.php'); +} + +/** + * EU Recapitulative Statement View class + * + * @package VirtueMart + * @subpackage Report + * @author Open Tools + */ +class VirtuemartViewEuRecap extends VmViewAdmin { + function __construct(){ + parent::__construct(); + // Add the proper view pathes... + $this->_addPath('template', JPATH_PLUGINS.DS . 'vmextended' . DS . 'eurecap' . DS . 'views' . DS . $this->getName() . DS . 'tmpl'); + } + + /** + * Render the view + */ + function display($tpl = null){ + $model = VmModel::getModel(); + +// $layoutName = vRequest::getCmd('layout', 'export'); + + $month = vRequest::getVar('month', '1'); + $year = vRequest::getVar('year', date("Y")); + + $settingsModel = VmModel::getModel("eurecap_config"); + $settings = $settingsModel->getConfig(); + + $this->frequency = $settings['frequency']; + + $this->assignRef('from_period', $model->from_date); + $this->assignRef('until_period', $model->until_date); + + $this->assignRef('from', $model->from); + $this->assignRef('until', $model->until); + + $euIntracommunityRevenue = $model->getEuRecap(); + $this->assignRef('report', $euIntracommunityRevenue); + + $this->assignRef('settings', $settings); + + $this->assignRef('export_format', $settings['export_format']); + parent::display($tpl); + } + + + + +}