Erfolgsrechnung
authorRolf Fluehmann <rolf.fluehmann@revamp-it.ch>
Mon, 4 Jan 2016 15:58:53 +0000 (16:58 +0100)
committerSven Schöling <s.schoeling@linet-services.de>
Tue, 5 Jan 2016 13:47:22 +0000 (14:47 +0100)
SL/RP.pm
bin/mozilla/rp.pl
menus/user/00-erp.yaml
templates/webpages/rp/erfolgsrechnung.html [new file with mode: 0644]
templates/webpages/rp/report.html

index b2fd5e0..09c8d1c 100644 (file)
--- a/SL/RP.pm
+++ b/SL/RP.pm
@@ -1871,4 +1871,88 @@ sub income_statement {
   }
   $main::lxdebug->leave_sub();
 }
+
+sub erfolgsrechnung {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+  $form->{company} = $::instance_conf->get_company;
+  $form->{address} = $::instance_conf->get_address;
+
+  # wrong user inputs should be handled during users input
+  # e.g.  spaces, tabs, wrong format or wrong dates
+  $form->{fromdate} = "01.01.2000" if !$form->{fromdate};
+  $form->{todate} = $form->current_date(%{$myconfig}) if !$form->{todate};
+
+  my %categories = (I => "ERTRAG", E => "AUFWAND");
+  my $fromdate = conv_dateq($form->{fromdate});
+  my $todate = conv_dateq($form->{todate});
+
+  $form->{total} = 0;
+  foreach my $category (keys %categories) {
+    my %category = (
+      name => $categories{$category},
+      total => 0,
+      accounts => get_accounts_ch($category),
+    );
+    foreach my $account (@{$category{accounts}}) {
+      $account->{total} += ($account->{category} eq $category ? 1 : -1) * get_total_ch($account->{id}, $fromdate, $todate);
+      $category{total} += $account->{total};
+      $account->{total} = $form->format_amount($myconfig, $form->parse_amount($myconfig, $account->{total}), 2);
+    }
+    $form->{total} += $category{total};
+    $category{total} = $form->format_amount($myconfig, $form->parse_amount($myconfig, $category{total}), 2);
+    push(@{$form->{categories}}, \%category);
+  }
+  $form->{total} = $form->format_amount($myconfig, $form->parse_amount($myconfig, $form->{total}), 2);
+
+  $main::lxdebug->leave_sub();
+  return {};
+}
+
+sub get_accounts_ch {
+  $main::lxdebug->enter_sub();
+
+  my ($category) = @_;
+  my ($inclusion);
+
+  if ($category eq 'I') {
+    $inclusion = "AND pos_eur = NULL OR pos_eur > '0' AND pos_eur <= '5'";
+  } elsif ($category eq 'E') {
+    $inclusion = "AND pos_eur = NULL OR pos_eur >= '6' AND pos_eur < '100'";
+  } else {
+    $inclusion = "";
+  }
+
+  my $query = qq|
+    SELECT id, accno, description, category
+    FROM chart
+    WHERE category = ? $inclusion
+    ORDER BY accno
+  |;
+  my $accounts = selectall_hashref_query($::form, $::form->get_standard_dbh, $query, $category);
+
+  $main::lxdebug->leave_sub();
+  return $accounts;
+}
+
+sub get_total_ch {
+  $main::lxdebug->enter_sub();
+
+  my ($chart_id, $fromdate, $todate) = @_;
+  my $total = 0;
+  my $query = qq|
+    SELECT SUM(amount)
+    FROM acc_trans
+    WHERE chart_id = ?
+      AND transdate >= ?
+      AND transdate <= ?
+  |;
+  my $data = selectfirst_hashref_query($::form, $::form->get_standard_dbh, $query, $chart_id, $fromdate, $todate);
+  $total += $data->{sum};
+
+  $main::lxdebug->leave_sub();
+  return $total;
+}
+
 1;
