Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9557707c

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 9557707c3a18daeb9371f2366b8637a7e1f0fa3c
  • Vorgänger c1a8c632
  • Nachfolger ae27679f

Revert "Nutzung der Tabelle currencies"

This reverts commit be776964b83340e69fa2f02eae59b703c0c95b88.

Unterschiede anzeigen:

SL/AM.pm
1060 1060
  my %accnos;
1061 1061
  map { ($accnos{$_}) = split(m/--/, $form->{$_}) } qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno ar_paid_accno);
1062 1062

  
1063
  $form->{curr}  =~ s/ //g;
1064
  my @currencies =  grep { $_ ne '' } split m/:/, $form->{curr};
1065
  my $currency   =  join ':', @currencies;
1066

  
1063 1067
  # these defaults are database wide
1064 1068

  
1065 1069
  my $query =
......
1083 1087
        assemblynumber     = ?,
1084 1088
        sdonumber          = ?,
1085 1089
        pdonumber          = ?,
1090
        curr               = ?,
1086 1091
        businessnumber     = ?,
1087 1092
        weightunit         = ?,
1088 1093
        language_id        = ?|;
......
1095 1100
                $form->{articlenumber},   $form->{servicenumber},
1096 1101
                $form->{assemblynumber},
1097 1102
                $form->{sdonumber},       $form->{pdonumber},
1103
                $currency,
1098 1104
                $form->{businessnumber},  $form->{weightunit},
1099 1105
                conv_i($form->{language_id}));
1100 1106
  do_query($form, $dbh, $query, @values);
1101 1107

  
1102
  $main::lxdebug->message(0, "es gibt rowcount: " . $form->{rowcount});
1103

  
1104
  for my $i (1..$form->{rowcount}) {
1105
    if ($form->{"curr_$i"} ne $form->{"old_curr_$i"}) {
1106
      $query = qq|UPDATE currencies SET curr = '| . $form->{"curr_$i"} . qq|' WHERE curr = '| . $form->{"old_curr_$i"} . qq|'|;
1107
      do_query($form, $dbh, $query);
1108
    }
1109
  }
1110

  
1111
  if (length($form->{new_curr}) > 0) {
1112
    $query = qq|INSERT INTO currencies (curr) VALUES ('| . $form->{new_curr} . qq|')|;
1113
    do_query($form, $dbh, $query);
1114
  }
1115

  
1116 1108
  $dbh->commit();
1117 1109

  
1118 1110
  $main::lxdebug->leave_sub();
......
1126 1118

  
1127 1119
  my $dbh = $form->get_standard_dbh($myconfig);
1128 1120

  
1129
  my ($businessnumber) = selectrow_query($form, $dbh, qq|SELECT businessnumber FROM defaults|);
1121
  my ($currency, $businessnumber) = selectrow_query($form, $dbh, qq|SELECT curr, businessnumber FROM defaults|);
1130 1122

  
1131 1123
  # update name
1132 1124
  my $query = qq|UPDATE employee SET name = ? WHERE login = ?|;
......
1134 1126

  
1135 1127
  my $rc = $dbh->commit();
1136 1128

  
1129
  # save first currency in myconfig
1130
  $currency               =~ s/:.*//;
1131
  $form->{currency}       =  $currency;
1132

  
1137 1133
  $form->{businessnumber} =  $businessnumber;
1138 1134

  
1139 1135
  $myconfig = User->new(login => $form->{login});
SL/AP.pm
55 55
  my $exchangerate = 0;
56 56

  
57 57
  $form->{defaultcurrency} = $form->get_default_currency($myconfig);
58
  delete $form->{currency} unless $form->{defaultcurrency};
58 59

  
59 60
  ($null, $form->{department_id}) = split(/--/, $form->{department});
60 61

  
......
184 185
    $query = qq|UPDATE ap SET
185 186
                invnumber = ?, transdate = ?, ordnumber = ?, vendor_id = ?, taxincluded = ?,
186 187
                amount = ?, duedate = ?, paid = ?, netamount = ?,
187
                curr = (SELECT id FROM currencies WHERE curr = ?), notes = ?, department_id = ?, storno = ?, storno_id = ?,
188
                curr = ?, notes = ?, department_id = ?, storno = ?, storno_id = ?,
188 189
                globalproject_id = ?, direct_debit = ?
189 190
               WHERE id = ?|;
190 191
    @values = ($form->{invnumber}, conv_date($form->{transdate}),
......
664 665

  
665 666
  $form->{exchangerate}    = $form->format_amount($myconfig, $form->{exchangerate});
666 667
  $form->{defaultcurrency} = $form->get_default_currency($myconfig);
668
  delete $form->{currency} unless $form->{defaultcurrency};
667 669

  
668 670
  # Get the AP accno.
669 671
  $query =
SL/AR.pm
56 56

  
57 57
  my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
58 58
  $form->{defaultcurrency} = $form->get_default_currency($myconfig);
59
  delete $form->{currency} unless $form->{defaultcurrency};
59 60

  
60 61
  # set exchangerate
61 62
  $form->{exchangerate} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 :
......
134 135
    } else {
135 136
      $query = qq|SELECT nextval('glid')|;
136 137
      ($form->{id}) = selectrow_query($form, $dbh, $query);
137
      $query = qq|INSERT INTO ar (id, invnumber, employee_id, curr) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE curr=?))|;
