1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
   9 # Copyright (c) 1998-2002
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  15 #  Contributors: Antonio Gallardo <agssa@ibw.com.ni>
 
  16 #                Benjamin Lee <benjaminlee@consultant.com>
 
  17 #                Philip Reetz <p.reetz@linet-services.de>
 
  20 # This program is free software; you can redistribute it and/or modify
 
  21 # it under the terms of the GNU General Public License as published by
 
  22 # the Free Software Foundation; either version 2 of the License, or
 
  23 # (at your option) any later version.
 
  25 # This program is distributed in the hope that it will be useful,
 
  26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  28 # GNU General Public License for more details.
 
  29 # You should have received a copy of the GNU General Public License
 
  30 # along with this program; if not, write to the Free Software
 
  31 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  32 #======================================================================
 
  34 # module for preparing Income Statement and Balance Sheet
 
  36 #======================================================================
 
  38 use POSIX qw(strftime);
 
  43 use SL::ReportGenerator;
 
  46 require "bin/mozilla/arap.pl";
 
  47 require "bin/mozilla/common.pl";
 
  48 require "bin/mozilla/reportgenerator.pl";
 
  50 # note: this file was particularly hard to strictify.
 
  51 # alot of the vars are passed carelessly between invocations
 
  52 # should there be any missing vars, declare them globally
 
  55 # this is for our long dates
 
  56 # $locale->text('January')
 
  57 # $locale->text('February')
 
  58 # $locale->text('March')
 
  59 # $locale->text('April')
 
  60 # $locale->text('May ')
 
  61 # $locale->text('June')
 
  62 # $locale->text('July')
 
  63 # $locale->text('August')
 
  64 # $locale->text('September')
 
  65 # $locale->text('October')
 
  66 # $locale->text('November')
 
  67 # $locale->text('December')
 
  69 # this is for our short month
 
  70 # $locale->text('Jan')
 
  71 # $locale->text('Feb')
 
  72 # $locale->text('Mar')
 
  73 # $locale->text('Apr')
 
  74 # $locale->text('May')
 
  75 # $locale->text('Jun')
 
  76 # $locale->text('Jul')
 
  77 # $locale->text('Aug')
 
  78 # $locale->text('Sep')
 
  79 # $locale->text('Oct')
 
  80 # $locale->text('Nov')
 
  81 # $locale->text('Dec')
 
  83 # $locale->text('Balance Sheet')
 
  84 # $locale->text('Income Statement')
 
  85 # $locale->text('Trial Balance')
 
  86 # $locale->text('AR Aging')
 
  87 # $locale->text('AP Aging')
 
  88 # $locale->text('Tax collected')
 
  89 # $locale->text('Tax paid')
 
  90 # $locale->text('Receipts')
 
  91 # $locale->text('Payments')
 
  92 # $locale->text('Project Transactions')
 
  93 # $locale->text('Non-taxable Sales')
 
  94 # $locale->text('Non-taxable Purchases')
 
  96 # $form->parse_html_template('rp/html_report_susa')
 
  99   'projects'         => 'report',
 
 100   'ar_aging'         => 'general_ledger',
 
 101   'ap_aging'         => 'general_ledger',
 
 102   'receipts'         => 'cash',
 
 103   'payments'         => 'cash',
 
 104   'trial_balance'    => 'report',
 
 105   'income_statement' => 'report',
 
 107   'balance_sheet'    => 'report',
 
 110 # subs use these pretty freely, so declare them here
 
 111 our (%column_data, @column_index);
 
 112 our ($subtotalnetamount, $subtotaltax, $subtotal);
 
 114 sub check_rp_access {
 
 115   my $form     = $main::form;
 
 117   my $right   = $rp_access_map->{$form->{report}};
 
 118   $right    ||= 'DOES_NOT_EXIST';
 
 120   $main::auth->assert($right);
 
 124   $main::lxdebug->enter_sub();
 
 128   my $form     = $main::form;
 
 129   my %myconfig = %main::myconfig;
 
 130   my $locale   = $main::locale;
 
 133             'balance_sheet'        => 'Balance Sheet',
 
 134             'income_statement'     => 'Income Statement',
 
 135             'trial_balance'        => 'Trial Balance',
 
 136             'ar_aging'             => 'AR Aging',
 
 137             'ap_aging'             => 'Offene Verbindlichkeiten',
 
 138             'tax_collected'        => 'Tax collected',
 
 139             'tax_paid'             => 'Tax paid',
 
 140             'nontaxable_sales'     => 'Non-taxable Sales',
 
 141             'nontaxable_purchases' => 'Non-taxable Purchases',
 
 142             'receipts'             => 'Receipts',
 
 143             'payments'             => 'Payments',
 
 144             'projects'             => 'Project Transactions',
 
 145             'bwa'                  => 'Betriebswirtschaftliche Auswertung',
 
 148   $form->{title} = $locale->text($title{ $form->{report} });
 
 150   my $accrual = ($main::eur) ? ""        : "checked";
 
 151   my $cash    = ($main::eur) ? "checked" : "";
 
 153   my $year = (localtime)[5] + 1900;
 
 156   $form->all_departments(\%myconfig);
 
 157   if (@{ $form->{all_departments} || [] }) {
 
 158     $form->{selectdepartment} = "<option>\n";
 
 159     map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $form->{all_departments} || [] };
 
 164           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 165           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 167 | if $form->{selectdepartment};
 
 169   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 172   my %project_labels = ();
 
 173   my @project_values = ("");
 
 174   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 175     push(@project_values, $item->{"id"});
 
 176     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 180     NTI($main::cgi->popup_menu('-name' => "project_id",
 
 181                                '-values' => \@project_values,
 
 182                                '-labels' => \%project_labels));
 
 184   # use JavaScript Calendar or not
 
 185   $form->{jsscript} = 1;
 
 187   my ( $name_1, $id_1, $value_1, $trigger_1, $name_2, $id_2, $value_2, $trigger_2, );
 
 188   if ($form->{report} eq "balance_sheet") {
 
 189     $name_1    = "asofdate";
 
 191     $value_1   = "$form->{asofdate}";
 
 192     $trigger_1 = "trigger1";
 
 193     $name_2    = "compareasofdate";
 
 194     $id_2      = "compareasofdate";
 
 195     $value_2   = "$form->{compareasofdate}";
 
 196     $trigger_2 = "trigger2";
 
 197   } elsif ($form->{report} =~ /(receipts|payments)$/) {
 
 198     $name_1    = "fromdate";
 
 200     $value_1   = "$form->{fromdate}";
 
 201     $trigger_1 = "trigger1";
 
 205     $trigger_2 = "trigger2";
 
 206   } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
 
 207     $name_1    = "fromdate";
 
 209     $value_1   = "$form->{fromdate}";
 
 210     $trigger_1 = "trigger1";
 
 214     $trigger_2 = "trigger2";
 
 217     $name_1    = "fromdate";
 
 219     $value_1   = "$form->{fromdate}";
 
 220     $trigger_1 = "trigger1";
 
 224     $trigger_2 = "trigger2";
 
 227   my ($button1, $button1_2, $button2, $button2_2);
 
 230   # with JavaScript Calendar
 
 231   if ($form->{jsscript}) {
 
 233       $button1   = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 234       $button1_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|>|;
 
 237       $jsscript = Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
 
 239       $button1   = qq| <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
 
 240       $button1_2 = qq| <input type=button name=$name_1 id="$trigger_1" value=| . $locale->text('button') . qq|>|;
 
 241       $button2   = qq| <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 242       $button2_2 = qq| <input type=button name=$name_2 id="$trigger_2" value=| . $locale->text('button') . qq|> |;
 
 245       $jsscript = Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1", "$name_2", "BL", "$trigger_2");
 
 249     # without JavaScript Calendar
 
 251       $button1 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 253       $button1 = qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
 
 254       $button2 = qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 257   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 259   my $onload = qq|focus()|;
 
 260   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 261   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 263 <body onLoad="$onload">
 
 265 <form method=post action=$form->{script}>
 
 267 <input type=hidden name=title value="$form->{title}">
 
 271     <th class=listtop>$form->{title}</th>
 
 280   if ($form->{report} eq "projects") {
 
 283           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 284           <td colspan=5><input name=projectnumber size=25</td>
 
 286         <input type=hidden name=nextsub value=generate_projects>
 
 288           <th align=right>| . $locale->text('From') . qq|</th>
 
 291           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 302           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 303           <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
 
 304           <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|</td>
 
 311   if ($form->{report} eq "income_statement") {
 
 314           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 315           <td colspan=3>$projectnumber</td>
 
 317         <input type=hidden name=nextsub value=generate_income_statement>
 
 321           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
 
 324           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 325           <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
 
 331                 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 332                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 333                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 336                 <td align=right>  <input name=duetyp class=radio type=radio value="13" "checked"></td>
 
 337                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
 
 341                 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
 
 345                 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
 
 346                 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
 
 350                 <td align= right> </td>
 
 351                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
 
 352                 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
 
 353                 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
 
 354                 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
 
 358                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
 
 359                 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
 
 360                 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
 
 361                 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
 
 366                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
 
 367                 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
 
 368                 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
 
 369                 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
 
 373                    <td colspan=5><hr size=3 noshade></td>
 
 376           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
 
 377           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 380               | . $locale->text('Bis') . qq|
 
 386                    <td colspan=5><hr size=3 noshade></td>
 
 389           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 390           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
 
 391            <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
 
 398   if ($form->{report} eq "bwa") {
 
 401           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 402           <td colspan=3>$projectnumber</td>
 
 404         <input type=hidden name=nextsub value=generate_bwa>
 
 408           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
 
 411           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 412           <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
 
 418                 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 419                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 420                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 423                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 425                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
 
 427     $checked = "checked";
 
 429                 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
 
 433                 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
 
 434                 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
 
 438                 <td align= right> </td>
 
 439                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
 
 440                 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
 
 441                 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
 
 442                 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
 
 446                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
 
 447                 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
 
 448                 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
 
 449                 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
 
 454                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
 
 455                 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
 
 456                 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
 
 457                 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
 
 461                    <td colspan=5><hr size=3 noshade></td>
 
 464           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
 
 465           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 468               | . $locale->text('Bis') . qq| 
 
 474                    <td colspan=5><hr size=3 noshade></td>
 
 477           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 478           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
 
 479            <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
 
 482          <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
 
 483              <td><input name=decimalplaces size=3 value="2"></td>
 
 490   if ($form->{report} eq "balance_sheet") {
 
 492         <input type=hidden name=nextsub value=generate_balance_sheet>
 
 494           <th align=right>| . $locale->text('as at') . qq|</th>
 
 499           <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
 
 506           <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
 
 507           <td><input name=decimalplaces size=3 value="2"></td>
 
 516           <th align=right>| . $locale->text('Method') . qq|</th>
 
 517           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
 
 518            <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
 
 522           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 523           <td><input name=l_heading class=checkbox type=checkbox value=Y> | . $locale->text('Heading') . qq|
 
 524           <input name=l_subtotal class=checkbox type=checkbox value=Y> | . $locale->text('Subtotal') . qq|
 
 525           <input name=l_accno class=checkbox type=checkbox value=Y> | . $locale->text('Account Number') . qq|</td>
 
 532   if ($form->{report} eq "trial_balance") {
 
 535           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 536           <td colspan=3>$projectnumber</td>
 
 538         <input type=hidden name=nextsub value=generate_trial_balance>
 
 542           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> | . $locale->text('Customized Report') . qq|</th>
 
 545           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 546           <td><input name=year size=11 title="| . $locale->text('YYYY') . qq|" value="$year"></td>
 
 552                 <td align=right> <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 553                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 554                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 557                 <td align=right>  <input name=duetyp class=radio type=radio value="13" $checked></td>
 
 558                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. | . $locale->text('Quarter') . qq|</td>
 
 560     $checked = "checked";
 
 562                 <td><input name=duetyp class=radio type=radio value="1" $checked > | . $locale->text('January') . qq|</td>
 
 566                 <td><input name=duetyp class=radio type=radio value="5" $checked > | . $locale->text('May') . qq|</td>
 
 567                 <td><input name=duetyp class=radio type=radio value="9" $checked > | . $locale->text('September') . qq|</td>
 
 571                 <td align= right> </td>
 
 572                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. | . $locale->text('Quarter') . qq|</td>
 
 573                 <td><input name=duetyp class=radio type=radio value="2" $checked > | . $locale->text('February') . qq|</td>
 
 574                 <td><input name=duetyp class=radio type=radio value="6" $checked > | . $locale->text('June') . qq|</td>
 
 575                 <td><input name=duetyp class=radio type=radio value="10" $checked > | . $locale->text('October') . qq|</td>
 
 579                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. | . $locale->text('Quarter') . qq|</td>
 
 580                 <td><input name=duetyp class=radio type=radio value="3" $checked > | . $locale->text('March') . qq|</td>
 
 581                 <td><input name=duetyp class=radio type=radio value="7" $checked > | . $locale->text('July') . qq|</td>
 
 582                 <td><input name=duetyp class=radio type=radio value="11" $checked > | . $locale->text('November') . qq|</td>
 
 587                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. | . $locale->text('Quarter') . qq| </td>
 
 588                 <td><input name=duetyp class=radio type=radio value="4" $checked > | . $locale->text('April') . qq|</td>
 
 589                 <td><input name=duetyp class=radio type=radio value="8" $checked > | . $locale->text('August') . qq|</td>
 
 590                 <td><input name=duetyp class=radio type=radio value="12" $checked > | . $locale->text('December') . qq|</td>
 
 594                    <td colspan=5><hr size=3 noshade></td>
 
 597           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> | . $locale->text('Free report period') . qq|</th>
 
 598           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 601               | . $locale->text('Bis') . qq| 
 
 607                    <td colspan=5><hr size=3 noshade></td>
 
 610           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 611           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
 
 612            <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
 
 615          <th align=right colspan=4>| . $locale->text('All Accounts') . qq|</th>
 
 616              <td><input name=all_accounts type=checkbox value=1></td>
 
 619          <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
 
 620              <td><input name=decimalplaces size=3 value="2"></td>
 
 627   if ($form->{report} =~ /^tax_/) {
 
 628     $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
 
 630     RP->get_taxaccounts(\%myconfig, \%$form);
 
 633         <input type=hidden name=nextsub value=generate_tax_report>
 
 635           <th align=right>| . $locale->text('From') . qq|</th>
 
 636           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
 
 637           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 638           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
 
 641           <th align=right>| . $locale->text('Report for') . qq|</th>
 
 645     $checked = "checked";
 
 646     foreach my $ref (@{ $form->{taxaccounts} }) {
 
 649         qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
 
 651     <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
 
 652     <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
 
 659   <input type=hidden name=db value=$form->{db}>
 
 660   <input type=hidden name=sort value=transdate>
 
 665           <th align=right>| . $locale->text('Method') . qq|</th>
 
 666           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>| . $locale->text('Accrual') . qq|
 
 667            <input name=method class=radio type=radio value=cash $cash>| . $locale->text('EUR') . qq|</td>
 
 676           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 680                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 681                 <td>| . $locale->text('ID') . qq|</td>
 
 682                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
 683                 <td>| . $locale->text('Invoice') . qq|</td>
 
 684                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 685                 <td>| . $locale->text('Date') . qq|</td>
 
 688                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
 691     if ($form->{db} eq 'ar') {
 
 692       print $locale->text('Customer');
 
 694     if ($form->{db} eq 'ap') {
 
 695       print $locale->text('Vendor');
 
 699                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
 
 700                 <td>| . $locale->text('Amount') . qq|</td>
 
 701                 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
 
 702                 <td>| . $locale->text('Tax') . qq|</td>
 
 703                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
 
 704                 <td>| . $locale->text('Total') . qq|</td>
 
 707                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 708                 <td>| . $locale->text('Subtotal') . qq|</td>
 
 717   if ($form->{report} =~ /^nontaxable_/) {
 
 718     $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
 
 721         <input type=hidden name=nextsub value=generate_tax_report>
 
 723         <input type=hidden name=db value=$form->{db}>
 
 724         <input type=hidden name=sort value=transdate>
 
 725         <input type=hidden name=report value=$form->{report}>
 
 728           <th align=right>| . $locale->text('From') . qq|</th>
 
 729           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
 
 730           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 731           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
 
 734           <th align=right>| . $locale->text('Method') . qq|</th>
 
 735           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 736       . $locale->text('Accrual') . qq|
 
 737            <input name=method class=radio type=radio value=cash $cash>|
 
 738       . $locale->text('EUR') . qq|</td>
 
 741           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 745                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 746                 <td>| . $locale->text('ID') . qq|</td>
 
 747                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
 748                 <td>| . $locale->text('Invoice') . qq|</td>
 
 749                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 750                 <td>| . $locale->text('Date') . qq|</td>
 
 753                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
 756     if ($form->{db} eq 'ar') {
 
 757       print $locale->text('Customer');
 
 759     if ($form->{db} eq 'ap') {
 
 760       print $locale->text('Vendor');
 
 764                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
 
 765                 <td>| . $locale->text('Amount') . qq|</td>
 
 766                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
 
 767                 <td>| . $locale->text('Total') . qq|</td>
 
 770                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 771                 <td>| . $locale->text('Subtotal') . qq|</td>
 
 780   my ($label, $nextsub, $vc);
 
 781   if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
 
 782     if ($form->{report} eq 'ar_aging') {
 
 783       $label = $locale->text('Customer');
 
 784       $form->{vc} = 'customer';
 
 786       $label = $locale->text('Vendor');
 
 787       $form->{vc} = 'vendor';
 
 790     $nextsub = "generate_$form->{report}";
 
 793     $form->all_vc(\%myconfig, $form->{vc},
 
 794                   ($form->{vc} eq 'customer') ? "AR" : "AP");
 
 796     map { $vc .= "<option>$_->{name}--$_->{id}\n" }
 
 797       @{ $form->{"all_$form->{vc}"} };
 
 801       ? qq|<select name=$form->{vc}><option>\n$vc</select>|
 
 802       : qq|<input name=$form->{vc} size=35>|;
 
 806           <th align=right>| . $locale->text($label) . qq|</th>
 
 810           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 813               | . $locale->text('Bis') . qq| 
 
 818         <input type=hidden name=type value=statement>
 
 819         <input type=hidden name=format value=html>
 
 820         <input type=hidden name=media value=screen>
 
 822         <input type=hidden name=nextsub value=$nextsub>
 
 823         <input type=hidden name=action value=$nextsub>
 
 829   # above action can be removed if there is more than one input field
 
 831   my ($selection, $paymentaccounts);
 
 832   if ($form->{report} =~ /(receipts|payments)$/) {
 
 833     $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
 
 835     RP->paymentaccounts(\%myconfig, \%$form);
 
 837     $selection = "<option>\n";
 
 838     foreach my $ref (@{ $form->{PR} }) {
 
 839       $paymentaccounts .= "$ref->{accno} ";
 
 840       $selection       .= "<option>$ref->{accno}--$ref->{description}\n";
 
 843     chop $paymentaccounts;
 
 846         <input type=hidden name=nextsub value=list_payments>
 
 848           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
 
 849           <td colspan=3><select name=account>$selection</select>
 
 850             <input type=hidden name=paymentaccounts value="$paymentaccounts">
 
 854           <th align=right>| . $locale->text('Reference') . qq|</th>
 
 855           <td colspan=3><input name=reference></td>
 
 858           <th align=right nowrap>| . $locale->text('Source') . qq|</th>
 
 859           <td colspan=3><input name=source></td>
 
 862           <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
 
 863           <td colspan=3><input name=memo size=30></td>
 
 866           <th align=right>| . $locale->text('From') . qq|</th>
 
 871           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 878           <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
 
 879           <th align=left colspan=3>| . $locale->text('Include Exchangerate Difference') . qq|</td>
 
 884           <input type=hidden name=db value=$form->{db}>
 
 885           <input type=hidden name=sort value=transdate>
 
 896     <td><hr size=3 noshade></td>
 
 901 <input type=submit class=submit name=action value="| . $locale->text('Continue') . qq|">
 
 909   $main::lxdebug->leave_sub();
 
 912 sub continue { call_sub($main::form->{"nextsub"}); }
 
 915   $main::lxdebug->enter_sub();
 
 917   $main::auth->assert('report');
 
 919   my $form     = $main::form;
 
 920   my %myconfig = %main::myconfig;
 
 921   my $locale   = $main::locale;
 
 925   $form->{project_id} = $form->{project_id_1};
 
 926   if ($form->{projectnumber} && !$form->{project_id}) {
 
 927     $form->{rowcount} = 1;
 
 929     # call this instead of update
 
 930     $form->{update}          = $nextsub;
 
 931     $form->{projectnumber_1} = $form->{projectnumber};
 
 933     delete $form->{sort};
 
 934     check_project('generate_projects');
 
 936     # if there is one only, assign id
 
 937     $form->{project_id} = $form->{project_id_1};
 
 940   $main::lxdebug->leave_sub();
 
 943 sub generate_income_statement {
 
 944   $main::lxdebug->enter_sub();
 
 946   $main::auth->assert('report');
 
 948   my $form     = $main::form;
 
 949   my %myconfig = %main::myconfig;
 
 950   my $locale   = $main::locale;
 
 952   $form->{padding} = "  ";
 
 953   $form->{bold}    = "<b>";
 
 954   $form->{endbold} = "</b>";
 
 955   $form->{br}      = "<br>";
 
 957   if ($form->{reporttype} eq "custom") {
 
 959     #forgotten the year --> thisyear
 
 960     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
 961       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
 967     if ($form->{duetyp} eq "13") {
 
 968       $form->{fromdate} = "1.1.$form->{year}";
 
 969       $form->{todate}   = "31.12.$form->{year}";
 
 973     if ($form->{duetyp} eq "A") {
 
 974       $form->{fromdate} = "1.1.$form->{year}";
 
 975       $form->{todate}   = "31.3.$form->{year}";
 
 977     if ($form->{duetyp} eq "B") {
 
 978       $form->{fromdate} = "1.4.$form->{year}";
 
 979       $form->{todate}   = "30.6.$form->{year}";
 
 981     if ($form->{duetyp} eq "C") {
 
 982       $form->{fromdate} = "1.7.$form->{year}";
 
 983       $form->{todate}   = "30.9.$form->{year}";
 
 985     if ($form->{duetyp} eq "D") {
 
 986       $form->{fromdate} = "1.10.$form->{year}";
 
 987       $form->{todate}   = "31.12.$form->{year}";
 
 992       $form->{duetyp} eq "1" && do {
 
 993         $form->{fromdate} = "1.1.$form->{year}";
 
 994         $form->{todate}   = "31.1.$form->{year}";
 
 997       $form->{duetyp} eq "2" && do {
 
 998         $form->{fromdate} = "1.2.$form->{year}";
 
1000         #this works from 1901 to 2099, 1900 and 2100 fail.
 
1001         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
1002         $form->{todate} = "$leap.2.$form->{year}";
 
1005       $form->{duetyp} eq "3" && do {
 
1006         $form->{fromdate} = "1.3.$form->{year}";
 
1007         $form->{todate}   = "31.3.$form->{year}";
 
1010       $form->{duetyp} eq "4" && do {
 
1011         $form->{fromdate} = "1.4.$form->{year}";
 
1012         $form->{todate}   = "30.4.$form->{year}";
 
1015       $form->{duetyp} eq "5" && do {
 
1016         $form->{fromdate} = "1.5.$form->{year}";
 
1017         $form->{todate}   = "31.5.$form->{year}";
 
1020       $form->{duetyp} eq "6" && do {
 
1021         $form->{fromdate} = "1.6.$form->{year}";
 
1022         $form->{todate}   = "30.6.$form->{year}";
 
1025       $form->{duetyp} eq "7" && do {
 
1026         $form->{fromdate} = "1.7.$form->{year}";
 
1027         $form->{todate}   = "31.7.$form->{year}";
 
1030       $form->{duetyp} eq "8" && do {
 
1031         $form->{fromdate} = "1.8.$form->{year}";
 
1032         $form->{todate}   = "31.8.$form->{year}";
 
1035       $form->{duetyp} eq "9" && do {
 
1036         $form->{fromdate} = "1.9.$form->{year}";
 
1037         $form->{todate}   = "30.9.$form->{year}";
 
1040       $form->{duetyp} eq "10" && do {
 
1041         $form->{fromdate} = "1.10.$form->{year}";
 
1042         $form->{todate}   = "31.10.$form->{year}";
 
1045       $form->{duetyp} eq "11" && do {
 
1046         $form->{fromdate} = "1.11.$form->{year}";
 
1047         $form->{todate}   = "30.11.$form->{year}";
 
1050       $form->{duetyp} eq "12" && do {
 
1051         $form->{fromdate} = "1.12.$form->{year}";
 
1052         $form->{todate}   = "31.12.$form->{year}";
 
1058   RP->income_statement(\%myconfig, \%$form);
 
1060   ($form->{department}) = split /--/, $form->{department};
 
1063     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1064   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
1066   # if there are any dates construct a where
 
1067   if ($form->{fromdate} || $form->{todate}) {
 
1069     unless ($form->{todate}) {
 
1070       $form->{todate} = $form->current_date(\%myconfig);
 
1073     my $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
 
1074     my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
 
1076     my $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1077     my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
 
1079     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
1081         $locale->text('for Period')
 
1082       . qq|\n$longfromdate |
 
1083       . $locale->text('Bis')
 
1087   if ($form->{comparefromdate} || $form->{comparetodate}) {
 
1088     my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
 
1089     my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
 
1091     my $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
 
1092     my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
 
1094     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
 
1096         "\n$longcomparefromdate "
 
1097       . $locale->text('Bis')
 
1098       . qq| $longcomparetodate|;
 
1101   # setup variables for the form
 
1102   my @a = qw(company address businessnumber);
 
1103   map { $form->{$_} = $myconfig{$_} } @a;
 
1105   $form->{templates} = $myconfig{templates};
 
1107   $form->{IN} = "income_statement.html";
 
1109   $form->parse_template;
 
1111   $main::lxdebug->leave_sub();
 
1114 sub generate_balance_sheet {
 
1115   $main::lxdebug->enter_sub();
 
1117   $main::auth->assert('report');
 
1119   my $form     = $main::form;
 
1120   my %myconfig = %main::myconfig;
 
1121   my $locale   = $main::locale;
 
1123   $form->{decimalplaces} = $form->{decimalplaces} * 1 || 2;
 
1124   $form->{padding} = "  ";
 
1125   $form->{bold}    = "<b>";
 
1126   $form->{endbold} = "</b>";
 
1127   $form->{br}      = "<br>";
 
1129   my $data = RP->balance_sheet(\%myconfig, \%$form);
 
1131   $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
 
1132   $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1134   ($form->{department}) = split /--/, $form->{department};
 
1136   # define Current Earnings account
 
1137   my $padding = ($form->{l_heading}) ? $form->{padding} : "";
 
1138   push(@{ $form->{equity_account} }, $padding . $locale->text('Current Earnings'));
 
1140   $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
 
1141   $form->{last_period} = $locale->date(\%myconfig, $form->{compareasofdate}, 0);
 
1143   $form->{IN} = "balance_sheet.html";
 
1145   # setup company variables for the form
 
1146   map { $form->{$_} = $myconfig{$_}; } (qw(company address businessnumber nativecurr));
 
1148   $form->{templates} = $myconfig{templates};
 
1151   print $form->parse_html_template('rp/balance_sheet', $data);
 
1152 #  $form->parse_template();
 
1154   $main::lxdebug->leave_sub();
 
1157 sub generate_projects {
 
1158   $main::lxdebug->enter_sub();
 
1160   $main::auth->assert('report');
 
1162   my $form     = $main::form;
 
1163   my %myconfig = %main::myconfig;
 
1164   my $locale   = $main::locale;
 
1166   &get_project("generate_projects");
 
1167   $form->{projectnumber} = $form->{projectnumber_1};
 
1169   $form->{nextsub} = "generate_projects";
 
1170   $form->{title}   = $locale->text('Project Transactions');
 
1171   RP->trial_balance(\%myconfig, \%$form);
 
1173   list_accounts('generate_projects');
 
1175   $main::lxdebug->leave_sub();
 
1181 # included links to display transactions for period entered
 
1182 # added headers and subtotals
 
1184 sub generate_trial_balance {
 
1185   $main::lxdebug->enter_sub();
 
1187   $main::auth->assert('report');
 
1189   my $form     = $main::form;
 
1190   my %myconfig = %main::myconfig;
 
1191   my $locale   = $main::locale;
 
1193   if ($form->{reporttype} eq "custom") {
 
1195     #forgotten the year --> thisyear
 
1196     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
1197       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
1203     if ($form->{duetyp} eq "13") {
 
1204       $form->{fromdate} = "1.1.$form->{year}";
 
1205       $form->{todate}   = "31.12.$form->{year}";
 
1209     if ($form->{duetyp} eq "A") {
 
1210       $form->{fromdate} = "1.1.$form->{year}";
 
1211       $form->{todate}   = "31.3.$form->{year}";
 
1213     if ($form->{duetyp} eq "B") {
 
1214       $form->{fromdate} = "1.4.$form->{year}";
 
1215       $form->{todate}   = "30.6.$form->{year}";
 
1217     if ($form->{duetyp} eq "C") {
 
1218       $form->{fromdate} = "1.7.$form->{year}";
 
1219       $form->{todate}   = "30.9.$form->{year}";
 
1221     if ($form->{duetyp} eq "D") {
 
1222       $form->{fromdate} = "1.10.$form->{year}";
 
1223       $form->{todate}   = "31.12.$form->{year}";
 
1228       $form->{duetyp} eq "1" && do {
 
1229         $form->{fromdate} = "1.1.$form->{year}";
 
1230         $form->{todate}   = "31.1.$form->{year}";
 
1233       $form->{duetyp} eq "2" && do {
 
1234         $form->{fromdate} = "1.2.$form->{year}";
 
1236         #this works from 1901 to 2099, 1900 and 2100 fail.
 
1237         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
1238         $form->{todate} = "$leap.2.$form->{year}";
 
1241       $form->{duetyp} eq "3" && do {
 
1242         $form->{fromdate} = "1.3.$form->{year}";
 
1243         $form->{todate}   = "31.3.$form->{year}";
 
1246       $form->{duetyp} eq "4" && do {
 
1247         $form->{fromdate} = "1.4.$form->{year}";
 
1248         $form->{todate}   = "30.4.$form->{year}";
 
1251       $form->{duetyp} eq "5" && do {
 
1252         $form->{fromdate} = "1.5.$form->{year}";
 
1253         $form->{todate}   = "31.5.$form->{year}";
 
1256       $form->{duetyp} eq "6" && do {
 
1257         $form->{fromdate} = "1.6.$form->{year}";
 
1258         $form->{todate}   = "30.6.$form->{year}";
 
1261       $form->{duetyp} eq "7" && do {
 
1262         $form->{fromdate} = "1.7.$form->{year}";
 
1263         $form->{todate}   = "31.7.$form->{year}";
 
1266       $form->{duetyp} eq "8" && do {
 
1267         $form->{fromdate} = "1.8.$form->{year}";
 
1268         $form->{todate}   = "31.8.$form->{year}";
 
1271       $form->{duetyp} eq "9" && do {
 
1272         $form->{fromdate} = "1.9.$form->{year}";
 
1273         $form->{todate}   = "30.9.$form->{year}";
 
1276       $form->{duetyp} eq "10" && do {
 
1277         $form->{fromdate} = "1.10.$form->{year}";
 
1278         $form->{todate}   = "31.10.$form->{year}";
 
1281       $form->{duetyp} eq "11" && do {
 
1282         $form->{fromdate} = "1.11.$form->{year}";
 
1283         $form->{todate}   = "30.11.$form->{year}";
 
1286       $form->{duetyp} eq "12" && do {
 
1287         $form->{fromdate} = "1.12.$form->{year}";
 
1288         $form->{todate}   = "31.12.$form->{year}";
 
1295   # get for each account initial balance, debits and credits
 
1296   RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
 
1299   $form->{rowcount} = scalar @{ $form->{TB} || [] };
 
1300   $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
 
1303     "accno",               "description",
 
1304     "last_transaction",    "soll_eb",
 
1307     "soll_kumuliert",      "haben_kumuliert",
 
1308     "soll_saldo",          "haben_saldo"
 
1312   my $attachment_basename = $locale->text('trial_balance');
 
1313   my $report              = SL::ReportGenerator->new(\%myconfig, $form);
 
1315   my @hidden_variables    = qw(fromdate todate year cash);
 
1317   my $href                = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
 
1320     'accno'               => { 'text' => $locale->text('Account'), },
 
1321     'description'         => { 'text' => $locale->text('Description'), },
 
1322     'last_transaction'    => { 'text' => $locale->text('Last Transaction'), },
 
1323     'soll_eb'             => { 'text' => $locale->text('Debit Starting Balance'), },
 
1324     'haben_eb'            => { 'text' => $locale->text('Credit Starting Balance'), },
 
1325     'soll'                => { 'text' => $locale->text('Debit'), },
 
1326     'haben'               => { 'text' => $locale->text('Credit'), },
 
1327     'soll_kumuliert'      => { 'text' => $locale->text('Sum Debit'), },
 
1328     'haben_kumuliert'     => { 'text' => $locale->text('Sum Credit'), },
 
1329     'soll_saldo'          => { 'text' => $locale->text('Saldo Debit'), },
 
1330     'haben_saldo'         => { 'text' => $locale->text('Saldo Credit'), }
 
1335   my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
 
1337   map { $column_defs{$_}->{visible} =  1 } @columns;
 
1339   $report->set_columns(%column_defs);
 
1340   $report->set_column_order(@columns);
 
1342   $report->set_export_options('generate_trial_balance', @hidden_variables);
 
1347   $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . "  -  " . $locale->date(\%myconfig, $form->{todate}, 0);
 
1349   $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
 
1350   push (@options, $form->{print_date});
 
1352   $form->{company} = $locale->text('Company') . " " . $myconfig{company};
 
1353   push (@options, $form->{company});
 
1356   $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
 
1358   $report->set_options('output_format'        => 'HTML',
 
1359                        'top_info_text'        => join("\n", @options),
 
1360                        'title'                => $form->{title},
 
1361                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
1362                        'html_template'        => 'rp/html_report_susa',
 
1363                        'pdf_template'         => 'rp/html_report_susa',
 
1365   $report->set_options_from_form();
 
1367   # add sort and escape callback, this one we use for the add sub
 
1368   $form->{callback} = $href .= "&sort=$form->{sort}";
 
1370   # escape callback for href
 
1371   my $callback = $form->escape($href);
 
1373   my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
 
1375   my %totals    = map { $_ => 0 } @subtotal_columns;
 
1377   my $edit_url = build_std_url('action=edit', 'type', 'vc');
 
1380   foreach my $accno (@{ $form->{TB} }) {
 
1382     $accno->{soll} = $accno->{debit};
 
1383     $accno->{haben} = $accno->{credit};
 
1384     map { $totals{$_}    += $accno->{$_} } @subtotal_columns;
 
1386     map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
 
1387       qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
 
1391     foreach my $column (@columns) {
 
1393         'data'  => $accno->{$column},
 
1394         'align' => $column_alignment{$column},
 
1398     $row->{accno}->{link} = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($accno->{accno}), 'description=' . E($accno->{description}), 'fromdate=' . E($form->{fromdate}), 'todate=' . E($form->{todate}), 'method=' . E($form->{method}));
 
1400     my $row_set = [ $row ];
 
1403     $report->add_data($row_set);
 
1408   $report->add_separator();
 
1410   $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
 
1412   $report->generate_with_headers();
 
1414   $main::lxdebug->leave_sub();
 
1418 sub create_subtotal_row {
 
1419   $main::lxdebug->enter_sub();
 
1421   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
1423   my $form     = $main::form;
 
1424   my %myconfig = %main::myconfig;
 
1425   my $locale   = $main::locale;
 
1427   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
1429   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
 
1431   $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
 
1433   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
1435   $main::lxdebug->leave_sub();
 
1440 sub create_list_accounts_subtotal_row {
 
1441   $main::lxdebug->enter_sub();
 
1443   my ($subtotals, $columns, $fields, $class) = @_;
 
1445   my $form     = $main::form;
 
1446   my %myconfig = %main::myconfig;
 
1447   my $locale   = $main::locale;
 
1449   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
1451   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
 
1453   $main::lxdebug->leave_sub();
 
1459   $main::lxdebug->enter_sub();
 
1463   my $form     = $main::form;
 
1464   my %myconfig = %main::myconfig;
 
1465   my $locale   = $main::locale;
 
1468   if ($form->{department}) {
 
1469     my ($department) = split /--/, $form->{department};
 
1470     push @options, $locale->text('Department') . " : $department";
 
1472   if ($form->{projectnumber}) {
 
1473     push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
 
1476   # if there are any dates
 
1477   if ($form->{fromdate} || $form->{todate}) {
 
1478     my ($fromdate, $todate);
 
1480     if ($form->{fromdate}) {
 
1481       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1483     if ($form->{todate}) {
 
1484       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
 
1487     push @options, "$fromdate - $todate";
 
1490     push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1493   my @columns     = qw(accno description begbalance debit credit endbalance);
 
1495     'accno'       => { 'text' => $locale->text('Account'), },
 
1496     'description' => { 'text' => $locale->text('Description'), },
 
1497     'debit'       => { 'text' => $locale->text('Debit'), },
 
1498     'credit'      => { 'text' => $locale->text('Credit'), },
 
1499     'begbalance'  => { 'text' => $locale->text('Balance'), },
 
1500     'endbalance'  => { 'text' => $locale->text('Balance'), },
 
1502   my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
 
1504   my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
 
1506   $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
 
1508   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1510   $report->set_options('top_info_text'         => join("\n", @options),
 
1511                        'output_format'         => 'HTML',
 
1512                        'title'                 => $form->{title},
 
1513                        'attachment_basename'   => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
 
1514                        'std_column_visibility' => 1,
 
1516   $report->set_options_from_form();
 
1518   $report->set_columns(%column_defs);
 
1519   $report->set_column_order(@columns);
 
1521   $report->set_export_options($action, @hidden_variables);
 
1523   my @totals_columns = qw(credit debit begbalance endbalance);
 
1524   my %subtotals      = map { $_ => 0 } @totals_columns;
 
1525   my %totals         = map { $_ => 0 } @totals_columns;
 
1526   my $found_heading  = 0;
 
1527   my @tb             = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
 
1529   # sort the whole thing by account numbers and display
 
1530   foreach my $idx (0 .. scalar(@tb) - 1) {
 
1531     my $ref  = $tb[$idx];
 
1532     my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
 
1534     my $ml   = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
 
1536     my $row  = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
 
1538     if ($ref->{charttype} eq 'H') {
 
1539       next unless ($form->{l_heading});
 
1541       %subtotals                   = map { $_ => 0 } @totals_columns;
 
1543       $row->{description}->{class} = 'listheading';
 
1544       $row->{description}->{data}  = $ref->{description};
 
1546       $report->add_data($row);
 
1551     foreach (qw(debit credit)) {
 
1552       $subtotals{$_} += $ref->{$_};
 
1553       $totals{$_}    += $ref->{$_};
 
1556     $subtotals{begbalance} += $ref->{balance} * $ml;
 
1557     $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
 
1559     map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
 
1560     map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
 
1562     $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
 
1563     $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
 
1565     $report->add_data($row);
 
1567     if ($form->{l_heading} && $found_heading &&
 
1568         (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
 
1569       $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
 
1573   $report->add_separator();
 
1575   $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
 
1577   $report->generate_with_headers();
 
1579   $main::lxdebug->leave_sub();
 
1582 sub generate_ar_aging {
 
1583   $main::lxdebug->enter_sub();
 
1585   $main::auth->assert('general_ledger');
 
1587   my $form     = $main::form;
 
1588   my %myconfig = %main::myconfig;
 
1589   my $locale   = $main::locale;
 
1592   ($form->{customer}) = split(/--/, $form->{customer});
 
1594   $form->{ct}   = "customer";
 
1595   $form->{arap} = "ar";
 
1597   $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
 
1599   RP->aging(\%myconfig, \%$form);
 
1602   $main::lxdebug->leave_sub();
 
1605 sub generate_ap_aging {
 
1606   $main::lxdebug->enter_sub();
 
1608   $main::auth->assert('general_ledger');
 
1610   my $form     = $main::form;
 
1611   my %myconfig = %main::myconfig;
 
1612   my $locale   = $main::locale;
 
1615   ($form->{vendor}) = split(/--/, $form->{vendor});
 
1617   $form->{ct}   = "vendor";
 
1618   $form->{arap} = "ap";
 
1620   $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
 
1622   RP->aging(\%myconfig, \%$form);
 
1625   $main::lxdebug->leave_sub();
 
1628 sub create_aging_subtotal_row {
 
1629   $main::lxdebug->enter_sub();
 
1631   my ($subtotals, $columns, $periods, $class) = @_;
 
1633   my $form     = $main::form;
 
1634   my %myconfig = %main::myconfig;
 
1635   my $locale   = $main::locale;
 
1637   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
1639   foreach (@{ $periods }) {
 
1640     $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
 
1641     $subtotals->{$_}      = 0;
 
1644   $main::lxdebug->leave_sub();
 
1650   $main::lxdebug->enter_sub();
 
1652   $main::auth->assert('general_ledger');
 
1654   my $form     = $main::form;
 
1655   my %myconfig = %main::myconfig;
 
1656   my $locale   = $main::locale;
 
1657   my $cgi      = $main::cgi;
 
1659   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1661   my @columns = qw(statement ct invnumber transdate duedate amount open);
 
1664     'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
 
1665     'ct'        => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
 
1666     'invnumber' => { 'text' => $locale->text('Invoice'), },
 
1667     'transdate' => { 'text' => $locale->text('Date'), },
 
1668     'duedate'   => { 'text' => $locale->text('Due'), },
 
1669     'amount'        => { 'text' => $locale->text('Amount'), },
 
1670     'open'       => { 'text' => $locale->text('Open'), },
 
1673   my %column_alignment = ('statement' => 'center',
 
1674                           map { $_ => 'right' } qw(open amount));
 
1676   $report->set_options('std_column_visibility' => 1);
 
1677   $report->set_columns(%column_defs);
 
1678   $report->set_column_order(@columns);
 
1680   my @hidden_variables = qw(todate customer vendor arap title ct);
 
1681   $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
 
1684   my $attachment_basename;
 
1686   if ($form->{department}) {
 
1687     my ($department) = split /--/, $form->{department};
 
1688     push @options, $locale->text('Department') . " : $department";
 
1689     $form->{callback} .= "&department=" . E($department);
 
1692   if (($form->{arap} eq 'ar') && $form->{customer}) {
 
1693     push @options, $form->{customer};
 
1694     $attachment_basename = $locale->text('ar_aging_list');
 
1695     $form->{title} = sprintf($locale->text('Ar aging on %s'), $form->{todate});
 
1698   if (($form->{arap} eq 'ap') && $form->{vendor}) {
 
1699     push @options, $form->{vendor};
 
1700     $attachment_basename = $locale->text('ap_aging_list');
 
1701     $form->{title} = sprintf($locale->text('Ap aging on %s'), $form->{todate});
 
1704   if ($form->{fromdate}) {
 
1705     push @options, $locale->text('for Period') . " " . $locale->text('From') . " " .$locale->date(\%myconfig, $form->{fromdate}, 1) . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
 
1707     push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
 
1710   $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
 
1712   $report->set_options('top_info_text'        => join("\n", @options),
 
1713                        'output_format'        => 'HTML',
 
1714                        'title'                => $form->{title},
 
1715                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
1718   my $previous_ctid = 0;
 
1720   my @periods       = qw(open amount);
 
1721   my %subtotals     = map { $_ => 0 } @periods;
 
1722   my %totals        = map { $_ => 0 } @periods;
 
1724   foreach my $ref (@{ $form->{AG} }) {
 
1725     if ($row_idx && ($previous_ctid != $ref->{ctid})) {
 
1726       $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
 
1729     foreach my $key (@periods) {
 
1730       $subtotals{$key}  += $ref->{"$key"};
 
1731       $totals{$key}     += $ref->{"$key"};
 
1732       $ref->{"$key"}  = $ref->{"$key"} != 0 ? $form->format_amount(\%myconfig, $ref->{"$key"}, 2) : '';
 
1737     foreach my $column (@columns) {
 
1739         'data'   => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
 
1740         'align'  => $column_alignment{$column},
 
1741         'valign' => $column eq 'statement' ? 'center' : '',
 
1745     $row->{invnumber}->{link} =  build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
 
1747     if ($previous_ctid != $ref->{ctid}) {
 
1748       $row->{statement}->{raw_data} =
 
1749           $cgi->hidden('-name' => "customer_id_" . ($row_idx + 1), '-value' => $ref->{ctid})
 
1750         . $cgi->checkbox('-name' => "statement_" . ($row_idx + 1), '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
 
1751       $row->{ct}->{data} = $ref->{name};
 
1756     $previous_ctid = $ref->{ctid};
 
1758     $report->add_data($row);
 
1761   $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
 
1763   $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
 
1765   if ($form->{arap} eq 'ar') {
 
1766     my $raw_top_info_text    = $form->parse_html_template('rp/aging_ar_top');
 
1767     my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
 
1768                                                                                'PRINT_OPTIONS' => print_options(inline => 1), });
 
1769     $report->set_options('raw_top_info_text'    => $raw_top_info_text,
 
1770                          'raw_bottom_info_text' => $raw_bottom_info_text);
 
1773   $report->set_options_from_form();
 
1775   $report->generate_with_headers();
 
1777   $main::lxdebug->leave_sub();
 
1781   $main::lxdebug->enter_sub();
 
1783   my $form     = $main::form;
 
1784   my %myconfig = %main::myconfig;
 
1785   my $locale   = $main::locale;
 
1787   RP->aging(\%myconfig, \%$form);
 
1789   map { $_->{checked} = "checked" } @{ $form->{AG} };
 
1793   $main::lxdebug->leave_sub();
 
1797   $main::lxdebug->enter_sub();
 
1799   $main::auth->assert('general_ledger');
 
1801   my $form     = $main::form;
 
1802   my %myconfig = %main::myconfig;
 
1803   my $locale   = $main::locale;
 
1805   # get name and email addresses
 
1807   for my $i (1 .. $form->{rowcount}) {
 
1808     if ($form->{"statement_$i"}) {
 
1809       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
 
1810       RP->get_customer(\%myconfig, \%$form);
 
1816   $form->error($locale->text('Nothing selected!')) unless $selected;
 
1819   if ($myconfig{role} eq 'admin') {
 
1821           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
 
1822           <td><input name=bcc size=30 value="$form->{bcc}"></td>
 
1826   my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
 
1828   $form->{media} = "email";
 
1835 <form method=post action=$form->{script}>
 
1841   <tr height="5"></tr>
 
1846           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
 
1847           <td><input name=email size=30 value="$form->{email}"></td>
 
1848           <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
 
1849           <td><input name=cc size=30 value="$form->{cc}"></td>
 
1852           <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
 
1853           <td><input name=subject size=30 value="$form->{subject}"></td>
 
1863           <th align=left nowrap>| . $locale->text('Message') . qq|</th>
 
1866           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
 
1877   map { delete $form->{$_} }
 
1878     qw(action email cc bcc subject message type sendmode format header);
 
1880   # save all other variables
 
1881   foreach my $key (keys %$form) {
 
1882     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
1883     $form->{$key} =~ s/\"/"/g;
 
1884     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1891     <td><hr size=3 noshade></td>
 
1895 <input type=hidden name=nextsub value=send_email>
 
1898 <input name=action class=submit type=submit value="|
 
1899     . $locale->text('Continue') . qq|">
 
1906   $main::lxdebug->leave_sub();
 
1910   $main::lxdebug->enter_sub();
 
1912   $main::auth->assert('general_ledger');
 
1914   my $form     = $main::form;
 
1915   my %myconfig = %main::myconfig;
 
1916   my $locale   = $main::locale;
 
1918   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
 
1919     unless $form->{subject};
 
1921   RP->aging(\%myconfig, \%$form);
 
1923   $form->{"statement_1"} = 1;
 
1925   $form->{media} = 'email';
 
1928   $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
 
1930   $main::lxdebug->leave_sub();
 
1934   $main::lxdebug->enter_sub();
 
1936   $main::auth->assert('general_ledger');
 
1938   my $form     = $main::form;
 
1939   my %myconfig = %main::myconfig;
 
1940   my $locale   = $main::locale;
 
1942   if ($form->{media} eq 'printer') {
 
1943     $form->error($locale->text('Select postscript or PDF!'))
 
1944       if ($form->{format} !~ /(postscript|pdf)/);
 
1948   for my $i (1 .. $form->{rowcount}) {
 
1949     if ($form->{"statement_$i"}) {
 
1950       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
 
1956   $form->error($locale->text('Nothing selected!')) unless $selected;
 
1958   if ($form->{media} eq 'printer') {
 
1959     $form->{"$form->{ct}_id"} = "";
 
1961     $form->{"statement_1"} = 1;
 
1964   RP->aging(\%myconfig, \%$form);
 
1968   $form->redirect($locale->text('Statements sent to printer!'))
 
1969     if ($form->{media} eq 'printer');
 
1971   $main::lxdebug->leave_sub();
 
1975   $main::lxdebug->enter_sub();
 
1977   $main::auth->assert('general_ledger');
 
1979   my $form     = $main::form;
 
1980   my %myconfig = %main::myconfig;
 
1981   my $locale   = $main::locale;
 
1983   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
 
1985   $form->{templates} = "$myconfig{templates}";
 
1987   my $suffix = "html";
 
1988   my $attachment_suffix = "html";
 
1989   if ($form->{format} eq 'postscript') {
 
1990     $form->{postscript} = 1;
 
1992     $attachment_suffix = "ps";
 
1993   } elsif ($form->{format} eq 'pdf') {
 
1996     $attachment_suffix = "pdf";
 
1999   $form->{IN}  = "$form->{type}.$suffix";
 
2000   $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
 
2002   # Save $form->{email} because it will be overwritten.
 
2003   $form->{EMAIL_RECIPIENT} = $form->{email};
 
2007   while (@{ $form->{AG} }) {
 
2009     my $ref = shift @{ $form->{AG} };
 
2011     if ($ctid != $ref->{ctid}) {
 
2013       $ctid = $ref->{ctid};
 
2016       if ($form->{"statement_$i"}) {
 
2019           ("name", "street", "zipcode", "city", "country", "contact", "email",
 
2020            "$form->{ct}phone", "$form->{ct}fax");
 
2021         map { $form->{$_} = $ref->{$_} } @a;
 
2023         $form->{ $form->{ct} } = $form->{name};
 
2024         $form->{"$form->{ct}_id"} = $ref->{ctid};
 
2026         map { $form->{$_} = () } qw(invnumber invdate duedate);
 
2028         foreach my $item (qw(c0 c30 c60 c90)) {
 
2029           $form->{$item} = ();
 
2030           $form->{"${item}total"} = 0;
 
2033         &statement_details($ref);
 
2037           if (scalar(@{ $form->{AG} }) > 0) {
 
2039             # one or more left to go
 
2040             if ($ctid == $form->{AG}->[0]->{ctid}) {
 
2041               $ref = shift @{ $form->{AG} };
 
2042               &statement_details($ref);
 
2045               $ref = scalar(@{ $form->{AG} });
 
2051             # set initial ref to 0
 
2058           $form->{"${_}total"} =
 
2059             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
 
2060         } ('c0', 'c30', 'c60', 'c90', "");
 
2062         $form->{attachment_filename} =  $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
 
2063         $form->{attachment_filename} =~ s/\s+/_/g;
 
2065         $form->parse_template(\%myconfig, $main::userspath);
 
2070   # saving the history
 
2071   if(!exists $form->{addition} && $form->{id} ne "") {
 
2072     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
2073     $form->{addition} = "PRINTED";
 
2074     $form->{what_done} = $form->{type};
 
2075     $form->save_history($form->dbconnect(\%myconfig));
 
2077   # /saving the history
 
2078   $main::lxdebug->leave_sub();
 
2081 sub statement_details {
 
2082   $main::lxdebug->enter_sub();
 
2084   $main::auth->assert('general_ledger');
 
2086   my $form     = $main::form;
 
2087   my %myconfig = %main::myconfig;
 
2088   my $locale   = $main::locale;
 
2092   push @{ $form->{invnumber} }, $ref->{invnumber};
 
2093   push @{ $form->{invdate} },   $ref->{transdate};
 
2094   push @{ $form->{duedate} },   $ref->{duedate};
 
2096   foreach my $item (qw(c0 c30 c60 c90)) {
 
2097     if ($ref->{exchangerate} * 1) {
 
2099         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
 
2101     $form->{"${item}total"} += $ref->{$item};
 
2102     $form->{total}          += $ref->{$item};
 
2103     push @{ $form->{$item} },
 
2104       $form->format_amount(\%myconfig, $ref->{$item}, 2);
 
2107   $main::lxdebug->leave_sub();
 
2110 sub generate_tax_report {
 
2111   $main::lxdebug->enter_sub();
 
2113   $main::auth->assert('report');
 
2115   my $form     = $main::form;
 
2116   my %myconfig = %main::myconfig;
 
2117   my $locale   = $main::locale;
 
2119   RP->tax_report(\%myconfig, \%$form);
 
2121   my $descvar     = "$form->{accno}_description";
 
2122   my $description = $form->escape($form->{$descvar});
 
2123   my $ratevar     = "$form->{accno}_rate";
 
2124   our $taxrate; # most likely error
 
2126   my $department = $form->escape($form->{department});
 
2130     "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
 
2132   # construct callback
 
2133   $description = $form->escape($form->{$descvar},   1);
 
2134   $department  = $form->escape($form->{department}, 1);
 
2136     "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
 
2138   my $title = $form->escape($form->{title});
 
2139   $href .= "&title=$title";
 
2140   $title = $form->escape($form->{title}, 1);
 
2141   $callback .= "&title=$title";
 
2143   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
 
2146     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
 
2148   foreach my $item (@columns) {
 
2149     if ($form->{"l_$item"} eq "Y") {
 
2150       push @column_index, $item;
 
2152       # add column to href and callback
 
2153       $callback .= "&l_$item=Y";
 
2154       $href     .= "&l_$item=Y";
 
2158   if ($form->{l_subtotal} eq 'Y') {
 
2159     $callback .= "&l_subtotal=Y";
 
2160     $href     .= "&l_subtotal=Y";
 
2164   if ($form->{department}) {
 
2165     ($department) = split /--/, $form->{department};
 
2166     $option = $locale->text('Department') . " : $department";
 
2169   my ($fromdate, $todate);
 
2170   # if there are any dates
 
2171   if ($form->{fromdate} || $form->{todate}) {
 
2172     if ($form->{fromdate}) {
 
2173       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
2175     if ($form->{todate}) {
 
2176       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
 
2179     $form->{period} = "$fromdate - $todate";
 
2182       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2185   my ($name, $invoice, $arap);
 
2186   if ($form->{db} eq 'ar') {
 
2187     $name    = $locale->text('Customer');
 
2191   if ($form->{db} eq 'ap') {
 
2192     $name    = $locale->text('Vendor');
 
2197   $option .= "<br>" if $option;
 
2198   $option .= "$form->{period}";
 
2201   $column_header{id}        = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
 
2202   $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
 
2203   $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
 
2204   $column_header{netamount} = qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
 
2205   $column_header{tax}       = qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
 
2206   $column_header{amount}    = qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
 
2208   $column_header{name}      = qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
 
2217     <th class=listtop>$form->{title}</th>
 
2219   <tr height="5"></tr>
 
2226         <tr class=listheading>
 
2229   map { print "$column_header{$_}\n" } @column_index;
 
2235   # add sort and escape callback
 
2236   $callback = $form->escape($callback . "&sort=$form->{sort}");
 
2239   if (@{ $form->{TR} }) {
 
2240     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
 
2243   my ($totalnetamount, $totaltax);
 
2245   foreach my $ref (@{ $form->{TR} }) {
 
2247     my $module = ($ref->{invoice}) ? $invoice : $arap;
 
2249     if ($form->{l_subtotal} eq 'Y') {
 
2250       if ($sameitem ne $ref->{ $form->{sort} }) {
 
2252         $sameitem = $ref->{ $form->{sort} };
 
2256     $totalnetamount += $ref->{netamount};
 
2257     $totaltax       += $ref->{tax};
 
2258     $ref->{amount} = $ref->{netamount} + $ref->{tax};
 
2260     $subtotalnetamount += $ref->{netamount};
 
2261     $subtotaltax       += $ref->{tax};
 
2264       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
 
2265     } qw(netamount tax amount);
 
2267     $column_data{id}        = qq|<td>$ref->{id}</td>|;
 
2268     $column_data{invnumber} =
 
2269       qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
 
2270     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
 
2271     $column_data{name}      = qq|<td>$ref->{name} </td>|;
 
2273     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
 
2274       qw(netamount tax amount);
 
2279         <tr class=listrow$i>
 
2282     map { print "$column_data{$_}\n" } @column_index;
 
2290   if ($form->{l_subtotal} eq 'Y') {
 
2294   map { $column_data{$_} = qq|<th> </th>| } @column_index;
 
2298         <tr class=listtotal>
 
2301   my $total          = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
 
2302   $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
 
2303   $totaltax       = $form->format_amount(\%myconfig, $totaltax, 2, " ");
 
2305   $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
 
2306   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
 
2307   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
 
2309   map { print "$column_data{$_}\n" } @column_index;
 
2317     <td><hr size=3 noshade></td>
 
2325   $main::lxdebug->leave_sub();
 
2329   $main::lxdebug->enter_sub();
 
2331   my $form     = $main::form;
 
2332   my %myconfig = %main::myconfig;
 
2333   my $locale   = $main::locale;
 
2335   map { $column_data{$_} = "<td> </td>" } @column_index;
 
2337   $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
 
2338   $subtotaltax       = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
 
2339   $subtotal          = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, " ");
 
2341   $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
 
2342   $column_data{tax}       = "<th class=listsubtotal align=right>$subtotaltax</th>";
 
2343   $column_data{amount}    = "<th class=listsubtotal align=right>$subtotal</th>";
 
2345   $subtotalnetamount = 0;
 
2349         <tr class=listsubtotal>
 
2351   map { print "\n$column_data{$_}" } @column_index;
 
2357   $main::lxdebug->leave_sub();
 
2361   $main::lxdebug->enter_sub();
 
2363   $main::auth->assert('cash');
 
2365   my $form     = $main::form;
 
2366   my %myconfig = %main::myconfig;
 
2367   my $locale   = $main::locale;
 
2369   if ($form->{account}) {
 
2370     ($form->{paymentaccounts}) = split /--/, $form->{account};
 
2374   if ($form->{department}) {
 
2375     (my $department, $form->{department_id}) = split /--/, $form->{department};
 
2376     $option = $locale->text('Department') . " : $department";
 
2379   report_generator_set_default_sort('transdate', 1);
 
2381   RP->payments(\%myconfig, \%$form);
 
2383   my @hidden_variables = qw(account title department reference source memo fromdate todate
 
2384                             fx_transaction db prepayment paymentaccounts sort);
 
2386   my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
 
2387   $form->{callback} = $href;
 
2389   my @columns     = qw(transdate invnumber name paid source memo);
 
2391     'name'      => { 'text' => $locale->text('Description'), },
 
2392     'invnumber' => { 'text' => $locale->text('Reference'), },
 
2393     'transdate' => { 'text' => $locale->text('Date'), },
 
2394     'paid'      => { 'text' => $locale->text('Amount'), },
 
2395     'source'    => { 'text' => $locale->text('Source'), },
 
2396     'memo'      => { 'text' => $locale->text('Memo'), },
 
2398   my %column_alignment = ('paid' => 'right');
 
2400   foreach my $name (grep { $_ ne 'paid' } @columns) {
 
2401     my $sortdir                 = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
 
2402     $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir";
 
2406   if ($form->{fromdate}) {
 
2407     push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
 
2409   if ($form->{todate}) {
 
2410     push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
 
2413   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
2415   my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
 
2417   $report->set_options('top_info_text'         => join("\n", @options),
 
2418                        'output_format'         => 'HTML',
 
2419                        'title'                 => $form->{title},
 
2420                        'attachment_basename'   => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
2421                        'std_column_visibility' => 1,
 
2423   $report->set_options_from_form();
 
2425   $report->set_columns(%column_defs);
 
2426   $report->set_column_order(@columns);
 
2428   $report->set_export_options('list_payments', @hidden_variables, qw(sort sortdir));
 
2430   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
2434   foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
 
2435     next unless @{ $form->{ $ref->{id} } };
 
2437     $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
 
2439     my $subtotal_paid = 0;
 
2441     foreach my $payment (@{ $form->{ $ref->{id} } }) {
 
2442       my $module = $payment->{module};
 
2443       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
 
2444       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
 
2446       $subtotal_paid += $payment->{paid};
 
2447       $total_paid    += $payment->{paid};
 
2449       $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
 
2453       foreach my $column (@columns) {
 
2455           'data'  => $payment->{$column},
 
2456           'align' => $column_alignment{$column},
 
2460       $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
 
2462       $report->add_data($row);
 
2465     my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
 
2467       'data'  => $form->format_amount(\%myconfig, $subtotal_paid, 2),
 
2469       'class' => 'listsubtotal',
 
2472     $report->add_data($row);
 
2475   $report->add_separator();
 
2477   my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
 
2479     'data'  => $form->format_amount(\%myconfig, $total_paid, 2),
 
2481     'class' => 'listtotal',
 
2484   $report->add_data($row);
 
2486   $report->generate_with_headers();
 
2488   $main::lxdebug->leave_sub();
 
2492   $main::lxdebug->enter_sub();
 
2494   my ($dont_print) = @_;
 
2496   my $form     = $main::form;
 
2497   my %myconfig = %main::myconfig;
 
2498   my $locale   = $main::locale;
 
2500   $form->{sendmode} = "attachment";
 
2503     $form->{"format"} ? $form->{"format"} :
 
2504     $myconfig{"template_format"} ? $myconfig{"template_format"} :
 
2508     $form->{"copies"} ? $form->{"copies"} :
 
2509     $myconfig{"copies"} ? $myconfig{"copies"} :
 
2512   $form->{PD}{ $form->{type} }     = "selected";
 
2513   $form->{DF}{ $form->{format} }   = "selected";
 
2514   $form->{OP}{ $form->{media} }    = "selected";
 
2515   $form->{SM}{ $form->{sendmode} } = "selected";
 
2519             <option value=statement $form->{PD}{statement}>| . $locale->text('Statement');
 
2521   if ($form->{media} eq 'email') {
 
2523             <option value=attachment $form->{SM}{attachment}>| . $locale->text('Attachment') . qq|
 
2524             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
 
2527             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
 
2528     if ($myconfig{printer} && $main::latex_templates) {
 
2530             <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
 
2535   if ($main::latex_templates) {
 
2537             <option value=html $form->{DF}{html}>| . $locale->text('HTML')
 
2538       . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
 
2539       . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
 
2545     <td><select name=type>$type</select></td>
 
2546     <td><select name=format>$format</select></td>
 
2547     <td><select name=media>$media</select></td>
 
2550   if ($myconfig{printer} && $main::latex_templates && $form->{media} ne 'email') {
 
2552       <td>| . $locale->text('Copies') . qq|
 
2553       <input name=copies size=2 value=$form->{copies}></td>
 
2562   print $output unless $dont_print;
 
2564   $main::lxdebug->leave_sub();
 
2570   $main::lxdebug->enter_sub();
 
2572   $main::auth->assert('report');
 
2574   my $form     = $main::form;
 
2575   my %myconfig = %main::myconfig;
 
2576   my $locale   = $main::locale;
 
2578   $form->{padding} = "  ";
 
2579   $form->{bold}    = "<b>";
 
2580   $form->{endbold} = "</b>";
 
2581   $form->{br}      = "<br>";
 
2583   if ($form->{reporttype} eq "custom") {
 
2585     #forgotten the year --> thisyear
 
2586     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
2587       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
2593     if ($form->{duetyp} eq "13") {
 
2594       $form->{fromdate}        = "1.1.$form->{year}";
 
2595       $form->{todate}          = "31.12.$form->{year}";
 
2596       $form->{comparefromdate} = "1.01.$form->{year}";
 
2597       $form->{comparetodate}   = "31.12.$form->{year}";
 
2601     if ($form->{duetyp} eq "A") {
 
2602       $form->{fromdate}        = "1.1.$form->{year}";
 
2603       $form->{todate}          = "31.3.$form->{year}";
 
2604       $form->{comparefromdate} = "1.01.$form->{year}";
 
2605       $form->{comparetodate}   = "31.03.$form->{year}";
 
2607     if ($form->{duetyp} eq "B") {
 
2608       $form->{fromdate}        = "1.4.$form->{year}";
 
2609       $form->{todate}          = "30.6.$form->{year}";
 
2610       $form->{comparefromdate} = "1.01.$form->{year}";
 
2611       $form->{comparetodate}   = "30.06.$form->{year}";
 
2613     if ($form->{duetyp} eq "C") {
 
2614       $form->{fromdate}        = "1.7.$form->{year}";
 
2615       $form->{todate}          = "30.9.$form->{year}";
 
2616       $form->{comparefromdate} = "1.01.$form->{year}";
 
2617       $form->{comparetodate}   = "30.09.$form->{year}";
 
2619     if ($form->{duetyp} eq "D") {
 
2620       $form->{fromdate}        = "1.10.$form->{year}";
 
2621       $form->{todate}          = "31.12.$form->{year}";
 
2622       $form->{comparefromdate} = "1.01.$form->{year}";
 
2623       $form->{comparetodate}   = "31.12.$form->{year}";
 
2628       $form->{duetyp} eq "1" && do {
 
2629         $form->{fromdate}        = "1.1.$form->{year}";
 
2630         $form->{todate}          = "31.1.$form->{year}";
 
2631         $form->{comparefromdate} = "1.01.$form->{year}";
 
2632         $form->{comparetodate}   = "31.01.$form->{year}";
 
2635       $form->{duetyp} eq "2" && do {
 
2636         $form->{fromdate} = "1.2.$form->{year}";
 
2638         #this works from 1901 to 2099, 1900 and 2100 fail.
 
2639         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
2640         $form->{todate}          = "$leap.2.$form->{year}";
 
2641         $form->{comparefromdate} = "1.01.$form->{year}";
 
2642         $form->{comparetodate}   = "$leap.02.$form->{year}";
 
2645       $form->{duetyp} eq "3" && do {
 
2646         $form->{fromdate}        = "1.3.$form->{year}";
 
2647         $form->{todate}          = "31.3.$form->{year}";
 
2648         $form->{comparefromdate} = "1.01.$form->{year}";
 
2649         $form->{comparetodate}   = "31.03.$form->{year}";
 
2652       $form->{duetyp} eq "4" && do {
 
2653         $form->{fromdate}        = "1.4.$form->{year}";
 
2654         $form->{todate}          = "30.4.$form->{year}";
 
2655         $form->{comparefromdate} = "1.01.$form->{year}";
 
2656         $form->{comparetodate}   = "30.04.$form->{year}";
 
2659       $form->{duetyp} eq "5" && do {
 
2660         $form->{fromdate}        = "1.5.$form->{year}";
 
2661         $form->{todate}          = "31.5.$form->{year}";
 
2662         $form->{comparefromdate} = "1.01.$form->{year}";
 
2663         $form->{comparetodate}   = "31.05.$form->{year}";
 
2666       $form->{duetyp} eq "6" && do {
 
2667         $form->{fromdate}        = "1.6.$form->{year}";
 
2668         $form->{todate}          = "30.6.$form->{year}";
 
2669         $form->{comparefromdate} = "1.01.$form->{year}";
 
2670         $form->{comparetodate}   = "30.06.$form->{year}";
 
2673       $form->{duetyp} eq "7" && do {
 
2674         $form->{fromdate}        = "1.7.$form->{year}";
 
2675         $form->{todate}          = "31.7.$form->{year}";
 
2676         $form->{comparefromdate} = "1.01.$form->{year}";
 
2677         $form->{comparetodate}   = "31.07.$form->{year}";
 
2680       $form->{duetyp} eq "8" && do {
 
2681         $form->{fromdate}        = "1.8.$form->{year}";
 
2682         $form->{todate}          = "31.8.$form->{year}";
 
2683         $form->{comparefromdate} = "1.01.$form->{year}";
 
2684         $form->{comparetodate}   = "31.08.$form->{year}";
 
2687       $form->{duetyp} eq "9" && do {
 
2688         $form->{fromdate}        = "1.9.$form->{year}";
 
2689         $form->{todate}          = "30.9.$form->{year}";
 
2690         $form->{comparefromdate} = "1.01.$form->{year}";
 
2691         $form->{comparetodate}   = "30.09.$form->{year}";
 
2694       $form->{duetyp} eq "10" && do {
 
2695         $form->{fromdate}        = "1.10.$form->{year}";
 
2696         $form->{todate}          = "31.10.$form->{year}";
 
2697         $form->{comparefromdate} = "1.01.$form->{year}";
 
2698         $form->{comparetodate}   = "31.10.$form->{year}";
 
2701       $form->{duetyp} eq "11" && do {
 
2702         $form->{fromdate}        = "1.11.$form->{year}";
 
2703         $form->{todate}          = "30.11.$form->{year}";
 
2704         $form->{comparefromdate} = "1.01.$form->{year}";
 
2705         $form->{comparetodate}   = "30.11.$form->{year}";
 
2708       $form->{duetyp} eq "12" && do {
 
2709         $form->{fromdate}        = "1.12.$form->{year}";
 
2710         $form->{todate}          = "31.12.$form->{year}";
 
2711         $form->{comparefromdate} = "1.01.$form->{year}";
 
2712         $form->{comparetodate}   = "31.12.$form->{year}";
 
2717     # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
 
2718     # ansonsten ist die prüfung in RP.pm 
 
2719     # if (defined ($form->{fromdate|todate}=='..'))
 
2721     if ($form->{fromdate}){
 
2722       my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
 
2723       $form->{fromdate} = "${dd}.${mm}.${yy}";
 
2724       $form->{comparefromdate} = "01.01.$yy";
 
2726     if ($form->{todate}){
 
2727       my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
 
2728       $form->{todate}          = "${dd}.${mm}.${yy}";
 
2729       $form->{comparetodate}   = $form->{todate};
 
2733   RP->bwa(\%myconfig, \%$form);
 
2735   ($form->{department}) = split /--/, $form->{department};
 
2738     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2739   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
2741   # if there are any dates construct a where
 
2742   if ($form->{fromdate} || $form->{todate}) {
 
2744     unless ($form->{todate}) {
 
2745       $form->{todate} = $form->current_date(\%myconfig);
 
2748     my %germandate = ("dateformat" => "dd.mm.yyyy");
 
2750     my $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
 
2751     my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
 
2753     my $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
 
2754     my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
 
2756     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
2758         $locale->text('for Period')
 
2759       . qq|\n$longfromdate |
 
2760       . $locale->text('bis')
 
2764   # setup variables for the form
 
2765   my @a = qw(company address businessnumber);
 
2766   map { $form->{$_} = $myconfig{$_} } @a;
 
2767   $form->{templates} = $myconfig{templates};
 
2769   $form->{IN} = "bwa.html";
 
2771   $form->parse_template;
 
2773   $main::lxdebug->leave_sub();