Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision be776964

Von Niclas Zimmermann vor mehr als 11 Jahren hinzugefügt

  • ID be776964b83340e69fa2f02eae59b703c0c95b88
  • Vorgänger 6d06b178
  • Nachfolger 014161b8

Nutzung der Tabelle currencies

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

Unterschiede anzeigen:

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

  

Auch abrufbar als: Unified diff