Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a4d74009

Von Niclas Zimmermann vor mehr als 11 Jahren hinzugefügt

  • ID a4d740099476b4383a40a21ab5472e75806f3f4f
  • Vorgänger 714a28b1
  • Nachfolger 96dbc076

Verbesserungen in Upgrade-Scripten

In den Scripten currencies.pl rm_whitespaces wurden einige Ver-
besserungen durchgeführt:
1. Umbenennung von Spalten curr in currency_id in allen Tabellen
außer currencies.
2. Umbenennung von Spalte curr in name in Tabelle currencies.
3. Update in rm_whitespaces wird jetzt in einer Schleife erledigt
anstatt für jede Tabelle eigenen Code zu schreiben.
4. Tabelle currencies hat jetzt id als Primärschlüssel und nicht
mehr curr.

Die oben aufgeführten Änderungen führen natürlich auch zu notwendigen
Änderungen im Programm, welche dieses Commit ebenfalls enthält.

Unterschiede anzeigen:

SL/AM.pm
1103 1103

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

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

  
......
1292 1292
  $sth->finish;
1293 1293

  
1294 1294
  #Get currencies:
1295
  $query = qq|SELECT curr FROM currencies ORDER BY id|;
1295
  $query = qq|SELECT name AS curr FROM currencies ORDER BY id|;
1296 1296

  
1297 1297
  $form->{CURRENCIES} = [];
1298 1298

  
......
1304 1304
  $sth->finish;
1305 1305

  
1306 1306
  #Which of them is the default currency?
1307
  $query = qq|SELECT curr AS defaultcurrency FROM currencies WHERE id = (SELECT curr FROM defaults LIMIT 1);|;
1307
  $query = qq|SELECT name AS defaultcurrency FROM currencies WHERE id = (SELECT currency_id FROM defaults LIMIT 1);|;
1308 1308
  $sth   = $dbh->prepare($query);
1309 1309
  $sth->execute || $form->dberror($query);
1310 1310

  
SL/AP.pm
184 184
    $query = qq|UPDATE ap SET
185 185
                invnumber = ?, transdate = ?, ordnumber = ?, vendor_id = ?, taxincluded = ?,
186 186
                amount = ?, duedate = ?, paid = ?, netamount = ?,
187
                curr = (SELECT id FROM currencies WHERE curr = ?), notes = ?, department_id = ?, storno = ?, storno_id = ?,
187
                currency_id = (SELECT id FROM currencies WHERE name = ?), notes = ?, department_id = ?, storno = ?, storno_id = ?,
188 188
                globalproject_id = ?, direct_debit = ?
189 189
               WHERE id = ?|;
190 190
    @values = ($form->{invnumber}, conv_date($form->{transdate}),
SL/AR.pm
134 134
    } else {
135 135
      $query = qq|SELECT nextval('glid')|;
136 136
      ($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=?))|;
137
      $query = qq|INSERT INTO ar (id, invnumber, employee_id, currency_id) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE name=?))|;
138 138
      do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}, $form->{currency});
139 139
      $form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh) unless $form->{invnumber};
140 140
    }
SL/CP.pm
149 149
  my $arap = $form->{arap} eq "ar" ? "ar" : "ap";
150 150

  
151 151
  my $query =
152
     qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, cu.curr | .
152
     qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, cu.name AS curr | .
153 153
     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)| .
154
     qq|LEFT JOIN currencies cu ON (cu.id=a.currency_id)| .
155
     qq|WHERE (a.${vc}_id = ?) AND cu.name = ? 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 ((SELECT cu.name FROM currencies cu WHERE cu.id=${arap}.currency_id) <> ?)
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.currency_id = (SELECT id FROM currencies WHERE name = ?)) AND (a.id = ?)|;
254 254
      my ($exchangerate) =
255 255
        selectrow_query($form, $dbh, $query,
256 256
                        $form->{currency}, $form->{"id_$i"});
SL/CT.pm
71 71
  $sth->finish;
72 72

  
73 73
  #get name of currency instead of id:
74
  $query = qq|SELECT curr FROM currencies WHERE id=?|;
74
  $query = qq|SELECT name AS curr FROM currencies WHERE id=?|;