138
      do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}, $form->{currency});
138
      $query = qq|INSERT INTO ar (id, invnumber, employee_id) VALUES (?, 'dummy', ?)|;
139
      do_query($form, $dbh, $query, $form->{id}, $form->{employee_id});
139 140
      $form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh) unless $form->{invnumber};
140 141
    }
141 142
  }
......
155 156
      qq|UPDATE ar set
156 157
           invnumber = ?, ordnumber = ?, transdate = ?, customer_id = ?,
157 158
           taxincluded = ?, amount = ?, duedate = ?, paid = ?,
158
           netamount = ?, notes = ?, department_id = ?,
159
           netamount = ?, curr = ?, notes = ?, department_id = ?,
159 160
           employee_id = ?, storno = ?, storno_id = ?, globalproject_id = ?,
160 161
           direct_debit = ?
161 162
         WHERE id = ?|;
162 163
    my @values = ($form->{invnumber}, $form->{ordnumber}, conv_date($form->{transdate}), conv_i($form->{customer_id}), $form->{taxincluded} ? 't' : 'f', $form->{amount},
163
                  conv_date($form->{duedate}), $form->{paid}, $form->{netamount}, $form->{notes}, conv_i($form->{department_id}),
164
                  conv_date($form->{duedate}), $form->{paid}, $form->{netamount}, $form->{currency}, $form->{notes}, conv_i($form->{department_id}),
164 165
                  conv_i($form->{employee_id}), $form->{storno} ? 't' : 'f', $form->{storno_id},
165 166
                  conv_i($form->{globalproject_id}), $form->{direct_debit} ? 't' : 'f', conv_i($form->{id}));
166 167
    do_query($form, $dbh, $query, @values);
......
425 426

  
426 427
  $form->{exchangerate}    = $form->format_amount($myconfig, $form->{exchangerate});
427 428
  $form->{defaultcurrency} = $form->get_default_currency($myconfig);
429
  delete $form->{currency} unless $form->{defaultcurrency};
428 430

  
429 431
  # Get the AR accno (which is normally done by Form::create_links()).
430 432
  $query =
SL/CP.pm
93 93
  }
94 94
  $sth->finish;
95 95

  
96
  # get closedto
97
  $query = qq|SELECT closedto FROM defaults|;
98
  ($form->{closedto}) = selectrow_query($form, $dbh, $query);
96
  # get currencies and closedto
97
  $query = qq|SELECT curr, closedto FROM defaults|;
98
  ($form->{currencies}, $form->{closedto}) =
99
    selectrow_query($form, $dbh, $query);
99 100

  
100 101
  $dbh->disconnect;
101 102

  
......
149 150
  my $arap = $form->{arap} eq "ar" ? "ar" : "ap";
150 151

  
151 152
  my $query =
152
     qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, cu.curr | .
153
     qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, a.curr | .
153 154
     qq|FROM $arap a | .
154
     qq|LEFT JOIN currencies cu ON (cu.id=a.curr)| .
155
     qq|WHERE (a.${vc}_id = ?) AND cu.curr = ? AND NOT (a.amount = a.paid)| .
155
     qq|WHERE (a.${vc}_id = ?) AND (COALESCE(a.curr, '') = ?) AND NOT (a.amount = a.paid)| .
156 156
     qq|ORDER BY a.id|;
157 157
  my $sth = prepare_execute_query($form, $dbh, $query,
158 158
                                  conv_i($form->{"${vc}_id"}),
......
174 174
    SELECT COUNT(*)
175 175
    FROM $arap
176 176
    WHERE (${vc}_id = ?)
177
      AND ((SELECT cu.curr FROM currencies cu WHERE cu.id=${arap}.curr) <> ?)
177
      AND (COALESCE(curr, '') <> ?)
178 178
      AND (amount <> paid)
179 179
SQL
180 180
  ($form->{openinvoices_other_currencies}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{"${vc}_id"}), "$form->{currency}");
......
250 250
        qq|SELECT $buysell | .
251 251
        qq|FROM exchangerate e | .
252 252
        qq|JOIN ${arap} a ON (a.transdate = e.transdate) | .
253
        qq|WHERE (e.curr = (SELECT id FROM currencies WHERE curr = ?)) AND (a.id = ?)|;
253
        qq|WHERE (e.curr = ?) AND (a.id = ?)|;
254 254
      my ($exchangerate) =
255 255
        selectrow_query($form, $dbh, $query,
256 256
                        $form->{currency}, $form->{"id_$i"});
SL/CT.pm
68 68
  my $ref = $sth->fetchrow_hashref("NAME_lc");
69 69

  
70 70
  map { $form->{$_} = $ref->{$_} } keys %$ref;
71
  $sth->finish;
72 71

  
73
  #get name of currency instead of id:
74
  $query = qq|SELECT curr FROM currencies WHERE id=?|;
75
  ($form->{curr}) = selectrow_query($form, $dbh, $query, conv_i($form->{curr}));
72
  # remove any trailing whitespace
73
  $form->{curr} =~ s/\s*$//;
76 74

  
75
  $sth->finish;
