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')
 
  94 # $form->parse_html_template('rp/html_report_susa')
 
  97   'projects'         => 'report',
 
  98   'ar_aging'         => 'general_ledger',
 
  99   'ap_aging'         => 'general_ledger',
 
 100   'receipts'         => 'cash',
 
 101   'payments'         => 'cash',
 
 102   'trial_balance'    => 'report',
 
 103   'income_statement' => 'report',
 
 105   'balance_sheet'    => 'report',
 
 108 sub check_rp_access {
 
 109   my $right   = $rp_access_map->{$form->{report}};
 
 110   $right    ||= 'DOES_NOT_EXIST';
 
 112   $auth->assert($right);
 
 116   $lxdebug->enter_sub();
 
 120   %title = ('balance_sheet'        => 'Balance Sheet',
 
 121             'income_statement'     => 'Income Statement',
 
 122             'trial_balance'        => 'Trial Balance',
 
 123             'ar_aging'             => 'AR Aging',
 
 124             'ap_aging'             => 'Offene Verbindlichkeiten',
 
 125             'tax_collected'        => 'Tax collected',
 
 126             'tax_paid'             => 'Tax paid',
 
 127             'nontaxable_sales'     => 'Non-taxable Sales',
 
 128             'nontaxable_purchases' => 'Non-taxable Purchases',
 
 129             'receipts'             => 'Receipts',
 
 130             'payments'             => 'Payments',
 
 131             'projects'             => 'Project Transactions',
 
 132             'bwa'                  => 'Betriebswirtschaftliche Auswertung',);
 
 134   $form->{title} = $locale->text($title{ $form->{report} });
 
 136   $accrual = ($eur) ? ""        : "checked";
 
 137   $cash    = ($eur) ? "checked" : "";
 
 139   $year = (localtime)[5] + 1900;
 
 142   $form->all_departments(\%myconfig);
 
 143   if (@{ $form->{all_departments} }) {
 
 144     $form->{selectdepartment} = "<option>\n";
 
 147       $form->{selectdepartment} .=
 
 148         "<option>$_->{description}--$_->{id}\n"
 
 149     } (@{ $form->{all_departments} });
 
 154           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 155           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 157 | if $form->{selectdepartment};
 
 159   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 162   my %project_labels = ();
 
 163   my @project_values = ("");
 
 164   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 165     push(@project_values, $item->{"id"});
 
 166     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 170     NTI($cgi->popup_menu('-name' => "project_id",
 
 171                          '-values' => \@project_values,
 
 172                          '-labels' => \%project_labels));
 
 174   # use JavaScript Calendar or not
 
 175   $form->{jsscript} = 1;
 
 177   if ($form->{report} eq "balance_sheet") {
 
 178     $name_1    = "asofdate";
 
 180     $value_1   = "$form->{asofdate}";
 
 181     $trigger_1 = "trigger1";
 
 182     $name_2    = "compareasofdate";
 
 183     $id_2      = "compareasofdate";
 
 184     $value_2   = "$form->{compareasofdate}";
 
 185     $trigger_2 = "trigger2";
 
 186   } elsif ($form->{report} =~ /(receipts|payments)$/) {
 
 187     $name_1    = "fromdate";
 
 189     $value_1   = "$form->{fromdate}";
 
 190     $trigger_1 = "trigger1";
 
 194     $trigger_2 = "trigger2";
 
 195   } elsif (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
 
 203     $trigger_2 = "trigger2";
 
 206     $name_1    = "fromdate";
 
 208     $value_1   = "$form->{fromdate}";
 
 209     $trigger_1 = "trigger1";
 
 213     $trigger_2 = "trigger2";
 
 216   # with JavaScript Calendar
 
 217   if ($form->{jsscript}) {
 
 221          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 223         <input type=button name=$name_2 id="$trigger_2" value=|
 
 224         . $locale->text('button') . qq|>|;
 
 228         Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
 
 231          <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
 
 233         <input type=button name=$name_1 id="$trigger_1" value=|
 
 234         . $locale->text('button') . qq|>|;
 
 236          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 238          <input type=button name=$name_2 id="$trigger_2" value=|
 
 239         . $locale->text('button') . qq|>
 
 244         Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
 
 245                             "$name_2", "BL", "$trigger_2");
 
 249     # without JavaScript Calendar
 
 252         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 255         qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
 
 257         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 260   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 262   $onload = qq|focus()|;
 
 263   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 264   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 266 <body onLoad="$onload">
 
 268 <form method=post action=$form->{script}>
 
 270 <input type=hidden name=title value="$form->{title}">
 
 274     <th class=listtop>$form->{title}</th>
 
 283   if ($form->{report} eq "projects") {
 
 286           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 287           <td colspan=5><input name=projectnumber size=25</td>
 
 289         <input type=hidden name=nextsub value=generate_projects>
 
 291           <th align=right>| . $locale->text('From') . qq|</th>
 
 294           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 305           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 306           <td><input name=l_heading class=checkbox type=checkbox value=Y> |
 
 307       . $locale->text('Heading') . qq|
 
 308           <input name=l_subtotal class=checkbox type=checkbox value=Y> |
 
 309       . $locale->text('Subtotal') . qq|</td>
 
 316   if ($form->{report} eq "income_statement") {
 
 319           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 320           <td colspan=3>$projectnumber</td>
 
 322         <input type=hidden name=nextsub value=generate_income_statement>
 
 326           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
 
 327       . $locale->text('Customized Report') . qq|</th>
 
 330           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 331           <td><input name=year size=11 title="|
 
 332       . $locale->text('YYYY') . qq|" value="$year"></td>
 
 339 <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 340                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 341                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 344                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 346                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
 
 347       . $locale->text('Quarter') . qq|</td>
 
 351                 <td><input name=duetyp class=radio type=radio value="1" $checked > |
 
 352       . $locale->text('January') . qq|</td>
 
 356                 <td><input name=duetyp class=radio type=radio value="5" $checked > |
 
 357       . $locale->text('May') . qq|</td>
 
 358                 <td><input name=duetyp class=radio type=radio value="9" $checked > |
 
 359       . $locale->text('September') . qq|</td>
 
 363                 <td align= right> </td>
 
 364                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
 
 365       . $locale->text('Quarter') . qq|</td>
 
 366                 <td><input name=duetyp class=radio type=radio value="2" $checked > |
 
 367       . $locale->text('February') . qq|</td>
 
 368                 <td><input name=duetyp class=radio type=radio value="6" $checked > |
 
 369       . $locale->text('June') . qq|</td>
 
 370                 <td><input name=duetyp class=radio type=radio value="10" $checked > |
 
 371       . $locale->text('October') . qq|</td>
 
 375                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
 
 376       . $locale->text('Quarter') . qq|</td>
 
 377                 <td><input name=duetyp class=radio type=radio value="3" $checked > |
 
 378       . $locale->text('March') . qq|</td>
 
 379                 <td><input name=duetyp class=radio type=radio value="7" $checked > |
 
 380       . $locale->text('July') . qq|</td>
 
 381                 <td><input name=duetyp class=radio type=radio value="11" $checked > |
 
 382       . $locale->text('November') . qq|</td>
 
 387                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
 
 388       . $locale->text('Quarter') . qq| </td>
 
 389                 <td><input name=duetyp class=radio type=radio value="4" $checked > |
 
 390       . $locale->text('April') . qq|</td>
 
 391                 <td><input name=duetyp class=radio type=radio value="8" $checked > |
 
 392       . $locale->text('August') . qq|</td>
 
 393                 <td><input name=duetyp class=radio type=radio value="12" $checked > |
 
 394       . $locale->text('December') . qq|</td>
 
 398                 <td colspan=5><hr size=3 noshade></td>
 
 401           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
 
 402       . $locale->text('Free report period') . qq|</th>
 
 403           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 406               | . $locale->text('Bis') . qq|
 
 412                 <td colspan=5><hr size=3 noshade></td>
 
 415           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 416           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 417       . $locale->text('Accrual') . qq|
 
 418            <input name=method class=radio type=radio value=cash $cash>|
 
 419       . $locale->text('EUR') . qq|</td>
 
 426   if ($form->{report} eq "bwa") {
 
 429           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 430           <td colspan=3>$projectnumber</td>
 
 432         <input type=hidden name=nextsub value=generate_bwa>
 
 436           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
 
 437       . $locale->text('Customized Report') . qq|</th>
 
 440           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 441           <td><input name=year size=11 title="|
 
 442       . $locale->text('YYYY') . qq|" value="$year"></td>
 
 449 <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 450                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 451                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 454                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 456                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
 
 457       . $locale->text('Quarter') . qq|</td>
 
 459     $checked = "checked";
 
 461                 <td><input name=duetyp class=radio type=radio value="1" $checked > |
 
 462       . $locale->text('January') . qq|</td>
 
 466                 <td><input name=duetyp class=radio type=radio value="5" $checked > |
 
 467       . $locale->text('May') . qq|</td>
 
 468                 <td><input name=duetyp class=radio type=radio value="9" $checked > |
 
 469       . $locale->text('September') . qq|</td>
 
 473                 <td align= right> </td>
 
 474                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
 
 475       . $locale->text('Quarter') . qq|</td>
 
 476                 <td><input name=duetyp class=radio type=radio value="2" $checked > |
 
 477       . $locale->text('February') . qq|</td>
 
 478                 <td><input name=duetyp class=radio type=radio value="6" $checked > |
 
 479       . $locale->text('June') . qq|</td>
 
 480                 <td><input name=duetyp class=radio type=radio value="10" $checked > |
 
 481       . $locale->text('October') . qq|</td>
 
 485                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
 
 486       . $locale->text('Quarter') . qq|</td>
 
 487                 <td><input name=duetyp class=radio type=radio value="3" $checked > |
 
 488       . $locale->text('March') . qq|</td>
 
 489                 <td><input name=duetyp class=radio type=radio value="7" $checked > |
 
 490       . $locale->text('July') . qq|</td>
 
 491                 <td><input name=duetyp class=radio type=radio value="11" $checked > |
 
 492       . $locale->text('November') . qq|</td>
 
 497                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
 
 498       . $locale->text('Quarter') . qq| </td>
 
 499                 <td><input name=duetyp class=radio type=radio value="4" $checked > |
 
 500       . $locale->text('April') . qq|</td>
 
 501                 <td><input name=duetyp class=radio type=radio value="8" $checked > |
 
 502       . $locale->text('August') . qq|</td>
 
 503                 <td><input name=duetyp class=radio type=radio value="12" $checked > |
 
 504       . $locale->text('December') . qq|</td>
 
 508                 <td colspan=5><hr size=3 noshade></td>
 
 511           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
 
 512       . $locale->text('Free report period') . qq|</th>
 
 513           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 516               | . $locale->text('Bis') . qq| 
 
 522                 <td colspan=5><hr size=3 noshade></td>
 
 525           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 526           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 527       . $locale->text('Accrual') . qq|
 
 528            <input name=method class=radio type=radio value=cash $cash>|
 
 529       . $locale->text('EUR') . qq|</td>
 
 532          <th align=right colspan=4>|
 
 533       . $locale->text('Decimalplaces')
 
 535              <td><input name=decimalplaces size=3 value="2"></td>
 
 542   if ($form->{report} eq "balance_sheet") {
 
 544         <input type=hidden name=nextsub value=generate_balance_sheet>
 
 546           <th align=right>| . $locale->text('as at') . qq|</th>
 
 551           <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
 
 558           <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
 
 559           <td><input name=decimalplaces size=3 value="2"></td>
 
 568           <th align=right>| . $locale->text('Method') . qq|</th>
 
 569           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 570       . $locale->text('Accrual') . qq|
 
 571            <input name=method class=radio type=radio value=cash $cash>|
 
 572       . $locale->text('EUR') . qq|</td>
 
 576           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 577           <td><input name=l_heading class=checkbox type=checkbox value=Y> |
 
 578       . $locale->text('Heading') . qq|
 
 579           <input name=l_subtotal class=checkbox type=checkbox value=Y> |
 
 580       . $locale->text('Subtotal') . qq|
 
 581           <input name=l_accno class=checkbox type=checkbox value=Y> |
 
 582       . $locale->text('Account Number') . qq|</td>
 
 589   if ($form->{report} eq "trial_balance") {
 
 592           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 593           <td colspan=3>$projectnumber</td>
 
 595         <input type=hidden name=nextsub value=generate_trial_balance>
 
 599           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
 
 600       . $locale->text('Customized Report') . qq|</th>
 
 603           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 604           <td><input name=year size=11 title="|
 
 605       . $locale->text('YYYY') . qq|" value="$year"></td>
 
 612 <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 613                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 614                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 617                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 619                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
 
 620       . $locale->text('Quarter') . qq|</td>
 
 622     $checked = "checked";
 
 624                 <td><input name=duetyp class=radio type=radio value="1" $checked > |
 
 625       . $locale->text('January') . qq|</td>
 
 629                 <td><input name=duetyp class=radio type=radio value="5" $checked > |
 
 630       . $locale->text('May') . qq|</td>
 
 631                 <td><input name=duetyp class=radio type=radio value="9" $checked > |
 
 632       . $locale->text('September') . qq|</td>
 
 636                 <td align= right> </td>
 
 637                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
 
 638       . $locale->text('Quarter') . qq|</td>
 
 639                 <td><input name=duetyp class=radio type=radio value="2" $checked > |
 
 640       . $locale->text('February') . qq|</td>
 
 641                 <td><input name=duetyp class=radio type=radio value="6" $checked > |
 
 642       . $locale->text('June') . qq|</td>
 
 643                 <td><input name=duetyp class=radio type=radio value="10" $checked > |
 
 644       . $locale->text('October') . qq|</td>
 
 648                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
 
 649       . $locale->text('Quarter') . qq|</td>
 
 650                 <td><input name=duetyp class=radio type=radio value="3" $checked > |
 
 651       . $locale->text('March') . qq|</td>
 
 652                 <td><input name=duetyp class=radio type=radio value="7" $checked > |
 
 653       . $locale->text('July') . qq|</td>
 
 654                 <td><input name=duetyp class=radio type=radio value="11" $checked > |
 
 655       . $locale->text('November') . qq|</td>
 
 660                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
 
 661       . $locale->text('Quarter') . qq| </td>
 
 662                 <td><input name=duetyp class=radio type=radio value="4" $checked > |
 
 663       . $locale->text('April') . qq|</td>
 
 664                 <td><input name=duetyp class=radio type=radio value="8" $checked > |
 
 665       . $locale->text('August') . qq|</td>
 
 666                 <td><input name=duetyp class=radio type=radio value="12" $checked > |
 
 667       . $locale->text('December') . qq|</td>
 
 671                 <td colspan=5><hr size=3 noshade></td>
 
 674           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
 
 675       . $locale->text('Free report period') . qq|</th>
 
 676           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 679               | . $locale->text('Bis') . qq| 
 
 685                 <td colspan=5><hr size=3 noshade></td>
 
 688           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 689           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 690       . $locale->text('Accrual') . qq|
 
 691            <input name=method class=radio type=radio value=cash $cash>|
 
 692       . $locale->text('EUR') . qq|</td>
 
 695          <th align=right colspan=4>|
 
 696       . $locale->text('All Accounts')
 
 698              <td><input name=all_accounts type=checkbox value=1></td>
 
 701          <th align=right colspan=4>|
 
 702       . $locale->text('Decimalplaces')
 
 704              <td><input name=decimalplaces size=3 value="2"></td>
 
 711   if ($form->{report} =~ /^tax_/) {
 
 712     $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
 
 714     RP->get_taxaccounts(\%myconfig, \%$form);
 
 717         <input type=hidden name=nextsub value=generate_tax_report>
 
 719           <th align=right>| . $locale->text('From') . qq|</th>
 
 720           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
 
 721           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 722           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
 
 725           <th align=right>| . $locale->text('Report for') . qq|</th>
 
 729     $checked = "checked";
 
 730     foreach $ref (@{ $form->{taxaccounts} }) {
 
 733         qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked> $ref->{description}
 
 735     <input name="$ref->{accno}_description" type=hidden value="$ref->{description}">
 
 736     <input name="$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
 
 743   <input type=hidden name=db value=$form->{db}>
 
 744   <input type=hidden name=sort value=transdate>
 
 749           <th align=right>| . $locale->text('Method') . qq|</th>
 
 750           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 751       . $locale->text('Accrual') . qq|
 
 752            <input name=method class=radio type=radio value=cash $cash>|
 
 753       . $locale->text('EUR') . qq|</td>
 
 762           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 766                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 767                 <td>| . $locale->text('ID') . qq|</td>
 
 768                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
 769                 <td>| . $locale->text('Invoice') . qq|</td>
 
 770                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 771                 <td>| . $locale->text('Date') . qq|</td>
 
 774                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
 777     if ($form->{db} eq 'ar') {
 
 778       print $locale->text('Customer');
 
 780     if ($form->{db} eq 'ap') {
 
 781       print $locale->text('Vendor');
 
 785                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
 
 786                 <td>| . $locale->text('Amount') . qq|</td>
 
 787                 <td><input name="l_tax" class=checkbox type=checkbox value=Y checked></td>
 
 788                 <td>| . $locale->text('Tax') . qq|</td>
 
 789                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
 
 790                 <td>| . $locale->text('Total') . qq|</td>
 
 793                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 794                 <td>| . $locale->text('Subtotal') . qq|</td>
 
 803   if ($form->{report} =~ /^nontaxable_/) {
 
 804     $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
 
 807         <input type=hidden name=nextsub value=generate_tax_report>
 
 809         <input type=hidden name=db value=$form->{db}>
 
 810         <input type=hidden name=sort value=transdate>
 
 811         <input type=hidden name=report value=$form->{report}>
 
 814           <th align=right>| . $locale->text('From') . qq|</th>
 
 815           <td><input name=fromdate size=11 title="$myconfig{dateformat}" value=$form->{fromdate}></td>
 
 816           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 817           <td><input name=todate size=11 title="$myconfig{dateformat}"></td>
 
 820           <th align=right>| . $locale->text('Method') . qq|</th>
 
 821           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 822       . $locale->text('Accrual') . qq|
 
 823            <input name=method class=radio type=radio value=cash $cash>|
 
 824       . $locale->text('EUR') . qq|</td>
 
 827           <th align=right>| . $locale->text('Include in Report') . qq|</th>
 
 831                 <td><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
 832                 <td>| . $locale->text('ID') . qq|</td>
 
 833                 <td><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
 834                 <td>| . $locale->text('Invoice') . qq|</td>
 
 835                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
 836                 <td>| . $locale->text('Date') . qq|</td>
 
 839                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
 842     if ($form->{db} eq 'ar') {
 
 843       print $locale->text('Customer');
 
 845     if ($form->{db} eq 'ap') {
 
 846       print $locale->text('Vendor');
 
 850                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y checked></td>
 
 851                 <td>| . $locale->text('Amount') . qq|</td>
 
 852                 <td><input name="l_amount" class=checkbox type=checkbox value=Y></td>
 
 853                 <td>| . $locale->text('Total') . qq|</td>
 
 856                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
 857                 <td>| . $locale->text('Subtotal') . qq|</td>
 
 866   if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
 
 867     if ($form->{report} eq 'ar_aging') {
 
 868       $label = $locale->text('Customer');
 
 869       $form->{vc} = 'customer';
 
 871       $label = $locale->text('Vendor');
 
 872       $form->{vc} = 'vendor';
 
 875     $nextsub = "generate_$form->{report}";
 
 878     $form->all_vc(\%myconfig, $form->{vc},
 
 879                   ($form->{vc} eq 'customer') ? "AR" : "AP");
 
 881     map { $vc .= "<option>$_->{name}--$_->{id}\n" }
 
 882       @{ $form->{"all_$form->{vc}"} };
 
 886       ? qq|<select name=$form->{vc}><option>\n$vc</select>|
 
 887       : qq|<input name=$form->{vc} size=35>|;
 
 891           <th align=right>| . $locale->text($label) . qq|</th>
 
 895           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 901         <input type=hidden name=type value=statement>
 
 902         <input type=hidden name=format value=html>
 
 903         <input type=hidden name=media value=screen>
 
 905         <input type=hidden name=nextsub value=$nextsub>
 
 906         <input type=hidden name=action value=$nextsub>
 
 912   # above action can be removed if there is more than one input field
 
 914   if ($form->{report} =~ /(receipts|payments)$/) {
 
 915     $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
 
 917     RP->paymentaccounts(\%myconfig, \%$form);
 
 919     $selection = "<option>\n";
 
 920     foreach $ref (@{ $form->{PR} }) {
 
 921       $paymentaccounts .= "$ref->{accno} ";
 
 922       $selection       .= "<option>$ref->{accno}--$ref->{description}\n";
 
 925     chop $paymentaccounts;
 
 928         <input type=hidden name=nextsub value=list_payments>
 
 930           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
 
 931           <td colspan=3><select name=account>$selection</select>
 
 932             <input type=hidden name=paymentaccounts value="$paymentaccounts">
 
 936           <th align=right>| . $locale->text('Reference') . qq|</th>
 
 937           <td colspan=3><input name=reference></td>
 
 940           <th align=right nowrap>| . $locale->text('Source') . qq|</th>
 
 941           <td colspan=3><input name=source></td>
 
 944           <th align=right nowrap>| . $locale->text('Memo') . qq|</th>
 
 945           <td colspan=3><input name=memo size=30></td>
 
 948           <th align=right>| . $locale->text('From') . qq|</th>
 
 953           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 960           <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
 
 961           <th align=left colspan=3>|
 
 962       . $locale->text('Include Exchangerate Difference') . qq|</td>
 
 967           <input type=hidden name=db value=$form->{db}>
 
 968           <input type=hidden name=sort value=transdate>
 
 979     <td><hr size=3 noshade></td>
 
 984 <input type=submit class=submit name=action value="|
 
 985     . $locale->text('Continue') . qq|">
 
 993   $lxdebug->leave_sub();
 
 996 sub continue { call_sub($form->{"nextsub"}); }
 
 999   $lxdebug->enter_sub();
 
1001   $auth->assert('report');
 
1003   my $nextsub = shift;
 
1005   $form->{project_id} = $form->{project_id_1};
 
1006   if ($form->{projectnumber} && !$form->{project_id}) {
 
1007     $form->{rowcount} = 1;
 
1009     # call this instead of update
 
1010     $form->{update}          = $nextsub;
 
1011     $form->{projectnumber_1} = $form->{projectnumber};
 
1013     delete $form->{sort};
 
1016     # if there is one only, assign id
 
1017     $form->{project_id} = $form->{project_id_1};
 
1020   $lxdebug->leave_sub();
 
1023 sub generate_income_statement {
 
1024   $lxdebug->enter_sub();
 
1026   $auth->assert('report');
 
1028   $form->{padding} = "  ";
 
1029   $form->{bold}    = "<b>";
 
1030   $form->{endbold} = "</b>";
 
1031   $form->{br}      = "<br>";
 
1033   if ($form->{reporttype} eq "custom") {
 
1035     #forgotten the year --> thisyear
 
1036     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
1037       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
1043     if ($form->{duetyp} eq "13") {
 
1044       $form->{fromdate} = "1.1.$form->{year}";
 
1045       $form->{todate}   = "31.12.$form->{year}";
 
1049     if ($form->{duetyp} eq "A") {
 
1050       $form->{fromdate} = "1.1.$form->{year}";
 
1051       $form->{todate}   = "31.3.$form->{year}";
 
1053     if ($form->{duetyp} eq "B") {
 
1054       $form->{fromdate} = "1.4.$form->{year}";
 
1055       $form->{todate}   = "30.6.$form->{year}";
 
1057     if ($form->{duetyp} eq "C") {
 
1058       $form->{fromdate} = "1.7.$form->{year}";
 
1059       $form->{todate}   = "30.9.$form->{year}";
 
1061     if ($form->{duetyp} eq "D") {
 
1062       $form->{fromdate} = "1.10.$form->{year}";
 
1063       $form->{todate}   = "31.12.$form->{year}";
 
1068       $form->{duetyp} eq "1" && do {
 
1069         $form->{fromdate} = "1.1.$form->{year}";
 
1070         $form->{todate}   = "31.1.$form->{year}";
 
1073       $form->{duetyp} eq "2" && do {
 
1074         $form->{fromdate} = "1.2.$form->{year}";
 
1076         #this works from 1901 to 2099, 1900 and 2100 fail.
 
1077         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
1078         $form->{todate} = "$leap.2.$form->{year}";
 
1081       $form->{duetyp} eq "3" && do {
 
1082         $form->{fromdate} = "1.3.$form->{year}";
 
1083         $form->{todate}   = "31.3.$form->{year}";
 
1086       $form->{duetyp} eq "4" && do {
 
1087         $form->{fromdate} = "1.4.$form->{year}";
 
1088         $form->{todate}   = "30.4.$form->{year}";
 
1091       $form->{duetyp} eq "5" && do {
 
1092         $form->{fromdate} = "1.5.$form->{year}";
 
1093         $form->{todate}   = "31.5.$form->{year}";
 
1096       $form->{duetyp} eq "6" && do {
 
1097         $form->{fromdate} = "1.6.$form->{year}";
 
1098         $form->{todate}   = "30.6.$form->{year}";
 
1101       $form->{duetyp} eq "7" && do {
 
1102         $form->{fromdate} = "1.7.$form->{year}";
 
1103         $form->{todate}   = "31.7.$form->{year}";
 
1106       $form->{duetyp} eq "8" && do {
 
1107         $form->{fromdate} = "1.8.$form->{year}";
 
1108         $form->{todate}   = "31.8.$form->{year}";
 
1111       $form->{duetyp} eq "9" && do {
 
1112         $form->{fromdate} = "1.9.$form->{year}";
 
1113         $form->{todate}   = "30.9.$form->{year}";
 
1116       $form->{duetyp} eq "10" && do {
 
1117         $form->{fromdate} = "1.10.$form->{year}";
 
1118         $form->{todate}   = "31.10.$form->{year}";
 
1121       $form->{duetyp} eq "11" && do {
 
1122         $form->{fromdate} = "1.11.$form->{year}";
 
1123         $form->{todate}   = "30.11.$form->{year}";
 
1126       $form->{duetyp} eq "12" && do {
 
1127         $form->{fromdate} = "1.12.$form->{year}";
 
1128         $form->{todate}   = "31.12.$form->{year}";
 
1134   RP->income_statement(\%myconfig, \%$form);
 
1136   ($form->{department}) = split /--/, $form->{department};
 
1139     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1140   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
1142   # if there are any dates construct a where
 
1143   if ($form->{fromdate} || $form->{todate}) {
 
1145     unless ($form->{todate}) {
 
1146       $form->{todate} = $form->current_date(\%myconfig);
 
1149     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
 
1150     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
 
1152     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1153     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
 
1155     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
1157         $locale->text('for Period')
 
1158       . qq|\n$longfromdate |
 
1159       . $locale->text('Bis')
 
1163   if ($form->{comparefromdate} || $form->{comparetodate}) {
 
1164     $longcomparefromdate =
 
1165       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
 
1166     $shortcomparefromdate =
 
1167       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
 
1169     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
 
1170     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
 
1172     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
 
1174         "\n$longcomparefromdate "
 
1175       . $locale->text('Bis')
 
1176       . qq| $longcomparetodate|;
 
1179   # setup variables for the form
 
1180   @a = qw(company address businessnumber);
 
1181   map { $form->{$_} = $myconfig{$_} } @a;
 
1183   $form->{templates} = $myconfig{templates};
 
1185   $form->{IN} = "income_statement.html";
 
1187   $form->parse_template;
 
1189   $lxdebug->leave_sub();
 
1192 sub generate_balance_sheet {
 
1193   $lxdebug->enter_sub();
 
1195   $auth->assert('report');
 
1197   $form->{padding} = "  ";
 
1198   $form->{bold}    = "<b>";
 
1199   $form->{endbold} = "</b>";
 
1200   $form->{br}      = "<br>";
 
1202   RP->balance_sheet(\%myconfig, \%$form);
 
1204   $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
 
1206     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1208   ($form->{department}) = split /--/, $form->{department};
 
1210   # define Current Earnings account
 
1211   $padding = ($form->{l_heading}) ? $form->{padding} : "";
 
1212   push(@{ $form->{equity_account} },
 
1213        $padding . $locale->text('Current Earnings'));
 
1215   $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
 
1216   $form->{last_period} =
 
1217     $locale->date(\%myconfig, $form->{compareasofdate}, 0);
 
1219   $form->{IN} = "balance_sheet.html";
 
1221   # setup company variables for the form
 
1222   map { $form->{$_} = $myconfig{$_}; } (qw(company address businessnumber nativecurr));
 
1224   $form->{templates} = $myconfig{templates};
 
1226   $form->parse_template;
 
1228   $lxdebug->leave_sub();
 
1231 sub generate_projects {
 
1232   $lxdebug->enter_sub();
 
1234   $auth->assert('report');
 
1236   &get_project(generate_projects);
 
1237   $form->{projectnumber} = $form->{projectnumber_1};
 
1239   $form->{nextsub} = "generate_projects";
 
1240   $form->{title}   = $locale->text('Project Transactions');
 
1241   RP->trial_balance(\%myconfig, \%$form);
 
1243   list_accounts('generate_projects');
 
1245   $lxdebug->leave_sub();
 
1251 # included links to display transactions for period entered
 
1252 # added headers and subtotals
 
1254 sub generate_trial_balance {
 
1255   $lxdebug->enter_sub();
 
1257   $auth->assert('report');
 
1259   if ($form->{reporttype} eq "custom") {
 
1261     #forgotten the year --> thisyear
 
1262     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
1263       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
1269     if ($form->{duetyp} eq "13") {
 
1270       $form->{fromdate} = "1.1.$form->{year}";
 
1271       $form->{todate}   = "31.12.$form->{year}";
 
1275     if ($form->{duetyp} eq "A") {
 
1276       $form->{fromdate} = "1.1.$form->{year}";
 
1277       $form->{todate}   = "31.3.$form->{year}";
 
1279     if ($form->{duetyp} eq "B") {
 
1280       $form->{fromdate} = "1.4.$form->{year}";
 
1281       $form->{todate}   = "30.6.$form->{year}";
 
1283     if ($form->{duetyp} eq "C") {
 
1284       $form->{fromdate} = "1.7.$form->{year}";
 
1285       $form->{todate}   = "30.9.$form->{year}";
 
1287     if ($form->{duetyp} eq "D") {
 
1288       $form->{fromdate} = "1.10.$form->{year}";
 
1289       $form->{todate}   = "31.12.$form->{year}";
 
1294       $form->{duetyp} eq "1" && do {
 
1295         $form->{fromdate} = "1.1.$form->{year}";
 
1296         $form->{todate}   = "31.1.$form->{year}";
 
1299       $form->{duetyp} eq "2" && do {
 
1300         $form->{fromdate} = "1.2.$form->{year}";
 
1302         #this works from 1901 to 2099, 1900 and 2100 fail.
 
1303         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
1304         $form->{todate} = "$leap.2.$form->{year}";
 
1307       $form->{duetyp} eq "3" && do {
 
1308         $form->{fromdate} = "1.3.$form->{year}";
 
1309         $form->{todate}   = "31.3.$form->{year}";
 
1312       $form->{duetyp} eq "4" && do {
 
1313         $form->{fromdate} = "1.4.$form->{year}";
 
1314         $form->{todate}   = "30.4.$form->{year}";
 
1317       $form->{duetyp} eq "5" && do {
 
1318         $form->{fromdate} = "1.5.$form->{year}";
 
1319         $form->{todate}   = "31.5.$form->{year}";
 
1322       $form->{duetyp} eq "6" && do {
 
1323         $form->{fromdate} = "1.6.$form->{year}";
 
1324         $form->{todate}   = "30.6.$form->{year}";
 
1327       $form->{duetyp} eq "7" && do {
 
1328         $form->{fromdate} = "1.7.$form->{year}";
 
1329         $form->{todate}   = "31.7.$form->{year}";
 
1332       $form->{duetyp} eq "8" && do {
 
1333         $form->{fromdate} = "1.8.$form->{year}";
 
1334         $form->{todate}   = "31.8.$form->{year}";
 
1337       $form->{duetyp} eq "9" && do {
 
1338         $form->{fromdate} = "1.9.$form->{year}";
 
1339         $form->{todate}   = "30.9.$form->{year}";
 
1342       $form->{duetyp} eq "10" && do {
 
1343         $form->{fromdate} = "1.10.$form->{year}";
 
1344         $form->{todate}   = "31.10.$form->{year}";
 
1347       $form->{duetyp} eq "11" && do {
 
1348         $form->{fromdate} = "1.11.$form->{year}";
 
1349         $form->{todate}   = "30.11.$form->{year}";
 
1352       $form->{duetyp} eq "12" && do {
 
1353         $form->{fromdate} = "1.12.$form->{year}";
 
1354         $form->{todate}   = "31.12.$form->{year}";
 
1361   # get for each account initial balance, debits and credits
 
1362   RP->trial_balance(\%myconfig, \%$form);
 
1365   $form->{rowcount} = scalar @{ $form->{TB} };
 
1368     "accno",               "description",
 
1369     "last_transaction",    "soll_eb",
 
1372     "soll_kumuliert", "haben_kumuliert",
 
1373     "soll_saldo", "haben_saldo"
 
1377   my $attachment_basename;
 
1379   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1381   my @hidden_variables = ();
 
1382   push @hidden_variables, qw(fromdate todate year cash );
 
1384   my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
 
1387     'accno'                   => { 'text' => $locale->text('Account Number'), },
 
1388     'description'             => { 'text' => $locale->text('Description'), },
 
1389     'last_transaction'        => { 'text' => $locale->text('Last Transaction'), },
 
1390     'soll_eb'                 => { 'text' => $locale->text('Debit Starting Balance'), },
 
1391     'haben_eb'                => { 'text' => $locale->text('Credit Starting Balance'), },
 
1392     'soll'                    => { 'text' => $locale->text('Debit'), },
 
1393     'haben'                   => { 'text' => $locale->text('Credit'), },
 
1394     'soll_kumuliert'          => { 'text' => $locale->text('Sum Debit'), },
 
1395     'haben_kumuliert'         => { 'text' => $locale->text('Sum Credit'), },
 
1396     'soll_saldo'              => { 'text' => $locale->text('Saldo Debit'), },
 
1397     'haben_saldo'                => { 'text' => $locale->text('Saldo Credit'), }
 
1402   my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
 
1404   map { $column_defs{$_}->{visible} =  1 } @columns;
 
1406   $report->set_columns(%column_defs);
 
1407   $report->set_column_order(@columns);
 
1409   $report->set_export_options('trial_balance', @hidden_variables);
 
1411   $report->set_sort_indicator($form->{sort}, 1);
 
1416   $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . "  -  " . $locale->date(\%myconfig, $form->{todate}, 0);
 
1417   $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
 
1419   $report->set_options('output_format'        => 'HTML',
 
1420                        'title'                => $form->{title},
 
1421                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
1422                        'html_template'        => 'rp/html_report_susa',
 
1423                        'pdf_template'         => 'rp/html_report_susa',
 
1425   $report->set_options_from_form();
 
1427   # add sort and escape callback, this one we use for the add sub
 
1428   $form->{callback} = $href .= "&sort=$form->{sort}";
 
1430   # escape callback for href
 
1431   $callback = $form->escape($href);
 
1433   my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
 
1435   my %totals    = map { $_ => 0 } @subtotal_columns;
 
1437   my $edit_url = build_std_url('action=edit', 'type', 'vc');
 
1439   foreach $accno (@{ $form->{TB} }) {
 
1441     $accno->{soll} = $accno->{debit};
 
1442     $accno->{haben} = $accno->{credit};
 
1443     map { $totals{$_}    += $accno->{$_} } @subtotal_columns;
 
1445     map { $accno->{$_} = $form->format_amount(\%myconfig, $accno->{$_}, 2) } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
 
1447     map { $accno->{$_} = ($accno->{$_} == 0) ? '' : $accno->{$_} } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
 
1451     foreach my $column (@columns) {
 
1453         'data'  => $accno->{$column},
 
1454         'align' => $column_alignment{$column},
 
1459     $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
 
1461     my $row_set = [ $row ];
 
1464     $report->add_data($row_set);
 
1469   $report->add_separator();
 
1471   $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
 
1473   $report->generate_with_headers();
 
1475   $lxdebug->leave_sub();
 
1479 sub create_subtotal_row {
 
1480   $lxdebug->enter_sub();
 
1482   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
1484   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
1486   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
 
1488   $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
 
1490   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
1492   $lxdebug->leave_sub();
 
1497 sub create_list_accounts_subtotal_row {
 
1498   $lxdebug->enter_sub();
 
1500   my ($subtotals, $columns, $fields, $class) = @_;
 
1502   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
1504   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
 
1506   $lxdebug->leave_sub();
 
1512   $lxdebug->enter_sub();
 
1517   if ($form->{department}) {
 
1518     my ($department) = split /--/, $form->{department};
 
1519     push @options, $locale->text('Department') . " : $department";
 
1521   if ($form->{projectnumber}) {
 
1522     push @options, $locale->text('Project Number') . " : $form->{projectnumber}";
 
1525   # if there are any dates
 
1526   if ($form->{fromdate} || $form->{todate}) {
 
1527     my ($fromdate, $todate);
 
1529     if ($form->{fromdate}) {
 
1530       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1532     if ($form->{todate}) {
 
1533       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
 
1536     push @options, "$fromdate - $todate";
 
1539     push @options, $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1542   my @columns     = qw(accno description begbalance debit credit endbalance);
 
1544     'accno'       => { 'text' => $locale->text('Account'), },
 
1545     'description' => { 'text' => $locale->text('Description'), },
 
1546     'debit'       => { 'text' => $locale->text('Debit'), },
 
1547     'credit'      => { 'text' => $locale->text('Credit'), },
 
1548     'begbalance'  => { 'text' => $locale->text('Balance'), },
 
1549     'endbalance'  => { 'text' => $locale->text('Balance'), },
 
1551   my %column_alignment = map { $_ => 'right' } qw(debit credit begbalance endbalance);
 
1553   my @hidden_variables = qw(fromdate todate department l_heading l_subtotal all_accounts sort accounttype eur projectnumber project_id title nextsub);
 
1555   $form->{callback} = build_std_url("action=$action", grep { $form->{$_} } @hidden_variables);
 
1557   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1559   $report->set_options('top_info_text'         => join("\n", @options),
 
1560                        'output_format'         => 'HTML',
 
1561                        'title'                 => $form->{title},
 
1562                        'attachment_basename'   => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
 
1563                        'std_column_visibility' => 1,
 
1565   $report->set_options_from_form();
 
1567   $report->set_columns(%column_defs);
 
1568   $report->set_column_order(@columns);
 
1570   $report->set_export_options($action, @hidden_variables);
 
1572   $report->set_sort_indicator('accno', 1);
 
1574   my @totals_columns = qw(credit debit begbalance endbalance);
 
1575   my %subtotals      = map { $_ => 0 } @totals_columns;
 
1576   my %totals         = map { $_ => 0 } @totals_columns;
 
1577   my $found_heading  = 0;
 
1578   my @tb             = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
 
1580   # sort the whole thing by account numbers and display
 
1581   foreach my $idx (0 .. scalar(@tb) - 1) {
 
1582     my $ref  = $tb[$idx];
 
1583     my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
 
1585     my $ml   = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
 
1587     my $row  = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
 
1589     if ($ref->{charttype} eq 'H') {
 
1590       next unless ($form->{l_heading});
 
1592       %subtotals                   = map { $_ => 0 } @totals_columns;
 
1594       $row->{description}->{class} = 'listheading';
 
1595       $row->{description}->{data}  = $ref->{description};
 
1597       $report->add_data($row);
 
1602     foreach (qw(debit credit)) {
 
1603       $subtotals{$_} += $ref->{$_};
 
1604       $totals{$_}    += $ref->{$_};
 
1607     $subtotals{begbalance} += $ref->{balance} * $ml;
 
1608     $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
 
1610     map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
 
1611     map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
 
1613     $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
 
1614     $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
 
1616     $report->add_data($row);
 
1618     if ($form->{l_heading} && $found_heading &&
 
1619         (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
 
1620       $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
 
1624   $report->add_separator();
 
1626   $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
 
1628   $report->generate_with_headers();
 
1630   $lxdebug->leave_sub();
 
1633 sub generate_ar_aging {
 
1634   $lxdebug->enter_sub();
 
1636   $auth->assert('general_ledger');
 
1639   ($form->{customer}) = split(/--/, $form->{customer});
 
1641   $form->{ct}   = "customer";
 
1642   $form->{arap} = "ar";
 
1644   $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
 
1646   RP->aging(\%myconfig, \%$form);
 
1649   $lxdebug->leave_sub();
 
1652 sub generate_ap_aging {
 
1653   $lxdebug->enter_sub();
 
1655   $auth->assert('general_ledger');
 
1658   ($form->{vendor}) = split(/--/, $form->{vendor});
 
1660   $form->{ct}   = "vendor";
 
1661   $form->{arap} = "ap";
 
1663   $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
 
1665   RP->aging(\%myconfig, \%$form);
 
1668   $lxdebug->leave_sub();
 
1671 sub create_aging_subtotal_row {
 
1672   $lxdebug->enter_sub();
 
1674   my ($subtotals, $columns, $periods, $class) = @_;
 
1676   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
1678   foreach (@{ $periods }) {
 
1679     $row->{"c$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
 
1680     $subtotals->{$_}      = 0;
 
1683   $lxdebug->leave_sub();
 
1689   $lxdebug->enter_sub();
 
1691   $auth->assert('general_ledger');
 
1693   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1695   my @columns = qw(statement ct invnumber transdate duedate c0 c30 c60 c90);
 
1698     'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
 
1699     'ct'        => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
 
1700     'invnumber' => { 'text' => $locale->text('Invoice'), },
 
1701     'transdate' => { 'text' => $locale->text('Date'), },
 
1702     'duedate'   => { 'text' => $locale->text('Due'), },
 
1703     'c0'        => { 'text' => $locale->text('Current'), },
 
1704     'c30'       => { 'text' => '30', },
 
1705     'c60'       => { 'text' => '60', },
 
1706     'c90'       => { 'text' => '90', },
 
1709   my %column_alignment = ('statement' => 'center',
 
1710                           map { $_ => 'right' } qw(c0 c30 c60 c90));
 
1712   $report->set_options('std_column_visibility' => 1);
 
1713   $report->set_columns(%column_defs);
 
1714   $report->set_column_order(@columns);
 
1716   my @hidden_variables = qw(todate customer vendor arap title ct);
 
1717   $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
 
1721   if ($form->{department}) {
 
1722     my ($department) = split /--/, $form->{department};
 
1723     push @options, $locale->text('Department') . " : $department";
 
1724     $form->{callback} .= "&department=" . E($department);
 
1727   if (($form->{arap} eq 'ar') && $form->{customer}) {
 
1728     push @options, $form->{customer};
 
1731   if (($form->{arap} eq 'ap') && $form->{vendor}) {
 
1732     push @options, $form->{vendor};
 
1735   push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
 
1737   my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
 
1739   $report->set_options('top_info_text'        => join("\n", @options),
 
1740                        'output_format'        => 'HTML',
 
1741                        'title'                => $form->{title},
 
1742                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
1745   my $previous_ctid = 0;
 
1747   my @periods       = qw(0 30 60 90);
 
1748   my %subtotals     = map { $_ => 0 } @periods;
 
1749   my %totals        = map { $_ => 0 } @periods;
 
1751   foreach $ref (@{ $form->{AG} }) {
 
1752     if ($row_idx && ($previous_ctid != $ref->{ctid})) {
 
1753       $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
 
1756     foreach my $key (@periods) {
 
1757       $subtotals{$key}  += $ref->{"c${key}"};
 
1758       $totals{$key}     += $ref->{"c${key}"};
 
1759       $ref->{"c${key}"}  = $ref->{"c${key}"} != 0 ? $form->format_amount(\%myconfig, $ref->{"c${key}"}, 2) : '';
 
1764     foreach my $column (@columns) {
 
1766         'data'   => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
 
1767         'align'  => $column_alignment{$column},
 
1768         'valign' => $column eq 'statement' ? 'center' : '',
 
1772     $row->{invnumber}->{link} =  build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
 
1774     if ($previous_ctid != $ref->{ctid}) {
 
1775       $row->{statement}->{raw_data} =
 
1776           $cgi->hidden('-name' => "customer_id_${row_idx}", '-value' => $ref->{ctid})
 
1777         . $cgi->checkbox('-name' => "statement_${row_idx}", '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
 
1778       $row->{ct}->{data} = $ref->{name};
 
1783     $previous_ctid = $ref->{ctid};
 
1785     $report->add_data($row);
 
1788   $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
 
1790   $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
 
1792   if ($form->{arap} eq 'ar') {
 
1793     $raw_top_info_text    = $form->parse_html_template('rp/aging_ar_top');
 
1794     $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
 
1795                                                                                'PRINT_OPTIONS' => print_options(inline => 1), });
 
1796     $report->set_options('raw_top_info_text'    => $raw_top_info_text,
 
1797                          'raw_bottom_info_text' => $raw_bottom_info_text);
 
1800   $report->set_options_from_form();
 
1802   $report->generate_with_headers();
 
1804   $lxdebug->leave_sub();
 
1808   $lxdebug->enter_sub();
 
1810   RP->aging(\%myconfig, \%$form);
 
1812   map { $_->{checked} = "checked" } @{ $form->{AG} };
 
1816   $lxdebug->leave_sub();
 
1820   $lxdebug->enter_sub();
 
1822   $auth->assert('general_ledger');
 
1824   # get name and email addresses
 
1825   for $i (1 .. $form->{rowcount}) {
 
1826     if ($form->{"statement_$i"}) {
 
1827       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
 
1828       RP->get_customer(\%myconfig, \%$form);
 
1834   $form->error($locale->text('Nothing selected!')) unless $selected;
 
1836   if ($myconfig{role} eq 'admin') {
 
1838           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
 
1839           <td><input name=bcc size=30 value="$form->{bcc}"></td>
 
1843   $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
 
1845   $form->{media} = "email";
 
1852 <form method=post action=$form->{script}>
 
1858   <tr height="5"></tr>
 
1863           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
 
1864           <td><input name=email size=30 value="$form->{email}"></td>
 
1865           <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
 
1866           <td><input name=cc size=30 value="$form->{cc}"></td>
 
1869           <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
 
1870           <td><input name=subject size=30 value="$form->{subject}"></td>
 
1880           <th align=left nowrap>| . $locale->text('Message') . qq|</th>
 
1883           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
 
1894   map { delete $form->{$_} }
 
1895     qw(action email cc bcc subject message type sendmode format header);
 
1897   # save all other variables
 
1898   foreach $key (keys %$form) {
 
1899     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
1900     $form->{$key} =~ s/\"/"/g;
 
1901     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1908     <td><hr size=3 noshade></td>
 
1912 <input type=hidden name=nextsub value=send_email>
 
1915 <input name=action class=submit type=submit value="|
 
1916     . $locale->text('Continue') . qq|">
 
1923   $lxdebug->leave_sub();
 
1927   $lxdebug->enter_sub();
 
1929   $auth->assert('general_ledger');
 
1931   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
 
1932     unless $form->{subject};
 
1934   RP->aging(\%myconfig, \%$form);
 
1936   $form->{"statement_1"} = 1;
 
1938   $form->{media} = 'email';
 
1941   $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
 
1943   $lxdebug->leave_sub();
 
1947   $lxdebug->enter_sub();
 
1949   $auth->assert('general_ledger');
 
1951   if ($form->{media} eq 'printer') {
 
1952     $form->error($locale->text('Select postscript or PDF!'))
 
1953       if ($form->{format} !~ /(postscript|pdf)/);
 
1956   for $i (1 .. $form->{rowcount}) {
 
1957     if ($form->{"statement_$i"}) {
 
1958       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
 
1964   $form->error($locale->text('Nothing selected!')) unless $selected;
 
1966   if ($form->{media} eq 'printer') {
 
1967     $form->{"$form->{ct}_id"} = "";
 
1969     $form->{"statement_1"} = 1;
 
1972   RP->aging(\%myconfig, \%$form);
 
1976   $form->redirect($locale->text('Statements sent to printer!'))
 
1977     if ($form->{media} eq 'printer');
 
1979   $lxdebug->leave_sub();
 
1983   $lxdebug->enter_sub();
 
1985   $auth->assert('general_ledger');
 
1989      "ä" => "ae", "ö" => "oe", "ü" => "ue",
 
1990      "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
 
1995   foreach my $key (keys %replacements) {
 
1996     my $new_key = SL::Iconv::convert("ISO-8859-15", $dbcharset, $key);
 
1997     $replacements{$new_key} = $replacements{$key} if $new_key ne $key;
 
2000   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
 
2002   $form->{templates} = "$myconfig{templates}";
 
2004   my $suffix = "html";
 
2005   my $attachment_suffix = "html";
 
2006   if ($form->{format} eq 'postscript') {
 
2007     $form->{postscript} = 1;
 
2009     $attachment_suffix = "ps";
 
2010   } elsif ($form->{format} eq 'pdf') {
 
2013     $attachment_suffix = "pdf";
 
2016   $form->{IN}  = "$form->{type}.$suffix";
 
2017   $form->{OUT} = $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
 
2019   # Save $form->{email} because it will be overwritten.
 
2020   $form->{EMAIL_RECIPIENT} = $form->{email};
 
2023   while (@{ $form->{AG} }) {
 
2025     $ref = shift @{ $form->{AG} };
 
2027     if ($ctid != $ref->{ctid}) {
 
2029       $ctid = $ref->{ctid};
 
2032       if ($form->{"statement_$i"}) {
 
2035           (name, street, zipcode, city, country, contact, email,
 
2036            "$form->{ct}phone", "$form->{ct}fax");
 
2037         map { $form->{$_} = $ref->{$_} } @a;
 
2039         $form->{ $form->{ct} } = $form->{name};
 
2040         $form->{"$form->{ct}_id"} = $ref->{ctid};
 
2042         map { $form->{$_} = () } qw(invnumber invdate duedate);
 
2044         foreach $item (qw(c0 c30 c60 c90)) {
 
2045           $form->{$item} = ();
 
2046           $form->{"${item}total"} = 0;
 
2049         &statement_details($ref);
 
2053           if (scalar(@{ $form->{AG} }) > 0) {
 
2055             # one or more left to go
 
2056             if ($ctid == $form->{AG}->[0]->{ctid}) {
 
2057               $ref = shift @{ $form->{AG} };
 
2058               &statement_details($ref);
 
2061               $ref = scalar(@{ $form->{AG} });
 
2067             # set initial ref to 0
 
2074           $form->{"${_}total"} =
 
2075             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
 
2076         } (c0, c30, c60, c90, "");
 
2078         $form->{attachment_filename} = $locale->text("Statement") . "_$form->{todate}.$attachment_suffix";
 
2079         map({ $form->{attachment_filename} =~ s/$_/$replacements{$_}/g; } keys(%replacements));
 
2081         $form->parse_template(\%myconfig, $userspath);
 
2086   # saving the history
 
2087   if(!exists $form->{addition} && $form->{id} ne "") {
 
2088     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
2089         $form->{addition} = "PRINTED";
 
2090         $form->{what_done} = $form->{type};
 
2091         $form->save_history($form->dbconnect(\%myconfig));
 
2093   # /saving the history 
 
2094   $lxdebug->leave_sub();
 
2097 sub statement_details {
 
2098   $lxdebug->enter_sub();
 
2100   $auth->assert('general_ledger');
 
2104   push @{ $form->{invnumber} }, $ref->{invnumber};
 
2105   push @{ $form->{invdate} },   $ref->{transdate};
 
2106   push @{ $form->{duedate} },   $ref->{duedate};
 
2108   foreach $item (qw(c0 c30 c60 c90)) {
 
2109     if ($ref->{exchangerate} * 1) {
 
2111         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
 
2113     $form->{"${item}total"} += $ref->{$item};
 
2114     $form->{total}          += $ref->{$item};
 
2115     push @{ $form->{$item} },
 
2116       $form->format_amount(\%myconfig, $ref->{$item}, 2);
 
2119   $lxdebug->leave_sub();
 
2122 sub generate_tax_report {
 
2123   $lxdebug->enter_sub();
 
2125   $auth->assert('report');
 
2127   RP->tax_report(\%myconfig, \%$form);
 
2129   $descvar     = "$form->{accno}_description";
 
2130   $description = $form->escape($form->{$descvar});
 
2131   $ratevar     = "$form->{accno}_rate";
 
2133   $department = $form->escape($form->{department});
 
2137     "$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}";
 
2139   # construct callback
 
2140   $description = $form->escape($form->{$descvar},   1);
 
2141   $department  = $form->escape($form->{department}, 1);
 
2143     "$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}";
 
2145   $title = $form->escape($form->{title});
 
2146   $href .= "&title=$title";
 
2147   $title = $form->escape($form->{title}, 1);
 
2148   $callback .= "&title=$title";
 
2150   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
 
2153     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
 
2155   foreach $item (@columns) {
 
2156     if ($form->{"l_$item"} eq "Y") {
 
2157       push @column_index, $item;
 
2159       # add column to href and callback
 
2160       $callback .= "&l_$item=Y";
 
2161       $href     .= "&l_$item=Y";
 
2165   if ($form->{l_subtotal} eq 'Y') {
 
2166     $callback .= "&l_subtotal=Y";
 
2167     $href     .= "&l_subtotal=Y";
 
2170   if ($form->{department}) {
 
2171     ($department) = split /--/, $form->{department};
 
2172     $option = $locale->text('Department') . " : $department";
 
2175   # if there are any dates
 
2176   if ($form->{fromdate} || $form->{todate}) {
 
2177     if ($form->{fromdate}) {
 
2178       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
2180     if ($form->{todate}) {
 
2181       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
 
2184     $form->{period} = "$fromdate - $todate";
 
2187       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2190   if ($form->{db} eq 'ar') {
 
2191     $name    = $locale->text('Customer');
 
2195   if ($form->{db} eq 'ap') {
 
2196     $name    = $locale->text('Vendor');
 
2201   $option .= "<br>" if $option;
 
2202   $option .= "$form->{period}";
 
2204   $column_header{id} =
 
2205       qq|<th><a class=listheading href=$href&sort=id>|
 
2206     . $locale->text('ID')
 
2208   $column_header{invnumber} =
 
2209       qq|<th><a class=listheading href=$href&sort=invnumber>|
 
2210     . $locale->text('Invoice')
 
2212   $column_header{transdate} =
 
2213       qq|<th><a class=listheading href=$href&sort=transdate>|
 
2214     . $locale->text('Date')
 
2216   $column_header{netamount} =
 
2217     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
 
2218   $column_header{tax} =
 
2219     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
 
2220   $column_header{amount} =
 
2221     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
 
2223   $column_header{name} =
 
2224     qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
 
2233     <th class=listtop colspan=$colspan>$form->{title}</th>
 
2235   <tr height="5"></tr>
 
2242         <tr class=listheading>
 
2245   map { print "$column_header{$_}\n" } @column_index;
 
2251   # add sort and escape callback
 
2252   $callback = $form->escape($callback . "&sort=$form->{sort}");
 
2254   if (@{ $form->{TR} }) {
 
2255     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
 
2258   foreach $ref (@{ $form->{TR} }) {
 
2260     $module = ($ref->{invoice}) ? $invoice : $arap;
 
2262     if ($form->{l_subtotal} eq 'Y') {
 
2263       if ($sameitem ne $ref->{ $form->{sort} }) {
 
2265         $sameitem = $ref->{ $form->{sort} };
 
2269     $totalnetamount += $ref->{netamount};
 
2270     $totaltax       += $ref->{tax};
 
2271     $ref->{amount} = $ref->{netamount} + $ref->{tax};
 
2273     $subtotalnetamount += $ref->{netamount};
 
2274     $subtotaltax       += $ref->{tax};
 
2277       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
 
2278     } qw(netamount tax amount);
 
2280     $column_data{id}        = qq|<td>$ref->{id}</td>|;
 
2281     $column_data{invnumber} =
 
2282       qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
 
2283     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
 
2284     $column_data{name}      = qq|<td>$ref->{name} </td>|;
 
2286     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
 
2287       qw(netamount tax amount);
 
2292         <tr class=listrow$i>
 
2295     map { print "$column_data{$_}\n" } @column_index;
 
2303   if ($form->{l_subtotal} eq 'Y') {
 
2307   map { $column_data{$_} = qq|<th> </th>| } @column_index;
 
2311         <tr class=listtotal>
 
2315     $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
 
2317     $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
 
2318   $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
 
2320   $column_data{netamount} =
 
2321     qq|<th class=listtotal align=right>$totalnetamount</th>|;
 
2322   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
 
2323   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
 
2325   map { print "$column_data{$_}\n" } @column_index;
 
2333     <td><hr size=3 noshade></td>
 
2341   $lxdebug->leave_sub();
 
2345   $lxdebug->enter_sub();
 
2347   map { $column_data{$_} = "<td> </td>" } @column_index;
 
2349   $subtotalnetamount =
 
2350     $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
 
2351   $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
 
2353     $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
 
2356   $column_data{netamount} =
 
2357     "<th class=listsubtotal align=right>$subtotalnetamount</th>";
 
2358   $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
 
2359   $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
 
2361   $subtotalnetamount = 0;
 
2365         <tr class=listsubtotal>
 
2367   map { print "\n$column_data{$_}" } @column_index;
 
2373   $lxdebug->leave_sub();
 
2377   $lxdebug->enter_sub();
 
2379   $auth->assert('cash');
 
2381   if ($form->{account}) {
 
2382     ($form->{paymentaccounts}) = split /--/, $form->{account};
 
2384   if ($form->{department}) {
 
2385     ($department, $form->{department_id}) = split /--/, $form->{department};
 
2386     $option = $locale->text('Department') . " : $department";
 
2389   RP->payments(\%myconfig, \%$form);
 
2391   my @hidden_variables = qw(account title department reference source memo fromdate todate
 
2392                             fx_transaction db prepayment paymentaccounts sort);
 
2394   my $href = build_std_url('action=list_payments', grep { $form->{$_} } @hidden_variables);
 
2395   $form->{callback} = $href;
 
2397   my @columns     = qw(transdate invnumber name paid source memo);
 
2399     'name'      => { 'text' => $locale->text('Description'), },
 
2400     'invnumber' => { 'text' => $locale->text('Reference'), },
 
2401     'transdate' => { 'text' => $locale->text('Date'), },
 
2402     'paid'      => { 'text' => $locale->text('Amount'), },
 
2403     'source'    => { 'text' => $locale->text('Source'), },
 
2404     'memo'      => { 'text' => $locale->text('Memo'), },
 
2406   my %column_alignment = ('paid' => 'right');
 
2408   map { $column_defs{$_}->{link} = $href . "&sort=$_" } grep { $_ ne 'paid' } @columns;
 
2411   if ($form->{fromdate}) {
 
2412     push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{fromdate}, 1);
 
2414   if ($form->{todate}) {
 
2415     push @options, $locale->text('bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
 
2418   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
2420   my $attachment_basename = $form->{db} eq 'ar' ? $locale->text('list_of_receipts') : $locale->text('list_of_payments');
 
2422   $report->set_options('top_info_text'         => join("\n", @options),
 
2423                        'output_format'         => 'HTML',
 
2424                        'title'                 => $form->{title},
 
2425                        'attachment_basename'   => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
2426                        'std_column_visibility' => 1,
 
2428   $report->set_options_from_form();
 
2430   $report->set_columns(%column_defs);
 
2431   $report->set_column_order(@columns);
 
2433   $report->set_export_options('list_payments', @hidden_variables);
 
2435   $report->set_sort_indicator($form->{sort}, 1);
 
2439   foreach my $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
 
2440     next unless @{ $form->{ $ref->{id} } };
 
2442     $report->add_control({ 'type' => 'colspan_data', 'data' => "$ref->{accno}--$ref->{description}" });
 
2444     my $subtotal_paid = 0;
 
2446     foreach my $payment (@{ $form->{ $ref->{id} } }) {
 
2447       my $module = $payment->{module};
 
2448       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
 
2449       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
 
2451       $subtotal_paid += $payment->{paid};
 
2452       $total_paid    += $payment->{paid};
 
2454       $payment->{paid} = $form->format_amount(\%myconfig, $payment->{paid}, 2);
 
2458       foreach my $column (@columns) {
 
2460           'data'  => $payment->{$column},
 
2461           'align' => $column_alignment{$column},
 
2465       $row->{invnumber}->{link} = build_std_url("script=${module}.pl", 'action=edit', 'id=' . E($payment->{id}), 'callback');
 
2467       $report->add_data($row);
 
2470     my $row = { map { $_ => { 'class' => 'listsubtotal' } } @columns };
 
2472       'data'  => $form->format_amount(\%myconfig, $subtotal_paid, 2),
 
2474       'class' => 'listsubtotal',
 
2477     $report->add_data($row);
 
2480   $report->add_separator();
 
2482   my $row = { map { $_ => { 'class' => 'listtotal' } } @columns };
 
2484     'data'  => $form->format_amount(\%myconfig, $total_paid, 2),
 
2486     'class' => 'listtotal',
 
2489   $report->add_data($row);
 
2491   $report->generate_with_headers();
 
2493   $lxdebug->leave_sub();
 
2497   $lxdebug->enter_sub();
 
2499   my ($dont_print) = @_;
 
2501   $form->{sendmode} = "attachment";
 
2504     $form->{"format"} ? $form->{"format"} :
 
2505     $myconfig{"template_format"} ? $myconfig{"template_format"} :
 
2509     $form->{"copies"} ? $form->{"copies"} :
 
2510     $myconfig{"copies"} ? $myconfig{"copies"} :
 
2513   $form->{PD}{ $form->{type} }     = "selected";
 
2514   $form->{DF}{ $form->{format} }   = "selected";
 
2515   $form->{OP}{ $form->{media} }    = "selected";
 
2516   $form->{SM}{ $form->{sendmode} } = "selected";
 
2519             <option value=statement $form->{PD}{statement}>|
 
2520       . $locale->text('Statement');
 
2522   if ($form->{media} eq 'email') {
 
2524             <option value=attachment $form->{SM}{attachment}>|
 
2525       . $locale->text('Attachment') . qq|
 
2526             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
 
2529             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
 
2530     if ($myconfig{printer} && $latex_templates) {
 
2532             <option value=printer $form->{OP}{printer}>|
 
2533         . $locale->text('Printer');
 
2537   if ($latex_templates) {
 
2539             <option value=html $form->{DF}{html}>| . $locale->text('HTML')
 
2540       . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
 
2541       . qq| <option value=postscript $form->{DF}{postscript}>| . $locale->text('Postscript');
 
2547     <td><select name=type>$type</select></td>
 
2548     <td><select name=format>$format</select></td>
 
2549     <td><select name=media>$media</select></td>
 
2552   if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
 
2554       <td>| . $locale->text('Copies') . qq|
 
2555       <input name=copies size=2 value=$form->{copies}></td>
 
2564   print $output unless $dont_print;
 
2566   $lxdebug->leave_sub();
 
2572   $lxdebug->enter_sub();
 
2574   $auth->assert('report');
 
2576   $form->{padding} = "  ";
 
2577   $form->{bold}    = "<b>";
 
2578   $form->{endbold} = "</b>";
 
2579   $form->{br}      = "<br>";
 
2581   if ($form->{reporttype} eq "custom") {
 
2583     #forgotten the year --> thisyear
 
2584     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
2585       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
2591     if ($form->{duetyp} eq "13") {
 
2592       $form->{fromdate}        = "1.1.$form->{year}";
 
2593       $form->{todate}          = "31.12.$form->{year}";
 
2594       $form->{comparefromdate} = "1.01.$form->{year}";
 
2595       $form->{comparetodate}   = "31.12.$form->{year}";
 
2599     if ($form->{duetyp} eq "A") {
 
2600       $form->{fromdate}        = "1.1.$form->{year}";
 
2601       $form->{todate}          = "31.3.$form->{year}";
 
2602       $form->{comparefromdate} = "1.01.$form->{year}";
 
2603       $form->{comparetodate}   = "31.03.$form->{year}";
 
2605     if ($form->{duetyp} eq "B") {
 
2606       $form->{fromdate}        = "1.4.$form->{year}";
 
2607       $form->{todate}          = "30.6.$form->{year}";
 
2608       $form->{comparefromdate} = "1.01.$form->{year}";
 
2609       $form->{comparetodate}   = "30.06.$form->{year}";
 
2611     if ($form->{duetyp} eq "C") {
 
2612       $form->{fromdate}        = "1.7.$form->{year}";
 
2613       $form->{todate}          = "30.9.$form->{year}";
 
2614       $form->{comparefromdate} = "1.01.$form->{year}";
 
2615       $form->{comparetodate}   = "30.09.$form->{year}";
 
2617     if ($form->{duetyp} eq "D") {
 
2618       $form->{fromdate}        = "1.10.$form->{year}";
 
2619       $form->{todate}          = "31.12.$form->{year}";
 
2620       $form->{comparefromdate} = "1.01.$form->{year}";
 
2621       $form->{comparetodate}   = "31.12.$form->{year}";
 
2626       $form->{duetyp} eq "1" && do {
 
2627         $form->{fromdate}        = "1.1.$form->{year}";
 
2628         $form->{todate}          = "31.1.$form->{year}";
 
2629         $form->{comparefromdate} = "1.01.$form->{year}";
 
2630         $form->{comparetodate}   = "31.01.$form->{year}";
 
2633       $form->{duetyp} eq "2" && do {
 
2634         $form->{fromdate} = "1.2.$form->{year}";
 
2636         #this works from 1901 to 2099, 1900 and 2100 fail.
 
2637         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
2638         $form->{todate}          = "$leap.2.$form->{year}";
 
2639         $form->{comparefromdate} = "1.01.$form->{year}";
 
2640         $form->{comparetodate}   = "$leap.02.$form->{year}";
 
2643       $form->{duetyp} eq "3" && do {
 
2644         $form->{fromdate}        = "1.3.$form->{year}";
 
2645         $form->{todate}          = "31.3.$form->{year}";
 
2646         $form->{comparefromdate} = "1.01.$form->{year}";
 
2647         $form->{comparetodate}   = "31.03.$form->{year}";
 
2650       $form->{duetyp} eq "4" && do {
 
2651         $form->{fromdate}        = "1.4.$form->{year}";
 
2652         $form->{todate}          = "30.4.$form->{year}";
 
2653         $form->{comparefromdate} = "1.01.$form->{year}";
 
2654         $form->{comparetodate}   = "30.04.$form->{year}";
 
2657       $form->{duetyp} eq "5" && do {
 
2658         $form->{fromdate}        = "1.5.$form->{year}";
 
2659         $form->{todate}          = "31.5.$form->{year}";
 
2660         $form->{comparefromdate} = "1.01.$form->{year}";
 
2661         $form->{comparetodate}   = "31.05.$form->{year}";
 
2664       $form->{duetyp} eq "6" && do {
 
2665         $form->{fromdate}        = "1.6.$form->{year}";
 
2666         $form->{todate}          = "30.6.$form->{year}";
 
2667         $form->{comparefromdate} = "1.01.$form->{year}";
 
2668         $form->{comparetodate}   = "30.06.$form->{year}";
 
2671       $form->{duetyp} eq "7" && do {
 
2672         $form->{fromdate}        = "1.7.$form->{year}";
 
2673         $form->{todate}          = "31.7.$form->{year}";
 
2674         $form->{comparefromdate} = "1.01.$form->{year}";
 
2675         $form->{comparetodate}   = "31.07.$form->{year}";
 
2678       $form->{duetyp} eq "8" && do {
 
2679         $form->{fromdate}        = "1.8.$form->{year}";
 
2680         $form->{todate}          = "31.8.$form->{year}";
 
2681         $form->{comparefromdate} = "1.01.$form->{year}";
 
2682         $form->{comparetodate}   = "31.08.$form->{year}";
 
2685       $form->{duetyp} eq "9" && do {
 
2686         $form->{fromdate}        = "1.9.$form->{year}";
 
2687         $form->{todate}          = "30.9.$form->{year}";
 
2688         $form->{comparefromdate} = "1.01.$form->{year}";
 
2689         $form->{comparetodate}   = "30.09.$form->{year}";
 
2692       $form->{duetyp} eq "10" && do {
 
2693         $form->{fromdate}        = "1.10.$form->{year}";
 
2694         $form->{todate}          = "31.10.$form->{year}";
 
2695         $form->{comparefromdate} = "1.01.$form->{year}";
 
2696         $form->{comparetodate}   = "31.10.$form->{year}";
 
2699       $form->{duetyp} eq "11" && do {
 
2700         $form->{fromdate}        = "1.11.$form->{year}";
 
2701         $form->{todate}          = "30.11.$form->{year}";
 
2702         $form->{comparefromdate} = "1.01.$form->{year}";
 
2703         $form->{comparetodate}   = "30.11.$form->{year}";
 
2706       $form->{duetyp} eq "12" && do {
 
2707         $form->{fromdate}        = "1.12.$form->{year}";
 
2708         $form->{todate}          = "31.12.$form->{year}";
 
2709         $form->{comparefromdate} = "1.01.$form->{year}";
 
2710         $form->{comparetodate}   = "31.12.$form->{year}";
 
2715     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
 
2716     $form->{fromdate} = "${dd}.${mm}.${yy}";
 
2717     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
 
2718     $form->{todate}          = "${dd}.${mm}.${yy}";
 
2719     $form->{comparefromdate} = "01.01.$yy";
 
2720     $form->{comparetodate}   = $form->{todate};
 
2723   RP->bwa(\%myconfig, \%$form);
 
2725   ($form->{department}) = split /--/, $form->{department};
 
2728     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2729   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
2731   # if there are any dates construct a where
 
2732   if ($form->{fromdate} || $form->{todate}) {
 
2734     unless ($form->{todate}) {
 
2735       $form->{todate} = $form->current_date(\%myconfig);
 
2738     my %germandate = ("dateformat" => "dd.mm.yyyy");
 
2740     $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
 
2741     $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
 
2743     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
 
2744     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
 
2746     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
2748         $locale->text('for Period')
 
2749       . qq|\n$longfromdate |
 
2750       . $locale->text('bis')
 
2754   # setup variables for the form
 
2755   @a = qw(company address businessnumber);
 
2756   map { $form->{$_} = $myconfig{$_} } @a;
 
2757   $form->{templates} = $myconfig{templates};
 
2759   $form->{IN} = "bwa.html";
 
2761   $form->parse_template;
 
2763   $lxdebug->leave_sub();