75 75
  ($form->{curr}) = selectrow_query($form, $dbh, $query, conv_i($form->{curr}));
76 76

  
77 77
  if ( $form->{salesman_id} ) {
......
320 320
    qq|user_password = ?, | .
321 321
    qq|c_vendor_id = ?, | .
322 322
    qq|klass = ?, | .
323
    qq|curr = (SELECT id FROM currencies WHERE curr = ?), | .
323
    qq|currency_id = (SELECT id FROM currencies WHERE name = ?), | .
324 324
    qq|taxincluded_checked = ? | .
325 325
    qq|WHERE id = ?|;
326 326
  my @values = (
......
472 472
    qq|  username = ?, | .
473 473
    qq|  user_password = ?, | .
474 474
    qq|  v_customer_id = ?, | .
475
    qq|  curr = (SELECT id FROM currencies WHERE curr = ?) | .
475
    qq|  currency_id = (SELECT id FROM currencies WHERE name = ?) | .
476 476
    qq|WHERE id = ?|;
477 477
  my @values = (
478 478
    $form->{vendornumber},
SL/DN.pm
208 208
  $query =
209 209
    qq|INSERT INTO ar (id,          invnumber, transdate, gldate, customer_id,
210 210
                       taxincluded, amount,    netamount, paid,   duedate,
211
                       invoice,     curr,      notes,
211
                       invoice,     currency_id,      notes,
212 212
                       employee_id)
213 213
       VALUES (
214 214
         ?,                     -- id
......
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
         (SELECT id FROM currencies WHERE name = ?), -- 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
         (SELECT cu.name FROM currencies cu WHERE cu.id=ar.currency_id) 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 = (SELECT id FROM currencies WHERE curr = ?)
351
         is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, currency_id = (SELECT id FROM currencies WHERE name = ?)
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, (SELECT cu.name FROM currencies cu WHERE cu.id=dord.currency_id) 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)
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 name AS curr FROM currencies WHERE id=(SELECT currency_id FROM defaults)|;
1494 1494

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

  
......
1499 1499
    return;
1500 1500
  }
1501 1501

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

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

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

  
1574
  $query = qq|SELECT curr FROM currencies WHERE id = (SELECT curr FROM defaults)|;
1574
  $query = qq|SELECT name AS curr FROM currencies WHERE id = (SELECT currency_id FROM defaults)|;
1575 1575

  
1576 1576
  my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
1577 1577

  
......
1581 1581
  }
1582 1582

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

  
1587 1587

  
......
1614 1614

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

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

  
......
1631 1631
  my $dbh      = $self->get_standard_dbh($myconfig);
1632 1632
  my @currencies =();
1633 1633

  
1634
  my $query = qq|SELECT curr FROM currencies|;
1634
  my $query = qq|SELECT name AS curr FROM currencies|;
1635 1635

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

  
......
1650 1650

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

  
1655 1655
  my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
1656 1656

  
......
2707 2707
    $query =
2708 2708
      qq|SELECT
2709 2709
           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,
2710
           a.duedate, a.ordnumber, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.notes,
2711 2711
           a.intnotes, a.department_id, a.amount AS oldinvtotal,
2712 2712
           a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
2713 2713
           a.globalproject_id, ${extra_columns}
......
2812 2812
    $query =
2813 2813
      qq|SELECT
2814 2814
           d.closedto, d.revtrans,
2815
           (SELECT cu.curr FROM currencies cu WHERE cu.id=d.curr) AS defaultcurrency,
2815
           (SELECT cu.name FROM currencies cu WHERE cu.id=d.currency_id) AS defaultcurrency,
2816 2816
           (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2817 2817
           (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2818 2818
         FROM defaults d|;
......
2825 2825
    $query =
2826 2826
       qq|SELECT
2827 2827
            current_date AS transdate, d.closedto, d.revtrans,
2828
            (SELECT cu.curr FROM currencies cu WHERE cu.id=d.curr) AS defaultcurrency,
2828
            (SELECT cu.name FROM currencies cu WHERE cu.id=d.currency_id) AS defaultcurrency,
2829 2829
            (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2830 2830
            (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2831 2831
          FROM defaults d|;
......
2864 2864
                    "a.department_id"         => "department_id",
2865 2865
                    "d.description"           => "department",
2866 2866
                    "ct.name"                 => $table,
2867
                    "cu.curr"                 => "currency",
2867
                    "cu.name AS curr"         => "currency",
2868 2868
                    "current_date + ct.terms" => "duedate",
2869 2869
    );
2870 2870

  
......
2899 2899
                        FROM $arap a
2900 2900
                        LEFT JOIN $table     ct ON (a.${table}_id = ct.id)
2901 2901
                        LEFT JOIN department d  ON (a.department_id = d.id)
2902
                        LEFT JOIN currencies cu ON (cu.id=ct.curr)
2902
                        LEFT JOIN currencies cu ON (cu.id=ct.currency_id)
2903 2903
                        WHERE a.id = ?|;
2904 2904
  my $ref          = selectfirst_hashref_query($self, $dbh, $query, $trans_id);
2905 2905

  
SL/IR.pm
77 77
      &reverse_invoice($dbh, $form);
78 78
    } else {
79 79
      ($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});
80
      do_query($form, $dbh, qq|INSERT INTO ap (id, invnumber, currency_id) VALUES (?, '', (SELECT id FROM currencies WHERE name=?))|, $form->{id}, $form->{currency});
81 81
    }
82 82
  }
83 83

  
......
940 940
  $query = qq|SELECT cp_id, invnumber, transdate AS invdate, duedate,
941 941
                orddate, quodate, globalproject_id,
942 942
                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
943
                intnotes, (SELECT cu.name FROM currencies cu WHERE cu.id=ap.currency_id) AS currency, direct_debit
944 944
              FROM ap
945 945
              WHERE id = ?|;
946 946
  $ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id}));