77 76
  if ( $form->{salesman_id} ) {
78 77
    my $query =
79 78
      qq|SELECT ct.name AS salesman | .
......
320 319
    qq|user_password = ?, | .
321 320
    qq|c_vendor_id = ?, | .
322 321
    qq|klass = ?, | .
323
    qq|curr = (SELECT id FROM currencies WHERE curr = ?), | .
322
    qq|curr = ?, | .
324 323
    qq|taxincluded_checked = ? | .
325 324
    qq|WHERE id = ?|;
326 325
  my @values = (
......
363 362
    $form->{user_password},
364 363
    $form->{c_vendor_id},
365 364
    conv_i($form->{klass}),
366
    $form->{currency},
365
    substr($form->{currency}, 0, 3),
367 366
    $form->{taxincluded_checked} ne '' ? $form->{taxincluded_checked} : undef,
368 367
    $form->{id}
369 368
    );
......
472 471
    qq|  username = ?, | .
473 472
    qq|  user_password = ?, | .
474 473
    qq|  v_customer_id = ?, | .
475
    qq|  curr = (SELECT id FROM currencies WHERE curr = ?) | .
474
    qq|  curr = ? | .
476 475
    qq|WHERE id = ?|;
477 476
  my @values = (
478 477
    $form->{vendornumber},
......
512 511
    $form->{username},
513 512
    $form->{user_password},
514 513
    $form->{v_customer_id},
515
    $form->{currency},
514
    substr($form->{currency}, 0, 3),
516 515
    $form->{id}
517 516
    );
518 517
  do_query($form, $dbh, $query, @values);
SL/DN.pm
228 228
         -- duedate:
229 229
         (SELECT duedate FROM dunning WHERE dunning_id = ? LIMIT 1),
230 230
         'f',                   -- invoice
231
         (SELECT id FROM currencies WHERE curr = ?), -- curr
231
         ?,                     -- curr
232 232
         ?,                     -- notes
233 233
         -- employee_id:
234 234
         (SELECT id FROM employee WHERE login = ?)
......
761 761
         ar.transdate,       ar.duedate,      ar.customer_id,
762 762
         ar.invnumber,       ar.ordnumber,    ar.cp_id,
763 763
         ar.amount,          ar.netamount,    ar.paid,
764
         (SELECT cu.curr FROM currencies cu WHERE cu.id=ar.curr) AS curr,
764
         ar.curr,
765 765
         ar.amount - ar.paid AS open_amount,
766 766
         ar.amount - ar.paid + da.fee + da.interest AS linetotal
767 767

  
SL/DO.pm
348 348
         shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, closed = ?,
349 349
         delivered = ?, department_id = ?, language_id = ?, shipto_id = ?,
350 350
         globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?,
351
         is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, curr = (SELECT id FROM currencies WHERE curr = ?)
351
         is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, curr = ?
352 352
       WHERE id = ?|;
353 353

  
354 354
  @values = ($form->{donumber}, $form->{ordnumber},
......
616 616
         d.description AS department, dord.language_id,
617 617
         dord.shipto_id,
618 618
         dord.globalproject_id, dord.delivered, dord.transaction_description,
619
         dord.taxzone_id, dord.taxincluded, dord.terms, (SELECT cu.curr FROM currencies cu WHERE cu.id=dord.curr) AS currency
619
         dord.taxzone_id, dord.taxincluded, dord.terms, dord.curr AS currency
620 620
       FROM delivery_orders dord
621 621
       JOIN ${vc} cv ON (dord.${vc}_id = cv.id)
622 622
       LEFT JOIN employee e ON (dord.employee_id = e.id)
......
638 638
  }
639 639
  $sth->finish();
640 640

  
641
  # remove any trailing whitespace
642
  $form->{currency} =~ s/\s*$//;
643

  
641 644
  $form->{donumber_array} =~ s/\s*$//g;
642 645

  
643 646
  $form->{saved_donumber} = $form->{donumber};
SL/Form.pm
1490 1490
    $main::lxdebug->leave_sub();
1491 1491
    return;
1492 1492
  }
1493
  $query = qq|SELECT curr FROM currencies WHERE id=(SELECT curr FROM defaults)|;
1493
  $query = qq|SELECT curr FROM defaults|;
1494

  
1495
  my ($currency) = selectrow_query($self, $dbh, $query);
1496
  my ($defaultcurrency) = split m/:/, $currency;
1494 1497

  
1495
  my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
1496 1498

  
1497 1499
  if ($curr eq $defaultcurrency) {
1498 1500
    $main::lxdebug->leave_sub();
......
1500 1502
  }
1501 1503

  
1502 1504
  $query = qq|SELECT e.curr FROM exchangerate e
1503
                 WHERE e.curr = (SELECT cu.id FROM currencies cu WHERE cu.curr=?) AND e.transdate = ?
1505
                 WHERE e.curr = ? AND e.transdate = ?
1504 1506
                 FOR UPDATE|;
1505 1507
  my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
1506 1508

  
......
1526 1528
  if ($sth->fetchrow_array) {
1527 1529
    $query = qq|UPDATE exchangerate
1528 1530
                SET $set
1529
                WHERE curr = (SELECT id FROM currencies WHERE curr = ?)
1531
                WHERE curr = ?
1530 1532
                AND transdate = ?|;
1531 1533

  
1532 1534
  } else {
1533 1535
    $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1534
                VALUES ((SELECT id FROM currencies WHERE curr = ?), $buy, $sell, ?)|;
1536
                VALUES (?, $buy, $sell, ?)|;
1535 1537
  }
