]> wagnertech.de Git - mfinanz.git/commitdiff
Merge branch 'master' into currency
authorNiclas Zimmermann <niclas@kivitendo-premium.de>
Thu, 2 May 2013 08:55:07 +0000 (10:55 +0200)
committerNiclas Zimmermann <niclas@kivitendo-premium.de>
Thu, 2 May 2013 08:55:07 +0000 (10:55 +0200)
Conflicts:
locale/de/all

23 files changed:
SL/AM.pm
SL/AP.pm
SL/AR.pm
SL/CP.pm
SL/CT.pm
SL/DN.pm
SL/DO.pm
SL/Form.pm
SL/IR.pm
SL/IS.pm
SL/OE.pm
SL/User.pm
bin/mozilla/admin.pl
bin/mozilla/cp.pl
bin/mozilla/ic.pl
bin/mozilla/ir.pl
locale/de/all
sql/Pg-upgrade2/currencies.pl [new file with mode: 0644]
sql/Pg-upgrade2/rm_whitespaces.pl [new file with mode: 0644]
templates/webpages/admin/create_dataset.html
templates/webpages/am/edit_defaults.html
templates/webpages/dbupgrade/no_default_currency.html [new file with mode: 0644]
templates/webpages/dbupgrade/orphaned_currencies.html [new file with mode: 0644]

index c85c479118bf80415c5c3b2a7997d5ec77d59714..e4727047cb48692ac6a0cf75810f6bdb99d4d964 100644 (file)
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -1060,10 +1060,6 @@ sub save_defaults {
   my %accnos;
   map { ($accnos{$_}) = split(m/--/, $form->{$_}) } qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno ar_paid_accno);
 
-  $form->{curr}  =~ s/ //g;
-  my @currencies =  grep { $_ ne '' } split m/:/, $form->{curr};
-  my $currency   =  join ':', @currencies;
-
   # these defaults are database wide
 
   my $query =
