Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1228aa97

Von Sven Schöling vor mehr als 14 Jahren hinzugefügt

  • ID 1228aa97dd33175f74c5dfbdf759a6b3d9458f93
  • Vorgänger dd011621
  • Nachfolger 6f7c3b10

IC->retrieve_account umgeschrieben auf batchmode.

Unterschiede anzeigen:

SL/IC.pm
1479 1479
sub retrieve_accounts {
1480 1480
  $main::lxdebug->enter_sub(2);
1481 1481

  
1482
  my ($self, $myconfig, $form, $parts_id, $index) = @_;
1482
  my $self     = shift;
1483
  my $myconfig = shift;
1484
  my $form     = shift;
1485
  my $dbh      = $form->get_standard_dbh;
1486
  my %args     = @_;     # part_id => index
1483 1487

  
1484 1488
  my ($query, $sth);
1485 1489

  
1486 1490
  $form->{taxzone_id} *= 1;
1487 1491

  
1488
  my $dbh = $form->get_standard_dbh;
1489

  
1492
  # transdate madness.
1490 1493
  my $transdate = "";
1491 1494
  if ($form->{type} eq "invoice") {
1492 1495
    if (($form->{vc} eq "vendor") || !$form->{deliverydate}) {
......
1505 1508
  } else {
1506 1509
    $transdate = $dbh->quote($transdate);
1507 1510
  }
1511
  #/transdate
1508 1512

  
1509
  $query = <<SQL;
1513
  my $sth_accno = prepare_query($::form, $dbh, <<SQL);
1510 1514
    SELECT
1511 1515
      p.inventory_accno_id AS is_part,
1512 1516
      bg.inventory_accno_id,
......
1522 1526
    LEFT JOIN chart c3 ON bg.expense_accno_id_$form->{taxzone_id} = c3.id
1523 1527
    WHERE p.id = ?
1524 1528
SQL
1525
  my $ref = selectfirst_hashref_query($form, $dbh, $query, $parts_id);
1526

  
1527
  return $main::lxdebug->leave_sub(2) if (!$ref);
1528

  
1529
  $ref->{"inventory_accno_id"} = undef unless ($ref->{"is_part"});
1530

  
1531
  my %accounts;
1532
  foreach my $type (qw(inventory income expense)) {
1533
    next unless ($ref->{"${type}_accno_id"});
1534
    ($accounts{"${type}_accno_id"}, $accounts{"${type}_accno"}) =
1535
      $self->follow_account_chain($form, $dbh, $transdate,
1536
                                  $ref->{"${type}_accno_id"},
1537
                                  $ref->{"${type}_accno"});
1538
  }
1539

  
1540
  map { $form->{"${_}_accno_$index"} = $accounts{"${_}_accno"} }
1541
      qw(inventory income expense);
1542

  
1543
  my $inc_exp = $form->{"vc"} eq "customer" ? "income" : "expense";
1544
  my $accno_id = $accounts{"${inc_exp}_accno_id"};
1545 1529

  
1546
  $query = <<SQL;
1530
  my $sth_tx = prepare_query($::form, $dbh, <<SQL);
1547 1531
    SELECT c.accno, t.taxdescription AS description, t.rate, t.taxnumber
1548 1532
    FROM tax t
1549 1533
    LEFT JOIN chart c ON c.id = t.chart_id
......
1553 1537
       WHERE tk.chart_id = ? AND startdate <= ?
1554 1538
       ORDER BY startdate DESC LIMIT 1)
1555 1539
SQL
1556
  $ref = selectfirst_hashref_query($form, $dbh, $query, $accno_id, quote_db_date($transdate));
1557 1540

  
1558
  unless ($ref) {
1559
    $::lxdebug->leave_sub(2);
1560
    return;
1561
  }
1541
  while (my ($part_id, $index) = each %args) {
1542
    my $ref = $sth_accno->fetchrow_hashref($part_id) or next;
1543

  
1544
    $ref->{"inventory_accno_id"} = undef unless $ref->{"is_part"};
1545

  
1546
    my %accounts;
1547
    for my $type (qw(inventory income expense)) {
1548
      next unless $ref->{"${type}_accno_id"};
1549
      ($accounts{"${type}_accno_id"}, $accounts{"${type}_accno"}) =
1550
        $self->follow_account_chain($form, $dbh, $transdate, $ref->{"${type}_accno_id"}, $ref->{"${type}_accno"});
1551
    }
1552

  
1553
    $form->{"${_}_accno_$index"} = $accounts{"${_}_accno"} for qw(inventory income expense);
1554

  
1555
    my $inc_exp = $form->{"vc"} eq "customer" ? "income" : "expense";
1556
    $ref = $sth->fetchrow_hashref($accounts{"${inc_exp}_accno_id"}, quote_db_date($transdate)) or next;
1557

  
1558
    $form->{"taxaccounts_$index"} = $ref->{"accno"};
1559
    $form->{"taxaccounts"} .= "$ref->{accno} "if $form->{"taxaccounts"} !~ /$ref->{accno}/;
1562 1560

  
1563
  $form->{"taxaccounts_$index"} = $ref->{"accno"};
1564
  if ($form->{"taxaccounts"} !~ /$ref->{accno}/) {
1565
    $form->{"taxaccounts"} .= "$ref->{accno} ";
1561
    $form->{"$ref->{accno}_${_}"} = $ref->{$_} for qw(rate description taxnumber);
1566 1562
  }
1567
  map { $form->{"$ref->{accno}_${_}"} = $ref->{$_}; } qw(rate description taxnumber);
1568 1563

  
1569 1564
  $::lxdebug->leave_sub(2);
1570 1565
}

Auch abrufbar als: Unified diff