1536 1538
  $sth->finish;
1537 1539
  do_query($self, $dbh, $query, $curr, $transdate);
......
1571 1573
    return 1;
1572 1574
  }
1573 1575

  
1574
  $query = qq|SELECT curr FROM currencies WHERE id = (SELECT curr FROM defaults)|;
1576
  $query = qq|SELECT curr FROM defaults|;
1575 1577

  
1576
  my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
1578
  my ($currency) = selectrow_query($self, $dbh, $query);
1579
  my ($defaultcurrency) = split m/:/, $currency;
1577 1580

  
1578
  if ($curr eq $defaultcurrency) {
1581
  if ($currency eq $defaultcurrency) {
1579 1582
    $main::lxdebug->leave_sub();
1580 1583
    return 1;
1581 1584
  }
1582 1585

  
1583 1586
  $query = qq|SELECT e.$fld FROM exchangerate e
1584
                 WHERE e.curr = (SELECT id FROM currencies WHERE curr = ?) AND e.transdate = ?|;
1587
                 WHERE e.curr = ? AND e.transdate = ?|;
1585 1588
  my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
1586 1589

  
1587 1590

  
......
1614 1617

  
1615 1618
  my $dbh   = $self->get_standard_dbh($myconfig);
1616 1619
  my $query = qq|SELECT e.$fld FROM exchangerate e
1617
                 WHERE e.curr = (SELECT id FROM currencies WHERE curr = ?) AND e.transdate = ?|;
1620
                 WHERE e.curr = ? AND e.transdate = ?|;
1618 1621

  
1619 1622
  my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
1620 1623

  
......
1629 1632
  my $self     = shift;
1630 1633
  my $myconfig = shift || \%::myconfig;
1631 1634
  my $dbh      = $self->get_standard_dbh($myconfig);
1632
  my @currencies =();
1633 1635

  
1634
  my $query = qq|SELECT curr FROM currencies|;
1636
  my $query = qq|SELECT curr FROM defaults|;
1635 1637

  
1636
  my $sth = prepare_execute_query($self, $dbh, $query);
1637

  
1638
  while (my $ref = $sth->fetchrow_hashref()) {
1639
    push(@currencies, $ref->{curr});
1640
  }
1641
  $sth->finish;
1638
  my ($curr)     = selectrow_query($self, $dbh, $query);
1639
  my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
1642 1640

  
1643 1641
  $main::lxdebug->leave_sub();
1644 1642

  
......
1649 1647
  $main::lxdebug->enter_sub();
1650 1648

  
1651 1649
  my ($self, $myconfig) = @_;
1652
  my $dbh      = $self->get_standard_dbh($myconfig);
1653
  my $query = qq|SELECT curr FROM currencies WHERE id = (SELECT curr FROM defaults)|;
1654

  
1655
  my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
1650
  my @currencies        = $self->get_all_currencies($myconfig);
1656 1651

  
1657 1652
  $main::lxdebug->leave_sub();
1658 1653

  
1659
  return $defaultcurrency;
1654
  return $currencies[0];
1660 1655
}
1661 1656

  
1662 1657
sub set_payment_options {
......
2196 2191

  
2197 2192
  $key = "all_currencies" unless ($key);
2198 2193

  
2199
  $self->{$key} = [$self->get_all_currencies()];
2194
  my $query = qq|SELECT curr AS currency FROM defaults|;
2195

  
2196
  $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
2200 2197

  
2201 2198
  $main::lxdebug->leave_sub();
2202 2199
}
......
2707 2704
    $query =
2708 2705
      qq|SELECT
2709 2706
           a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
2710
           a.duedate, a.ordnumber, a.taxincluded, (SELECT cu.curr FROM currencies cu WHERE cu.id=a.curr) AS currency, a.notes,
2707
           a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
2711 2708
           a.intnotes, a.department_id, a.amount AS oldinvtotal,
2712 2709
           a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
2713 2710
           a.globalproject_id, ${extra_columns}
......
2725 2722
      $self->{$key} = $ref->{$key};
2726 2723
    }
2727 2724

  
2725
    # remove any trailing whitespace
2726
    $self->{currency} =~ s/\s*$//;
2727

  
2728 2728
    my $transdate = "current_date";
2729 2729
    if ($self->{transdate}) {
2730 2730
      $transdate = $dbh->quote($self->{transdate});
......
2808 2808
    }
2809 2809

  
2810 2810
    $sth->finish;
2811
    #check das:
2812 2811
    $query =
2813 2812
      qq|SELECT
2814
           d.closedto, d.revtrans,
2815
           (SELECT cu.curr FROM currencies cu WHERE cu.id=d.curr) AS defaultcurrency,
2813
           d.curr AS currencies, d.closedto, d.revtrans,
