1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  16 # This program is free software; you can redistribute it and/or modify
 
  17 # it under the terms of the GNU General Public License as published by
 
  18 # the Free Software Foundation; either version 2 of the License, or
 
  19 # (at your option) any later version.
 
  21 # This program is distributed in the hope that it will be useful,
 
  22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  24 # GNU General Public License for more details.
 
  25 # You should have received a copy of the GNU General Public License
 
  26 # along with this program; if not, write to the Free Software
 
  27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  28 #======================================================================
 
  30 # Accounts Receivables
 
  32 #======================================================================
 
  34 use POSIX qw(strftime);
 
  39 use SL::ReportGenerator;
 
  45 our ($cgi, $form, $lxdebug, $locale, %myconfig);
 
  47 require "bin/mozilla/arap.pl";
 
  48 require "bin/mozilla/common.pl";
 
  49 require "bin/mozilla/drafts.pl";
 
  50 require "bin/mozilla/reportgenerator.pl";
 
  56 # this is for our long dates
 
  57 # $locale->text('January')
 
  58 # $locale->text('February')
 
  59 # $locale->text('March')
 
  60 # $locale->text('April')
 
  61 # $locale->text('May ')
 
  62 # $locale->text('June')
 
  63 # $locale->text('July')
 
  64 # $locale->text('August')
 
  65 # $locale->text('September')
 
  66 # $locale->text('October')
 
  67 # $locale->text('November')
 
  68 # $locale->text('December')
 
  70 # this is for our short month
 
  71 # $locale->text('Jan')
 
  72 # $locale->text('Feb')
 
  73 # $locale->text('Mar')
 
  74 # $locale->text('Apr')
 
  75 # $locale->text('May')
 
  76 # $locale->text('Jun')
 
  77 # $locale->text('Jul')
 
  78 # $locale->text('Aug')
 
  79 # $locale->text('Sep')
 
  80 # $locale->text('Oct')
 
  81 # $locale->text('Nov')
 
  82 # $locale->text('Dec')
 
  85   $lxdebug->enter_sub();
 
  87   return $lxdebug->leave_sub() if (load_draft_maybe());
 
  90   if(!exists $form->{addition} && ($form->{id} ne "")) {
 
  91     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
  92         $form->{addition} = "ADDED";
 
  93         $form->save_history($form->dbconnect(\%myconfig));
 
  97   $form->{title}    = "Add";
 
  99     "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
 
 100     unless $form->{callback};
 
 102   AR->get_transdate(\%myconfig, $form);
 
 103   $form->{initial_transdate} = $form->{transdate};
 
 105   $form->{transdate} = $form->{initial_transdate};
 
 107   $lxdebug->leave_sub();
 
 111   $lxdebug->enter_sub();
 
 112   # show history button
 
 113   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
 114   #/show hhistory button
 
 115   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 116   $form->{title} = "Edit";
 
 121   $lxdebug->leave_sub();
 
 125   $lxdebug->enter_sub();
 
 130   $lxdebug->leave_sub();
 
 134   $lxdebug->enter_sub();
 
 136   my ($duedate, $taxincluded, @curr);
 
 138   $form->create_links("AR", \%myconfig, "customer");
 
 139   $duedate = $form->{duedate};
 
 141   $taxincluded = $form->{taxincluded};
 
 142   my $id = $form->{id};
 
 143   IS->get_customer(\%myconfig, \%$form);
 
 144   $form->{taxincluded} = $taxincluded;
 
 147   $form->{duedate}     = $duedate if $duedate;
 
 148   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
 149   $form->{rowcount}    = 1;
 
 152   $form->{notes} = $form->{intnotes} unless $form->{notes};
 
 155   @curr = split(/:/, $form->{currencies});
 
 157   $form->{defaultcurrency} = $curr[0];
 
 159   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
 162   if (@{ $form->{all_customer} }) {
 
 163     $form->{customer} = "$form->{customer}--$form->{customer_id}";
 
 164     map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
 
 165       (@{ $form->{all_customer} });
 
 169   if (@{ $form->{all_departments} }) {
 
 170     $form->{selectdepartment} = "<option>\n";
 
 171     $form->{department}       = "$form->{department}--$form->{department_id}";
 
 174       $form->{selectdepartment} .=
 
 175         "<option>$_->{description}--$_->{id}\n"
 
 176     } (@{ $form->{all_departments} });
 
 179   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
 182   if (@{ $form->{all_employees} }) {
 
 183     $form->{selectemployee} = "";
 
 184     map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
 
 185       (@{ $form->{all_employees} });
 
 188   # build the popup menus
 
 189   $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
 
 191   AR->setup_form($form);
 
 194     ($form->datetonum($form->{transdate}, \%myconfig) <=
 
 195      $form->datetonum($form->{closedto}, \%myconfig));
 
 197   $lxdebug->leave_sub();
 
 201   $lxdebug->enter_sub();
 
 203   my ($title, $readonly, $exchangerate, $rows);
 
 204   my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
 
 205   my ($jsscript, $button1, $button2, $onload);
 
 206   my ($selectAR_amount, $selectAR_paid, $korrektur_checked, $ARselected, $tax);
 
 207   my (@column_index, %column_data);
 
 210   $title = $form->{title};
 
 211   $form->{title} = $locale->text("$title Accounts Receivables Transaction");
 
 213   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
 215   # $locale->text('Add Accounts Receivables Transaction')
 
 216   # $locale->text('Edit Accounts Receivables Transaction')
 
 217   $form->{javascript} = qq|<script type="text/javascript">
 
 219   function setTaxkey(accno, row) {
 
 220     var taxkey = accno.options[accno.selectedIndex].value;
 
 221     var reg = /--([0-9]*)/;
 
 222     var found = reg.exec(taxkey);
 
 223     var index = found[1];
 
 224     index = parseInt(index);
 
 225     var tax = 'taxchart_' + row;
 
 226     for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
 
 227       var reg2 = new RegExp("^"+ index, "");
 
 228       if (reg2.exec(document.getElementById(tax).options[i].value)) {
 
 229         document.getElementById(tax).options[i].selected = true;
 
 236   # show history button js
 
 237   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
 
 238   #/show history button js
 
 239   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
 240   $readonly = ($form->{id}) ? "readonly" : "";
 
 243     ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
 244   $readonly = ($form->{radier}) ? "" : $readonly;
 
 246   # set option selected
 
 247   foreach my $item (qw(customer currency department employee)) {
 
 248     $form->{"select$item"} =~ s/ selected//;
 
 249     $form->{"select$item"} =~
 
 250       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
 
 253   $form->{exchangerate} = $exchangerate
 
 257                        $form->check_exchangerate(
 
 258                        \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
 
 262   $form->{exchangerate} =
 
 263     $form->format_amount(\%myconfig, $form->{exchangerate});
 
 265   if ($form->{exchangerate} == 0) {
 
 266     $form->{exchangerate} = "";
 
 269   $form->{creditlimit} =
 
 270     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
 
 271   $form->{creditremaining} =
 
 272     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
 275 <input type=hidden name=forex value=$form->{forex}>
 
 277   if ($form->{currency} ne $form->{defaultcurrency}) {
 
 278     if ($form->{forex}) {
 
 280         <th align=right>| . $locale->text('Exchangerate') . qq|</th>
 
 281         <td><input type=hidden name=exchangerate value=$form->{exchangerate}>$form->{exchangerate}</td>
 
 285         <th align=right>| . $locale->text('Exchangerate') . qq|</th>
 
 286         <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
 
 293                 <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
 
 294                 <th align=left nowrap>| . $locale->text('Tax Included') . qq|</th>
 
 298   if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
 
 302     qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
 
 306                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
 
 307                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
 
 308                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
 
 311 | if $form->{selectdepartment};
 
 313   my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
 315   $customer = ($form->{selectcustomer}) 
 
 316     ? qq|<select name="customer" onchange="document.getElementById('update_button').click();">$form->{selectcustomer}</select>| 
 
 317     : qq|<input name=customer value="$form->{customer}" size=35>|;
 
 320                 <input type=hidden name=employee value="$form->{employee}">
 
 323   if ($form->{selectemployee}) {
 
 326                 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
 
 327                 <td  colspan=2><select name=employee>$form->{selectemployee}</select></td>
 
 328                 <input type=hidden name=selectemployee value="$form->{selectemployee}">
 
 333   my @old_project_ids = ();
 
 334   map({ push(@old_project_ids, $form->{"project_id_$_"})
 
 335           if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
 
 337   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
 339                                    "old_id" => \@old_project_ids },
 
 340                    "charts" => { "key" => "ALL_CHARTS",
 
 341                                  "transdate" => $form->{transdate} },
 
 342                    "taxcharts" => "ALL_TAXCHARTS");
 
 344   map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
 
 345       @{ $form->{ALL_CHARTS} });
 
 347   my %project_labels = ();
 
 348   my @project_values = ("");
 
 349   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
 350     push(@project_values, $item->{"id"});
 
 351     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
 
 354   my (%AR_amount_labels, @AR_amount_values);
 
 355   my (%AR_labels, @AR_values);
 
 356   my (%AR_paid_labels, @AR_paid_values);
 
 360   foreach my $item (@{ $form->{ALL_CHARTS} }) {
 
 361     if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) {
 
 362       $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
 
 363       my $key = "$item->{accno}--$item->{tax_id}";
 
 364       push(@AR_amount_values, $key);
 
 365       $AR_amount_labels{$key} =
 
 366         "$item->{accno}--$item->{description}";
 
 368     } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) {
 
 369       push(@AR_values, $item->{accno});
 
 370       $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
 
 372     } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) {
 
 373       push(@AR_paid_values, $item->{accno});
 
 374       $AR_paid_labels{$item->{accno}} =
 
 375         "$item->{accno}--$item->{description}";
 
 378     $charts{$item->{accno}} = $item;
 
 381   my %taxchart_labels = ();
 
 382   my @taxchart_values = ();
 
 384   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
 
 385     my $key = "$item->{id}--$item->{rate}";
 
 386     $taxchart_init = $key if ($taxchart_init eq $item->{id});
 
 387     push(@taxchart_values, $key);
 
 388     $taxchart_labels{$key} =
 
 389       "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
 
 390     $taxcharts{$item->{id}} = $item;
 
 393   $form->{fokus} = "arledger.customer";
 
 395   # use JavaScript Calendar or not
 
 396   $form->{jsscript} = 1;
 
 398   if ($form->{jsscript}) {
 
 400     # with JavaScript Calendar
 
 402        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
 
 403        <td><input type=button name=transdate id="trigger1" value=|
 
 404       . $locale->text('button') . qq|></td>
 
 407        <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>
 
 408        <td><input type=button name=duedate id="trigger2" value=|
 
 409       . $locale->text('button') . qq|></td></td>
 
 414       Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
 
 415                           "duedate", "BL", "trigger2");
 
 418     # without JavaScript Calendar
 
 420       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
 
 422       qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
 
 425   $form->{javascript} .=
 
 426     qq|<script type="text/javascript" src="js/common.js"></script>| .
 
 427     qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
 
 430   $onload = qq|focus()|;
 
 431   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
 432   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
 434 <body onLoad="$onload">
 
 436 <form method=post name="arledger" action=$form->{script}>
 
 438 <input type=hidden name=id value=$form->{id}>
 
 439 <input type=hidden name=sort value=$form->{sort}>
 
 440 <input type=hidden name=closedto value=$form->{closedto}>
 
 441 <input type=hidden name=locked value=$form->{locked}>
 
 442 <input type=hidden name=title value="$title">
 
 444 | . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
 
 448     <th class=listtop>$form->{title}</th>
 
 458                 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
 
 459                 <td colspan=3>$customer <input type="button" value="?" onclick="show_vc_details('customer')"></td>
 
 460                 <input type=hidden name=selectcustomer value="$form->{selectcustomer}">
 
 461                 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
 
 462                 <input type=hidden name=customer_id value="$form->{customer_id}">
 
 463                 <input type=hidden name=terms value=$form->{terms}>
 
 470                       <th align=left nowrap>| . $locale->text('Credit Limit') . qq|</th>
 
 471                       <td>$form->{creditlimit}</td>
 
 472                       <th align=left nowrap>| . $locale->text('Remaining') . qq|</th>
 
 473                       <td class="plus$n">$form->{creditremaining}</td>
 
 474                       <input type=hidden name=creditlimit value=$form->{creditlimit}>
 
 475                       <input type=hidden name=creditremaining value=$form->{creditremaining}>
 
 481                 <th align=right>| . $locale->text('Currency') . qq|</th>
 
 482                 <td><select name=currency>$form->{selectcurrency}</select></td>
 
 483                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
 
 484                 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
 
 485                 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
 
 486                 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
 
 497                 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
 498                 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
 
 501                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
 502                 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
 
 505                 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
 
 509                 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
 
 520   <input type=hidden name=rowcount value=$form->{rowcount}>
 
 524            <tr class=listheading>
 
 525           <th class=listheading style="width:15%">|
 
 526     . $locale->text('Account') . qq|</th>
 
 527           <th class=listheading style="width:10%">|
 
 528     . $locale->text('Amount') . qq|</th>
 
 529           <th class=listheading style="width:10%">|
 
 530     . $locale->text('Tax') . qq|</th>
 
 531           <th class=listheading style="width:5%">|
 
 532     . $locale->text('Korrektur') . qq|</th>
 
 533           <th class=listheading style="width:10%">|
 
 534     . $locale->text('Taxkey') . qq|</th>
 
 535           <th class=listheading style="width:10%">|
 
 536     . $locale->text('Project') . qq|</th>
 
 540   $amount  = $locale->text('Amount');
 
 541   $project = $locale->text('Project');
 
 543   for my $i (1 .. $form->{rowcount}) {
 
 546     $form->{"amount_$i"} =
 
 547       $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
 
 548     $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
 
 550     my $selected_accno_full;
 
 551     my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
 
 552     my $item = $charts{$accno_row};
 
 553     $selected_accno_full = "$item->{accno}--$item->{tax_id}";
 
 555     my $selected_taxchart = $form->{"taxchart_$i"};
 
 556     my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
 
 557     my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
 
 559     if ($previous_accno &&
 
 560         ($previous_accno eq $selected_accno) &&
 
 561         ($previous_tax_id ne $selected_tax_id)) {
 
 562       my $item = $taxcharts{$selected_tax_id};
 
 563       $selected_taxchart = "$item->{id}--$item->{rate}";
 
 566     $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
 
 569       NTI($cgi->popup_menu('-name' => "AR_amount_$i",
 
 570                            '-id' => "AR_amount_$i",
 
 571                            '-style' => 'width:400px',
 
 572                            '-onChange' => "setTaxkey(this, $i)",
 
 573                            '-values' => \@AR_amount_values,
 
 574                            '-labels' => \%AR_amount_labels,
 
 575                            '-default' => $selected_accno_full))
 
 576       . $cgi->hidden('-name' => "previous_AR_amount_$i",
 
 577                      '-default' => $selected_accno_full);
 
 580       NTI($cgi->popup_menu('-name' => "taxchart_$i",
 
 581                            '-id' => "taxchart_$i",
 
 582                            '-style' => 'width:200px',
 
 583                            '-values' => \@taxchart_values,
 
 584                            '-labels' => \%taxchart_labels,
 
 585                            '-default' => $selected_taxchart))
 
 588     $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
 
 591       NTI($cgi->popup_menu('-name' => "project_id_$i",
 
 592                            '-values' => \@project_values,
 
 593                            '-labels' => \%project_labels,
 
 594                            '-default' => $form->{"project_id_$i"} ));
 
 598           <td>$selectAR_amount</td>
 
 599           <td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
 
 600           <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
 
 601           <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
 
 603           <td>$projectnumber</td>
 
 610   $form->{invtotal_unformatted} = $form->{invtotal};
 
 611   $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
 
 614     NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
 
 615                          '-style' => 'width:400px',
 
 616                          '-values' => \@AR_values, '-labels' => \%AR_labels,
 
 617                          '-default' => $form->{ARselected}));
 
 626           <td>${ARselected}</td>
 
 627           <th align=left>$form->{invtotal}</th>
 
 629           <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
 
 630           <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
 
 632           <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
 
 645           <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
 
 646           <td align=left>$notes</td>
 
 654         <tr class=listheading>
 
 655           <th colspan=7 class=listheading>|
 
 656     . $locale->text('Incoming Payments') . qq|</th>
 
 660   if ($form->{currency} eq $form->{defaultcurrency}) {
 
 661     @column_index = qw(datepaid source memo paid AR_paid paid_project_id);
 
 663     @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id);
 
 666   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
 
 667   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
 
 668   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
 
 669   $column_data{AR_paid}      = "<th>" . $locale->text('Account') . "</th>";
 
 670   $column_data{source}       = "<th>" . $locale->text('Source') . "</th>";
 
 671   $column_data{memo}         = "<th>" . $locale->text('Memo') . "</th>"; 
 
 672   $column_data{paid_project_id} = "<th>" . $locale->text('Project Number') . "</th>"; 
 
 677   map { print "$column_data{$_}\n" } @column_index;
 
 685   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
 
 686   for my $i (1 .. $form->{paidaccounts}) {
 
 692       NTI($cgi->popup_menu('-name' => "AR_paid_$i",
 
 693                            '-id' => "AR_paid_$i",
 
 694                            '-values' => \@AR_paid_values,
 
 695                            '-labels' => \%AR_paid_labels,
 
 696                            '-default' => $form->{"AR_paid_$i"}));
 
 698     $totalpaid += $form->{"paid_$i"};
 
 701     if ($form->{"paid_$i"}) {
 
 703         $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
 
 705     $form->{"exchangerate_$i"} =
 
 706       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
 708     if ($form->{"exchangerate_$i"} == 0) {
 
 709       $form->{"exchangerate_$i"} = "";
 
 712     $exchangerate = qq| |;
 
 713     if ($form->{currency} ne $form->{defaultcurrency}) {
 
 714       if ($form->{"forex_$i"}) {
 
 716           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
 
 719           qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
 
 724 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 
 728       qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
 
 729     $column_data{AR_paid} =
 
 730       qq|<td align=center>${selectAR_paid}</td>|;
 
 731     $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
 
 732     $column_data{datepaid}     =
 
 733       qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
 
 734          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
 
 735     $column_data{source} =
 
 736       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
 
 738       qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
 
 740     $column_data{paid_project_id} =
 
 742       . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
 
 743                              '-values' => \@project_values,
 
 744                              '-labels' => \%project_labels,
 
 745                              '-default' => $form->{"paid_project_id_$i"} ))
 
 748     map { print qq|$column_data{$_}\n| } @column_index;
 
 753     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
 
 756   my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
 
 762           <td align="center">| . $locale->text('Total') . qq|</td>
 
 763           <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
 
 768           <td align="center">| . $locale->text('Missing amount') . qq|</td>
 
 769           <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
 
 771 | . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
 
 773 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 
 779     <td><hr size=3 noshade></td>
 
 784   $lxdebug->leave_sub();
 
 788   $lxdebug->enter_sub();
 
 790   my ($transdate, $closedto);
 
 794 <input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
 
 796 <input name=callback type=hidden value="$form->{callback}">
 
 798 <input type=hidden name=login value=$form->{login}>
 
 799 <input type=hidden name=password value=$form->{password}>
 
 801 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
 
 802 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
 
 808   if (!$form->{id} && $form->{draft_id}) {
 
 809     print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
 
 810                              '-value' => 1, '-checked' => $form->{remove_draft},
 
 812           qq| <label for="remove_draft">| .
 
 813           $locale->text("Remove draft when posting") .
 
 817   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
 818   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
 820   print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
 
 822   # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
 
 823   print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
 
 824     if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar'));
 
 827     if ($form->{radier}) {
 
 829         <input class=submit type=submit name=action value="| . $locale->text('Post') .            qq|">
 
 830         <input class=submit type=submit name=action value="| . $locale->text('Delete') .          qq|"> |;
 
 832     if ($transdate > $closedto) {
 
 834         <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
 
 837         <input class=submit type=submit name=action value="| . $locale->text('Post Payment') .    qq|"> |;
 
 840     if ($transdate > $closedto) {
 
 841       print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') .     qq|"> | .
 
 842         NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
 
 846   if ($form->{menubar}) {
 
 847     require "bin/mozilla/menu.pl";
 
 850   # button for saving history
 
 851   if($form->{id} ne "") {
 
 852     print qq| <input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|> |;
 
 854   # /button for saving history
 
 855   # mark_as_paid button 
 
 856   if($form->{id} ne "") {  
 
 857     print qq|<input type="submit" class="submit" name="action" value="| 
 
 858           . $locale->text('mark as paid') . qq|">|;
 
 860   # /mark_as_paid button
 
 869   $lxdebug->leave_sub();
 
 873   $lxdebug->enter_sub();
 
 874   &mark_as_paid_common(\%myconfig,"ar");  
 
 875   $lxdebug->leave_sub();
 
 879   $lxdebug->enter_sub();
 
 883   my ($totaltax, $exchangerate, $totalpaid);
 
 885   $form->{invtotal} = 0;
 
 887   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
 
 888     qw(exchangerate creditlimit creditremaining);
 
 890   my @flds  = qw(amount AR_amount projectnumber oldprojectnumber project_id);
 
 894   for my $i (1 .. $form->{rowcount}) {
 
 895     $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
 
 896     $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
 
 897     if ($form->{"amount_$i"}) {
 
 900       if (!$form->{"korrektur_$i"}) {
 
 901         my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
 
 903           if ($form->{taxincluded}) {
 
 904             $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
 
 906             $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
 
 909           $form->{"tax_$i"} = 0;
 
 912       $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
 
 914       $totaltax += $form->{"tax_$i"};
 
 915       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
 920   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
 
 921   $form->{rowcount} = $count + 1;
 
 922   map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
 
 924   $form->{exchangerate} = $exchangerate
 
 928                        $form->check_exchangerate(
 
 929                        \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
 
 932   $form->{invdate} = $form->{transdate};
 
 933   my $save_AR = $form->{AR};
 
 934   check_name("customer");
 
 935   $form->{AR} = $save_AR;
 
 938     ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
 
 940   for my $i (1 .. $form->{paidaccounts}) {
 
 941     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
 944           $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
 
 945       } qw(paid exchangerate);
 
 947       $totalpaid += $form->{"paid_$i"};
 
 949       $form->{"exchangerate_$i"} = $exchangerate
 
 951             $form->{"forex_$i"} = (
 
 953                    $form->check_exchangerate(
 
 954                    \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
 
 959   $form->{creditremaining} -=
 
 960     ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
 
 961      $form->{oldinvtotal});
 
 962   $form->{oldinvtotal}  = $form->{invtotal};
 
 963   $form->{oldtotalpaid} = $totalpaid;
 
 967   $lxdebug->leave_sub();
 
 971 # ToDO: fix $closedto and $invdate
 
 974   $lxdebug->enter_sub();
 
 976   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
 978   for my $i (1 .. $form->{paidaccounts}) {
 
 980     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
 981       my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
 983       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
 985 #      $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
 
 987       if ($form->{currency} ne $form->{defaultcurrency}) {
 
 988 #        $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
 
 989         $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
 
 994   ($form->{AR})      = split /--/, $form->{AR};
 
 995   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
 
 996   $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
 
 997   $form->error($locale->text('Cannot post payment!'));
 
 999   $lxdebug->leave_sub();
 
1008   $lxdebug->enter_sub();
 
1014   # check if there is an invoice number, invoice and due date
 
1015   $form->isblank("transdate", $locale->text('Invoice Date missing!'));
 
1016   $form->isblank("duedate",   $locale->text('Due Date missing!'));
 
1017   $form->isblank("customer",  $locale->text('Customer missing!'));
 
1019   my $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
1020   my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
 
1021   $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
 
1023   $form->error($locale->text('Zero amount posting!')) 
 
1024     unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
 
1026   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
 
1027     if ($form->{currency} ne $form->{defaultcurrency});
 
1029   delete($form->{AR});
 
1031   for my $i (1 .. $form->{paidaccounts}) {
 
1032     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
 
1033       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
1035       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
1037       $form->error($locale->text('Cannot post payment for a closed period!'))
 
1038         if ($datepaid <= $closedto);
 
1040       if ($form->{currency} ne $form->{defaultcurrency}) {
 
1041         $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
 
1042         $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
 
1047   # if oldcustomer ne customer redo form
 
1048   my ($customer) = split /--/, $form->{customer};
 
1049   if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
 
1054   $form->{AR}{receivables} = $form->{ARselected};
 
1055   $form->{storno}          = 0;
 
1057   $lxdebug->message(0, $form->{amount});
 
1058   $form->{id} = 0 if $form->{postasnew};
 
1059   $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
 
1061   # saving the history
 
1062   if(!exists $form->{addition} && $form->{id} ne "") {
 
1063     $form->{snumbers} = "invnumber_$form->{invnumber}";
 
1064     $form->{addition} = "POSTED";
 
1065     $form->save_history($form->dbconnect(\%myconfig));
 
1067   # /saving the history 
 
1068   remove_draft() if $form->{remove_draft};
 
1070   $form->redirect($locale->text('Transaction posted!')) unless $inline;
 
1072   $lxdebug->leave_sub();
 
1076   $lxdebug->enter_sub();
 
1078   $form->{postasnew} = 1;
 
1079   # saving the history
 
1080   if(!exists $form->{addition} && $form->{id} ne "") {
 
1081     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1082         $form->{addition} = "POSTED AS NEW";
 
1083         $form->save_history($form->dbconnect(\%myconfig));
 
1085   # /saving the history 
 
1088   $lxdebug->leave_sub();
 
1091 sub use_as_template {
 
1092   $lxdebug->enter_sub();
 
1094   map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
 
1095   $form->{paidaccounts} = 1;
 
1096   $form->{rowcount}--;
 
1097   $form->{invdate} = $form->current_date(\%myconfig);
 
1100   $lxdebug->leave_sub();
 
1104   $lxdebug->enter_sub();
 
1106   $form->{title} = $locale->text('Confirm!');
 
1110   delete $form->{header};
 
1115 <form method=post action=$form->{script}>
 
1118   foreach my $key (keys %$form) {
 
1119     $form->{$key} =~ s/\"/"/g;
 
1120     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
 
1124 <h2 class=confirm>$form->{title}</h2>
 
1127     . $locale->text('Are you sure you want to delete Transaction')
 
1128     . qq| $form->{invnumber}</h4>
 
1130 <input name=action class=submit type=submit value="|
 
1131     . $locale->text('Yes') . qq|">
 
1138   $lxdebug->leave_sub();
 
1142   $lxdebug->enter_sub();
 
1143   if (AR->delete_transaction(\%myconfig, \%$form)) {
 
1144     # saving the history
 
1145     if(!exists $form->{addition}) {
 
1146       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
1147           $form->{addition} = "DELETED";
 
1148           $form->save_history($form->dbconnect(\%myconfig));
 
1150     # /saving the history 
 
1151     $form->redirect($locale->text('Transaction deleted!'));
 
1153   $form->error($locale->text('Cannot delete transaction!'));
 
1155   $lxdebug->leave_sub();
 
1159   $lxdebug->enter_sub();
 
1161   my ($customer, $department);
 
1162   my ($jsscript, $button1, $button2, $onload);
 
1164   # setup customer selection
 
1165   $form->all_vc(\%myconfig, "customer", "AR");
 
1167   if (@{ $form->{all_customer} }) {
 
1168     map { $customer .= "<option>$_->{name}--$_->{id}\n" }
 
1169       @{ $form->{all_customer} };
 
1170     $customer = qq|<select name=customer><option>\n$customer</select>|;
 
1172     $customer = qq|<input name=customer size=35>|;
 
1176   if (@{ $form->{all_departments} }) {
 
1177     $form->{selectdepartment} = "<option>\n";
 
1180       $form->{selectdepartment} .=
 
1181         "<option>$_->{description}--$_->{id}\n"
 
1182     } (@{ $form->{all_departments} });
 
1187           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
 
1188           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
 
1190 | if $form->{selectdepartment};
 
1192   $form->{title} = $locale->text('AR Transactions');
 
1194   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
1196   # use JavaScript Calendar or not
 
1197   $form->{jsscript} = 1;
 
1199   if ($form->{jsscript}) {
 
1201     # with JavaScript Calendar
 
1203        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
1204        <input type=button name=transdatefrom id="trigger1" value=|
 
1205       . $locale->text('button') . qq|></td>
 
1208        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
1209        <input type=button name=transdateto name=transdateto id="trigger2" value=|
 
1210       . $locale->text('button') . qq|></td>
 
1215       Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1",
 
1216                           "transdateto", "BL", "trigger2");
 
1219     # without JavaScript Calendar
 
1221                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
1223                               <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
 
1226   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
 
1231   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
 
1232     push(@values, $item->{"id"});
 
1233     $labels{$item->{"id"}} = $item->{"projectnumber"};
 
1236     NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
 
1237                          '-labels' => \%labels));
 
1239   $form->{fokus} = "search.customer";
 
1241   $onload = qq|focus()|;
 
1242   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
1243   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
1245 <body onLoad="$onload">
 
1247 <form method=post name="search" action=$form->{script}>
 
1250   <tr><th class=listtop>$form->{title}</th></tr>
 
1251   <tr height="5"></tr>
 
1256           <th align=right>| . $locale->text('Customer') . qq|</th>
 
1257           <td colspan=3>$customer</td>
 
1261           <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
 
1262           <td colspan=3><input name=invnumber size=20></td>
 
1265           <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 
1266           <td colspan=3><input name=ordnumber size=20></td>
 
1269          <th align=right nowrap>| . $locale->text('Transaction description') . qq|</th>
 
1270          <td colspan=3><input name=transaction_description size=40></td>
 
1273           <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
 
1274           <td colspan=3><input name=notes size=40></td>
 
1277           <th align="right">| . $locale->text("Project Number") . qq|</th>
 
1278           <td colspan="3">$projectnumber</td>
 
1281           <th align=right nowrap>| . $locale->text('From') . qq|</th>
 
1283           <th align=right>| . $locale->text('Bis') . qq|</th>
 
1286         <input type=hidden name=sort value=transdate>
 
1294           <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
 
1298                 <td align=right><input name=open class=checkbox type=checkbox value=Y checked></td>
 
1299                 <td nowrap>| . $locale->text('Open') . qq|</td>
 
1300                 <td align=right><input name=closed class=checkbox type=checkbox value=Y></td>
 
1301                 <td nowrap>| . $locale->text('Closed') . qq|</td>
 
1304                 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
 
1305                 <td nowrap>| . $locale->text('ID') . qq|</td>
 
1306                 <td align=right><input name="l_invnumber" class=checkbox type=checkbox value=Y checked></td>
 
1307                 <td nowrap>| . $locale->text('Invoice Number') . qq|</td>
 
1308                 <td align=right><input name="l_ordnumber" class=checkbox type=checkbox value=Y></td>
 
1309                 <td nowrap>| . $locale->text('Order Number') . qq|</td>
 
1310                 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
 
1311                 <td nowrap>| . $locale->text('Invoice Date') . qq|</td>
 
1314                 <td align=right><input name="l_name" class=checkbox type=checkbox value=Y checked></td>
 
1315                 <td nowrap>| . $locale->text('Customer') . qq|</td>
 
1316                 <td align=right><input name="l_netamount" class=checkbox type=checkbox value=Y></td>
 
1317                 <td nowrap>| . $locale->text('Amount') . qq|</td>
 
1318                 <td align=right><input name="l_tax" class=checkbox type=checkbox value=Y></td>
 
1319                 <td nowrap>| . $locale->text('Tax') . qq|</td>
 
1320                 <td align=right><input name="l_amount" class=checkbox type=checkbox value=Y checked></td>
 
1321                 <td nowrap>| . $locale->text('Total') . qq|</td>
 
1324                 <td align=right><input name="l_datepaid" class=checkbox type=checkbox value=Y></td>
 
1325                 <td nowrap>| . $locale->text('Date Paid') . qq|</td>
 
1326                 <td align=right><input name="l_paid" class=checkbox type=checkbox value=Y checked></td>
 
1327                 <td nowrap>| . $locale->text('Paid') . qq|</td>
 
1328                 <td align=right><input name="l_duedate" class=checkbox type=checkbox value=Y></td>
 
1329                 <td nowrap>| . $locale->text('Due Date') . qq|</td>
 
1330                 <td align=right><input name="l_due" class=checkbox type=checkbox value=Y></td>
 
1331                 <td nowrap>| . $locale->text('Amount Due') . qq|</td>
 
1334                 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
 
1335                 <td nowrap>| . $locale->text('Notes') . qq|</td>
 
1336                 <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
 
1337                 <td nowrap>| . $locale->text('Salesperson') . qq|</td>
 
1338                 <td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
 
1339                 <td nowrap>| . $locale->text('Shipping Point') . qq|</td>
 
1340                 <td align=right><input name="l_shipvia" class=checkbox type=checkbox value=Y></td>
 
1341                 <td nowrap>| . $locale->text('Ship via') . qq|</td>
 
1344                 <td align=right><input name="l_marge_total" class=checkbox type=checkbox value=Y></td><td> |
 
1345     .             $locale->text('Ertrag') . qq|</td>
 
1346                 <td align=right><input name="l_marge_percent" class=checkbox type=checkbox value=Y></td><td> |
 
1347     .             $locale->text('Ertrag prozentual') . qq|</td>
 
1350                 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
 
1351                 <td nowrap>| . $locale->text('Subtotal') . qq|</td>
 
1352                 <td align=right><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y></td>
 
1353                 <td nowrap>| . $locale->text('Project Number') . qq|</td>
 
1354                 <td align=right><input name="l_transaction_description" class=checkbox type=checkbox value=Y></td>
 
1355                 <td nowrap>| . $locale->text('Transaction description') . qq|</td>
 
1364     <td><hr size=3 noshade></td>
 
1368 <input type=hidden name=nextsub value=$form->{nextsub}>
 
1370 <input type=hidden name=login value=$form->{login}>
 
1371 <input type=hidden name=password value=$form->{password}>
 
1374 <input class=submit type=submit name=action value="|
 
1375     . $locale->text('Continue') . qq|">
 
1386   $lxdebug->leave_sub();
 
1389 sub create_subtotal_row {
 
1390   $lxdebug->enter_sub();
 
1392   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
1394   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
1396   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
 
1398   $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
 
1400   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
1402   $lxdebug->leave_sub();
 
1407 sub ar_transactions {
 
1408   $lxdebug->enter_sub();
 
1410   my ($callback, $href, @columns);
 
1412   $form->{customer} = $form->unescape($form->{customer});
 
1413   ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
 
1415   $form->{sort} ||= 'transdate';
 
1417   AR->ar_transactions(\%myconfig, \%$form);
 
1419   $form->{title} = $locale->text('AR Transactions');
 
1421   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
1424     qw(transdate id type invnumber ordnumber name netamount tax amount paid
 
1425        datepaid due duedate transaction_description notes employee shippingpoint shipvia
 
1426        marge_total marge_percent globalprojectnumber);
 
1428   my @hidden_variables = map { "l_${_}" } @columns;
 
1429   push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
 
1431   $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
 
1434     'transdate'               => { 'text' => $locale->text('Date'), },
 
1435     'id'                      => { 'text' => $locale->text('ID'), },
 
1436     'type'                    => { 'text' => $locale->text('Type'), },
 
1437     'invnumber'               => { 'text' => $locale->text('Invoice'), },
 
1438     'ordnumber'               => { 'text' => $locale->text('Order'), },
 
1439     'name'                    => { 'text' => $locale->text('Customer'), },
 
1440     'netamount'               => { 'text' => $locale->text('Amount'), },
 
1441     'tax'                     => { 'text' => $locale->text('Tax'), },
 
1442     'amount'                  => { 'text' => $locale->text('Total'), },
 
1443     'paid'                    => { 'text' => $locale->text('Paid'), },
 
1444     'datepaid'                => { 'text' => $locale->text('Date Paid'), },
 
1445     'due'                     => { 'text' => $locale->text('Amount Due'), },
 
1446     'duedate'                 => { 'text' => $locale->text('Due Date'), },
 
1447     'transaction_description' => { 'text' => $locale->text('Transaction description'), },
 
1448     'notes'                   => { 'text' => $locale->text('Notes'), },
 
1449     'employee'                => { 'text' => $locale->text('Salesperson'), },
 
1450     'shippingpoint'           => { 'text' => $locale->text('Shipping Point'), },
 
1451     'shipvia'                 => { 'text' => $locale->text('Ship via'), },
 
1452     'globalprojectnumber'     => { 'text' => $locale->text('Project Number'), },
 
1453     'marge_total'             => { 'text' => $locale->text('Ertrag'), },
 
1454     'marge_percent'           => { 'text' => $locale->text('Ertrag prozentual'), },
 
1457   foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid
 
1458                        employee shippingpoint shipvia)) {
 
1459     $column_defs{$name}->{link} = $href . "&sort=$name";
 
1462   my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
 
1464   $form->{"l_type"} = "Y";
 
1465   map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
 
1467   $report->set_columns(%column_defs);
 
1468   $report->set_column_order(@columns);
 
1470   $report->set_export_options('ar_transactions', @hidden_variables);
 
1472   $report->set_sort_indicator($form->{sort}, 1);
 
1475   if ($form->{customer}) {
 
1476     push @options, $locale->text('Customer') . " : $form->{customer}";
 
1478   if ($form->{department}) {
 
1479     my ($department) = split /--/, $form->{department};
 
1480     push @options, $locale->text('Department') . " : $department";
 
1482   if ($form->{invnumber}) {
 
1483     push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
 
1485   if ($form->{ordnumber}) {
 
1486     push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
 
1488   if ($form->{notes}) {
 
1489     push @options, $locale->text('Notes') . " : $form->{notes}";
 
1491   if ($form->{transaction_description}) {
 
1492     push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
 
1494   if ($form->{transdatefrom}) {
 
1495     push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
 
1497   if ($form->{transdateto}) {
 
1498     push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
 
1500   if ($form->{open}) {
 
1501     push @options, $locale->text('Open');
 
1503   if ($form->{closed}) {
 
1504     push @options, $locale->text('Closed');
 
1507   $report->set_options('top_info_text'        => join("\n", @options),
 
1508                        'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
 
1509                        'output_format'        => 'HTML',
 
1510                        'title'                => $form->{title},
 
1511                        'attachment_basename'  => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
 
1513   $report->set_options_from_form();
 
1515   # add sort and escape callback, this one we use for the add sub
 
1516   $form->{callback} = $href .= "&sort=$form->{sort}";
 
1518   # escape callback for href
 
1519   $callback = $form->escape($href);
 
1521   my @subtotal_columns = qw(netamount amount paid due marge_total);
 
1523   my %totals    = map { $_ => 0 } @subtotal_columns;
 
1524   my %subtotals = map { $_ => 0 } @subtotal_columns;
 
1528   foreach my $ar (@{ $form->{AR} }) {
 
1529     $ar->{tax} = $ar->{amount} - $ar->{netamount};
 
1530     $ar->{due} = $ar->{amount} - $ar->{paid};
 
1532     map { $subtotals{$_} += $ar->{$_};
 
1533           $totals{$_}    += $ar->{$_} } @subtotal_columns;
 
1535     map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
 
1537     my $is_storno  = $ar->{storno} && !$ar->{storno_id};
 
1538     my $has_storno = $ar->{storno} && $ar->{storno_id};
 
1541       $has_storno       ? $locale->text("Invoice with Storno (abbreviation)") :
 
1542       $is_storno        ? $locale->text("Storno (one letter abbreviation)") :
 
1543       $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
 
1544       $ar->{invoice}    ? $locale->text("Invoice (one letter abbreviation)") :
 
1545                           $locale->text("AR Transaction (abbreviation)");
 
1549     foreach my $column (@columns) {
 
1551         'data'  => $ar->{$column},
 
1552         'align' => $column_alignment{$column},
 
1556     $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
 
1557       . "&id=" . E($ar->{id}) . "&callback=${callback}";
 
1559     my $row_set = [ $row ];
 
1561     if (($form->{l_subtotal} eq 'Y')
 
1562         && (($idx == (scalar @{ $form->{AR} } - 1))
 
1563             || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
 
1564       push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
 
1567     $report->add_data($row_set);
 
1572   $report->add_separator();
 
1573   $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
 
1575   $report->generate_with_headers();
 
1577   $lxdebug->leave_sub();
 
1581   $lxdebug->enter_sub();
 
1583   # don't cancel cancelled transactions
 
1584   if (IS->has_storno(\%myconfig, $form, 'ar')) {
 
1585     $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
 
1586     $form->error($locale->text("Transaction has already been cancelled!"));
 
1589   AR->storno($form, \%myconfig, $form->{id});
 
1591   # saving the history
 
1592   if(!exists $form->{addition} && $form->{id} ne "") {
 
1593     $form->{snumbers} = "ordnumber_$form->{ordnumber}";
 
1594     $form->{addition} = "STORNO";
 
1595     $form->save_history($form->dbconnect(\%myconfig));
 
1597   # /saving the history 
 
1599   $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); 
 
1601   $lxdebug->leave_sub();