......
1087 1087
         v.id AS vendor_id, v.name AS vendor, v.discount as vendor_discount,
1088 1088
         v.creditlimit, v.terms, v.notes AS intnotes,
1089 1089
         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,
1090
         v.street, v.zipcode, v.city, v.country, v.taxzone_id, (SELECT cu.name FROM currencies cu WHERE cu.id=v.currency_id) AS curr, v.direct_debit,
1091 1091
         $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
1092 1092
         b.description AS business
1093 1093
       FROM vendor v
......
1109 1109
  $query = qq|SELECT o.amount,
1110 1110
                (SELECT e.sell
1111 1111
                 FROM exchangerate e
1112
                 WHERE (e.curr = o.curr)
1112
                 WHERE (e.currency_id = o.currency_id)
1113 1113
                   AND (e.transdate = o.transdate)) AS exch
1114 1114
              FROM oe o
1115 1115
              WHERE (o.vendor_id = ?) AND (o.quotation = '0') AND (o.closed = '0')|;
......
1384 1384
  # fax and phone and email as vendor*
1385 1385
  my $query =
1386 1386
    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
1387
         (SELECT cu.name FROM currencies cu WHERE cu.id=ct.currency_id) AS currency
1388 1388
       FROM vendor ct
1389 1389
       LEFT JOIN contacts cp ON (ct.id = cp.cp_cv_id)
1390 1390
       WHERE (ct.id = ?) $contact
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
         (SELECT cu.name FROM currencies cu WHERE cu.id=ct.currency_id) 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
......
555 555
      $query = qq|SELECT nextval('glid')|;
556 556
      ($form->{"id"}) = selectrow_query($form, $dbh, $query);