2816 2814
           (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2817 2815
           (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2818 2816
         FROM defaults d|;
......
2824 2822
    # get date
2825 2823
    $query =
2826 2824
       qq|SELECT
2827
            current_date AS transdate, d.closedto, d.revtrans,
2828
            (SELECT cu.curr FROM currencies cu WHERE cu.id=d.curr) AS defaultcurrency,
2825
            current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
2829 2826
            (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2830 2827
            (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2831 2828
          FROM defaults d|;
......
2835 2832
    if ($self->{"$self->{vc}_id"}) {
2836 2833

  
2837 2834
      # only setup currency
2838
      ($self->{currency}) = $self->{defaultcurrency} if !$self->{currency};
2835
      ($self->{currency}) = split(/:/, $self->{currencies}) if !$self->{currency};
2839 2836

  
2840 2837
    } else {
2841 2838

  
......
2860 2857
  my ($arap, $where);
2861 2858

  
2862 2859
  $table         = $table eq "customer" ? "customer" : "vendor";
2863
  my %column_map = ("a.${table}_id"           => "${table}_id",
2860
  my %column_map = ("a.curr"                  => "currency",
2861
                    "a.${table}_id"           => "${table}_id",
2864 2862
                    "a.department_id"         => "department_id",
2865 2863
                    "d.description"           => "department",
2866 2864
                    "ct.name"                 => $table,
2867
                    "cu.curr"                 => "currency",
2865
                    "ct.curr"                 => "cv_curr",
2868 2866
                    "current_date + ct.terms" => "duedate",
2869 2867
    );
2870 2868

  
2871 2869
  if ($self->{type} =~ /delivery_order/) {
2872 2870
    $arap  = 'delivery_orders';
2873
    delete $column_map{"cu.currency"};
2871
    delete $column_map{"a.curr"};
2872
    delete $column_map{"ct.curr"};
2874 2873

  
2875 2874
  } elsif ($self->{type} =~ /_order/) {
2876 2875
    $arap  = 'oe';
......
2899 2898
                        FROM $arap a
2900 2899
                        LEFT JOIN $table     ct ON (a.${table}_id = ct.id)
2901 2900
                        LEFT JOIN department d  ON (a.department_id = d.id)
2902
                        LEFT JOIN currencies cu ON (cu.id=ct.curr)
2903 2901
                        WHERE a.id = ?|;
2904 2902
  my $ref          = selectfirst_hashref_query($self, $dbh, $query, $trans_id);
2905 2903

  
2906 2904
  map { $self->{$_} = $ref->{$_} } values %column_map;
2907 2905

  
2906
  # remove any trailing whitespace
2907
  $self->{currency} =~ s/\s*$// if $self->{currency};
2908
  $self->{cv_curr} =~ s/\s*$// if $self->{cv_curr};
2909

  
2910
  # if customer/vendor currency is set use this
2911
  $self->{currency} = $self->{cv_curr} if $self->{cv_curr};
2912

  
2908 2913
  $main::lxdebug->leave_sub();
2909 2914
}
2910 2915

  
SL/IR.pm
57 57
  # connect to database, turn off autocommit
58 58
  my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
59 59
  $form->{defaultcurrency} = $form->get_default_currency($myconfig);
60
  my $defaultcurrency = $form->{defaultcurrency};
61 60

  
62 61
  my $ic_cvar_configs = CVar->get_configs(module => 'IC',
63 62
                                          dbh    => $dbh);
......
71 70

  
72 71
  my $all_units = AM->retrieve_units($myconfig, $form);
73 72

  
74
#markierung
75 73
  if (!$payments_only) {
76 74
    if ($form->{id}) {
77 75
      &reverse_invoice($dbh, $form);
78 76
    } else {
79 77
      ($form->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('glid')|);
80
      do_query($form, $dbh, qq|INSERT INTO ap (id, invnumber, curr) VALUES (?, '', (SELECT id FROM currencies WHERE curr=?))|, $form->{id}, $form->{currency});
78
      do_query($form, $dbh, qq|INSERT INTO ap (id, invnumber) VALUES (?, '')|, $form->{id});
81 79
    }
82 80
  }
83 81

  
82
  my ($currencies)    = selectfirst_array_query($form, $dbh, qq|SELECT curr FROM defaults|);
83
  my $defaultcurrency = (split m/:/, $currencies)[0];
84

  
84 85
  if ($form->{currency} eq $defaultcurrency) {
85 86
    $form->{exchangerate} = 1;
86 87
  } else {
......
685 686
                orddate      = ?, quodate     = ?, vendor_id     = ?, amount      = ?,
686 687
                netamount    = ?, paid        = ?, duedate       = ?,
687 688
                invoice      = ?, taxzone_id  = ?, notes         = ?, taxincluded = ?,
688
                intnotes     = ?, storno_id   = ?, storno        = ?,
689
                intnotes     = ?, curr        = ?, storno_id     = ?, storno      = ?,
689 690
                cp_id        = ?, employee_id = ?, department_id = ?,
690 691
                globalproject_id = ?, direct_debit = ?
691 692
              WHERE id = ?|;
......
694 695
      conv_date($form->{orddate}), conv_date($form->{quodate}),     conv_i($form->{vendor_id}),               $amount,
695 696
                $netamount,                  $form->{paid},      conv_date($form->{duedate}),
696 697
            '1',                             $taxzone_id,                  $form->{notes},          $form->{taxincluded} ? 't' : 'f',
697
                $form->{intnotes},           conv_i($form->{storno_id}),     $form->{storno}      ? 't' : 'f',
698
                $form->{intnotes},           $form->{currency},     conv_i($form->{storno_id}),     $form->{storno}      ? 't' : 'f',
698 699
         conv_i($form->{cp_id}),      conv_i($form->{employee_id}), conv_i($form->{department_id}),
699 700
         conv_i($form->{globalproject_id}),
700 701
                $form->{direct_debit} ? 't' : 'f',
......
923 924
               (SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id)    AS income_accno,
924 925
               (SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id)   AS expense_accno,
925 926
               (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id)    AS fxgain_accno,
926
               (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id)    AS fxloss_accno
927
               (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id)    AS fxloss_accno,
928
               d.curr AS currencies
927 929
               $q_invdate
928 930
               FROM defaults d|;
929 931
  $ref = selectfirst_hashref_query($form, $dbh, $query);
......
940 942
  $query = qq|SELECT cp_id, invnumber, transdate AS invdate, duedate,
941 943
                orddate, quodate, globalproject_id,
942 944
                ordnumber, quonumber, paid, taxincluded, notes, taxzone_id, storno, gldate,
943
                intnotes, (SELECT cu.curr FROM currencies cu WHERE cu.id=ap.curr) AS currency, direct_debit
945
                intnotes, curr AS currency, direct_debit
944 946
              FROM ap
945 947
              WHERE id = ?|;
946 948
  $ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id}));
947 949
  map { $form->{$_} = $ref->{$_} } keys %$ref;
948 950

  
951
  # remove any trailing whitespace
952
  $form->{currency} =~ s/\s*$//;
953

  
949 954
  $form->{exchangerate}  = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "sell");
950 955

  
951 956
  # get shipto
......
1087 1092
         v.id AS vendor_id, v.name AS vendor, v.discount as vendor_discount,
1088 1093
         v.creditlimit, v.terms, v.notes AS intnotes,
1089 1094
         v.email, v.cc, v.bcc, v.language_id, v.payment_id,
1090
         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,
1095
         v.street, v.zipcode, v.city, v.country, v.taxzone_id, v.curr, v.direct_debit,
1091 1096
         $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
1092 1097
         b.description AS business
1093 1098
       FROM vendor v
......
1097 1102
  my $ref = selectfirst_hashref_query($form, $dbh, $query, @values);
1098 1103
  map { $params->{$_} = $ref->{$_} } keys %$ref;
1099 1104

  
1100
  # use vendor currency
1101
  $form->{currency} = $form->{curr};
1105
  # remove any trailing whitespace
1106
  $form->{curr} =~ s/\s*$//;
1107

  
1108
  # use vendor currency if not empty
1109
  $form->{currency} = $form->{curr} if $form->{curr};
1102 1110

  
1103 1111
  $params->{creditremaining} = $params->{creditlimit};
1104 1112

  
......
1384 1392
  # fax and phone and email as vendor*
1385 1393
  my $query =
1386 1394
    qq|SELECT ct.*, cp.*, ct.notes as vendornotes, phone as vendorphone, fax as vendorfax, email as vendoremail,
1387
         (SELECT cu.curr FROM currencies cu WHERE cu.id=ct.curr) AS currency
1395
         ct.curr AS currency
1388 1396
       FROM vendor ct
1389 1397
       LEFT JOIN contacts cp ON (ct.id = cp.cp_cv_id)
1390 1398
       WHERE (ct.id = ?) $contact
......
1403 1411
  }
1404 1412

  
1405 1413
  map { $form->{$_} = $ref->{$_} } keys %$ref;
1414
  # remove any trailing whitespace
1415
  $form->{currency} =~ s/\s*$// if ($form->{currency});
1406 1416

  
1407 1417
  my $custom_variables = CVar->get_custom_variables('dbh'      => $dbh,
1408 1418
                                                    'module'   => 'CT',
SL/IS.pm
458 458
  my $query =
459 459
    qq|SELECT ct.*, cp.*, ct.notes as customernotes,
460 460
         ct.phone AS customerphone, ct.fax AS customerfax, ct.email AS customeremail,
461
         (SELECT cu.curr FROM currencies cu WHERE cu.id=ct.curr) AS currency
461
         ct.curr AS currency
462 462
       FROM customer ct
463 463
       LEFT JOIN contacts cp on ct.id = cp.cp_cv_id
464 464
       WHERE (ct.id = ?) $where
......
478 478

  
479 479
  map { $form->{$_} = $ref->{$_} } keys %$ref;
480 480

  
481
  # remove any trailing whitespace
482
  $form->{currency} =~ s/\s*$// if ($form->{currency});
483

  
481 484
  if ($form->{delivery_customer_id}) {
482 485
    $query =
483 486
      qq|SELECT *, notes as customernotes
......
533 536
  }
534 537

  
535 538
  $form->{defaultcurrency} = $form->get_default_currency($myconfig);
536
  my $defaultcurrency = $form->{defaultcurrency};
537

  
538 539
  # Seit neuestem wird die department_id schon übergeben UND $form->department nicht mehr
539 540
  # korrekt zusammengebaut. Sehr wahrscheinlich beim Umstieg auf T8 kaputt gegangen
540 541
  # Ich lass den Code von 2005 erstmal noch stehen ;-) jb 03-2011
......
555 556
      $query = qq|SELECT nextval('glid')|;
556 557
      ($form->{"id"}) = selectrow_query($form, $dbh, $query);
557 558

  
558
      $query = qq|INSERT INTO ar (id, invnumber, curr) VALUES (?, ?, (SELECT id FROM currencies WHERE curr=?))|;
559
      do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"}, $form->{currency});
559
      $query = qq|INSERT INTO ar (id, invnumber) VALUES (?, ?)|;
560
      do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"});
560 561

  
561 562
      if (!$form->{invnumber}) {
562 563
        $form->{invnumber} =
......
569 570
  my ($netamount, $invoicediff) = (0, 0);
570 571
  my ($amount, $linetotal, $lastincomeaccno);
571 572

  
573
  my ($currencies)    = selectfirst_array_query($form, $dbh, qq|SELECT curr FROM defaults|);
574
  my $defaultcurrency = (split m/:/, $currencies)[0];
575

  
572 576
  if ($form->{currency} eq $defaultcurrency) {
573 577
    $form->{exchangerate} = 1;
574 578
  } else {
......
1081 1085
                amount      = ?, netamount     = ?, paid          = ?,
1082 1086
                duedate     = ?, deliverydate  = ?, invoice       = ?, shippingpoint = ?,
1083 1087
                shipvia     = ?, terms         = ?, notes         = ?, intnotes      = ?,
1084
                curr        = (SELECT id FROM currencies WHERE curr= ?),
1085
                department_id = ?, payment_id    = ?, taxincluded   = ?,
1088
                curr        = ?, department_id = ?, payment_id    = ?, taxincluded   = ?,
1086 1089
                type        = ?, language_id   = ?, taxzone_id    = ?, shipto_id     = ?,
1087 1090
                employee_id = ?, salesman_id   = ?, storno_id     = ?, storno        = ?,
1088 1091
                cp_id       = ?, marge_total   = ?, marge_percent = ?,
......
1555 1558
         (SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id)    AS income_accno,
1556 1559
         (SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id)   AS expense_accno,
1557 1560
         (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id)    AS fxgain_accno,
1558
         (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id)    AS fxloss_accno
1561
         (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id)    AS fxloss_accno,
1562
         d.curr AS currencies
1559 1563
         ${query_transdate}
1560 1564
       FROM defaults d|;
1561 1565

  
......
1574 1578
           a.orddate, a.quodate, a.globalproject_id,
1575 1579
           a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.gldate,
1576 1580
           a.shippingpoint, a.shipvia, a.terms, a.notes, a.intnotes, a.taxzone_id,
1577
           a.duedate, a.taxincluded, (SELECT cu.curr FROM currencies cu WHERE cu.id=a.curr) AS currency, a.shipto_id, a.cp_id,
1581
           a.duedate, a.taxincluded, a.curr AS currency, a.shipto_id, a.cp_id,
1578 1582
           a.employee_id, a.salesman_id, a.payment_id,
1579 1583
           a.language_id, a.delivery_customer_id, a.delivery_vendor_id, a.type,
1580 1584
           a.transaction_description, a.donumber, a.invnumber_for_credit_note,
......
1586 1590
    $ref = selectfirst_hashref_query($form, $dbh, $query, $id);
1587 1591
    map { $form->{$_} = $ref->{$_} } keys %{ $ref };
1588 1592

  
1593
    # remove any trailing whitespace
1594
    $form->{currency} =~ s/\s*$//;
1595

  
1589 1596
    $form->{exchangerate} = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "buy");
1590 1597

  
1591 1598
    # get shipto
......
1750 1757
         c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit, c.terms,
1751 1758
         c.email, c.cc, c.bcc, c.language_id, c.payment_id,
1752 1759
         c.street, c.zipcode, c.city, c.country,
1753
         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,
1760
         c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, c.curr,
1754 1761
         c.taxincluded_checked, c.direct_debit,
1755 1762
         $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
1756 1763
         b.discount AS tradediscount, b.description AS business
......
1765 1772

  
1766 1773
  map { $form->{$_} = $ref->{$_} } keys %$ref;
1767 1774

  
1768
  # use customer currency
1769
  $form->{currency} = $form->{curr};
1775
  # remove any trailing whitespace
1776
  $form->{curr} =~ s/\s*$//;
1777

  
1778
  # use customer currency if not empty
1779
  $form->{currency} = $form->{curr} if $form->{curr};
1770 1780

  
1771 1781
  $query =
1772 1782
    qq|SELECT sum(amount - paid) AS dunning_amount
SL/OE.pm
311 311
    $query = qq|SELECT nextval('id')|;
312 312
    ($form->{id}) = selectrow_query($form, $dbh, $query);
313 313

  
314
    $query = qq|INSERT INTO oe (id, ordnumber, employee_id, curr) VALUES (?, '', ?, (SELECT curr FROM defaults))|;
314
    $query = qq|INSERT INTO oe (id, ordnumber, employee_id) VALUES (?, '', ?)|;
315 315
    do_query($form, $dbh, $query, $form->{id}, $form->{employee_id});
316 316
  }
317 317

  
......
494 494
    qq|UPDATE oe SET
495 495
         ordnumber = ?, quonumber = ?, cusordnumber = ?, transdate = ?, vendor_id = ?,
496 496
         customer_id = ?, amount = ?, netamount = ?, reqdate = ?, taxincluded = ?,
497
         shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, curr = (SELECT id FROM currencies WHERE curr=?), closed = ?,
497
         shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, curr = ?, closed = ?,
498 498
         delivered = ?, proforma = ?, quotation = ?, department_id = ?, language_id = ?,
499 499
         taxzone_id = ?, shipto_id = ?, payment_id = ?, delivery_vendor_id = ?, delivery_customer_id = ?,
500 500
         globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?, marge_total = ?, marge_percent = ?
......
506 506
             $amount, $netamount, conv_date($reqdate),
507 507
             $form->{taxincluded} ? 't' : 'f', $form->{shippingpoint},
508 508
             $form->{shipvia}, $form->{notes}, $form->{intnotes},
509
             $form->{currency}, $form->{closed} ? 't' : 'f',
509
             substr($form->{currency}, 0, 3), $form->{closed} ? 't' : 'f',
510 510
             $form->{delivered} ? "t" : "f", $form->{proforma} ? 't' : 'f',
511 511
             $quotation, conv_i($form->{department_id}),
512 512
             conv_i($form->{language_id}), conv_i($form->{taxzone_id}),
......
759 759
                     (SELECT c.accno FROM chart c WHERE d.income_accno_id    = c.id) AS income_accno,
760 760
                     (SELECT c.accno FROM chart c WHERE d.expense_accno_id   = c.id) AS expense_accno,
761 761
                     (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id    = c.id) AS fxgain_accno,
762
                     (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id    = c.id) AS fxloss_accno
762
                     (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id    = c.id) AS fxloss_accno,
763
              d.curr AS currencies
763 764
              $query_add
764 765
              FROM defaults d|;
765 766
  my $ref = selectfirst_hashref_query($form, $dbh, $query);
766 767
  map { $form->{$_} = $ref->{$_} } keys %$ref;
767 768

  
768
  $form->{currency} = $form->get_default_currency($myconfig);
769
  ($form->{currency}) = split(/:/, $form->{currencies}) unless ($form->{currency});
769 770

  
770 771
  # set reqdate if this is an invoice->order conversion. If someone knows a better check to ensure
771 772
  # we come from invoices, feel free.
......
784 785
    $query =
785 786
      qq|SELECT o.cp_id, o.ordnumber, o.transdate, o.reqdate,
786 787
           o.taxincluded, o.shippingpoint, o.shipvia, o.notes, o.intnotes,
787
           (SELECT cu.curr FROM currencies cu WHERE cu.id=o.curr) AS currency, e.name AS employee, o.employee_id, o.salesman_id,
788
           o.curr AS currency, e.name AS employee, o.employee_id, o.salesman_id,
788 789
           o.${vc}_id, cv.name AS ${vc}, o.amount AS invtotal,
789 790
           o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber,
790 791
           d.description AS department, o.payment_id, o.language_id, o.taxzone_id,
......
806 807
    if ($ref) {
807 808
      map { $form->{$_} = $ref->{$_} } keys %$ref;
808 809

  
810
      # remove any trailing whitespace
811
      $form->{currency} =~ s/\s*$//;
812

  
809 813
      $form->{saved_xyznumber} = $form->{$form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber"};
810 814

  
811 815
      # set all entries for multiple ids blank that yield different information
bin/mozilla/cp.pl
109 109
  # geben und hier reinparsen, oder besser multibox oder html auslagern?
110 110
  # Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
111 111
  # Wofür macht das Sinn?
112
  @curr = $form->get_all_currencies();
112
  @curr = split(/:/, $form->{currencies});
113
  chomp $curr[0];
113 114
  $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
114
    $form->get_default_currency(\%myconfig);
115
    $curr[0];
115 116

  
116 117
  # Entsprechend präventiv die Auswahlliste für Währungen
117 118
  # auch mit value= zusammenbauen (s.a. oben bugfix 1771)
bin/mozilla/ic.pl
1489 1489
  IC->create_links("IC", \%myconfig, \%$form);
1490 1490

  
1491 1491
  # currencies
1492
  map({ $form->{selectcurrency} .= "<option>$_\n" } $::form->get_all_currencies());
1492
  map({ $form->{selectcurrency} .= "<option>$_\n" }
1493
      split(/:/, $form->{currencies}));
1493 1494

  
1494 1495
  # parts and assemblies have the same links
1495 1496
  my $item = $form->{item};
bin/mozilla/ir.pl
149 149
    $form->{currency} = $currency;
150 150
  }
151 151

  
152
  my @curr = $form->get_all_currencies();
152
  my @curr = split(/:/, $form->{currencies}); #seems to be missing
153 153
  map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
154 154

  
155 155
  $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
templates/webpages/am/edit_defaults.html
150 150
     <input type="hidden" name="rowcount" value="[% CURRENCIES.size %]">
151 151
     <th align="right">[% 'Currencies' | $T8 %]</th>
152 152
     <td colspan="3">[% FOREACH row = CURRENCIES %]<input name="curr_[% loop.count %]" size="3" value="[% HTML.escape(row.curr) %]">
153
                                                   <input type=hidden name="old_curr_[% loop.count %]" value="[% HTML.escape(row.curr) %]">
153
                                                   <input type=hidden name="old_curr_[% loop.count %]" value="[% HTML.escape(defaults_curr) %]">
154 154
                     [% END %]
155 155
                     <input name="new_curr" size="3" value="">
156 156
     </td>

Auch abrufbar als: Unified diff