Browse files

Initial Import

  • Loading branch information...
0 parents commit 4d07773c0291f15ce7e6ef887b0ee3a216cf4ee4 @derklaus derklaus committed Jul 6, 2005
33 intranet-exchange-rate.info
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!-- Generated by the OpenACS Package Manager -->
+
+<package key="intranet-exchange-rate" url="http://openacs.org/repository/apm/packages/intranet-exchange-rate" type="apm_application">
+ <package-name>Project/Open Exchange-Rates</package-name>
+ <pretty-plural>Project/Open Exchange-Rates</pretty-plural>
+ <initial-install-p>f</initial-install-p>
+ <singleton-p>t</singleton-p>
+ <auto-mount>intranet-exchange-rate</auto-mount>
+
+ <version name="3.0.0.2.1" url="http://projop.dnsalias.com/download/apm/intranet-exchange-rate-3.0.0.2.1.apm">
+
+ <owner url="mailto:fraber@fraber.de">Frank Bergmann</owner>
+ <summary>Allows to maintain and query currency exchange rates</summary>
+ <vendor url="http://www.project-open.com/">]project-open[</vendor>
+ <description format="text/plain">
+ The module allows to maintain and query currency exchange rates.
+ Manual entries in the currency table are denormalized into a per-day
+ format in order to allow for fast SQL joins.
+ </description>
+
+ <provides url="intranet-exchange-rate" version="3.0.0"/>
+ <requires url="intranet-core" version="3.0.0"/>
+ <requires url="intranet-cost" version="3.0.0"/>
+
+ <callbacks>
+ </callbacks>
+ <parameters>
+ <!-- No version parameters -->
+ </parameters>
+
+ </version>
+</package>
110 sql/postgresql/intranet-exchange-rate-create.sql
@@ -0,0 +1,110 @@
+-- /packages/intranet-exchange-rate/sql/postgresql/intranet-exchange-rate-create.sql
+--
+-- ]project[ Exchange Rate Module
+-- Copyright (c) 2003-2004 Project/Open
+--
+-- All rights reserved. Please check
+-- http://www.project-open.com/license/ for details.
+-- @author frank.bergmann@project-open.com
+
+----------------------------------------------------
+-- Exchange rates of currencies with respect to the dollar
+
+create table im_exchange_rates (
+ day date
+ constraint im_exchange_rates_nn
+ not null,
+ currency char(3)
+ constraint im_exchange_rates_currency_fk
+ references currency_codes,
+ rate numeric(12,6),
+ manual_p char(1)
+ constraint im_exchange_rates_manual_ck
+ check (manual_p in ('t','f')),
+ constraint im_exchange_rates_pk
+ primary key (day,currency)
+);
+
+-- load data from 1999-01-01 until 2005-06-30
+\i intranet-exchange-rate-data.sql
+
+-- Populate im_exchange_rates for the next 5 years
+create or replace function inline_0 ()
+returns integer as '
+DECLARE
+ v_max integer;
+ v_i integer;
+ v_first_block_of_month integer;
+ v_rate numeric;
+ row RECORD;
+BEGIN
+ v_max := 365 * 5;
+ FOR row IN
+ select iso as currency
+ from currency_codes
+ where supported_p = ''t''
+ LOOP
+ -- get the latest manually entered exchange rate
+ select rate
+ into v_rate
+ from im_exchange_rates
+ where day = (
+ select max(day)
+ from im_exchange_rates
+ where currency = row.currency
+ )
+ and manual_p = ''t''
+ and currency = row.currency;
+
+ -- use the latest exchange rate for the next few years...
+ FOR v_i IN 0..v_max-1 LOOP
+
+ insert into im_exchange_rates (
+ day, rate, currency, manual_p
+ ) values (
+ to_date(''2005-07-01'',''YYYY-MM-DD'') + v_i,
+ v_rate, row.currency, ''f''
+ );
+
+ END LOOP;
+ END LOOP;
+ return 0;
+end;' language 'plpgsql';
+select inline_0 ();
+drop function inline_0 ();
+
+
+-- shortcut function to calculate the exchange rate for a
+-- specific day. This function is relatively slow and should
+-- NOT be used within a SQL query loop.
+-- Instead, it is useful as a shortcut to convert a single
+-- currency item.
+--
+create or replace function im_exchange_rate (date, char(3), char(3))
+returns float as '
+DECLARE
+ p_day alias for $1;
+ p_from_cur alias for $2;
+ p_to_cur alias for $3;
+
+ v_from_rate float;
+ v_to_rate float;
+BEGIN
+ -- Exchange rate of From-Currency to Dollar
+ select rate
+ into v_from_rate
+ from im_exchange_rates
+ where currency = p_from_cur
+ and day = p_day;
+
+ -- Exchange rate of Dollar to To-Currency
+ select rate
+ into v_to_rate
+ from im_exchange_rates
+ where currency = p_to_cur
+ and day = p_day;
+
+ return v_from_rate / v_to_rate;
+end;' language 'plpgsql';
+
+select im_exchange_rate(to_date('2005-07-01','YYYY-MM-DD'), 'EUR', 'USD');
9,535 sql/postgresql/intranet-exchange-rate-data.sql
9,535 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
12 sql/postgresql/intranet-exchange-rate-drop.sql
@@ -0,0 +1,12 @@
+-- /packages/intranet-hr/sql/oracle/intranet-hr-drop.sql
+--
+-- ]project[ Exchange Rate Module
+-- Copyright (c) 2003-2004 Project/Open
+--
+-- All rights reserved. Please check
+-- http://www.project-open.com/license/ for details.
+-- @author frank.bergmann@project-open.com
+
+
+drop table im_exchange_rates;
+
23 tcl/intranet-exchange-rate-procs-postgresql.xql
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!DOCTYPE queryset PUBLIC "-//OpenACS//DTD XQL 1.0//EN" "/usr/share/emacs/DTDs/xql.dtd">
+<!-- packages/intranet-exchange-rates/tcl/intranet-exchange-rate-procs-postgresql.xql -->
+<!-- @author (frank.bergmann@project-open.com) -->
+<!-- @creation-date 2005-06-09 -->
+<!-- @arch-tag 0cbec04f-a982-45e4-88b0-c5933aaa9b0b -->
+<!-- @cvs-id $Id$ -->
+
+<queryset>
+
+ <rdbms>
+ <type>postgresql</type>
+ <version>7.2</version>
+ </rdbms>
+
+ <fullquery name="im_exchange_rate_helper.exchange_rate">
+ <querytext>
+
+ select im_exchange_rate (:day, :from_cur, :to_cur);
+
+ </querytext>
+ </fullquery>
+</queryset>
29 tcl/intranet-exchange-rate-procs.tcl
@@ -0,0 +1,29 @@
+# /packages/intranet-exchange-rate/tcl/intranet-exchange-rate-procs.tcl
+#
+# Copyright (C) 2003-2004 Project/Open
+#
+# All rights reserved. Please check
+# http://www.project-open.com/license/ for details.
+
+ad_library {
+ Common procedures for Exchange Rates
+ @author frank.bergmann@project-open.com
+}
+
+# ----------------------------------------------------------------------
+# Exchange Rate from TCL
+# ----------------------------------------------------------------------
+
+ad_proc im_exchange_rate { day from_cur to_cur } {
+ Returns the exchange rate for a given day
+} {
+ return [im_exchange_rate_helper $day $from_cur $to_cur]
+}
+
+
+ad_proc im_exchange_rate_helper { day from_cur to_cur } {
+ Returns the exchange rate for a given day
+} {
+ return [db_exec_plsql exchange_rate {}]
+}
+
10 www/index.adp
@@ -0,0 +1,10 @@
+<master src="../../intranet-core/www/master">
+<property name="title">@page_title@</property>
+<property name="context_bar">@context_bar;noquote@</property>
+<property name="main_navbar_label">home</property>
+<property name="focus">@page_focus;noquote@</property>
+
+<h2>@page_title@</h2>
+
+<formtemplate id="exchange_rates"></formtemplate>
+
60 www/index.tcl
@@ -0,0 +1,60 @@
+# /packages/intranet-exchange-rate/www/index.tcl
+#
+# Copyright (C) 2003-2004 Project/Open
+#
+# All rights reserved. Please check
+# http://www.project-open.com/license/ for details.
+
+# ---------------------------------------------------------------
+# Page Contract
+# ---------------------------------------------------------------
+
+ad_page_contract {
+ Demo page to show indicators
+ @author Frank Bergmann (frank.bergmann@project-open.com)
+} {
+ { form_mode "edit" }
+}
+
+
+# ---------------------------------------------------------------
+# Defaults & Security
+# ---------------------------------------------------------------
+
+set user_id [ad_maybe_redirect_for_registration]
+set page_title "[_ intranet-exchange-rate.Exchange-Rate]"
+set context_bar [im_context_bar $page_title]
+set page_focus "im_header_form.keywords"
+set return_url [im_url_with_query]
+
+set form_id "exchange_rates"
+set action_url "index"
+
+set todays_date [lindex [split [ns_localsqltimestamp] " "] 0]
+
+# ---------------------------------------------------------------
+# Indicators
+# ---------------------------------------------------------------
+
+set supported_currencies [db_list supported_currencies "select iso from currency_codes where supported_p = 't'"]
+
+ad_return_coplaint 1 $supported_currencies
+
+ad_form \
+ -name $form_id \
+ -cancel_url $return_url \
+ -action $action_url \
+ -mode $form_mode \
+ -export {return_url} \
+ -form {
+ {todays_date:date(text)
+ {label "[_ intranet-exchange-rate.Todays_Date]"}
+ }
+}
+
+
+template::element create $form_id $form_id \
+ -datatype integer \
+ -widget hidden \
+ -value $object_id
+

0 comments on commit 4d07773

Please sign in to comment.