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
 
  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 #======================================================================
 
  32 #======================================================================
 
  47 require "bin/mozilla/common.pl";
 
  51 sub add      { call_sub("add_$form->{type}"); }
 
  52 sub delete   { call_sub("delete_$form->{type}"); }
 
  53 sub save     { call_sub("save_$form->{type}"); }
 
  54 sub edit     { call_sub("edit_$form->{type}"); }
 
  55 sub continue { call_sub($form->{"nextsub"}); }
 
  58   $lxdebug->enter_sub();
 
  60   $form->{title}     = "Add";
 
  61   $form->{charttype} = "A";
 
  62   AM->get_account(\%myconfig, \%$form);
 
  65     "$form->{script}?action=list_account&login=$form->{login}&password=$form->{password}"
 
  66     unless $form->{callback};
 
  71   $lxdebug->leave_sub();
 
  75   $lxdebug->enter_sub();
 
  77   $form->{title} = "Edit";
 
  78   AM->get_account(\%myconfig, \%$form);
 
  80   foreach my $item (split(/:/, $form->{link})) {
 
  81     $form->{$item} = "checked";
 
  87   $lxdebug->leave_sub();
 
  91   $lxdebug->enter_sub();
 
  93   if ( $form->{action} eq 'edit_account') {
 
  94     $form->{account_exists} = '1';
 
  97   $form->{title} = $locale->text("$form->{title} Account");
 
  99   $form->{"$form->{charttype}_checked"} = "checked";
 
 100   $form->{"$form->{category}_checked"}  = "checked";
 
 102   $form->{select_tax} = "";
 
 104   my @tax_report_pos = USTVA->report_variables({
 
 105       myconfig   => \%myconfig, 
 
 108       attribute  => 'position',
 
 112   if (@{ $form->{TAXKEY} }) {
 
 113     foreach my $item (@{ $form->{TAXKEY} }) {
 
 114       $item->{rate} = $item->{rate} * 100 . '%';
 
 117     # Fill in empty row for new Taxkey
 
 123       taxdescription => '',
 
 130     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 133     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 135       # Fill in a runningnumber
 
 136       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 138       # Fill in the Taxkeys as select options
 
 139       foreach my $item (@{ $form->{TAXKEY} }) {
 
 140         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 141           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 142             qq|<option value="$item->{id}" selected="selected">|
 
 143             . sprintf("%.2d", $item->{taxkey}) 
 
 144             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 145             . $locale->text('Tax-o-matic Account') 
 
 146             . qq|: $item->{chart_accno}\n|;
 
 149           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 150             qq|<option value="$item->{id}">|
 
 151             . sprintf("%.2d", $item->{taxkey}) 
 
 152             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 153             . $locale->text('Tax-o-matic Account')
 
 154             . qq|: $item->{chart_accno}\n|;
 
 159       # Fill in the USTVA Numbers as select options
 
 160       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 162           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 164         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 165           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 168           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 177   # Newaccount Folgekonto 
 
 178   if (@{ $form->{NEWACCOUNT} }) {
 
 179     if (!$form->{new_chart_valid}) {
 
 180       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 182     foreach $item (@{ $form->{NEWACCOUNT} }) {
 
 183       if ($item->{id} == $form->{new_chart_id}) {
 
 184         $form->{selectnewaccount} .=
 
 185           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 186       } elsif (!$form->{new_chart_valid}) {
 
 187         $form->{selectnewaccount} .=
 
 188           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 194   $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 195   %eur = (1  => "Umsatzerlöse",
 
 196           2  => "sonstige Erlöse",
 
 197           3  => "Privatanteile",
 
 199           5  => "Ausserordentliche Erträge",
 
 200           6  => "Vereinnahmte Umsatzst.",
 
 201           7  => "Umsatzsteuererstattungen",
 
 202           8  => "Wareneingänge",
 
 203           9  => "Löhne und Gehälter",
 
 204           10 => "Gesetzl. sozialer Aufw.",
 
 206           12 => "Gas, Strom, Wasser",
 
 207           13 => "Instandhaltung",
 
 208           14 => "Steuern, Versich., Beiträge",
 
 210           16 => "Kfz-Versicherungen",
 
 211           17 => "Sonst. Fahrtkosten",
 
 212           18 => "Werbe- und Reisekosten",
 
 213           19 => "Instandhaltung u. Werkzeuge",
 
 214           20 => "Fachzeitschriften, Bücher",
 
 215           21 => "Miete für Einrichtungen",
 
 216           22 => "Rechts- und Beratungskosten",
 
 217           23 => "Bürobedarf, Porto, Telefon",
 
 218           24 => "Sonstige Aufwendungen",
 
 219           25 => "Abschreibungen auf Anlagever.",
 
 220           26 => "Abschreibungen auf GWG",
 
 222           28 => "Umsatzsteuerzahlungen",
 
 224           30 => "Ausserordentlicher Aufwand",
 
 225           31 => "Betriebliche Steuern");
 
 226   foreach $item (sort({ $a <=> $b } keys(%eur))) {
 
 227     my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $eur{$item}));
 
 228     if ($item == $form->{pos_eur}) {
 
 229       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 231       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 236   $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 238   %bwapos = (1  => 'Umsatzerlöse',
 
 239              2  => 'Best.Verdg.FE/UE',
 
 240              3  => 'Aktiv.Eigenleistung',
 
 241              4  => 'Mat./Wareneinkauf',
 
 242              5  => 'So.betr.Erlöse',
 
 243              10 => 'Personalkosten',
 
 245              12 => 'Betriebl.Steuern',
 
 246              13 => 'Vers./Beiträge',
 
 247              14 => 'Kfz.Kosten o.St.',
 
 248              15 => 'Werbe-Reisek.',
 
 249              16 => 'Kosten Warenabgabe',
 
 250              17 => 'Abschreibungen',
 
 251              18 => 'Rep./instandhlt.',
 
 252              19 => 'Übrige Steuern',
 
 253              20 => 'Sonst.Kosten',
 
 255              31 => 'Sonst.neutr.Aufw.',
 
 257              33 => 'Sonst.neutr.Ertrag',
 
 258              34 => 'Verr.kalk.Kosten',
 
 259              35 => 'Steuern Eink.u.Ertr.');
 
 260   foreach $item (sort({ $a <=> $b } keys %bwapos)) {
 
 261     my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $bwapos{$item}));
 
 262     if ($item == $form->{pos_bwa}) {
 
 263       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 265       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 270 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 271   $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 272   foreach $item ((1, 2, 3, 4)) {
 
 273     if ($item == $form->{pos_bilanz}) {
 
 274       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 276       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 281   # this is for our parser only! Do not remove.
 
 282   # type=submit $locale->text('Add Account')
 
 283   # type=submit $locale->text('Edit Account')
 
 285   $form->{type} = "account";
 
 287   # preselections category
 
 289   $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 292       'A'  => $locale->text('Asset'),
 
 293       'L'  => $locale->text('Liability'),
 
 294       'Q'  => $locale->text('Equity'),
 
 295       'I'  => $locale->text('Revenue'),      
 
 296       'E'  => $locale->text('Expense'),
 
 297       'C'  => $locale->text('Costs'),
 
 299   foreach $item ( sort({ $a <=> $b } keys %category) ) {
 
 300     if ($item eq $form->{category}) {
 
 301       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 303       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 308   # preselection chart type
 
 309   my $select_charttype = q{};
 
 312       'A'  => $locale->text('Account'),
 
 313       'H'  => $locale->text('Header'),
 
 316   foreach $item ( sort({ $a <=> $b } keys %charttype) ) {
 
 317     if ($item eq $form->{charttype}) {
 
 318       $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
 
 321       $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
 
 326   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 330   my $parameters_ref = {
 
 331     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 332     select_category            => $select_category,
 
 333     select_charttype           => $select_charttype,
 
 334     newaccount                 => $newaccount,
 
 336     select_bwa                 => $select_bwa,
 
 337     select_bilanz              => $select_bilanz,
 
 338     select_eur                 => $select_eur,
 
 341   # Ausgabe des Templates
 
 342   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 345   $lxdebug->leave_sub();
 
 349   $lxdebug->enter_sub();
 
 353 <input name=callback type=hidden value="$form->{callback}">
 
 355 <input type=hidden name=login value=$form->{login}>
 
 356 <input type=hidden name=password value=$form->{password}>
 
 359   if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
 
 361 <input type=submit class=submit name=action value="|
 
 362     . $locale->text('Save') . qq|">
 
 366   if ($form->{id} && $form->{orphaned}) {
 
 367     print qq|<input type=submit class=submit name=action value="|
 
 368       . $locale->text('Delete') . qq|">|;
 
 378   $lxdebug->leave_sub();
 
 382   $lxdebug->enter_sub();
 
 384   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 385   $form->isblank("description", $locale->text('Account Description missing!'));
 
 387   if ($form->{charttype} eq 'A'){
 
 388     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 391   $form->redirect($locale->text('Account saved!'))
 
 392     if (AM->save_account(\%myconfig, \%$form));
 
 393   $form->error($locale->text('Cannot save account!'));
 
 395   $lxdebug->leave_sub();
 
 399   $lxdebug->enter_sub();
 
 401   CA->all_accounts(\%myconfig, \%$form);
 
 403   $form->{title} = $locale->text('Chart of Accounts');
 
 407     "$form->{script}?action=list_account&login=$form->{login}&password=$form->{password}";
 
 412   $callback = $form->escape($callback);
 
 414   foreach $ca (@{ $form->{CA} }) {
 
 419     if ($ca->{amount} > 0) {
 
 420       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 422     if ($ca->{amount} < 0) {
 
 423       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 425     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:''; 
 
 426     $ca->{link_edit_account} = 
 
 427         qq|$form->{script}?action=edit_account&id=$ca->{id}|
 
 428        .qq|&login=$form->{login}|
 
 429        .qq|&password=$form->{password}&callback=$callback|;
 
 433   my $list_account_details_url = 
 
 434               "$form->{script}?login=$form->{login}"
 
 435              ."&password=$form->{password}&action=list_account_details&";
 
 438   my $pjx = new CGI::Ajax('list_account_details' => $list_account_details_url);
 
 440   # Eneable AJAX debuging
 
 444   push(@ { $form->{AJAX} }, $pjx);
 
 446   $form->{stylesheets} = "list_accounts.css";
 
 451   my $parameters_ref = {
 
 452   #   hidden_variables                => $_hidden_variables_ref,
 
 455   # Ausgabe des Templates
 
 456   print($form->parse_html_template2('am/list_accounts', $parameters_ref));
 
 458   $lxdebug->leave_sub();
 
 463 sub list_account_details {
 
 464 # Ajax Funktion aus list_account_details  
 
 465   $lxdebug->enter_sub();
 
 467   my $chart_id = $form->{args};
 
 469   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 471   $form->{title} = $locale->text('Chart of Accounts');
 
 475     "$form->{script}?action=list_account&login=$form->{login}&password=$form->{password}";
 
 480   $callback = $form->escape($callback);
 
 482   foreach $ca (@{ $form->{CA} }) {
 
 484     $ca->{debit}  = " ";
 
 485     $ca->{credit} = " ";
 
 487     if ($ca->{amount} > 0) {
 
 489         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 491     if ($ca->{amount} < 0) {
 
 493         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 496     my @links = split( q{:}, $ca->{link});
 
 500     foreach my $link (@links){
 
 501       $link = ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 502                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 503                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 504                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 505                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 506                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 507                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 508                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 509                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 510                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 511                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 512                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 513                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 514                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 515                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 516 #               : ( $link eq 'CT_tax' )        ? $locale->text('Account Link CT_tax')
 
 517                : $locale->text('Unknown Link') . ': ' . $link;
 
 519       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 522     $ca->{startdate}      =~ s/,/<br>/og;
 
 523     $ca->{tk_ustva}       =~ s/,/<br>/og;
 
 524     $ca->{taxkey}         =~ s/,/<br>/og;
 
 525     $ca->{taxaccount}     =~ s/,/<br>/og;
 
 526     $ca->{taxdescription} =~ s/,/<br>/og;
 
 527     $ca->{datevautomatik} = ($ca->{datevautomatik}) ? $locale->text('On'):$locale->text('Off');
 
 529     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 530                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 531                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 532                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 533                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 534                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 535                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 536                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 538     $ca->{link_edit_account} = 
 
 539         qq|$form->{script}?action=edit_account&id=$ca->{id}|
 
 540        .qq|&login=$form->{login}|
 
 541        .qq|&password=$form->{password}&callback=$callback|;
 
 547   my $parameters_ref = {
 
 550   #   hidden_variables                => $_hidden_variables_ref,
 
 553   # Ausgabe des Templates
 
 555   my $result = $form->parse_html_template('am/list_account_details', $parameters_ref);
 
 558 #  print "chart_id:$chart_id, form->chartid:$form->{chart_id}, rest=$rest";
 
 560   $lxdebug->leave_sub();
 
 565   $lxdebug->enter_sub();
 
 567   $form->{title} = $locale->text('Delete Account');
 
 570     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
 
 572     if ($form->{id} == $form->{$id}) {
 
 573       $form->error($locale->text('Cannot delete default account!'));
 
 577   $form->redirect($locale->text('Account deleted!'))
 
 578     if (AM->delete_account(\%myconfig, \%$form));
 
 579   $form->error($locale->text('Cannot delete account!'));
 
 581   $lxdebug->leave_sub();
 
 585   $lxdebug->enter_sub();
 
 587   $form->{title} = "Add";
 
 591     "$form->{script}?action=add_department&login=$form->{login}&password=$form->{password}"
 
 592     unless $form->{callback};
 
 597   $lxdebug->leave_sub();
 
 600 sub edit_department {
 
 601   $lxdebug->enter_sub();
 
 603   $form->{title} = "Edit";
 
 605   AM->get_department(\%myconfig, \%$form);
 
 610   $lxdebug->leave_sub();
 
 613 sub list_department {
 
 614   $lxdebug->enter_sub();
 
 616   AM->departments(\%myconfig, \%$form);
 
 619     "$form->{script}?action=list_department&login=$form->{login}&password=$form->{password}";
 
 621   $callback = $form->escape($form->{callback});
 
 623   $form->{title} = $locale->text('Departments');
 
 625   @column_index = qw(description cost profit);
 
 627   $column_header{description} =
 
 628       qq|<th class=listheading width=90%>|
 
 629     . $locale->text('Description')
 
 631   $column_header{cost} =
 
 632       qq|<th class=listheading nowrap>|
 
 633     . $locale->text('Cost Center')
 
 635   $column_header{profit} =
 
 636       qq|<th class=listheading nowrap>|
 
 637     . $locale->text('Profit Center')
 
 647     <th class=listtop>$form->{title}</th>
 
 653         <tr class=listheading>
 
 656   map { print "$column_header{$_}\n" } @column_index;
 
 662   foreach $ref (@{ $form->{ALL} }) {
 
 668         <tr valign=top class=listrow$i>
 
 671     $costcenter   = ($ref->{role} eq "C") ? "X" : "";
 
 672     $profitcenter = ($ref->{role} eq "P") ? "X" : "";
 
 674     $column_data{description} =
 
 675       qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
 
 676     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
 
 677     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
 
 679     map { print "$column_data{$_}\n" } @column_index;
 
 691   <td><hr size=3 noshade></td>
 
 696 <form method=post action=$form->{script}>
 
 698 <input name=callback type=hidden value="$form->{callback}">
 
 700 <input type=hidden name=type value=department>
 
 702 <input type=hidden name=login value=$form->{login}>
 
 703 <input type=hidden name=password value=$form->{password}>
 
 705 <input class=submit type=submit name=action value="|
 
 706     . $locale->text('Add') . qq|">
 
 714   $lxdebug->leave_sub();
 
 717 sub department_header {
 
 718   $lxdebug->enter_sub();
 
 720   $form->{title} = $locale->text("$form->{title} Department");
 
 722   # $locale->text('Add Department')
 
 723   # $locale->text('Edit Department')
 
 725   $form->{description} =~ s/\"/"/g;
 
 727   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
 
 729       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
 
 732       qq|<input name=description size=60 value="$form->{description}">|;
 
 735   $costcenter   = "checked" if $form->{role} eq "C";
 
 736   $profitcenter = "checked" if $form->{role} eq "P";
 
 743 <form method=post action=$form->{script}>
 
 745 <input type=hidden name=id value=$form->{id}>
 
 746 <input type=hidden name=type value=department>
 
 750     <th class=listtop colspan=2>$form->{title}</th>
 
 754     <th align=right>| . $locale->text('Description') . qq|</th>
 
 755     <td>$description</td>
 
 759     <td><input type=radio style=radio name=role value="C" $costcenter> |
 
 760     . $locale->text('Cost Center') . qq|
 
 761         <input type=radio style=radio name=role value="P" $profitcenter> |
 
 762     . $locale->text('Profit Center') . qq|
 
 765     <td colspan=2><hr size=3 noshade></td>
 
 770   $lxdebug->leave_sub();
 
 773 sub save_department {
 
 774   $lxdebug->enter_sub();
 
 776   $form->isblank("description", $locale->text('Description missing!'));
 
 777   AM->save_department(\%myconfig, \%$form);
 
 778   $form->redirect($locale->text('Department saved!'));
 
 780   $lxdebug->leave_sub();
 
 783 sub delete_department {
 
 784   $lxdebug->enter_sub();
 
 786   AM->delete_department(\%myconfig, \%$form);
 
 787   $form->redirect($locale->text('Department deleted!'));
 
 789   $lxdebug->leave_sub();
 
 793   $lxdebug->enter_sub();
 
 795   $form->{title} = "Add";
 
 798     "$form->{script}?action=add_lead&login=$form->{login}&password=$form->{password}"
 
 799     unless $form->{callback};
 
 804   $lxdebug->leave_sub();
 
 808   $lxdebug->enter_sub();
 
 810   $form->{title} = "Edit";
 
 812   AM->get_lead(\%myconfig, \%$form);
 
 816   $form->{orphaned} = 1;
 
 819   $lxdebug->leave_sub();
 
 823   $lxdebug->enter_sub();
 
 825   AM->lead(\%myconfig, \%$form);
 
 828     "$form->{script}?action=list_lead&login=$form->{login}&password=$form->{password}";
 
 830   $callback = $form->escape($form->{callback});
 
 832   $form->{title} = $locale->text('Lead');
 
 834   @column_index = qw(description cost profit);
 
 836   $column_header{description} =
 
 837       qq|<th class=listheading width=100%>|
 
 838     . $locale->text('Description')
 
 848     <th class=listtop>$form->{title}</th>
 
 851   <tr class=listheading>
 
 854   map { print "$column_header{$_}\n" } @column_index;
 
 860   foreach $ref (@{ $form->{ALL} }) {
 
 866         <tr valign=top class=listrow$i>
 
 869         $lead = $ref->{lead};
 
 871     $column_data{description} =
 
 872       qq|<td><a href=$form->{script}?action=edit_lead&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{lead}</td>|;
 
 874     map { print "$column_data{$_}\n" } @column_index;
 
 883   <td><hr size=3 noshade></td>
 
 888 <form method=post action=$form->{script}>
 
 890 <input name=callback type=hidden value="$form->{callback}">
 
 892 <input type=hidden name=type value=lead>
 
 894 <input type=hidden name=login value=$form->{login}>
 
 895 <input type=hidden name=password value=$form->{password}>
 
 897 <input class=submit type=submit name=action value="|
 
 898     . $locale->text('Add') . qq|">
 
 906   $lxdebug->leave_sub();
 
 910   $lxdebug->enter_sub();
 
 912   $form->{title} = $locale->text("$form->{title} Lead");
 
 914   # $locale->text('Add Lead')
 
 915   # $locale->text('Edit Lead')
 
 917   $form->{description} =~ s/\"/"/g;
 
 920       qq|<input name=description size=50 value="$form->{lead}">|;
 
 927 <form method=post action=$form->{script}>
 
 929 <input type=hidden name=id value=$form->{id}>
 
 930 <input type=hidden name=type value=lead>
 
 934     <th class=listtop colspan=2>$form->{title}</th>
 
 938     <th align=right>| . $locale->text('Description') . qq|</th>
 
 939     <td>$description</td>
 
 941     <td colspan=2><hr size=3 noshade></td>
 
 946   $lxdebug->leave_sub();
 
 950   $lxdebug->enter_sub();
 
 952   $form->isblank("description", $locale->text('Description missing!'));
 
 953   AM->save_lead(\%myconfig, \%$form);
 
 954   $form->redirect($locale->text('lead saved!'));
 
 956   $lxdebug->leave_sub();
 
 960   $lxdebug->enter_sub();
 
 962   AM->delete_lead(\%myconfig, \%$form);
 
 963   $form->redirect($locale->text('lead deleted!'));
 
 965   $lxdebug->leave_sub();
 
 969   $lxdebug->enter_sub();
 
 971   $form->{title} = "Add";
 
 974     "$form->{script}?action=add_business&login=$form->{login}&password=$form->{password}"
 
 975     unless $form->{callback};
 
 980   $lxdebug->leave_sub();
 
 984   $lxdebug->enter_sub();
 
 986   $form->{title} = "Edit";
 
 988   AM->get_business(\%myconfig, \%$form);
 
 992   $form->{orphaned} = 1;
 
 995   $lxdebug->leave_sub();
 
 999   $lxdebug->enter_sub();
 
1001   AM->business(\%myconfig, \%$form);
 
1004     "$form->{script}?action=list_business&login=$form->{login}&password=$form->{password}";
 
1006   $callback = $form->escape($form->{callback});
 
1008   $form->{title} = $locale->text('Type of Business');
 
1010   @column_index = qw(description discount customernumberinit);
 
1012   $column_header{description} =
 
1013       qq|<th class=listheading width=60%>|
 
1014     . $locale->text('Description')
 
1016   $column_header{discount} =
 
1017       qq|<th class=listheading width=10%>|
 
1018     . $locale->text('Discount')
 
1020   $column_header{customernumberinit} =
 
1021       qq|<th class=listheading>|
 
1022     . $locale->text('Customernumberinit')
 
1032     <th class=listtop>$form->{title}</th>
 
1034   <tr height="5"></tr>
 
1038         <tr class=listheading>
 
1041   map { print "$column_header{$_}\n" } @column_index;
 
1047   foreach $ref (@{ $form->{ALL} }) {
 
1053         <tr valign=top class=listrow$i>
 
1057       $form->format_amount(\%myconfig, $ref->{discount} * 100);
 
1059       $ref->{description};
 
1060     $column_data{description} =
 
1061       qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$description</td>|;
 
1062     $column_data{discount}           = qq|<td align=right>$discount</td>|;
 
1063     $column_data{customernumberinit} =
 
1064       qq|<td align=right>$ref->{customernumberinit}</td>|;
 
1066     map { print "$column_data{$_}\n" } @column_index;
 
1078   <td><hr size=3 noshade></td>
 
1083 <form method=post action=$form->{script}>
 
1085 <input name=callback type=hidden value="$form->{callback}">
 
1087 <input type=hidden name=type value=business>
 
1089 <input type=hidden name=login value=$form->{login}>
 
1090 <input type=hidden name=password value=$form->{password}>
 
1092 <input class=submit type=submit name=action value="|
 
1093     . $locale->text('Add') . qq|">
 
1101   $lxdebug->leave_sub();
 
1104 sub business_header {
 
1105   $lxdebug->enter_sub();
 
1107   $form->{title}    = $locale->text("$form->{title} Business");
 
1109   # $locale->text('Add Business')
 
1110   # $locale->text('Edit Business')
 
1112   $form->{description} =~ s/\"/"/g;
 
1114     $form->format_amount(\%myconfig, $form->{discount} * 100);
 
1121 <form method=post action=$form->{script}>
 
1123 <input type=hidden name=id value=$form->{id}>
 
1124 <input type=hidden name=type value=business>
 
1128     <th class=listtop colspan=2>$form->{title}</th>
 
1130   <tr height="5"></tr>
 
1132     <th align=right>| . $locale->text('Type of Business') . qq|</th>
 
1133     <td><input name=description size=30 value="$form->{description}"></td>
 
1136     <th align=right>| . $locale->text('Discount') . qq| %</th>
 
1137     <td><input name=discount size=5 value=$form->{discount}></td>
 
1140     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
 
1141     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
 
1143   <td colspan=2><hr size=3 noshade></td>
 
1148   $lxdebug->leave_sub();
 
1152   $lxdebug->enter_sub();
 
1154   $form->isblank("description", $locale->text('Description missing!'));
 
1155   $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
 
1156   AM->save_business(\%myconfig, \%$form);
 
1157   $form->redirect($locale->text('Business saved!'));
 
1159   $lxdebug->leave_sub();
 
1162 sub delete_business {
 
1163   $lxdebug->enter_sub();
 
1165   AM->delete_business(\%myconfig, \%$form);
 
1166   $form->redirect($locale->text('Business deleted!'));
 
1168   $lxdebug->leave_sub();
 
1172   $lxdebug->enter_sub();
 
1174   $form->{title} = "Add";
 
1177     "$form->{script}?action=add_language&login=$form->{login}&password=$form->{password}"
 
1178     unless $form->{callback};
 
1183   $lxdebug->leave_sub();
 
1187   $lxdebug->enter_sub();
 
1189   $form->{title} = "Edit";
 
1191   AM->get_language(\%myconfig, \%$form);
 
1195   $form->{orphaned} = 1;
 
1198   $lxdebug->leave_sub();
 
1202   $lxdebug->enter_sub();
 
1204   AM->language(\%myconfig, \%$form);
 
1207     "$form->{script}?action=list_language&login=$form->{login}&password=$form->{password}";
 
1209   $callback = $form->escape($form->{callback});
 
1211   $form->{title} = $locale->text('Languages');
 
1213   @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
 
1215   $column_header{description} =
 
1216       qq|<th class=listheading width=60%>|
 
1217     . $locale->text('Description')
 
1219   $column_header{template_code} =
 
1220       qq|<th class=listheading width=10%>|
 
1221     . $locale->text('Template Code')
 
1223   $column_header{article_code} =
 
1224       qq|<th class=listheading>|
 
1225     . $locale->text('Article Code')
 
1227   $column_header{output_numberformat} =
 
1228       qq|<th class=listheading>|
 
1229     . $locale->text('Number Format')
 
1231   $column_header{output_dateformat} =
 
1232       qq|<th class=listheading>|
 
1233     . $locale->text('Date Format')
 
1235   $column_header{output_longdates} =
 
1236       qq|<th class=listheading>|
 
1237     . $locale->text('Long Dates')
 
1247     <th class=listtop>$form->{title}</th>
 
1249   <tr height="5"></tr>
 
1253         <tr class=listheading>
 
1256   map { print "$column_header{$_}\n" } @column_index;
 
1262   foreach $ref (@{ $form->{ALL} }) {
 
1268         <tr valign=top class=listrow$i>
 
1272     $column_data{description} =
 
1273       qq|<td><a href=$form->{script}?action=edit_language&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
 
1274     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
 
1275     $column_data{article_code} =
 
1276       qq|<td align=right>$ref->{article_code}</td>|;
 
1277     $column_data{output_numberformat} =
 
1279       ($ref->{output_numberformat} ? $ref->{output_numberformat} :
 
1280        $locale->text("use program settings")) .
 
1282     $column_data{output_dateformat} =
 
1284       ($ref->{output_dateformat} ? $ref->{output_dateformat} :
 
1285        $locale->text("use program settings")) .
 
1287     $column_data{output_longdates} =
 
1289       ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
 
1292     map { print "$column_data{$_}\n" } @column_index;
 
1304   <td><hr size=3 noshade></td>
 
1309 <form method=post action=$form->{script}>
 
1311 <input name=callback type=hidden value="$form->{callback}">
 
1313 <input type=hidden name=type value=language>
 
1315 <input type=hidden name=login value=$form->{login}>
 
1316 <input type=hidden name=password value=$form->{password}>
 
1318 <input class=submit type=submit name=action value="|
 
1319     . $locale->text('Add') . qq|">
 
1327   $lxdebug->leave_sub();
 
1330 sub language_header {
 
1331   $lxdebug->enter_sub();
 
1333   $form->{title}    = $locale->text("$form->{title} Language");
 
1335   # $locale->text('Add Language')
 
1336   # $locale->text('Edit Language')
 
1338   $form->{description} =~ s/\"/"/g;
 
1339   $form->{template_code} =~ s/\"/"/g;
 
1340   $form->{article_code} =~ s/\"/"/g;
 
1346     qq|<option value="">| . $locale->text("use program settings") .
 
1348   foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
 
1350       ($item eq $form->{output_numberformat})
 
1351       ? "<option selected>$item"
 
1357     qq|<option value="">| . $locale->text("use program settings") .
 
1359   foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
 
1361       ($item eq $form->{output_dateformat})
 
1362       ? "<option selected>$item"
 
1370 <form method=post action=$form->{script}>
 
1372 <input type=hidden name=id value=$form->{id}>
 
1373 <input type=hidden name=type value=language>
 
1377     <th class=listtop colspan=2>$form->{title}</th>
 
1379   <tr height="5"></tr>
 
1381     <th align=right>| . $locale->text('Language') . qq|</th>
 
1382     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1385     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1386     <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
 
1389     <th align=right>| . $locale->text('Article Code') . qq|</th>
 
1390     <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
 
1393     <th align=right>| . $locale->text('Number Format') . qq|</th>
 
1394     <td><select name="output_numberformat">$numberformat</select></td>
 
1397     <th align=right>| . $locale->text('Date Format') . qq|</th>
 
1398     <td><select name="output_dateformat">$dateformat</select></td>
 
1401     <th align=right>| . $locale->text('Long Dates') . qq|</th>
 
1402     <td><input type="radio" name="output_longdates" value="1"| .
 
1403     ($form->{output_longdates} ? " checked" : "") .
 
1404     qq|>| . $locale->text("Yes") .
 
1405     qq|<input type="radio" name="output_longdates" value="0"| .
 
1406     ($form->{output_longdates} ? "" : " checked") .
 
1407     qq|>| . $locale->text("No") .
 
1410   <td colspan=2><hr size=3 noshade></td>
 
1415   $lxdebug->leave_sub();
 
1419   $lxdebug->enter_sub();
 
1421   $form->isblank("description", $locale->text('Language missing!'));
 
1422   $form->isblank("template_code", $locale->text('Template Code missing!'));
 
1423   $form->isblank("article_code", $locale->text('Article Code missing!'));
 
1424   AM->save_language(\%myconfig, \%$form);
 
1425   $form->redirect($locale->text('Language saved!'));
 
1427   $lxdebug->leave_sub();
 
1430 sub delete_language {
 
1431   $lxdebug->enter_sub();
 
1433   AM->delete_language(\%myconfig, \%$form);
 
1434   $form->redirect($locale->text('Language deleted!'));
 
1436   $lxdebug->leave_sub();
 
1440 sub add_buchungsgruppe {
 
1441   $lxdebug->enter_sub();
 
1443   # $locale->text("Add Buchungsgruppe")
 
1444   # $locale->text("Edit Buchungsgruppe")
 
1445   $form->{title} = "Add";
 
1448     "$form->{script}?action=add_buchungsgruppe&login=$form->{login}&password=$form->{password}"
 
1449     unless $form->{callback};
 
1450   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1451   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
 
1452   for (my $i = 0; 4 > $i; $i++) {
 
1453     map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
 
1454         qw(income expense));
 
1457   &buchungsgruppe_header;
 
1460   $lxdebug->leave_sub();
 
1463 sub edit_buchungsgruppe {
 
1464   $lxdebug->enter_sub();
 
1466   $form->{title} = "Edit";
 
1468   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1470   &buchungsgruppe_header;
 
1474   $lxdebug->leave_sub();
 
1477 sub list_buchungsgruppe {
 
1478   $lxdebug->enter_sub();
 
1480   AM->buchungsgruppe(\%myconfig, \%$form);
 
1483     "$form->{script}?action=list_buchungsgruppe&login=$form->{login}&password=$form->{password}";
 
1485   $callback = $form->escape($form->{callback});
 
1487   $form->{title} = $locale->text('Buchungsgruppen');
 
1489   @column_index = qw(up down description inventory_accno
 
1490                      income_accno_0 expense_accno_0
 
1491                      income_accno_1 expense_accno_1
 
1492                      income_accno_2 expense_accno_2
 
1493                      income_accno_3 expense_accno_3 );
 
1495   $column_header{up} =
 
1496       qq|<th class="listheading" width="16">|
 
1497     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
1499   $column_header{down} =
 
1500       qq|<th class="listheading" width="16">|
 
1501     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
1503   $column_header{description} =
 
1504       qq|<th class="listheading" width="40%">|
 
1505     . $locale->text('Description')
 
1507   $column_header{inventory_accno} =
 
1508       qq|<th class=listheading>|
 
1509     . $locale->text('Bestandskonto')
 
1511   $column_header{income_accno_0} =
 
1512       qq|<th class=listheading>|
 
1513     . $locale->text('National Revenues')
 
1515   $column_header{expense_accno_0} =
 
1516       qq|<th class=listheading>|
 
1517     . $locale->text('National Expenses')
 
1519   $column_header{income_accno_1} =
 
1520       qq|<th class=listheading>|
 
1521     . $locale->text('Revenues EU with UStId')
 
1523   $column_header{expense_accno_1} =
 
1524       qq|<th class=listheading>|
 
1525     . $locale->text('Expenses EU with UStId')
 
1527   $column_header{income_accno_2} =
 
1528       qq|<th class=listheading>|
 
1529     . $locale->text('Revenues EU without UStId')
 
1531   $column_header{expense_accno_2} =
 
1532       qq|<th class=listheading>|
 
1533     . $locale->text('Expenses EU without UStId')
 
1535   $column_header{income_accno_3} =
 
1536       qq|<th class=listheading>|
 
1537     . $locale->text('Foreign Revenues')
 
1539   $column_header{expense_accno_3} =
 
1540       qq|<th class=listheading>|
 
1541     . $locale->text('Foreign Expenses')
 
1550     <th class=listtop>$form->{title}</th>
 
1552   <tr height="5"></tr>
 
1556         <tr class=listheading>
 
1559   map { print "$column_header{$_}\n" } @column_index;
 
1565   my $swap_link = qq|$form->{script}?action=swap_buchungsgruppen&|;
 
1566   map({ $swap_link .= $_ . "=" . $form->escape($form->{$_}) . "&" }
 
1567       qw(login password));
 
1570   foreach $ref (@{ $form->{ALL} }) {
 
1576         <tr valign=top class=listrow$i>
 
1580       my $pref = $form->{ALL}->[$row - 1];
 
1582         qq|<td align="center" valign="center" width="16">| .
 
1583         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
 
1584         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
1587       $column_data{up} = qq|<td width="16"> </td>|;
 
1590     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
1591       $column_data{down} = qq|<td width="16"> </td>|;
 
1593       my $nref = $form->{ALL}->[$row + 1];
 
1594       $column_data{down} =
 
1595         qq|<td align="center" valign="center" width="16">| .
 
1596         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
 
1597         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
1601     $column_data{description} =
 
1602       qq|<td><a href=$form->{script}?action=edit_buchungsgruppe&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
 
1603     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
 
1604     $column_data{income_accno_0} =
 
1605       qq|<td align=right>$ref->{income_accno_0}</td>|;
 
1606     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
 
1607     $column_data{income_accno_1} =
 
1608       qq|<td align=right>$ref->{income_accno_1}</td>|;
 
1609     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
 
1610     $column_data{income_accno_2} =
 
1611       qq|<td align=right>$ref->{income_accno_2}</td>|;
 
1612     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
 
1613     $column_data{income_accno_3} =
 
1614       qq|<td align=right>$ref->{income_accno_3}</td>|;
 
1615     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
 
1617     map { print "$column_data{$_}\n" } @column_index;
 
1631   <td><hr size=3 noshade></td>
 
1636 <form method=post action=$form->{script}>
 
1638 <input name=callback type=hidden value="$form->{callback}">
 
1640 <input type=hidden name=type value=buchungsgruppe>
 
1642 <input type=hidden name=login value=$form->{login}>
 
1643 <input type=hidden name=password value=$form->{password}>
 
1645 <input class=submit type=submit name=action value="|
 
1646     . $locale->text('Add') . qq|">
 
1654   $lxdebug->leave_sub();
 
1657 sub buchungsgruppe_header {
 
1658   $lxdebug->enter_sub();
 
1660   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
 
1662   # $locale->text('Add Accounting Group')
 
1663   # $locale->text('Edit Accounting Group')
 
1665   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
 
1666   my %acc_type_map = (
 
1667     "IC" => $acc_inventory,
 
1668     "IC_income" => $acc_income,
 
1669     "IC_sale" => $acc_income,
 
1670     "IC_expense" => $acc_expense,
 
1671     "IC_cogs" => $acc_expense,
 
1674   foreach $key (keys(%acc_type_map)) {
 
1675     foreach $ref (@{ $form->{IC_links}{$key} }) {
 
1676       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
 
1680   foreach my $type (qw(IC IC_income IC_expense)) {
 
1681     $form->{"select$type"} =
 
1683            map({ "<option value=$_->{id} $_->{selected}>" .
 
1684                    "$_->{accno}--" . H($_->{description}) . "</option>" }
 
1685                sort({ $a->{"accno"} cmp $b->{"accno"} }
 
1686                     values(%{$acc_type_map{$type}}))));
 
1690     $form->{selectIC} =~ s/selected//g;
 
1691     $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/  value=$form->{inventory_accno_id} selected/;
 
1692     $form->{selectIC_income} =~ s/selected//g;
 
1693     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/  value=$form->{income_accno_id_0} selected/;
 
1694     $form->{selectIC_expense} =~ s/selected//g;
 
1695     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
 
1701                 <th align=right>| . $locale->text('Inventory') . qq|</th>
 
1702                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
 
1703                 <input name=selectIC type=hidden value="$form->{selectIC}">
 
1707                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
 
1711   $linkaccounts .= qq|
 
1713                 <th align=right>| . $locale->text('National Revenues') . qq|</th>
 
1714                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
 
1717                 <th align=right>| . $locale->text('National Expenses') . qq|</th>
 
1718                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
 
1721     $form->{selectIC_income} =~ s/selected//g;
 
1722     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/  value=$form->{income_accno_id_1} selected/;
 
1723     $form->{selectIC_expense} =~ s/selected//g;
 
1724     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/  value=$form->{expense_accno_id_1} selected/;
 
1726   $linkaccounts .= qq|        <tr>
 
1727                 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
 
1728                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
 
1731                 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
 
1732                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
 
1736     $form->{selectIC_income} =~ s/selected//g;
 
1737     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/  value=$form->{income_accno_id_2} selected/;
 
1738     $form->{selectIC_expense} =~ s/selected//g;
 
1739     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/  value=$form->{expense_accno_id_2} selected/;
 
1742   $linkaccounts .= qq|        <tr>
 
1743                 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
 
1744                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
 
1747                 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
 
1748                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
 
1752     $form->{selectIC_income} =~ s/selected//g;
 
1753     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/  value=$form->{income_accno_id_3} selected/;
 
1754     $form->{selectIC_expense} =~ s/selected//g;
 
1755     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/  value=$form->{expense_accno_id_3} selected/;
 
1758   $linkaccounts .= qq|        <tr>
 
1759                 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
 
1760                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
 
1763                 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
 
1764                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
 
1774 <form method=post action=$form->{script}>
 
1776 <input type=hidden name=id value=$form->{id}>
 
1777 <input type=hidden name=type value=buchungsgruppe>
 
1781     <th class=listtop colspan=2>$form->{title}</th>
 
1783   <tr height="5"></tr>
 
1785     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
 
1786     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1789   <td colspan=2><hr size=3 noshade></td>
 
1794   $lxdebug->leave_sub();
 
1797 sub save_buchungsgruppe {
 
1798   $lxdebug->enter_sub();
 
1800   $form->isblank("description", $locale->text('Description missing!'));
 
1802   AM->save_buchungsgruppe(\%myconfig, \%$form);
 
1803   $form->redirect($locale->text('Accounting Group saved!'));
 
1805   $lxdebug->leave_sub();
 
1808 sub delete_buchungsgruppe {
 
1809   $lxdebug->enter_sub();
 
1811   AM->delete_buchungsgruppe(\%myconfig, \%$form);
 
1812   $form->redirect($locale->text('Accounting Group deleted!'));
 
1814   $lxdebug->leave_sub();
 
1817 sub swap_buchungsgruppen {
 
1818   $lxdebug->enter_sub();
 
1820   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
 
1821   list_buchungsgruppe();
 
1823   $lxdebug->leave_sub();
 
1828   $lxdebug->enter_sub();
 
1830   $form->{title} = "Add";
 
1833     "$form->{script}?action=add_printer&login=$form->{login}&password=$form->{password}"
 
1834     unless $form->{callback};
 
1839   $lxdebug->leave_sub();
 
1843   $lxdebug->enter_sub();
 
1845   $form->{title} = "Edit";
 
1847   AM->get_printer(\%myconfig, \%$form);
 
1851   $form->{orphaned} = 1;
 
1854   $lxdebug->leave_sub();
 
1858   $lxdebug->enter_sub();
 
1860   AM->printer(\%myconfig, \%$form);
 
1863     "$form->{script}?action=list_printer&login=$form->{login}&password=$form->{password}";
 
1865   $callback = $form->escape($form->{callback});
 
1867   $form->{title} = $locale->text('Printer');
 
1869   @column_index = qw(printer_description printer_command template_code);
 
1871   $column_header{printer_description} =
 
1872       qq|<th class=listheading width=60%>|
 
1873     . $locale->text('Printer Description')
 
1875   $column_header{printer_command} =
 
1876       qq|<th class=listheading width=10%>|
 
1877     . $locale->text('Printer Command')
 
1879   $column_header{template_code} =
 
1880       qq|<th class=listheading>|
 
1881     . $locale->text('Template Code')
 
1891     <th class=listtop>$form->{title}</th>
 
1893   <tr height="5"></tr>
 
1897         <tr class=listheading>
 
1900   map { print "$column_header{$_}\n" } @column_index;
 
1906   foreach $ref (@{ $form->{ALL} }) {
 
1912         <tr valign=top class=listrow$i>
 
1916     $column_data{printer_description} =
 
1917       qq|<td><a href=$form->{script}?action=edit_printer&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{printer_description}</td>|;
 
1918     $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
 
1919     $column_data{template_code} =
 
1920       qq|<td align=right>$ref->{template_code}</td>|;
 
1922     map { print "$column_data{$_}\n" } @column_index;
 
1934   <td><hr size=3 noshade></td>
 
1939 <form method=post action=$form->{script}>
 
1941 <input name=callback type=hidden value="$form->{callback}">
 
1943 <input type=hidden name=type value=printer>
 
1945 <input type=hidden name=login value=$form->{login}>
 
1946 <input type=hidden name=password value=$form->{password}>
 
1948 <input class=submit type=submit name=action value="|
 
1949     . $locale->text('Add') . qq|">
 
1957   $lxdebug->leave_sub();
 
1960 sub printer_header {
 
1961   $lxdebug->enter_sub();
 
1963   $form->{title}    = $locale->text("$form->{title} Printer");
 
1965   # $locale->text('Add Printer')
 
1966   # $locale->text('Edit Printer')
 
1968   $form->{printer_description} =~ s/\"/"/g;
 
1969   $form->{template_code} =~ s/\"/"/g;
 
1970   $form->{printer_command} =~ s/\"/"/g;
 
1978 <form method=post action=$form->{script}>
 
1980 <input type=hidden name=id value=$form->{id}>
 
1981 <input type=hidden name=type value=printer>
 
1985     <th class=listtop colspan=2>$form->{title}</th>
 
1987   <tr height="5"></tr>
 
1989     <th align=right>| . $locale->text('Printer') . qq|</th>
 
1990     <td><input name=printer_description size=30 value="$form->{printer_description}"></td>
 
1993     <th align=right>| . $locale->text('Printer Command') . qq|</th>
 
1994     <td><input name=printer_command size=30 value="$form->{printer_command}"></td>
 
1997     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1998     <td><input name=template_code size=5 value="$form->{template_code}"></td>
 
2000   <td colspan=2><hr size=3 noshade></td>
 
2005   $lxdebug->leave_sub();
 
2009   $lxdebug->enter_sub();
 
2011   $form->isblank("printer_description", $locale->text('Description missing!'));
 
2012   $form->isblank("printer_command", $locale->text('Printer Command missing!'));
 
2013   AM->save_printer(\%myconfig, \%$form);
 
2014   $form->redirect($locale->text('Printer saved!'));
 
2016   $lxdebug->leave_sub();
 
2019 sub delete_printer {
 
2020   $lxdebug->enter_sub();
 
2022   AM->delete_printer(\%myconfig, \%$form);
 
2023   $form->redirect($locale->text('Printer deleted!'));
 
2025   $lxdebug->leave_sub();
 
2029   $lxdebug->enter_sub();
 
2031   $form->{title} = "Add";
 
2034     "$form->{script}?action=add_payment&login=$form->{login}&password=$form->{password}"
 
2035     unless $form->{callback};
 
2037   $form->{terms_netto} = 0;
 
2038   $form->{terms_skonto} = 0;
 
2039   $form->{percent_skonto} = 0;
 
2040   my @languages = AM->language(\%myconfig, $form, 1);
 
2041   map({ $_->{"language"} = $_->{"description"};
 
2042         $_->{"language_id"} = $_->{"id"}; } @languages);
 
2043   $form->{"TRANSLATION"} = \@languages;
 
2047   $lxdebug->leave_sub();
 
2051   $lxdebug->enter_sub();
 
2053   $form->{title} = "Edit";
 
2055   AM->get_payment(\%myconfig, $form);
 
2056   $form->{percent_skonto} =
 
2057     $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
 
2061   $form->{orphaned} = 1;
 
2064   $lxdebug->leave_sub();
 
2068   $lxdebug->enter_sub();
 
2070   AM->payment(\%myconfig, \%$form);
 
2072   $form->{callback} = build_std_url("action=list_payment");
 
2074   $callback = $form->escape($form->{callback});
 
2076   $form->{title} = $locale->text('Payment Terms');
 
2078   @column_index = qw(up down description description_long terms_netto
 
2079                      terms_skonto percent_skonto);
 
2081   $column_header{up} =
 
2082       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2083     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
2085   $column_header{down} =
 
2086       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2087     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
2089   $column_header{description} =
 
2090       qq|<th class=listheading>|
 
2091     . $locale->text('Description')
 
2093   $column_header{description_long} =
 
2094       qq|<th class=listheading>|
 
2095     . $locale->text('Long Description')
 
2097   $column_header{terms_netto} =
 
2098       qq|<th class=listheading>|
 
2099     . $locale->text('Netto Terms')
 
2101   $column_header{terms_skonto} =
 
2102       qq|<th class=listheading>|
 
2103     . $locale->text('Skonto Terms')
 
2105   $column_header{percent_skonto} =
 
2106       qq|<th class=listheading>|
 
2107     . $locale->text('Skonto')
 
2117     <th class=listtop>$form->{title}</th>
 
2119   <tr height="5"></tr>
 
2123         <tr class=listheading>
 
2126   map { print "$column_header{$_}\n" } @column_index;
 
2132   my $swap_link = build_std_url("action=swap_payment_terms");
 
2135   foreach $ref (@{ $form->{ALL} }) {
 
2141         <tr valign=top class=listrow$i>
 
2145       my $pref = $form->{ALL}->[$row - 1];
 
2147         qq|<td align="center" valign="center" width="16">| .
 
2148         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
 
2149         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
2152       $column_data{up} = qq|<td width="16"> </td>|;
 
2155     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
2156       $column_data{down} = qq|<td width="16"> </td>|;
 
2158       my $nref = $form->{ALL}->[$row + 1];
 
2159       $column_data{down} =
 
2160         qq|<td align="center" valign="center" width="16">| .
 
2161         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
 
2162         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
2166     $column_data{description} =
 
2168       build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
 
2169       qq|">| . H($ref->{description}) . qq|</a></td>|;
 
2170     $column_data{description_long} =
 
2171       qq|<td>| . H($ref->{description_long}) . qq|</td>|;
 
2172     $column_data{terms_netto} =
 
2173       qq|<td align=right>$ref->{terms_netto}</td>|;
 
2174     $column_data{terms_skonto} =
 
2175       qq|<td align=right>$ref->{terms_skonto}</td>|;
 
2176     $column_data{percent_skonto} =
 
2177       qq|<td align=right>| .
 
2178       $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
 
2180     map { print "$column_data{$_}\n" } @column_index;
 
2193   <td><hr size=3 noshade></td>
 
2198 <form method=post action=$form->{script}>
 
2200 <input name=callback type=hidden value="$form->{callback}">
 
2202 <input type=hidden name=type value=payment>
 
2204 <input type=hidden name=login value=$form->{login}>
 
2205 <input type=hidden name=password value=$form->{password}>
 
2207 <input class=submit type=submit name=action value="|
 
2208     . $locale->text('Add') . qq|">
 
2216   $lxdebug->leave_sub();
 
2219 sub payment_header {
 
2220   $lxdebug->enter_sub();
 
2222   $form->{title}    = $locale->text("$form->{title} Payment Terms");
 
2224   # $locale->text('Add Payment Terms')
 
2225   # $locale->text('Edit Payment Terms')
 
2227   $form->{description} =~ s/\"/"/g;
 
2236 <form method=post action=$form->{script}>
 
2238 <input type=hidden name=id value=$form->{id}>
 
2239 <input type=hidden name=type value=payment>
 
2243     <th class=listtop colspan=2>$form->{title}</th>
 
2245   <tr height="5"></tr>
 
2247     <th align=right>| . $locale->text('Description') . qq|</th>
 
2248     <td><input name=description size=30 value="$form->{description}"></td>
 
2251     <th align=right>| . $locale->text('Long Description') . qq|</th>
 
2252     <td><input name=description_long size=50 value="$form->{description_long}"></td>
 
2256   foreach my $language (@{ $form->{"TRANSLATION"} }) {
 
2259     <th align="right">| .
 
2260     sprintf($locale->text('Translation (%s)'),
 
2261             $language->{"language"})
 
2263     <td><input name="description_long_$language->{language_id}" size="50"
 
2264          value="| . Q($language->{"description_long"}) . qq|"></td>
 
2271     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
 
2272     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
 
2275     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
 
2276     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
 
2279     <th align=right>| . $locale->text('Skonto') . qq| %</th>
 
2280     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
 
2282   <td colspan=2><hr size=3 noshade></td>
 
2286 <p>| . $locale->text("You can use the following strings in the long " .
 
2287                      "description and all translations. They will be " .
 
2288                      "replaced by their actual values by Lx-Office " .
 
2289                      "before they're output.")
 
2293   <li>| . $locale->text("<%netto_date%> -- Date the payment is due in " .
 
2296   <li>| . $locale->text("<%skonto_date%> -- Date the payment is due " .
 
2299   <li>| . $locale->text("<%skonto_amount%> -- The deductible amount")
 
2301   <li>| . $locale->text("<%total%> -- Amount payable")
 
2303   <li>| . $locale->text("<%total_wo_skonto%> -- Amount payable less discount")
 
2305   <li>| . $locale->text("<%invtotal%> -- Invoice total")
 
2307   <li>| . $locale->text("<%invtotal_wo_skonto%> -- Invoice total less discount")
 
2309   <li>| . $locale->text("<%currency%> -- The selected currency")
 
2311   <li>| . $locale->text("<%terms_netto%> -- The number of days for " .
 
2314   <li>| . $locale->text("<%account_number%> -- Your account number")
 
2316   <li>| . $locale->text("<%bank%> -- Your bank")
 
2318   <li>| . $locale->text("<%bank_code%> -- Your bank code")
 
2322   $lxdebug->leave_sub();
 
2326   $lxdebug->enter_sub();
 
2328   $form->isblank("description", $locale->text('Description missing!'));
 
2329   $form->{"percent_skonto"} =
 
2330     $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
 
2331   AM->save_payment(\%myconfig, \%$form);
 
2332   $form->redirect($locale->text('Payment Terms saved!'));
 
2334   $lxdebug->leave_sub();
 
2337 sub delete_payment {
 
2338   $lxdebug->enter_sub();
 
2340   AM->delete_payment(\%myconfig, \%$form);
 
2341   $form->redirect($locale->text('Payment terms deleted!'));
 
2343   $lxdebug->leave_sub();
 
2346 sub swap_payment_terms {
 
2347   $lxdebug->enter_sub();
 
2349   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
 
2352   $lxdebug->leave_sub();
 
2355 sub _build_cfg_options {
 
2357   my $array = uc($idx) . 'S';
 
2359   $form->{$array} = [];
 
2360   foreach my $item (@_) {
 
2361     push @{ $form->{$array} }, {
 
2364       'selected' => $item eq $myconfig{$idx},
 
2370   $lxdebug->enter_sub();
 
2372   # get defaults for account numbers and last numbers
 
2373   AM->defaultaccounts(\%myconfig, \%$form);
 
2375   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
 
2377   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
2378   _build_cfg_options('numberformat', qw(1,000.00 1000.00 1.000,00 1000,00));
 
2381   if ($opendocument_templates && $openofficeorg_writer_bin &&
 
2382       $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
 
2383     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
2384                      "value" => "opendocument_pdf" });
 
2386   if ($latex_templates) {
 
2387     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
2389   push(@formats, { "name" => "HTML", "value" => "html" });
 
2390   if ($latex_templates) {
 
2391     push(@formats, { "name" => $locale->text("Postscript"),
 
2392                      "value" => "postscript" });
 
2394   if ($opendocument_templates) {
 
2395     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
2396                      "value" => "opendocument" });
 
2399   if (!$myconfig{"template_format"}) {
 
2400     $myconfig{"template_format"} = "pdf";
 
2402   $form->{TEMPLATE_FORMATS} = [];
 
2403   foreach $item (@formats) {
 
2404     push @{ $form->{TEMPLATE_FORMATS} }, {
 
2405       'name'     => $item->{name},
 
2406       'value'    => $item->{value},
 
2407       'selected' => $item->{value} eq $myconfig{template_format},
 
2411   if (!$myconfig{"default_media"}) {
 
2412     $myconfig{"default_media"} = "screen";
 
2415   my %selected = ($myconfig{"default_media"} => "selected");
 
2417     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
2418     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
2419     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
2422   AM->printer(\%myconfig, $form);
 
2424   $form->{PRINTERS} = [];
 
2425   foreach my $printer (@{$form->{"ALL"}}) {
 
2426     push @{ $form->{PRINTERS} }, {
 
2427       'name'     => $printer->{printer_description},
 
2428       'value'    => $printer->{id},
 
2429       'selected' => $printer->{id} == $myconfig{default_printer_id},
 
2433   %countrycodes = User->country_codes;
 
2435   $countrycodes{""} = "American English";
 
2436   $form->{COUNTRYCODES} = [];
 
2437   foreach $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
2438     push @{ $form->{COUNTRYCODES} }, {
 
2439       'name'     => $countrycodes{$countrycode},
 
2440       'value'    => $countrycode,
 
2441       'selected' => $countrycode eq $myconfig{countrycode},
 
2445   foreach $key (keys %{ $form->{IC} }) {
 
2446     foreach $accno (sort keys %{ $form->{IC}->{$key} }) {
 
2447       my $array = "ACCNOS_" . uc($key);
 
2448       $form->{$array} ||= [];
 
2450       my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
 
2451       push @{ $form->{$array} }, {
 
2454         'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
 
2459   $form->{STYLESHEETS} = [];
 
2460   foreach $item (qw(lx-office-erp.css Win2000.css)) {
 
2461     push @{ $form->{STYLESHEETS} }, {
 
2464       'selected' => $item eq $myconfig{stylesheet},
 
2468   $myconfig{show_form_details}              = 1 unless (defined($myconfig{show_form_details}));
 
2469   $form->{"menustyle_$myconfig{menustyle}"} = 1;
 
2471   $form->{title}                            = $locale->text('Edit Preferences for #1', $form->{login});
 
2474   print $form->parse_html_template2('am/config');
 
2476   $lxdebug->leave_sub();
 
2479 sub save_preferences {
 
2480   $lxdebug->enter_sub();
 
2482   $form->{stylesheet} = $form->{usestylesheet};
 
2484   $form->redirect($locale->text('Preferences saved!'))
 
2486      AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath, $webdav
 
2488   $form->error($locale->text('Cannot save preferences!'));
 
2490   $lxdebug->leave_sub();
 
2494   $lxdebug->enter_sub();
 
2496   $form->{title} = $locale->text('Audit Control');
 
2498   AM->closedto(\%myconfig, \%$form);
 
2500   if ($form->{revtrans}) {
 
2501     $checked{Y} = "checked";
 
2503     $checked{N} = "checked";
 
2511 <form method=post action=$form->{script}>
 
2513 <input type=hidden name=login value=$form->{login}>
 
2514 <input type=hidden name=password value=$form->{password}>
 
2517   <tr><th class=listtop>$form->{title}</th></tr>
 
2518   <tr height="5"></tr>
 
2524     . $locale->text('Enforce transaction reversal for all dates') . qq|</th>
 
2525           <td><input name=revtrans class=radio type=radio value="1" $checked{Y}> |
 
2526     . $locale->text('Yes')
 
2527     . qq| <input name=revtrans class=radio type=radio value="0" $checked{N}> |
 
2528     . $locale->text('No')
 
2532           <th>| . $locale->text('Close Books up to') . qq|</th>
 
2533           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
 
2543 <input type=hidden name=nextsub value=doclose>
 
2545 <input type=submit class=submit name=action value="|
 
2546     . $locale->text('Continue') . qq|">
 
2554   $lxdebug->leave_sub();
 
2558   $lxdebug->enter_sub();
 
2560   AM->closebooks(\%myconfig, \%$form);
 
2562   if ($form->{revtrans}) {
 
2564                  $locale->text('Transaction reversal enforced for all dates'));
 
2566     if ($form->{closedto}) {
 
2568                      $locale->text('Transaction reversal enforced up to') . " "
 
2569                        . $locale->date(\%myconfig, $form->{closedto}, 1));
 
2571       $form->redirect($locale->text('Books are open'));
 
2575   $lxdebug->leave_sub();
 
2579   $lxdebug->enter_sub();
 
2581   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
 
2582   AM->units_in_use(\%myconfig, $form, $units);
 
2583   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
2585   @languages = AM->language(\%myconfig, $form, 1);
 
2587   @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
2590   foreach (@unit_list) {
 
2591     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
2592     $_->{"UNITLANGUAGES"} = [];
 
2593     foreach my $lang (@languages) {
 
2594       push(@{ $_->{"UNITLANGUAGES"} },
 
2596              "unit" => $_->{"name"},
 
2597              "language_id" => $lang->{"id"},
 
2598              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
2599              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
2605   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
 
2606   $ddbox = AM->unit_select_data($units, undef, 1);
 
2608   my $updownlink = build_std_url("action=swap_units", "unit_type");
 
2610   $form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units"));
 
2612   print($form->parse_html_template("am/edit_units",
 
2613                                    { "UNITS" => \@unit_list,
 
2614                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
2615                                      "LANGUAGES" => \@languages,
 
2616                                      "updownlink" => $updownlink }));
 
2618   $lxdebug->leave_sub();
 
2622   $lxdebug->enter_sub();
 
2624   $form->isblank("new_name", $locale->text("The name is missing."));
 
2625   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
 
2626   $all_units = AM->retrieve_units(\%myconfig, $form);
 
2627   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
2629   my ($base_unit, $factor);
 
2630   if ($form->{"new_base_unit"}) {
 
2631     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
2633     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
2634     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
2635     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
2636     $base_unit = $form->{"new_base_unit"};
 
2640   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
2641     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
2642     push(@languages, { "id" => $lang->{"id"},
 
2643                        "localized" => $form->{"new_localized_$lang->{id}"},
 
2644                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
2648   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}, \@languages);
 
2650   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
2654   $lxdebug->leave_sub();
 
2657 sub set_unit_languages {
 
2658   $lxdebug->enter_sub();
 
2660   my ($unit, $languages, $idx) = @_;
 
2662   $unit->{"LANGUAGES"} = [];
 
2664   foreach my $lang (@{$languages}) {
 
2665     push(@{ $unit->{"LANGUAGES"} },
 
2666          { "id" => $lang->{"id"},
 
2667            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
2668            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
2672   $lxdebug->leave_sub();
 
2676   $lxdebug->enter_sub();
 
2678   $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
 
2679   AM->units_in_use(\%myconfig, $form, $old_units);
 
2681   @languages = AM->language(\%myconfig, $form, 1);
 
2685   foreach $i (1..($form->{"rowcount"} * 1)) {
 
2686     $old_unit = $old_units->{$form->{"old_name_$i"}};
 
2688       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
2691     if ($form->{"unchangeable_$i"}) {
 
2692       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
2693       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
2694       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2698     if ($old_unit->{"in_use"}) {
 
2699       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
2702     if ($form->{"delete_$i"}) {
 
2703       push(@delete_units, $old_unit->{"name"});
 
2707     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
2709     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
2710     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
2711     $new_units->{$form->{"name_$i"}} = \%h;
 
2712     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
2713     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2716   foreach $unit (values(%{$new_units})) {
 
2717     next unless ($unit->{"old_name"});
 
2718     if ($unit->{"base_unit"}) {
 
2719       $form->show_generic_error(sprintf($locale->text("The base unit does not exist or it is about to be deleted in row %d."), $unit->{"row"}))
 
2720         unless (defined($new_units->{$unit->{"base_unit"}}));
 
2721       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
2722       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
2724       $unit->{"base_unit"} = undef;
 
2725       $unit->{"factor"} = undef;
 
2729   foreach $unit (values(%{$new_units})) {
 
2730     next if ($unit->{"unchanged_unit"});
 
2732     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
2734     while ($new_unit->{"base_unit"}) {
 
2735       $new_unit->{"seen"} = 1;
 
2736       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
2737       if ($new_unit->{"seen"}) {
 
2738         $form->show_generic_error(sprintf($locale->text("The base unit relations must not contain loops (e.g. by saying that unit A's base unit is B, " .
 
2739                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
2744   AM->save_units(\%myconfig, $form, $form->{"unit_type"}, $new_units, \@delete_units);
 
2746   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
2750   $lxdebug->leave_sub();
 
2753 sub show_history_search {
 
2754         $lxdebug->enter_sub();
 
2756         $form->{title} = $locale->text("History Search");
 
2759     print $form->parse_html_template("/common/search_history");
 
2761         $lxdebug->leave_sub();
 
2764 sub show_am_history {
 
2765         $lxdebug->enter_sub();
 
2766         my %search = ( "Artikelnummer" => "parts",
 
2767                                    "Kundennummer"  => "customer",
 
2768                                    "Lieferantennummer" => "vendor",
 
2769                                    "Projektnummer" => "project",
 
2770                                    "Buchungsnummer" => "oe",
 
2771                                    "Eingangsrechnungnummer" => "ap",
 
2772                                    "Ausgangsrechnungnummer" => "ar",
 
2773            "Mahnungsnummer" => "dunning"
 
2775         my %searchNo = ( "Artikelnummer" => "partnumber",
 
2776                                      "Kundennummer"  => "customernumber",
 
2777                                      "Lieferantennummer" => "vendornumber",
 
2778                                      "Projektnummer" => "projectnummer",
 
2779                                      "Buchungsnummer" => "ordnumber",
 
2780                                      "Eingangsrechnungnummer" => "invnumber",
 
2781                                      "Ausgangsrechnungnummer" => "invnumber",
 
2782              "Mahnungsnummer" => "dunning_id"
 
2787         foreach(split(/\,/, $form->{einschraenkungen})) {
 
2789                         $restriction .= " AND addition = '" . $_ . "'";
 
2793                         $restriction .= " OR addition = '" . $_ . "'";
 
2796         $restriction .= (($form->{transdate} ne "" && $form->{reqdate} ne "") 
 
2797                                                 ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|' AND st.itime::date <= '| . $form->{reqdate} . qq|'|
 
2798                                                 : (($form->{transdate} ne "" && $form->{reqdate} eq "") 
 
2799                                                         ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|'|
 
2800                                                         : ($form->{transdate} eq "" && $form->{reqdate} ne "") 
 
2801                                                                 ? qq| AND st.itime::date <= '| . $form->{reqdate} . qq|'|
 
2805   $restriction .= ($form->{mitarbeiter} eq "" ? "" 
 
2806           : ($form->{mitarbeiter} =~ /^[0-9]*$/  
 
2807             ? " AND employee_id = " . $form->{mitarbeiter} 
 
2808             : " AND employee_id = " . &get_employee_id($form->{mitarbeiter}, $dbh)));
 
2810         my $dbh = $form->dbconnect(\%myconfig);
 
2811         my $query = qq|SELECT trans_id AS id FROM history_erp | . 
 
2812                 ($form->{'searchid'} ? 
 
2813                   qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'| : 
 
2814                   qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
2816   my $sth = $dbh->prepare($query);
 
2818         $sth->execute() || $form->dberror($query);
 
2820   $form->{title} = $locale->text("History Search");
 
2825   while(my $hash_ref = $sth->fetchrow_hashref()){
 
2827       $daten .= $hash_ref->{id};
 
2831       $daten .= " OR trans_id = " . $hash_ref->{id};
 
2835   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
2836   $sort =~ s/.*\.(.*)$/$1/;
 
2838         print $form->parse_html_template("/common/show_history", 
 
2839     {"DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
2840      "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
2843      uc($sort)."BY" => $sortby
 
2846   $lxdebug->leave_sub();
 
2849 sub get_employee_id {
 
2850         $lxdebug->enter_sub();
 
2851         my $query = qq|SELECT id FROM employee WHERE name = '| . $_[0] . qq|'|;
 
2852         my $sth = $_[1]->prepare($query);
 
2853         $sth->execute() || $form->dberror($query);
 
2854         my $return = $sth->fetch();
 
2856         return ${$return}[0];
 
2857         $lxdebug->leave_sub();
 
2861   $lxdebug->enter_sub();
 
2863   my $dir = $form->{"dir"} eq "down" ? "down" : "up";
 
2864   my $unit_type = $form->{"unit_type"} eq "dimension" ?
 
2865     "dimension" : "service";
 
2866   AM->swap_units(\%myconfig, $form, $dir, $form->{"name"}, $unit_type);
 
2870   $lxdebug->leave_sub();
 
2874   $lxdebug->enter_sub();
 
2876   $form->{title} =  $locale->text('Add');
 
2879     "$form->{script}?action=add_tax&login=$form->{login}&password=$form->{password}"
 
2880     unless $form->{callback};
 
2882   _get_taxaccount_selection();
 
2886   my $parameters_ref = {
 
2887 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
2890   # Ausgabe des Templates
 
2891   print($form->parse_html_template2('am/edit_tax', $parameters_ref));
 
2893   $lxdebug->leave_sub();
 
2897   $lxdebug->enter_sub();
 
2899   $form->{title} =  $locale->text('Edit');
 
2901   AM->get_tax(\%myconfig, \%$form);
 
2902   _get_taxaccount_selection();
 
2904   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
2908   my $parameters_ref = {
 
2911   # Ausgabe des Templates
 
2912   print($form->parse_html_template2('am/edit_tax', $parameters_ref));
 
2914   $lxdebug->leave_sub();
 
2918   $lxdebug->enter_sub();
 
2920   AM->taxes(\%myconfig, \%$form);
 
2922   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
2924   $form->{callback} = build_std_url('action=list_tax');
 
2926   $form->{title} = $locale->text('Tax-O-Matic');
 
2930   # Ausgabe des Templates
 
2931   print($form->parse_html_template2('am/list_tax', $parameters_ref));
 
2933   $lxdebug->leave_sub();
 
2936 sub _get_taxaccount_selection{
 
2937   $lxdebug->enter_sub();
 
2939   AM->get_tax_accounts(\%myconfig, \%$form);
 
2941   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
2943   $lxdebug->leave_sub();
 
2947   $lxdebug->enter_sub();
 
2949   $form->isblank("rate", $locale->text('Taxrate missing!'));
 
2950   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
 
2951   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
 
2953   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
2955   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
2956     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
2959   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
2960     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
2963   AM->save_tax(\%myconfig, \%$form);
 
2964   $form->redirect($locale->text('Tax saved!'));
 
2966   $lxdebug->leave_sub();
 
2970   $lxdebug->enter_sub();
 
2972   AM->delete_tax(\%myconfig, \%$form);
 
2973   $form->redirect($locale->text('Tax deleted!'));
 
2975   $lxdebug->leave_sub();
 
2978 sub add_price_factor {
 
2979   $lxdebug->enter_sub();
 
2981   $form->{title}      = $locale->text('Add Price Factor');
 
2982   $form->{callback} ||= build_std_url('action=add_price_factor');
 
2983   $form->{fokus}      = 'description';
 
2986   print $form->parse_html_template2('am/edit_price_factor');
 
2988   $lxdebug->leave_sub();
 
2991 sub edit_price_factor {
 
2992   $lxdebug->enter_sub();
 
2994   $form->{title}      = $locale->text('Edit Price Factor');
 
2995   $form->{callback} ||= build_std_url('action=add_price_factor');
 
2996   $form->{fokus}      = 'description';
 
2998   AM->get_price_factor(\%myconfig, $form);
 
3000   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
 
3003   print $form->parse_html_template2('am/edit_price_factor');
 
3005   $lxdebug->leave_sub();
 
3008 sub list_price_factors {
 
3009   $lxdebug->enter_sub();
 
3011   AM->get_all_price_factors(\%myconfig, \%$form);
 
3014   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
 
3016       $previous->{next_id}    = $current->{id};
 
3017       $current->{previous_id} = $previous->{id};
 
3020     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
 
3022     $previous = $current;
 
3025   $form->{callback} = build_std_url('action=list_price_factors');
 
3026   $form->{title}    = $locale->text('Price Factors');
 
3027   $form->{url_base} = build_std_url('callback');
 
3030   print $form->parse_html_template2('am/list_price_factors');
 
3032   $lxdebug->leave_sub();
 
3035 sub save_price_factor {
 
3036   $lxdebug->enter_sub();
 
3038   $form->isblank("description", $locale->text('Description missing!'));
 
3039   $form->isblank("factor", $locale->text('Factor missing!'));
 
3041   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
 
3043   AM->save_price_factor(\%myconfig, $form);
 
3045   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
 
3047   $form->redirect($locale->text('Price factor saved!'));
 
3049   $lxdebug->leave_sub();
 
3052 sub delete_price_factor {
 
3053   $lxdebug->enter_sub();
 
3055   AM->delete_price_factor(\%myconfig, \%$form);
 
3057   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
 
3059   $form->redirect($locale->text('Price factor deleted!'));
 
3061   $lxdebug->leave_sub();
 
3064 sub swap_price_factors {
 
3065   $lxdebug->enter_sub();
 
3067   AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
 
3068   list_price_factors();
 
3070   $lxdebug->leave_sub();