]> Frank Brehm's Git Trees - books.git/commitdiff
Mit Währungen angefangen
authorFrank Brehm <frank@brehm-online.com>
Sun, 30 Mar 2008 21:50:48 +0000 (21:50 +0000)
committerFrank Brehm <frank@brehm-online.com>
Sun, 30 Mar 2008 21:50:48 +0000 (21:50 +0000)
lib/FrBr/Books/Controller/Books.pm
lib/FrBr/Books/Util/Waehrung.pm [new file with mode: 0644]
root/src/books/book_form.tt2

index 17fbc67587794eddf7b377bd7b25431da235a133..267af5707fb0c23e8c3d8760f3b3be9ee3225abf 100644 (file)
@@ -13,6 +13,7 @@ use FrBr::Books::Util::Book;
 use FrBr::Books::Util::Category;
 use FrBr::Books::Util::Serie;
 use FrBr::Books::Util::Verlag;
+use FrBr::Books::Util::Waehrung;
 
 =head1 NAME
 
@@ -514,6 +515,17 @@ sub prepare_data_structures : Private {
     }
     $c->log->debug( get_output_string( $K . "Serien: ", $c->stash->{'serienliste'} ) );
 
+    # Waehrungen zusammensammeln
+    my $waehrungsliste = get_waehrungsliste($c);
+    $c->log->debug( get_output_string( $K . "Waehrungen gesamt: ", $waehrungsliste ) );
+    $c->stash->{'waehrungsliste'} = {};
+    $c->stash->{'waehrungs_ids'}  = [];
+    for my $waehrung ( @$waehrungsliste ) {
+        push @{$c->stash->{'waehrungs_ids'}}, $waehrung->{'id'};
+        $c->stash->{'waehrungsliste'}{$waehrung->{'id'}} = $waehrung;
+    }
+    $c->log->debug( get_output_string( $K . "Waehrungen: ", $c->stash->{'waehrungsliste'} ) );
+
     return 1;
 
 }
diff --git a/lib/FrBr/Books/Util/Waehrung.pm b/lib/FrBr/Books/Util/Waehrung.pm
new file mode 100644 (file)
index 0000000..8a67883
--- /dev/null
@@ -0,0 +1,131 @@
+package FrBr::Books::Util::Waehrung;
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+use FrBr::Common;
+
+# Export-Deklarationen
+
+BEGIN {
+
+    use Exporter();
+    our ( $VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
+
+    # set the version for version checking
+    $VERSION = 0.1;
+    my ($rev) = '$Revision$' =~ /(\d+)/;
+    $VERSION = sprintf( $VERSION . ".%d", $rev );
+
+    @ISA    = qw(Exporter);
+    @EXPORT = qw(
+        &get_waehrungsliste
+    );
+
+    #%EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
+
+    # your exported package globals go here,
+    # as well as any optionally exported functions
+    #@EXPORT_OK   = qw($Var1 %Hashit &func3);
+} ## end BEGIN
+
+our @EXPORT_OK;
+
+=head1 NAME
+
+FrBr::Books::Util::Waehrung - Modul fuer Funktionen rund um Waehrungen
+
+=head1 METHODS
+
+=cut
+
+#-----------------------------------------------------------------------------------
+
+=head2 get_waehrungsliste( $c, $params )
+
+Sammelt alle Waehrungen zusammen.
+
+Folgende benannte Parameter koennen ueber $params uebergeben werden:
+
+Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Waehrungen, die den uebergebenen Suchkriterien entsprechen:
+
+  $res = [
+    { 'id'     => 1,
+      'kuerzel'        => '$',
+      'name'   => 'US-Dollar',
+      'in_euro'        => 0.66225,
+    },
+    { 'id'     => 2,
+      ...
+    },
+    ...
+  ];
+
+Die Liste ist nach den Waehrungs-Namen alphabetisch sortiert.
+
+=cut
+
+sub get_waehrungsliste {
+
+    my $c = shift;
+    my $K = __PACKAGE__ . "::get_waehrungsliste(): ";
+
+    $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+    my $params = {};
+    if ( ref($_[0]) and ref($_[0]) eq 'HASH' ) {
+        $params = $_[0];
+    }
+    else {
+        %$params = @_;
+    }
+    $c->log->debug(  get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2;
+
+    my $list = [];
+
+    my $search_params = undef;
+
+    my $other_params = {};
+    $other_params->{'order_by'} = [ 'waehrungs_name' ];
+    $other_params->{'select'} = [
+        'id',
+        'waehrungs_kuerzel',
+        'waehrungs_name',
+        'umrechnung_in_euro',
+    ];
+    $other_params->{'as'} = [
+        'id',
+        'waehrungs_kuerzel',
+        'waehrungs_name',
+        'umrechnung_in_euro',
+    ];
+    for my $waehrung_rs ( $c->model('Schema::Waehrungen')->search( $search_params, $other_params )->all() ) {
+        my $waehrung = {};
+        $waehrung->{'id'}      = $waehrung_rs->id();
+        $waehrung->{'kuerzel'} = $waehrung_rs->waehrungs_kuerzel();
+        $waehrung->{'name'}    = $waehrung_rs->waehrungs_name();
+        $waehrung->{'in_euro'} = $waehrung_rs->umrechnung_in_euro();
+        push @$list, $waehrung;
+    }
+
+    return $list;
+}
+
+#-----------------------------------------------------------------------------------
+
+=head1 AUTHOR
+
+Frank Brehm
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
index 5995377b3eb04f99459ce62b87286607f15b96a0..4691379341bc13f05024fd170521b1d105c40144 100644 (file)
@@ -125,7 +125,11 @@ function goto_new_author() {
       <td><input type="text" name="book_seiten" size="20" maxlength="20" value="[% book_edit.seiten | html %]" class="zahl" /></td>
     </tr><tr>
       <th>Preis:</th>
-      <td><input type="text" name="book_preis" size="20" maxlength="20" value="[% book_edit.preis | replace('\.', ',')  %]" class="zahl" /></td>
+      <td><input type="text" name="book_preis" size="20" maxlength="20" value="[% book_edit.preis | replace('\.', ',')  %]" class="zahl" />
+          <select name="waehrungs_id" size="1">
+            <option value="">-- Währung auswählen --</option>[% FOR waehrungsid IN waehrungs_ids %]
+            <option value="[% waehrungsid %]"[% IF book_edit.waehrungs_id == waehrungsid %] selected[% END %]>[% waehrungsliste.$waehrungsid.kuerzel %]</option>[% END %]
+          </select></td>
     </tr><tr>
       <td colspan="2">&nbsp;</td>
     </tr><tr>