Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 335fc788

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

  • ID 335fc788611b85c4879e701fba2892ec1ed2c8dd
  • Vorgänger 12727b13
  • Nachfolger fc1e3973

Revert "Erfolgsrechnung"

This reverts commit e3f8237101c331c52098cf6f7db86e1db2a2b36a.

Unterschiede anzeigen:

SL/RP.pm
1866 1866
  }
1867 1867
  $main::lxdebug->leave_sub();
1868 1868
}
1869

  
1870
sub erfolgsrechnung {
1871
  $main::lxdebug->enter_sub();
1872

  
1873
  my ($self, $myconfig, $form) = @_;
1874
  $form->{company} = $::instance_conf->get_company;
1875
  $form->{address} = $::instance_conf->get_address;
1876

  
1877
  # wrong user inputs should be handled during users input
1878
  # e.g.  spaces, tabs, wrong format or wrong dates
1879
  $form->{fromdate} = "01.01.2000" if !$form->{fromdate};
1880
  $form->{todate} = $form->current_date(%{$myconfig}) if !$form->{todate};
1881

  
1882
  my %categories = (I => "ERTRAG", E => "AUFWAND");
1883
  my $fromdate = conv_dateq($form->{fromdate});
1884
  my $todate = conv_dateq($form->{todate});
1885

  
1886
  $form->{total} = 0;
1887
  foreach my $category (keys %categories) {
1888
    my %category = (
1889
      name => $categories{$category},
1890
      total => 0,
1891
      accounts => get_accounts_ch($category),
1892
    );
1893
    foreach my $account (@{$category{accounts}}) {
1894
      $account->{total} += ($account->{category} eq $category ? 1 : -1) * get_total_ch($account->{id}, $fromdate, $todate);
1895
      $category{total} += $account->{total};
1896
      $account->{total} = $form->format_amount($myconfig, $form->parse_amount($myconfig, $account->{total}), 2);
1897
    }
1898
    $form->{total} += $category{total};
1899
    $category{total} = $form->format_amount($myconfig, $form->parse_amount($myconfig, $category{total}), 2);
1900
    push(@{$form->{categories}}, \%category);
1901
  }
1902
  $form->{total} = $form->format_amount($myconfig, $form->parse_amount($myconfig, $form->{total}), 2);
1903

  
1904
  $main::lxdebug->leave_sub();
1905
  return {};
1906
}
1907

  
1908
sub get_accounts_ch {
1909
  $main::lxdebug->enter_sub();
1910

  
1911
  my ($category) = @_;
1912
  my ($inclusion);
1913

  
1914
  if ($category eq 'I') {
1915
    $inclusion = "AND pos_er = NULL OR pos_er > '0' AND pos_er <= '5'";
1916
  } elsif ($category eq 'E') {
1917
    $inclusion = "AND pos_er = NULL OR pos_er >= '6' AND pos_er < '100'";
1918
  } else {
1919
    $inclusion = "";
1920
  }
1921

  
1922
  my $query = qq|
1923
    SELECT id, accno, description, category
1924
    FROM chart
1925
    WHERE category = ? $inclusion
1926
    ORDER BY accno
1927
  |;
1928
  my $accounts = selectall_hashref_query($::form, $::form->get_standard_dbh, $query, $category);
1929

  
1930
  $main::lxdebug->leave_sub();
1931
  return $accounts;
1932
}
1933

  
1934
sub get_total_ch {
1935
  $main::lxdebug->enter_sub();
1936

  
1937
  my ($chart_id, $fromdate, $todate) = @_;
1938
  my $total = 0;
1939
  my $query = qq|
1940
    SELECT SUM(amount)
1941
    FROM acc_trans
1942
    WHERE chart_id = ?
1943
      AND transdate >= ?
1944
      AND transdate <= ?
1945
  |;
1946
  my $data = selectfirst_hashref_query($::form, $::form->get_standard_dbh, $query, $chart_id, $fromdate, $todate);
1947
  $total += $data->{sum};
1948

  
1949
  $main::lxdebug->leave_sub();
1950
  return $total;
1951
}
1952

  
1953 1869
1;

Auch abrufbar als: Unified diff