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_template2('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   $form->{callback}     = build_std_url('action=list_account');
 
 402   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 404   CA->all_accounts(\%myconfig, \%$form);
 
 406   foreach $ca (@{ $form->{CA} }) {
 
 411     if ($ca->{amount} > 0) {
 
 412       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 414     if ($ca->{amount} < 0) {
 
 415       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 417     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:''; 
 
 418     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 422   my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
 
 424   # Eneable AJAX debuging
 
 428   push(@ { $form->{AJAX} }, $pjx);
 
 430   $form->{stylesheets} = "list_accounts.css";
 
 431   $form->{title}       = $locale->text('Chart of Accounts');
 
 436   my $parameters_ref = {
 
 437   #   hidden_variables                => $_hidden_variables_ref,
 
 440   # Ausgabe des Templates
 
 441   print($form->parse_html_template2('am/list_accounts', $parameters_ref));
 
 443   $lxdebug->leave_sub();
 
 448 sub list_account_details {
 
 449 # Ajax Funktion aus list_account_details
 
 450   $lxdebug->enter_sub();
 
 452   my $chart_id = $form->{args};
 
 454   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 456   foreach $ca (@{ $form->{CA} }) {
 
 458     $ca->{debit}  = " ";
 
 459     $ca->{credit} = " ";
 
 461     if ($ca->{amount} > 0) {
 
 463         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 465     if ($ca->{amount} < 0) {
 
 467         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 470     my @links = split( q{:}, $ca->{link});
 
 474     foreach my $link (@links){
 
 475       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 476                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 477                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 478                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 479                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 480                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 481                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 482                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 483                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 484                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 485                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 486                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 487                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 488                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 489                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 490 #               : ( $link eq 'CT_tax' )        ? $locale->text('Account Link CT_tax')
 
 491                : $locale->text('Unknown Link') . ': ' . $link;
 
 492       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 495     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 496                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 497                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 498                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 499                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 500                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 501                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 502                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 505   $form->{title} = $locale->text('Chart of Accounts');
 
 508   print $form->parse_html_template2('am/list_account_details');
 
 510   $lxdebug->leave_sub();
 
 515   $lxdebug->enter_sub();
 
 517   $form->{title} = $locale->text('Delete Account');
 
 520     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
 
 522     if ($form->{id} == $form->{$id}) {
 
 523       $form->error($locale->text('Cannot delete default account!'));
 
 527   $form->redirect($locale->text('Account deleted!'))
 
 528     if (AM->delete_account(\%myconfig, \%$form));
 
 529   $form->error($locale->text('Cannot delete account!'));
 
 531   $lxdebug->leave_sub();
 
 535   $lxdebug->enter_sub();
 
 537   $form->{title} = "Add";
 
 541     "$form->{script}?action=add_department&login=$form->{login}&password=$form->{password}"
 
 542     unless $form->{callback};
 
 547   $lxdebug->leave_sub();
 
 550 sub edit_department {
 
 551   $lxdebug->enter_sub();
 
 553   $form->{title} = "Edit";
 
 555   AM->get_department(\%myconfig, \%$form);
 
 560   $lxdebug->leave_sub();
 
 563 sub list_department {
 
 564   $lxdebug->enter_sub();
 
 566   AM->departments(\%myconfig, \%$form);
 
 569     "$form->{script}?action=list_department&login=$form->{login}&password=$form->{password}";
 
 571   $callback = $form->escape($form->{callback});
 
 573   $form->{title} = $locale->text('Departments');
 
 575   @column_index = qw(description cost profit);
 
 577   $column_header{description} =
 
 578       qq|<th class=listheading width=90%>|
 
 579     . $locale->text('Description')
 
 581   $column_header{cost} =
 
 582       qq|<th class=listheading nowrap>|
 
 583     . $locale->text('Cost Center')
 
 585   $column_header{profit} =
 
 586       qq|<th class=listheading nowrap>|
 
 587     . $locale->text('Profit Center')
 
 597     <th class=listtop>$form->{title}</th>
 
 603         <tr class=listheading>
 
 606   map { print "$column_header{$_}\n" } @column_index;
 
 612   foreach $ref (@{ $form->{ALL} }) {
 
 618         <tr valign=top class=listrow$i>
 
 621     $costcenter   = ($ref->{role} eq "C") ? "X" : "";
 
 622     $profitcenter = ($ref->{role} eq "P") ? "X" : "";
 
 624     $column_data{description} =
 
 625       qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
 
 626     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
 
 627     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
 
 629     map { print "$column_data{$_}\n" } @column_index;
 
 641   <td><hr size=3 noshade></td>
 
 646 <form method=post action=$form->{script}>
 
 648 <input name=callback type=hidden value="$form->{callback}">
 
 650 <input type=hidden name=type value=department>
 
 652 <input type=hidden name=login value=$form->{login}>
 
 653 <input type=hidden name=password value=$form->{password}>
 
 655 <input class=submit type=submit name=action value="|
 
 656     . $locale->text('Add') . qq|">
 
 664   $lxdebug->leave_sub();
 
 667 sub department_header {
 
 668   $lxdebug->enter_sub();
 
 670   $form->{title} = $locale->text("$form->{title} Department");
 
 672   # $locale->text('Add Department')
 
 673   # $locale->text('Edit Department')
 
 675   $form->{description} =~ s/\"/"/g;
 
 677   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
 
 679       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
 
 682       qq|<input name=description size=60 value="$form->{description}">|;
 
 685   $costcenter   = "checked" if $form->{role} eq "C";
 
 686   $profitcenter = "checked" if $form->{role} eq "P";
 
 693 <form method=post action=$form->{script}>
 
 695 <input type=hidden name=id value=$form->{id}>
 
 696 <input type=hidden name=type value=department>
 
 700     <th class=listtop colspan=2>$form->{title}</th>
 
 704     <th align=right>| . $locale->text('Description') . qq|</th>
 
 705     <td>$description</td>
 
 709     <td><input type=radio style=radio name=role value="C" $costcenter> |
 
 710     . $locale->text('Cost Center') . qq|
 
 711         <input type=radio style=radio name=role value="P" $profitcenter> |
 
 712     . $locale->text('Profit Center') . qq|
 
 715     <td colspan=2><hr size=3 noshade></td>
 
 720   $lxdebug->leave_sub();
 
 723 sub save_department {
 
 724   $lxdebug->enter_sub();
 
 726   $form->isblank("description", $locale->text('Description missing!'));
 
 727   AM->save_department(\%myconfig, \%$form);
 
 728   $form->redirect($locale->text('Department saved!'));
 
 730   $lxdebug->leave_sub();
 
 733 sub delete_department {
 
 734   $lxdebug->enter_sub();
 
 736   AM->delete_department(\%myconfig, \%$form);
 
 737   $form->redirect($locale->text('Department deleted!'));
 
 739   $lxdebug->leave_sub();
 
 743   $lxdebug->enter_sub();
 
 745   $form->{title} = "Add";
 
 748     "$form->{script}?action=add_lead&login=$form->{login}&password=$form->{password}"
 
 749     unless $form->{callback};
 
 754   $lxdebug->leave_sub();
 
 758   $lxdebug->enter_sub();
 
 760   $form->{title} = "Edit";
 
 762   AM->get_lead(\%myconfig, \%$form);
 
 766   $form->{orphaned} = 1;
 
 769   $lxdebug->leave_sub();
 
 773   $lxdebug->enter_sub();
 
 775   AM->lead(\%myconfig, \%$form);
 
 778     "$form->{script}?action=list_lead&login=$form->{login}&password=$form->{password}";
 
 780   $callback = $form->escape($form->{callback});
 
 782   $form->{title} = $locale->text('Lead');
 
 784   @column_index = qw(description cost profit);
 
 786   $column_header{description} =
 
 787       qq|<th class=listheading width=100%>|
 
 788     . $locale->text('Description')
 
 798     <th class=listtop>$form->{title}</th>
 
 801   <tr class=listheading>
 
 804   map { print "$column_header{$_}\n" } @column_index;
 
 810   foreach $ref (@{ $form->{ALL} }) {
 
 816         <tr valign=top class=listrow$i>
 
 819         $lead = $ref->{lead};
 
 821     $column_data{description} =
 
 822       qq|<td><a href=$form->{script}?action=edit_lead&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{lead}</td>|;
 
 824     map { print "$column_data{$_}\n" } @column_index;
 
 833   <td><hr size=3 noshade></td>
 
 838 <form method=post action=$form->{script}>
 
 840 <input name=callback type=hidden value="$form->{callback}">
 
 842 <input type=hidden name=type value=lead>
 
 844 <input type=hidden name=login value=$form->{login}>
 
 845 <input type=hidden name=password value=$form->{password}>
 
 847 <input class=submit type=submit name=action value="|
 
 848     . $locale->text('Add') . qq|">
 
 856   $lxdebug->leave_sub();
 
 860   $lxdebug->enter_sub();
 
 862   $form->{title} = $locale->text("$form->{title} Lead");
 
 864   # $locale->text('Add Lead')
 
 865   # $locale->text('Edit Lead')
 
 867   $form->{description} =~ s/\"/"/g;
 
 870       qq|<input name=description size=50 value="$form->{lead}">|;
 
 877 <form method=post action=$form->{script}>
 
 879 <input type=hidden name=id value=$form->{id}>
 
 880 <input type=hidden name=type value=lead>
 
 884     <th class=listtop colspan=2>$form->{title}</th>
 
 888     <th align=right>| . $locale->text('Description') . qq|</th>
 
 889     <td>$description</td>
 
 891     <td colspan=2><hr size=3 noshade></td>
 
 896   $lxdebug->leave_sub();
 
 900   $lxdebug->enter_sub();
 
 902   $form->isblank("description", $locale->text('Description missing!'));
 
 903   AM->save_lead(\%myconfig, \%$form);
 
 904   $form->redirect($locale->text('lead saved!'));
 
 906   $lxdebug->leave_sub();
 
 910   $lxdebug->enter_sub();
 
 912   AM->delete_lead(\%myconfig, \%$form);
 
 913   $form->redirect($locale->text('lead deleted!'));
 
 915   $lxdebug->leave_sub();
 
 919   $lxdebug->enter_sub();
 
 921   $form->{title} = "Add";
 
 924     "$form->{script}?action=add_business&login=$form->{login}&password=$form->{password}"
 
 925     unless $form->{callback};
 
 930   $lxdebug->leave_sub();
 
 934   $lxdebug->enter_sub();
 
 936   $form->{title} = "Edit";
 
 938   AM->get_business(\%myconfig, \%$form);
 
 942   $form->{orphaned} = 1;
 
 945   $lxdebug->leave_sub();
 
 949   $lxdebug->enter_sub();
 
 951   AM->business(\%myconfig, \%$form);
 
 954     "$form->{script}?action=list_business&login=$form->{login}&password=$form->{password}";
 
 956   $callback = $form->escape($form->{callback});
 
 958   $form->{title} = $locale->text('Type of Business');
 
 960   @column_index = qw(description discount customernumberinit);
 
 962   $column_header{description} =
 
 963       qq|<th class=listheading width=60%>|
 
 964     . $locale->text('Description')
 
 966   $column_header{discount} =
 
 967       qq|<th class=listheading width=10%>|
 
 968     . $locale->text('Discount')
 
 970   $column_header{customernumberinit} =
 
 971       qq|<th class=listheading>|
 
 972     . $locale->text('Customernumberinit')
 
 982     <th class=listtop>$form->{title}</th>
 
 988         <tr class=listheading>
 
 991   map { print "$column_header{$_}\n" } @column_index;
 
 997   foreach $ref (@{ $form->{ALL} }) {
 
1003         <tr valign=top class=listrow$i>
 
1007       $form->format_amount(\%myconfig, $ref->{discount} * 100);
 
1009       $ref->{description};
 
1010     $column_data{description} =
 
1011       qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$description</td>|;
 
1012     $column_data{discount}           = qq|<td align=right>$discount</td>|;
 
1013     $column_data{customernumberinit} =
 
1014       qq|<td align=right>$ref->{customernumberinit}</td>|;
 
1016     map { print "$column_data{$_}\n" } @column_index;
 
1028   <td><hr size=3 noshade></td>
 
1033 <form method=post action=$form->{script}>
 
1035 <input name=callback type=hidden value="$form->{callback}">
 
1037 <input type=hidden name=type value=business>
 
1039 <input type=hidden name=login value=$form->{login}>
 
1040 <input type=hidden name=password value=$form->{password}>
 
1042 <input class=submit type=submit name=action value="|
 
1043     . $locale->text('Add') . qq|">
 
1051   $lxdebug->leave_sub();
 
1054 sub business_header {
 
1055   $lxdebug->enter_sub();
 
1057   $form->{title}    = $locale->text("$form->{title} Business");
 
1059   # $locale->text('Add Business')
 
1060   # $locale->text('Edit Business')
 
1062   $form->{description} =~ s/\"/"/g;
 
1064     $form->format_amount(\%myconfig, $form->{discount} * 100);
 
1071 <form method=post action=$form->{script}>
 
1073 <input type=hidden name=id value=$form->{id}>
 
1074 <input type=hidden name=type value=business>
 
1078     <th class=listtop colspan=2>$form->{title}</th>
 
1080   <tr height="5"></tr>
 
1082     <th align=right>| . $locale->text('Type of Business') . qq|</th>
 
1083     <td><input name=description size=30 value="$form->{description}"></td>
 
1086     <th align=right>| . $locale->text('Discount') . qq| %</th>
 
1087     <td><input name=discount size=5 value=$form->{discount}></td>
 
1090     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
 
1091     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
 
1093   <td colspan=2><hr size=3 noshade></td>
 
1098   $lxdebug->leave_sub();
 
1102   $lxdebug->enter_sub();
 
1104   $form->isblank("description", $locale->text('Description missing!'));
 
1105   $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
 
1106   AM->save_business(\%myconfig, \%$form);
 
1107   $form->redirect($locale->text('Business saved!'));
 
1109   $lxdebug->leave_sub();
 
1112 sub delete_business {
 
1113   $lxdebug->enter_sub();
 
1115   AM->delete_business(\%myconfig, \%$form);
 
1116   $form->redirect($locale->text('Business deleted!'));
 
1118   $lxdebug->leave_sub();
 
1122   $lxdebug->enter_sub();
 
1124   $form->{title} = "Add";
 
1127     "$form->{script}?action=add_language&login=$form->{login}&password=$form->{password}"
 
1128     unless $form->{callback};
 
1133   $lxdebug->leave_sub();
 
1137   $lxdebug->enter_sub();
 
1139   $form->{title} = "Edit";
 
1141   AM->get_language(\%myconfig, \%$form);
 
1145   $form->{orphaned} = 1;
 
1148   $lxdebug->leave_sub();
 
1152   $lxdebug->enter_sub();
 
1154   AM->language(\%myconfig, \%$form);
 
1157     "$form->{script}?action=list_language&login=$form->{login}&password=$form->{password}";
 
1159   $callback = $form->escape($form->{callback});
 
1161   $form->{title} = $locale->text('Languages');
 
1163   @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
 
1165   $column_header{description} =
 
1166       qq|<th class=listheading width=60%>|
 
1167     . $locale->text('Description')
 
1169   $column_header{template_code} =
 
1170       qq|<th class=listheading width=10%>|
 
1171     . $locale->text('Template Code')
 
1173   $column_header{article_code} =
 
1174       qq|<th class=listheading>|
 
1175     . $locale->text('Article Code')
 
1177   $column_header{output_numberformat} =
 
1178       qq|<th class=listheading>|
 
1179     . $locale->text('Number Format')
 
1181   $column_header{output_dateformat} =
 
1182       qq|<th class=listheading>|
 
1183     . $locale->text('Date Format')
 
1185   $column_header{output_longdates} =
 
1186       qq|<th class=listheading>|
 
1187     . $locale->text('Long Dates')
 
1197     <th class=listtop>$form->{title}</th>
 
1199   <tr height="5"></tr>
 
1203         <tr class=listheading>
 
1206   map { print "$column_header{$_}\n" } @column_index;
 
1212   foreach $ref (@{ $form->{ALL} }) {
 
1218         <tr valign=top class=listrow$i>
 
1222     $column_data{description} =
 
1223       qq|<td><a href=$form->{script}?action=edit_language&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
 
1224     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
 
1225     $column_data{article_code} =
 
1226       qq|<td align=right>$ref->{article_code}</td>|;
 
1227     $column_data{output_numberformat} =
 
1229       ($ref->{output_numberformat} ? $ref->{output_numberformat} :
 
1230        $locale->text("use program settings")) .
 
1232     $column_data{output_dateformat} =
 
1234       ($ref->{output_dateformat} ? $ref->{output_dateformat} :
 
1235        $locale->text("use program settings")) .
 
1237     $column_data{output_longdates} =
 
1239       ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
 
1242     map { print "$column_data{$_}\n" } @column_index;
 
1254   <td><hr size=3 noshade></td>
 
1259 <form method=post action=$form->{script}>
 
1261 <input name=callback type=hidden value="$form->{callback}">
 
1263 <input type=hidden name=type value=language>
 
1265 <input type=hidden name=login value=$form->{login}>
 
1266 <input type=hidden name=password value=$form->{password}>
 
1268 <input class=submit type=submit name=action value="|
 
1269     . $locale->text('Add') . qq|">
 
1277   $lxdebug->leave_sub();
 
1280 sub language_header {
 
1281   $lxdebug->enter_sub();
 
1283   $form->{title}    = $locale->text("$form->{title} Language");
 
1285   # $locale->text('Add Language')
 
1286   # $locale->text('Edit Language')
 
1288   $form->{description} =~ s/\"/"/g;
 
1289   $form->{template_code} =~ s/\"/"/g;
 
1290   $form->{article_code} =~ s/\"/"/g;
 
1296     qq|<option value="">| . $locale->text("use program settings") .
 
1298   foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
 
1300       ($item eq $form->{output_numberformat})
 
1301       ? "<option selected>$item"
 
1307     qq|<option value="">| . $locale->text("use program settings") .
 
1309   foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
 
1311       ($item eq $form->{output_dateformat})
 
1312       ? "<option selected>$item"
 
1320 <form method=post action=$form->{script}>
 
1322 <input type=hidden name=id value=$form->{id}>
 
1323 <input type=hidden name=type value=language>
 
1327     <th class=listtop colspan=2>$form->{title}</th>
 
1329   <tr height="5"></tr>
 
1331     <th align=right>| . $locale->text('Language') . qq|</th>
 
1332     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1335     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1336     <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
 
1339     <th align=right>| . $locale->text('Article Code') . qq|</th>
 
1340     <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
 
1343     <th align=right>| . $locale->text('Number Format') . qq|</th>
 
1344     <td><select name="output_numberformat">$numberformat</select></td>
 
1347     <th align=right>| . $locale->text('Date Format') . qq|</th>
 
1348     <td><select name="output_dateformat">$dateformat</select></td>
 
1351     <th align=right>| . $locale->text('Long Dates') . qq|</th>
 
1352     <td><input type="radio" name="output_longdates" value="1"| .
 
1353     ($form->{output_longdates} ? " checked" : "") .
 
1354     qq|>| . $locale->text("Yes") .
 
1355     qq|<input type="radio" name="output_longdates" value="0"| .
 
1356     ($form->{output_longdates} ? "" : " checked") .
 
1357     qq|>| . $locale->text("No") .
 
1360   <td colspan=2><hr size=3 noshade></td>
 
1365   $lxdebug->leave_sub();
 
1369   $lxdebug->enter_sub();
 
1371   $form->isblank("description", $locale->text('Language missing!'));
 
1372   $form->isblank("template_code", $locale->text('Template Code missing!'));
 
1373   $form->isblank("article_code", $locale->text('Article Code missing!'));
 
1374   AM->save_language(\%myconfig, \%$form);
 
1375   $form->redirect($locale->text('Language saved!'));
 
1377   $lxdebug->leave_sub();
 
1380 sub delete_language {
 
1381   $lxdebug->enter_sub();
 
1383   AM->delete_language(\%myconfig, \%$form);
 
1384   $form->redirect($locale->text('Language deleted!'));
 
1386   $lxdebug->leave_sub();
 
1390 sub add_buchungsgruppe {
 
1391   $lxdebug->enter_sub();
 
1393   # $locale->text("Add Buchungsgruppe")
 
1394   # $locale->text("Edit Buchungsgruppe")
 
1395   $form->{title} = "Add";
 
1398     "$form->{script}?action=add_buchungsgruppe&login=$form->{login}&password=$form->{password}"
 
1399     unless $form->{callback};
 
1400   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1401   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
 
1402   for (my $i = 0; 4 > $i; $i++) {
 
1403     map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
 
1404         qw(income expense));
 
1407   &buchungsgruppe_header;
 
1410   $lxdebug->leave_sub();
 
1413 sub edit_buchungsgruppe {
 
1414   $lxdebug->enter_sub();
 
1416   $form->{title} = "Edit";
 
1418   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1420   &buchungsgruppe_header;
 
1424   $lxdebug->leave_sub();
 
1427 sub list_buchungsgruppe {
 
1428   $lxdebug->enter_sub();
 
1430   AM->buchungsgruppe(\%myconfig, \%$form);
 
1433     "$form->{script}?action=list_buchungsgruppe&login=$form->{login}&password=$form->{password}";
 
1435   $callback = $form->escape($form->{callback});
 
1437   $form->{title} = $locale->text('Buchungsgruppen');
 
1439   @column_index = qw(up down description inventory_accno
 
1440                      income_accno_0 expense_accno_0
 
1441                      income_accno_1 expense_accno_1
 
1442                      income_accno_2 expense_accno_2
 
1443                      income_accno_3 expense_accno_3 );
 
1445   $column_header{up} =
 
1446       qq|<th class="listheading" width="16">|
 
1447     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
1449   $column_header{down} =
 
1450       qq|<th class="listheading" width="16">|
 
1451     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
1453   $column_header{description} =
 
1454       qq|<th class="listheading" width="40%">|
 
1455     . $locale->text('Description')
 
1457   $column_header{inventory_accno} =
 
1458       qq|<th class=listheading>|
 
1459     . $locale->text('Bestandskonto')
 
1461   $column_header{income_accno_0} =
 
1462       qq|<th class=listheading>|
 
1463     . $locale->text('National Revenues')
 
1465   $column_header{expense_accno_0} =
 
1466       qq|<th class=listheading>|
 
1467     . $locale->text('National Expenses')
 
1469   $column_header{income_accno_1} =
 
1470       qq|<th class=listheading>|
 
1471     . $locale->text('Revenues EU with UStId')
 
1473   $column_header{expense_accno_1} =
 
1474       qq|<th class=listheading>|
 
1475     . $locale->text('Expenses EU with UStId')
 
1477   $column_header{income_accno_2} =
 
1478       qq|<th class=listheading>|
 
1479     . $locale->text('Revenues EU without UStId')
 
1481   $column_header{expense_accno_2} =
 
1482       qq|<th class=listheading>|
 
1483     . $locale->text('Expenses EU without UStId')
 
1485   $column_header{income_accno_3} =
 
1486       qq|<th class=listheading>|
 
1487     . $locale->text('Foreign Revenues')
 
1489   $column_header{expense_accno_3} =
 
1490       qq|<th class=listheading>|
 
1491     . $locale->text('Foreign Expenses')
 
1500     <th class=listtop>$form->{title}</th>
 
1502   <tr height="5"></tr>
 
1506         <tr class=listheading>
 
1509   map { print "$column_header{$_}\n" } @column_index;
 
1515   my $swap_link = qq|$form->{script}?action=swap_buchungsgruppen&|;
 
1516   map({ $swap_link .= $_ . "=" . $form->escape($form->{$_}) . "&" }
 
1517       qw(login password));
 
1520   foreach $ref (@{ $form->{ALL} }) {
 
1526         <tr valign=top class=listrow$i>
 
1530       my $pref = $form->{ALL}->[$row - 1];
 
1532         qq|<td align="center" valign="center" width="16">| .
 
1533         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
 
1534         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
1537       $column_data{up} = qq|<td width="16"> </td>|;
 
1540     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
1541       $column_data{down} = qq|<td width="16"> </td>|;
 
1543       my $nref = $form->{ALL}->[$row + 1];
 
1544       $column_data{down} =
 
1545         qq|<td align="center" valign="center" width="16">| .
 
1546         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
 
1547         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
1551     $column_data{description} =
 
1552       qq|<td><a href=$form->{script}?action=edit_buchungsgruppe&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
 
1553     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
 
1554     $column_data{income_accno_0} =
 
1555       qq|<td align=right>$ref->{income_accno_0}</td>|;
 
1556     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
 
1557     $column_data{income_accno_1} =
 
1558       qq|<td align=right>$ref->{income_accno_1}</td>|;
 
1559     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
 
1560     $column_data{income_accno_2} =
 
1561       qq|<td align=right>$ref->{income_accno_2}</td>|;
 
1562     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
 
1563     $column_data{income_accno_3} =
 
1564       qq|<td align=right>$ref->{income_accno_3}</td>|;
 
1565     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
 
1567     map { print "$column_data{$_}\n" } @column_index;
 
1581   <td><hr size=3 noshade></td>
 
1586 <form method=post action=$form->{script}>
 
1588 <input name=callback type=hidden value="$form->{callback}">
 
1590 <input type=hidden name=type value=buchungsgruppe>
 
1592 <input type=hidden name=login value=$form->{login}>
 
1593 <input type=hidden name=password value=$form->{password}>
 
1595 <input class=submit type=submit name=action value="|
 
1596     . $locale->text('Add') . qq|">
 
1604   $lxdebug->leave_sub();
 
1607 sub buchungsgruppe_header {
 
1608   $lxdebug->enter_sub();
 
1610   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
 
1612   # $locale->text('Add Accounting Group')
 
1613   # $locale->text('Edit Accounting Group')
 
1615   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
 
1616   my %acc_type_map = (
 
1617     "IC" => $acc_inventory,
 
1618     "IC_income" => $acc_income,
 
1619     "IC_sale" => $acc_income,
 
1620     "IC_expense" => $acc_expense,
 
1621     "IC_cogs" => $acc_expense,
 
1624   foreach $key (keys(%acc_type_map)) {
 
1625     foreach $ref (@{ $form->{IC_links}{$key} }) {
 
1626       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
 
1630   foreach my $type (qw(IC IC_income IC_expense)) {
 
1631     $form->{"select$type"} =
 
1633            map({ "<option value=$_->{id} $_->{selected}>" .
 
1634                    "$_->{accno}--" . H($_->{description}) . "</option>" }
 
1635                sort({ $a->{"accno"} cmp $b->{"accno"} }
 
1636                     values(%{$acc_type_map{$type}}))));
 
1640     $form->{selectIC} =~ s/selected//g;
 
1641     $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/  value=$form->{inventory_accno_id} selected/;
 
1642     $form->{selectIC_income} =~ s/selected//g;
 
1643     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/  value=$form->{income_accno_id_0} selected/;
 
1644     $form->{selectIC_expense} =~ s/selected//g;
 
1645     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
 
1651                 <th align=right>| . $locale->text('Inventory') . qq|</th>
 
1652                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
 
1653                 <input name=selectIC type=hidden value="$form->{selectIC}">
 
1657                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
 
1661   $linkaccounts .= qq|
 
1663                 <th align=right>| . $locale->text('National Revenues') . qq|</th>
 
1664                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
 
1667                 <th align=right>| . $locale->text('National Expenses') . qq|</th>
 
1668                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
 
1671     $form->{selectIC_income} =~ s/selected//g;
 
1672     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/  value=$form->{income_accno_id_1} selected/;
 
1673     $form->{selectIC_expense} =~ s/selected//g;
 
1674     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/  value=$form->{expense_accno_id_1} selected/;
 
1676   $linkaccounts .= qq|        <tr>
 
1677                 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
 
1678                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
 
1681                 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
 
1682                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
 
1686     $form->{selectIC_income} =~ s/selected//g;
 
1687     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/  value=$form->{income_accno_id_2} selected/;
 
1688     $form->{selectIC_expense} =~ s/selected//g;
 
1689     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/  value=$form->{expense_accno_id_2} selected/;
 
1692   $linkaccounts .= qq|        <tr>
 
1693                 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
 
1694                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
 
1697                 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
 
1698                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
 
1702     $form->{selectIC_income} =~ s/selected//g;
 
1703     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/  value=$form->{income_accno_id_3} selected/;
 
1704     $form->{selectIC_expense} =~ s/selected//g;
 
1705     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/  value=$form->{expense_accno_id_3} selected/;
 
1708   $linkaccounts .= qq|        <tr>
 
1709                 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
 
1710                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
 
1713                 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
 
1714                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
 
1724 <form method=post action=$form->{script}>
 
1726 <input type=hidden name=id value=$form->{id}>
 
1727 <input type=hidden name=type value=buchungsgruppe>
 
1731     <th class=listtop colspan=2>$form->{title}</th>
 
1733   <tr height="5"></tr>
 
1735     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
 
1736     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1739   <td colspan=2><hr size=3 noshade></td>
 
1744   $lxdebug->leave_sub();
 
1747 sub save_buchungsgruppe {
 
1748   $lxdebug->enter_sub();
 
1750   $form->isblank("description", $locale->text('Description missing!'));
 
1752   AM->save_buchungsgruppe(\%myconfig, \%$form);
 
1753   $form->redirect($locale->text('Accounting Group saved!'));
 
1755   $lxdebug->leave_sub();
 
1758 sub delete_buchungsgruppe {
 
1759   $lxdebug->enter_sub();
 
1761   AM->delete_buchungsgruppe(\%myconfig, \%$form);
 
1762   $form->redirect($locale->text('Accounting Group deleted!'));
 
1764   $lxdebug->leave_sub();
 
1767 sub swap_buchungsgruppen {
 
1768   $lxdebug->enter_sub();
 
1770   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
 
1771   list_buchungsgruppe();
 
1773   $lxdebug->leave_sub();
 
1778   $lxdebug->enter_sub();
 
1780   $form->{title} = "Add";
 
1783     "$form->{script}?action=add_printer&login=$form->{login}&password=$form->{password}"
 
1784     unless $form->{callback};
 
1789   $lxdebug->leave_sub();
 
1793   $lxdebug->enter_sub();
 
1795   $form->{title} = "Edit";
 
1797   AM->get_printer(\%myconfig, \%$form);
 
1801   $form->{orphaned} = 1;
 
1804   $lxdebug->leave_sub();
 
1808   $lxdebug->enter_sub();
 
1810   AM->printer(\%myconfig, \%$form);
 
1813     "$form->{script}?action=list_printer&login=$form->{login}&password=$form->{password}";
 
1815   $callback = $form->escape($form->{callback});
 
1817   $form->{title} = $locale->text('Printer');
 
1819   @column_index = qw(printer_description printer_command template_code);
 
1821   $column_header{printer_description} =
 
1822       qq|<th class=listheading width=60%>|
 
1823     . $locale->text('Printer Description')
 
1825   $column_header{printer_command} =
 
1826       qq|<th class=listheading width=10%>|
 
1827     . $locale->text('Printer Command')
 
1829   $column_header{template_code} =
 
1830       qq|<th class=listheading>|
 
1831     . $locale->text('Template Code')
 
1841     <th class=listtop>$form->{title}</th>
 
1843   <tr height="5"></tr>
 
1847         <tr class=listheading>
 
1850   map { print "$column_header{$_}\n" } @column_index;
 
1856   foreach $ref (@{ $form->{ALL} }) {
 
1862         <tr valign=top class=listrow$i>
 
1866     $column_data{printer_description} =
 
1867       qq|<td><a href=$form->{script}?action=edit_printer&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{printer_description}</td>|;
 
1868     $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
 
1869     $column_data{template_code} =
 
1870       qq|<td align=right>$ref->{template_code}</td>|;
 
1872     map { print "$column_data{$_}\n" } @column_index;
 
1884   <td><hr size=3 noshade></td>
 
1889 <form method=post action=$form->{script}>
 
1891 <input name=callback type=hidden value="$form->{callback}">
 
1893 <input type=hidden name=type value=printer>
 
1895 <input type=hidden name=login value=$form->{login}>
 
1896 <input type=hidden name=password value=$form->{password}>
 
1898 <input class=submit type=submit name=action value="|
 
1899     . $locale->text('Add') . qq|">
 
1907   $lxdebug->leave_sub();
 
1910 sub printer_header {
 
1911   $lxdebug->enter_sub();
 
1913   $form->{title}    = $locale->text("$form->{title} Printer");
 
1915   # $locale->text('Add Printer')
 
1916   # $locale->text('Edit Printer')
 
1918   $form->{printer_description} =~ s/\"/"/g;
 
1919   $form->{template_code} =~ s/\"/"/g;
 
1920   $form->{printer_command} =~ s/\"/"/g;
 
1928 <form method=post action=$form->{script}>
 
1930 <input type=hidden name=id value=$form->{id}>
 
1931 <input type=hidden name=type value=printer>
 
1935     <th class=listtop colspan=2>$form->{title}</th>
 
1937   <tr height="5"></tr>
 
1939     <th align=right>| . $locale->text('Printer') . qq|</th>
 
1940     <td><input name=printer_description size=30 value="$form->{printer_description}"></td>
 
1943     <th align=right>| . $locale->text('Printer Command') . qq|</th>
 
1944     <td><input name=printer_command size=30 value="$form->{printer_command}"></td>
 
1947     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1948     <td><input name=template_code size=5 value="$form->{template_code}"></td>
 
1950   <td colspan=2><hr size=3 noshade></td>
 
1955   $lxdebug->leave_sub();
 
1959   $lxdebug->enter_sub();
 
1961   $form->isblank("printer_description", $locale->text('Description missing!'));
 
1962   $form->isblank("printer_command", $locale->text('Printer Command missing!'));
 
1963   AM->save_printer(\%myconfig, \%$form);
 
1964   $form->redirect($locale->text('Printer saved!'));
 
1966   $lxdebug->leave_sub();
 
1969 sub delete_printer {
 
1970   $lxdebug->enter_sub();
 
1972   AM->delete_printer(\%myconfig, \%$form);
 
1973   $form->redirect($locale->text('Printer deleted!'));
 
1975   $lxdebug->leave_sub();
 
1979   $lxdebug->enter_sub();
 
1981   $form->{title} = "Add";
 
1984     "$form->{script}?action=add_payment&login=$form->{login}&password=$form->{password}"
 
1985     unless $form->{callback};
 
1987   $form->{terms_netto} = 0;
 
1988   $form->{terms_skonto} = 0;
 
1989   $form->{percent_skonto} = 0;
 
1990   my @languages = AM->language(\%myconfig, $form, 1);
 
1991   map({ $_->{"language"} = $_->{"description"};
 
1992         $_->{"language_id"} = $_->{"id"}; } @languages);
 
1993   $form->{"TRANSLATION"} = \@languages;
 
1997   $lxdebug->leave_sub();
 
2001   $lxdebug->enter_sub();
 
2003   $form->{title} = "Edit";
 
2005   AM->get_payment(\%myconfig, $form);
 
2006   $form->{percent_skonto} =
 
2007     $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
 
2011   $form->{orphaned} = 1;
 
2014   $lxdebug->leave_sub();
 
2018   $lxdebug->enter_sub();
 
2020   AM->payment(\%myconfig, \%$form);
 
2022   $form->{callback} = build_std_url("action=list_payment");
 
2024   $callback = $form->escape($form->{callback});
 
2026   $form->{title} = $locale->text('Payment Terms');
 
2028   @column_index = qw(up down description description_long terms_netto
 
2029                      terms_skonto percent_skonto);
 
2031   $column_header{up} =
 
2032       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2033     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
2035   $column_header{down} =
 
2036       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2037     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
2039   $column_header{description} =
 
2040       qq|<th class=listheading>|
 
2041     . $locale->text('Description')
 
2043   $column_header{description_long} =
 
2044       qq|<th class=listheading>|
 
2045     . $locale->text('Long Description')
 
2047   $column_header{terms_netto} =
 
2048       qq|<th class=listheading>|
 
2049     . $locale->text('Netto Terms')
 
2051   $column_header{terms_skonto} =
 
2052       qq|<th class=listheading>|
 
2053     . $locale->text('Skonto Terms')
 
2055   $column_header{percent_skonto} =
 
2056       qq|<th class=listheading>|
 
2057     . $locale->text('Skonto')
 
2067     <th class=listtop>$form->{title}</th>
 
2069   <tr height="5"></tr>
 
2073         <tr class=listheading>
 
2076   map { print "$column_header{$_}\n" } @column_index;
 
2082   my $swap_link = build_std_url("action=swap_payment_terms");
 
2085   foreach $ref (@{ $form->{ALL} }) {
 
2091         <tr valign=top class=listrow$i>
 
2095       my $pref = $form->{ALL}->[$row - 1];
 
2097         qq|<td align="center" valign="center" width="16">| .
 
2098         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
 
2099         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
2102       $column_data{up} = qq|<td width="16"> </td>|;
 
2105     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
2106       $column_data{down} = qq|<td width="16"> </td>|;
 
2108       my $nref = $form->{ALL}->[$row + 1];
 
2109       $column_data{down} =
 
2110         qq|<td align="center" valign="center" width="16">| .
 
2111         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
 
2112         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
2116     $column_data{description} =
 
2118       build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
 
2119       qq|">| . H($ref->{description}) . qq|</a></td>|;
 
2120     $column_data{description_long} =
 
2121       qq|<td>| . H($ref->{description_long}) . qq|</td>|;
 
2122     $column_data{terms_netto} =
 
2123       qq|<td align=right>$ref->{terms_netto}</td>|;
 
2124     $column_data{terms_skonto} =
 
2125       qq|<td align=right>$ref->{terms_skonto}</td>|;
 
2126     $column_data{percent_skonto} =
 
2127       qq|<td align=right>| .
 
2128       $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
 
2130     map { print "$column_data{$_}\n" } @column_index;
 
2143   <td><hr size=3 noshade></td>
 
2148 <form method=post action=$form->{script}>
 
2150 <input name=callback type=hidden value="$form->{callback}">
 
2152 <input type=hidden name=type value=payment>
 
2154 <input type=hidden name=login value=$form->{login}>
 
2155 <input type=hidden name=password value=$form->{password}>
 
2157 <input class=submit type=submit name=action value="|
 
2158     . $locale->text('Add') . qq|">
 
2166   $lxdebug->leave_sub();
 
2169 sub payment_header {
 
2170   $lxdebug->enter_sub();
 
2172   $form->{title}    = $locale->text("$form->{title} Payment Terms");
 
2174   # $locale->text('Add Payment Terms')
 
2175   # $locale->text('Edit Payment Terms')
 
2177   $form->{description} =~ s/\"/"/g;
 
2186 <form method=post action=$form->{script}>
 
2188 <input type=hidden name=id value=$form->{id}>
 
2189 <input type=hidden name=type value=payment>
 
2193     <th class=listtop colspan=2>$form->{title}</th>
 
2195   <tr height="5"></tr>
 
2197     <th align=right>| . $locale->text('Description') . qq|</th>
 
2198     <td><input name=description size=30 value="$form->{description}"></td>
 
2201     <th align=right>| . $locale->text('Long Description') . qq|</th>
 
2202     <td><input name=description_long size=50 value="$form->{description_long}"></td>
 
2206   foreach my $language (@{ $form->{"TRANSLATION"} }) {
 
2209     <th align="right">| .
 
2210     sprintf($locale->text('Translation (%s)'),
 
2211             $language->{"language"})
 
2213     <td><input name="description_long_$language->{language_id}" size="50"
 
2214          value="| . Q($language->{"description_long"}) . qq|"></td>
 
2221     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
 
2222     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
 
2225     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
 
2226     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
 
2229     <th align=right>| . $locale->text('Skonto') . qq| %</th>
 
2230     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
 
2232   <td colspan=2><hr size=3 noshade></td>
 
2236 <p>| . $locale->text("You can use the following strings in the long " .
 
2237                      "description and all translations. They will be " .
 
2238                      "replaced by their actual values by Lx-Office " .
 
2239                      "before they're output.")
 
2243   <li>| . $locale->text("<%netto_date%> -- Date the payment is due in " .
 
2246   <li>| . $locale->text("<%skonto_date%> -- Date the payment is due " .
 
2249   <li>| . $locale->text("<%skonto_amount%> -- The deductible amount")
 
2251   <li>| . $locale->text("<%total%> -- Amount payable")
 
2253   <li>| . $locale->text("<%total_wo_skonto%> -- Amount payable less discount")
 
2255   <li>| . $locale->text("<%invtotal%> -- Invoice total")
 
2257   <li>| . $locale->text("<%invtotal_wo_skonto%> -- Invoice total less discount")
 
2259   <li>| . $locale->text("<%currency%> -- The selected currency")
 
2261   <li>| . $locale->text("<%terms_netto%> -- The number of days for " .
 
2264   <li>| . $locale->text("<%account_number%> -- Your account number")
 
2266   <li>| . $locale->text("<%bank%> -- Your bank")
 
2268   <li>| . $locale->text("<%bank_code%> -- Your bank code")
 
2272   $lxdebug->leave_sub();
 
2276   $lxdebug->enter_sub();
 
2278   $form->isblank("description", $locale->text('Description missing!'));
 
2279   $form->{"percent_skonto"} =
 
2280     $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
 
2281   AM->save_payment(\%myconfig, \%$form);
 
2282   $form->redirect($locale->text('Payment Terms saved!'));
 
2284   $lxdebug->leave_sub();
 
2287 sub delete_payment {
 
2288   $lxdebug->enter_sub();
 
2290   AM->delete_payment(\%myconfig, \%$form);
 
2291   $form->redirect($locale->text('Payment terms deleted!'));
 
2293   $lxdebug->leave_sub();
 
2296 sub swap_payment_terms {
 
2297   $lxdebug->enter_sub();
 
2299   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
 
2302   $lxdebug->leave_sub();
 
2305 sub _build_cfg_options {
 
2307   my $array = uc($idx) . 'S';
 
2309   $form->{$array} = [];
 
2310   foreach my $item (@_) {
 
2311     push @{ $form->{$array} }, {
 
2314       'selected' => $item eq $myconfig{$idx},
 
2320   $lxdebug->enter_sub();
 
2322   # get defaults for account numbers and last numbers
 
2323   AM->defaultaccounts(\%myconfig, \%$form);
 
2325   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
 
2327   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
2328   _build_cfg_options('numberformat', qw(1,000.00 1000.00 1.000,00 1000,00));
 
2331   if ($opendocument_templates && $openofficeorg_writer_bin &&
 
2332       $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
 
2333     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
2334                      "value" => "opendocument_pdf" });
 
2336   if ($latex_templates) {
 
2337     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
2339   push(@formats, { "name" => "HTML", "value" => "html" });
 
2340   if ($latex_templates) {
 
2341     push(@formats, { "name" => $locale->text("Postscript"),
 
2342                      "value" => "postscript" });
 
2344   if ($opendocument_templates) {
 
2345     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
2346                      "value" => "opendocument" });
 
2349   if (!$myconfig{"template_format"}) {
 
2350     $myconfig{"template_format"} = "pdf";
 
2352   $form->{TEMPLATE_FORMATS} = [];
 
2353   foreach $item (@formats) {
 
2354     push @{ $form->{TEMPLATE_FORMATS} }, {
 
2355       'name'     => $item->{name},
 
2356       'value'    => $item->{value},
 
2357       'selected' => $item->{value} eq $myconfig{template_format},
 
2361   if (!$myconfig{"default_media"}) {
 
2362     $myconfig{"default_media"} = "screen";
 
2365   my %selected = ($myconfig{"default_media"} => "selected");
 
2367     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
2368     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
2369     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
2372   AM->printer(\%myconfig, $form);
 
2374   $form->{PRINTERS} = [];
 
2375   foreach my $printer (@{$form->{"ALL"}}) {
 
2376     push @{ $form->{PRINTERS} }, {
 
2377       'name'     => $printer->{printer_description},
 
2378       'value'    => $printer->{id},
 
2379       'selected' => $printer->{id} == $myconfig{default_printer_id},
 
2383   %countrycodes = User->country_codes;
 
2385   $countrycodes{""} = "American English";
 
2386   $form->{COUNTRYCODES} = [];
 
2387   foreach $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
2388     push @{ $form->{COUNTRYCODES} }, {
 
2389       'name'     => $countrycodes{$countrycode},
 
2390       'value'    => $countrycode,
 
2391       'selected' => $countrycode eq $myconfig{countrycode},
 
2395   foreach $key (keys %{ $form->{IC} }) {
 
2396     foreach $accno (sort keys %{ $form->{IC}->{$key} }) {
 
2397       my $array = "ACCNOS_" . uc($key);
 
2398       $form->{$array} ||= [];
 
2400       my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
 
2401       push @{ $form->{$array} }, {
 
2404         'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
 
2409   $form->{STYLESHEETS} = [];
 
2410   foreach $item (qw(lx-office-erp.css Win2000.css)) {
 
2411     push @{ $form->{STYLESHEETS} }, {
 
2414       'selected' => $item eq $myconfig{stylesheet},
 
2418   $myconfig{show_form_details}              = 1 unless (defined($myconfig{show_form_details}));
 
2419   $form->{"menustyle_$myconfig{menustyle}"} = 1;
 
2421   $form->{title}                            = $locale->text('Edit Preferences for #1', $form->{login});
 
2424   print $form->parse_html_template2('am/config');
 
2426   $lxdebug->leave_sub();
 
2429 sub save_preferences {
 
2430   $lxdebug->enter_sub();
 
2432   $form->{stylesheet} = $form->{usestylesheet};
 
2434   $form->redirect($locale->text('Preferences saved!'))
 
2436      AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath, $webdav
 
2438   $form->error($locale->text('Cannot save preferences!'));
 
2440   $lxdebug->leave_sub();
 
2444   $lxdebug->enter_sub();
 
2446   $form->{title} = $locale->text('Audit Control');
 
2448   AM->closedto(\%myconfig, \%$form);
 
2450   if ($form->{revtrans}) {
 
2451     $checked{Y} = "checked";
 
2453     $checked{N} = "checked";
 
2461 <form method=post action=$form->{script}>
 
2463 <input type=hidden name=login value=$form->{login}>
 
2464 <input type=hidden name=password value=$form->{password}>
 
2467   <tr><th class=listtop>$form->{title}</th></tr>
 
2468   <tr height="5"></tr>
 
2474     . $locale->text('Enforce transaction reversal for all dates') . qq|</th>
 
2475           <td><input name=revtrans class=radio type=radio value="1" $checked{Y}> |
 
2476     . $locale->text('Yes')
 
2477     . qq| <input name=revtrans class=radio type=radio value="0" $checked{N}> |
 
2478     . $locale->text('No')
 
2482           <th>| . $locale->text('Close Books up to') . qq|</th>
 
2483           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
 
2493 <input type=hidden name=nextsub value=doclose>
 
2495 <input type=submit class=submit name=action value="|
 
2496     . $locale->text('Continue') . qq|">
 
2504   $lxdebug->leave_sub();
 
2508   $lxdebug->enter_sub();
 
2510   AM->closebooks(\%myconfig, \%$form);
 
2512   if ($form->{revtrans}) {
 
2514                  $locale->text('Transaction reversal enforced for all dates'));
 
2516     if ($form->{closedto}) {
 
2518                      $locale->text('Transaction reversal enforced up to') . " "
 
2519                        . $locale->date(\%myconfig, $form->{closedto}, 1));
 
2521       $form->redirect($locale->text('Books are open'));
 
2525   $lxdebug->leave_sub();
 
2529   $lxdebug->enter_sub();
 
2531   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
 
2532   AM->units_in_use(\%myconfig, $form, $units);
 
2533   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
2535   @languages = AM->language(\%myconfig, $form, 1);
 
2537   @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
2540   foreach (@unit_list) {
 
2541     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
2542     $_->{"UNITLANGUAGES"} = [];
 
2543     foreach my $lang (@languages) {
 
2544       push(@{ $_->{"UNITLANGUAGES"} },
 
2546              "unit" => $_->{"name"},
 
2547              "language_id" => $lang->{"id"},
 
2548              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
2549              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
2555   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
 
2556   $ddbox = AM->unit_select_data($units, undef, 1);
 
2558   my $updownlink = build_std_url("action=swap_units", "unit_type");
 
2560   $form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units"));
 
2562   print($form->parse_html_template2("am/edit_units",
 
2563                                     { "UNITS"               => \@unit_list,
 
2564                                       "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
2565                                       "LANGUAGES"           => \@languages,
 
2566                                       "updownlink"          => $updownlink }));
 
2568   $lxdebug->leave_sub();
 
2572   $lxdebug->enter_sub();
 
2574   $form->isblank("new_name", $locale->text("The name is missing."));
 
2575   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
 
2576   $all_units = AM->retrieve_units(\%myconfig, $form);
 
2577   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
2579   my ($base_unit, $factor);
 
2580   if ($form->{"new_base_unit"}) {
 
2581     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
2583     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
2584     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
2585     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
2586     $base_unit = $form->{"new_base_unit"};
 
2590   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
2591     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
2592     push(@languages, { "id" => $lang->{"id"},
 
2593                        "localized" => $form->{"new_localized_$lang->{id}"},
 
2594                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
2598   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}, \@languages);
 
2600   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
2604   $lxdebug->leave_sub();
 
2607 sub set_unit_languages {
 
2608   $lxdebug->enter_sub();
 
2610   my ($unit, $languages, $idx) = @_;
 
2612   $unit->{"LANGUAGES"} = [];
 
2614   foreach my $lang (@{$languages}) {
 
2615     push(@{ $unit->{"LANGUAGES"} },
 
2616          { "id" => $lang->{"id"},
 
2617            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
2618            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
2622   $lxdebug->leave_sub();
 
2626   $lxdebug->enter_sub();
 
2628   $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
 
2629   AM->units_in_use(\%myconfig, $form, $old_units);
 
2631   @languages = AM->language(\%myconfig, $form, 1);
 
2635   foreach $i (1..($form->{"rowcount"} * 1)) {
 
2636     $old_unit = $old_units->{$form->{"old_name_$i"}};
 
2638       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
2641     if ($form->{"unchangeable_$i"}) {
 
2642       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
2643       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
2644       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2648     if ($old_unit->{"in_use"}) {
 
2649       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
2652     if ($form->{"delete_$i"}) {
 
2653       push(@delete_units, $old_unit->{"name"});
 
2657     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
2659     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
2660     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
2661     $new_units->{$form->{"name_$i"}} = \%h;
 
2662     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
2663     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2666   foreach $unit (values(%{$new_units})) {
 
2667     next unless ($unit->{"old_name"});
 
2668     if ($unit->{"base_unit"}) {
 
2669       $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"}))
 
2670         unless (defined($new_units->{$unit->{"base_unit"}}));
 
2671       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
2672       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
2674       $unit->{"base_unit"} = undef;
 
2675       $unit->{"factor"} = undef;
 
2679   foreach $unit (values(%{$new_units})) {
 
2680     next if ($unit->{"unchanged_unit"});
 
2682     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
2684     while ($new_unit->{"base_unit"}) {
 
2685       $new_unit->{"seen"} = 1;
 
2686       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
2687       if ($new_unit->{"seen"}) {
 
2688         $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, " .
 
2689                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
2694   AM->save_units(\%myconfig, $form, $form->{"unit_type"}, $new_units, \@delete_units);
 
2696   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
2700   $lxdebug->leave_sub();
 
2703 sub show_history_search {
 
2704         $lxdebug->enter_sub();
 
2706         $form->{title} = $locale->text("History Search");
 
2709     print $form->parse_html_template2("common/search_history");
 
2711         $lxdebug->leave_sub();
 
2714 sub show_am_history {
 
2715         $lxdebug->enter_sub();
 
2716         my %search = ( "Artikelnummer" => "parts",
 
2717                                    "Kundennummer"  => "customer",
 
2718                                    "Lieferantennummer" => "vendor",
 
2719                                    "Projektnummer" => "project",
 
2720                                    "Buchungsnummer" => "oe",
 
2721                                    "Eingangsrechnungnummer" => "ap",
 
2722                                    "Ausgangsrechnungnummer" => "ar",
 
2723            "Mahnungsnummer" => "dunning"
 
2725         my %searchNo = ( "Artikelnummer" => "partnumber",
 
2726                                      "Kundennummer"  => "customernumber",
 
2727                                      "Lieferantennummer" => "vendornumber",
 
2728                                      "Projektnummer" => "projectnummer",
 
2729                                      "Buchungsnummer" => "ordnumber",
 
2730                                      "Eingangsrechnungnummer" => "invnumber",
 
2731                                      "Ausgangsrechnungnummer" => "invnumber",
 
2732              "Mahnungsnummer" => "dunning_id"
 
2737         foreach(split(/\,/, $form->{einschraenkungen})) {
 
2739                         $restriction .= " AND addition = '" . $_ . "'";
 
2743                         $restriction .= " OR addition = '" . $_ . "'";
 
2746         $restriction .= (($form->{transdate} ne "" && $form->{reqdate} ne "") 
 
2747                                                 ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|' AND st.itime::date <= '| . $form->{reqdate} . qq|'|
 
2748                                                 : (($form->{transdate} ne "" && $form->{reqdate} eq "") 
 
2749                                                         ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|'|
 
2750                                                         : ($form->{transdate} eq "" && $form->{reqdate} ne "") 
 
2751                                                                 ? qq| AND st.itime::date <= '| . $form->{reqdate} . qq|'|
 
2755   $restriction .= ($form->{mitarbeiter} eq "" ? "" 
 
2756           : ($form->{mitarbeiter} =~ /^[0-9]*$/  
 
2757             ? " AND employee_id = " . $form->{mitarbeiter} 
 
2758             : " AND employee_id = " . &get_employee_id($form->{mitarbeiter}, $dbh)));
 
2760         my $dbh = $form->dbconnect(\%myconfig);
 
2761         my $query = qq|SELECT trans_id AS id FROM history_erp | . 
 
2762                 ($form->{'searchid'} ? 
 
2763                   qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'| : 
 
2764                   qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
2766   my $sth = $dbh->prepare($query);
 
2768         $sth->execute() || $form->dberror($query);
 
2770   $form->{title} = $locale->text("History Search");
 
2775   while(my $hash_ref = $sth->fetchrow_hashref()){
 
2777       $daten .= $hash_ref->{id};
 
2781       $daten .= " OR trans_id = " . $hash_ref->{id};
 
2785   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
2786   $sort =~ s/.*\.(.*)$/$1/;
 
2788         print $form->parse_html_template2("common/show_history", 
 
2789     {"DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
2790      "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
2793      uc($sort)."BY" => $sortby
 
2796   $lxdebug->leave_sub();
 
2799 sub get_employee_id {
 
2800         $lxdebug->enter_sub();
 
2801         my $query = qq|SELECT id FROM employee WHERE name = '| . $_[0] . qq|'|;
 
2802         my $sth = $_[1]->prepare($query);
 
2803         $sth->execute() || $form->dberror($query);
 
2804         my $return = $sth->fetch();
 
2806         return ${$return}[0];
 
2807         $lxdebug->leave_sub();
 
2811   $lxdebug->enter_sub();
 
2813   my $dir = $form->{"dir"} eq "down" ? "down" : "up";
 
2814   my $unit_type = $form->{"unit_type"} eq "dimension" ?
 
2815     "dimension" : "service";
 
2816   AM->swap_units(\%myconfig, $form, $dir, $form->{"name"}, $unit_type);
 
2820   $lxdebug->leave_sub();
 
2824   $lxdebug->enter_sub();
 
2826   $form->{title} =  $locale->text('Add');
 
2829     "$form->{script}?action=add_tax&login=$form->{login}&password=$form->{password}"
 
2830     unless $form->{callback};
 
2832   _get_taxaccount_selection();
 
2836   my $parameters_ref = {
 
2837 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
2840   # Ausgabe des Templates
 
2841   print($form->parse_html_template2('am/edit_tax', $parameters_ref));
 
2843   $lxdebug->leave_sub();
 
2847   $lxdebug->enter_sub();
 
2849   $form->{title} =  $locale->text('Edit');
 
2851   AM->get_tax(\%myconfig, \%$form);
 
2852   _get_taxaccount_selection();
 
2854   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
2858   my $parameters_ref = {
 
2861   # Ausgabe des Templates
 
2862   print($form->parse_html_template2('am/edit_tax', $parameters_ref));
 
2864   $lxdebug->leave_sub();
 
2868   $lxdebug->enter_sub();
 
2870   AM->taxes(\%myconfig, \%$form);
 
2872   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
2874   $form->{callback} = build_std_url('action=list_tax');
 
2876   $form->{title} = $locale->text('Tax-O-Matic');
 
2880   # Ausgabe des Templates
 
2881   print($form->parse_html_template2('am/list_tax', $parameters_ref));
 
2883   $lxdebug->leave_sub();
 
2886 sub _get_taxaccount_selection{
 
2887   $lxdebug->enter_sub();
 
2889   AM->get_tax_accounts(\%myconfig, \%$form);
 
2891   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
2893   $lxdebug->leave_sub();
 
2897   $lxdebug->enter_sub();
 
2899   $form->isblank("rate", $locale->text('Taxrate missing!'));
 
2900   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
 
2901   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
 
2903   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
2905   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
2906     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
2909   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
2910     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
2913   AM->save_tax(\%myconfig, \%$form);
 
2914   $form->redirect($locale->text('Tax saved!'));
 
2916   $lxdebug->leave_sub();
 
2920   $lxdebug->enter_sub();
 
2922   AM->delete_tax(\%myconfig, \%$form);
 
2923   $form->redirect($locale->text('Tax deleted!'));
 
2925   $lxdebug->leave_sub();
 
2928 sub add_price_factor {
 
2929   $lxdebug->enter_sub();
 
2931   $form->{title}      = $locale->text('Add Price Factor');
 
2932   $form->{callback} ||= build_std_url('action=add_price_factor');
 
2933   $form->{fokus}      = 'description';
 
2936   print $form->parse_html_template2('am/edit_price_factor');
 
2938   $lxdebug->leave_sub();
 
2941 sub edit_price_factor {
 
2942   $lxdebug->enter_sub();
 
2944   $form->{title}      = $locale->text('Edit Price Factor');
 
2945   $form->{callback} ||= build_std_url('action=add_price_factor');
 
2946   $form->{fokus}      = 'description';
 
2948   AM->get_price_factor(\%myconfig, $form);
 
2950   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
 
2953   print $form->parse_html_template2('am/edit_price_factor');
 
2955   $lxdebug->leave_sub();
 
2958 sub list_price_factors {
 
2959   $lxdebug->enter_sub();
 
2961   AM->get_all_price_factors(\%myconfig, \%$form);
 
2964   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
 
2966       $previous->{next_id}    = $current->{id};
 
2967       $current->{previous_id} = $previous->{id};
 
2970     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
 
2972     $previous = $current;
 
2975   $form->{callback} = build_std_url('action=list_price_factors');
 
2976   $form->{title}    = $locale->text('Price Factors');
 
2977   $form->{url_base} = build_std_url('callback');
 
2980   print $form->parse_html_template2('am/list_price_factors');
 
2982   $lxdebug->leave_sub();
 
2985 sub save_price_factor {
 
2986   $lxdebug->enter_sub();
 
2988   $form->isblank("description", $locale->text('Description missing!'));
 
2989   $form->isblank("factor", $locale->text('Factor missing!'));
 
2991   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
 
2993   AM->save_price_factor(\%myconfig, $form);
 
2995   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
 
2997   $form->redirect($locale->text('Price factor saved!'));
 
2999   $lxdebug->leave_sub();
 
3002 sub delete_price_factor {
 
3003   $lxdebug->enter_sub();
 
3005   AM->delete_price_factor(\%myconfig, \%$form);
 
3007   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
 
3009   $form->redirect($locale->text('Price factor deleted!'));
 
3011   $lxdebug->leave_sub();
 
3014 sub swap_price_factors {
 
3015   $lxdebug->enter_sub();
 
3017   AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
 
3018   list_price_factors();
 
3020   $lxdebug->leave_sub();