557 557

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

  
561 561
      if (!$form->{invnumber}) {
......
1081 1081
                amount      = ?, netamount     = ?, paid          = ?,
1082 1082
                duedate     = ?, deliverydate  = ?, invoice       = ?, shippingpoint = ?,
1083 1083
                shipvia     = ?, terms         = ?, notes         = ?, intnotes      = ?,
1084
                curr        = (SELECT id FROM currencies WHERE curr= ?),
1084
                currency_id = (SELECT id FROM currencies WHERE name = ?),
1085 1085
                department_id = ?, payment_id    = ?, taxincluded   = ?,
1086 1086
                type        = ?, language_id   = ?, taxzone_id    = ?, shipto_id     = ?,
1087 1087
                employee_id = ?, salesman_id   = ?, storno_id     = ?, storno        = ?,
......
1574 1574
           a.orddate, a.quodate, a.globalproject_id,
1575 1575
           a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.gldate,
1576 1576
           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,
1577
           a.duedate, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.shipto_id, a.cp_id,
1578 1578
           a.employee_id, a.salesman_id, a.payment_id,
1579 1579
           a.language_id, a.delivery_customer_id, a.delivery_vendor_id, a.type,
1580 1580
           a.transaction_description, a.donumber, a.invnumber_for_credit_note,
......
1750 1750
         c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit, c.terms,
1751 1751
         c.email, c.cc, c.bcc, c.language_id, c.payment_id,
1752 1752
         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,
1753
         c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, (SELECT cu.name FROM currencies cu WHERE cu.id=c.currency_id) AS curr,
1754 1754
         c.taxincluded_checked, c.direct_debit,
1755 1755
         $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
1756 1756
         b.discount AS tradediscount, b.description AS business
......
1795 1795
  $query =
1796 1796
    qq|SELECT o.amount,
1797 1797
         (SELECT e.buy FROM exchangerate e
1798
          WHERE e.curr = o.curr
1798
          WHERE e.currency_id = o.currency_id
1799 1799
            AND e.transdate = o.transdate)
1800 1800
       FROM oe o
1801 1801
       WHERE o.customer_id = ?
SL/OE.pm
91 91
    qq|JOIN $vc ct ON (o.${vc}_id = ct.id) | .
92 92
    qq|LEFT JOIN employee e ON (o.employee_id = e.id) | .
93 93
    qq|LEFT JOIN employee s ON (o.salesman_id = s.id) | .
94
    qq|LEFT JOIN exchangerate ex ON (ex.curr = o.curr | .
94
    qq|LEFT JOIN exchangerate ex ON (ex.currency_id = o.currency_id | .
95 95
    qq|  AND ex.transdate = o.transdate) | .
96 96
    qq|LEFT JOIN project pr ON (o.globalproject_id = pr.id) | .
97 97
    qq|$periodic_invoices_joins | .
......
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, currency_id) VALUES (?, '', ?, (SELECT currency_id 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 = (SELECT id FROM currencies WHERE curr=?), closed = ?,
497
         shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, currency_id = (SELECT id FROM currencies WHERE name=?), 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 = ?
......
784 784
    $query =
785 785
      qq|SELECT o.cp_id, o.ordnumber, o.transdate, o.reqdate,
786 786
           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,
787
           (SELECT cu.name FROM currencies cu WHERE cu.id=o.currency_id) AS currency, e.name AS employee, o.employee_id, o.salesman_id,
788 788
           o.${vc}_id, cv.name AS ${vc}, o.amount AS invtotal,
789 789
           o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber,
790 790
           d.description AS department, o.payment_id, o.language_id, o.taxzone_id,
sql/Pg-upgrade2/currencies.pl
122 122
sub create_and_fill_table {
123 123
  my $self = shift;
124 124
  #Create an fill table currencies:
125
  my $query = qq|CREATE TABLE currencies (id INTEGER DEFAULT nextval(('id'::text)::regclass) UNIQUE NOT NULL, curr TEXT PRIMARY KEY)|;
125
  my $query = qq|CREATE TABLE currencies (id   SERIAL        PRIMARY KEY,
126
                                          name TEXT NOT NULL UNIQUE)|;
126 127
  $self->db_query($query);
127 128
  foreach my $item ( @_ ) {
128
    $query = qq|INSERT INTO currencies (curr) VALUES ('| . $item . qq|')|;
129
    $query = qq|INSERT INTO currencies (name) VALUES ('| . $item . qq|')|;
129 130
    $self->db_query($query);
130 131
  }
131 132

  
......
148 149
    $self->db_query($query);
149 150
  }
150 151

  
151
  #Create a new columns currency and update with curr.id:
152
  $query = qq|ALTER TABLE ap ADD currency INTEGER;
153
              ALTER TABLE ar ADD currency INTEGER;
154
              ALTER TABLE oe ADD currency INTEGER;
155
              ALTER TABLE customer ADD currency INTEGER;
156
              ALTER TABLE delivery_orders ADD currency INTEGER;
157
              ALTER TABLE exchangerate ADD currency INTEGER;
158
              ALTER TABLE vendor ADD currency INTEGER;
159
              ALTER TABLE defaults ADD currency INTEGER;|;
152
  #Create a new columns currency_id and update with curr.id:
153
  $query = qq|ALTER TABLE ap ADD currency_id INTEGER;
154
              ALTER TABLE ar ADD currency_id INTEGER;
155
              ALTER TABLE oe ADD currency_id INTEGER;
156
              ALTER TABLE customer ADD currency_id INTEGER;
157
              ALTER TABLE delivery_orders ADD currency_id INTEGER;
158
              ALTER TABLE exchangerate ADD currency_id INTEGER;
159
              ALTER TABLE vendor ADD currency_id INTEGER;
160
              ALTER TABLE defaults ADD currency_id INTEGER;|;
160 161
  $self->db_query($query);
161 162
  #Set defaultcurrency:
162
  $query = qq|UPDATE defaults SET currency= (SELECT id FROM currencies WHERE curr = '| . $main::form->{defaultcurrency} . qq|')|;
163
  $query = qq|UPDATE defaults SET currency_id= (SELECT id FROM currencies WHERE name = '| . $main::form->{defaultcurrency} . qq|')|;
163 164
  $self->db_query($query);
164
  $query = qq|UPDATE ap SET currency = (SELECT id FROM currencies c WHERE c.curr = ap.curr);
165
              UPDATE ar SET currency = (SELECT id FROM currencies c WHERE c.curr = ar.curr);
166
              UPDATE oe SET currency = (SELECT id FROM currencies c WHERE c.curr = oe.curr);
167
              UPDATE customer SET currency = (SELECT id FROM currencies c WHERE c.curr = customer.curr);
168
              UPDATE delivery_orders SET currency = (SELECT id FROM currencies c WHERE c.curr = delivery_orders.curr);
169
              UPDATE exchangerate SET currency = (SELECT id FROM currencies c WHERE c.curr = exchangerate.curr);
170
              UPDATE vendor SET currency = (SELECT id FROM currencies c WHERE c.curr = vendor.curr);|;
165
  $query = qq|UPDATE ap SET currency_id = (SELECT id FROM currencies c WHERE c.name = ap.curr);
166
              UPDATE ar SET currency_id = (SELECT id FROM currencies c WHERE c.name = ar.curr);
167
              UPDATE oe SET currency_id = (SELECT id FROM currencies c WHERE c.name = oe.curr);
168
              UPDATE customer SET currency_id = (SELECT id FROM currencies c WHERE c.name = customer.curr);
169
              UPDATE delivery_orders SET currency_id = (SELECT id FROM currencies c WHERE c.name = delivery_orders.curr);
170
              UPDATE exchangerate SET currency_id = (SELECT id FROM currencies c WHERE c.name = exchangerate.curr);
171
              UPDATE vendor SET currency_id = (SELECT id FROM currencies c WHERE c.name = vendor.curr);|;
171 172
  $self->db_query($query);
172 173

  
173 174
  #Drop column 'curr':
......
181 182
              ALTER TABLE defaults DROP COLUMN curr;|;
182 183
  $self->db_query($query);
183 184

  
184
  #Rename currency to curr:
185
  $query = qq|ALTER TABLE defaults RENAME COLUMN currency TO curr;
186
              ALTER TABLE ap RENAME COLUMN currency TO curr;
187
              ALTER TABLE ar RENAME COLUMN currency TO curr;
188
              ALTER TABLE oe RENAME COLUMN currency TO curr;
189
              ALTER TABLE customer RENAME COLUMN currency TO curr;
190
              ALTER TABLE delivery_orders RENAME COLUMN currency TO curr;
191
              ALTER TABLE exchangerate RENAME COLUMN currency TO curr;
192
              ALTER TABLE vendor RENAME COLUMN currency TO curr;|;
193
  $self->db_query($query);
194

  
195 185
  #Set NOT NULL constraints:
196
  $query = qq|ALTER TABLE ap ALTER COLUMN curr SET NOT NULL;
197
              ALTER TABLE ar ALTER COLUMN curr SET NOT NULL;
198
              ALTER TABLE oe ALTER COLUMN curr SET NOT NULL;
199
              ALTER TABLE customer ALTER COLUMN curr SET NOT NULL;
200
              ALTER TABLE delivery_orders ALTER COLUMN curr SET NOT NULL;
201
              ALTER TABLE exchangerate ALTER COLUMN curr SET NOT NULL;
202
              ALTER TABLE vendor ALTER COLUMN curr SET NOT NULL;
203
              ALTER TABLE defaults ALTER COLUMN curr SET NOT NULL;|;
186
  $query = qq|ALTER TABLE ap ALTER COLUMN currency_id SET NOT NULL;
187
              ALTER TABLE ar ALTER COLUMN currency_id SET NOT NULL;
188
              ALTER TABLE oe ALTER COLUMN currency_id SET NOT NULL;
189
              ALTER TABLE customer ALTER COLUMN currency_id SET NOT NULL;
190
              ALTER TABLE delivery_orders ALTER COLUMN currency_id SET NOT NULL;
191
              ALTER TABLE exchangerate ALTER COLUMN currency_id SET NOT NULL;
192
              ALTER TABLE vendor ALTER COLUMN currency_id SET NOT NULL;
193
              ALTER TABLE defaults ALTER COLUMN currency_id SET NOT NULL;|;
204 194
  $self->db_query($query);
205 195

  
206 196
  #Set foreign keys:
207
  $query = qq|ALTER TABLE ap ADD FOREIGN KEY (curr) REFERENCES currencies(id);
208
              ALTER TABLE ar ADD FOREIGN KEY (curr) REFERENCES currencies(id);
209
              ALTER TABLE oe ADD FOREIGN KEY (curr) REFERENCES currencies(id);
210
              ALTER TABLE customer ADD FOREIGN KEY (curr) REFERENCES currencies(id);
211
              ALTER TABLE delivery_orders ADD FOREIGN KEY (curr) REFERENCES currencies(id);
212
              ALTER TABLE exchangerate ADD FOREIGN KEY (curr) REFERENCES currencies(id);
213
              ALTER TABLE vendor ADD FOREIGN KEY (curr) REFERENCES currencies(id);
214
              ALTER TABLE defaults ADD FOREIGN KEY (curr) REFERENCES currencies(id);|;
197
  $query = qq|ALTER TABLE ap ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
198
              ALTER TABLE ar ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
199
              ALTER TABLE oe ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
200
              ALTER TABLE customer ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
201
              ALTER TABLE delivery_orders ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
202
              ALTER TABLE exchangerate ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
203
              ALTER TABLE vendor ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
204
              ALTER TABLE defaults ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);|;
215 205
  $self->db_query($query);
216 206

  
217 207
};
sql/Pg-upgrade2/rm_whitespaces.pl
11 11

  
12 12
sub run {
13 13
  my ($self) = @_;
14
  my $query = qq|UPDATE ar SET curr = RTRIM(LTRIM(curr))|;
15
  $self->db_query($query);
16
  $query = qq|UPDATE ap SET curr = RTRIM(LTRIM(curr))|;
17
  $self->db_query($query);
18
  $query = qq|UPDATE oe SET curr = RTRIM(LTRIM(curr))|;
19
  $self->db_query($query);
20
  $query = qq|UPDATE customer SET curr = RTRIM(LTRIM(curr))|;
21
  $self->db_query($query);
22
  $query = qq|UPDATE delivery_orders SET curr = RTRIM(LTRIM(curr))|;
23
  $self->db_query($query);
24
  $query = qq|UPDATE exchangerate SET curr = RTRIM(LTRIM(curr))|;
25
  $self->db_query($query);
26
  $query = qq|UPDATE vendor SET curr = RTRIM(LTRIM(curr))|;
27
  $self->db_query($query);
14

  
15
  my $query;
16

  
17
  foreach my $table (qw(ar ap oe customer delivery_orders exchangerate vendor)){
18
    $self->db_query(qq|UPDATE ${table} SET curr=BTRIM(curr)|)
19
  }
28 20

  
29 21
  $query = qq|SELECT curr FROM defaults|;
30 22
  my ($curr)     = $self->dbh->selectrow_array($query);

Auch abrufbar als: Unified diff