Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d331a3d7

Von Niclas Zimmermann vor mehr als 11 Jahren hinzugefügt

  • ID d331a3d77f0b24a301412799d2e9cc5fa1bf27ba
  • Vorgänger 9c8450d9
  • Nachfolger c25ec982

Nutzung der Tabelle currencies

Dieser Commmit passt den Code an, um die Tabelle currencies zu nutzen.

Unterschiede anzeigen:

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

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

  
1070 1066
  # these defaults are database wide
1071 1067

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

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

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

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

  
1109 1117
  $dbh->commit();
1110 1118

  
1111 1119
  $main::lxdebug->leave_sub();
......
1119 1127

  
1120 1128
  my $dbh = $form->get_standard_dbh($myconfig);
1121 1129

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

  
1124 1132
  # update name
1125 1133
  my $query = qq|UPDATE employee SET name = ? WHERE login = ?|;
......
1127 1135

  
1128 1136
  my $rc = $dbh->commit();
1129 1137

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

  
1134 1138
  $form->{businessnumber} =  $businessnumber;
1135 1139

  
1136 1140
  $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};
59 58

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

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

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

  
670 668
  # Get the AP accno.
671 669
  $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};
60 59

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

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

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

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

  
101 100
  $dbh->disconnect;
102 101

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

  
152 151
  my $query =
153
     qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, a.curr | .
152
     qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, cu.curr | .
154 153
     qq|FROM $arap a | .
155
     qq|WHERE (a.${vc}_id = ?) AND (COALESCE(a.curr, '') = ?) AND NOT (a.amount = a.paid)| .
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)| .
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 (COALESCE(curr, '') <> ?)
177
      AND ((SELECT cu.curr FROM currencies cu WHERE cu.id=${arap}.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 = ?) AND (a.id = ?)|;
253
        qq|WHERE (e.curr = (SELECT id FROM currencies WHERE 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;
71 72

  
72
  # remove any trailing whitespace
73
  $form->{curr} =~ s/\s*$//;
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}));
74 76

  
75
  $sth->finish;
76 77
  if ( $form->{salesman_id} ) {
77 78
    my $query =
78 79
      qq|SELECT ct.name AS salesman | .
......
319 320
    qq|user_password = ?, | .
320 321
    qq|c_vendor_id = ?, | .
321 322
    qq|klass = ?, | .
322
    qq|curr = ?, | .
323
    qq|curr = (SELECT id FROM currencies WHERE curr = ?), | .
323 324
    qq|taxincluded_checked = ? | .
324 325
    qq|WHERE id = ?|;
325 326
  my @values = (
......
362 363
    $form->{user_password},
363 364
    $form->{c_vendor_id},
364 365
    conv_i($form->{klass}),
365
    substr($form->{currency}, 0, 3),
366
    $form->{currency},
366 367
    $form->{taxincluded_checked} ne '' ? $form->{taxincluded_checked} : undef,
367 368
    $form->{id}
368 369
    );
......
471 472
    qq|  username = ?, | .
472 473
    qq|  user_password = ?, | .
473 474
    qq|  v_customer_id = ?, | .
474
    qq|  curr = ? | .
475
    qq|  curr = (SELECT id FROM currencies WHERE curr = ?) | .
475 476
    qq|WHERE id = ?|;
476 477
  my @values = (
477 478
    $form->{vendornumber},
......
511 512
    $form->{username},
512 513
    $form->{user_password},
513 514
    $form->{v_customer_id},
514
    substr($form->{currency}, 0, 3),
515
    $form->{currency},
515 516
    $form->{id}
516 517
    );
517 518
  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
         ?,                     -- curr
231
         (SELECT id FROM currencies WHERE curr = ?), -- 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
         ar.curr,
764
         (SELECT cu.curr FROM currencies cu WHERE cu.id=ar.curr) AS 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 = ?
351
         is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, curr = (SELECT id FROM currencies WHERE 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, dord.curr AS currency
619
         dord.taxzone_id, dord.taxincluded, dord.terms, (SELECT cu.curr FROM currencies cu WHERE cu.id=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

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

  
646 643
  $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 defaults|;
1494

  
1495
  my ($currency) = selectrow_query($self, $dbh, $query);
1496
  my ($defaultcurrency) = split m/:/, $currency;
1493
  $query = qq|SELECT curr FROM currencies WHERE id=(SELECT curr FROM defaults)|;
1497 1494

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

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

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

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

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

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

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

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

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

  
1590 1587

  
......
1617 1614

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

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

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

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

  
1638
  my ($curr)     = selectrow_query($self, $dbh, $query);
1639
  my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
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;
1640 1642

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

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

  
1649 1651
  my ($self, $myconfig) = @_;
1650
  my @currencies        = $self->get_all_currencies($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);
1651 1656

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

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

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

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

  
2194
  my $query = qq|SELECT curr AS currency FROM defaults|;
2195

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

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

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

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

  
2837 2840
    } else {
2838 2841

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

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

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

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

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

  
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

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

  
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};
60 61

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

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

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

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

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

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

  
952 947
  $form->{exchangerate}  = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "sell");
953 948

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

  
1103
  # remove any trailing whitespace
1104
  $form->{curr} =~ s/\s*$//;
1105

  
1106
  # use vendor currency if not empty
1107
  $form->{currency} = $form->{curr} if $form->{curr};
1098
  # use vendor currency
1099
  $form->{currency} = $form->{curr};
1108 1100

  
1109 1101
  $params->{creditremaining} = $params->{creditlimit};
1110 1102

  
......
1388 1380
  # fax and phone and email as vendor*
1389 1381
  my $query =
1390 1382
    qq|SELECT ct.*, cp.*, ct.notes as vendornotes, phone as vendorphone, fax as vendorfax, email as vendoremail,
1391
         ct.curr AS currency
1383
         (SELECT cu.curr FROM currencies cu WHERE cu.id=ct.curr) AS currency
1392 1384
       FROM vendor ct
1393 1385
       LEFT JOIN contacts cp ON (ct.id = cp.cp_cv_id)
1394 1386
       WHERE (ct.id = ?) $contact
......
1407 1399
  }
