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;
 
  45 require "bin/mozilla/arap.pl";
 
  46 require "bin/mozilla/common.pl";
 
  47 require "bin/mozilla/reportgenerator.pl";
 
  53 # this is for our long dates
 
  54 # $locale->text('January')
 
  55 # $locale->text('February')
 
  56 # $locale->text('March')
 
  57 # $locale->text('April')
 
  58 # $locale->text('May ')
 
  59 # $locale->text('June')
 
  60 # $locale->text('July')
 
  61 # $locale->text('August')
 
  62 # $locale->text('September')
 
  63 # $locale->text('October')
 
  64 # $locale->text('November')
 
  65 # $locale->text('December')
 
  67 # this is for our short month
 
  68 # $locale->text('Jan')
 
  69 # $locale->text('Feb')
 
  70 # $locale->text('Mar')
 
  71 # $locale->text('Apr')
 
  72 # $locale->text('May')
 
  73 # $locale->text('Jun')
 
  74 # $locale->text('Jul')
 
  75 # $locale->text('Aug')
 
  76 # $locale->text('Sep')
 
  77 # $locale->text('Oct')
 
  78 # $locale->text('Nov')
 
  79 # $locale->text('Dec')
 
  81 # $locale->text('Balance Sheet')
 
  82 # $locale->text('Income Statement')
 
  83 # $locale->text('Trial Balance')
 
  84 # $locale->text('AR Aging')
 
  85 # $locale->text('AP Aging')
 
  86 # $locale->text('Tax collected')
 
  87 # $locale->text('Tax paid')
 
  88 # $locale->text('Receipts')
 
  89 # $locale->text('Payments')
 
  90 # $locale->text('Project Transactions')
 
  91 # $locale->text('Non-taxable Sales')
 
  92 # $locale->text('Non-taxable Purchases')
 
  95   $lxdebug->enter_sub();
 
  97   %title = ('balance_sheet'        => 'Balance Sheet',
 
  98             'income_statement'     => 'Income Statement',
 
  99             'trial_balance'        => 'Trial Balance',
 
 100             'ar_aging'             => 'AR Aging',
 
 101             'ap_aging'             => 'Offene Verbindlichkeiten',
 
 102             'tax_collected'        => 'Tax collected',
 
 103             'tax_paid'             => 'Tax paid',
 
 104             'nontaxable_sales'     => 'Non-taxable Sales',
 
 105             'nontaxable_purchases' => 'Non-taxable Purchases',
 
 106             'receipts'             => 'Receipts',
 
 107             'payments'             => 'Payments',
 
 108             'projects'             => 'Project Transactions',
 
 109             'bwa'                  => 'Betriebswirtschaftliche Auswertung',);
 
 111   $form->{title} = $locale->text($title{ $form->{report} });
 
 113   $accrual = ($eur) ? ""        : "checked";
 
 114   $cash    = ($eur) ? "checked" : "";
 
 116   $year = (localtime)[5] + 1900;
 
 119   $form->all_departments(\%myconfig);
 
 120   if (@{ $form->{all_departments} }) {
 
 121     $form->{selectdepartment} = "<option>\n";
 
 124       $form->{selectdepartment} .=
 
 125         "<option>$_->{description}--$_->{id}\n"
 
 126     } (@{ $form->{all_departments} });
 
 131           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 132           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 134 | if $form->{selectdepartment};
 
 136   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 139   my %project_labels = ();
 
 140   my @project_values = ("");
 
 141   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 142     push(@project_values, $item->{"id"});
 
 143     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 147     NTI($cgi->popup_menu('-name' => "project_id",
 
 148                          '-values' => \@project_values,
 
 149                          '-labels' => \%project_labels));
 
 151   # use JavaScript Calendar or not
 
 152   $form->{jsscript} = 1;
 
 154   if ($form->{report} eq "balance_sheet") {
 
 155     $name_1    = "asofdate";
 
 157     $value_1   = "$form->{asofdate}";
 
 158     $trigger_1 = "trigger1";
 
 159     $name_2    = "compareasofdate";
 
 160     $id_2      = "compareasofdate";
 
 161     $value_2   = "$form->{compareasofdate}";
 
 162     $trigger_2 = "trigger2";
 
 163   } elsif ($form->{report} =~ /(receipts|payments)$/) {
 
 164     $name_1    = "fromdate";
 
 166     $value_1   = "$form->{fromdate}";
 
 167     $trigger_1 = "trigger1";
 
 171     $trigger_2 = "trigger2";
 
 172   } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
 
 180     $trigger_2 = "trigger2";
 
 183     $name_1    = "fromdate";
 
 185     $value_1   = "$form->{fromdate}";
 
 186     $trigger_1 = "trigger1";
 
 190     $trigger_2 = "trigger2";
 
 193   # with JavaScript Calendar
 
 194   if ($form->{jsscript}) {
 
 198          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 200         <input type=button name=$name_2 id="$trigger_2" value=|
 
 201         . $locale->text('button') . qq|>|;
 
 205         Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
 
 208          <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
 
 210         <input type=button name=$name_1 id="$trigger_1" value=|
 
 211         . $locale->text('button') . qq|>|;
 
 213          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 215          <input type=button name=$name_2 id="$trigger_2" value=|
 
 216         . $locale->text('button') . qq|>
 
 221         Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
 
 222                             "$name_2", "BL", "$trigger_2");
 
 226     # without JavaScript Calendar
 
 229         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 232         qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
 
 234         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 237   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 239   $onload = qq|focus()|;
 
 240   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 241   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 243 <body onLoad="$onload">
 
 245 <form method=post action=$form->{script}>
 
 247 <input type=hidden name=title value="$form->{title}">
 
 251     <th class=listtop>$form->{title}</th>
 
 260   if ($form->{report} eq "projects") {
 
 263           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 264           <td colspan=5><input name=projectnumber size=25</td>
 
 266         <input type=hidden name=nextsub value=generate_projects>
 
 268           <th align=right>| . $locale->text('From') . qq|</th>
 
 271           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 282           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 283           <td><input name=l_heading class=checkbox type=checkbox value=Y> |
 
 284       . $locale->text('Heading') . qq|
 
 285           <input name=l_subtotal class=checkbox type=checkbox value=Y> |
 
 286       . $locale->text('Subtotal') . qq|</td>
 
 293   if ($form->{report} eq "income_statement") {
 
 296           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 297           <td colspan=3>$projectnumber</td>
 
 299         <input type=hidden name=nextsub value=generate_income_statement>
 
 303           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
 
 304       . $locale->text('Customized Report') . qq|</th>
 
 307           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 308           <td><input name=year size=11 title="|
 
 309       . $locale->text('YYYY') . qq|" value="$year"></td>
 
 316 <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 317                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 318                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 321                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 323                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
 
 324       . $locale->text('Quarter') . qq|</td>
 
 328                 <td><input name=duetyp class=radio type=radio value="1" $checked > |
 
 329       . $locale->text('January') . qq|</td>
 
 333                 <td><input name=duetyp class=radio type=radio value="5" $checked > |
 
 334       . $locale->text('May') . qq|</td>
 
 335                 <td><input name=duetyp class=radio type=radio value="9" $checked > |
 
 336       . $locale->text('September') . qq|</td>
 
 340                 <td align= right> </td>
 
 341                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
 
 342       . $locale->text('Quarter') . qq|</td>
 
 343                 <td><input name=duetyp class=radio type=radio value="2" $checked > |
 
 344       . $locale->text('February') . qq|</td>
 
 345                 <td><input name=duetyp class=radio type=radio value="6" $checked > |
 
 346       . $locale->text('June') . qq|</td>
 
 347                 <td><input name=duetyp class=radio type=radio value="10" $checked > |
 
 348       . $locale->text('October') . qq|</td>
 
 352                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
 
 353       . $locale->text('Quarter') . qq|</td>
 
 354                 <td><input name=duetyp class=radio type=radio value="3" $checked > |
 
 355       . $locale->text('March') . qq|</td>
 
 356                 <td><input name=duetyp class=radio type=radio value="7" $checked > |
 
 357       . $locale->text('July') . qq|</td>
 
 358                 <td><input name=duetyp class=radio type=radio value="11" $checked > |
 
 359       . $locale->text('November') . qq|</td>
 
 364                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
 
 365       . $locale->text('Quarter') . qq| </td>
 
 366                 <td><input name=duetyp class=radio type=radio value="4" $checked > |
 
 367       . $locale->text('April') . qq|</td>
 
 368                 <td><input name=duetyp class=radio type=radio value="8" $checked > |
 
 369       . $locale->text('August') . qq|</td>
 
 370                 <td><input name=duetyp class=radio type=radio value="12" $checked > |
 
 371       . $locale->text('December') . qq|</td>
 
 375                 <td colspan=5><hr size=3 noshade></td>
 
 378           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
 
 379       . $locale->text('Free report period') . qq|</th>
 
 380           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 383               | . $locale->text('Bis') . qq|
 
 389                 <td colspan=5><hr size=3 noshade></td>
 
 392           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 393           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 394       . $locale->text('Accrual') . qq|
 
 395            <input name=method class=radio type=radio value=cash $cash>|
 
 396       . $locale->text('EUR') . qq|</td>
 
 403   if ($form->{report} eq "bwa") {
 
 406           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 407           <td colspan=3>$projectnumber</td>
 
 409         <input type=hidden name=nextsub value=generate_bwa>
 
 413           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
 
 414       . $locale->text('Customized Report') . qq|</th>
 
 417           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 418           <td><input name=year size=11 title="|
 
 419       . $locale->text('YYYY') . qq|" value="$year"></td>
 
 426 <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 427                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 428                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 431                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 433                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
 
 434       . $locale->text('Quarter') . qq|</td>
 
 436     $checked = "checked";
 
 438                 <td><input name=duetyp class=radio type=radio value="1" $checked > |
 
 439       . $locale->text('January') . qq|</td>
 
 443                 <td><input name=duetyp class=radio type=radio value="5" $checked > |
 
 444       . $locale->text('May') . qq|</td>
 
 445                 <td><input name=duetyp class=radio type=radio value="9" $checked > |
 
 446       . $locale->text('September') . qq|</td>
 
 450                 <td align= right> </td>
 
 451                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
 
 452       . $locale->text('Quarter') . qq|</td>
 
 453                 <td><input name=duetyp class=radio type=radio value="2" $checked > |
 
 454       . $locale->text('February') . qq|</td>
 
 455                 <td><input name=duetyp class=radio type=radio value="6" $checked > |
 
 456       . $locale->text('June') . qq|</td>
 
 457                 <td><input name=duetyp class=radio type=radio value="10" $checked > |
 
 458       . $locale->text('October') . qq|</td>
 
 462                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
 
 463       . $locale->text('Quarter') . qq|</td>
 
 464                 <td><input name=duetyp class=radio type=radio value="3" $checked > |
 
 465       . $locale->text('March') . qq|</td>
 
 466                 <td><input name=duetyp class=radio type=radio value="7" $checked > |
 
 467       . $locale->text('July') . qq|</td>
 
 468                 <td><input name=duetyp class=radio type=radio value="11" $checked > |
 
 469       . $locale->text('November') . qq|</td>
 
 474                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
 
 475       . $locale->text('Quarter') . qq| </td>
 
 476                 <td><input name=duetyp class=radio type=radio value="4" $checked > |
 
 477       . $locale->text('April') . qq|</td>
 
 478                 <td><input name=duetyp class=radio type=radio value="8" $checked > |
 
 479       . $locale->text('August') . qq|</td>
 
 480                 <td><input name=duetyp class=radio type=radio value="12" $checked > |
 
 481       . $locale->text('December') . qq|</td>
 
 485                 <td colspan=5><hr size=3 noshade></td>
 
 488           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
 
 489       . $locale->text('Free report period') . qq|</th>
 
 490           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 493               | . $locale->text('Bis') . qq| 
 
 499                 <td colspan=5><hr size=3 noshade></td>
 
 502           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 503           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 504       . $locale->text('Accrual') . qq|
 
 505            <input name=method class=radio type=radio value=cash $cash>|
 
 506       . $locale->text('EUR') . qq|</td>
 
 509          <th align=right colspan=4>|
 
 510       . $locale->text('Decimalplaces')
 
 512              <td><input name=decimalplaces size=3 value="2"></td>
 
 519   if ($form->{report} eq "balance_sheet") {
 
 521         <input type=hidden name=nextsub value=generate_balance_sheet>
 
 523           <th align=right>| . $locale->text('as at') . qq|</th>
 
 528           <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
 
 535           <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
 
 536           <td><input name=decimalplaces size=3 value="2"></td>
 
 545           <th align=right>| . $locale->text('Method') . qq|</th>
 
 546           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 547       . $locale->text('Accrual') . qq|
 
 548            <input name=method class=radio type=radio value=cash $cash>|
 
 549       . $locale->text('EUR') . qq|</td>
 
 553           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 554           <td><input name=l_heading class=checkbox type=checkbox value=Y> |
 
 555       . $locale->text('Heading') . qq|
 
 556           <input name=l_subtotal class=checkbox type=checkbox value=Y> |
 
 557       . $locale->text('Subtotal') . qq|
 
 558           <input name=l_accno class=checkbox type=checkbox value=Y> |
 
 559       . $locale->text('Account Number') . qq|</td>
 
 566   if ($form->{report} eq "trial_balance") {
 
 568         <input type=hidden name=nextsub value=generate_trial_balance>
 
 569         <input type=hidden name=eur value=$eur>
 
 571           <th align=right>| . $locale->text('From') . qq|</th>
 
 576           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 589           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 590           <td><input name=l_heading class=checkbox type=checkbox value=Y> |
 
 591       . $locale->text('Heading') . qq|
 
 592           <input name=l_subtotal class=checkbox type=checkbox value=Y> |
 
 593       . $locale->text('Subtotal') . qq|
 
 594           <input name=all_accounts class=checkbox type=checkbox value=Y> |
 
 595       . $locale->text('All Accounts') . qq|</td>
 
 602   if ($form->{report} =~ /^tax_/) {
 
 603     $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
 
 605     RP->get_taxaccounts(\%myconfig, \%$form);
 
 608         <input type=hidden name=nextsub value=generate_tax_report>
 
 610           <th align=right>| . $locale->text('From') . qq|</th>
 
 611           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
 
 612           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 613           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
 
 616           <th align=right>| . $locale->text('Report for') . qq|</th>
 
 620     $checked = "checked";
 
 621     foreach $ref (@{ $form->{taxaccounts} }) {
 
 624         qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
 
 626     <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
 
 627     <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
 
 634   <input type=hidden name=db value=$form->{db}>
 
 635   <input type=hidden name=sort value=transdate>
 
 640           <th align=right>| . $locale->text('Method') . qq|</th>
 
 641           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 642       . $locale->text('Accrual') . qq|
 
 643            <input name=method class=radio type=radio value=cash $cash>|
 
 644       . $locale->text('EUR') . qq|</td>
 
 653           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 657                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 658                 <td>| . $locale->text('ID') . qq|</td>
 
 659                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
 660                 <td>| . $locale->text('Invoice') . qq|</td>
 
 661                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 662                 <td>| . $locale->text('Date') . qq|</td>
 
 665                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
 668     if ($form->{db} eq 'ar') {
 
 669       print $locale->text('Customer');
 
 671     if ($form->{db} eq 'ap') {
 
 672       print $locale->text('Vendor');
 
 676                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
 
 677                 <td>| . $locale->text('Amount') . qq|</td>
 
 678                 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
 
 679                 <td>| . $locale->text('Tax') . qq|</td>
 
 680                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
 
 681                 <td>| . $locale->text('Total') . qq|</td>
 
 684                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 685                 <td>| . $locale->text('Subtotal') . qq|</td>
 
 694   if ($form->{report} =~ /^nontaxable_/) {
 
 695     $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
 
 698         <input type=hidden name=nextsub value=generate_tax_report>
 
 700         <input type=hidden name=db value=$form->{db}>
 
 701         <input type=hidden name=sort value=transdate>
 
 702         <input type=hidden name=report value=$form->{report}>
 
 705           <th align=right>| . $locale->text('From') . qq|</th>
 
 706           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
 
 707           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 708           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
 
 711           <th align=right>| . $locale->text('Method') . qq|</th>
 
 712           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 713       . $locale->text('Accrual') . qq|
 
 714            <input name=method class=radio type=radio value=cash $cash>|
 
 715       . $locale->text('EUR') . qq|</td>
 
 718           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 722                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 723                 <td>| . $locale->text('ID') . qq|</td>
 
 724                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
 725                 <td>| . $locale->text('Invoice') . qq|</td>
 
 726                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 727                 <td>| . $locale->text('Date') . qq|</td>
 
 730                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
 733     if ($form->{db} eq 'ar') {
 
 734       print $locale->text('Customer');
 
 736     if ($form->{db} eq 'ap') {
 
 737       print $locale->text('Vendor');
 
 741                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
 
 742                 <td>| . $locale->text('Amount') . qq|</td>
 
 743                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
 
 744                 <td>| . $locale->text('Total') . qq|</td>
 
 747                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 748                 <td>| . $locale->text('Subtotal') . qq|</td>
 
 757   if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
 
 758     if ($form->{report} eq 'ar_aging') {
 
 759       $label = $locale->text('Customer');
 
 760       $form->{vc} = 'customer';
 
 762       $label = $locale->text('Vendor');
 
 763       $form->{vc} = 'vendor';
 
 766     $nextsub = "generate_$form->{report}";
 
 769     $form->all_vc(\%myconfig, $form->{vc},
 
 770                   ($form->{vc} eq 'customer') ? "AR" : "AP");
 
 772     map { $vc .= "<option>$_->{name}--$_->{id}\n" }
 
 773       @{ $form->{"all_$form->{vc}"} };
 
 777       ? qq|<select name=$form->{vc}><option>\n$vc</select>|
 
 778       : qq|<input name=$form->{vc} size=35>|;
 
 782           <th align=right>| . $locale->text($label) . qq|</th>
 
 786           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 792         <input type=hidden name=type value=statement>
 
 793         <input type=hidden name=format value=html>
 
 794         <input type=hidden name=media value=screen>
 
 796         <input type=hidden name=nextsub value=$nextsub>
 
 797         <input type=hidden name=action value=$nextsub>
 
 803   # above action can be removed if there is more than one input field
 
 805   if ($form->{report} =~ /(receipts|payments)$/) {
 
 806     $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
 
 808     RP->paymentaccounts(\%myconfig, \%$form);
 
 810     $selection = "<option>\n";
 
 811     foreach $ref (@{ $form->{PR} }) {
 
 812       $paymentaccounts .= "$ref->{accno} ";
 
 813       $selection       .= "<option>$ref->{accno}--$ref->{description}\n";
 
 816     chop $paymentaccounts;
 
 819         <input type=hidden name=nextsub value=list_payments>
 
 821           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
 
 822           <td colspan=3><select name=account>$selection</select>
 
 823             <input type=hidden name=paymentaccounts value="$paymentaccounts">
 
 827           <th align=right>| . $locale->text('Reference') . qq|</th>
 
 828           <td colspan=3><input name=reference></td>
 
 831           <th align=right nowrap>| . $locale->text('Source') . qq|</th>
 
 832           <td colspan=3><input name=source></td>
 
 835           <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
 
 836           <td colspan=3><input name=memo size=30></td>
 
 839           <th align=right>| . $locale->text('From') . qq|</th>
 
 844           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 851           <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
 
 852           <th align=left colspan=3>|
 
 853       . $locale->text('Include Exchangerate Difference') . qq|</td>
 
 858           <input type=hidden name=db value=$form->{db}>
 
 859           <input type=hidden name=sort value=transdate>
 
 870     <td><hr size=3 noshade></td>
 
 875 <input type=hidden name=login value=$form->{login}>
 
 876 <input type=hidden name=password value=$form->{password}>
 
 878 <input type=submit class=submit name=action value="|
 
 879     . $locale->text('Continue') . qq|">
 
 887   $lxdebug->leave_sub();
 
 890 sub continue { call_sub($form->{"nextsub"}); }
 
 893   $lxdebug->enter_sub();
 
 896   $form->{project_id} = $form->{project_id_1};
 
 897   if ($form->{projectnumber} && !$form->{project_id}) {
 
 898     $form->{rowcount} = 1;
 
 900     # call this instead of update
 
 901     $form->{update}          = $nextsub;
 
 902     $form->{projectnumber_1} = $form->{projectnumber};
 
 904     delete $form->{sort};
 
 907     # if there is one only, assign id
 
 908     $form->{project_id} = $form->{project_id_1};
 
 911   $lxdebug->leave_sub();
 
 914 sub generate_income_statement {
 
 915   $lxdebug->enter_sub();
 
 917   $form->{padding} = "  ";
 
 918   $form->{bold}    = "<b>";
 
 919   $form->{endbold} = "</b>";
 
 920   $form->{br}      = "<br>";
 
 922   if ($form->{reporttype} eq "custom") {
 
 924     #forgotten the year --> thisyear
 
 925     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
 926       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
 932     if ($form->{duetyp} eq "13") {
 
 933       $form->{fromdate} = "1.1.$form->{year}";
 
 934       $form->{todate}   = "31.12.$form->{year}";
 
 938     if ($form->{duetyp} eq "A") {
 
 939       $form->{fromdate} = "1.1.$form->{year}";
 
 940       $form->{todate}   = "31.3.$form->{year}";
 
 942     if ($form->{duetyp} eq "B") {
 
 943       $form->{fromdate} = "1.4.$form->{year}";
 
 944       $form->{todate}   = "30.6.$form->{year}";
 
 946     if ($form->{duetyp} eq "C") {
 
 947       $form->{fromdate} = "1.7.$form->{year}";
 
 948       $form->{todate}   = "30.9.$form->{year}";
 
 950     if ($form->{duetyp} eq "D") {
 
 951       $form->{fromdate} = "1.10.$form->{year}";
 
 952       $form->{todate}   = "31.12.$form->{year}";
 
 957       $form->{duetyp} eq "1" && do {
 
 958         $form->{fromdate} = "1.1.$form->{year}";
 
 959         $form->{todate}   = "31.1.$form->{year}";
 
 962       $form->{duetyp} eq "2" && do {
 
 963         $form->{fromdate} = "1.2.$form->{year}";
 
 965         #this works from 1901 to 2099, 1900 and 2100 fail.
 
 966         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
 967         $form->{todate} = "$leap.2.$form->{year}";
 
 970       $form->{duetyp} eq "3" && do {
 
 971         $form->{fromdate} = "1.3.$form->{year}";
 
 972         $form->{todate}   = "31.3.$form->{year}";
 
 975       $form->{duetyp} eq "4" && do {
 
 976         $form->{fromdate} = "1.4.$form->{year}";
 
 977         $form->{todate}   = "30.4.$form->{year}";
 
 980       $form->{duetyp} eq "5" && do {
 
 981         $form->{fromdate} = "1.5.$form->{year}";
 
 982         $form->{todate}   = "31.5.$form->{year}";
 
 985       $form->{duetyp} eq "6" && do {
 
 986         $form->{fromdate} = "1.6.$form->{year}";
 
 987         $form->{todate}   = "30.6.$form->{year}";
 
 990       $form->{duetyp} eq "7" && do {
 
 991         $form->{fromdate} = "1.7.$form->{year}";
 
 992         $form->{todate}   = "31.7.$form->{year}";
 
 995       $form->{duetyp} eq "8" && do {
 
 996         $form->{fromdate} = "1.8.$form->{year}";
 
 997         $form->{todate}   = "31.8.$form->{year}";
 
1000       $form->{duetyp} eq "9" && do {
 
1001         $form->{fromdate} = "1.9.$form->{year}";
 
1002         $form->{todate}   = "30.9.$form->{year}";
 
1005       $form->{duetyp} eq "10" && do {
 
1006         $form->{fromdate} = "1.10.$form->{year}";
 
1007         $form->{todate}   = "31.10.$form->{year}";
 
1010       $form->{duetyp} eq "11" && do {
 
1011         $form->{fromdate} = "1.11.$form->{year}";
 
1012         $form->{todate}   = "30.11.$form->{year}";
 
1015       $form->{duetyp} eq "12" && do {
 
1016         $form->{fromdate} = "1.12.$form->{year}";
 
1017         $form->{todate}   = "31.12.$form->{year}";
 
1023   RP->income_statement(\%myconfig, \%$form);
 
1025   ($form->{department}) = split /--/, $form->{department};
 
1028     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1029   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
1031   # if there are any dates construct a where
 
1032   if ($form->{fromdate} || $form->{todate}) {
 
1034     unless ($form->{todate}) {
 
1035       $form->{todate} = $form->current_date(\%myconfig);
 
1038     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
 
1039     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
 
1041     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1042     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
 
1044     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
1046         $locale->text('for Period')
 
1047       . qq|\n$longfromdate |
 
1048       . $locale->text('Bis')
 
1052   if ($form->{comparefromdate} || $form->{comparetodate}) {
 
1053     $longcomparefromdate =
 
1054       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
 
1055     $shortcomparefromdate =
 
1056       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
 
1058     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
 
1059     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
 
1061     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
 
1063         "\n$longcomparefromdate "
 
1064       . $locale->text('Bis')
 
1065       . qq| $longcomparetodate|;
 
1068   # setup variables for the form
 
1069   @a = qw(company address businessnumber);
 
1070   map { $form->{$_} = $myconfig{$_} } @a;
 
1072   $form->{templates} = $myconfig{templates};
 
1074   $form->{IN} = "income_statement.html";
 
1076   $form->parse_template;
 
1078   $lxdebug->leave_sub();
 
1081 sub generate_balance_sheet {
 
1082   $lxdebug->enter_sub();
 
1084   $form->{padding} = "  ";
 
1085   $form->{bold}    = "<b>";
 
1086   $form->{endbold} = "</b>";
 
1087   $form->{br}      = "<br>";
 
1089   RP->balance_sheet(\%myconfig, \%$form);
 
1091   $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
 
1093     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1095   ($form->{department}) = split /--/, $form->{department};
 
1097   # define Current Earnings account
 
1098   $padding = ($form->{l_heading}) ? $form->{padding} : "";
 
1099   push(@{ $form->{equity_account} },
 
1100        $padding . $locale->text('Current Earnings'));
 
1102   $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
 
1103   $form->{last_period} =
 
1104     $locale->date(\%myconfig, $form->{compareasofdate}, 0);
 
1106   $form->{IN} = "balance_sheet.html";
 
1108   # setup company variables for the form
 
1109   map { $form->{$_} = $myconfig{$_};
 
1110         $form->{$_} =~ s/\\n/\n/g; }
 
1111     (qw(company address businessnumber nativecurr));
 
1113   $form->{templates} = $myconfig{templates};
 
1115   $form->parse_template;
 
1117   $lxdebug->leave_sub();
 
1120 sub generate_projects {
 
1121   $lxdebug->enter_sub();
 
1123   &get_project(generate_projects);
 
1124   $form->{projectnumber} = $form->{projectnumber_1};
 
1126   $form->{nextsub} = "generate_projects";
 
1127   $form->{title}   = $locale->text('Project Transactions');
 
1128   RP->trial_balance(\%myconfig, \%$form);
 
1130   list_accounts('generate_projects');
 
1132   $lxdebug->leave_sub();
 
1138 # included links to display transactions for period entered
 
1139 # added headers and subtotals
 
1141 sub generate_trial_balance {
 
1142   $lxdebug->enter_sub();
 
1144   # get for each account initial balance, debits and credits
 
1145   RP->trial_balance(\%myconfig, \%$form);
 
1147   $form->{nextsub} = "generate_trial_balance";
 
1148   $form->{title}   = $locale->text('Trial Balance');
 
1149   list_accounts('generate_trial_balance');
 
1151   $lxdebug->leave_sub();
 
1154 sub create_list_accounts_subtotal_row {
 
1155   $lxdebug->enter_sub();
 
1157   my ($subtotals, $columns, $fields, $class) = @_;
 
1159   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
1161   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
 
1163   $lxdebug->leave_sub();
 
1169   $lxdebug->enter_sub();
 
1174   if ($form->{department}) {
 
1175     my ($department) = split /--/, $form->{department};
 
1176     push @options, $locale->text('Department') . " : $department";
 
1178   if ($form->{projectnumber}) {
 
1179     push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
 
1182   # if there are any dates
 
1183   if ($form->{fromdate} || $form->{todate}) {
 
1184     my ($fromdate, $todate);
 
1186     if ($form->{fromdate}) {
 
1187       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1189     if ($form->{todate}) {
 
1190       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
 
1193     push @options, "$fromdate - $todate";
 
1196     push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1199   my @columns     = qw(accno description begbalance debit credit endbalance);
 
1201     'accno'       => { 'text' => $locale->text('Account'), },
 
1202     'description' => { 'text' => $locale->text('Description'), },
 
1203     'debit'       => { 'text' => $locale->text('Debit'), },
 
1204     'credit'      => { 'text' => $locale->text('Credit'), },
 
1205     'begbalance'  => { 'text' => $locale->text('Balance'), },
 
1206     'endbalance'  => { 'text' => $locale->text('Balance'), },
 
1208   my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
 
1210   my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
 
1212   $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
 
1214   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1216   $report->set_options('top_info_text'         => join("\n", @options),
 
1217                        'output_format'         => 'HTML',
 
1218                        'title'                 => $form->{title},
 
1219                        'attachment_basename'   => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
 
1220                        'std_column_visibility' => 1,
 
1222   $report->set_options_from_form();
 
1224   $report->set_columns(%column_defs);
 
1225   $report->set_column_order(@columns);
 
1227   $report->set_export_options($action, @hidden_variables);
 
1229   $report->set_sort_indicator('accno', 1);
 
1231   my @totals_columns = qw(credit debit begbalance endbalance);
 
1232   my %subtotals      = map { $_ => 0 } @totals_columns;
 
1233   my %totals         = map { $_ => 0 } @totals_columns;
 
1234   my $found_heading  = 0;
 
1235   my @tb             = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
 
1237   # sort the whole thing by account numbers and display
 
1238   foreach my $idx (0 .. scalar(@tb) - 1) {
 
1239     my $ref  = $tb[$idx];
 
1240     my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
 
1242     my $ml   = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
 
1244     my $row  = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
 
1246     if ($ref->{charttype} eq 'H') {
 
1247       next unless ($form->{l_heading});
 
1249       %subtotals                   = map { $_ => 0 } @totals_columns;
 
1251       $row->{description}->{class} = 'listheading';
 
1252       $row->{description}->{data}  = $ref->{description};
 
1254       $report->add_data($row);
 
1259     foreach (qw(debit credit)) {
 
1260       $subtotals{$_} += $ref->{$_};
 
1261       $totals{$_}    += $ref->{$_};
 
1264     $subtotals{begbalance} += $ref->{balance} * $ml;
 
1265     $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
 
1267     map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
 
1268     map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
 
1270     $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
 
1271     $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
 
1273     $report->add_data($row);
 
1275     if ($form->{l_heading} && $found_heading &&
 
1276         (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
 
1277       $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
 
1281   $report->add_separator();
 
1283   $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
 
1285   $report->generate_with_headers();
 
1287   $lxdebug->leave_sub();
 
1290 sub generate_ar_aging {
 
1291   $lxdebug->enter_sub();
 
1294   ($form->{customer}) = split(/--/, $form->{customer});
 
1296   $form->{ct}   = "customer";
 
1297   $form->{arap} = "ar";
 
1299   $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
 
1301   RP->aging(\%myconfig, \%$form);
 
1304   $lxdebug->leave_sub();
 
1307 sub generate_ap_aging {
 
1308   $lxdebug->enter_sub();
 
1311   ($form->{vendor}) = split(/--/, $form->{vendor});
 
1313   $form->{ct}   = "vendor";
 
1314   $form->{arap} = "ap";
 
1316   $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
 
1318   RP->aging(\%myconfig, \%$form);
 
1321   $lxdebug->leave_sub();
 
1324 sub create_aging_subtotal_row {
 
1325   $lxdebug->enter_sub();
 
1327   my ($subtotals, $columns, $periods, $class) = @_;
 
1329   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
1331   foreach (@{ $periods }) {
 
1332     $row->{"c$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
 
1333     $subtotals->{$_}      = 0;
 
1336   $lxdebug->leave_sub();
 
1342   $lxdebug->enter_sub();
 
1344   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1346   my @columns = qw(statement ct invnumber transdate duedate c0 c30 c60 c90);
 
1349     'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
 
1350     'ct'        => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
 
1351     'invnumber' => { 'text' => $locale->text('Invoice'), },
 
1352     'transdate' => { 'text' => $locale->text('Date'), },
 
1353     'duedate'   => { 'text' => $locale->text('Due'), },
 
1354     'c0'        => { 'text' => $locale->text('Current'), },
 
1355     'c30'       => { 'text' => '30', },
 
1356     'c60'       => { 'text' => '60', },
 
1357     'c90'       => { 'text' => '90', },
 
1360   my %column_alignment = ('statement' => 'center',
 
1361                           map { $_ => 'right' } qw(c0 c30 c60 c90));
 
1363   $report->set_options('std_column_visibility' => 1);
 
1364   $report->set_columns(%column_defs);
 
1365   $report->set_column_order(@columns);
 
1367   my @hidden_variables = qw(todate customer vendor arap title ct);
 
1368   $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
 
1372   if ($form->{department}) {
 
1373     my ($department) = split /--/, $form->{department};
 
1374     push @options, $locale->text('Department') . " : $department";
 
1375     $form->{callback} .= "&department=" . E($department);
 
1378   if (($form->{arap} eq 'ar') && $form->{customer}) {
 
1379     push @options, $form->{customer};
 
1382   if (($form->{arap} eq 'ap') && $form->{vendor}) {
 
1383     push @options, $form->{vendor};
 
1386   push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
 
1388   my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
 
1390   $report->set_options('top_info_text'        => join("\n", @options),
 
1391                        'output_format'        => 'HTML',
 
1392                        'title'                => $form->{title},
 
1393                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
1396   my $previous_ctid = 0;
 
1398   my @periods       = qw(0 30 60 90);
 
1399   my %subtotals     = map { $_ => 0 } @periods;
 
1400   my %totals        = map { $_ => 0 } @periods;
 
1402   foreach $ref (@{ $form->{AG} }) {
 
1403     if ($row_idx && ($previous_ctid != $ref->{ctid})) {
 
1404       $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
 
1407     foreach my $key (@periods) {
 
1408       $subtotals{$key}  += $ref->{"c${key}"};
 
1409       $totals{$key}     += $ref->{"c${key}"};
 
1410       $ref->{"c${key}"}  = $ref->{"c${key}"} != 0 ? $form->format_amount(\%myconfig, $ref->{"c${key}"}, 2) : '';
 
1415     foreach my $column (@columns) {
 
1417         'data'   => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
 
1418         'align'  => $column_alignment{$column},
 
1419         'valign' => $column eq 'statement' ? 'center' : '',
 
1423     $row->{invnumber}->{link} =  build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
 
1425     if ($previous_ctid != $ref->{ctid}) {
 
1426       $row->{statement}->{raw_data} =
 
1427           $cgi->hidden('-name' => "customer_id_${row_idx}", '-value' => $ref->{ctid})
 
1428         . $cgi->checkbox('-name' => "statement_${row_idx}", '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
 
1429       $row->{ct}->{data} = $ref->{name};
 
1434     $previous_ctid = $ref->{ctid};
 
1436     $report->add_data($row);
 
1439   $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
 
1441   $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
 
1443   if ($form->{arap} eq 'ar') {
 
1444     $raw_top_info_text    = $form->parse_html_template('rp/aging_ar_top');
 
1445     $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
 
1446                                                                                'PRINT_OPTIONS' => print_options(1), });
 
1447     $report->set_options('raw_top_info_text'    => $raw_top_info_text,
 
1448                          'raw_bottom_info_text' => $raw_bottom_info_text);
 
1451   $report->set_options_from_form();
 
1453   $report->generate_with_headers();
 
1455   $lxdebug->leave_sub();
 
1459   $lxdebug->enter_sub();
 
1461   RP->aging(\%myconfig, \%$form);
 
1463   map { $_->{checked} = "checked" } @{ $form->{AG} };
 
1467   $lxdebug->leave_sub();
 
1471   $lxdebug->enter_sub();
 
1473   # get name and email addresses
 
1474   for $i (1 .. $form->{rowcount}) {
 
1475     if ($form->{"statement_$i"}) {
 
1476       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
 
1477       RP->get_customer(\%myconfig, \%$form);
 
1483   $form->error($locale->text('Nothing selected!')) unless $selected;
 
1485   if ($myconfig{role} eq 'admin') {
 
1487           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
 
1488           <td><input name=bcc size=30 value="$form->{bcc}"></td>
 
1492   $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
 
1494   $form->{media} = "email";
 
1501 <form method=post action=$form->{script}>
 
1507   <tr height="5"></tr>
 
1512           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
 
1513           <td><input name=email size=30 value="$form->{email}"></td>
 
1514           <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
 
1515           <td><input name=cc size=30 value="$form->{cc}"></td>
 
1518           <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
 
1519           <td><input name=subject size=30 value="$form->{subject}"></td>
 
1529           <th align=left nowrap>| . $locale->text('Message') . qq|</th>
 
1532           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
 
1543   map { delete $form->{$_} }
 
1544     qw(action email cc bcc subject message type sendmode format header);
 
1546   # save all other variables
 
1547   foreach $key (keys %$form) {
 
1548     $form->{$key} =~ s/\"/"/g;
 
1549     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1556     <td><hr size=3 noshade></td>
 
1560 <input type=hidden name=nextsub value=send_email>
 
1563 <input name=action class=submit type=submit value="|
 
1564     . $locale->text('Continue') . qq|">
 
1571   $lxdebug->leave_sub();
 
1575   $lxdebug->enter_sub();
 
1577   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
 
1578     unless $form->{subject};
 
1580   RP->aging(\%myconfig, \%$form);
 
1582   $form->{"statement_1"} = 1;
 
1584   $form->{media} = 'email';
 
1587   $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
 
1589   $lxdebug->leave_sub();
 
1593   $lxdebug->enter_sub();
 
1595   if ($form->{media} eq 'printer') {
 
1596     $form->error($locale->text('Select postscript or PDF!'))
 
1597       if ($form->{format} !~ /(postscript|pdf)/);
 
1600   for $i (1 .. $form->{rowcount}) {
 
1601     if ($form->{"statement_$i"}) {
 
1602       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
 
1608   $form->error($locale->text('Nothing selected!')) unless $selected;
 
1610   if ($form->{media} eq 'printer') {
 
1611     $form->{"$form->{ct}_id"} = "";
 
1613     $form->{"statement_1"} = 1;
 
1616   RP->aging(\%myconfig, \%$form);
 
1620   $form->redirect($locale->text('Statements sent to printer!'))
 
1621     if ($form->{media} eq 'printer');
 
1623   $lxdebug->leave_sub();
 
1627   $lxdebug->enter_sub();
 
1631      "ä" => "ae", "ö" => "oe", "ü" => "ue",
 
1632      "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
 
1637   foreach my $key (keys %replacements) {
 
1638     my $new_key = SL::Iconv::convert("ISO-8859-15", $dbcharset, $key);
 
1639     $replacements{$new_key} = $replacements{$key} if $new_key ne $key;
 
1642   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
 
1644   $form->{templates} = "$myconfig{templates}";
 
1646   my $suffix = "html";
 
1647   my $attachment_suffix = "html";
 
1648   if ($form->{format} eq 'postscript') {
 
1649     $form->{postscript} = 1;
 
1651     $attachment_suffix = "ps";
 
1652   } elsif ($form->{format} eq 'pdf') {
 
1655     $attachment_suffix = "pdf";
 
1658   $form->{IN}  = "$form->{type}.$suffix";
 
1660     $form->{media} eq 'email'   ? $sendmail              :
 
1661     $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
 
1663   # Save $form->{email} because it will be overwritten.
 
1664   $form->{EMAIL_RECIPIENT} = $form->{email};
 
1667   while (@{ $form->{AG} }) {
 
1669     $ref = shift @{ $form->{AG} };
 
1671     if ($ctid != $ref->{ctid}) {
 
1673       $ctid = $ref->{ctid};
 
1676       if ($form->{"statement_$i"}) {
 
1679           (name, street, zipcode, city, country, contact, email,
 
1680            "$form->{ct}phone", "$form->{ct}fax");
 
1681         map { $form->{$_} = $ref->{$_} } @a;
 
1683         $form->{ $form->{ct} } = $form->{name};
 
1684         $form->{"$form->{ct}_id"} = $ref->{ctid};
 
1686         map { $form->{$_} = () } qw(invnumber invdate duedate);
 
1688         foreach $item (qw(c0 c30 c60 c90)) {
 
1689           $form->{$item} = ();
 
1690           $form->{"${item}total"} = 0;
 
1693         &statement_details($ref);
 
1697           if (scalar(@{ $form->{AG} }) > 0) {
 
1699             # one or more left to go
 
1700             if ($ctid == $form->{AG}->[0]->{ctid}) {
 
1701               $ref = shift @{ $form->{AG} };
 
1702               &statement_details($ref);
 
1705               $ref = scalar(@{ $form->{AG} });
 
1711             # set initial ref to 0
 
1718           $form->{"${_}total"} =
 
1719             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
 
1720         } (c0, c30, c60, c90, "");
 
1722         $form->{attachment_filename} = $locale->text("Statement") . "_$form->{todate}.$attachment_suffix";
 
1723         map({ $form->{attachment_filename} =~ s/$_/$replacements{$_}/g; } keys(%replacements));
 
1725         $form->parse_template(\%myconfig, $userspath);
 
1730   # saving the history
 
1731   if(!exists $form->{addition} && $form->{id} ne "") {
 
1732     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1733         $form->{addition} = "PRINTED";
 
1734         $form->{what_done} = $form->{type};
 
1735         $form->save_history($form->dbconnect(\%myconfig));
 
1737   # /saving the history 
 
1738   $lxdebug->leave_sub();
 
1741 sub statement_details {
 
1742   $lxdebug->enter_sub();
 
1745   push @{ $form->{invnumber} }, $ref->{invnumber};
 
1746   push @{ $form->{invdate} },   $ref->{transdate};
 
1747   push @{ $form->{duedate} },   $ref->{duedate};
 
1749   foreach $item (qw(c0 c30 c60 c90)) {
 
1750     if ($ref->{exchangerate} * 1) {
 
1752         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
 
1754     $form->{"${item}total"} += $ref->{$item};
 
1755     $form->{total}          += $ref->{$item};
 
1756     push @{ $form->{$item} },
 
1757       $form->format_amount(\%myconfig, $ref->{$item}, 2);
 
1760   $lxdebug->leave_sub();
 
1763 sub generate_tax_report {
 
1764   $lxdebug->enter_sub();
 
1766   RP->tax_report(\%myconfig, \%$form);
 
1768   $descvar     = "$form->{accno}_description";
 
1769   $description = $form->escape($form->{$descvar});
 
1770   $ratevar     = "$form->{accno}_rate";
 
1772   $department = $form->escape($form->{department});
 
1776     "$form->{script}?&action=generate_tax_report&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
 
1778   # construct callback
 
1779   $description = $form->escape($form->{$descvar},   1);
 
1780   $department  = $form->escape($form->{department}, 1);
 
1782     "$form->{script}?&action=generate_tax_report&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
 
1784   $title = $form->escape($form->{title});
 
1785   $href .= "&title=$title";
 
1786   $title = $form->escape($form->{title}, 1);
 
1787   $callback .= "&title=$title";
 
1789   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
 
1792     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
 
1794   foreach $item (@columns) {
 
1795     if ($form->{"l_$item"} eq "Y") {
 
1796       push @column_index, $item;
 
1798       # add column to href and callback
 
1799       $callback .= "&l_$item=Y";
 
1800       $href     .= "&l_$item=Y";
 
1804   if ($form->{l_subtotal} eq 'Y') {
 
1805     $callback .= "&l_subtotal=Y";
 
1806     $href     .= "&l_subtotal=Y";
 
1809   if ($form->{department}) {
 
1810     ($department) = split /--/, $form->{department};
 
1811     $option = $locale->text('Department') . " : $department";
 
1814   # if there are any dates
 
1815   if ($form->{fromdate} || $form->{todate}) {
 
1816     if ($form->{fromdate}) {
 
1817       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1819     if ($form->{todate}) {
 
1820       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
 
1823     $form->{period} = "$fromdate - $todate";
 
1826       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1829   if ($form->{db} eq 'ar') {
 
1830     $name    = $locale->text('Customer');
 
1834   if ($form->{db} eq 'ap') {
 
1835     $name    = $locale->text('Vendor');
 
1840   $option .= "<br>" if $option;
 
1841   $option .= "$form->{period}";
 
1843   $column_header{id} =
 
1844       qq|<th><a class=listheading href=$href&sort=id>|
 
1845     . $locale->text('ID')
 
1847   $column_header{invnumber} =
 
1848       qq|<th><a class=listheading href=$href&sort=invnumber>|
 
1849     . $locale->text('Invoice')
 
1851   $column_header{transdate} =
 
1852       qq|<th><a class=listheading href=$href&sort=transdate>|
 
1853     . $locale->text('Date')
 
1855   $column_header{netamount} =
 
1856     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
 
1857   $column_header{tax} =
 
1858     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
 
1859   $column_header{amount} =
 
1860     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
 
1862   $column_header{name} =
 
1863     qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
 
1872     <th class=listtop colspan=$colspan>$form->{title}</th>
 
1874   <tr height="5"></tr>
 
1881         <tr class=listheading>
 
1884   map { print "$column_header{$_}\n" } @column_index;
 
1890   # add sort and escape callback
 
1891   $callback = $form->escape($callback . "&sort=$form->{sort}");
 
1893   if (@{ $form->{TR} }) {
 
1894     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
 
1897   foreach $ref (@{ $form->{TR} }) {
 
1899     $module = ($ref->{invoice}) ? $invoice : $arap;
 
1901     if ($form->{l_subtotal} eq 'Y') {
 
1902       if ($sameitem ne $ref->{ $form->{sort} }) {
 
1904         $sameitem = $ref->{ $form->{sort} };
 
1908     $totalnetamount += $ref->{netamount};
 
1909     $totaltax       += $ref->{tax};
 
1910     $ref->{amount} = $ref->{netamount} + $ref->{tax};
 
1912     $subtotalnetamount += $ref->{netamount};
 
1913     $subtotaltax       += $ref->{tax};
 
1916       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
 
1917     } qw(netamount tax amount);
 
1919     $column_data{id}        = qq|<td>$ref->{id}</td>|;
 
1920     $column_data{invnumber} =
 
1921       qq|<td><a href=$module?action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>|;
 
1922     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
 
1923     $column_data{name}      = qq|<td>$ref->{name} </td>|;
 
1925     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
 
1926       qw(netamount tax amount);
 
1931         <tr class=listrow$i>
 
1934     map { print "$column_data{$_}\n" } @column_index;
 
1942   if ($form->{l_subtotal} eq 'Y') {
 
1946   map { $column_data{$_} = qq|<th> </th>| } @column_index;
 
1950         <tr class=listtotal>
 
1954     $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
 
1956     $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
 
1957   $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
 
1959   $column_data{netamount} =
 
1960     qq|<th class=listtotal align=right>$totalnetamount</th>|;
 
1961   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
 
1962   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
 
1964   map { print "$column_data{$_}\n" } @column_index;
 
1972     <td><hr size=3 noshade></td>
 
1980   $lxdebug->leave_sub();
 
1984   $lxdebug->enter_sub();
 
1986   map { $column_data{$_} = "<td> </td>" } @column_index;
 
1988   $subtotalnetamount =
 
1989     $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
 
1990   $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
 
1992     $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
 
1995   $column_data{netamount} =
 
1996     "<th class=listsubtotal align=right>$subtotalnetamount</th>";
 
1997   $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
 
1998   $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
 
2000   $subtotalnetamount = 0;
 
2004         <tr class=listsubtotal>
 
2006   map { print "\n$column_data{$_}" } @column_index;
 
2012   $lxdebug->leave_sub();
 
2016   $lxdebug->enter_sub();
 
2018   if ($form->{account}) {
 
2019     ($form->{paymentaccounts}) = split /--/, $form->{account};
 
2021   if ($form->{department}) {
 
2022     ($department, $form->{department_id}) = split /--/, $form->{department};
 
2023     $option = $locale->text('Department') . " : $department";
 
2026   RP->payments(\%myconfig, \%$form);
 
2028   my @hidden_variables = qw(account title department reference source memo fromdate todate
 
2029                             fx_transaction db prepayment paymentaccounts sort);
 
2031   my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
 
2032   $form->{callback} = $href;
 
2034   my @columns     = qw(transdate invnumber name paid source memo);
 
2036     'name'      => { 'text' => $locale->text('Description'), },
 
2037     'invnumber' => { 'text' => $locale->text('Reference'), },
 
2038     'transdate' => { 'text' => $locale->text('Date'), },
 
2039     'paid'      => { 'text' => $locale->text('Amount'), },
 
2040     'source'    => { 'text' => $locale->text('Source'), },
 
2041     'memo'      => { 'text' => $locale->text('Memo'), },
 
2043   my %column_alignment = ('paid' => 'right');
 
2045   map { $column_defs{$_}->{link} = $href . "&sort=$_" } grep { $_ ne 'paid' } @columns;
 
2048   if ($form->{fromdate}) {
 
2049     push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
 
2051   if ($form->{todate}) {
 
2052     push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
 
2055   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
2057   my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
 
2059   $report->set_options('top_info_text'         => join("\n", @options),
 
2060                        'output_format'         => 'HTML',
 
2061                        'title'                 => $form->{title},
 
2062                        'attachment_basename'   => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
2063                        'std_column_visibility' => 1,
 
2065   $report->set_options_from_form();
 
2067   $report->set_columns(%column_defs);
 
2068   $report->set_column_order(@columns);
 
2070   $report->set_export_options('list_payments', @hidden_variables);
 
2072   $report->set_sort_indicator($form->{sort}, 1);
 
2076   foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
 
2077     next unless @{ $form->{ $ref->{id} } };
 
2079     $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
 
2081     my $subtotal_paid = 0;
 
2083     foreach my $payment (@{ $form->{ $ref->{id} } }) {
 
2084       my $module = $payment->{module};
 
2085       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
 
2086       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
 
2088       $subtotal_paid += $payment->{paid};
 
2089       $total_paid    += $payment->{paid};
 
2091       $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
 
2095       foreach my $column (@columns) {
 
2097           'data'  => $payment->{$column},
 
2098           'align' => $column_alignment{$column},
 
2102       $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
 
2104       $report->add_data($row);
 
2107     my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
 
2109       'data'  => $form->format_amount(\%myconfig, $subtotal_paid, 2),
 
2111       'class' => 'listsubtotal',
 
2114     $report->add_data($row);
 
2117   $report->add_separator();
 
2119   my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
 
2121     'data'  => $form->format_amount(\%myconfig, $total_paid, 2),
 
2123     'class' => 'listtotal',
 
2126   $report->add_data($row);
 
2128   $report->generate_with_headers();
 
2130   $lxdebug->leave_sub();
 
2134   $lxdebug->enter_sub();
 
2136   my ($dont_print) = @_;
 
2138   $form->{sendmode} = "attachment";
 
2141     $form->{"format"} ? $form->{"format"} :
 
2142     $myconfig{"template_format"} ? $myconfig{"template_format"} :
 
2146     $form->{"copies"} ? $form->{"copies"} :
 
2147     $myconfig{"copies"} ? $myconfig{"copies"} :
 
2150   $form->{PD}{ $form->{type} }     = "selected";
 
2151   $form->{DF}{ $form->{format} }   = "selected";
 
2152   $form->{OP}{ $form->{media} }    = "selected";
 
2153   $form->{SM}{ $form->{sendmode} } = "selected";
 
2156             <option value=statement $form->{PD}{statement}>|
 
2157       . $locale->text('Statement');
 
2159   if ($form->{media} eq 'email') {
 
2161             <option value=attachment $form->{SM}{attachment}>|
 
2162       . $locale->text('Attachment') . qq|
 
2163             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
 
2166             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
 
2167     if ($myconfig{printer} && $latex_templates) {
 
2169             <option value=printer $form->{OP}{printer}>|
 
2170         . $locale->text('Printer');
 
2174   if ($latex_templates) {
 
2176             <option value=html $form->{DF}{html}>| . $locale->text('HTML')
 
2177       . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
 
2178       . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
 
2184     <td><select name=type>$type</select></td>
 
2185     <td><select name=format>$format</select></td>
 
2186     <td><select name=media>$media</select></td>
 
2189   if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
 
2191       <td>| . $locale->text('Copies') . qq|
 
2192       <input name=copies size=2 value=$form->{copies}></td>
 
2201   print $output unless $dont_print;
 
2203   $lxdebug->leave_sub();
 
2209   $lxdebug->enter_sub();
 
2210   $form->{padding} = "  ";
 
2211   $form->{bold}    = "<b>";
 
2212   $form->{endbold} = "</b>";
 
2213   $form->{br}      = "<br>";
 
2215   if ($form->{reporttype} eq "custom") {
 
2217     #forgotten the year --> thisyear
 
2218     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
2219       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
2225     if ($form->{duetyp} eq "13") {
 
2226       $form->{fromdate}        = "1.1.$form->{year}";
 
2227       $form->{todate}          = "31.12.$form->{year}";
 
2228       $form->{comparefromdate} = "1.01.$form->{year}";
 
2229       $form->{comparetodate}   = "31.12.$form->{year}";
 
2233     if ($form->{duetyp} eq "A") {
 
2234       $form->{fromdate}        = "1.1.$form->{year}";
 
2235       $form->{todate}          = "31.3.$form->{year}";
 
2236       $form->{comparefromdate} = "1.01.$form->{year}";
 
2237       $form->{comparetodate}   = "31.03.$form->{year}";
 
2239     if ($form->{duetyp} eq "B") {
 
2240       $form->{fromdate}        = "1.4.$form->{year}";
 
2241       $form->{todate}          = "30.6.$form->{year}";
 
2242       $form->{comparefromdate} = "1.01.$form->{year}";
 
2243       $form->{comparetodate}   = "30.06.$form->{year}";
 
2245     if ($form->{duetyp} eq "C") {
 
2246       $form->{fromdate}        = "1.7.$form->{year}";
 
2247       $form->{todate}          = "30.9.$form->{year}";
 
2248       $form->{comparefromdate} = "1.01.$form->{year}";
 
2249       $form->{comparetodate}   = "30.09.$form->{year}";
 
2251     if ($form->{duetyp} eq "D") {
 
2252       $form->{fromdate}        = "1.10.$form->{year}";
 
2253       $form->{todate}          = "31.12.$form->{year}";
 
2254       $form->{comparefromdate} = "1.01.$form->{year}";
 
2255       $form->{comparetodate}   = "31.12.$form->{year}";
 
2260       $form->{duetyp} eq "1" && do {
 
2261         $form->{fromdate}        = "1.1.$form->{year}";
 
2262         $form->{todate}          = "31.1.$form->{year}";
 
2263         $form->{comparefromdate} = "1.01.$form->{year}";
 
2264         $form->{comparetodate}   = "31.01.$form->{year}";
 
2267       $form->{duetyp} eq "2" && do {
 
2268         $form->{fromdate} = "1.2.$form->{year}";
 
2270         #this works from 1901 to 2099, 1900 and 2100 fail.
 
2271         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
2272         $form->{todate}          = "$leap.2.$form->{year}";
 
2273         $form->{comparefromdate} = "1.01.$form->{year}";
 
2274         $form->{comparetodate}   = "$leap.02.$form->{year}";
 
2277       $form->{duetyp} eq "3" && do {
 
2278         $form->{fromdate}        = "1.3.$form->{year}";
 
2279         $form->{todate}          = "31.3.$form->{year}";
 
2280         $form->{comparefromdate} = "1.01.$form->{year}";
 
2281         $form->{comparetodate}   = "31.03.$form->{year}";
 
2284       $form->{duetyp} eq "4" && do {
 
2285         $form->{fromdate}        = "1.4.$form->{year}";
 
2286         $form->{todate}          = "30.4.$form->{year}";
 
2287         $form->{comparefromdate} = "1.01.$form->{year}";
 
2288         $form->{comparetodate}   = "30.04.$form->{year}";
 
2291       $form->{duetyp} eq "5" && do {
 
2292         $form->{fromdate}        = "1.5.$form->{year}";
 
2293         $form->{todate}          = "31.5.$form->{year}";
 
2294         $form->{comparefromdate} = "1.01.$form->{year}";
 
2295         $form->{comparetodate}   = "31.05.$form->{year}";
 
2298       $form->{duetyp} eq "6" && do {
 
2299         $form->{fromdate}        = "1.6.$form->{year}";
 
2300         $form->{todate}          = "30.6.$form->{year}";
 
2301         $form->{comparefromdate} = "1.01.$form->{year}";
 
2302         $form->{comparetodate}   = "30.06.$form->{year}";
 
2305       $form->{duetyp} eq "7" && do {
 
2306         $form->{fromdate}        = "1.7.$form->{year}";
 
2307         $form->{todate}          = "31.7.$form->{year}";
 
2308         $form->{comparefromdate} = "1.01.$form->{year}";
 
2309         $form->{comparetodate}   = "31.07.$form->{year}";
 
2312       $form->{duetyp} eq "8" && do {
 
2313         $form->{fromdate}        = "1.8.$form->{year}";
 
2314         $form->{todate}          = "31.8.$form->{year}";
 
2315         $form->{comparefromdate} = "1.01.$form->{year}";
 
2316         $form->{comparetodate}   = "31.08.$form->{year}";
 
2319       $form->{duetyp} eq "9" && do {
 
2320         $form->{fromdate}        = "1.9.$form->{year}";
 
2321         $form->{todate}          = "30.9.$form->{year}";
 
2322         $form->{comparefromdate} = "1.01.$form->{year}";
 
2323         $form->{comparetodate}   = "30.09.$form->{year}";
 
2326       $form->{duetyp} eq "10" && do {
 
2327         $form->{fromdate}        = "1.10.$form->{year}";
 
2328         $form->{todate}          = "31.10.$form->{year}";
 
2329         $form->{comparefromdate} = "1.01.$form->{year}";
 
2330         $form->{comparetodate}   = "31.10.$form->{year}";
 
2333       $form->{duetyp} eq "11" && do {
 
2334         $form->{fromdate}        = "1.11.$form->{year}";
 
2335         $form->{todate}          = "30.11.$form->{year}";
 
2336         $form->{comparefromdate} = "1.01.$form->{year}";
 
2337         $form->{comparetodate}   = "30.11.$form->{year}";
 
2340       $form->{duetyp} eq "12" && do {
 
2341         $form->{fromdate}        = "1.12.$form->{year}";
 
2342         $form->{todate}          = "31.12.$form->{year}";
 
2343         $form->{comparefromdate} = "1.01.$form->{year}";
 
2344         $form->{comparetodate}   = "31.12.$form->{year}";
 
2349     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
 
2350     $form->{fromdate} = "${dd}.${mm}.${yy}";
 
2351     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
 
2352     $form->{todate}          = "${dd}.${mm}.${yy}";
 
2353     $form->{comparefromdate} = "01.01.$yy";
 
2354     $form->{comparetodate}   = $form->{todate};
 
2357   RP->bwa(\%myconfig, \%$form);
 
2359   ($form->{department}) = split /--/, $form->{department};
 
2362     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2363   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
2365   # if there are any dates construct a where
 
2366   if ($form->{fromdate} || $form->{todate}) {
 
2368     unless ($form->{todate}) {
 
2369       $form->{todate} = $form->current_date(\%myconfig);
 
2372     my %germandate = ("dateformat" => "dd.mm.yyyy");
 
2374     $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
 
2375     $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
 
2377     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
 
2378     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
 
2380     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
2382         $locale->text('for Period')
 
2383       . qq|\n$longfromdate |
 
2384       . $locale->text('bis')
 
2388   # setup variables for the form
 
2389   @a = qw(company address businessnumber);
 
2390   map { $form->{$_} = $myconfig{$_} } @a;
 
2391   $form->{templates} = $myconfig{templates};
 
2393   $form->{IN} = "bwa.html";
 
2395   $form->parse_template;
 
2397   $lxdebug->leave_sub();