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);
 
  44 use SL::ReportGenerator;
 
  46 require "bin/mozilla/arap.pl";
 
  47 require "bin/mozilla/common.pl";
 
  48 require "bin/mozilla/report_generator.pl";
 
  54 # this is for our long dates
 
  55 # $locale->text('January')
 
  56 # $locale->text('February')
 
  57 # $locale->text('March')
 
  58 # $locale->text('April')
 
  59 # $locale->text('May ')
 
  60 # $locale->text('June')
 
  61 # $locale->text('July')
 
  62 # $locale->text('August')
 
  63 # $locale->text('September')
 
  64 # $locale->text('October')
 
  65 # $locale->text('November')
 
  66 # $locale->text('December')
 
  68 # this is for our short month
 
  69 # $locale->text('Jan')
 
  70 # $locale->text('Feb')
 
  71 # $locale->text('Mar')
 
  72 # $locale->text('Apr')
 
  73 # $locale->text('May')
 
  74 # $locale->text('Jun')
 
  75 # $locale->text('Jul')
 
  76 # $locale->text('Aug')
 
  77 # $locale->text('Sep')
 
  78 # $locale->text('Oct')
 
  79 # $locale->text('Nov')
 
  80 # $locale->text('Dec')
 
  82 # $locale->text('Balance Sheet')
 
  83 # $locale->text('Income Statement')
 
  84 # $locale->text('Trial Balance')
 
  85 # $locale->text('AR Aging')
 
  86 # $locale->text('AP Aging')
 
  87 # $locale->text('Tax collected')
 
  88 # $locale->text('Tax paid')
 
  89 # $locale->text('Receipts')
 
  90 # $locale->text('Payments')
 
  91 # $locale->text('Project Transactions')
 
  92 # $locale->text('Non-taxable Sales')
 
  93 # $locale->text('Non-taxable Purchases')
 
  96   $lxdebug->enter_sub();
 
  98   %title = ('balance_sheet'        => 'Balance Sheet',
 
  99             'income_statement'     => 'Income Statement',
 
 100             'trial_balance'        => 'Trial Balance',
 
 101             'ar_aging'             => 'AR Aging',
 
 102             'ap_aging'             => 'Offene Verbindlichkeiten',
 
 103             'tax_collected'        => 'Tax collected',
 
 104             'tax_paid'             => 'Tax paid',
 
 105             'nontaxable_sales'     => 'Non-taxable Sales',
 
 106             'nontaxable_purchases' => 'Non-taxable Purchases',
 
 107             'receipts'             => 'Receipts',
 
 108             'payments'             => 'Payments',
 
 109             'projects'             => 'Project Transactions',
 
 110             'bwa'                  => 'Betriebswirtschaftliche Auswertung',
 
 111             'ustva'                => 'Umsatzsteuervoranmeldung',);
 
 113   $form->{title} = $locale->text($title{ $form->{report} });
 
 115   $accrual = ($eur) ? ""        : "checked";
 
 116   $cash    = ($eur) ? "checked" : "";
 
 118   $year = (localtime)[5] + 1900;
 
 121   $form->all_departments(\%myconfig);
 
 122   if (@{ $form->{all_departments} }) {
 
 123     $form->{selectdepartment} = "<option>\n";
 
 126       $form->{selectdepartment} .=
 
 127         "<option>$_->{description}--$_->{id}\n"
 
 128     } (@{ $form->{all_departments} });
 
 133           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
 134           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
 136 | if $form->{selectdepartment};
 
 138   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 141   my %project_labels = ();
 
 142   my @project_values = ("");
 
 143   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 144     push(@project_values, $item->{"id"});
 
 145     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 149     NTI($cgi->popup_menu('-name' => "project_id",
 
 150                          '-values' => \@project_values,
 
 151                          '-labels' => \%project_labels));
 
 153   # use JavaScript Calendar or not
 
 154   $form->{jsscript} = 1;
 
 156   if ($form->{report} eq "ustva") {
 
 159     if ($form->{report} eq "balance_sheet") {
 
 160       $name_1    = "asofdate";
 
 162       $value_1   = "$form->{asofdate}";
 
 163       $trigger_1 = "trigger1";
 
 164       $name_2    = "compareasofdate";
 
 165       $id_2      = "compareasofdate";
 
 166       $value_2   = "$form->{compareasofdate}";
 
 167       $trigger_2 = "trigger2";
 
 168     } elsif ($form->{report} =~ /(receipts|payments)$/) {
 
 169       $name_1    = "fromdate";
 
 171       $value_1   = "$form->{fromdate}";
 
 172       $trigger_1 = "trigger1";
 
 176       $trigger_2 = "trigger2";
 
 178       if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
 
 186         $trigger_2 = "trigger2";
 
 189         $name_1    = "fromdate";
 
 191         $value_1   = "$form->{fromdate}";
 
 192         $trigger_1 = "trigger1";
 
 196         $trigger_2 = "trigger2";
 
 201   # with JavaScript Calendar
 
 202   if ($form->{jsscript}) {
 
 206          <input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 208         <input type=button name=$name_2 id="$trigger_2" value=|
 
 209         . $locale->text('button') . qq|>|;
 
 213         Form->write_trigger(\%myconfig, "1", "$name_2", "BR", "$trigger_2");
 
 216          <input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value="$value_1" onBlur=\"check_right_date_format(this)\">|;
 
 218         <input type=button name=$name_1 id="$trigger_1" value=|
 
 219         . $locale->text('button') . qq|>|;
 
 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|>
 
 229         Form->write_trigger(\%myconfig, "2", "$name_1", "BR", "$trigger_1",
 
 230                             "$name_2", "BL", "$trigger_2");
 
 234     # without JavaScript Calendar
 
 237         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 240         qq|<input name=$name_1 id=$id_1 size=11 title="$myconfig{dateformat}" value=$value_1 onBlur=\"check_right_date_format(this)\">|;
 
 242         qq|<input name=$name_2 id=$id_2 size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">|;
 
 245   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 247   $onload = qq|focus()|;
 
 248   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 249   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 251 <body onLoad="$onload">
 
 253 <form method=post action=$form->{script}>
 
 255 <input type=hidden name=title value="$form->{title}">
 
 259     <th class=listtop>$form->{title}</th>
 
 268   if ($form->{report} eq "projects") {
 
 271           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 272           <td colspan=5><input name=projectnumber size=25</td>
 
 274         <input type=hidden name=nextsub value=generate_projects>
 
 276           <th align=right>| . $locale->text('From') . qq|</th>
 
 279           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 290           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 291           <td><input name=l_heading class=checkbox type=checkbox value=Y> |
 
 292       . $locale->text('Heading') . qq|
 
 293           <input name=l_subtotal class=checkbox type=checkbox value=Y> |
 
 294       . $locale->text('Subtotal') . qq|</td>
 
 301   if ($form->{report} eq "income_statement") {
 
 304           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 305           <td colspan=3>$projectnumber</td>
 
 307         <input type=hidden name=nextsub value=generate_income_statement>
 
 311           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
 
 312       . $locale->text('Customized Report') . qq|</th>
 
 315           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 316           <td><input name=year size=11 title="|
 
 317       . $locale->text('YYYY') . qq|" value="$year"></td>
 
 324 <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 325                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 326                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 329                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 331                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
 
 332       . $locale->text('Quarter') . qq|</td>
 
 336                 <td><input name=duetyp class=radio type=radio value="1" $checked > |
 
 337       . $locale->text('January') . qq|</td>
 
 341                 <td><input name=duetyp class=radio type=radio value="5" $checked > |
 
 342       . $locale->text('May') . qq|</td>
 
 343                 <td><input name=duetyp class=radio type=radio value="9" $checked > |
 
 344       . $locale->text('September') . qq|</td>
 
 348                 <td align= right> </td>
 
 349                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
 
 350       . $locale->text('Quarter') . qq|</td>
 
 351                 <td><input name=duetyp class=radio type=radio value="2" $checked > |
 
 352       . $locale->text('February') . qq|</td>
 
 353                 <td><input name=duetyp class=radio type=radio value="6" $checked > |
 
 354       . $locale->text('June') . qq|</td>
 
 355                 <td><input name=duetyp class=radio type=radio value="10" $checked > |
 
 356       . $locale->text('October') . qq|</td>
 
 360                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
 
 361       . $locale->text('Quarter') . qq|</td>
 
 362                 <td><input name=duetyp class=radio type=radio value="3" $checked > |
 
 363       . $locale->text('March') . qq|</td>
 
 364                 <td><input name=duetyp class=radio type=radio value="7" $checked > |
 
 365       . $locale->text('July') . qq|</td>
 
 366                 <td><input name=duetyp class=radio type=radio value="11" $checked > |
 
 367       . $locale->text('November') . qq|</td>
 
 372                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
 
 373       . $locale->text('Quarter') . qq| </td>
 
 374                 <td><input name=duetyp class=radio type=radio value="4" $checked > |
 
 375       . $locale->text('April') . qq|</td>
 
 376                 <td><input name=duetyp class=radio type=radio value="8" $checked > |
 
 377       . $locale->text('August') . qq|</td>
 
 378                 <td><input name=duetyp class=radio type=radio value="12" $checked > |
 
 379       . $locale->text('December') . qq|</td>
 
 383                 <td colspan=5><hr size=3 noshade></td>
 
 386           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
 
 387       . $locale->text('Free report period') . qq|</th>
 
 388           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 391               | . $locale->text('Bis') . qq|
 
 397                 <td colspan=5><hr size=3 noshade></td>
 
 400           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 401           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 402       . $locale->text('Accrual') . qq|
 
 403            <input name=method class=radio type=radio value=cash $cash>|
 
 404       . $locale->text('EUR') . qq|</td>
 
 411   if ($form->{report} eq "bwa") {
 
 414           <th align=right nowrap>| . $locale->text('Project') . qq|</th>
 
 415           <td colspan=3>$projectnumber</td>
 
 417         <input type=hidden name=nextsub value=generate_bwa>
 
 421           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
 
 422       . $locale->text('Customized Report') . qq|</th>
 
 425           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 426           <td><input name=year size=11 title="|
 
 427       . $locale->text('YYYY') . qq|" value="$year"></td>
 
 434 <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 435                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 436                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 439                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 441                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
 
 442       . $locale->text('Quarter') . qq|</td>
 
 444     $checked = "checked";
 
 446                 <td><input name=duetyp class=radio type=radio value="1" $checked > |
 
 447       . $locale->text('January') . qq|</td>
 
 451                 <td><input name=duetyp class=radio type=radio value="5" $checked > |
 
 452       . $locale->text('May') . qq|</td>
 
 453                 <td><input name=duetyp class=radio type=radio value="9" $checked > |
 
 454       . $locale->text('September') . qq|</td>
 
 458                 <td align= right> </td>
 
 459                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
 
 460       . $locale->text('Quarter') . qq|</td>
 
 461                 <td><input name=duetyp class=radio type=radio value="2" $checked > |
 
 462       . $locale->text('February') . qq|</td>
 
 463                 <td><input name=duetyp class=radio type=radio value="6" $checked > |
 
 464       . $locale->text('June') . qq|</td>
 
 465                 <td><input name=duetyp class=radio type=radio value="10" $checked > |
 
 466       . $locale->text('October') . qq|</td>
 
 470                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
 
 471       . $locale->text('Quarter') . qq|</td>
 
 472                 <td><input name=duetyp class=radio type=radio value="3" $checked > |
 
 473       . $locale->text('March') . qq|</td>
 
 474                 <td><input name=duetyp class=radio type=radio value="7" $checked > |
 
 475       . $locale->text('July') . qq|</td>
 
 476                 <td><input name=duetyp class=radio type=radio value="11" $checked > |
 
 477       . $locale->text('November') . qq|</td>
 
 482                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
 
 483       . $locale->text('Quarter') . qq| </td>
 
 484                 <td><input name=duetyp class=radio type=radio value="4" $checked > |
 
 485       . $locale->text('April') . qq|</td>
 
 486                 <td><input name=duetyp class=radio type=radio value="8" $checked > |
 
 487       . $locale->text('August') . qq|</td>
 
 488                 <td><input name=duetyp class=radio type=radio value="12" $checked > |
 
 489       . $locale->text('December') . qq|</td>
 
 493                 <td colspan=5><hr size=3 noshade></td>
 
 496           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
 
 497       . $locale->text('Free report period') . qq|</th>
 
 498           <td align=left colspan=4>| . $locale->text('From') . qq| 
 
 501               | . $locale->text('Bis') . qq| 
 
 507                 <td colspan=5><hr size=3 noshade></td>
 
 510           <th align=leftt>| . $locale->text('Method') . qq|</th>
 
 511           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 512       . $locale->text('Accrual') . qq|
 
 513            <input name=method class=radio type=radio value=cash $cash>|
 
 514       . $locale->text('EUR') . qq|</td>
 
 517          <th align=right colspan=4>|
 
 518       . $locale->text('Decimalplaces')
 
 520              <td><input name=decimalplaces size=3 value="2"></td>
 
 527   if ($form->{report} eq "ustva") {
 
 532         <input type=hidden name=nextsub value=generate_ustva>
 
 536           <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
 
 537       . $locale->text('Zeitraum') . qq|</th>
 
 540           <th colspan=1>| . $locale->text('Year') . qq|</th>
 
 541           <td><input name=year size=11 title="|
 
 542       . $locale->text('YYYY') . qq|" value="$year"></td>
 
 549 <b> | . $locale->text('Yearly') . qq|</b> </td>
 
 550                 <th align=left>| . $locale->text('Quarterly') . qq|</th>
 
 551                 <th align=left colspan=3>| . $locale->text('Monthly') . qq|</th>
 
 554                 <td align=right>  <input name=duetyp class=radio type=radio value="13"
 
 556                 <td><input name=duetyp class=radio type=radio value="A" $checked > 1. |
 
 557       . $locale->text('Quarter') . qq|</td>
 
 559     $checked = "checked";
 
 561                 <td><input name=duetyp class=radio type=radio value="1" $checked > |
 
 562       . $locale->text('January') . qq|</td>
 
 566                 <td><input name=duetyp class=radio type=radio value="5" $checked > |
 
 567       . $locale->text('May') . qq|</td>
 
 568                 <td><input name=duetyp class=radio type=radio value="9" $checked > |
 
 569       . $locale->text('September') . qq|</td>
 
 573                 <td align= right> </td>
 
 574                 <td><input name=duetyp class=radio type=radio value="B" $checked> 2. |
 
 575       . $locale->text('Quarter') . qq|</td>
 
 576                 <td><input name=duetyp class=radio type=radio value="2" $checked > |
 
 577       . $locale->text('February') . qq|</td>
 
 578                 <td><input name=duetyp class=radio type=radio value="6" $checked > |
 
 579       . $locale->text('June') . qq|</td>
 
 580                 <td><input name=duetyp class=radio type=radio value="10" $checked > |
 
 581       . $locale->text('October') . qq|</td>
 
 585                 <td><input name=duetyp class=radio type=radio value="C" $checked> 3. |
 
 586       . $locale->text('Quarter') . qq|</td>
 
 587                 <td><input name=duetyp class=radio type=radio value="3" $checked > |
 
 588       . $locale->text('March') . qq|</td>
 
 589                 <td><input name=duetyp class=radio type=radio value="7" $checked > |
 
 590       . $locale->text('July') . qq|</td>
 
 591                 <td><input name=duetyp class=radio type=radio value="11" $checked > |
 
 592       . $locale->text('November') . qq|</td>
 
 597                 <td><input name=duetyp class=radio type=radio value="D" $checked> 4. |
 
 598       . $locale->text('Quarter') . qq| </td>
 
 599                 <td><input name=duetyp class=radio type=radio value="4" $checked > |
 
 600       . $locale->text('April') . qq|</td>
 
 601                 <td><input name=duetyp class=radio type=radio value="8" $checked > |
 
 602       . $locale->text('August') . qq|</td>
 
 603                 <td><input name=duetyp class=radio type=radio value="12" $checked > |
 
 604       . $locale->text('December') . qq|</td>
 
 608                 <td colspan=5><hr size=3 noshade></td>
 
 611           <th align=left>| . $locale->text('Method') . qq|</th>
 
 612           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 613       . $locale->text('Accrual') . qq|
 
 614            <input name=method class=radio type=radio value=cash $cash>|
 
 615       . $locale->text('EUR') . qq|</td>
 
 628   if ($form->{report} eq "balance_sheet") {
 
 630         <input type=hidden name=nextsub value=generate_balance_sheet>
 
 632           <th align=right>| . $locale->text('as at') . qq|</th>
 
 637           <th align=right nowrap>| . $locale->text('Compare to') . qq|</th>
 
 644           <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
 
 645           <td><input name=decimalplaces size=3 value="2"></td>
 
 654           <th align=right>| . $locale->text('Method') . qq|</th>
 
 655           <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
 
 656       . $locale->text('Accrual') . qq|
 
 657            <input name=method class=radio type=radio value=cash $cash>|
 
 658       . $locale->text('EUR') . qq|</td>
 
 662           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 663           <td><input name=l_heading class=checkbox type=checkbox value=Y> |
 
 664       . $locale->text('Heading') . qq|
 
 665           <input name=l_subtotal class=checkbox type=checkbox value=Y> |
 
 666       . $locale->text('Subtotal') . qq|
 
 667           <input name=l_accno class=checkbox type=checkbox value=Y> |
 
 668       . $locale->text('Account Number') . qq|</td>
 
 675   if ($form->{report} eq "trial_balance") {
 
 677         <input type=hidden name=nextsub value=generate_trial_balance>
 
 678         <input type=hidden name=eur value=$eur>
 
 680           <th align=right>| . $locale->text('From') . qq|</th>
 
 685           <th align=right>| . $locale->text('Bis') . qq|</th>
 
 698           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
 699           <td><input name=l_heading class=checkbox type=checkbox value=Y> |
 
 700       . $locale->text('Heading') . qq|
 
 701           <input name=l_subtotal class=checkbox type=checkbox value=Y> |
 
 702       . $locale->text('Subtotal') . qq|
 
 703           <input name=all_accounts class=checkbox type=checkbox value=Y> |
 
 704       . $locale->text('All Accounts') . qq|</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=hidden name=login value=$form->{login}>
 
 985 <input type=hidden name=password value=$form->{password}>
 
 987 <input type=submit class=submit name=action value="|
 
 988     . $locale->text('Continue') . qq|">
 
 991   # Hier Aufruf von get_config zum Einlesen der Finanzamtdaten
 
 992   USTVA->get_config($userspath, 'finanzamt.ini');
 
 994   $disabled = qq|disabled="disabled"|;
 
 995   $disabled = '' if ($form->{elster} eq '1');
 
 996   if ($form->{report} eq 'ustva') {
 
 998   <input type=submit class=submit name=action value="|
 
 999       . $locale->text('debug') . qq|">
 
1000   <input type=submit class=submit name=action $disabled
 
1001    value="| . $locale->text('winston_export') . qq|">
 
1004    <input type=submit class=submit name=action value="|
 
1005       . $locale->text('config') . qq|">
 
1016   $lxdebug->leave_sub();
 
1019 sub continue { call_sub($form->{"nextsub"}); }
 
1022   $lxdebug->enter_sub();
 
1023   my $nextsub = shift;
 
1025   $form->{project_id} = $form->{project_id_1};
 
1026   if ($form->{projectnumber} && !$form->{project_id}) {
 
1027     $form->{rowcount} = 1;
 
1029     # call this instead of update
 
1030     $form->{update}          = $nextsub;
 
1031     $form->{projectnumber_1} = $form->{projectnumber};
 
1033     delete $form->{sort};
 
1036     # if there is one only, assign id
 
1037     $form->{project_id} = $form->{project_id_1};
 
1040   $lxdebug->leave_sub();
 
1043 sub generate_income_statement {
 
1044   $lxdebug->enter_sub();
 
1046   $form->{padding} = "  ";
 
1047   $form->{bold}    = "<b>";
 
1048   $form->{endbold} = "</b>";
 
1049   $form->{br}      = "<br>";
 
1051   if ($form->{reporttype} eq "custom") {
 
1053     #forgotten the year --> thisyear
 
1054     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
1055       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
1061     if ($form->{duetyp} eq "13") {
 
1062       $form->{fromdate} = "1.1.$form->{year}";
 
1063       $form->{todate}   = "31.12.$form->{year}";
 
1067     if ($form->{duetyp} eq "A") {
 
1068       $form->{fromdate} = "1.1.$form->{year}";
 
1069       $form->{todate}   = "31.3.$form->{year}";
 
1071     if ($form->{duetyp} eq "B") {
 
1072       $form->{fromdate} = "1.4.$form->{year}";
 
1073       $form->{todate}   = "30.6.$form->{year}";
 
1075     if ($form->{duetyp} eq "C") {
 
1076       $form->{fromdate} = "1.7.$form->{year}";
 
1077       $form->{todate}   = "30.9.$form->{year}";
 
1079     if ($form->{duetyp} eq "D") {
 
1080       $form->{fromdate} = "1.10.$form->{year}";
 
1081       $form->{todate}   = "31.12.$form->{year}";
 
1086       $form->{duetyp} eq "1" && do {
 
1087         $form->{fromdate} = "1.1.$form->{year}";
 
1088         $form->{todate}   = "31.1.$form->{year}";
 
1091       $form->{duetyp} eq "2" && do {
 
1092         $form->{fromdate} = "1.2.$form->{year}";
 
1094         #this works from 1901 to 2099, 1900 and 2100 fail.
 
1095         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
1096         $form->{todate} = "$leap.2.$form->{year}";
 
1099       $form->{duetyp} eq "3" && do {
 
1100         $form->{fromdate} = "1.3.$form->{year}";
 
1101         $form->{todate}   = "31.3.$form->{year}";
 
1104       $form->{duetyp} eq "4" && do {
 
1105         $form->{fromdate} = "1.4.$form->{year}";
 
1106         $form->{todate}   = "30.4.$form->{year}";
 
1109       $form->{duetyp} eq "5" && do {
 
1110         $form->{fromdate} = "1.5.$form->{year}";
 
1111         $form->{todate}   = "31.5.$form->{year}";
 
1114       $form->{duetyp} eq "6" && do {
 
1115         $form->{fromdate} = "1.6.$form->{year}";
 
1116         $form->{todate}   = "30.6.$form->{year}";
 
1119       $form->{duetyp} eq "7" && do {
 
1120         $form->{fromdate} = "1.7.$form->{year}";
 
1121         $form->{todate}   = "31.7.$form->{year}";
 
1124       $form->{duetyp} eq "8" && do {
 
1125         $form->{fromdate} = "1.8.$form->{year}";
 
1126         $form->{todate}   = "31.8.$form->{year}";
 
1129       $form->{duetyp} eq "9" && do {
 
1130         $form->{fromdate} = "1.9.$form->{year}";
 
1131         $form->{todate}   = "30.9.$form->{year}";
 
1134       $form->{duetyp} eq "10" && do {
 
1135         $form->{fromdate} = "1.10.$form->{year}";
 
1136         $form->{todate}   = "31.10.$form->{year}";
 
1139       $form->{duetyp} eq "11" && do {
 
1140         $form->{fromdate} = "1.11.$form->{year}";
 
1141         $form->{todate}   = "30.11.$form->{year}";
 
1144       $form->{duetyp} eq "12" && do {
 
1145         $form->{fromdate} = "1.12.$form->{year}";
 
1146         $form->{todate}   = "31.12.$form->{year}";
 
1152   RP->income_statement(\%myconfig, \%$form);
 
1154   ($form->{department}) = split /--/, $form->{department};
 
1157     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1158   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
1160   # if there are any dates construct a where
 
1161   if ($form->{fromdate} || $form->{todate}) {
 
1163     unless ($form->{todate}) {
 
1164       $form->{todate} = $form->current_date(\%myconfig);
 
1167     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
 
1168     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
 
1170     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1171     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
 
1173     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
1175         $locale->text('for Period')
 
1176       . qq|\n$longfromdate |
 
1177       . $locale->text('Bis')
 
1181   if ($form->{comparefromdate} || $form->{comparetodate}) {
 
1182     $longcomparefromdate =
 
1183       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
 
1184     $shortcomparefromdate =
 
1185       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
 
1187     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
 
1188     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
 
1190     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
 
1192         "\n$longcomparefromdate "
 
1193       . $locale->text('Bis')
 
1194       . qq| $longcomparetodate|;
 
1197   # setup variables for the form
 
1198   @a = qw(company address businessnumber);
 
1199   map { $form->{$_} = $myconfig{$_} } @a;
 
1201   $form->{templates} = $myconfig{templates};
 
1203   $form->{IN} = "income_statement.html";
 
1205   $form->parse_template;
 
1207   $lxdebug->leave_sub();
 
1210 sub generate_balance_sheet {
 
1211   $lxdebug->enter_sub();
 
1213   $form->{padding} = "  ";
 
1214   $form->{bold}    = "<b>";
 
1215   $form->{endbold} = "</b>";
 
1216   $form->{br}      = "<br>";
 
1218   RP->balance_sheet(\%myconfig, \%$form);
 
1220   $form->{asofdate} = $form->current_date(\%myconfig) unless $form->{asofdate};
 
1222     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1224   ($form->{department}) = split /--/, $form->{department};
 
1226   # define Current Earnings account
 
1227   $padding = ($form->{l_heading}) ? $form->{padding} : "";
 
1228   push(@{ $form->{equity_account} },
 
1229        $padding . $locale->text('Current Earnings'));
 
1231   $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
 
1232   $form->{last_period} =
 
1233     $locale->date(\%myconfig, $form->{compareasofdate}, 0);
 
1235   $form->{IN} = "balance_sheet.html";
 
1237   # setup company variables for the form
 
1238   map { $form->{$_} = $myconfig{$_};
 
1239         $form->{$_} =~ s/\\n/\n/g; }
 
1240     (qw(company address businessnumber nativecurr));
 
1242   $form->{templates} = $myconfig{templates};
 
1244   $form->parse_template;
 
1246   $lxdebug->leave_sub();
 
1249 sub generate_projects {
 
1250   $lxdebug->enter_sub();
 
1252   &get_project(generate_projects);
 
1253   $form->{projectnumber} = $form->{projectnumber_1};
 
1255   $form->{nextsub} = "generate_projects";
 
1256   $form->{title}   = $locale->text('Project Transactions');
 
1257   RP->trial_balance(\%myconfig, \%$form);
 
1261   $lxdebug->leave_sub();
 
1267 # included links to display transactions for period entered
 
1268 # added headers and subtotals
 
1270 sub generate_trial_balance {
 
1271   $lxdebug->enter_sub();
 
1273   # get for each account initial balance, debits and credits
 
1274   RP->trial_balance(\%myconfig, \%$form);
 
1276   $form->{nextsub} = "generate_trial_balance";
 
1277   $form->{title}   = $locale->text('Trial Balance');
 
1280   $lxdebug->leave_sub();
 
1284   $lxdebug->enter_sub();
 
1286   $title = $form->escape($form->{title});
 
1288   if ($form->{department}) {
 
1289     ($department) = split /--/, $form->{department};
 
1290     $options    = $locale->text('Department') . " : $department<br>";
 
1291     $department = $form->escape($form->{department});
 
1293   if ($form->{projectnumber}) {
 
1295       $locale->text('Project Number') . " : $form->{projectnumber}<br>";
 
1296     $projectnumber = $form->escape($form->{projectnumber});
 
1299   # if there are any dates
 
1300   if ($form->{fromdate} || $form->{todate}) {
 
1301     if ($form->{fromdate}) {
 
1302       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
1304     if ($form->{todate}) {
 
1305       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
 
1308     $form->{period} = "$fromdate - $todate";
 
1311       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
1314   $options .= $form->{period};
 
1316   @column_index = qw(accno description begbalance debit credit endbalance);
 
1318   $column_header{accno} =
 
1319     qq|<th class=listheading>| . $locale->text('Account') . qq|</th>|;
 
1320   $column_header{description} =
 
1321     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
 
1322   $column_header{debit} =
 
1323     qq|<th class=listheading>| . $locale->text('Debit') . qq|</th>|;
 
1324   $column_header{credit} =
 
1325     qq|<th class=listheading>| . $locale->text('Credit') . qq|</th>|;
 
1326   $column_header{begbalance} =
 
1327     qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
 
1328   $column_header{endbalance} =
 
1329     qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
 
1338     <th class=listtop>$form->{title}</th>
 
1340   <tr height="5"></tr>
 
1349   map { print "$column_header{$_}\n" } @column_index;
 
1355   # sort the whole thing by account numbers and display
 
1356   foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} }) {
 
1358     $description = $form->escape($ref->{description});
 
1361       qq|ca.pl?action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&eur=$form->{eur}&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}&accno=$ref->{accno}&description=$description|;
 
1363     $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
 
1365     $debit  = ($ref->{debit} != 0) ? $form->format_amount(\%myconfig, $ref->{debit},  2, " ") : " ";
 
1366     $credit = ($ref->{credit} != 0) ? $form->format_amount(\%myconfig, $ref->{credit}, 2, " ") : " ";
 
1368       $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, " ");
 
1370       $form->format_amount(\%myconfig,
 
1371                            ($ref->{balance} + $ref->{amount}) * $ml,
 
1374     #    next if ($ref->{debit} == 0 && $ref->{credit} == 0);
 
1376     if ($ref->{charttype} eq "H" && $subtotal && $form->{l_subtotal}) {
 
1377       map { $column_data{$_} = "<th> </th>" }
 
1378         qw(accno begbalance endbalance);
 
1380       $subtotalbegbalance =
 
1381         $form->format_amount(\%myconfig, $subtotalbegbalance, 2, " ");
 
1382       $subtotalendbalance =
 
1383         $form->format_amount(\%myconfig, $subtotalendbalance, 2, " ");
 
1385         $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
 
1387         $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
 
1389       $column_data{description} = "<th>$subtotaldescription</th>";
 
1390       $column_data{begbalance}  = "<th align=right>$subtotalbegbalance</th>";
 
1391       $column_data{endbalance}  = "<th align=right>$subtotalendbalance</th>";
 
1392       $column_data{debit}       = "<th align=right>$subtotaldebit</th>";
 
1393       $column_data{credit}      = "<th align=right>$subtotalcredit</th>";
 
1396         <tr class=listsubtotal>
 
1398       map { print "$column_data{$_}\n" } @column_index;
 
1405     if ($ref->{charttype} eq "H") {
 
1407       $subtotaldescription = $ref->{description};
 
1408       $subtotaldebit       = $ref->{debit};
 
1409       $subtotalcredit      = $ref->{credit};
 
1410       $subtotalbegbalance  = 0;
 
1411       $subtotalendbalance  = 0;
 
1413       next unless $form->{l_heading};
 
1415       map { $column_data{$_} = "<th> </th>" }
 
1416         qw(accno debit credit begbalance endbalance);
 
1417       $column_data{description} =
 
1418         "<th class=listheading>$ref->{description}</th>";
 
1421     if ($ref->{charttype} eq "A") {
 
1422       $column_data{accno}       = "<td><a href=$href>$ref->{accno}</a></td>";
 
1423       $column_data{description} = "<td>$ref->{description}</td>";
 
1424       $column_data{debit}       = "<td align=right>$debit</td>";
 
1425       $column_data{credit}      = "<td align=right>$credit</td>";
 
1426       $column_data{begbalance}  = "<td align=right>$begbalance</td>";
 
1427       $column_data{endbalance}  = "<td align=right>$endbalance</td>";
 
1429       $totaldebit  += $ref->{debit};
 
1430       $totalcredit += $ref->{credit};
 
1432       $subtotalbegbalance += $ref->{balance} * $ml;
 
1433       $subtotalendbalance += ($ref->{balance} + $ref->{amount}) * $ml;
 
1437     if ($ref->{charttype} eq "H") {
 
1439       <tr class=listheading>
 
1442     if ($ref->{charttype} eq "A") {
 
1446       <tr class=listrow$i>
 
1450     map { print "$column_data{$_}\n" } @column_index;
 
1457   # print last subtotal
 
1458   if ($subtotal && $form->{l_subtotal}) {
 
1459     map { $column_data{$_} = "<th> </th>" }
 
1460       qw(accno begbalance endbalance);
 
1461     $subtotalbegbalance =
 
1462       $form->format_amount(\%myconfig, $subtotalbegbalance, 2, " ");
 
1463     $subtotalendbalance =
 
1464       $form->format_amount(\%myconfig, $subtotalendbalance, 2, " ");
 
1466       $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
 
1468       $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
 
1469     $column_data{description} = "<th>$subdescription</th>";
 
1470     $column_data{begbalance}  = "<th align=right>$subtotalbegbalance</th>";
 
1471     $column_data{endbalance}  = "<th align=right>$subtotalendbalance</th>";
 
1472     $column_data{debit}       = "<th align=right>$subtotaldebit</th>";
 
1473     $column_data{credit}      = "<th align=right>$subtotalcredit</th>";
 
1476       <tr class=listsubtotal>
 
1478     map { print "$column_data{$_}\n" } @column_index;
 
1485   $totaldebit  = $form->format_amount(\%myconfig, $totaldebit,  2, " ");
 
1486   $totalcredit = $form->format_amount(\%myconfig, $totalcredit, 2, " ");
 
1488   map { $column_data{$_} = "<th> </th>" }
 
1489     qw(accno description begbalance endbalance);
 
1491   $column_data{debit}  = qq|<th align=right class=listtotal>$totaldebit</th>|;
 
1492   $column_data{credit} = qq|<th align=right class=listtotal>$totalcredit</th>|;
 
1495         <tr class=listtotal>
 
1498   map { print "$column_data{$_}\n" } @column_index;
 
1506     <td><hr size=3 noshade></td>
 
1514   $lxdebug->leave_sub();
 
1517 sub generate_ar_aging {
 
1518   $lxdebug->enter_sub();
 
1521   ($form->{customer}) = split(/--/, $form->{customer});
 
1523   $form->{ct}   = "customer";
 
1524   $form->{arap} = "ar";
 
1526   $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
 
1528   RP->aging(\%myconfig, \%$form);
 
1531   $lxdebug->leave_sub();
 
1534 sub generate_ap_aging {
 
1535   $lxdebug->enter_sub();
 
1538   ($form->{vendor}) = split(/--/, $form->{vendor});
 
1540   $form->{ct}   = "vendor";
 
1541   $form->{arap} = "ap";
 
1543   $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
 
1545   RP->aging(\%myconfig, \%$form);
 
1548   $lxdebug->leave_sub();
 
1551 sub create_aging_subtotal_row {
 
1552   $lxdebug->enter_sub();
 
1554   my ($subtotals, $columns, $periods, $class) = @_;
 
1556   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
1558   foreach (@{ $periods }) {
 
1559     $row->{"c$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
 
1560     $subtotals->{$_}      = 0;
 
1563   $lxdebug->leave_sub();
 
1569   $lxdebug->enter_sub();
 
1571   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1573   my @columns = qw(statement ct invnumber transdate duedate c0 c30 c60 c90);
 
1576     'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
 
1577     'ct'        => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
 
1578     'invnumber' => { 'text' => $locale->text('Invoice'), },
 
1579     'transdate' => { 'text' => $locale->text('Date'), },
 
1580     'duedate'   => { 'text' => $locale->text('Due'), },
 
1581     'c0'        => { 'text' => $locale->text('Current'), },
 
1582     'c30'       => { 'text' => '30', },
 
1583     'c60'       => { 'text' => '60', },
 
1584     'c90'       => { 'text' => '90', },
 
1587   my %column_alignment = ('statement' => 'center',
 
1588                           map { $_ => 'right' } qw(c0 c30 c60 c90));
 
1590   $report->set_options('std_column_visibility' => 1);
 
1591   $report->set_columns(%column_defs);
 
1592   $report->set_column_order(@columns);
 
1594   my @hidden_variables = qw(todate customer vendor arap title ct);
 
1595   $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
 
1599   if ($form->{department}) {
 
1600     my ($department) = split /--/, $form->{department};
 
1601     push @options, $locale->text('Department') . " : $department";
 
1602     $form->{callback} .= "&department=" . E($department);
 
1605   if (($form->{arap} eq 'ar') && $form->{customer}) {
 
1606     push @options, $form->{customer};
 
1609   if (($form->{arap} eq 'ap') && $form->{vendor}) {
 
1610     push @options, $form->{vendor};
 
1613   push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
 
1615   my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
 
1617   $report->set_options('top_info_text'        => join("\n", @options),
 
1618                        'output_format'        => 'HTML',
 
1619                        'title'                => $form->{title},
 
1620                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
1623   my $previous_ctid = 0;
 
1625   my @periods       = qw(0 30 60 90);
 
1626   my %subtotals     = map { $_ => 0 } @periods;
 
1627   my %totals        = map { $_ => 0 } @periods;
 
1629   foreach $ref (@{ $form->{AG} }) {
 
1630     if ($row_idx && ($previous_ctid != $ref->{ctid})) {
 
1631       $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
 
1634     foreach my $key (@periods) {
 
1635       $subtotals{$key}  += $ref->{"c${key}"};
 
1636       $totals{$key}     += $ref->{"c${key}"};
 
1637       $ref->{"c${key}"}  = $ref->{"c${key}"} != 0 ? $form->format_amount(\%myconfig, $ref->{"c${key}"}, 2) : '';
 
1642     foreach my $column (@columns) {
 
1644         'data'   => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
 
1645         'align'  => $column_alignment{$column},
 
1646         'valign' => $column eq 'statement' ? 'center' : '',
 
1650     $row->{invnumber}->{link} =  build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
 
1652     if ($previous_ctid != $ref->{ctid}) {
 
1653       $row->{statement}->{raw_data} =
 
1654           $cgi->hidden('-name' => "customer_id_${row_idx}", '-value' => $ref->{ctid})
 
1655         . $cgi->checkbox('-name' => "statement_${row_idx}", '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
 
1656       $row->{ct}->{data} = $ref->{name};
 
1661     $previous_ctid = $ref->{ctid};
 
1663     $report->add_data($row);
 
1666   $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
 
1668   $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
 
1670   if ($form->{arap} eq 'ar') {
 
1671     $raw_top_info_text    = $form->parse_html_template('rp/aging_ar_top');
 
1672     $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
 
1673                                                                                'PRINT_OPTIONS' => print_options(1), });
 
1674     $report->set_options('raw_top_info_text'    => $raw_top_info_text,
 
1675                          'raw_bottom_info_text' => $raw_bottom_info_text);
 
1678   $report->set_options_from_form();
 
1680   $report->generate_with_headers();
 
1682   $lxdebug->leave_sub();
 
1686   $lxdebug->enter_sub();
 
1688   RP->aging(\%myconfig, \%$form);
 
1690   map { $_->{checked} = "checked" } @{ $form->{AG} };
 
1694   $lxdebug->leave_sub();
 
1698   $lxdebug->enter_sub();
 
1700   # get name and email addresses
 
1701   for $i (1 .. $form->{rowcount}) {
 
1702     if ($form->{"statement_$i"}) {
 
1703       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
 
1704       RP->get_customer(\%myconfig, \%$form);
 
1710   $form->error($locale->text('Nothing selected!')) unless $selected;
 
1712   if ($myconfig{role} eq 'admin') {
 
1714           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
 
1715           <td><input name=bcc size=30 value="$form->{bcc}"></td>
 
1719   $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
 
1721   $form->{media} = "email";
 
1728 <form method=post action=$form->{script}>
 
1734   <tr height="5"></tr>
 
1739           <th align=right nowrap>| . $locale->text('E-mail') . qq|</th>
 
1740           <td><input name=email size=30 value="$form->{email}"></td>
 
1741           <th align=right nowrap>| . $locale->text('Cc') . qq|</th>
 
1742           <td><input name=cc size=30 value="$form->{cc}"></td>
 
1745           <th align=right nowrap>| . $locale->text('Subject') . qq|</th>
 
1746           <td><input name=subject size=30 value="$form->{subject}"></td>
 
1756           <th align=left nowrap>| . $locale->text('Message') . qq|</th>
 
1759           <td><textarea name=message rows=15 cols=60 wrap=soft>$form->{message}</textarea></td>
 
1770   map { delete $form->{$_} }
 
1771     qw(action email cc bcc subject message type sendmode format header);
 
1773   # save all other variables
 
1774   foreach $key (keys %$form) {
 
1775     $form->{$key} =~ s/\"/"/g;
 
1776     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1783     <td><hr size=3 noshade></td>
 
1787 <input type=hidden name=nextsub value=send_email>
 
1790 <input name=action class=submit type=submit value="|
 
1791     . $locale->text('Continue') . qq|">
 
1798   $lxdebug->leave_sub();
 
1802   $lxdebug->enter_sub();
 
1804   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
 
1805     unless $form->{subject};
 
1807   RP->aging(\%myconfig, \%$form);
 
1809   $form->{"statement_1"} = 1;
 
1811   $form->{media} = 'email';
 
1814   $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
 
1816   $lxdebug->leave_sub();
 
1820   $lxdebug->enter_sub();
 
1822   if ($form->{media} eq 'printer') {
 
1823     $form->error($locale->text('Select postscript or PDF!'))
 
1824       if ($form->{format} !~ /(postscript|pdf)/);
 
1827   for $i (1 .. $form->{rowcount}) {
 
1828     if ($form->{"statement_$i"}) {
 
1829       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
 
1835   $form->error($locale->text('Nothing selected!')) unless $selected;
 
1837   if ($form->{media} eq 'printer') {
 
1838     $form->{"$form->{ct}_id"} = "";
 
1840     $form->{"statement_1"} = 1;
 
1843   RP->aging(\%myconfig, \%$form);
 
1847   $form->redirect($locale->text('Statements sent to printer!'))
 
1848     if ($form->{media} eq 'printer');
 
1850   $lxdebug->leave_sub();
 
1854   $lxdebug->enter_sub();
 
1858      "ä" => "ae", "ö" => "oe", "ü" => "ue",
 
1859      "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
 
1864   foreach my $key (keys %replacements) {
 
1865     my $new_key = SL::Iconv::convert("ISO-8859-15", $dbcharset, $key);
 
1866     $replacements{$new_key} = $replacements{$key} if $new_key ne $key;
 
1869   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
 
1871   $form->{templates} = "$myconfig{templates}";
 
1873   my $suffix = "html";
 
1874   my $attachment_suffix = "html";
 
1875   if ($form->{format} eq 'postscript') {
 
1876     $form->{postscript} = 1;
 
1878     $attachment_suffix = "ps";
 
1879   } elsif ($form->{format} eq 'pdf') {
 
1882     $attachment_suffix = "pdf";
 
1885   $form->{IN}  = "$form->{type}.$suffix";
 
1887     $form->{media} eq 'email'   ? $sendmail              :
 
1888     $form->{media} eq 'printer' ? "| $myconfig{printer}" : "";
 
1890   # Save $form->{email} because it will be overwritten.
 
1891   $form->{EMAIL_RECIPIENT} = $form->{email};
 
1894   while (@{ $form->{AG} }) {
 
1896     $ref = shift @{ $form->{AG} };
 
1898     if ($ctid != $ref->{ctid}) {
 
1900       $ctid = $ref->{ctid};
 
1903       if ($form->{"statement_$i"}) {
 
1906           (name, street, zipcode, city, country, contact, email,
 
1907            "$form->{ct}phone", "$form->{ct}fax");
 
1908         map { $form->{$_} = $ref->{$_} } @a;
 
1910         $form->{ $form->{ct} } = $form->{name};
 
1911         $form->{"$form->{ct}_id"} = $ref->{ctid};
 
1913         map { $form->{$_} = () } qw(invnumber invdate duedate);
 
1915         foreach $item (qw(c0 c30 c60 c90)) {
 
1916           $form->{$item} = ();
 
1917           $form->{"${item}total"} = 0;
 
1920         &statement_details($ref);
 
1924           if (scalar(@{ $form->{AG} }) > 0) {
 
1926             # one or more left to go
 
1927             if ($ctid == $form->{AG}->[0]->{ctid}) {
 
1928               $ref = shift @{ $form->{AG} };
 
1929               &statement_details($ref);
 
1932               $ref = scalar(@{ $form->{AG} });
 
1938             # set initial ref to 0
 
1945           $form->{"${_}total"} =
 
1946             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
 
1947         } (c0, c30, c60, c90, "");
 
1949         $form->{attachment_filename} = $locale->text("Statement") . "_$form->{todate}.$attachment_suffix";
 
1950         map({ $form->{attachment_filename} =~ s/$_/$replacements{$_}/g; } keys(%replacements));
 
1952         $form->parse_template(\%myconfig, $userspath);
 
1957   # saving the history
 
1958   if(!exists $form->{addition} && $form->{id} ne "") {
 
1959     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
1960         $form->{addition} = "PRINTED";
 
1961         $form->{what_done} = $form->{type};
 
1962         $form->save_history($form->dbconnect(\%myconfig));
 
1964   # /saving the history 
 
1965   $lxdebug->leave_sub();
 
1968 sub statement_details {
 
1969   $lxdebug->enter_sub();
 
1972   push @{ $form->{invnumber} }, $ref->{invnumber};
 
1973   push @{ $form->{invdate} },   $ref->{transdate};
 
1974   push @{ $form->{duedate} },   $ref->{duedate};
 
1976   foreach $item (qw(c0 c30 c60 c90)) {
 
1977     if ($ref->{exchangerate} * 1) {
 
1979         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
 
1981     $form->{"${item}total"} += $ref->{$item};
 
1982     $form->{total}          += $ref->{$item};
 
1983     push @{ $form->{$item} },
 
1984       $form->format_amount(\%myconfig, $ref->{$item}, 2);
 
1987   $lxdebug->leave_sub();
 
1990 sub generate_tax_report {
 
1991   $lxdebug->enter_sub();
 
1993   RP->tax_report(\%myconfig, \%$form);
 
1995   $descvar     = "$form->{accno}_description";
 
1996   $description = $form->escape($form->{$descvar});
 
1997   $ratevar     = "$form->{accno}_rate";
 
1999   $department = $form->escape($form->{department});
 
2003     "$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}";
 
2005   # construct callback
 
2006   $description = $form->escape($form->{$descvar},   1);
 
2007   $department  = $form->escape($form->{department}, 1);
 
2009     "$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}";
 
2011   $title = $form->escape($form->{title});
 
2012   $href .= "&title=$title";
 
2013   $title = $form->escape($form->{title}, 1);
 
2014   $callback .= "&title=$title";
 
2016   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
 
2019     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
 
2021   foreach $item (@columns) {
 
2022     if ($form->{"l_$item"} eq "Y") {
 
2023       push @column_index, $item;
 
2025       # add column to href and callback
 
2026       $callback .= "&l_$item=Y";
 
2027       $href     .= "&l_$item=Y";
 
2031   if ($form->{l_subtotal} eq 'Y') {
 
2032     $callback .= "&l_subtotal=Y";
 
2033     $href     .= "&l_subtotal=Y";
 
2036   if ($form->{department}) {
 
2037     ($department) = split /--/, $form->{department};
 
2038     $option = $locale->text('Department') . " : $department";
 
2041   # if there are any dates
 
2042   if ($form->{fromdate} || $form->{todate}) {
 
2043     if ($form->{fromdate}) {
 
2044       $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
2046     if ($form->{todate}) {
 
2047       $todate = $locale->date(\%myconfig, $form->{todate}, 1);
 
2050     $form->{period} = "$fromdate - $todate";
 
2053       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2056   if ($form->{db} eq 'ar') {
 
2057     $name    = $locale->text('Customer');
 
2061   if ($form->{db} eq 'ap') {
 
2062     $name    = $locale->text('Vendor');
 
2067   $option .= "<br>" if $option;
 
2068   $option .= "$form->{period}";
 
2070   $column_header{id} =
 
2071       qq|<th><a class=listheading href=$href&sort=id>|
 
2072     . $locale->text('ID')
 
2074   $column_header{invnumber} =
 
2075       qq|<th><a class=listheading href=$href&sort=invnumber>|
 
2076     . $locale->text('Invoice')
 
2078   $column_header{transdate} =
 
2079       qq|<th><a class=listheading href=$href&sort=transdate>|
 
2080     . $locale->text('Date')
 
2082   $column_header{netamount} =
 
2083     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
 
2084   $column_header{tax} =
 
2085     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
 
2086   $column_header{amount} =
 
2087     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
 
2089   $column_header{name} =
 
2090     qq|<th><a class=listheading href=$href&sort=name>$name</th>|;
 
2099     <th class=listtop colspan=$colspan>$form->{title}</th>
 
2101   <tr height="5"></tr>
 
2108         <tr class=listheading>
 
2111   map { print "$column_header{$_}\n" } @column_index;
 
2117   # add sort and escape callback
 
2118   $callback = $form->escape($callback . "&sort=$form->{sort}");
 
2120   if (@{ $form->{TR} }) {
 
2121     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
 
2124   foreach $ref (@{ $form->{TR} }) {
 
2126     $module = ($ref->{invoice}) ? $invoice : $arap;
 
2128     if ($form->{l_subtotal} eq 'Y') {
 
2129       if ($sameitem ne $ref->{ $form->{sort} }) {
 
2131         $sameitem = $ref->{ $form->{sort} };
 
2135     $totalnetamount += $ref->{netamount};
 
2136     $totaltax       += $ref->{tax};
 
2137     $ref->{amount} = $ref->{netamount} + $ref->{tax};
 
2139     $subtotalnetamount += $ref->{netamount};
 
2140     $subtotaltax       += $ref->{tax};
 
2143       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, " ");
 
2144     } qw(netamount tax amount);
 
2146     $column_data{id}        = qq|<td>$ref->{id}</td>|;
 
2147     $column_data{invnumber} =
 
2148       qq|<td><a href=$module?action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>|;
 
2149     $column_data{transdate} = qq|<td>$ref->{transdate}</td>|;
 
2150     $column_data{name}      = qq|<td>$ref->{name} </td>|;
 
2152     map { $column_data{$_} = qq|<td align=right>$ref->{$_}</td>| }
 
2153       qw(netamount tax amount);
 
2158         <tr class=listrow$i>
 
2161     map { print "$column_data{$_}\n" } @column_index;
 
2169   if ($form->{l_subtotal} eq 'Y') {
 
2173   map { $column_data{$_} = qq|<th> </th>| } @column_index;
 
2177         <tr class=listtotal>
 
2181     $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, " ");
 
2183     $form->format_amount(\%myconfig, $totalnetamount, 2, " ");
 
2184   $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, " ");
 
2186   $column_data{netamount} =
 
2187     qq|<th class=listtotal align=right>$totalnetamount</th>|;
 
2188   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
 
2189   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
 
2191   map { print "$column_data{$_}\n" } @column_index;
 
2199     <td><hr size=3 noshade></td>
 
2207   $lxdebug->leave_sub();
 
2211   $lxdebug->enter_sub();
 
2213   map { $column_data{$_} = "<td> </td>" } @column_index;
 
2215   $subtotalnetamount =
 
2216     $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ");
 
2217   $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, " ");
 
2219     $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
 
2222   $column_data{netamount} =
 
2223     "<th class=listsubtotal align=right>$subtotalnetamount</th>";
 
2224   $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
 
2225   $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
 
2227   $subtotalnetamount = 0;
 
2231         <tr class=listsubtotal>
 
2233   map { print "\n$column_data{$_}" } @column_index;
 
2239   $lxdebug->leave_sub();
 
2243   $lxdebug->enter_sub();
 
2245   if ($form->{account}) {
 
2246     ($form->{paymentaccounts}) = split /--/, $form->{account};
 
2248   if ($form->{department}) {
 
2249     ($department, $form->{department_id}) = split /--/, $form->{department};
 
2250     $option = $locale->text('Department') . " : $department";
 
2253   RP->payments(\%myconfig, \%$form);
 
2256     $form->sort_columns(qw(transdate reference name paid source memo));
 
2259   $account    = $form->escape($form->{account});
 
2260   $title      = $form->escape($form->{title});
 
2261   $department = $form->escape($form->{department});
 
2262   $form->{paymentaccounts} =~ s/ /%20/g;
 
2263   $reference = $form->escape($form->{reference});
 
2264   $source    = $form->escape($form->{source});
 
2265   $memo      = $form->escape($form->{memo});
 
2268     "$form->{script}?action=list_payments&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&prepayment=$form->{prepayment}&title=$title&account=$account&department=$department&paymentaccounts=$form->{paymentaccounts}&reference=$reference&source=$source&memo=$memo";
 
2270   # construct callback
 
2271   $account    = $form->escape($form->{account},    1);
 
2272   $title      = $form->escape($form->{title},      1);
 
2273   $department = $form->escape($form->{department}, 1);
 
2274   $reference  = $form->escape($form->{reference},  1);
 
2275   $source     = $form->escape($form->{source},     1);
 
2276   $memo       = $form->escape($form->{memo},       1);
 
2279     "$form->{script}?action=list_payments&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&prepayment=$form->{prepayment}&title=$title&account=$account&department=$department&paymentaccounts=$form->{paymentaccounts}&reference=$reference&source=$source&memo=$memo&sort=$form->{sort}";
 
2280   $callback = $form->escape($form->{callback});
 
2282   $column_header{name} =
 
2283       "<th><a class=listheading href=$href&sort=name>"
 
2284     . $locale->text('Description')
 
2286   $column_header{reference} =
 
2287       "<th><a class=listheading href=$href&sort=invnumber>"
 
2288     . $locale->text('Reference')
 
2290   $column_header{transdate} =
 
2291       "<th><a class=listheading href=$href&sort=transdate>"
 
2292     . $locale->text('Date')
 
2294   $column_header{paid} =
 
2295     "<th class=listheading>" . $locale->text('Amount') . "</a></th>";
 
2296   $column_header{source} =
 
2297       "<th><a class=listheading href=$href&sort=source>"
 
2298     . $locale->text('Source')
 
2300   $column_header{memo} =
 
2301       "<th><a class=listheading href=$href&sort=memo>"
 
2302     . $locale->text('Memo')
 
2305   if ($form->{fromdate}) {
 
2306     $option .= "\n<br>" if ($option);
 
2308         $locale->text('From') . " "
 
2309       . $locale->date(\%myconfig, $form->{fromdate}, 1);
 
2311   if ($form->{todate}) {
 
2312     $option .= "\n<br>" if ($option);
 
2314         $locale->text('bis') . " "
 
2315       . $locale->date(\%myconfig, $form->{todate}, 1);
 
2318   @column_index = @columns;
 
2319   $colspan      = $#column_index + 1;
 
2328     <th class=listtop>$form->{title}</th>
 
2330   <tr height="5"></tr>
 
2337         <tr class=listheading>
 
2340   map { print "\n$column_header{$_}" } @column_index;
 
2346   foreach $ref (sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} }) {
 
2348     next unless @{ $form->{ $ref->{id} } };
 
2352           <th colspan=$colspan align=left>$ref->{accno}--$ref->{description}</th>
 
2356     foreach $payment (@{ $form->{ $ref->{id} } }) {
 
2358       $module = $payment->{module};
 
2359       $module = 'is' if ($payment->{invoice} && $payment->{module} eq 'ar');
 
2360       $module = 'ir' if ($payment->{invoice} && $payment->{module} eq 'ap');
 
2363         qq|${module}.pl?action=edit&id=$payment->{id}&login=$form->{login}&password=$form->{password}&callback=$callback|;
 
2365       $column_data{name}      = "<td>$payment->{name} </td>";
 
2366       $column_data{reference} =
 
2367         qq|<td><a href=$href>$payment->{invnumber}</a></td>|;
 
2368       $column_data{transdate} = "<td>$payment->{transdate} </td>";
 
2369       $column_data{paid}      =
 
2371         . $form->format_amount(\%myconfig, $payment->{paid}, 2, " ")
 
2373       $column_data{source} = "<td>$payment->{source} </td>";
 
2374       $column_data{memo}   = "<td>$payment->{memo} </td>";
 
2376       $subtotalpaid += $payment->{paid};
 
2377       $totalpaid    += $payment->{paid};
 
2382         <tr class=listrow$i>
 
2385       map { print "\n$column_data{$_}" } @column_index;
 
2394     map { $column_data{$_} = "<td> </td>" } @column_index;
 
2396     $column_data{paid} =
 
2397       "<th class=listsubtotal align=right>"
 
2398       . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . "</th>";
 
2401         <tr class=listsubtotal>
 
2404     map { print "\n$column_data{$_}" } @column_index;
 
2415   map { $column_data{$_} = "<td> </td>" } @column_index;
 
2417   $column_data{paid} =
 
2418     "<th class=listtotal align=right>"
 
2419     . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . "</th>";
 
2422         <tr class=listtotal>
 
2425   map { print "\n$column_data{$_}" } @column_index;
 
2434     <td><hr size=3 noshade></td>
 
2442   $lxdebug->leave_sub();
 
2446   $lxdebug->enter_sub();
 
2451   $lxdebug->leave_sub();
 
2460 sub winston_export {
 
2461   $lxdebug->enter_sub();
 
2464   $form->{winston} = 1;
 
2466   $lxdebug->leave_sub();
 
2470   $lxdebug->enter_sub();
 
2472   my ($dont_print) = @_;
 
2474   $form->{sendmode} = "attachment";
 
2477     $form->{"format"} ? $form->{"format"} :
 
2478     $myconfig{"template_format"} ? $myconfig{"template_format"} :
 
2482     $form->{"copies"} ? $form->{"copies"} :
 
2483     $myconfig{"copies"} ? $myconfig{"copies"} :
 
2486   $form->{PD}{ $form->{type} }     = "selected";
 
2487   $form->{DF}{ $form->{format} }   = "selected";
 
2488   $form->{OP}{ $form->{media} }    = "selected";
 
2489   $form->{SM}{ $form->{sendmode} } = "selected";
 
2491   if ($form->{report} eq 'ustva') {
 
2493             <option value=ustva $form->{PD}{ustva}>| . $locale->text('ustva');
 
2496             <option value=statement $form->{PD}{statement}>|
 
2497       . $locale->text('Statement');
 
2500   if ($form->{media} eq 'email') {
 
2502             <option value=attachment $form->{SM}{attachment}>|
 
2503       . $locale->text('Attachment') . qq|
 
2504             <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
 
2507             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
 
2508     if ($myconfig{printer} && $latex_templates) {
 
2510             <option value=printer $form->{OP}{printer}>|
 
2511         . $locale->text('Printer');
 
2515   if ($latex_templates) {
 
2517             <option value=html $form->{DF}{html}>|
 
2518       . $locale->text('HTML') . qq|
 
2519             <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
 
2520     if ($form->{report} ne 'ustva') {
 
2522             <option value=postscript $form->{DF}{postscript}>|
 
2523         . $locale->text('Postscript');
 
2530     <td><select name=type>$type</select></td>
 
2531     <td><select name=format>$format</select></td>
 
2532     <td><select name=media>$media</select></td>
 
2535   if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
 
2537       <td>| . $locale->text('Copies') . qq|
 
2538       <input name=copies size=2 value=$form->{copies}></td>
 
2547   print $output unless $dont_print;
 
2549   $lxdebug->leave_sub();
 
2555   $lxdebug->enter_sub();
 
2556   $form->{padding} = "  ";
 
2557   $form->{bold}    = "<b>";
 
2558   $form->{endbold} = "</b>";
 
2559   $form->{br}      = "<br>";
 
2561   if ($form->{reporttype} eq "custom") {
 
2563     #forgotten the year --> thisyear
 
2564     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
2565       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
2571     if ($form->{duetyp} eq "13") {
 
2572       $form->{fromdate}        = "1.1.$form->{year}";
 
2573       $form->{todate}          = "31.12.$form->{year}";
 
2574       $form->{comparefromdate} = "1.01.$form->{year}";
 
2575       $form->{comparetodate}   = "31.12.$form->{year}";
 
2579     if ($form->{duetyp} eq "A") {
 
2580       $form->{fromdate}        = "1.1.$form->{year}";
 
2581       $form->{todate}          = "31.3.$form->{year}";
 
2582       $form->{comparefromdate} = "1.01.$form->{year}";
 
2583       $form->{comparetodate}   = "31.03.$form->{year}";
 
2585     if ($form->{duetyp} eq "B") {
 
2586       $form->{fromdate}        = "1.4.$form->{year}";
 
2587       $form->{todate}          = "30.6.$form->{year}";
 
2588       $form->{comparefromdate} = "1.01.$form->{year}";
 
2589       $form->{comparetodate}   = "30.06.$form->{year}";
 
2591     if ($form->{duetyp} eq "C") {
 
2592       $form->{fromdate}        = "1.7.$form->{year}";
 
2593       $form->{todate}          = "30.9.$form->{year}";
 
2594       $form->{comparefromdate} = "1.01.$form->{year}";
 
2595       $form->{comparetodate}   = "30.09.$form->{year}";
 
2597     if ($form->{duetyp} eq "D") {
 
2598       $form->{fromdate}        = "1.10.$form->{year}";
 
2599       $form->{todate}          = "31.12.$form->{year}";
 
2600       $form->{comparefromdate} = "1.01.$form->{year}";
 
2601       $form->{comparetodate}   = "31.12.$form->{year}";
 
2606       $form->{duetyp} eq "1" && do {
 
2607         $form->{fromdate}        = "1.1.$form->{year}";
 
2608         $form->{todate}          = "31.1.$form->{year}";
 
2609         $form->{comparefromdate} = "1.01.$form->{year}";
 
2610         $form->{comparetodate}   = "31.01.$form->{year}";
 
2613       $form->{duetyp} eq "2" && do {
 
2614         $form->{fromdate} = "1.2.$form->{year}";
 
2616         #this works from 1901 to 2099, 1900 and 2100 fail.
 
2617         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
2618         $form->{todate}          = "$leap.2.$form->{year}";
 
2619         $form->{comparefromdate} = "1.01.$form->{year}";
 
2620         $form->{comparetodate}   = "$leap.02.$form->{year}";
 
2623       $form->{duetyp} eq "3" && do {
 
2624         $form->{fromdate}        = "1.3.$form->{year}";
 
2625         $form->{todate}          = "31.3.$form->{year}";
 
2626         $form->{comparefromdate} = "1.01.$form->{year}";
 
2627         $form->{comparetodate}   = "31.03.$form->{year}";
 
2630       $form->{duetyp} eq "4" && do {
 
2631         $form->{fromdate}        = "1.4.$form->{year}";
 
2632         $form->{todate}          = "30.4.$form->{year}";
 
2633         $form->{comparefromdate} = "1.01.$form->{year}";
 
2634         $form->{comparetodate}   = "30.04.$form->{year}";
 
2637       $form->{duetyp} eq "5" && do {
 
2638         $form->{fromdate}        = "1.5.$form->{year}";
 
2639         $form->{todate}          = "31.5.$form->{year}";
 
2640         $form->{comparefromdate} = "1.01.$form->{year}";
 
2641         $form->{comparetodate}   = "31.05.$form->{year}";
 
2644       $form->{duetyp} eq "6" && do {
 
2645         $form->{fromdate}        = "1.6.$form->{year}";
 
2646         $form->{todate}          = "30.6.$form->{year}";
 
2647         $form->{comparefromdate} = "1.01.$form->{year}";
 
2648         $form->{comparetodate}   = "30.06.$form->{year}";
 
2651       $form->{duetyp} eq "7" && do {
 
2652         $form->{fromdate}        = "1.7.$form->{year}";
 
2653         $form->{todate}          = "31.7.$form->{year}";
 
2654         $form->{comparefromdate} = "1.01.$form->{year}";
 
2655         $form->{comparetodate}   = "31.07.$form->{year}";
 
2658       $form->{duetyp} eq "8" && do {
 
2659         $form->{fromdate}        = "1.8.$form->{year}";
 
2660         $form->{todate}          = "31.8.$form->{year}";
 
2661         $form->{comparefromdate} = "1.01.$form->{year}";
 
2662         $form->{comparetodate}   = "31.08.$form->{year}";
 
2665       $form->{duetyp} eq "9" && do {
 
2666         $form->{fromdate}        = "1.9.$form->{year}";
 
2667         $form->{todate}          = "30.9.$form->{year}";
 
2668         $form->{comparefromdate} = "1.01.$form->{year}";
 
2669         $form->{comparetodate}   = "30.09.$form->{year}";
 
2672       $form->{duetyp} eq "10" && do {
 
2673         $form->{fromdate}        = "1.10.$form->{year}";
 
2674         $form->{todate}          = "31.10.$form->{year}";
 
2675         $form->{comparefromdate} = "1.01.$form->{year}";
 
2676         $form->{comparetodate}   = "31.10.$form->{year}";
 
2679       $form->{duetyp} eq "11" && do {
 
2680         $form->{fromdate}        = "1.11.$form->{year}";
 
2681         $form->{todate}          = "30.11.$form->{year}";
 
2682         $form->{comparefromdate} = "1.01.$form->{year}";
 
2683         $form->{comparetodate}   = "30.11.$form->{year}";
 
2686       $form->{duetyp} eq "12" && do {
 
2687         $form->{fromdate}        = "1.12.$form->{year}";
 
2688         $form->{todate}          = "31.12.$form->{year}";
 
2689         $form->{comparefromdate} = "1.01.$form->{year}";
 
2690         $form->{comparetodate}   = "31.12.$form->{year}";
 
2695     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
 
2696     $form->{fromdate} = "${dd}.${mm}.${yy}";
 
2697     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
 
2698     $form->{todate}          = "${dd}.${mm}.${yy}";
 
2699     $form->{comparefromdate} = "01.01.$yy";
 
2700     $form->{comparetodate}   = $form->{todate};
 
2703   RP->bwa(\%myconfig, \%$form);
 
2705   ($form->{department}) = split /--/, $form->{department};
 
2708     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2709   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
2711   # if there are any dates construct a where
 
2712   if ($form->{fromdate} || $form->{todate}) {
 
2714     unless ($form->{todate}) {
 
2715       $form->{todate} = $form->current_date(\%myconfig);
 
2718     my %germandate = ("dateformat" => "dd.mm.yyyy");
 
2720     $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
 
2721     $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
 
2723     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
 
2724     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
 
2726     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
2728         $locale->text('for Period')
 
2729       . qq|\n$longfromdate |
 
2730       . $locale->text('bis')
 
2734   # setup variables for the form
 
2735   @a = qw(company address businessnumber);
 
2736   map { $form->{$_} = $myconfig{$_} } @a;
 
2737   $form->{templates} = $myconfig{templates};
 
2739   $form->{IN} = "bwa.html";
 
2741   $form->parse_template;
 
2743   $lxdebug->leave_sub();
 
2746 sub generate_ustva {
 
2747   $lxdebug->enter_sub();
 
2749   # Hier Aufruf von get_config zum Einlesen der Finanzamtdaten
 
2750   USTVA->get_config($userspath, 'finanzamt.ini');
 
2752   #  &get_project(generate_bwa);
 
2753   @anmeldungszeitraum =
 
2754     qw(0401, 0402, 0403, 0404, 0405, 0405, 0406, 0407, 0408, 0409, 0410, 0411, 0412, 0441, 0442, 0443, 0444);
 
2756   foreach $item (@anmeldungszeitraum) {
 
2757     $form->{$item} = "";
 
2759   if ($form->{reporttype} eq "custom") {
 
2761     #forgotten the year --> thisyear
 
2762     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
2763       $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
 
2769     if ($form->{duetyp} eq "13") {
 
2770       $form->{fromdate} = "1.1.$form->{year}";
 
2771       $form->{todate}   = "31.12.$form->{year}";
 
2775     if ($form->{duetyp} eq "A") {
 
2776       $form->{fromdate} = "1.1.$form->{year}";
 
2777       $form->{todate}   = "31.3.$form->{year}";
 
2778       $form->{"0441"}   = "X";
 
2780     if ($form->{duetyp} eq "B") {
 
2781       $form->{fromdate} = "1.4.$form->{year}";
 
2782       $form->{todate}   = "30.6.$form->{year}";
 
2783       $form->{"0442"}   = "X";
 
2785     if ($form->{duetyp} eq "C") {
 
2786       $form->{fromdate} = "1.7.$form->{year}";
 
2787       $form->{todate}   = "30.9.$form->{year}";
 
2788       $form->{"0443"}   = "X";
 
2790     if ($form->{duetyp} eq "D") {
 
2791       $form->{fromdate} = "1.10.$form->{year}";
 
2792       $form->{todate}   = "31.12.$form->{year}";
 
2793       $form->{"0444"}   = "X";
 
2798       $form->{duetyp} eq "1" && do {
 
2799         $form->{fromdate} = "1.1.$form->{year}";
 
2800         $form->{todate}   = "31.1.$form->{year}";
 
2801         $form->{"0401"}   = "X";
 
2804       $form->{duetyp} eq "2" && do {
 
2805         $form->{fromdate} = "1.2.$form->{year}";
 
2807         #this works from 1901 to 2099, 1900 and 2100 fail.
 
2808         $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
2809         $form->{todate} = "$leap.2.$form->{year}";
 
2810         $form->{"0402"} = "X";
 
2813       $form->{duetyp} eq "3" && do {
 
2814         $form->{fromdate} = "1.3.$form->{year}";
 
2815         $form->{todate}   = "31.3.$form->{year}";
 
2816         $form->{"0403"}   = "X";
 
2819       $form->{duetyp} eq "4" && do {
 
2820         $form->{fromdate} = "1.4.$form->{year}";
 
2821         $form->{todate}   = "30.4.$form->{year}";
 
2822         $form->{"0404"}   = "X";
 
2825       $form->{duetyp} eq "5" && do {
 
2826         $form->{fromdate} = "1.5.$form->{year}";
 
2827         $form->{todate}   = "31.5.$form->{year}";
 
2828         $form->{"0405"}   = "X";
 
2831       $form->{duetyp} eq "6" && do {
 
2832         $form->{fromdate} = "1.6.$form->{year}";
 
2833         $form->{todate}   = "30.6.$form->{year}";
 
2834         $form->{"0406"}   = "X";
 
2837       $form->{duetyp} eq "7" && do {
 
2838         $form->{fromdate} = "1.7.$form->{year}";
 
2839         $form->{todate}   = "31.7.$form->{year}";
 
2840         $form->{"0407"}   = "X";
 
2843       $form->{duetyp} eq "8" && do {
 
2844         $form->{fromdate} = "1.8.$form->{year}";
 
2845         $form->{todate}   = "31.8.$form->{year}";
 
2846         $form->{"0408"}   = "X";
 
2849       $form->{duetyp} eq "9" && do {
 
2850         $form->{fromdate} = "1.9.$form->{year}";
 
2851         $form->{todate}   = "30.9.$form->{year}";
 
2852         $form->{"0409"}   = "X";
 
2855       $form->{duetyp} eq "10" && do {
 
2856         $form->{fromdate} = "1.10.$form->{year}";
 
2857         $form->{todate}   = "31.10.$form->{year}";
 
2858         $form->{"0410"}   = "X";
 
2861       $form->{duetyp} eq "11" && do {
 
2862         $form->{fromdate} = "1.11.$form->{year}";
 
2863         $form->{todate}   = "30.11.$form->{year}";
 
2864         $form->{"0411"}   = "X";
 
2867       $form->{duetyp} eq "12" && do {
 
2868         $form->{fromdate} = "1.12.$form->{year}";
 
2869         $form->{todate}   = "31.12.$form->{year}";
 
2870         $form->{"0412"}   = "X";
 
2876   #    $locale->date(\%myconfig, $form->current_date(\%myconfig), 0)=~ /(\d\d\d\d)/;
 
2877   #    $form->{year}= $1;
 
2878   #    $form->{fromdate}="1.1.$form->{year}";
 
2879   #    $form->{todate}="31.3.$form->{year}";
 
2880   #    $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2883   RP->ustva(\%myconfig, \%$form);
 
2885   ($form->{department}) = split /--/, $form->{department};
 
2888     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
 
2889   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
2891   # if there are any dates construct a where
 
2892   if ($form->{fromdate} || $form->{todate}) {
 
2894     unless ($form->{todate}) {
 
2895       $form->{todate} = $form->current_date(\%myconfig);
 
2898     $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
 
2899     $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
 
2901     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
 
2902     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
 
2904     $form->{this_period} = "$shortfromdate\n$shorttodate";
 
2906         $locale->text('for Period')
 
2907       . qq|<br>\n$longfromdate |
 
2908       . $locale->text('bis')
 
2912   if ($form->{comparefromdate} || $form->{comparetodate}) {
 
2913     $longcomparefromdate =
 
2914       $locale->date(\%myconfig, $form->{comparefromdate}, 1);
 
2915     $shortcomparefromdate =
 
2916       $locale->date(\%myconfig, $form->{comparefromdate}, 0);
 
2918     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
 
2919     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
 
2921     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
 
2923         "\n$longcomparefromdate "
 
2924       . $locale->text('bis')
 
2925       . qq| $longcomparetodate|;
 
2928   $form->{Datum_heute} =
 
2929     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
 
2931   if (   $form->{format} eq 'pdf'
 
2932       or $form->{format} eq 'postscript') {
 
2933     $form->{padding} = "~~";
 
2934     $form->{bold}    = "\textbf{";
 
2935     $form->{endbold} = "}";
 
2936     $form->{br}      = '\\\\';
 
2938     @numbers = qw(51r 86r 97r 93r 96 43 45
 
2940     foreach $number (@numbers) {
 
2941       $form->{$number} =~ s/,/~~/g;
 
2944       } elsif ($form->{format} eq 'html') {
 
2945     $form->{padding} = "  ";
 
2946     $form->{bold}    = "<b>";
 
2947     $form->{endbold} = "</b>";
 
2948     $form->{br}      = "<br>"
 
2952   # setup variables for the form
 
2953   @a = qw(company address businessnumber);
 
2954   map { $form->{$_} = $myconfig{$_} } @a;
 
2956   $form->{address} =~ s/\\n/$form->{br}/g;
 
2958   if ($form->{winston} eq '1') {
 
2962     $form->{templates} = $myconfig{templates};
 
2963     $form->{IN}        = "$form->{type}";
 
2964     $form->{IN} .= '.tex'
 
2965       if (   $form->{format} eq 'pdf'
 
2966           or $form->{format} eq 'postscript');
 
2967     $form->{IN} .= '.html' if ($form->{format} eq 'html');
 
2969     $form->parse_template(\%myconfig, $userspath);
 
2971     # $form->parse_template;
 
2973   $lxdebug->leave_sub();