@@ -1087,7 +1083,6 @@ sub save_defaults {
         assemblynumber     = ?,
         sdonumber          = ?,
         pdonumber          = ?,
-        curr               = ?,
         businessnumber     = ?,
         weightunit         = ?,
         language_id        = ?|;
@@ -1100,11 +1095,24 @@ sub save_defaults {
                 $form->{articlenumber},   $form->{servicenumber},
                 $form->{assemblynumber},
                 $form->{sdonumber},       $form->{pdonumber},
-                $currency,
                 $form->{businessnumber},  $form->{weightunit},
                 conv_i($form->{language_id}));
   do_query($form, $dbh, $query, @values);
 
+  $main::lxdebug->message(0, "es gibt rowcount: " . $form->{rowcount});
+
+  for my $i (1..$form->{rowcount}) {
+    if ($form->{"curr_$i"} ne $form->{"old_curr_$i"}) {
+      $query = qq|UPDATE currencies SET curr = '| . $form->{"curr_$i"} . qq|' WHERE curr = '| . $form->{"old_curr_$i"} . qq|'|;
+      do_query($form, $dbh, $query);
+    }
+  }
+
+  if (length($form->{new_curr}) > 0) {
+    $query = qq|INSERT INTO currencies (curr) VALUES ('| . $form->{new_curr} . qq|')|;
+    do_query($form, $dbh, $query);
+  }
+
   $dbh->commit();
 
   $main::lxdebug->leave_sub();
@@ -1118,7 +1126,7 @@ sub save_preferences {
 
   my $dbh = $form->get_standard_dbh($myconfig);
 
-  my ($currency, $businessnumber) = selectrow_query($form, $dbh, qq|SELECT curr, businessnumber FROM defaults|);
+  my ($businessnumber) = selectrow_query($form, $dbh, qq|SELECT businessnumber FROM defaults|);
 
   # update name
   my $query = qq|UPDATE employee SET name = ? WHERE login = ?|;
@@ -1126,10 +1134,6 @@ sub save_preferences {
 
   my $rc = $dbh->commit();
 
-  # save first currency in myconfig
-  $currency               =~ s/:.*//;
-  $form->{currency}       =  $currency;
-
   $form->{businessnumber} =  $businessnumber;
 
   $myconfig = User->new(login => $form->{login});
@@ -1286,6 +1290,28 @@ sub defaultaccounts {
   }
 
   $sth->finish;
+
+  #Get currencies:
+  $query = qq|SELECT curr FROM currencies ORDER BY id|;
+
+  $form->{CURRENCIES} = [];
+
+  $sth = prepare_execute_query($form, $dbh, $query);
+  $sth->execute || $form->dberror($query);
+  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
+    push @{ $form->{ CURRENCIES } } , $ref;
+  }
+  $sth->finish;
+
+  #Which of them is the default currency?
+  $query = qq|SELECT curr AS defaultcurrency FROM currencies WHERE id = (SELECT curr FROM defaults LIMIT 1);|;
+  $sth   = $dbh->prepare($query);
+  $sth->execute || $form->dberror($query);
+
+  $form->{defaultcurrency}               = ($sth->fetchrow_hashref("NAME_lc"))->{defaultcurrency};
+
+  $sth->finish;
+
   $dbh->disconnect;
 
   $main::lxdebug->leave_sub();
index 54abcd17e4ada7633a51a3e72ed821ee3f9fdb63..810a15e529dde57170709145d6ba3f3f1491b22d 100644 (file)
--- a/SL/AP.pm
+++ b/SL/AP.pm
@@ -55,7 +55,6 @@ sub post_transaction {
   my $exchangerate = 0;
 
   $form->{defaultcurrency} = $form->get_default_currency($myconfig);
-  delete $form->{currency} unless $form->{defaultcurrency};
 
   ($null, $form->{department_id}) = split(/--/, $form->{department});
 
@@ -185,7 +184,7 @@ sub post_transaction {
     $query = qq|UPDATE ap SET
                 invnumber = ?, transdate = ?, ordnumber = ?, vendor_id = ?, taxincluded = ?,
                 amount = ?, duedate = ?, paid = ?, netamount = ?,
-                curr = ?, notes = ?, department_id = ?, storno = ?, storno_id = ?,
+                curr = (SELECT id FROM currencies WHERE curr = ?), notes = ?, department_id = ?, storno = ?, storno_id = ?,
                 globalproject_id = ?, direct_debit = ?
                WHERE id = ?|;
     @values = ($form->{invnumber}, conv_date($form->{transdate}),
@@ -665,7 +664,6 @@ sub post_payment {
 
   $form->{exchangerate}    = $form->format_amount($myconfig, $form->{exchangerate});
   $form->{defaultcurrency} = $form->get_default_currency($myconfig);
-  delete $form->{currency} unless $form->{defaultcurrency};
 
   # Get the AP accno.
   $query =
index 7958495839946f911cf257c2156c97b70d7c0afa..3def7597a5ff358777de8f3af4ddb93664dcfeb0 100644 (file)
--- a/SL/AR.pm
+++ b/SL/AR.pm
@@ -56,7 +56,6 @@ sub post_transaction {
 
   my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
   $form->{defaultcurrency} = $form->get_default_currency($myconfig);
-  delete $form->{currency} unless $form->{defaultcurrency};
 
   # set exchangerate
   $form->{exchangerate} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 :
@@ -135,8 +134,8 @@ sub post_transaction {
     } else {
       $query = qq|SELECT nextval('glid')|;
       ($form->{id}) = selectrow_query($form, $dbh, $query);
-      $query = qq|INSERT INTO ar (id, invnumber, employee_id) VALUES (?, 'dummy', ?)|;
-      do_query($form, $dbh, $query, $form->{id}, $form->{employee_id});
+      $query = qq|INSERT INTO ar (id, invnumber, employee_id, curr) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE curr=?))|;
+      do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}, $form->{currency});
       $form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh) unless $form->{invnumber};
     }
   }
@@ -156,12 +155,12 @@ sub post_transaction {
       qq|UPDATE ar set
            invnumber = ?, ordnumber = ?, transdate = ?, customer_id = ?,
            taxincluded = ?, amount = ?, duedate = ?, paid = ?,
-           netamount = ?, curr = ?, notes = ?, department_id = ?,
+           netamount = ?, notes = ?, department_id = ?,
            employee_id = ?, storno = ?, storno_id = ?, globalproject_id = ?,
            direct_debit = ?
          WHERE id = ?|;
     my @values = ($form->{invnumber}, $form->{ordnumber}, conv_date($form->{transdate}), conv_i($form->{customer_id}), $form->{taxincluded} ? 't' : 'f', $form->{amount},
-                  conv_date($form->{duedate}), $form->{paid}, $form->{netamount}, $form->{currency}, $form->{notes}, conv_i($form->{department_id}),
+                  conv_date($form->{duedate}), $form->{paid}, $form->{netamount}, $form->{notes}, conv_i($form->{department_id}),
                   conv_i($form->{employee_id}), $form->{storno} ? 't' : 'f', $form->{storno_id},
                   conv_i($form->{globalproject_id}), $form->{direct_debit} ? 't' : 'f', conv_i($form->{id}));
     do_query($form, $dbh, $query, @values);
@@ -426,7 +425,6 @@ sub post_payment {
 
   $form->{exchangerate}    = $form->format_amount($myconfig, $form->{exchangerate});
   $form->{defaultcurrency} = $form->get_default_currency($myconfig);
-  delete $form->{currency} unless $form->{defaultcurrency};
 
   # Get the AR accno (which is normally done by Form::create_links()).
   $query =
index 18673c21597c702dee495ae9b4c9a80b5c120c1c..91e032fe760101b75ee44c0cb6b032262d9164d7 100644 (file)
--- a/SL/CP.pm
+++ b/SL/CP.pm
@@ -93,10 +93,9 @@ sub paymentaccounts {
   }
   $sth->finish;
 
-  # get currencies and closedto
-  $query = qq|SELECT curr, closedto FROM defaults|;
-  ($form->{currencies}, $form->{closedto}) =
-    selectrow_query($form, $dbh, $query);
+  # get closedto
+  $query = qq|SELECT closedto FROM defaults|;
+  ($form->{closedto}) = selectrow_query($form, $dbh, $query);
 
   $dbh->disconnect;
 
@@ -150,9 +149,10 @@ sub get_openinvoices {
   my $arap = $form->{arap} eq "ar" ? "ar" : "ap";
 
   my $query =
-     qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, a.curr | .
+     qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, cu.curr | .
      qq|FROM $arap a | .
-     qq|WHERE (a.${vc}_id = ?) AND (COALESCE(a.curr, '') = ?) AND NOT (a.amount = a.paid)| .
+     qq|LEFT JOIN currencies cu ON (cu.id=a.curr)| .
+     qq|WHERE (a.${vc}_id = ?) AND cu.curr = ? AND NOT (a.amount = a.paid)| .
      qq|ORDER BY a.id|;
   my $sth = prepare_execute_query($form, $dbh, $query,
                                   conv_i($form->{"${vc}_id"}),
@@ -174,7 +174,7 @@ sub get_openinvoices {
     SELECT COUNT(*)
     FROM $arap
     WHERE (${vc}_id = ?)
-      AND (COALESCE(curr, '') <> ?)
+      AND ((SELECT cu.curr FROM currencies cu WHERE cu.id=${arap}.curr) <> ?)
       AND (amount <> paid)
 SQL
   ($form->{openinvoices_other_currencies}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{"${vc}_id"}), "$form->{currency}");
@@ -250,7 +250,7 @@ sub process_payment {
         qq|SELECT $buysell | .
         qq|FROM exchangerate e | .
         qq|JOIN ${arap} a ON (a.transdate = e.transdate) | .
-        qq|WHERE (e.curr = ?) AND (a.id = ?)|;
+        qq|WHERE (e.curr = (SELECT id FROM currencies WHERE curr = ?)) AND (a.id = ?)|;
       my ($exchangerate) =
         selectrow_query($form, $dbh, $query,
                         $form->{currency}, $form->{"id_$i"});
index 97f57c72c5510a684ef82521d4af00c77f1d2bfc..37550e4af37c5d168cc260ac1a3542ff693528bb 100644 (file)
--- a/SL/CT.pm
+++ b/SL/CT.pm
@@ -68,11 +68,12 @@ sub get_tuple {
   my $ref = $sth->fetchrow_hashref("NAME_lc");
 
   map { $form->{$_} = $ref->{$_} } keys %$ref;
+  $sth->finish;
 
-  # remove any trailing whitespace
-  $form->{curr} =~ s/\s*$//;
+  #get name of currency instead of id:
+  $query = qq|SELECT curr FROM currencies WHERE id=?|;
+  ($form->{curr}) = selectrow_query($form, $dbh, $query, conv_i($form->{curr}));
 
-  $sth->finish;
   if ( $form->{salesman_id} ) {
     my $query =
       qq|SELECT ct.name AS salesman | .
@@ -319,7 +320,7 @@ sub save_customer {
     qq|user_password = ?, | .
     qq|c_vendor_id = ?, | .
     qq|klass = ?, | .
-    qq|curr = ?, | .
+    qq|curr = (SELECT id FROM currencies WHERE curr = ?), | .
     qq|taxincluded_checked = ? | .
     qq|WHERE id = ?|;
   my @values = (
@@ -362,7 +363,7 @@ sub save_customer {
     $form->{user_password},
     $form->{c_vendor_id},
     conv_i($form->{klass}),
-    substr($form->{currency}, 0, 3),
+    $form->{currency},
     $form->{taxincluded_checked} ne '' ? $form->{taxincluded_checked} : undef,
     $form->{id}
     );
@@ -471,7 +472,7 @@ sub save_vendor {
     qq|  username = ?, | .
     qq|  user_password = ?, | .
     qq|  v_customer_id = ?, | .
-    qq|  curr = ? | .
+    qq|  curr = (SELECT id FROM currencies WHERE curr = ?) | .
     qq|WHERE id = ?|;
   my @values = (
     $form->{vendornumber},
@@ -511,7 +512,7 @@ sub save_vendor {
     $form->{username},
     $form->{user_password},
     $form->{v_customer_id},
-    substr($form->{currency}, 0, 3),
+    $form->{currency},
     $form->{id}
     );
   do_query($form, $dbh, $query, @values);
index 46749ab37cb676c656baadfbbe13c3169e88d048..a960a4c000a8e7967f2fba36b2e14ef2bd6689eb 100644 (file)
--- a/SL/DN.pm
+++ b/SL/DN.pm
@@ -228,7 +228,7 @@ sub create_invoice_for_fees {
          -- duedate:
          (SELECT duedate FROM dunning WHERE dunning_id = ? LIMIT 1),
          'f',                   -- invoice
-         ?,                     -- curr
+         (SELECT id FROM currencies WHERE curr = ?), -- curr
          ?,                     -- notes
          -- employee_id:
          (SELECT id FROM employee WHERE login = ?)
@@ -761,7 +761,7 @@ sub print_dunning {
          ar.transdate,       ar.duedate,      ar.customer_id,
          ar.invnumber,       ar.ordnumber,    ar.cp_id,
          ar.amount,          ar.netamount,    ar.paid,
-         ar.curr,
+         (SELECT cu.curr FROM currencies cu WHERE cu.id=ar.curr) AS curr,
          ar.amount - ar.paid AS open_amount,
          ar.amount - ar.paid + da.fee + da.interest AS linetotal
 
index 15e16cc16c44a96858cfdd5667ae19f1532fbb9f..2eb93376f132158cd8a60553bc1c04278968ccf6 100644 (file)
--- a/SL/DO.pm
+++ b/SL/DO.pm
@@ -348,7 +348,7 @@ sub save {
          shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, closed = ?,
          delivered = ?, department_id = ?, language_id = ?, shipto_id = ?,
          globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?,
-         is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, curr = ?
+         is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, curr = (SELECT id FROM currencies WHERE curr = ?)
        WHERE id = ?|;
 
   @values = ($form->{donumber}, $form->{ordnumber},
@@ -616,7 +616,7 @@ sub retrieve {
          d.description AS department, dord.language_id,
          dord.shipto_id,
          dord.globalproject_id, dord.delivered, dord.transaction_description,
-         dord.taxzone_id, dord.taxincluded, dord.terms, dord.curr AS currency
+         dord.taxzone_id, dord.taxincluded, dord.terms, (SELECT cu.curr FROM currencies cu WHERE cu.id=dord.curr) AS currency
        FROM delivery_orders dord
        JOIN ${vc} cv ON (dord.${vc}_id = cv.id)
        LEFT JOIN employee e ON (dord.employee_id = e.id)
@@ -638,9 +638,6 @@ sub retrieve {
   }
   $sth->finish();
 
-  # remove any trailing whitespace
-  $form->{currency} =~ s/\s*$//;
-
   $form->{donumber_array} =~ s/\s*$//g;
 
   $form->{saved_donumber} = $form->{donumber};
index 7b5d257b89942a9e70fca4c7291c910b206c5ff2..c2385ce791a61a435ab5ab24e7721451dc4a5bc1 100644 (file)
@@ -1490,11 +1490,9 @@ sub update_exchangerate {
     $main::lxdebug->leave_sub();
     return;
   }
-  $query = qq|SELECT curr FROM defaults|;
-
-  my ($currency) = selectrow_query($self, $dbh, $query);
-  my ($defaultcurrency) = split m/:/, $currency;
+  $query = qq|SELECT curr FROM currencies WHERE id=(SELECT curr FROM defaults)|;
 
+  my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
 
   if ($curr eq $defaultcurrency) {
     $main::lxdebug->leave_sub();
@@ -1502,7 +1500,7 @@ sub update_exchangerate {
   }
 
   $query = qq|SELECT e.curr FROM exchangerate e
-                 WHERE e.curr = ? AND e.transdate = ?
+                 WHERE e.curr = (SELECT cu.id FROM currencies cu WHERE cu.curr=?) AND e.transdate = ?
                  FOR UPDATE|;
   my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
 
@@ -1528,12 +1526,12 @@ sub update_exchangerate {
   if ($sth->fetchrow_array) {
     $query = qq|UPDATE exchangerate
                 SET $set
-                WHERE curr = ?
+                WHERE curr = (SELECT id FROM currencies WHERE curr = ?)
                 AND transdate = ?|;
 
   } else {
     $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
-                VALUES (?, $buy, $sell, ?)|;
+                VALUES ((SELECT id FROM currencies WHERE curr = ?), $buy, $sell, ?)|;
   }
   $sth->finish;
   do_query($self, $dbh, $query, $curr, $transdate);
@@ -1573,18 +1571,17 @@ sub get_exchangerate {
     return 1;
   }
 
-  $query = qq|SELECT curr FROM defaults|;
+  $query = qq|SELECT curr FROM currencies WHERE id = (SELECT curr FROM defaults)|;
 
-  my ($currency) = selectrow_query($self, $dbh, $query);
-  my ($defaultcurrency) = split m/:/, $currency;
+  my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
 
-  if ($currency eq $defaultcurrency) {
+  if ($curr eq $defaultcurrency) {
     $main::lxdebug->leave_sub();
     return 1;
   }
 
   $query = qq|SELECT e.$fld FROM exchangerate e
-                 WHERE e.curr = ? AND e.transdate = ?|;
+                 WHERE e.curr = (SELECT id FROM currencies WHERE curr = ?) AND e.transdate = ?|;
   my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
 
 
@@ -1617,7 +1614,7 @@ sub check_exchangerate {
 
   my $dbh   = $self->get_standard_dbh($myconfig);
   my $query = qq|SELECT e.$fld FROM exchangerate e
-                 WHERE e.curr = ? AND e.transdate = ?|;
+                 WHERE e.curr = (SELECT id FROM currencies WHERE curr = ?) AND e.transdate = ?|;
 
   my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
 
@@ -1632,11 +1629,16 @@ sub get_all_currencies {
   my $self     = shift;
   my $myconfig = shift || \%::myconfig;
   my $dbh      = $self->get_standard_dbh($myconfig);
+  my @currencies =();
 
-  my $query = qq|SELECT curr FROM defaults|;
+  my $query = qq|SELECT curr FROM currencies|;
 
-  my ($curr)     = selectrow_query($self, $dbh, $query);
-  my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
+  my $sth = prepare_execute_query($self, $dbh, $query);
+
+  while (my $ref = $sth->fetchrow_hashref()) {
+    push(@currencies, $ref->{curr});
+  }
+  $sth->finish;
 
   $main::lxdebug->leave_sub();
 
@@ -1647,11 +1649,14 @@ sub get_default_currency {
   $main::lxdebug->enter_sub();
 
   my ($self, $myconfig) = @_;
-  my @currencies        = $self->get_all_currencies($myconfig);
+  my $dbh      = $self->get_standard_dbh($myconfig);
+  my $query = qq|SELECT curr FROM currencies WHERE id = (SELECT curr FROM defaults)|;
+
+  my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
 
   $main::lxdebug->leave_sub();
 
-  return $currencies[0];
+  return $defaultcurrency;
 }
 
 sub set_payment_options {
@@ -2191,9 +2196,7 @@ $main::lxdebug->enter_sub();
 
   $key = "all_currencies" unless ($key);
 
-  my $query = qq|SELECT curr AS currency FROM defaults|;
-
-  $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
+  $self->{$key} = [$self->get_all_currencies()];
 
   $main::lxdebug->leave_sub();
 }
@@ -2704,7 +2707,7 @@ sub create_links {
     $query =
       qq|SELECT
            a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
-           a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
+           a.duedate, a.ordnumber, a.taxincluded, (SELECT cu.curr FROM currencies cu WHERE cu.id=a.curr) AS currency, a.notes,
            a.intnotes, a.department_id, a.amount AS oldinvtotal,
            a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
            a.globalproject_id, ${extra_columns}
@@ -2722,9 +2725,6 @@ sub create_links {
       $self->{$key} = $ref->{$key};
     }
 
-    # remove any trailing whitespace
-    $self->{currency} =~ s/\s*$//;
-
     my $transdate = "current_date";
     if ($self->{transdate}) {
       $transdate = $dbh->quote($self->{transdate});
@@ -2808,9 +2808,11 @@ sub create_links {
     }
 
     $sth->finish;
+    #check das:
     $query =
       qq|SELECT
-           d.curr AS currencies, d.closedto, d.revtrans,
+           d.closedto, d.revtrans,
+           (SELECT cu.curr FROM currencies cu WHERE cu.id=d.curr) AS defaultcurrency,
            (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
            (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
          FROM defaults d|;
@@ -2822,7 +2824,8 @@ sub create_links {
     # get date
     $query =
        qq|SELECT
-            current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
+            current_date AS transdate, d.closedto, d.revtrans,
+            (SELECT cu.curr FROM currencies cu WHERE cu.id=d.curr) AS defaultcurrency,
             (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
             (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
           FROM defaults d|;
@@ -2832,7 +2835,7 @@ sub create_links {
     if ($self->{"$self->{vc}_id"}) {
 
       # only setup currency
-      ($self->{currency}) = split(/:/, $self->{currencies}) if !$self->{currency};
+      ($self->{currency}) = $self->{defaultcurrency} if !$self->{currency};
 
     } else {
 
@@ -2857,19 +2860,17 @@ sub lastname_used {
   my ($arap, $where);
 
   $table         = $table eq "customer" ? "customer" : "vendor";
-  my %column_map = ("a.curr"                  => "currency",
-                    "a.${table}_id"           => "${table}_id",
+  my %column_map = ("a.${table}_id"           => "${table}_id",
                     "a.department_id"         => "department_id",
                     "d.description"           => "department",
                     "ct.name"                 => $table,
-                    "ct.curr"                 => "cv_curr",
+                    "cu.curr"                 => "currency",
                     "current_date + ct.terms" => "duedate",
     );
 
   if ($self->{type} =~ /delivery_order/) {
     $arap  = 'delivery_orders';
-    delete $column_map{"a.curr"};
-    delete $column_map{"ct.curr"};
+    delete $column_map{"cu.currency"};
 
   } elsif ($self->{type} =~ /_order/) {
     $arap  = 'oe';
@@ -2898,18 +2899,12 @@ sub lastname_used {
                         FROM $arap a
                         LEFT JOIN $table     ct ON (a.${table}_id = ct.id)
                         LEFT JOIN department d  ON (a.department_id = d.id)
+                        LEFT JOIN currencies cu ON (cu.id=ct.curr)
                         WHERE a.id = ?|;
   my $ref          = selectfirst_hashref_query($self, $dbh, $query, $trans_id);
 
   map { $self->{$_} = $ref->{$_} } values %column_map;
 
-  # remove any trailing whitespace
-  $self->{currency} =~ s/\s*$// if $self->{currency};
-  $self->{cv_curr} =~ s/\s*$// if $self->{cv_curr};
-
-  # if customer/vendor currency is set use this
-  $self->{currency} = $self->{cv_curr} if $self->{cv_curr};
-
   $main::lxdebug->leave_sub();
 }
 
index 73b3e14eda3ac703692421615b680a70bbbdbb64..0179d6e78c244a86901f5ca8637792f288e8b780 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -57,6 +57,7 @@ sub post_invoice {
   # connect to database, turn off autocommit
   my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
   $form->{defaultcurrency} = $form->get_default_currency($myconfig);
+  my $defaultcurrency = $form->{defaultcurrency};
 
   my $ic_cvar_configs = CVar->get_configs(module => 'IC',
                                           dbh    => $dbh);
@@ -70,18 +71,16 @@ sub post_invoice {
 
   my $all_units = AM->retrieve_units($myconfig, $form);
 
+#markierung
   if (!$payments_only) {
     if ($form->{id}) {
       &reverse_invoice($dbh, $form);
     } else {
       ($form->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('glid')|);
-      do_query($form, $dbh, qq|INSERT INTO ap (id, invnumber) VALUES (?, '')|, $form->{id});
+      do_query($form, $dbh, qq|INSERT INTO ap (id, invnumber, curr) VALUES (?, '', (SELECT id FROM currencies WHERE curr=?))|, $form->{id}, $form->{currency});
     }
   }
 
-  my ($currencies)    = selectfirst_array_query($form, $dbh, qq|SELECT curr FROM defaults|);
-  my $defaultcurrency = (split m/:/, $currencies)[0];
-
   if ($form->{currency} eq $defaultcurrency) {
     $form->{exchangerate} = 1;
   } else {
@@ -686,7 +685,7 @@ sub post_invoice {
                 orddate      = ?, quodate     = ?, vendor_id     = ?, amount      = ?,
                 netamount    = ?, paid        = ?, duedate       = ?,
                 invoice      = ?, taxzone_id  = ?, notes         = ?, taxincluded = ?,
-                intnotes     = ?, curr        = ?, storno_id     = ?, storno      = ?,
+                intnotes     = ?, storno_id   = ?, storno        = ?,
                 cp_id        = ?, employee_id = ?, department_id = ?,
                 globalproject_id = ?, direct_debit = ?
               WHERE id = ?|;
@@ -695,7 +694,7 @@ sub post_invoice {
       conv_date($form->{orddate}), conv_date($form->{quodate}),     conv_i($form->{vendor_id}),               $amount,
                 $netamount,                  $form->{paid},      conv_date($form->{duedate}),
             '1',                             $taxzone_id,                  $form->{notes},          $form->{taxincluded} ? 't' : 'f',
-                $form->{intnotes},           $form->{currency},     conv_i($form->{storno_id}),     $form->{storno}      ? 't' : 'f',
+                $form->{intnotes},           conv_i($form->{storno_id}),     $form->{storno}      ? 't' : 'f',
          conv_i($form->{cp_id}),      conv_i($form->{employee_id}), conv_i($form->{department_id}),
          conv_i($form->{globalproject_id}),
                 $form->{direct_debit} ? 't' : 'f',
@@ -924,8 +923,7 @@ sub retrieve_invoice {
                (SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id)    AS income_accno,
                (SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id)   AS expense_accno,
                (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id)    AS fxgain_accno,
-               (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id)    AS fxloss_accno,
-               d.curr AS currencies
+               (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id)    AS fxloss_accno
                $q_invdate
                FROM defaults d|;
   $ref = selectfirst_hashref_query($form, $dbh, $query);
@@ -942,15 +940,12 @@ sub retrieve_invoice {
   $query = qq|SELECT cp_id, invnumber, transdate AS invdate, duedate,
                 orddate, quodate, globalproject_id,
                 ordnumber, quonumber, paid, taxincluded, notes, taxzone_id, storno, gldate,
-                intnotes, curr AS currency, direct_debit
+                intnotes, (SELECT cu.curr FROM currencies cu WHERE cu.id=ap.curr) AS currency, direct_debit
               FROM ap
               WHERE id = ?|;
   $ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id}));
   map { $form->{$_} = $ref->{$_} } keys %$ref;
 
-  # remove any trailing whitespace
-  $form->{currency} =~ s/\s*$//;
-
   $form->{exchangerate}  = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "sell");
 
   # get shipto
@@ -1092,7 +1087,7 @@ sub get_vendor {
          v.id AS vendor_id, v.name AS vendor, v.discount as vendor_discount,
          v.creditlimit, v.terms, v.notes AS intnotes,
          v.email, v.cc, v.bcc, v.language_id, v.payment_id,
-         v.street, v.zipcode, v.city, v.country, v.taxzone_id, v.curr, v.direct_debit,
+         v.street, v.zipcode, v.city, v.country, v.taxzone_id, (SELECT cu.curr FROM currencies cu WHERE cu.id=v.curr) AS curr, v.direct_debit,
          $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
          b.description AS business
        FROM vendor v
@@ -1102,11 +1097,8 @@ sub get_vendor {
   my $ref = selectfirst_hashref_query($form, $dbh, $query, @values);
   map { $params->{$_} = $ref->{$_} } keys %$ref;
 
-  # remove any trailing whitespace
-  $form->{curr} =~ s/\s*$//;
-
-  # use vendor currency if not empty
-  $form->{currency} = $form->{curr} if $form->{curr};
+  # use vendor currency
+  $form->{currency} = $form->{curr};
 
   $params->{creditremaining} = $params->{creditlimit};
 
@@ -1392,7 +1384,7 @@ sub vendor_details {
   # fax and phone and email as vendor*
   my $query =
     qq|SELECT ct.*, cp.*, ct.notes as vendornotes, phone as vendorphone, fax as vendorfax, email as vendoremail,
-         ct.curr AS currency
+         (SELECT cu.curr FROM currencies cu WHERE cu.id=ct.curr) AS currency
        FROM vendor ct
        LEFT JOIN contacts cp ON (ct.id = cp.cp_cv_id)
        WHERE (ct.id = ?) $contact
@@ -1411,8 +1403,6 @@ sub vendor_details {
   }
 
   map { $form->{$_} = $ref->{$_} } keys %$ref;
-  # remove any trailing whitespace
-  $form->{currency} =~ s/\s*$// if ($form->{currency});
 
   my $custom_variables = CVar->get_custom_variables('dbh'      => $dbh,
                                                     'module'   => 'CT',
index ce8db64b96ab4325cc4c366ffdd9b85f13392dc0..c5147b1afb4957d81a00f3d1c466e1092a16b440 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -458,7 +458,7 @@ sub customer_details {
   my $query =
     qq|SELECT ct.*, cp.*, ct.notes as customernotes,
          ct.phone AS customerphone, ct.fax AS customerfax, ct.email AS customeremail,
-         ct.curr AS currency
+         (SELECT cu.curr FROM currencies cu WHERE cu.id=ct.curr) AS currency
        FROM customer ct
        LEFT JOIN contacts cp on ct.id = cp.cp_cv_id
        WHERE (ct.id = ?) $where
@@ -478,9 +478,6 @@ sub customer_details {
 
   map { $form->{$_} = $ref->{$_} } keys %$ref;
 
-  # remove any trailing whitespace
-  $form->{currency} =~ s/\s*$// if ($form->{currency});
-
   if ($form->{delivery_customer_id}) {
     $query =
       qq|SELECT *, notes as customernotes
@@ -536,6 +533,8 @@ sub post_invoice {
   }
 
   $form->{defaultcurrency} = $form->get_default_currency($myconfig);
+  my $defaultcurrency = $form->{defaultcurrency};
+
   # Seit neuestem wird die department_id schon übergeben UND $form->department nicht mehr
   # korrekt zusammengebaut. Sehr wahrscheinlich beim Umstieg auf T8 kaputt gegangen
   # Ich lass den Code von 2005 erstmal noch stehen ;-) jb 03-2011
@@ -556,8 +555,8 @@ sub post_invoice {
       $query = qq|SELECT nextval('glid')|;
       ($form->{"id"}) = selectrow_query($form, $dbh, $query);
 
-      $query = qq|INSERT INTO ar (id, invnumber) VALUES (?, ?)|;
-      do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"});
+      $query = qq|INSERT INTO ar (id, invnumber, curr) VALUES (?, ?, (SELECT id FROM currencies WHERE curr=?))|;
+      do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"}, $form->{currency});
 
       if (!$form->{invnumber}) {
         $form->{invnumber} =
@@ -570,9 +569,6 @@ sub post_invoice {
   my ($netamount, $invoicediff) = (0, 0);
   my ($amount, $linetotal, $lastincomeaccno);
 
-  my ($currencies)    = selectfirst_array_query($form, $dbh, qq|SELECT curr FROM defaults|);
-  my $defaultcurrency = (split m/:/, $currencies)[0];
-
   if ($form->{currency} eq $defaultcurrency) {
     $form->{exchangerate} = 1;
   } else {
@@ -1085,7 +1081,8 @@ sub post_invoice {
                 amount      = ?, netamount     = ?, paid          = ?,
                 duedate     = ?, deliverydate  = ?, invoice       = ?, shippingpoint = ?,
                 shipvia     = ?, terms         = ?, notes         = ?, intnotes      = ?,
-                curr        = ?, department_id = ?, payment_id    = ?, taxincluded   = ?,
+                curr        = (SELECT id FROM currencies WHERE curr= ?),
+                department_id = ?, payment_id    = ?, taxincluded   = ?,
                 type        = ?, language_id   = ?, taxzone_id    = ?, shipto_id     = ?,
                 employee_id = ?, salesman_id   = ?, storno_id     = ?, storno        = ?,
                 cp_id       = ?, marge_total   = ?, marge_percent = ?,
@@ -1558,8 +1555,7 @@ sub retrieve_invoice {
          (SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id)    AS income_accno,
          (SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id)   AS expense_accno,
          (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id)    AS fxgain_accno,
-         (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id)    AS fxloss_accno,
-         d.curr AS currencies
+         (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id)    AS fxloss_accno
          ${query_transdate}
        FROM defaults d|;
 
@@ -1578,7 +1574,7 @@ sub retrieve_invoice {
            a.orddate, a.quodate, a.globalproject_id,
            a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.gldate,
            a.shippingpoint, a.shipvia, a.terms, a.notes, a.intnotes, a.taxzone_id,
-           a.duedate, a.taxincluded, a.curr AS currency, a.shipto_id, a.cp_id,
+           a.duedate, a.taxincluded, (SELECT cu.curr FROM currencies cu WHERE cu.id=a.curr) AS currency, a.shipto_id, a.cp_id,
            a.employee_id, a.salesman_id, a.payment_id,
            a.language_id, a.delivery_customer_id, a.delivery_vendor_id, a.type,
            a.transaction_description, a.donumber, a.invnumber_for_credit_note,
@@ -1590,9 +1586,6 @@ sub retrieve_invoice {
     $ref = selectfirst_hashref_query($form, $dbh, $query, $id);
     map { $form->{$_} = $ref->{$_} } keys %{ $ref };
 
-    # remove any trailing whitespace
-    $form->{currency} =~ s/\s*$//;
-
     $form->{exchangerate} = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "buy");
 
     # get shipto
@@ -1757,7 +1750,7 @@ sub get_customer {
          c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit, c.terms,
          c.email, c.cc, c.bcc, c.language_id, c.payment_id,
          c.street, c.zipcode, c.city, c.country,
-         c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, c.curr,
+         c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, (SELECT cu.curr FROM currencies cu WHERE cu.id=c.curr) AS curr,
          c.taxincluded_checked, c.direct_debit,
          $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
          b.discount AS tradediscount, b.description AS business
@@ -1772,11 +1765,8 @@ sub get_customer {
 
   map { $form->{$_} = $ref->{$_} } keys %$ref;
 
-  # remove any trailing whitespace
-  $form->{curr} =~ s/\s*$//;
-
-  # use customer currency if not empty
-  $form->{currency} = $form->{curr} if $form->{curr};
+  # use customer currency
+  $form->{currency} = $form->{curr};
 
   $query =
     qq|SELECT sum(amount - paid) AS dunning_amount
index 3b3845c50dc135892ec8291cbad5a72ac10fa270..c5a8c26aec80121b539d13854b6e65b93f2004f3 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -311,7 +311,7 @@ sub save {
     $query = qq|SELECT nextval('id')|;
     ($form->{id}) = selectrow_query($form, $dbh, $query);
 
-    $query = qq|INSERT INTO oe (id, ordnumber, employee_id) VALUES (?, '', ?)|;
+    $query = qq|INSERT INTO oe (id, ordnumber, employee_id, curr) VALUES (?, '', ?, (SELECT curr FROM defaults))|;
     do_query($form, $dbh, $query, $form->{id}, $form->{employee_id});
   }
 
@@ -494,7 +494,7 @@ sub save {
     qq|UPDATE oe SET
          ordnumber = ?, quonumber = ?, cusordnumber = ?, transdate = ?, vendor_id = ?,
          customer_id = ?, amount = ?, netamount = ?, reqdate = ?, taxincluded = ?,
-         shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, curr = ?, closed = ?,
+         shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, curr = (SELECT id FROM currencies WHERE curr=?), closed = ?,
          delivered = ?, proforma = ?, quotation = ?, department_id = ?, language_id = ?,
          taxzone_id = ?, shipto_id = ?, payment_id = ?, delivery_vendor_id = ?, delivery_customer_id = ?,
          globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?, marge_total = ?, marge_percent = ?
@@ -506,7 +506,7 @@ sub save {
              $amount, $netamount, conv_date($reqdate),
              $form->{taxincluded} ? 't' : 'f', $form->{shippingpoint},
              $form->{shipvia}, $form->{notes}, $form->{intnotes},
-             substr($form->{currency}, 0, 3), $form->{closed} ? 't' : 'f',
+             $form->{currency}, $form->{closed} ? 't' : 'f',
              $form->{delivered} ? "t" : "f", $form->{proforma} ? 't' : 'f',
              $quotation, conv_i($form->{department_id}),
              conv_i($form->{language_id}), conv_i($form->{taxzone_id}),
@@ -759,14 +759,13 @@ sub retrieve {
                      (SELECT c.accno FROM chart c WHERE d.income_accno_id    = c.id) AS income_accno,
                      (SELECT c.accno FROM chart c WHERE d.expense_accno_id   = c.id) AS expense_accno,
                      (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id    = c.id) AS fxgain_accno,
-                     (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id    = c.id) AS fxloss_accno,
-              d.curr AS currencies
+                     (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id    = c.id) AS fxloss_accno
               $query_add
               FROM defaults d|;
   my $ref = selectfirst_hashref_query($form, $dbh, $query);
   map { $form->{$_} = $ref->{$_} } keys %$ref;
 
-  ($form->{currency}) = split(/:/, $form->{currencies}) unless ($form->{currency});
+  $form->{currency} = $form->get_default_currency($myconfig);
 
   # set reqdate if this is an invoice->order conversion. If someone knows a better check to ensure
   # we come from invoices, feel free.
@@ -785,7 +784,7 @@ sub retrieve {
     $query =
       qq|SELECT o.cp_id, o.ordnumber, o.transdate, o.reqdate,
            o.taxincluded, o.shippingpoint, o.shipvia, o.notes, o.intnotes,
-           o.curr AS currency, e.name AS employee, o.employee_id, o.salesman_id,
+           (SELECT cu.curr FROM currencies cu WHERE cu.id=o.curr) AS currency, e.name AS employee, o.employee_id, o.salesman_id,
            o.${vc}_id, cv.name AS ${vc}, o.amount AS invtotal,
            o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber,
            d.description AS department, o.payment_id, o.language_id, o.taxzone_id,
@@ -807,9 +806,6 @@ sub retrieve {
     if ($ref) {
       map { $form->{$_} = $ref->{$_} } keys %$ref;
 
-      # remove any trailing whitespace
-      $form->{currency} =~ s/\s*$//;
-
       $form->{saved_xyznumber} = $form->{$form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber"};
 
       # set all entries for multiple ids blank that yield different information
index 368a0a278ef869b75fc6f999c5bb1db64ab48742..21c3689f936b029ca68201c1422bfde3d54f0516 100644 (file)
@@ -398,6 +398,8 @@ sub dbcreate {
   do_query($form, $dbh, $query, $form->{profit_determination});
   $query = "UPDATE defaults SET inventory_system = ?";
   do_query($form, $dbh, $query, $form->{inventory_system});
+  $query = "UPDATE defaults SET curr = ?";
+  do_query($form, $dbh, $query, $form->{defaultcurrency});
 
   $dbh->disconnect;
 
index 7f0b80de85dd3d59628a0c337f5d86f82b2f6b12..84c8b069954e2813acdc351dc9760ef1cd84cddb 100755 (executable)
@@ -780,6 +780,7 @@ sub dbcreate {
   my $locale = $main::locale;
 
   $form->isblank("db", $locale->text('Dataset missing!'));
+  $form->isblank("defaultcurrency", $locale->text('Default currency missing!'));
 
   User->dbcreate(\%$form);
 
index a70c32eebdcd2b2a74882e0053f4d0bec1567c57..b9aed484aa457688a002420042950588ef3d9a16 100644 (file)
@@ -109,10 +109,9 @@ sub payment {
   # geben und hier reinparsen, oder besser multibox oder html auslagern?
   # Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
   # Wofür macht das Sinn?
-  @curr = split(/:/, $form->{currencies});
-  chomp $curr[0];
+  @curr = $form->get_all_currencies();
   $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
-    $curr[0];
+    $form->get_default_currency(\%myconfig);
 
   # Entsprechend präventiv die Auswahlliste für Währungen
   # auch mit value= zusammenbauen (s.a. oben bugfix 1771)
index 222a4d1d500c509e04f2369bb729419fd707c86f..8200b01100700d6e758bdfc3c5072fb609a7b1bb 100644 (file)
@@ -1489,8 +1489,7 @@ sub link_part {
   IC->create_links("IC", \%myconfig, \%$form);
 
   # currencies
-  map({ $form->{selectcurrency} .= "<option>$_\n" }
-      split(/:/, $form->{currencies}));
+  map({ $form->{selectcurrency} .= "<option>$_\n" } $::form->get_all_currencies());
 
   # parts and assemblies have the same links
   my $item = $form->{item};
index 143696311499868152f9b9a5402f150cc4a64e16..4209fdf6addc989e1d9f43bc19fe2abc70df7e07 100644 (file)
@@ -149,7 +149,7 @@ sub invoice_links {
     $form->{currency} = $currency;
   }
 
-  my @curr = split(/:/, $form->{currencies}); #seems to be missing
+  my @curr = $form->get_all_currencies();
   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
   $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
index cce6b2d0e872c22edd185b58ed5acbfdd5186bd8..2e840320d2ff5cc9e62e1bfd18e7f6e119ef0c31 100755 (executable)
@@ -18,6 +18,7 @@ $self->{texts} = {
   '#1 h'                        => '#1 h',
   '#1 of #2 importable objects were imported.' => '#1 von #2 importierbaren Objekten wurden importiert.',
   '#1 prices were updated.'     => '#1 Preise wurden aktualisiert.',
+  '(recommended) Insert the used currencies in the system. You can simply change the name of the currencies by editing the textfields above. Do not use a name of a currency that is already in use.' => '(empfohlen) Fügen Sie die verwaisten Währungen in Ihr System ein. Sie können den Namen der Währung einfach ändern, indem Sie die Felder oben bearbeiten. Benutzen Sie keine Namen von Währungen, die Sie bereits benutzen.',
   '* there are restrictions for the perpetual method, look at chapter "Bemerkungen zu Bestandsmethode"  in' => ' für die Bestandsmethode gibt es Einschränkungen, siehe Kapitel "Bemerkungen zu Bestandsmethode"  in',
   '*) Since version 2.7 these parameters ares set in the client database and not in the configuration file, details in chapter:' => '*) Seit 2.7 werden Gewinnermittlungsart, Versteuerungsart und Warenbuchungsmethode in der Mandanten-DB gesteuert und nicht mehr in der Konfigurationsdatei, Umstellungs-Details:',
   '*/'                          => '*/',
@@ -318,6 +319,7 @@ $self->{texts} = {
   'Both'                        => 'Beide',
   'Bottom'                      => 'Unten',
   'Bought'                      => 'Gekauft',
+  'Break up the update and contact a service provider.' => 'Diese Option bricht das Update ab. Bitte kontaktieren Sie Ihren Administrator oder beauftragen einen Dienstleister.',
   'Buchungsdatum'               => 'Buchungsdatum',
   'Buchungsgruppe'              => 'Buchungsgruppe',
   'Buchungsgruppe (database ID)' => 'Buchungsgruppe (Datenbank-ID)',
@@ -607,6 +609,8 @@ $self->{texts} = {
   'Default Accounts'            => 'Standardkonten',
   'Default Customer/Vendor Language' => 'Standard-Kunden-/Lieferantensprache',
   'Default buchungsgruppe'      => 'Standardbuchungsgruppe',
+  'Default currency'            => 'Standardwährung',
+  'Default currency missing!'   => 'Standardwährung fehlt!',
   'Default output medium'       => 'Standardausgabekanal',
   'Default printer'             => 'Standarddrucker',
   'Default template format'     => 'Standardvorlagenformat',
@@ -812,7 +816,6 @@ $self->{texts} = {
   'End date'                    => 'Enddatum',
   'Enter a description for this new draft.' => 'Geben Sie eine Beschreibung f&uuml;r diesen Entwurf ein.',
   'Enter longdescription'       => 'Langtext eingeben',
-  'Enter the abbreviations separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies' => 'Geben Sie Ihre und weitere Währungen als Abkürzungen durch Doppelpunkte getrennt ein (z.B. EUR:USD:CAD)',
   'Enter the requested execution date or leave empty for the quickest possible execution:' => 'Geben Sie das jeweils gewünschte Ausführungsdatum an, oder lassen Sie das Feld leer für die schnellstmögliche Ausführung:',
   'Entries for which automatic conversion failed:' => 'Einträge, für die die automatische Umstellung fehlschlug:',
   'Entries for which automatic conversion succeeded:' => 'Einträge, für die die automatische Umstellung erfolgreich war:',
@@ -931,6 +934,7 @@ $self->{texts} = {
   'Fristsetzung'                => 'Fristsetzung',
   'From'                        => 'Von',
   'From Date'                   => 'Von',
+  'From this version on it is necessary to name a default value.' => 'Ab dieser Version benötigt kivitendo eine Standardwährung.',
   'From this version on a new feature is available.' => 'Ab dieser Version ist ein neues Feature verfügbar.',
   'From this version on the partnumber of services, articles and assemblies have to be unique.' => 'Ab dieser Version müssen Artikelnummern eindeutig vergeben werden.',
   'From this version on the taxkey 0 must have a tax rate of 0 (for DATEV compatibility).' => 'Ab dieser Version muss der Steuerschlüssel 0 einen Steuersatz von 0% haben (auf Grund der DATEV-Kompatibilität).',
@@ -989,7 +993,6 @@ $self->{texts} = {
   'ID-Nummer'                   => 'ID-Nummer (intern)',
   'II'                          => 'II',
   'III'                         => 'III',
-  'IMPORTANT NOTE: You cannot safely change currencies, IF you have already booking entries!' => 'WICHTIGER HINWEIS: Falls schon Buchungen im Mandanten vorhanden sind, kann man nicht mehr UNKRITISCH neue oder andere Währungen konfigurieren!',
   'IV'                          => 'IV',
   'If checked the taxkey will not be exported in the DATEV Export, but only IF chart taxkeys differ from general ledger taxkeys' => 'Falls angehakt wird der DATEV-Steuerschlüssel bei Buchungen auf dieses Konto nicht beim DATEV-Export mitexportiert, allerdings nur wenn zusätzlich der Konto-Steuerschlüssel vom Buchungs (Hauptbuch) Steuerschlüssel abweicht',
   'If the article type is set to \'mixed\' then a column called \'type\' must be present.' => 'Falls der Artikeltyp auf \'gemischt\' gestellt wird, muss eine Spalte namens \'type\' vorhanden sein.',
@@ -1286,6 +1289,7 @@ $self->{texts} = {
   'No data was found.'          => 'Es wurden keine Daten gefunden.',
   'No databases have been found on this server.' => 'Auf diesem Server wurden keine Datenbanken gefunden.',
   'No datasets have been selected.' => 'Es wurden keine Datenbanken ausgew&auml;hlt.',
+  'No default currency'         => 'Keine Standardwährung',
   'No department has been created yet.' => 'Es wurde noch keine Abteilung erfasst.',
   'No dunnings have been selected for printing.' => 'Es wurden keine Mahnungen zum Drucken ausgew&auml;hlt.',
   'No entries were found which had no unit assigned to them.' => 'Es wurden keine Eintr&auml;ge gefunden, denen keine Einheit zugeordnet war.',
@@ -1371,6 +1375,7 @@ $self->{texts} = {
   'Orders / Delivery Orders deleteable' => 'Aufträge / Lieferscheine löschbar',
   'Orientation'                 => 'Seitenformat',
   'Orphaned'                    => 'Nie benutzt',
+  'Orphaned currencies'         => 'Verwaiste Währungen',
   'Other users\' follow-ups'    => 'Wiedervorlagen anderer Benutzer',
   'Other values are ignored.'   => 'Andere Eingaben werden ignoriert.',
   'Others'                      => 'Andere',
@@ -1454,6 +1459,7 @@ $self->{texts} = {
   'Please contact your administrator.' => 'Bitte wenden Sie sich an Ihren Administrator.',
   'Please define a taxkey for the following taxes and run the update again:' => 'Bitte definieren Sie einen Steuerschlüssel für die folgenden Steuern und starten Sie dann das Update erneut:',
   'Please enter a profile name.' => 'Bitte geben Sie einen Profilnamen an.',
+  'Please enter the currency you are working with.' => 'Bitte geben Sie die Währung an, mit der Sie arbeiten.',
   'Please enter the login for the new user.' => 'Bitte geben Sie das Login für den neuen Benutzer ein.',
   'Please enter the name of the database that will be used as the template for the new database:' => 'Bitte geben Sie den Namen der Datenbank an, die als Vorlage f&uuml;r die neue Datenbank benutzt wird:',
   'Please enter the name of the dataset you want to restore the backup in.' => 'Bitte geben Sie den Namen der Datenbank ein, in der Sie die Sicherung wiederherstellen wollen.',
@@ -1615,6 +1621,7 @@ $self->{texts} = {
   'Removed spoolfiles!'         => 'Druckdateien entfernt!',
   'Removing marked entries from queue ...' => 'Markierte Einträge werden von der Warteschlange entfernt ...',
   'Rename the group'            => 'Gruppe umbenennen',
+  'Replace the orphaned currencies by other not orphaned currencies. To do so, please delete the currency in the textfields above and replace it by another currency. You could loose or change unintentionally exchangerates. Go on very carefully since you could destroy transactions.' => 'Ersetze die Währungen durch andere gültige Währungen. Wenn Sie sich hierfür entscheiden, ersetzen Sie bitte alle Währungen, die oben angegeben sind, durch Währungen, die in Ihrem System ordnungsgemäß eingetragen sind. Alle eingetragenen Wechselkurse für die verwaiste Währung werden dabei gelöscht. Bitte gehen Sie sehr vorsichtig vor, denn die betroffenen Buchungen können unter Umständen kaputt gehen.',
   'Report Positions'            => 'Berichte',
   'Report about warehouse contents' => 'Lagerbestand anzeigen',
   'Report about warehouse transactions' => 'Lagerbuchungen anzeigen',
@@ -1923,6 +1930,7 @@ $self->{texts} = {
   'Text variables: \'MAXLENGTH=n\' sets the maximum entry length to \'n\'.' => 'Textzeilen: \'MAXLENGTH=n\' setzt eine Maximall&auml;nge von n Zeichen.',
   'Text, text field and number variables: The default value will be used as-is.' => 'Textzeilen, Textfelder und Zahlenvariablen: Der Standardwert wird so wie er ist &uuml;bernommen.',
   'That export does not exist.' => 'Dieser Export existiert nicht.',
+  'That is why kivitendo could not find a default currency.' => 'Daher konnte kivitendo keine Standardwährung finden.',
   'The \'tag\' field must only consist of alphanumeric characters or the carachters - _ ( )' => 'Das Feld \'tag\' darf nur aus alphanumerischen Zeichen und den Zeichen - _ ( ) bestehen.',
   'The AP transaction #1 has been deleted.' => 'Die Kreditorenbuchung #1 wurde gelöscht.',
   'The AR transaction #1 has been deleted.' => 'Die Debitorenbuchung #1 wurde gelöscht.',
@@ -2002,6 +2010,7 @@ $self->{texts} = {
   'The follow-up date is missing.' => 'Das Wiedervorlagedatum fehlt.',
   'The following Buchungsgruppen have already been created:' => 'Die folgenden Buchungsgruppen wurden bereits angelegt:',
   'The following Datasets need to be updated' => 'Folgende Datenbanken müssen aktualisiert werden',
+  'The following currencies have been used, but they are not defined:' => 'Die folgenden Währungen wurden benutzt, sind aber nicht ordnungsgemäß in der Datenbank eingetragen:',
   'The following drafts have been saved and can be loaded.' => 'Die folgenden Entw&uuml;rfe wurden gespeichert und k&ouml;nnen geladen werden.',
   'The following old files whose settings have to be merged manually into the new configuration file "config/kivitendo.conf" still exist:' => 'Es existieren noch die folgenden alten Dateien, deren Einstellungen manuell in die neue Konfiguratsdatei "config/kivitendo.conf" migriert werden müssen:',
   'The following transaction contains wrong taxes:' => 'Die folgende Buchung enthält falsche Steuern:',
@@ -2107,8 +2116,10 @@ $self->{texts} = {
   'There are no entries in the background job history.' => 'Es gibt keine Einträge im Hintergrund-Job-Verlauf.',
   'There are no items in stock.' => 'Dieser Artikel ist nicht eingelagert.',
   'There are no items on your TODO list at the moment.' => 'Ihre Aufgabenliste enth&auml;lt momentan keine Eintr&auml;ge.',
+  'There are several options you can handle this problem, please select one:' => 'Bitte wählen Sie eine der folgenden Optionen, um mit dem Problem umzugehen:',
   'There are still entries in the database for which no unit has been assigned.' => 'Es gibt noch Eintr&auml;ge in der Datenbank, f&uuml;r die keine Einheit zugeordnet ist.',
   'There are still transfers not matching the qty of the delivery order. Stock operations can not be changed later. Do you really want to proceed?' => 'Einige der Lagerbewegungen sind nicht vollständig und Lagerbewegungen können nachträglich nicht mehr verändert werden. Wollen Sie wirklich fortfahren?',
+  'There are undefined currencies in your system.' => 'In Ihrer Datenbank wurden Währungen benutzt, die nicht ordnungsgemäß in den Währungen eingetragen wurden.',
   'There are usually three ways to install Perl modules.' => 'Es gibt normalerweise drei Arten, ein Perlmodul zu installieren.',
   'There is already a taxkey 0 with tax rate not 0.' => 'Es existiert bereits ein Steuerschlüssel mit Steuersatz ungleich 0%.',
   'There is an inconsistancy in your database.' => 'In Ihrer Datenbank sind Unstimmigkeiten vorhanden.',
@@ -2343,6 +2354,7 @@ $self->{texts} = {
   'You cannot create an invoice for delivery orders from different vendors.' => 'Sie können keine Rechnung aus Lieferscheinen von verschiedenen Lieferanten erstellen.',
   'You do not have the permissions to access this function.' => 'Sie verf&uuml;gen nicht &uuml;ber die notwendigen Rechte, um auf diese Funktion zuzugreifen.',
   'You have entered or selected the following shipping address for this customer:' => 'Sie haben die folgende Lieferadresse eingegeben oder ausgew&auml;hlt:',
+  'You have never worked with currencies.' => 'Sie haben noch nie  mit Währungen gearbeitet.',
   'You have not added bank accounts yet.' => 'Sie haben noch keine Bankkonten angelegt.',
   'You have not selected any delivery order.' => 'Sie haben keinen Lieferschein ausgewählt.',
   'You have not selected any export.' => 'Sie haben keinen Export ausgewählt.',
diff --git a/sql/Pg-upgrade2/currencies.pl b/sql/Pg-upgrade2/currencies.pl
new file mode 100644 (file)
index 0000000..2497be9
--- /dev/null
@@ -0,0 +1,239 @@
+# @tag: currencies
+# @description: Erstellt neue Tabelle currencies. Währungen können dann einfacher eingegeben und unkritisch geändert werden.
+# @depends: release_3_0_0 rm_whitespaces
+# @charset: utf-8
+
+use utf8;
+use strict;
+
+die("This script cannot be run from the command line.") unless ($main::form);
+
+sub mydberror {
+  my ($msg) = @_;
+  die($dbup_locale->text("Database update error:") . "<br>$msg<br>" . $DBI::errstr);
+}
+
+sub do_query {
+  my ($query, $may_fail) = @_;
+
+  if (!$dbh->do($query)) {
+    mydberror($query) unless ($may_fail);
+    $dbh->rollback();
+    $dbh->begin_work();
+  }
+}
+
+
+sub do_update {
+  #Check wheather default currency exists
+  my $query = qq|SELECT curr FROM defaults|;
+  my ($currencies) = $dbh->selectrow_array($query);
+
+  if (length($currencies) == 0 and length($main::form->{defaultcurrency}) == 0){
+    print_no_default_currency();
+    return 2;
+  } else {
+    if (length($main::form->{defaultcurrency}) == 0){
+      $main::form->{defaultcurrency} = (split m/:/, $currencies)[0];
+    }
+  }
+  my @currency_array = grep {$_ ne '' } split m/:/, $currencies;
+
+  $query = qq|SELECT DISTINCT curr FROM ar
+              UNION
+              SELECT DISTINCT curr FROM ap
+              UNION
+              SELECT DISTINCT curr FROM oe
+              UNION
+              SELECT DISTINCT curr FROM customer
+              UNION
+              SELECT DISTINCT curr FROM delivery_orders
+              UNION
+              SELECT DISTINCT curr FROM exchangerate
+              UNION
+              SELECT DISTINCT curr FROM vendor|;
+
+  my $sth = $dbh->prepare($query);
+  $sth->execute || $self->dberror($query);
+
+  $main::form->{ORPHANED_CURRENCIES} = [];
+  my $is_orphaned;
+  my $rowcount = 0;
+  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
+    next unless length($ref->{curr}) > 0;
+    $is_orphaned = 1;
+    foreach my $key (split(/:/, $currencies)) {
+      if ($ref->{curr} eq $key) {
+        $is_orphaned = 0;
+        last;
+      }
+    }
+    if ($is_orphaned) {
+     push @{ $main::form->{ORPHANED_CURRENCIES} }, $ref;
+     $main::form->{ORPHANED_CURRENCIES}[$rowcount]->{name} = "curr_$rowcount";
+     $rowcount++;
+    }
+  }
+
+  $sth->finish;
+
+  if (scalar @{ $main::form->{ORPHANED_CURRENCIES} } > 0 and not ($main::form->{continue_options})) {
+    print_orphaned_currencies();
+    return 2;
+  }
+
+  if ($main::form->{continue_options} eq 'break_up') {
+    return 0;
+  }
+
+  if ($main::form->{continue_options} eq 'insert') {
+    for my $i (0..($rowcount-1)){
+      push @currency_array, $form->{"curr_$i"};
+    }
+    create_and_fill_table(@currency_array);
+    return 1;
+  }
+
+  my $still_orphaned;
+  if ($main::form->{continue_options} eq 'replace') {
+    for my $i (0..($rowcount - 1)){
+      $still_orphaned = 1;
+      for my $item (@currency_array){
+        if ($main::form->{"curr_$i"} eq $item){
+          $still_orphaned = 0;
+          $query = qq|DELETE FROM exchangerate WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+          do_query($query);
+          $query = qq|UPDATE ap SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+          do_query($query);
+          $query = qq|UPDATE ar SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+          do_query($query);
+          $query = qq|UPDATE oe SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+          do_query($query);
+          $query = qq|UPDATE customer SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+          do_query($query);
+          $query = qq|UPDATE delivery_orders SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+          do_query($query);
+          $query = qq|UPDATE vendor SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+          do_query($query);
+          last;
+        }
+      }
+      if ($still_orphaned){
+        $main::form->{continue_options} = '';
+        return do_update();
+      }
+    }
+    create_and_fill_table(@currency_array);
+    return 1;
+  }
+
+  #No orphaned currencies, so create table:
+  create_and_fill_table(@currency_array);
+  return 1;
+}; # end do_update
+
+sub create_and_fill_table {
+  #Create an fill table currencies:
+  my $query = qq|CREATE TABLE currencies (id INTEGER DEFAULT nextval(('id'::text)::regclass) UNIQUE NOT NULL, curr TEXT PRIMARY KEY)|;
+  do_query($query);
+  foreach my $item ( @_ ) {
+    $query = qq|INSERT INTO currencies (curr) VALUES ('| . $item . qq|')|;
+    do_query($query);
+  }
+
+  #Set default currency if no currency was chosen:
+  $query = qq|UPDATE ap SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+  $query .= qq|UPDATE ar SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+  $query .= qq|UPDATE oe SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+  $query .= qq|UPDATE customer SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+  $query .= qq|UPDATE delivery_orders SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+  $query .= qq|UPDATE vendor SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+  $query .= qq|DELETE FROM exchangerate WHERE curr IS NULL or curr='';|;
+  do_query($query);
+
+  #Check wheather defaultcurrency is already in table currencies:
+  $query = qq|SELECT curr FROM currencies WHERE curr = '| . $main::form->{defaultcurrency} . qq|'|;
+  my ($insert_default) = $dbh->selectrow_array($query);
+
+  if (!$insert_default) {
+    $query = qq|INSERT INTO currencies (curr) VALUES ('| . $main::form->{defaultcurrency} . qq|')|;
+    do_query($query);
+  }
+
+  #Create a new columns currency and update with curr.id:
+  $query = qq|ALTER TABLE ap ADD currency INTEGER;
+              ALTER TABLE ar ADD currency INTEGER;
+              ALTER TABLE oe ADD currency INTEGER;
+              ALTER TABLE customer ADD currency INTEGER;
+              ALTER TABLE delivery_orders ADD currency INTEGER;
+              ALTER TABLE exchangerate ADD currency INTEGER;
+              ALTER TABLE vendor ADD currency INTEGER;
+              ALTER TABLE defaults ADD currency INTEGER;|;
+  do_query($query);
+  #Set defaultcurrency:
+  $query = qq|UPDATE defaults SET currency= (SELECT id FROM currencies WHERE curr = '| . $main::form->{defaultcurrency} . qq|')|;
+  do_query($query);
+  $query = qq|UPDATE ap SET currency = (SELECT id FROM currencies c WHERE c.curr = ap.curr);
+              UPDATE ar SET currency = (SELECT id FROM currencies c WHERE c.curr = ar.curr);
+              UPDATE oe SET currency = (SELECT id FROM currencies c WHERE c.curr = oe.curr);
+              UPDATE customer SET currency = (SELECT id FROM currencies c WHERE c.curr = customer.curr);
+              UPDATE delivery_orders SET currency = (SELECT id FROM currencies c WHERE c.curr = delivery_orders.curr);
+              UPDATE exchangerate SET currency = (SELECT id FROM currencies c WHERE c.curr = exchangerate.curr);
+              UPDATE vendor SET currency = (SELECT id FROM currencies c WHERE c.curr = vendor.curr);|;
+  do_query($query);
+
+  #Drop column 'curr':
+  $query = qq|ALTER TABLE ap DROP COLUMN curr;
+              ALTER TABLE ar DROP COLUMN curr;
+              ALTER TABLE oe DROP COLUMN curr;
+              ALTER TABLE customer DROP COLUMN curr;
+              ALTER TABLE delivery_orders DROP COLUMN curr;
+              ALTER TABLE exchangerate DROP COLUMN curr;
+              ALTER TABLE vendor DROP COLUMN curr;
+              ALTER TABLE defaults DROP COLUMN curr;|;
+  do_query($query);
+
+  #Rename currency to curr:
+  $query = qq|ALTER TABLE defaults RENAME COLUMN currency TO curr;
+              ALTER TABLE ap RENAME COLUMN currency TO curr;
+              ALTER TABLE ar RENAME COLUMN currency TO curr;
+              ALTER TABLE oe RENAME COLUMN currency TO curr;
+              ALTER TABLE customer RENAME COLUMN currency TO curr;
+              ALTER TABLE delivery_orders RENAME COLUMN currency TO curr;
+              ALTER TABLE exchangerate RENAME COLUMN currency TO curr;
+              ALTER TABLE vendor RENAME COLUMN currency TO curr;|;
+  do_query($query);
+
+  #Set NOT NULL constraints:
+  $query = qq|ALTER TABLE ap ALTER COLUMN curr SET NOT NULL;
+              ALTER TABLE ar ALTER COLUMN curr SET NOT NULL;
+              ALTER TABLE oe ALTER COLUMN curr SET NOT NULL;
+              ALTER TABLE customer ALTER COLUMN curr SET NOT NULL;
+              ALTER TABLE delivery_orders ALTER COLUMN curr SET NOT NULL;
+              ALTER TABLE exchangerate ALTER COLUMN curr SET NOT NULL;
+              ALTER TABLE vendor ALTER COLUMN curr SET NOT NULL;
+              ALTER TABLE defaults ALTER COLUMN curr SET NOT NULL;|;
+  do_query($query);
+
+  #Set foreign keys:
+  $query = qq|ALTER TABLE ap ADD FOREIGN KEY (curr) REFERENCES currencies(id);
+              ALTER TABLE ar ADD FOREIGN KEY (curr) REFERENCES currencies(id);
+              ALTER TABLE oe ADD FOREIGN KEY (curr) REFERENCES currencies(id);
+              ALTER TABLE customer ADD FOREIGN KEY (curr) REFERENCES currencies(id);
+              ALTER TABLE delivery_orders ADD FOREIGN KEY (curr) REFERENCES currencies(id);
+              ALTER TABLE exchangerate ADD FOREIGN KEY (curr) REFERENCES currencies(id);
+              ALTER TABLE vendor ADD FOREIGN KEY (curr) REFERENCES currencies(id);
+              ALTER TABLE defaults ADD FOREIGN KEY (curr) REFERENCES currencies(id);|;
+  do_query($query);
+
+};
+
+sub print_no_default_currency {
+  print $main::form->parse_html_template("dbupgrade/no_default_currency");
+};
+
+sub print_orphaned_currencies {
+  print $main::form->parse_html_template("dbupgrade/orphaned_currencies");
+};
+
+return do_update();
diff --git a/sql/Pg-upgrade2/rm_whitespaces.pl b/sql/Pg-upgrade2/rm_whitespaces.pl
new file mode 100644 (file)
index 0000000..51d2395
--- /dev/null
@@ -0,0 +1,53 @@
+# @tag: rm_whitespaces
+# @description: Entfernt mögliche Leerzeichen am Anfang und Ende jeder Währung
+# @depends: release_3_0_0
+# @charset: utf-8
+
+use utf8;
+use strict;
+
+die("This script cannot be run from the command line.") unless ($main::form);
+
+sub mydberror {
+  my ($msg) = @_;
+  die($dbup_locale->text("Database update error:") . "<br>$msg<br>" . $DBI::errstr);
+}
+
+sub do_query {
+  my ($query, $may_fail) = @_;
+
+  if (!$dbh->do($query)) {
+    mydberror($query) unless ($may_fail);
+    $dbh->rollback();
+    $dbh->begin_work();
+  }
+}
+
+
+sub do_update {
+  my $query = qq|UPDATE ar SET curr = RTRIM(LTRIM(curr))|;
+  do_query($query);
+  $query = qq|UPDATE ap SET curr = RTRIM(LTRIM(curr))|;
+  do_query($query);
+  $query = qq|UPDATE oe SET curr = RTRIM(LTRIM(curr))|;
+  do_query($query);
+  $query = qq|UPDATE customer SET curr = RTRIM(LTRIM(curr))|;
+  do_query($query);
+  $query = qq|UPDATE delivery_orders SET curr = RTRIM(LTRIM(curr))|;
+  do_query($query);
+  $query = qq|UPDATE exchangerate SET curr = RTRIM(LTRIM(curr))|;
+  do_query($query);
+  $query = qq|UPDATE vendor SET curr = RTRIM(LTRIM(curr))|;
+  do_query($query);
+
+  $query = qq|SELECT curr FROM defaults|;
+  my ($curr)     = selectrow_query($self, $dbh, $query);
+
+  $curr  =~ s/ //g;
+
+  $query = qq|UPDATE defaults SET curr = '$curr'|;
+  do_query($query);
+  return 1;
+};
+
+return do_update();
index 3e4c6e70749b877472fc260c342a273ad4168c87..991bbc902f0e28f683146dba6ca2021381b01f8c 100644 (file)
      </td>
     </tr>
 
+    <tr>
+     <th align="right" nowrap>[% 'Default currency' | $T8 %]</th>
+     <td><input name="defaultcurrency" value="EUR"></td>
+     </td>
+   </tr>
+
     <tr>
      <th valign="top" align="right" nowrap>[% 'Create Chart of Accounts' | $T8 %]</th>
      <td>
index 248953cf31af13f0c17778854b4aa5a999c160e6..c8c91f60af6682a6ad97e249d3af7920bf03ba63 100644 (file)
     </tr>
 
     <tr>
-     <th align="right">[% 'Currencies' | $T8 %] <sup>(1)</sup></th>
-     <td colspan="3"><input name="curr" size="20" value="[% HTML.escape(defaults_curr) %]"></td>
+     <th align="right">[% 'Default currency' | $T8 %]</th>
+     <td colspan="3">[% HTML.escape(defaultcurrency) %]</td>
+    </tr>
+
+    <tr>
+     <input type="hidden" name="rowcount" value="[% CURRENCIES.size %]">
+     <th align="right">[% 'Currencies' | $T8 %]</th>
+     <td colspan="3">[% FOREACH row = CURRENCIES %]<input name="curr_[% loop.count %]" size="3" value="[% HTML.escape(row.curr) %]">
+                                                   <input type=hidden name="old_curr_[% loop.count %]" value="[% HTML.escape(row.curr) %]">
+                     [% END %]
+                     <input name="new_curr" size="3" value="">
+     </td>
     </tr>
 
     <tr>
 
   <hr height="3" noshade>
 
-  <p>
-   (1) [% 'Enter the abbreviations separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies' | $T8 %]
-       [% 'IMPORTANT NOTE: You cannot safely change currencies, IF you have already booking entries!' | $T8 %]
   </p>
  </form>
diff --git a/templates/webpages/dbupgrade/no_default_currency.html b/templates/webpages/dbupgrade/no_default_currency.html
new file mode 100644 (file)
index 0000000..e5bbe5d
--- /dev/null
@@ -0,0 +1,16 @@
+[%- USE T8 %]
+[% USE HTML %]<div class="listtop">[% 'No default currency' | $T8 %]</div>
+
+<form name="Form" method="post" action="login.pl">
+<input type="hidden" name="action" value="login">
+
+<p>[% 'You have never worked with currencies.' | $T8 %]</p>
+<p>[% 'That is why kivitendo could not find a default currency.' | $T8 %]</p>
+<p>[% 'From this version on it is necessary to name a default value.' | $T8 %]</p>
+<p>[% 'Please enter the currency you are working with.' | $T8 %]</p>
+
+<input name="defaultcurrency" value="EUR">
+<input type="submit" value="[% 'Continue' | $T8 %]">
+
+</form>
+
diff --git a/templates/webpages/dbupgrade/orphaned_currencies.html b/templates/webpages/dbupgrade/orphaned_currencies.html
new file mode 100644 (file)
index 0000000..ef613d0
--- /dev/null
@@ -0,0 +1,43 @@
+[%- USE T8 %]
+[%- USE L %]
+[% USE HTML %]<div class="listtop">[% 'Orphaned currencies' | $T8 %]</div>
+
+<form name="Form" method="post" action="login.pl">
+<input type="hidden" name="action" value="login">
+<input type="hidden" name="defaultcurrency" value="[% HTML.escape(defaultcurrency) %]">
+
+<p>[% 'There are undefined currencies in your system.' | $T8 %]</p>
+<p>[% 'The following currencies have been used, but they are not defined:' | $T8 %]</p>
+[% FOREACH row = ORPHANED_CURRENCIES %]
+<input name="[% row.name %]" value="[% HTML.escape(row.curr) %]"><br>
+<input type="hidden" name="old_[% row.name %]" value="[% HTML.escape(row.curr) %]">
+[% END %]
+<p>[% 'There are several options you can handle this problem, please select one:' | $T8 %]</p>
+
+<table width="100%">
+
+<tr>
+<td>
+[% L.radio_button_tag('continue_options',
+    value => 'insert',
+    disabled => 0,
+    checked  => 0) %]
+&nbsp;[% '(recommended) Insert the used currencies in the system. You can simply change the name of the currencies by editing the textfields above. Do not use a name of a currency that is already in use.' | $T8 %] <br>
+[% L.radio_button_tag('continue_options',
+    value => 'replace',
+    disabled => 0,
+    checked  => 0) %]
+&nbsp;[% 'Replace the orphaned currencies by other not orphaned currencies. To do so, please delete the currency in the textfields above and replace it by another currency. You could loose or change unintentionally exchangerates. Go on very carefully since you could destroy transactions.' | $T8 %] <br>
+[% L.radio_button_tag('continue_options',
+    value => 'break_up',
+    disabled => 0,
+    checked  => 0) %]
+&nbsp;[% 'Break up the update and contact a service provider.' | $T8 %]
+</tr>
+</td>
+</table>
+
+<input type="submit" value="[% 'Continue' | $T8 %]">
+
+</form>
+