1408 1400

  
1409 1401
  map { $form->{$_} = $ref->{$_} } keys %$ref;
1410
  # remove any trailing whitespace
1411
  $form->{currency} =~ s/\s*$// if ($form->{currency});
1412 1402

  
1413 1403
  my $custom_variables = CVar->get_custom_variables('dbh'      => $dbh,
1414 1404
                                                    '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
         ct.curr AS currency
461
         (SELECT cu.curr FROM currencies cu WHERE cu.id=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

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

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

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

  
559
      $query = qq|INSERT INTO ar (id, invnumber) VALUES (?, ?)|;
560
      do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"});
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});
561 560

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

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

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

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

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

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

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

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

  
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};
1768
  # use customer currency
1769
  $form->{currency} = $form->{curr};
1780 1770

  
1781 1771
  $query =
1782 1772
    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) VALUES (?, '', ?)|;
314
    $query = qq|INSERT INTO oe (id, ordnumber, employee_id, curr) VALUES (?, '', ?, (SELECT curr FROM defaults))|;
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 = ?, closed = ?,
497
         shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, curr = (SELECT id FROM currencies WHERE 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
             substr($form->{currency}, 0, 3), $form->{closed} ? 't' : 'f',
509
             $form->{currency}, $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,
763
              d.curr AS currencies
762
                     (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id    = c.id) AS fxloss_accno
764 763
              $query_add
765 764
              FROM defaults d|;
766 765
  my $ref = selectfirst_hashref_query($form, $dbh, $query);
767 766
  map { $form->{$_} = $ref->{$_} } keys %$ref;
768 767

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

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

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

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

  
815 811
      # 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 = split(/:/, $form->{currencies});
113
  chomp $curr[0];
112
  @curr = $form->get_all_currencies();
114 113
  $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
115
    $curr[0];
114
    $form->get_default_currency(\%myconfig);
116 115

  
117 116
  # Entsprechend präventiv die Auswahlliste für Währungen
118 117
  # 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" }
1493
      split(/:/, $form->{currencies}));
1492
  map({ $form->{selectcurrency} .= "<option>$_\n" } $::form->get_all_currencies());
1494 1493

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

  
152
  my @curr = split(/:/, $form->{currencies}); #seems to be missing
152
  my @curr = $form->get_all_currencies();
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
145 145
     <input type="hidden" name="rowcount" value="[% CURRENCIES.size %]">
146 146
     <th align="right">[% 'Currencies' | $T8 %]</th>
147 147
     <td colspan="3">[% FOREACH row = CURRENCIES %]<input name="curr_[% loop.count %]" size="3" value="[% HTML.escape(row.curr) %]">
148
                                                   <input type=hidden name="old_curr_[% loop.count %]" value="[% HTML.escape(defaults_curr) %]">
148
                                                   <input type=hidden name="old_curr_[% loop.count %]" value="[% HTML.escape(row.curr) %]">
149 149
                     [% END %]
150 150
                     <input name="new_curr" size="3" value="">
151 151
     </td>

Auch abrufbar als: Unified diff