index ae2669f..87f84b2 100644 (file)
@@ -101,15 +101,16 @@ use strict;
 # $form->parse_html_template('rp/html_report_susa')
 
 my $rp_access_map = {
-  'projects'         => 'report',
-  'ar_aging'         => 'general_ledger',
-  'ap_aging'         => 'general_ledger',
-  'receipts'         => 'cash',
-  'payments'         => 'cash',
-  'trial_balance'    => 'report',
-  'income_statement' => 'report',
-  'bwa'              => 'report',
-  'balance_sheet'    => 'report',
+  'projects'           => 'report',
+  'ar_aging'           => 'general_ledger',
+  'ap_aging'           => 'general_ledger',
+  'receipts'           => 'cash',
+  'payments'           => 'cash',
+  'trial_balance'      => 'report',
+  'income_statement'   => 'report',
+  'erfolgsrechnung'    => 'report',
+  'bwa'                => 'report',
+  'balance_sheet'      => 'report',
 };
 
 sub check_rp_access {
@@ -129,6 +130,7 @@ sub report {
   my %title = (
     balance_sheet        => $::locale->text('Balance Sheet'),
     income_statement     => $::locale->text('Income Statement'),
+    erfolgsrechnung      => $::locale->text('Erfolgsrechnung'),
     trial_balance        => $::locale->text('Trial Balance'),
     ar_aging             => $::locale->text('Search AR Aging'),
     ap_aging             => $::locale->text('Search AP Aging'),
@@ -142,6 +144,8 @@ sub report {
 
   $::form->{title} = $title{$::form->{report}};
   $::request->{layout}->add_javascripts('autocomplete_customer.js');
+  $::form->{fromdate} = DateTime->today->truncate(to => 'year')->to_kivitendo;
+  $::form->{todate} = DateTime->today->truncate(to => 'year')->add(years => 1)->add(days => -1)->to_kivitendo;
 
   # get departments
   $::form->all_departments(\%::myconfig);
@@ -152,13 +156,14 @@ sub report {
 
   $::form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 });
 
-  my $is_projects         = $::form->{report} eq "projects";
-  my $is_income_statement = $::form->{report} eq "income_statement";
-  my $is_bwa              = $::form->{report} eq "bwa";
-  my $is_balance_sheet    = $::form->{report} eq "balance_sheet";
-  my $is_trial_balance    = $::form->{report} eq "trial_balance";
-  my $is_aging            = $::form->{report} =~ /^a[rp]_aging$/;
-  my $is_payments         = $::form->{report} =~ /(receipts|payments)$/;
+  my $is_projects            = $::form->{report} eq "projects";
+  my $is_income_statement    = $::form->{report} eq "income_statement";
+  my $is_erfolgsrechnung     = $::form->{report} eq "erfolgsrechnung";
+  my $is_bwa                 = $::form->{report} eq "bwa";
+  my $is_balance_sheet       = $::form->{report} eq "balance_sheet";
+  my $is_trial_balance       = $::form->{report} eq "trial_balance";
+  my $is_aging               = $::form->{report} =~ /^a[rp]_aging$/;
+  my $is_payments            = $::form->{report} =~ /(receipts|payments)$/;
 
   my ($label, $nextsub, $vc);
   if ($is_aging) {
@@ -191,20 +196,21 @@ sub report {
 
   $::form->header;
   print $::form->parse_html_template('rp/report', {
-    paymentaccounts     => $paymentaccounts,
-    selection           => $selection,
-    is_aging            => $is_aging,
-    vc                  => $vc,
-    label               => $label,
-    year                => DateTime->today->year,
-    today               => DateTime->today,
-    nextsub             => $nextsub,
-    is_payments         => $is_payments,
-    is_trial_balance    => $is_trial_balance,
-    is_balance_sheet    => $is_balance_sheet,
-    is_bwa              => $is_bwa,
-    is_income_statement => $is_income_statement,
-    is_projects         => $is_projects,
+    paymentaccounts        => $paymentaccounts,
+    selection              => $selection,
+    is_aging               => $is_aging,
+    vc                     => $vc,
+    label                  => $label,
+    year                   => DateTime->today->year,
+    today                  => DateTime->today,
+    nextsub                => $nextsub,
+    is_payments            => $is_payments,
+    is_trial_balance       => $is_trial_balance,
+    is_balance_sheet       => $is_balance_sheet,
+    is_bwa                 => $is_bwa,
+    is_income_statement    => $is_income_statement,
+    is_erfolgsrechnung     => $is_erfolgsrechnung,
+    is_projects            => $is_projects,
   });
 
   $::lxdebug->leave_sub;
@@ -395,6 +401,25 @@ sub generate_income_statement {
   $main::lxdebug->leave_sub();
 }
 
+sub generate_erfolgsrechnung {
+  $::lxdebug->enter_sub;
+  $::auth->assert('report');
+
+  $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
+  $::form->{padding}       = "&emsp;";
+  $::form->{bold}          = "<b>";
+  $::form->{endbold}       = "</b>";
+  $::form->{br}            = "<br>";
+
+  my $data = RP->erfolgsrechnung(\%::myconfig, $::form);
+
+  $::form->header();
+  print $::form->parse_html_template('rp/erfolgsrechnung', $data);
+
+  $::lxdebug->leave_sub;
+}
+
+
 sub generate_balance_sheet {
   $::lxdebug->enter_sub;
   $::auth->assert('report');
index 53d0586..f693a0f 100644 (file)
   params:
     action: report
     report: trial_balance
+- parent: reports
+  id: reports_erfolgsrechnung
+  name: Erfolgsrechnung
+  icon: income_statement
+  order: 300
+  access: report
+  module: rp.pl
+  params:
+    action: report
+    report: erfolgsrechnung
 - parent: reports
   id: reports_income_statement
   name: Income Statement
diff --git a/templates/webpages/rp/erfolgsrechnung.html b/templates/webpages/rp/erfolgsrechnung.html
new file mode 100644 (file)
index 0000000..f3a73c7
--- /dev/null
@@ -0,0 +1,40 @@
+[%- USE T8 %]
+[%- USE HTML %]
+[%- USE LxERP %]
+
+<h2 align="center">
+  <br>[% company %]
+  <br>[% address %]
+  <p>[% 'ERFOLGSRECHNUNG' %]
+  <br>[% fromdate %] bis [% todate %]
+</h2>
+<table border="0">
+  <tr>
+    <th align="left" width="400" colspan="2"><br></th>
+  </tr>
+  [%- FOREACH category = categories %]
+    <tr valign="top">
+      <th align="left" colspan="4">[% category.name %]<b><hr align="left" width="250" size="5" noshade></th>
+    </tr>
+    [%- FOREACH row = category.accounts %]
+      <tr>
+        <td align="left">[% row.accno %]</td>
+        <td align="left">[% row.description %]</td>
+        <td align="right">[% row.total %]</td>
+      </tr>
+    [%- END %]
+    <tr>
+      <td colspan="2"> </td>
+      <td><hr noshade size="1"></td>
+      <td><hr noshade size="1"></td>
+    </tr>
+    <tr valign="top">
+      <th align="left" colspan="2">TOTAL</th>
+      <td align="right">[% category.total %]<hr noshade size="2"></td>
+    </tr>
+  [%- END %]
+  <tr valign="top">
+    <th align="left" colspan="2">GEWINN/VERLUST</th>
+    <td align="right">[% total %]<br><hr noshade size="2"></td>
+  </tr>
+</table>
index 2e9775a..1eb5e48 100644 (file)
@@ -9,7 +9,9 @@
   </tr>
   <tr>
     <th colspan=1>[% 'Year' | $T8 %]</th>
-    <td><input name=year size=11 title="[% 'YYYY' | $T8 %]" value="[% year %]" class="initial_focus"></td>
+    <td>
+      <input name=year size=11 title="[% 'YYYY' | $T8 %]" value="[% year %]" class="initial_focus" oninput='set_from_to(duetyp.value, this.value)'>
+    </td>
   </tr>
   <tr>
     <td align=right> <b>[% 'Yearly' | $T8 %]</b> </td>
     <th align=left colspan=3>[% 'Monthly' | $T8 %]</th>
   </tr>
   <tr>
-    <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"></td>
-    <td><input name=duetyp class=radio type=radio value="A">&nbsp;1. [% 'Quarter' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="1" checked>&nbsp;[% 'January' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="5">&nbsp;[% 'May' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="9">&nbsp;[% 'September' | $T8 %]</td>
+    <td align=right>&nbsp;
+      <input name=duetyp class=radio type=radio value="13" onchange='set_from_to(this.value, year.value)'>
+    </td>
+    <td><input name=duetyp class=radio type=radio value="A" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;1. [% 'Quarter' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="1" checked onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'January' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="5" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'May' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="9" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'September' | $T8 %]
+    </td>
   </tr>
   <tr>
     <td align= right>&nbsp;</td>
-    <td><input name=duetyp class=radio type=radio value="B">&nbsp;2. [% 'Quarter' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="2">&nbsp;[% 'February' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="6">&nbsp;[% 'June' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="10">&nbsp;[% 'October' | $T8 %]</td>
+    <td><input name=duetyp class=radio type=radio value="B" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;2. [% 'Quarter' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="2" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'February' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="6" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'June' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="10" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'October' | $T8 %]
+    </td>
   </tr>
   <tr>
     <td> &nbsp;</td>
-    <td><input name=duetyp class=radio type=radio value="C">&nbsp;3. [% 'Quarter' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="3">&nbsp;[% 'March' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="7">&nbsp;[% 'July' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="11">&nbsp;[% 'November' | $T8 %]</td>
+    <td><input name=duetyp class=radio type=radio value="C" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;3. [% 'Quarter' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="3" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'March' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="7" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'July' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="11" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'November' | $T8 %]
+    </td>
   </tr>
   <tr>
     <td> &nbsp;</td>
-    <td><input name=duetyp class=radio type=radio value="D">&nbsp;4. [% 'Quarter' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="4">&nbsp;[% 'April' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="8">&nbsp;[% 'August' | $T8 %]</td>
-    <td><input name=duetyp class=radio type=radio value="12">&nbsp;[% 'December' | $T8 %]</td>
+    <td><input name=duetyp class=radio type=radio value="D" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;4. [% 'Quarter' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="4" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'April' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="8" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'August' | $T8 %]
+    </td>
+    <td><input name=duetyp class=radio type=radio value="12" onchange='set_from_to(this.value, year.value)'>
+      &nbsp;[% 'December' | $T8 %]
+    </td>
   </tr>
   <tr>
     <td colspan=5><hr size=3 noshade></td>
@@ -51,7 +87,7 @@
     <th align=left><input name=reporttype class=radio type=radio value="free">[% 'Free report period' | $T8 %]</th>
     <td align=left colspan=4>
       [% 'From' | $T8 %] [% L.date_tag('fromdate', fromdate) %]
-      [% 'Bis' | $T8 %] [% L.date_tag('todate') %]
+      [% 'Bis' | $T8 %] [% L.date_tag('todate', todate)  %]
     </td>
   </tr>
   <tr>
   </tr>
 [%- END %]
 
+
 [%- IF is_bwa %]
 [%- PROCESS projectnumber %]
   <input type=hidden name=nextsub value=generate_bwa>
   </tr>
 [%- END %]
 
+
+[%- IF is_erfolgsrechnung %]
+  <input type=hidden name=nextsub value=generate_erfolgsrechnung>
+</table>
+<table>
+[%- PROCESS customized_report %]
+[%- END %]
+
+
 [%- IF is_balance_sheet %]
   <input type=hidden name=nextsub value=generate_balance_sheet>
   <tr>
 <input type=submit class=submit name=action value="[% 'Continue' | $T8 %]">
 
 </form>
+
+<script type="text/javascript">
+function format_date(yy, mm, dd) {
+  var format = "[% dateformat %]";
+  format = format.replace("yyyy", "yy");
+  format = format.replace("yy", yy);
+  format = format.replace("mm", mm);
+  format = format.replace("dd", dd);
+  return format;
+}
+function set_from_to(duetyp, year) {
+  switch(duetyp) {
+    case '1':
+      document.getElementById('fromdate').value=format_date(year, '01', '01');
+      document.getElementById('todate').value=format_date(year, '01', '31');
+    break;
+    case '2':
+      document.getElementById('fromdate').value=format_date(year, '02', '01');
+      if(year % 4) document.getElementById('todate').value=format_date(year, '02', '28');
+      else document.getElementById('todate').value=format_date(year, '2', '29');
+    break;
+    case '3':
+      document.getElementById('fromdate').value=format_date(year, '03', '01');
+      document.getElementById('todate').value=format_date(year, '03', '31');
+    break;
+    case '4':
+      document.getElementById('fromdate').value=format_date(year, '04', '01');
+      document.getElementById('todate').value=format_date(year, '04', '30');
+    break;
+    case '5':
+      document.getElementById('fromdate').value=format_date(year, '05', '01');
+      document.getElementById('todate').value=format_date(year, '05', '31');
+    break;
+    case '6':
+      document.getElementById('fromdate').value=format_date(year, '06', '01');
+      document.getElementById('todate').value=format_date(year, '06', '30');
+    break;
+    case '7':
+      document.getElementById('fromdate').value=format_date(year, '07', '01');
+      document.getElementById('todate').value=format_date(year, '07', '31');
+    break;
+    case '8':
+      document.getElementById('fromdate').value=format_date(year, '08', '01');
+      document.getElementById('todate').value=format_date(year, '08', '31');
+    break;
+    case '9':
+      document.getElementById('fromdate').value=format_date(year, '09', '01');
+      document.getElementById('todate').value=format_date(year, '09', '30');
+    break;
+    case '10':
+      document.getElementById('fromdate').value=format_date(year, '10', '01');
+      document.getElementById('todate').value=format_date(year, '10', '31');
+    break;
+    case '11':
+      document.getElementById('fromdate').value=format_date(year, '11', '01');
+      document.getElementById('todate').value=format_date(year, '11', '30');
+    break;
+    case '12':
+      document.getElementById('fromdate').value=format_date(year, '12', '01');
+      document.getElementById('todate').value=format_date(year, '12', '31');
+    break;
+    case '13':
+      document.getElementById('fromdate').value=format_date(year, '01', '01');
+      document.getElementById('todate').value=format_date(year, '12', '31');
+    break;
+    case 'A':
+      document.getElementById('fromdate').value=format_date(year, '01', '01');
+      document.getElementById('todate').value=format_date(year, '03', '31');
+    break;
+    case 'B':
+      document.getElementById('fromdate').value=format_date(year, '04', '01');
+      document.getElementById('todate').value=format_date(year, '06', '30');
+    break;
+    case 'C':
+      document.getElementById('fromdate').value=format_date(year, '07', '01');
+      document.getElementById('todate').value=format_date(year, '09', '31');
+    break;
+    case 'D':
+      document.getElementById('fromdate').value=format_date(year, '10', '01');
+      document.getElementById('todate').value=format_date(year, '12', '31');
+    break;
+    default:
+      document.getElementById('fromdate').value=format_date(year, '01', '01');
+      document.getElementById('todate').value=format_date(year, '12', '31');
+  }
+  return true;
+}
+</script>
+