Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision fc1e3973

Von Rolf Fluehmann vor mehr als 8 Jahren hinzugefügt

  • ID fc1e397330501fecd1ea62511c0965f0a5ef27b6
  • Vorgänger 335fc788
  • Nachfolger 030c2086

Erfolgsrechnung

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
  #injection-filter
1877
  $form->{fromdate} =~ s/[^0-9\.]//g;
1878
  $form->{todate} =~ s/[^0-9\.]//g;
1879
  #input validation
1880
  $form->{fromdate} = "01.01.2000" if $form->{fromdate} !~ m/[0-9]*\.[0-9]*\.[0-9]*/;
1881
  $form->{todate} = $form->current_date(%{$myconfig}) if $form->{todate} !~ m/[0-9]*\.[0-9]*\.[0-9]*/;
1882

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

  
1887
  $form->{total} = 0;
1888

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

  
1906
  $main::lxdebug->leave_sub();
1907
  return {};
1908
}
1909

  
1910
sub get_accounts_ch {
1911
  $main::lxdebug->enter_sub();
1912

  
1913
  my ($category) = @_;
1914
  my ($inclusion);
1915

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

  
1924
  my $query = qq|
1925
    SELECT id, accno, description, category
1926
    FROM chart
1927
    WHERE category = '$category' $inclusion
1928
    ORDER BY accno
1929
  |;
1930
  my $accounts = _query($query);
1931

  
1932
  $main::lxdebug->leave_sub();
1933
  return $accounts;
1934
}
1935

  
1936
sub get_total_ch {
1937
  $main::lxdebug->enter_sub();
1938

  
1939
  my ($chart_id, $fromdate, $todate) = @_;
1940
  my $total = 0;
1941
  my $query = qq|
1942
    SELECT SUM(amount)
1943
    FROM acc_trans
1944
    WHERE chart_id = '$chart_id'
1945
      AND transdate >= $fromdate
1946
      AND transdate <= $todate
1947
  |;
1948
  $total += _query($query)->[0]->{sum};
1949

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

  
1954
sub _query {return selectall_hashref_query($::form, $::form->get_standard_dbh, @_);}
1955

  
1869 1956
1;

Auch abrufbar als: Unified diff