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";
 
  55 sub add      { call_sub("add_$main::form->{type}"); }
 
  56 sub delete   { call_sub("delete_$main::form->{type}"); }
 
  57 sub save     { call_sub("save_$main::form->{type}"); }
 
  58 sub edit     { call_sub("edit_$main::form->{type}"); }
 
  59 sub continue { call_sub($main::form->{"nextsub"}); }
 
  60 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
  63   $main::lxdebug->enter_sub();
 
  65   my $form     = $main::form;
 
  66   my %myconfig = %main::myconfig;
 
  68   $main::auth->assert('config');
 
  70   $form->{title}     = "Add";
 
  71   $form->{charttype} = "A";
 
  72   AM->get_account(\%myconfig, \%$form);
 
  74   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
 
  79   $main::lxdebug->leave_sub();
 
  83   $main::lxdebug->enter_sub();
 
  85   my $form     = $main::form;
 
  86   my %myconfig = %main::myconfig;
 
  88   $main::auth->assert('config');
 
  90   $form->{title} = "Edit";
 
  91   AM->get_account(\%myconfig, \%$form);
 
  93   foreach my $item (split(/:/, $form->{link})) {
 
  94     $form->{$item} = "checked";
 
 100   $main::lxdebug->leave_sub();
 
 104   $main::lxdebug->enter_sub();
 
 106   my $form     = $main::form;
 
 107   my %myconfig = %main::myconfig;
 
 108   my $locale   = $main::locale;
 
 110   $main::auth->assert('config');
 
 112   if ( $form->{action} eq 'edit_account') {
 
 113     $form->{account_exists} = '1';
 
 116   $form->{title} = $locale->text("$form->{title} Account");
 
 118   $form->{"$form->{charttype}_checked"} = "checked";
 
 119   $form->{"$form->{category}_checked"}  = "checked";
 
 121   $form->{select_tax} = "";
 
 123   my @tax_report_pos = USTVA->report_variables({
 
 124       myconfig   => \%myconfig,
 
 127       attribute  => 'position',
 
 131   if (@{ $form->{TAXKEY} }) {
 
 132     foreach my $item (@{ $form->{TAXKEY} }) {
 
 133       $item->{rate} = $item->{rate} * 100 . '%';
 
 136     # Fill in empty row for new Taxkey
 
 137     my $newtaxkey_ref = {
 
 142       taxdescription => '',
 
 149     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 152     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 154       # Fill in a runningnumber
 
 155       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 157       # Fill in the Taxkeys as select options
 
 158       foreach my $item (@{ $form->{TAXKEY} }) {
 
 159         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 160           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 161             qq|<option value="$item->{id}" selected="selected">|
 
 162             . sprintf("%.2d", $item->{taxkey})
 
 163             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 164             . $locale->text('Tax-o-matic Account')
 
 165             . qq|: $item->{chart_accno}\n|;
 
 168           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 169             qq|<option value="$item->{id}">|
 
 170             . sprintf("%.2d", $item->{taxkey})
 
 171             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 172             . $locale->text('Tax-o-matic Account')
 
 173             . qq|: $item->{chart_accno}\n|;
 
 178       # Fill in the USTVA Numbers as select options
 
 179       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 181           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 183         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 184           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 187           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 196   # Newaccount Folgekonto
 
 197   if (@{ $form->{NEWACCOUNT} || [] }) {
 
 198     if (!$form->{new_chart_valid}) {
 
 199       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 201     foreach my $item (@{ $form->{NEWACCOUNT} }) {
 
 202       if ($item->{id} == $form->{new_chart_id}) {
 
 203         $form->{selectnewaccount} .=
 
 204           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 205       } elsif (!$form->{new_chart_valid}) {
 
 206         $form->{selectnewaccount} .=
 
 207           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 213   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 216           2  => "sonstige Erlöse",
 
 217           3  => "Privatanteile",
 
 219           5  => "Ausserordentliche Erträge",
 
 220           6  => "Vereinnahmte Umsatzst.",
 
 221           7  => "Umsatzsteuererstattungen",
 
 222           8  => "Wareneingänge",
 
 223           9  => "Löhne und Gehälter",
 
 224           10 => "Gesetzl. sozialer Aufw.",
 
 226           12 => "Gas, Strom, Wasser",
 
 227           13 => "Instandhaltung",
 
 228           14 => "Steuern, Versich., Beiträge",
 
 230           16 => "Kfz-Versicherungen",
 
 231           17 => "Sonst. Fahrzeugkosten",
 
 232           18 => "Werbe- und Reisekosten",
 
 233           19 => "Instandhaltung u. Werkzeuge",
 
 234           20 => "Fachzeitschriften, Bücher",
 
 235           21 => "Miete für Einrichtungen",
 
 236           22 => "Rechts- und Beratungskosten",
 
 237           23 => "Bürobedarf, Porto, Telefon",
 
 238           24 => "Sonstige Aufwendungen",
 
 239           25 => "Abschreibungen auf Anlagever.",
 
 240           26 => "Abschreibungen auf GWG",
 
 242           28 => "Umsatzsteuerzahlungen",
 
 244           30 => "Ausserordentlicher Aufwand",
 
 245           31 => "Betriebliche Steuern");
 
 246   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
 
 247     my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $eur{$item}));
 
 248     if ($item == $form->{pos_eur}) {
 
 249       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 251       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 256   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 260              2  => 'Best.Verdg.FE/UE',
 
 261              3  => 'Aktiv.Eigenleistung',
 
 262              4  => 'Mat./Wareneinkauf',
 
 263              5  => 'So.betr.Erlöse',
 
 264              10 => 'Personalkosten',
 
 266              12 => 'Betriebl.Steuern',
 
 267              13 => 'Vers./Beiträge',
 
 268              14 => 'Kfz.Kosten o.St.',
 
 269              15 => 'Werbe-Reisek.',
 
 270              16 => 'Kosten Warenabgabe',
 
 271              17 => 'Abschreibungen',
 
 272              18 => 'Rep./instandhlt.',
 
 273              19 => 'Übrige Steuern',
 
 274              20 => 'Sonst.Kosten',
 
 276              31 => 'Sonst.neutr.Aufw.',
 
 278              33 => 'Sonst.neutr.Ertrag',
 
 279              34 => 'Verr.kalk.Kosten',
 
 280              35 => 'Steuern Eink.u.Ertr.');
 
 281   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
 
 282     my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $bwapos{$item}));
 
 283     if ($item == $form->{pos_bwa}) {
 
 284       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 286       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 291 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 292   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 293   foreach my $item ((1, 2, 3, 4)) {
 
 294     if ($item == $form->{pos_bilanz}) {
 
 295       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 297       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 302   # this is for our parser only! Do not remove.
 
 303   # type=submit $locale->text('Add Account')
 
 304   # type=submit $locale->text('Edit Account')
 
 306   $form->{type} = "account";
 
 308   # preselections category
 
 310   my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 313       'A'  => $locale->text('Asset'),
 
 314       'L'  => $locale->text('Liability'),
 
 315       'Q'  => $locale->text('Equity'),
 
 316       'I'  => $locale->text('Revenue'),
 
 317       'E'  => $locale->text('Expense'),
 
 318       'C'  => $locale->text('Costs'),
 
 320   foreach my $item ( sort({ $a <=> $b } keys %category) ) {
 
 321     if ($item eq $form->{category}) {
 
 322       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 324       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 329   # preselection chart type
 
 330   my $select_charttype = q{};
 
 333       'A'  => $locale->text('Account'),
 
 334       'H'  => $locale->text('Header'),
 
 337   foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
 
 338     if ($item eq $form->{charttype}) {
 
 339       $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
 
 342       $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
 
 347   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 351   my $parameters_ref = {
 
 352     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 353     select_category            => $select_category,
 
 354     select_charttype           => $select_charttype,
 
 355     select_bwa                 => $select_bwa,
 
 356     select_bilanz              => $select_bilanz,
 
 357     select_eur                 => $select_eur,
 
 360   # Ausgabe des Templates
 
 361   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 364   $main::lxdebug->leave_sub();
 
 368   $main::lxdebug->enter_sub();
 
 370   my $form     = $main::form;
 
 371   my $locale   = $main::locale;
 
 373   $main::auth->assert('config');
 
 377 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
 
 380   if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
 
 382 <input type=submit class=submit name=action value="|
 
 383     . $locale->text('Save') . qq|">
 
 387   if ($form->{id} && $form->{orphaned}) {
 
 388     print qq|<input type=submit class=submit name=action value="|
 
 389       . $locale->text('Delete') . qq|">|;
 
 392   if ($form->{id} && $form->{type} eq "account") {
 
 394     <input class=submit type=submit name=action value="|
 
 395       . $locale->text('Save as new') . qq|">|;
 
 405   $main::lxdebug->leave_sub();
 
 409   $main::lxdebug->enter_sub();
 
 411   my $form     = $main::form;
 
 412   my %myconfig = %main::myconfig;
 
 413   my $locale   = $main::locale;
 
 415   $main::auth->assert('config');
 
 417   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 418   $form->isblank("description", $locale->text('Account Description missing!'));
 
 420   if ($form->{charttype} eq 'A'){
 
 421     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 424   $form->redirect($locale->text('Account saved!'))
 
 425     if (AM->save_account(\%myconfig, \%$form));
 
 426   $form->error($locale->text('Cannot save account!'));
 
 428   $main::lxdebug->leave_sub();
 
 431 sub save_as_new_account {
 
 432   $main::lxdebug->enter_sub();
 
 434   my $form     = $main::form;
 
 435   my %myconfig = %main::myconfig;
 
 436   my $locale   = $main::locale;
 
 438   $main::auth->assert('config');
 
 440   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 441   $form->isblank("description", $locale->text('Account Description missing!'));
 
 443   if ($form->{charttype} eq 'A'){
 
 444     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 447   for my $taxkey (0 .. 9) {
 
 448     if ($form->{"taxkey_id_$taxkey"}) {
 
 449       $form->{"taxkey_id_$taxkey"} = "NEW";
 
 454   if ($form->{"original_accno"} &&
 
 455       ($form->{"accno"} eq $form->{"original_accno"})) {
 
 456     $form->error($locale->text('Account Number already used!'));
 
 458   $form->redirect($locale->text('Account saved!'))
 
 459     if (AM->save_account(\%myconfig, \%$form));
 
 460   $form->error($locale->text('Cannot save account!'));
 
 462   $main::lxdebug->leave_sub();
 
 466   $main::lxdebug->enter_sub();
 
 468   my $form     = $main::form;
 
 469   my %myconfig = %main::myconfig;
 
 470   my $locale   = $main::locale;
 
 472   $main::auth->assert('config');
 
 474   $form->{callback}     = build_std_url('action=list_account');
 
 475   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 477   CA->all_accounts(\%myconfig, \%$form);
 
 479   foreach my $ca (@{ $form->{CA} }) {
 
 484     if ($ca->{amount} > 0) {
 
 485       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 487     if ($ca->{amount} < 0) {
 
 488       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 490     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:'';
 
 491     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 495   my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
 
 497   # Eneable AJAX debuging
 
 501   push(@ { $form->{AJAX} }, $pjx);
 
 503   $form->{stylesheets} = "list_accounts.css";
 
 504   $form->{title}       = $locale->text('Chart of Accounts');
 
 509   my $parameters_ref = {
 
 510   #   hidden_variables                => $_hidden_variables_ref,
 
 513   # Ausgabe des Templates
 
 514   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
 516   $main::lxdebug->leave_sub();
 
 521 sub list_account_details {
 
 522 # Ajax Funktion aus list_account_details
 
 523   $main::lxdebug->enter_sub();
 
 525   my $form     = $main::form;
 
 526   my %myconfig = %main::myconfig;
 
 527   my $locale   = $main::locale;
 
 529   $main::auth->assert('config');
 
 531   my $chart_id = $form->{args};
 
 533   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 535   foreach my $ca (@{ $form->{CA} }) {
 
 537     $ca->{debit}  = " ";
 
 538     $ca->{credit} = " ";
 
 540     if ($ca->{amount} > 0) {
 
 542         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 544     if ($ca->{amount} < 0) {
 
 546         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 549     my @links = split( q{:}, $ca->{link});
 
 553     foreach my $link (@links){
 
 554       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 555                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 556                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 557                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 558                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 559                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 560                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 561                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 562                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 563                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 564                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 565                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 566                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 567                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 568                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 569 #               : ( $link eq 'CT_tax' )        ? $locale->text('Account Link CT_tax')
 
 570                : $locale->text('Unknown Link') . ': ' . $link;
 
 571       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 574     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 575                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 576                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 577                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 578                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 579                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 580                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 581                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 584   $form->{title} = $locale->text('Chart of Accounts');
 
 587   print $form->parse_html_template('am/list_account_details');
 
 589   $main::lxdebug->leave_sub();
 
 594   $main::lxdebug->enter_sub();
 
 596   my $form     = $main::form;
 
 597   my %myconfig = %main::myconfig;
 
 598   my $locale   = $main::locale;
 
 600   $main::auth->assert('config');
 
 602   $form->{title} = $locale->text('Delete Account');
 
 605     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
 
 607     if ($form->{id} == $form->{$id}) {
 
 608       $form->error($locale->text('Cannot delete default account!'));
 
 612   $form->redirect($locale->text('Account deleted!'))
 
 613     if (AM->delete_account(\%myconfig, \%$form));
 
 614   $form->error($locale->text('Cannot delete account!'));
 
 616   $main::lxdebug->leave_sub();
 
 620   $main::lxdebug->enter_sub();
 
 622   my $form     = $main::form;
 
 624   $main::auth->assert('config');
 
 626   $form->{title} = "Add";
 
 629   $form->{callback} = "am.pl?action=add_department" unless $form->{callback};
 
 634   $main::lxdebug->leave_sub();
 
 637 sub edit_department {
 
 638   $main::lxdebug->enter_sub();
 
 640   my $form     = $main::form;
 
 641   my %myconfig = %main::myconfig;
 
 643   $main::auth->assert('config');
 
 645   $form->{title} = "Edit";
 
 647   AM->get_department(\%myconfig, \%$form);
 
 652   $main::lxdebug->leave_sub();
 
 655 sub list_department {
 
 656   $main::lxdebug->enter_sub();
 
 658   my $form     = $main::form;
 
 659   my %myconfig = %main::myconfig;
 
 660   my $locale   = $main::locale;
 
 662   $main::auth->assert('config');
 
 664   AM->departments(\%myconfig, \%$form);
 
 666   $form->{callback} = "am.pl?action=list_department";
 
 668   my $callback = $form->escape($form->{callback});
 
 670   $form->{title} = $locale->text('Departments');
 
 672   my @column_index = qw(description cost profit);
 
 674   $column_header{description} =
 
 675       qq|<th class=listheading width=90%>|
 
 676     . $locale->text('Description')
 
 678   $column_header{cost} =
 
 679       qq|<th class=listheading nowrap>|
 
 680     . $locale->text('Cost Center')
 
 682   $column_header{profit} =
 
 683       qq|<th class=listheading nowrap>|
 
 684     . $locale->text('Profit Center')
 
 694     <th class=listtop>$form->{title}</th>
 
 700         <tr class=listheading>
 
 703   map { print "$column_header{$_}\n" } @column_index;
 
 709   my ($i, %column_data);
 
 710   foreach my $ref (@{ $form->{ALL} }) {
 
 716         <tr valign=top class=listrow$i>
 
 719     my $costcenter   = ($ref->{role} eq "C") ? "X" : "";
 
 720     my $profitcenter = ($ref->{role} eq "P") ? "X" : "";
 
 722     $column_data{description} =
 
 723       qq|<td><a href="am.pl?action=edit_department&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
 724     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
 
 725     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
 
 727     map { print "$column_data{$_}\n" } @column_index;
 
 739   <td><hr size=3 noshade></td>
 
 744 <form method=post action=am.pl>
 
 746 <input name=callback type=hidden value="$form->{callback}">
 
 748 <input type=hidden name=type value=department>
 
 750 <input class=submit type=submit name=action value="|
 
 751     . $locale->text('Add') . qq|">
 
 759   $main::lxdebug->leave_sub();
 
 762 sub department_header {
 
 763   $main::lxdebug->enter_sub();
 
 765   my $form     = $main::form;
 
 766   my $locale   = $main::locale;
 
 768   $main::auth->assert('config');
 
 770   $form->{title} = $locale->text("$form->{title} Department");
 
 772   # $locale->text('Add Department')
 
 773   # $locale->text('Edit Department')
 
 775   $form->{description} =~ s/\"/"/g;
 
 777   my ($rows, $description);
 
 778   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
 
 780       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
 
 783       qq|<input name=description size=60 value="$form->{description}">|;
 
 786   my $costcenter   = "checked" if $form->{role} eq "C";
 
 787   my $profitcenter = "checked" if $form->{role} eq "P";
 
 794 <form method=post action=am.pl>
 
 796 <input type=hidden name=id value=$form->{id}>
 
 797 <input type=hidden name=type value=department>
 
 801     <th class=listtop colspan=2>$form->{title}</th>
 
 805     <th align=right>| . $locale->text('Description') . qq|</th>
 
 806     <td>$description</td>
 
 810     <td><input type=radio style=radio name=role value="C" $costcenter> |
 
 811     . $locale->text('Cost Center') . qq|
 
 812         <input type=radio style=radio name=role value="P" $profitcenter> |
 
 813     . $locale->text('Profit Center') . qq|
 
 816     <td colspan=2><hr size=3 noshade></td>
 
 821   $main::lxdebug->leave_sub();
 
 824 sub save_department {
 
 825   $main::lxdebug->enter_sub();
 
 827   my $form     = $main::form;
 
 828   my %myconfig = %main::myconfig;
 
 829   my $locale   = $main::locale;
 
 831   $main::auth->assert('config');
 
 833   $form->isblank("description", $locale->text('Description missing!'));
 
 834   AM->save_department(\%myconfig, \%$form);
 
 835   $form->redirect($locale->text('Department saved!'));
 
 837   $main::lxdebug->leave_sub();
 
 840 sub delete_department {
 
 841   $main::lxdebug->enter_sub();
 
 843   my $form     = $main::form;
 
 844   my %myconfig = %main::myconfig;
 
 845   my $locale   = $main::locale;
 
 847   $main::auth->assert('config');
 
 849   AM->delete_department(\%myconfig, \%$form);
 
 850   $form->redirect($locale->text('Department deleted!'));
 
 852   $main::lxdebug->leave_sub();
 
 856   $main::lxdebug->enter_sub();
 
 858   my $form     = $main::form;
 
 860   $main::auth->assert('config');
 
 862   $form->{title} = "Add";
 
 864   $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
 
 869   $main::lxdebug->leave_sub();
 
 873   $main::lxdebug->enter_sub();
 
 875   my $form     = $main::form;
 
 876   my %myconfig = %main::myconfig;
 
 878   $main::auth->assert('config');
 
 880   $form->{title} = "Edit";
 
 882   AM->get_lead(\%myconfig, \%$form);
 
 886   $form->{orphaned} = 1;
 
 889   $main::lxdebug->leave_sub();
 
 893   $main::lxdebug->enter_sub();
 
 895   my $form     = $main::form;
 
 896   my %myconfig = %main::myconfig;
 
 897   my $locale   = $main::locale;
 
 899   $main::auth->assert('config');
 
 901   AM->lead(\%myconfig, \%$form);
 
 903   $form->{callback} = "am.pl?action=list_lead";
 
 905   my $callback = $form->escape($form->{callback});
 
 907   $form->{title} = $locale->text('Lead');
 
 909   my @column_index = qw(description cost profit);
 
 911   $column_header{description} =
 
 912       qq|<th class=listheading width=100%>|
 
 913     . $locale->text('Description')
 
 923     <th class=listtop>$form->{title}</th>
 
 926   <tr class=listheading>
 
 929   map { print "$column_header{$_}\n" } @column_index;
 
 935   my ($i, %column_data);
 
 936   foreach my $ref (@{ $form->{ALL} }) {
 
 942   <tr valign=top class=listrow$i>
 
 945 #    $lead = $ref->{lead};
 
 947     $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
 
 949     map { print "$column_data{$_}\n" } @column_index;
 
 958   <td><hr size=3 noshade></td>
 
 963 <form method=post action=am.pl>
 
 965 <input name=callback type=hidden value="$form->{callback}">
 
 967 <input type=hidden name=type value=lead>
 
 969 <input class=submit type=submit name=action value="|
 
 970     . $locale->text('Add') . qq|">
 
 978   $main::lxdebug->leave_sub();
 
 982   $main::lxdebug->enter_sub();
 
 984   my $form     = $main::form;
 
 985   my $locale   = $main::locale;
 
 987   $main::auth->assert('config');
 
 989   $form->{title} = $locale->text("$form->{title} Lead");
 
 991   # $locale->text('Add Lead')
 
 992   # $locale->text('Edit Lead')
 
 994   $form->{description} =~ s/\"/"/g;
 
 997       qq|<input name=description size=50 value="$form->{lead}">|;
 
1004 <form method=post action=am.pl>
 
1006 <input type=hidden name=id value=$form->{id}>
 
1007 <input type=hidden name=type value=lead>
 
1011     <th class=listtop colspan=2>$form->{title}</th>
 
1013   <tr height="5"></tr>
 
1015     <th align=right>| . $locale->text('Description') . qq|</th>
 
1016     <td>$description</td>
 
1018     <td colspan=2><hr size=3 noshade></td>
 
1023   $main::lxdebug->leave_sub();
 
1027   $main::lxdebug->enter_sub();
 
1029   my $form     = $main::form;
 
1030   my %myconfig = %main::myconfig;
 
1031   my $locale   = $main::locale;
 
1033   $main::auth->assert('config');
 
1035   $form->isblank("description", $locale->text('Description missing!'));
 
1036   AM->save_lead(\%myconfig, \%$form);
 
1037   $form->redirect($locale->text('lead saved!'));
 
1039   $main::lxdebug->leave_sub();
 
1043   $main::lxdebug->enter_sub();
 
1045   my $form     = $main::form;
 
1046   my %myconfig = %main::myconfig;
 
1047   my $locale   = $main::locale;
 
1049   $main::auth->assert('config');
 
1051   AM->delete_lead(\%myconfig, \%$form);
 
1052   $form->redirect($locale->text('lead deleted!'));
 
1054   $main::lxdebug->leave_sub();
 
1058   $main::lxdebug->enter_sub();
 
1060   my $form     = $main::form;
 
1062   $main::auth->assert('config');
 
1064   $form->{title} = "Add";
 
1066   $form->{callback} = "am.pl?action=add_business" unless $form->{callback};
 
1071   $main::lxdebug->leave_sub();
 
1075   $main::lxdebug->enter_sub();
 
1077   my $form     = $main::form;
 
1078   my %myconfig = %main::myconfig;
 
1080   $form->{title} = "Edit";
 
1082   AM->get_business(\%myconfig, \%$form);
 
1086   $form->{orphaned} = 1;
 
1089   $main::lxdebug->leave_sub();
 
1093   $main::lxdebug->enter_sub();
 
1095   my $form     = $main::form;
 
1096   my %myconfig = %main::myconfig;
 
1097   my $locale   = $main::locale;
 
1099   $main::auth->assert('config');
 
1101   AM->business(\%myconfig, \%$form);
 
1103   $form->{callback} = "am.pl?action=list_business";
 
1105   my $callback = $form->escape($form->{callback});
 
1107   $form->{title} = $locale->text('Type of Business');
 
1109   my @column_index = qw(description discount customernumberinit);
 
1110   push @column_index, 'salesman' if $::vertreter;
 
1112   $column_header{description} =
 
1113       qq|<th class=listheading width=60%>|
 
1114     . $locale->text('Description')
 
1116   $column_header{discount} =
 
1117       qq|<th class=listheading width=10%>|
 
1118     . $locale->text('Discount')
 
1120   $column_header{customernumberinit} =
 
1121       qq|<th class=listheading>|
 
1122     . $locale->text('Customernumberinit')
 
1124   $column_header{salesman} =
 
1125       qq|<th class=listheading>|
 
1126     . $locale->text('Representative')
 
1136     <th class=listtop>$form->{title}</th>
 
1138   <tr height="5"></tr>
 
1142         <tr class=listheading>
 
1145   map { print "$column_header{$_}\n" } @column_index;
 
1151   my ($i, %column_data);
 
1152   foreach my $ref (@{ $form->{ALL} }) {
 
1158         <tr valign=top class=listrow$i>
 
1161     my $discount    = $form->format_amount(\%myconfig, $ref->{discount} * 100);
 
1162     my $description = $ref->{description};
 
1163     $column_data{description} = qq|<td><a href="am.pl?action=edit_business&id=$ref->{id}&callback=$callback">$description</td>|;
 
1164     $column_data{discount}           = qq|<td align=right>$discount</td>|;
 
1165     $column_data{customernumberinit} =
 
1166       qq|<td align=right>$ref->{customernumberinit}</td>|;
 
1167     $column_data{salesman} = '<td>' . ($ref->{salesman} ? $::locale->text('Yes') : $::locale->text('No')) . '</td>';
 
1169     map { print "$column_data{$_}\n" } @column_index;
 
1181   <td><hr size=3 noshade></td>
 
1186 <form method=post action=am.pl>
 
1188 <input name=callback type=hidden value="$form->{callback}">
 
1190 <input type=hidden name=type value=business>
 
1192 <input class=submit type=submit name=action value="|
 
1193     . $locale->text('Add') . qq|">
 
1201   $main::lxdebug->leave_sub();
 
1204 sub business_header {
 
1205   $main::lxdebug->enter_sub();
 
1207   my $form     = $main::form;
 
1208   my %myconfig = %main::myconfig;
 
1209   my $locale   = $main::locale;
 
1211   $main::auth->assert('config');
 
1213   $form->{title}    = $locale->text("$form->{title} Business");
 
1215   # $locale->text('Add Business')
 
1216   # $locale->text('Edit Business')
 
1218   $form->{description} =~ s/\"/"/g;
 
1220     $form->format_amount(\%myconfig, $form->{discount} * 100);
 
1224     $salesman_code = qq|
 
1226     <th align="right">| . $locale->text('Representative') . qq|</th>
 
1227     <td>| . $::cgi->checkbox(-name => "salesman", -value => 1, -label => '', 'checked' => $form->{salesman} ? 1 : 0) . qq|</td>
 
1231     $salesman_code = $::cgi->hidden(-name => 'salesman', -value => $form->{salesman} ? 1 : 0);
 
1239 <form method=post action=am.pl>
 
1241 <input type=hidden name=id value=$form->{id}>
 
1242 <input type=hidden name=type value=business>
 
1246     <th class=listtop colspan=2>$form->{title}</th>
 
1248   <tr height="5"></tr>
 
1250     <th align=right>| . $locale->text('Type of Business') . qq|</th>
 
1251     <td><input name=description size=30 value="$form->{description}"></td>
 
1254     <th align=right>| . $locale->text('Discount') . qq| %</th>
 
1255     <td><input name=discount size=5 value=$form->{discount}></td>
 
1258     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
 
1259     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
 
1262   <td colspan=2><hr size=3 noshade></td>
 
1267   $main::lxdebug->leave_sub();
 
1271   $main::lxdebug->enter_sub();
 
1273   my $form     = $main::form;
 
1274   my %myconfig = %main::myconfig;
 
1275   my $locale   = $main::locale;
 
1277   $main::auth->assert('config');
 
1279   $form->isblank("description", $locale->text('Description missing!'));
 
1280   $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
 
1281   AM->save_business(\%myconfig, \%$form);
 
1282   $form->redirect($locale->text('Business saved!'));
 
1284   $main::lxdebug->leave_sub();
 
1287 sub delete_business {
 
1288   $main::lxdebug->enter_sub();
 
1290   my $form     = $main::form;
 
1291   my %myconfig = %main::myconfig;
 
1292   my $locale   = $main::locale;
 
1294   $main::auth->assert('config');
 
1296   AM->delete_business(\%myconfig, \%$form);
 
1297   $form->redirect($locale->text('Business deleted!'));
 
1299   $main::lxdebug->leave_sub();
 
1303   $main::lxdebug->enter_sub();
 
1305   my $form     = $main::form;
 
1307   $main::auth->assert('config');
 
1309   $form->{title} = "Add";
 
1311   $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
 
1316   $main::lxdebug->leave_sub();
 
1320   $main::lxdebug->enter_sub();
 
1322   my $form     = $main::form;
 
1323   my %myconfig = %main::myconfig;
 
1325   $main::auth->assert('config');
 
1327   $form->{title} = "Edit";
 
1329   AM->get_language(\%myconfig, \%$form);
 
1333   $form->{orphaned} = 1;
 
1336   $main::lxdebug->leave_sub();
 
1340   $main::lxdebug->enter_sub();
 
1342   my $form     = $main::form;
 
1343   my %myconfig = %main::myconfig;
 
1344   my $locale   = $main::locale;
 
1346   $main::auth->assert('config');
 
1348   AM->language(\%myconfig, \%$form);
 
1350   $form->{callback} = "am.pl?action=list_language";
 
1352   my $callback = $form->escape($form->{callback});
 
1354   $form->{title} = $locale->text('Languages');
 
1356   my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
 
1358   $column_header{description} =
 
1359       qq|<th class=listheading width=60%>|
 
1360     . $locale->text('Description')
 
1362   $column_header{template_code} =
 
1363       qq|<th class=listheading width=10%>|
 
1364     . $locale->text('Template Code')
 
1366   $column_header{article_code} =
 
1367       qq|<th class=listheading>|
 
1368     . $locale->text('Article Code')
 
1370   $column_header{output_numberformat} =
 
1371       qq|<th class=listheading>|
 
1372     . $locale->text('Number Format')
 
1374   $column_header{output_dateformat} =
 
1375       qq|<th class=listheading>|
 
1376     . $locale->text('Date Format')
 
1378   $column_header{output_longdates} =
 
1379       qq|<th class=listheading>|
 
1380     . $locale->text('Long Dates')
 
1390     <th class=listtop>$form->{title}</th>
 
1392   <tr height="5"></tr>
 
1396         <tr class=listheading>
 
1399   map { print "$column_header{$_}\n" } @column_index;
 
1405   my ($i, %column_data);
 
1406   foreach my $ref (@{ $form->{ALL} }) {
 
1412         <tr valign=top class=listrow$i>
 
1416     $column_data{description} =
 
1417       qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1418     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
 
1419     $column_data{article_code} =
 
1420       qq|<td align=right>$ref->{article_code}</td>|;
 
1421     $column_data{output_numberformat} =
 
1423       ($ref->{output_numberformat} ? $ref->{output_numberformat} :
 
1424        $locale->text("use program settings")) .
 
1426     $column_data{output_dateformat} =
 
1428       ($ref->{output_dateformat} ? $ref->{output_dateformat} :
 
1429        $locale->text("use program settings")) .
 
1431     $column_data{output_longdates} =
 
1433       ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
 
1436     map { print "$column_data{$_}\n" } @column_index;
 
1448   <td><hr size=3 noshade></td>
 
1453 <form method=post action=am.pl>
 
1455 <input name=callback type=hidden value="$form->{callback}">
 
1457 <input type=hidden name=type value=language>
 
1459 <input class=submit type=submit name=action value="|
 
1460     . $locale->text('Add') . qq|">
 
1468   $main::lxdebug->leave_sub();
 
1471 sub language_header {
 
1472   $main::lxdebug->enter_sub();
 
1474   my $form     = $main::form;
 
1475   my $locale   = $main::locale;
 
1477   $main::auth->assert('config');
 
1479   $form->{title}    = $locale->text("$form->{title} Language");
 
1481   # $locale->text('Add Language')
 
1482   # $locale->text('Edit Language')
 
1484   $form->{description} =~ s/\"/"/g;
 
1485   $form->{template_code} =~ s/\"/"/g;
 
1486   $form->{article_code} =~ s/\"/"/g;
 
1492     qq|<option value="">| . $locale->text("use program settings") .
 
1494   foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
 
1496       ($item eq $form->{output_numberformat})
 
1497       ? "<option selected>$item"
 
1503     qq|<option value="">| . $locale->text("use program settings") .
 
1505   foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
 
1507       ($item eq $form->{output_dateformat})
 
1508       ? "<option selected>$item"
 
1516 <form method=post action=am.pl>
 
1518 <input type=hidden name=id value=$form->{id}>
 
1519 <input type=hidden name=type value=language>
 
1523     <th class=listtop colspan=2>$form->{title}</th>
 
1525   <tr height="5"></tr>
 
1527     <th align=right>| . $locale->text('Language') . qq|</th>
 
1528     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1531     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1532     <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
 
1535     <th align=right>| . $locale->text('Article Code') . qq|</th>
 
1536     <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
 
1539     <th align=right>| . $locale->text('Number Format') . qq|</th>
 
1540     <td><select name="output_numberformat">$numberformat</select></td>
 
1543     <th align=right>| . $locale->text('Date Format') . qq|</th>
 
1544     <td><select name="output_dateformat">$dateformat</select></td>
 
1547     <th align=right>| . $locale->text('Long Dates') . qq|</th>
 
1548     <td><input type="radio" name="output_longdates" value="1"| .
 
1549     ($form->{output_longdates} ? " checked" : "") .
 
1550     qq|>| . $locale->text("Yes") .
 
1551     qq|<input type="radio" name="output_longdates" value="0"| .
 
1552     ($form->{output_longdates} ? "" : " checked") .
 
1553     qq|>| . $locale->text("No") .
 
1556   <td colspan=2><hr size=3 noshade></td>
 
1561   $main::lxdebug->leave_sub();
 
1565   $main::lxdebug->enter_sub();
 
1567   my $form     = $main::form;
 
1568   my %myconfig = %main::myconfig;
 
1569   my $locale   = $main::locale;
 
1571   $main::auth->assert('config');
 
1573   $form->isblank("description", $locale->text('Language missing!'));
 
1574   $form->isblank("template_code", $locale->text('Template Code missing!'));
 
1575   $form->isblank("article_code", $locale->text('Article Code missing!'));
 
1576   AM->save_language(\%myconfig, \%$form);
 
1577   $form->redirect($locale->text('Language saved!'));
 
1579   $main::lxdebug->leave_sub();
 
1582 sub delete_language {
 
1583   $main::lxdebug->enter_sub();
 
1585   my $form     = $main::form;
 
1586   my %myconfig = %main::myconfig;
 
1587   my $locale   = $main::locale;
 
1589   $main::auth->assert('config');
 
1591   AM->delete_language(\%myconfig, \%$form);
 
1592   $form->redirect($locale->text('Language deleted!'));
 
1594   $main::lxdebug->leave_sub();
 
1598 sub add_buchungsgruppe {
 
1599   $main::lxdebug->enter_sub();
 
1601   my $form     = $main::form;
 
1602   my %myconfig = %main::myconfig;
 
1603   my $locale   = $main::locale;
 
1605   $main::auth->assert('config');
 
1607   # $locale->text("Add Buchungsgruppe")
 
1608   # $locale->text("Edit Buchungsgruppe")
 
1609   $form->{title} = "Add";
 
1611   $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
 
1613   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1614   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
 
1615   for (my $i = 0; 4 > $i; $i++) {
 
1616     map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
 
1617         qw(income expense));
 
1620   &buchungsgruppe_header;
 
1623   $main::lxdebug->leave_sub();
 
1626 sub edit_buchungsgruppe {
 
1627   $main::lxdebug->enter_sub();
 
1629   my $form     = $main::form;
 
1630   my %myconfig = %main::myconfig;
 
1632   $main::auth->assert('config');
 
1634   $form->{title} = "Edit";
 
1636   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1638   &buchungsgruppe_header;
 
1642   $main::lxdebug->leave_sub();
 
1645 sub list_buchungsgruppe {
 
1646   $main::lxdebug->enter_sub();
 
1648   my $form     = $main::form;
 
1649   my %myconfig = %main::myconfig;
 
1650   my $locale   = $main::locale;
 
1652   $main::auth->assert('config');
 
1654   AM->buchungsgruppe(\%myconfig, \%$form);
 
1656   $form->{callback} = "am.pl?action=list_buchungsgruppe";
 
1658   my $callback = $form->escape($form->{callback});
 
1660   $form->{title} = $locale->text('Buchungsgruppen');
 
1662   my @column_index = qw(up down description inventory_accno
 
1663                      income_accno_0 expense_accno_0
 
1664                      income_accno_1 expense_accno_1
 
1665                      income_accno_2 expense_accno_2
 
1666                      income_accno_3 expense_accno_3 );
 
1668   $column_header{up} =
 
1669       qq|<th class="listheading" width="16">|
 
1670     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
1672   $column_header{down} =
 
1673       qq|<th class="listheading" width="16">|
 
1674     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
1676   $column_header{description} =
 
1677       qq|<th class="listheading" width="40%">|
 
1678     . $locale->text('Description')
 
1680   $column_header{inventory_accno} =
 
1681       qq|<th class=listheading>|
 
1682     . $locale->text('Bestandskonto')
 
1684   $column_header{income_accno_0} =
 
1685       qq|<th class=listheading>|
 
1686     . $locale->text('National Revenues')
 
1688   $column_header{expense_accno_0} =
 
1689       qq|<th class=listheading>|
 
1690     . $locale->text('National Expenses')
 
1692   $column_header{income_accno_1} =
 
1693       qq|<th class=listheading>|
 
1694     . $locale->text('Revenues EU with UStId')
 
1696   $column_header{expense_accno_1} =
 
1697       qq|<th class=listheading>|
 
1698     . $locale->text('Expenses EU with UStId')
 
1700   $column_header{income_accno_2} =
 
1701       qq|<th class=listheading>|
 
1702     . $locale->text('Revenues EU without UStId')
 
1704   $column_header{expense_accno_2} =
 
1705       qq|<th class=listheading>|
 
1706     . $locale->text('Expenses EU without UStId')
 
1708   $column_header{income_accno_3} =
 
1709       qq|<th class=listheading>|
 
1710     . $locale->text('Foreign Revenues')
 
1712   $column_header{expense_accno_3} =
 
1713       qq|<th class=listheading>|
 
1714     . $locale->text('Foreign Expenses')
 
1723     <th class=listtop>$form->{title}</th>
 
1725   <tr height="5"></tr>
 
1729         <tr class=listheading>
 
1732   map { print "$column_header{$_}\n" } @column_index;
 
1738   my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
 
1741   my ($i, %column_data);
 
1742   foreach my $ref (@{ $form->{ALL} }) {
 
1748         <tr valign=top class=listrow$i>
 
1752       my $pref = $form->{ALL}->[$row - 1];
 
1754         qq|<td align="center" valign="center" width="16">| .
 
1755         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
 
1756         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
1759       $column_data{up} = qq|<td width="16"> </td>|;
 
1762     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
1763       $column_data{down} = qq|<td width="16"> </td>|;
 
1765       my $nref = $form->{ALL}->[$row + 1];
 
1766       $column_data{down} =
 
1767         qq|<td align="center" valign="center" width="16">| .
 
1768         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
 
1769         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
1773     $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1774     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
 
1775     $column_data{income_accno_0} =
 
1776       qq|<td align=right>$ref->{income_accno_0}</td>|;
 
1777     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
 
1778     $column_data{income_accno_1} =
 
1779       qq|<td align=right>$ref->{income_accno_1}</td>|;
 
1780     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
 
1781     $column_data{income_accno_2} =
 
1782       qq|<td align=right>$ref->{income_accno_2}</td>|;
 
1783     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
 
1784     $column_data{income_accno_3} =
 
1785       qq|<td align=right>$ref->{income_accno_3}</td>|;
 
1786     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
 
1788     map { print "$column_data{$_}\n" } @column_index;
 
1802   <td><hr size=3 noshade></td>
 
1807 <form method=post action=am.pl>
 
1809 <input name=callback type=hidden value="$form->{callback}">
 
1811 <input type=hidden name=type value=buchungsgruppe>
 
1813 <input class=submit type=submit name=action value="|
 
1814     . $locale->text('Add') . qq|">
 
1822   $main::lxdebug->leave_sub();
 
1825 sub buchungsgruppe_header {
 
1826   $main::lxdebug->enter_sub();
 
1828   my $form     = $main::form;
 
1829   my $locale   = $main::locale;
 
1831   $main::auth->assert('config');
 
1833   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
 
1835   # $locale->text('Add Accounting Group')
 
1836   # $locale->text('Edit Accounting Group')
 
1838   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
 
1839   my %acc_type_map = (
 
1840     "IC" => $acc_inventory,
 
1841     "IC_income" => $acc_income,
 
1842     "IC_sale" => $acc_income,
 
1843     "IC_expense" => $acc_expense,
 
1844     "IC_cogs" => $acc_expense,
 
1847   foreach my $key (keys(%acc_type_map)) {
 
1848     foreach my $ref (@{ $form->{IC_links}{$key} }) {
 
1849       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
 
1853   foreach my $type (qw(IC IC_income IC_expense)) {
 
1854     $form->{"select$type"} =
 
1856            map({ "<option value=$_->{id} $_->{selected}>" .
 
1857                    "$_->{accno}--" . H($_->{description}) . "</option>" }
 
1858                sort({ $a->{"accno"} cmp $b->{"accno"} }
 
1859                     values(%{$acc_type_map{$type}}))));
 
1863     $form->{selectIC} =~ s/selected//g;
 
1864     $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/  value=$form->{inventory_accno_id} selected/;
 
1865     $form->{selectIC_income} =~ s/selected//g;
 
1866     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/  value=$form->{income_accno_id_0} selected/;
 
1867     $form->{selectIC_expense} =~ s/selected//g;
 
1868     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
 
1875                 <th align=right>| . $locale->text('Inventory') . qq|</th>
 
1876                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
 
1877                 <input name=selectIC type=hidden value="$form->{selectIC}">
 
1881                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
 
1885   $linkaccounts .= qq|
 
1887                 <th align=right>| . $locale->text('National Revenues') . qq|</th>
 
1888                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
 
1891                 <th align=right>| . $locale->text('National Expenses') . qq|</th>
 
1892                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
 
1895     $form->{selectIC_income} =~ s/selected//g;
 
1896     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/  value=$form->{income_accno_id_1} selected/;
 
1897     $form->{selectIC_expense} =~ s/selected//g;
 
1898     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/  value=$form->{expense_accno_id_1} selected/;
 
1900   $linkaccounts .= qq|              <tr>
 
1901                 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
 
1902                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
 
1905                 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
 
1906                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
 
1910     $form->{selectIC_income} =~ s/selected//g;
 
1911     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/  value=$form->{income_accno_id_2} selected/;
 
1912     $form->{selectIC_expense} =~ s/selected//g;
 
1913     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/  value=$form->{expense_accno_id_2} selected/;
 
1916   $linkaccounts .= qq|              <tr>
 
1917                 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
 
1918                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
 
1921                 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
 
1922                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
 
1926     $form->{selectIC_income} =~ s/selected//g;
 
1927     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/  value=$form->{income_accno_id_3} selected/;
 
1928     $form->{selectIC_expense} =~ s/selected//g;
 
1929     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/  value=$form->{expense_accno_id_3} selected/;
 
1932   $linkaccounts .= qq|              <tr>
 
1933                 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
 
1934                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
 
1937                 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
 
1938                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
 
1948 <form method=post action=am.pl>
 
1950 <input type=hidden name=id value=$form->{id}>
 
1951 <input type=hidden name=type value=buchungsgruppe>
 
1955     <th class=listtop colspan=2>$form->{title}</th>
 
1957   <tr height="5"></tr>
 
1959     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
 
1960     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1963   <td colspan=2><hr size=3 noshade></td>
 
1968   $main::lxdebug->leave_sub();
 
1971 sub save_buchungsgruppe {
 
1972   $main::lxdebug->enter_sub();
 
1974   my $form     = $main::form;
 
1975   my %myconfig = %main::myconfig;
 
1976   my $locale   = $main::locale;
 
1978   $main::auth->assert('config');
 
1980   $form->isblank("description", $locale->text('Description missing!'));
 
1982   AM->save_buchungsgruppe(\%myconfig, \%$form);
 
1983   $form->redirect($locale->text('Accounting Group saved!'));
 
1985   $main::lxdebug->leave_sub();
 
1988 sub delete_buchungsgruppe {
 
1989   $main::lxdebug->enter_sub();
 
1991   my $form     = $main::form;
 
1992   my %myconfig = %main::myconfig;
 
1993   my $locale   = $main::locale;
 
1995   $main::auth->assert('config');
 
1997   AM->delete_buchungsgruppe(\%myconfig, \%$form);
 
1998   $form->redirect($locale->text('Accounting Group deleted!'));
 
2000   $main::lxdebug->leave_sub();
 
2003 sub swap_buchungsgruppen {
 
2004   $main::lxdebug->enter_sub();
 
2006   my $form     = $main::form;
 
2007   my %myconfig = %main::myconfig;
 
2009   $main::auth->assert('config');
 
2011   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
 
2012   list_buchungsgruppe();
 
2014   $main::lxdebug->leave_sub();
 
2019   $main::lxdebug->enter_sub();
 
2021   my $form     = $main::form;
 
2023   $main::auth->assert('config');
 
2025   $form->{title} = "Add";
 
2027   $form->{callback} = "am.pl?action=add_printer" unless $form->{callback};
 
2032   $main::lxdebug->leave_sub();
 
2036   $main::lxdebug->enter_sub();
 
2038   my $form     = $main::form;
 
2039   my %myconfig = %main::myconfig;
 
2041   $main::auth->assert('config');
 
2043   $form->{title} = "Edit";
 
2045   AM->get_printer(\%myconfig, \%$form);
 
2049   $form->{orphaned} = 1;
 
2052   $main::lxdebug->leave_sub();
 
2056   $main::lxdebug->enter_sub();
 
2058   my $form     = $main::form;
 
2059   my %myconfig = %main::myconfig;
 
2060   my $locale   = $main::locale;
 
2062   $main::auth->assert('config');
 
2064   AM->printer(\%myconfig, \%$form);
 
2066   $form->{callback} = "am.pl?action=list_printer";
 
2068   my $callback = $form->escape($form->{callback});
 
2070   $form->{title} = $locale->text('Printer');
 
2072   my @column_index = qw(printer_description printer_command template_code);
 
2074   $column_header{printer_description} =
 
2075       qq|<th class=listheading width=60%>|
 
2076     . $locale->text('Printer Description')
 
2078   $column_header{printer_command} =
 
2079       qq|<th class=listheading width=10%>|
 
2080     . $locale->text('Printer Command')
 
2082   $column_header{template_code} =
 
2083       qq|<th class=listheading>|
 
2084     . $locale->text('Template Code')
 
2094     <th class=listtop>$form->{title}</th>
 
2096   <tr height="5"></tr>
 
2100         <tr class=listheading>
 
2103   map { print "$column_header{$_}\n" } @column_index;
 
2109   my ($i, %column_data);
 
2110   foreach my $ref (@{ $form->{ALL} }) {
 
2116         <tr valign=top class=listrow$i>
 
2120     $column_data{printer_description} = qq|<td><a href="am.pl?action=edit_printer&id=$ref->{id}&callback=$callback">$ref->{printer_description}</td>|;
 
2121     $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
 
2122     $column_data{template_code} =
 
2123       qq|<td align=right>$ref->{template_code}</td>|;
 
2125     map { print "$column_data{$_}\n" } @column_index;
 
2137   <td><hr size=3 noshade></td>
 
2142 <form method=post action=am.pl>
 
2144 <input name=callback type=hidden value="$form->{callback}">
 
2146 <input type=hidden name=type value=printer>
 
2148 <input class=submit type=submit name=action value="|
 
2149     . $locale->text('Add') . qq|">
 
2157   $main::lxdebug->leave_sub();
 
2160 sub printer_header {
 
2161   $main::lxdebug->enter_sub();
 
2163   my $form     = $main::form;
 
2164   my $locale   = $main::locale;
 
2166   $main::auth->assert('config');
 
2168   $form->{title}    = $locale->text("$form->{title} Printer");
 
2170   # $locale->text('Add Printer')
 
2171   # $locale->text('Edit Printer')
 
2173   $form->{printer_description} =~ s/\"/"/g;
 
2174   $form->{template_code} =~ s/\"/"/g;
 
2175   $form->{printer_command} =~ s/\"/"/g;
 
2183 <form method=post action=am.pl>
 
2185 <input type=hidden name=id value=$form->{id}>
 
2186 <input type=hidden name=type value=printer>
 
2190     <th class=listtop colspan=2>$form->{title}</th>
 
2192   <tr height="5"></tr>
 
2194     <th align=right>| . $locale->text('Printer') . qq|</th>
 
2195     <td><input name=printer_description size=30 value="$form->{printer_description}"></td>
 
2198     <th align=right>| . $locale->text('Printer Command') . qq|</th>
 
2199     <td><input name=printer_command size=30 value="$form->{printer_command}"></td>
 
2202     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
2203     <td><input name=template_code size=5 value="$form->{template_code}"></td>
 
2205   <td colspan=2><hr size=3 noshade></td>
 
2210   $main::lxdebug->leave_sub();
 
2214   $main::lxdebug->enter_sub();
 
2216   my $form     = $main::form;
 
2217   my %myconfig = %main::myconfig;
 
2218   my $locale   = $main::locale;
 
2220   $main::auth->assert('config');
 
2222   $form->isblank("printer_description", $locale->text('Description missing!'));
 
2223   $form->isblank("printer_command", $locale->text('Printer Command missing!'));
 
2224   AM->save_printer(\%myconfig, \%$form);
 
2225   $form->redirect($locale->text('Printer saved!'));
 
2227   $main::lxdebug->leave_sub();
 
2230 sub delete_printer {
 
2231   $main::lxdebug->enter_sub();
 
2233   my $form     = $main::form;
 
2234   my %myconfig = %main::myconfig;
 
2235   my $locale   = $main::locale;
 
2237   $main::auth->assert('config');
 
2239   AM->delete_printer(\%myconfig, \%$form);
 
2240   $form->redirect($locale->text('Printer deleted!'));
 
2242   $main::lxdebug->leave_sub();
 
2246   $main::lxdebug->enter_sub();
 
2248   my $form     = $main::form;
 
2249   my %myconfig = %main::myconfig;
 
2251   $main::auth->assert('config');
 
2253   $form->{title} = "Add";
 
2255   $form->{callback} = "am.pl?action=add_payment" unless $form->{callback};
 
2257   $form->{terms_netto} = 0;
 
2258   $form->{terms_skonto} = 0;
 
2259   $form->{percent_skonto} = 0;
 
2260   my @languages = AM->language(\%myconfig, $form, 1);
 
2261   map({ $_->{"language"} = $_->{"description"};
 
2262         $_->{"language_id"} = $_->{"id"}; } @languages);
 
2263   $form->{"TRANSLATION"} = \@languages;
 
2267   $main::lxdebug->leave_sub();
 
2271   $main::lxdebug->enter_sub();
 
2273   my $form     = $main::form;
 
2274   my %myconfig = %main::myconfig;
 
2276   $main::auth->assert('config');
 
2278   $form->{title} = "Edit";
 
2280   AM->get_payment(\%myconfig, $form);
 
2281   $form->{percent_skonto} =
 
2282     $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
 
2286   $form->{orphaned} = 1;
 
2289   $main::lxdebug->leave_sub();
 
2293   $main::lxdebug->enter_sub();
 
2295   my $form     = $main::form;
 
2296   my %myconfig = %main::myconfig;
 
2297   my $locale   = $main::locale;
 
2299   $main::auth->assert('config');
 
2301   AM->payment(\%myconfig, \%$form);
 
2303   $form->{callback} = build_std_url("action=list_payment");
 
2305   my $callback = $form->escape($form->{callback});
 
2307   $form->{title} = $locale->text('Payment Terms');
 
2309   my @column_index = qw(up down description description_long terms_netto
 
2310                      terms_skonto percent_skonto);
 
2312   $column_header{up} =
 
2313       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2314     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
2316   $column_header{down} =
 
2317       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2318     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
2320   $column_header{description} =
 
2321       qq|<th class=listheading>|
 
2322     . $locale->text('Description')
 
2324   $column_header{description_long} =
 
2325       qq|<th class=listheading>|
 
2326     . $locale->text('Long Description')
 
2328   $column_header{terms_netto} =
 
2329       qq|<th class=listheading>|
 
2330     . $locale->text('Netto Terms')
 
2332   $column_header{terms_skonto} =
 
2333       qq|<th class=listheading>|
 
2334     . $locale->text('Skonto Terms')
 
2336   $column_header{percent_skonto} =
 
2337       qq|<th class=listheading>|
 
2338     . $locale->text('Skonto')
 
2348     <th class=listtop>$form->{title}</th>
 
2350   <tr height="5"></tr>
 
2354         <tr class=listheading>
 
2357   map { print "$column_header{$_}\n" } @column_index;
 
2363   my $swap_link = build_std_url("action=swap_payment_terms");
 
2366   my ($i, %column_data);
 
2367   foreach my $ref (@{ $form->{ALL} }) {
 
2373         <tr valign=top class=listrow$i>
 
2377       my $pref = $form->{ALL}->[$row - 1];
 
2379         qq|<td align="center" valign="center" width="16">| .
 
2380         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
 
2381         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
2384       $column_data{up} = qq|<td width="16"> </td>|;
 
2387     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
2388       $column_data{down} = qq|<td width="16"> </td>|;
 
2390       my $nref = $form->{ALL}->[$row + 1];
 
2391       $column_data{down} =
 
2392         qq|<td align="center" valign="center" width="16">| .
 
2393         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
 
2394         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
2398     $column_data{description} =
 
2400       build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
 
2401       qq|">| . H($ref->{description}) . qq|</a></td>|;
 
2402     $column_data{description_long} =
 
2403       qq|<td>| . H($ref->{description_long}) . qq|</td>|;
 
2404     $column_data{terms_netto} =
 
2405       qq|<td align=right>$ref->{terms_netto}</td>|;
 
2406     $column_data{terms_skonto} =
 
2407       qq|<td align=right>$ref->{terms_skonto}</td>|;
 
2408     $column_data{percent_skonto} =
 
2409       qq|<td align=right>| .
 
2410       $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
 
2412     map { print "$column_data{$_}\n" } @column_index;
 
2425   <td><hr size=3 noshade></td>
 
2430 <form method=post action=am.pl>
 
2432 <input name=callback type=hidden value="$form->{callback}">
 
2434 <input type=hidden name=type value=payment>
 
2436 <input class=submit type=submit name=action value="|
 
2437     . $locale->text('Add') . qq|">
 
2445   $main::lxdebug->leave_sub();
 
2448 sub payment_header {
 
2449   $main::lxdebug->enter_sub();
 
2451   my $form     = $main::form;
 
2452   my $locale   = $main::locale;
 
2454   $main::auth->assert('config');
 
2456   $form->{title}    = $locale->text("$form->{title} Payment Terms");
 
2458   # $locale->text('Add Payment Terms')
 
2459   # $locale->text('Edit Payment Terms')
 
2461   $form->{description} =~ s/\"/"/g;
 
2470 <form method=post action=am.pl>
 
2472 <input type=hidden name=id value=$form->{id}>
 
2473 <input type=hidden name=type value=payment>
 
2477     <th class=listtop colspan=2>$form->{title}</th>
 
2479   <tr height="5"></tr>
 
2481     <th align=right>| . $locale->text('Description') . qq|</th>
 
2482     <td><input name=description size=30 value="$form->{description}"></td>
 
2485     <th align=right>| . $locale->text('Long Description') . qq|</th>
 
2486     <td><input name=description_long size=50 value="$form->{description_long}"></td>
 
2490   foreach my $language (@{ $form->{"TRANSLATION"} }) {
 
2493     <th align="right">| .
 
2494     sprintf($locale->text('Translation (%s)'),
 
2495             $language->{"language"})
 
2497     <td><input name="description_long_$language->{language_id}" size="50"
 
2498          value="| . Q($language->{"description_long"}) . qq|"></td>
 
2505     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
 
2506     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
 
2509     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
 
2510     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
 
2513     <th align=right>| . $locale->text('Skonto') . qq| %</th>
 
2514     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
 
2516   <td colspan=2><hr size=3 noshade></td>
 
2520 <p>| . $locale->text("You can use the following strings in the long " .
 
2521                      "description and all translations. They will be " .
 
2522                      "replaced by their actual values by Lx-Office " .
 
2523                      "before they're output.")
 
2527   <li>| . $locale->text("<%netto_date%> -- Date the payment is due in " .
 
2530   <li>| . $locale->text("<%skonto_date%> -- Date the payment is due " .
 
2533   <li>| . $locale->text("<%skonto_amount%> -- The deductible amount")
 
2535   <li>| . $locale->text("<%skonto_in_percent%> -- The discount in percent")
 
2537   <li>| . $locale->text("<%total%> -- Amount payable")
 
2539   <li>| . $locale->text("<%total_wo_skonto%> -- Amount payable less discount")
 
2541   <li>| . $locale->text("<%invtotal%> -- Invoice total")
 
2543   <li>| . $locale->text("<%invtotal_wo_skonto%> -- Invoice total less discount")
 
2545   <li>| . $locale->text("<%currency%> -- The selected currency")
 
2547   <li>| . $locale->text("<%terms_netto%> -- The number of days for " .
 
2550   <li>| . $locale->text("<%account_number%> -- Your account number")
 
2552   <li>| . $locale->text("<%bank%> -- Your bank")
 
2554   <li>| . $locale->text("<%bank_code%> -- Your bank code")
 
2558   $main::lxdebug->leave_sub();
 
2562   $main::lxdebug->enter_sub();
 
2564   my $form     = $main::form;
 
2565   my %myconfig = %main::myconfig;
 
2566   my $locale   = $main::locale;
 
2568   $main::auth->assert('config');
 
2570   $form->isblank("description", $locale->text('Description missing!'));
 
2571   $form->{"percent_skonto"} =
 
2572     $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
 
2573   AM->save_payment(\%myconfig, \%$form);
 
2574   $form->redirect($locale->text('Payment Terms saved!'));
 
2576   $main::lxdebug->leave_sub();
 
2579 sub delete_payment {
 
2580   $main::lxdebug->enter_sub();
 
2582   my $form     = $main::form;
 
2583   my %myconfig = %main::myconfig;
 
2584   my $locale   = $main::locale;
 
2586   $main::auth->assert('config');
 
2588   AM->delete_payment(\%myconfig, \%$form);
 
2589   $form->redirect($locale->text('Payment terms deleted!'));
 
2591   $main::lxdebug->leave_sub();
 
2594 sub swap_payment_terms {
 
2595   $main::lxdebug->enter_sub();
 
2597   my $form     = $main::form;
 
2598   my %myconfig = %main::myconfig;
 
2600   $main::auth->assert('config');
 
2602   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
 
2605   $main::lxdebug->leave_sub();
 
2609   $main::lxdebug->enter_sub();
 
2611   my $form     = $main::form;
 
2612   my %myconfig = %main::myconfig;
 
2613   my $locale   = $main::locale;
 
2615   # get defaults for account numbers and last numbers
 
2616   AM->defaultaccounts(\%myconfig, \%$form);
 
2617   $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
 
2619   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
 
2621   foreach my $key (keys %{ $form->{IC} }) {
 
2622     foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
 
2623       my $array = "ACCNOS_" . uc($key);
 
2624       $form->{$array} ||= [];
 
2626       my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
 
2627       push @{ $form->{$array} }, {
 
2630         'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
 
2635   $form->{title} = $locale->text('Ranges of numbers and default accounts');
 
2638   print $form->parse_html_template('am/edit_defaults');
 
2640   $main::lxdebug->leave_sub();
 
2644   $main::lxdebug->enter_sub();
 
2646   my $form     = $main::form;
 
2647   my $locale   = $main::locale;
 
2649   AM->save_defaults();
 
2651   $form->redirect($locale->text('Defaults saved.'));
 
2653   $main::lxdebug->leave_sub();
 
2656 sub _build_cfg_options {
 
2657   my $form     = $main::form;
 
2658   my %myconfig = %main::myconfig;
 
2661   my $array = uc($idx) . 'S';
 
2663   $form->{$array} = [];
 
2664   foreach my $item (@_) {
 
2665     push @{ $form->{$array} }, {
 
2668       'selected' => $item eq $myconfig{$idx},
 
2674   $main::lxdebug->enter_sub();
 
2676   my $form     = $main::form;
 
2677   my %myconfig = %main::myconfig;
 
2678   my $locale   = $main::locale;
 
2680   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
2681   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
2684   if ($main::opendocument_templates && $main::openofficeorg_writer_bin &&
 
2685       $main::xvfb_bin && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)) {
 
2686     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
2687                      "value" => "opendocument_pdf" });
 
2689   if ($main::latex_templates) {
 
2690     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
2692   push(@formats, { "name" => "HTML", "value" => "html" });
 
2693   if ($main::latex_templates) {
 
2694     push(@formats, { "name" => $locale->text("Postscript"),
 
2695                      "value" => "postscript" });
 
2697   if ($main::opendocument_templates) {
 
2698     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
2699                      "value" => "opendocument" });
 
2702   if (!$myconfig{"template_format"}) {
 
2703     $myconfig{"template_format"} = "pdf";
 
2705   $form->{TEMPLATE_FORMATS} = [];
 
2706   foreach my $item (@formats) {
 
2707     push @{ $form->{TEMPLATE_FORMATS} }, {
 
2708       'name'     => $item->{name},
 
2709       'value'    => $item->{value},
 
2710       'selected' => $item->{value} eq $myconfig{template_format},
 
2714   if (!$myconfig{"default_media"}) {
 
2715     $myconfig{"default_media"} = "screen";
 
2718   my %selected = ($myconfig{"default_media"} => "selected");
 
2720     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
2721     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
2722     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
2725   AM->printer(\%myconfig, $form);
 
2727   $form->{PRINTERS} = [];
 
2728   foreach my $printer (@{$form->{"ALL"}}) {
 
2729     push @{ $form->{PRINTERS} }, {
 
2730       'name'     => $printer->{printer_description},
 
2731       'value'    => $printer->{id},
 
2732       'selected' => $printer->{id} == $myconfig{default_printer_id},
 
2736   my %countrycodes = User->country_codes;
 
2738   $form->{COUNTRYCODES} = [];
 
2739   foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
2740     push @{ $form->{COUNTRYCODES} }, {
 
2741       'name'     => $countrycodes{$countrycode},
 
2742       'value'    => $countrycode,
 
2743       'selected' => $countrycode eq $myconfig{countrycode},
 
2747   $form->{STYLESHEETS} = [];
 
2748   foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
 
2749     push @{ $form->{STYLESHEETS} }, {
 
2752       'selected' => $item eq $myconfig{stylesheet},
 
2756   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
 
2757   $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
2758   $form->{todo_cfg}            = { TODO->get_user_config('login' => $form->{login}) };
 
2760   $form->{title}               = $locale->text('Edit Preferences for #1', $form->{login});
 
2763   print $form->parse_html_template('am/config');
 
2765   $main::lxdebug->leave_sub();
 
2768 sub save_preferences {
 
2769   $main::lxdebug->enter_sub();
 
2771   my $form     = $main::form;
 
2772   my %myconfig = %main::myconfig;
 
2773   my $locale   = $main::locale;
 
2775   $form->{stylesheet} = $form->{usestylesheet};
 
2777   TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
 
2779   $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, 0));
 
2780   $form->error($locale->text('Cannot save preferences!'));
 
2782   $main::lxdebug->leave_sub();
 
2786   $main::lxdebug->enter_sub();
 
2788   my $form     = $main::form;
 
2789   my %myconfig = %main::myconfig;
 
2790   my $locale   = $main::locale;
 
2792   $main::auth->assert('config');
 
2794   $form->{title} = $locale->text('Audit Control');
 
2796   AM->closedto(\%myconfig, \%$form);
 
2803 <form method=post action=am.pl>
 
2806   <tr><th class=listtop>$form->{title}</th></tr>
 
2807   <tr height="5"></tr>
 
2812           <th>| . $locale->text('Close Books up to') . qq|</th>
 
2813           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
 
2823 <input type=hidden name=nextsub value=doclose>
 
2825 <input type=submit class=submit name=action value="|
 
2826     . $locale->text('Continue') . qq|">
 
2834   $main::lxdebug->leave_sub();
 
2838   $main::lxdebug->enter_sub();
 
2840   my $form     = $main::form;
 
2841   my %myconfig = %main::myconfig;
 
2842   my $locale   = $main::locale;
 
2844   $main::auth->assert('config');
 
2846   AM->closebooks(\%myconfig, \%$form);
 
2848   if ($form->{closedto}) {
 
2850                     $locale->text('Books closed up to') . " "
 
2851                       . $locale->date(\%myconfig, $form->{closedto}, 1));
 
2853     $form->redirect($locale->text('Books are open'));
 
2856   $main::lxdebug->leave_sub();
 
2860   $main::lxdebug->enter_sub();
 
2862   my $form     = $main::form;
 
2863   my %myconfig = %main::myconfig;
 
2864   my $locale   = $main::locale;
 
2866   $main::auth->assert('config');
 
2868   my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
2869   AM->units_in_use(\%myconfig, $form, $units);
 
2870   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
2872   my @languages = AM->language(\%myconfig, $form, 1);
 
2874   my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
2877   foreach (@unit_list) {
 
2878     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
2879     $_->{"UNITLANGUAGES"} = [];
 
2880     foreach my $lang (@languages) {
 
2881       push(@{ $_->{"UNITLANGUAGES"} },
 
2883              "unit" => $_->{"name"},
 
2884              "language_id" => $lang->{"id"},
 
2885              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
2886              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
2892   $units = AM->retrieve_units(\%myconfig, $form);
 
2893   my $ddbox = AM->unit_select_data($units, undef, 1);
 
2895   my $updownlink = build_std_url("action=swap_units");
 
2897   $form->{"title"} = $locale->text("Add and edit units");
 
2899   print($form->parse_html_template("am/edit_units",
 
2900                                    { "UNITS"               => \@unit_list,
 
2901                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
2902                                      "LANGUAGES"           => \@languages,
 
2903                                      "updownlink"          => $updownlink }));
 
2905   $main::lxdebug->leave_sub();
 
2909   $main::lxdebug->enter_sub();
 
2911   my $form     = $main::form;
 
2912   my %myconfig = %main::myconfig;
 
2913   my $locale   = $main::locale;
 
2915   $main::auth->assert('config');
 
2917   $form->isblank("new_name", $locale->text("The name is missing."));
 
2918   my $units = AM->retrieve_units(\%myconfig, $form);
 
2919   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
2920   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
2922   my ($base_unit, $factor);
 
2923   if ($form->{"new_base_unit"}) {
 
2924     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
2926     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
2927     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
2928     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
2929     $base_unit = $form->{"new_base_unit"};
 
2933   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
2934     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
2935     push(@languages, { "id" => $lang->{"id"},
 
2936                        "localized" => $form->{"new_localized_$lang->{id}"},
 
2937                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
2941   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
2943   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
2947   $main::lxdebug->leave_sub();
 
2950 sub set_unit_languages {
 
2951   $main::lxdebug->enter_sub();
 
2953   my $form     = $main::form;
 
2955   $main::auth->assert('config');
 
2957   my ($unit, $languages, $idx) = @_;
 
2959   $unit->{"LANGUAGES"} = [];
 
2961   foreach my $lang (@{$languages}) {
 
2962     push(@{ $unit->{"LANGUAGES"} },
 
2963          { "id" => $lang->{"id"},
 
2964            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
2965            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
2969   $main::lxdebug->leave_sub();
 
2973   $main::lxdebug->enter_sub();
 
2975   my $form     = $main::form;
 
2976   my %myconfig = %main::myconfig;
 
2977   my $locale   = $main::locale;
 
2979   $main::auth->assert('config');
 
2981   my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
2982   AM->units_in_use(\%myconfig, $form, $old_units);
 
2984   my @languages = AM->language(\%myconfig, $form, 1);
 
2987   my @delete_units = ();
 
2988   foreach my $i (1..($form->{"rowcount"} * 1)) {
 
2989     my $old_unit = $old_units->{$form->{"old_name_$i"}};
 
2991       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
2994     if ($form->{"unchangeable_$i"}) {
 
2995       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
2996       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
2997       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
3001     if ($old_unit->{"in_use"}) {
 
3002       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
3005     if ($form->{"delete_$i"}) {
 
3006       push(@delete_units, $old_unit->{"name"});
 
3010     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
3012     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
3013     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
3014     $new_units->{$form->{"name_$i"}} = \%h;
 
3015     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
3016     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
3019   foreach my $unit (values(%{$new_units})) {
 
3020     next unless ($unit->{"old_name"});
 
3021     if ($unit->{"base_unit"}) {
 
3022       $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"}))
 
3023         unless (defined($new_units->{$unit->{"base_unit"}}));
 
3024       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
3025       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
3027       $unit->{"base_unit"} = undef;
 
3028       $unit->{"factor"} = undef;
 
3032   foreach my $unit (values(%{$new_units})) {
 
3033     next if ($unit->{"unchanged_unit"});
 
3035     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
3036     my $new_unit = $unit;
 
3037     while ($new_unit->{"base_unit"}) {
 
3038       $new_unit->{"seen"} = 1;
 
3039       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
3040       if ($new_unit->{"seen"}) {
 
3041         $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, " .
 
3042                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
3047   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
3049   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
3053   $main::lxdebug->leave_sub();
 
3056 sub show_history_search {
 
3057   $main::lxdebug->enter_sub();
 
3059   my $form     = $main::form;
 
3060   my $locale   = $main::locale;
 
3062   $main::auth->assert('config');
 
3064   $form->{title} = $locale->text("History Search");
 
3067   print $form->parse_html_template("common/search_history");
 
3069   $main::lxdebug->leave_sub();
 
3072 sub show_am_history {
 
3073   $main::lxdebug->enter_sub();
 
3075   my $form     = $main::form;
 
3076   my %myconfig = %main::myconfig;
 
3077   my $locale   = $main::locale;
 
3079   $main::auth->assert('config');
 
3081   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
 
3082   $form->{order} ||= 'h.itime--1';
 
3084   my %search = ( "Artikelnummer"          => "parts",
 
3085                  "Kundennummer"           => "customer",
 
3086                  "Lieferantennummer"      => "vendor",
 
3087                  "Projektnummer"          => "project",
 
3088                  "Buchungsnummer"         => "oe",
 
3089                  "Eingangsrechnungnummer" => "ap",
 
3090                  "Ausgangsrechnungnummer" => "ar",
 
3091                  "Mahnungsnummer"         => "dunning"
 
3093   my %searchNo = ( "Artikelnummer"          => "partnumber",
 
3094                    "Kundennummer"           => "customernumber",
 
3095                    "Lieferantennummer"      => "vendornumber",
 
3096                    "Projektnummer"          => "projectnummer",
 
3097                    "Buchungsnummer"         => "ordnumber",
 
3098                    "Eingangsrechnungnummer" => "invnumber",
 
3099                    "Ausgangsrechnungnummer" => "invnumber",
 
3100                    "Mahnungsnummer"         => "dunning_id"
 
3103   my $dbh = $form->dbconnect(\%myconfig);
 
3105   my $restriction  = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
 
3106   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
 
3107   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
 
3108   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
3109     $restriction  .= qq| AND employee_id = |    . $form->{mitarbeiter};
 
3110   } elsif ($form->{mitarbeiter}) {
 
3111     $restriction  .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
 
3114   my $query = qq|SELECT trans_id AS id FROM history_erp | .
 
3115     (  $form->{'searchid'} ? qq| WHERE snumbers = '|  . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
 
3116      :                       qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
3118   my @ids    = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
 
3119   my $daten .= shift @ids;
 
3120   $daten    .= join '', map { " OR trans_id = $_" } @ids;
 
3122   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
3123   $sort =~ s/.*\.(.*)$/$1/;
 
3125   $form->{title} = $locale->text("History Search");
 
3128   print $form->parse_html_template("common/show_history",
 
3129                                    { "DATEN"          => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
3130                                      "SUCCESS"        => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
3133                                      uc($sort) . "BY" => $sortby,
 
3134                                      'callback'       => $callback,
 
3138   $main::lxdebug->leave_sub();
 
3142   $main::lxdebug->enter_sub();
 
3144   my $form     = $main::form;
 
3145   my %myconfig = %main::myconfig;
 
3147   $main::auth->assert('config');
 
3149   my $dir = $form->{"dir"} eq "down" ? "down" : "up";
 
3150   AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
 
3154   $main::lxdebug->leave_sub();
 
3158   $main::lxdebug->enter_sub();
 
3160   my $form     = $main::form;
 
3161   my $locale   = $main::locale;
 
3163   $main::auth->assert('config');
 
3165   $form->{title} =  $locale->text('Add');
 
3167   $form->{callback} ||= "am.pl?action=add_tax";
 
3169   _get_taxaccount_selection();
 
3173   my $parameters_ref = {
 
3174 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
3177   # Ausgabe des Templates
 
3178   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
3180   $main::lxdebug->leave_sub();
 
3184   $main::lxdebug->enter_sub();
 
3186   my $form     = $main::form;
 
3187   my %myconfig = %main::myconfig;
 
3188   my $locale   = $main::locale;
 
3190   $main::auth->assert('config');
 
3192   $form->{title} =  $locale->text('Edit');
 
3194   AM->get_tax(\%myconfig, \%$form);
 
3195   _get_taxaccount_selection();
 
3197   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
3201   my $parameters_ref = {
 
3204   # Ausgabe des Templates
 
3205   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
3207   $main::lxdebug->leave_sub();
 
3211   $main::lxdebug->enter_sub();
 
3213   my $form     = $main::form;
 
3214   my %myconfig = %main::myconfig;
 
3215   my $locale   = $main::locale;
 
3217   $main::auth->assert('config');
 
3219   AM->taxes(\%myconfig, \%$form);
 
3221   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
3223   $form->{callback} = build_std_url('action=list_tax');
 
3225   $form->{title} = $locale->text('Tax-O-Matic');
 
3229   my $parameters_ref = {
 
3232   # Ausgabe des Templates
 
3233   print($form->parse_html_template('am/list_tax', $parameters_ref));
 
3235   $main::lxdebug->leave_sub();
 
3238 sub _get_taxaccount_selection{
 
3239   $main::lxdebug->enter_sub();
 
3241   my $form     = $main::form;
 
3242   my %myconfig = %main::myconfig;
 
3244   $main::auth->assert('config');
 
3246   AM->get_tax_accounts(\%myconfig, \%$form);
 
3248   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
3250   $main::lxdebug->leave_sub();
 
3254   $main::lxdebug->enter_sub();
 
3256   my $form     = $main::form;
 
3257   my %myconfig = %main::myconfig;
 
3258   my $locale   = $main::locale;
 
3260   $main::auth->assert('config');
 
3262   $form->isblank("rate", $locale->text('Taxrate missing!'));
 
3263   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
 
3264   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
 
3266   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
3268   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
3269     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
3272   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
3273     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
3276   AM->save_tax(\%myconfig, \%$form);
 
3277   $form->redirect($locale->text('Tax saved!'));
 
3279   $main::lxdebug->leave_sub();
 
3283   $main::lxdebug->enter_sub();
 
3285   my $form     = $main::form;
 
3286   my %myconfig = %main::myconfig;
 
3287   my $locale   = $main::locale;
 
3289   $main::auth->assert('config');
 
3291   AM->delete_tax(\%myconfig, \%$form);
 
3292   $form->redirect($locale->text('Tax deleted!'));
 
3294   $main::lxdebug->leave_sub();
 
3297 sub add_price_factor {
 
3298   $main::lxdebug->enter_sub();
 
3300   my $form     = $main::form;
 
3301   my $locale   = $main::locale;
 
3303   $main::auth->assert('config');
 
3305   $form->{title}      = $locale->text('Add Price Factor');
 
3306   $form->{callback} ||= build_std_url('action=add_price_factor');
 
3307   $form->{fokus}      = 'description';
 
3310   print $form->parse_html_template('am/edit_price_factor');
 
3312   $main::lxdebug->leave_sub();
 
3315 sub edit_price_factor {
 
3316   $main::lxdebug->enter_sub();
 
3318   my $form     = $main::form;
 
3319   my %myconfig = %main::myconfig;
 
3320   my $locale   = $main::locale;
 
3322   $main::auth->assert('config');
 
3324   $form->{title}      = $locale->text('Edit Price Factor');
 
3325   $form->{callback} ||= build_std_url('action=add_price_factor');
 
3326   $form->{fokus}      = 'description';
 
3328   AM->get_price_factor(\%myconfig, $form);
 
3330   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
 
3333   print $form->parse_html_template('am/edit_price_factor');
 
3335   $main::lxdebug->leave_sub();
 
3338 sub list_price_factors {
 
3339   $main::lxdebug->enter_sub();
 
3341   my $form     = $main::form;
 
3342   my %myconfig = %main::myconfig;
 
3343   my $locale   = $main::locale;
 
3345   $main::auth->assert('config');
 
3347   AM->get_all_price_factors(\%myconfig, \%$form);
 
3350   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
 
3352       $previous->{next_id}    = $current->{id};
 
3353       $current->{previous_id} = $previous->{id};
 
3356     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
 
3358     $previous = $current;
 
3361   $form->{callback} = build_std_url('action=list_price_factors');
 
3362   $form->{title}    = $locale->text('Price Factors');
 
3363   $form->{url_base} = build_std_url('callback');
 
3366   print $form->parse_html_template('am/list_price_factors');
 
3368   $main::lxdebug->leave_sub();
 
3371 sub save_price_factor {
 
3372   $main::lxdebug->enter_sub();
 
3374   my $form     = $main::form;
 
3375   my %myconfig = %main::myconfig;
 
3376   my $locale   = $main::locale;
 
3378   $main::auth->assert('config');
 
3380   $form->isblank("description", $locale->text('Description missing!'));
 
3381   $form->isblank("factor", $locale->text('Factor missing!'));
 
3383   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
 
3385   AM->save_price_factor(\%myconfig, $form);
 
3387   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
 
3389   $form->redirect($locale->text('Price factor saved!'));
 
3391   $main::lxdebug->leave_sub();
 
3394 sub delete_price_factor {
 
3395   $main::lxdebug->enter_sub();
 
3397   my $form     = $main::form;
 
3398   my %myconfig = %main::myconfig;
 
3399   my $locale   = $main::locale;
 
3401   $main::auth->assert('config');
 
3403   AM->delete_price_factor(\%myconfig, \%$form);
 
3405   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
 
3407   $form->redirect($locale->text('Price factor deleted!'));
 
3409   $main::lxdebug->leave_sub();
 
3412 sub swap_price_factors {
 
3413   $main::lxdebug->enter_sub();
 
3415   my $form     = $main::form;
 
3416   my %myconfig = %main::myconfig;
 
3418   $main::auth->assert('config');
 
3420   AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
 
3421   list_price_factors();
 
3423   $main::lxdebug->leave_sub();
 
3427   $main::lxdebug->enter_sub();
 
3429   my $form     = $main::form;
 
3430   my $locale   = $main::locale;
 
3432   $main::auth->assert('config');
 
3434   $form->{title}      = $locale->text('Add Warehouse');
 
3435   $form->{callback} ||= build_std_url('action=add_warehouse');
 
3436   $form->{fokus}      = 'description';
 
3439   print $form->parse_html_template('am/edit_warehouse');
 
3441   $main::lxdebug->leave_sub();
 
3444 sub edit_warehouse {
 
3445   $main::lxdebug->enter_sub();
 
3447   my $form     = $main::form;
 
3448   my %myconfig = %main::myconfig;
 
3449   my $locale   = $main::locale;
 
3451   $main::auth->assert('config');
 
3453   AM->get_warehouse(\%myconfig, $form);
 
3455   $form->get_lists('employees' => 'EMPLOYEES');
 
3457   $form->{title}      = $locale->text('Edit Warehouse');
 
3458   $form->{callback} ||= build_std_url('action=list_warehouses');
 
3459   $form->{fokus}      = 'description';
 
3462   print $form->parse_html_template('am/edit_warehouse');
 
3464   $main::lxdebug->leave_sub();
 
3467 sub list_warehouses {
 
3468   $main::lxdebug->enter_sub();
 
3470   my $form     = $main::form;
 
3471   my %myconfig = %main::myconfig;
 
3472   my $locale   = $main::locale;
 
3474   $main::auth->assert('config');
 
3476   AM->get_all_warehouses(\%myconfig, $form);
 
3479   foreach my $current (@{ $form->{WAREHOUSES} }) {
 
3481       $previous->{next_id}    = $current->{id};
 
3482       $current->{previous_id} = $previous->{id};
 
3485     $previous = $current;
 
3488   $form->{callback} = build_std_url('action=list_warehouses');
 
3489   $form->{title}    = $locale->text('Warehouses');
 
3490   $form->{url_base} = build_std_url('callback');
 
3493   print $form->parse_html_template('am/list_warehouses');
 
3495   $main::lxdebug->leave_sub();
 
3498 sub save_warehouse {
 
3499   $main::lxdebug->enter_sub();
 
3501   my $form     = $main::form;
 
3502   my %myconfig = %main::myconfig;
 
3503   my $locale   = $main::locale;
 
3505   $main::auth->assert('config');
 
3507   $form->isblank("description", $locale->text('Description missing!'));
 
3509   $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
 
3511   AM->save_warehouse(\%myconfig, $form);
 
3513   $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
 
3515   $form->redirect($locale->text('Warehouse saved.'));
 
3517   $main::lxdebug->leave_sub();
 
3520 sub swap_warehouses {
 
3521   $main::lxdebug->enter_sub();
 
3523   my $form     = $main::form;
 
3524   my %myconfig = %main::myconfig;
 
3526   $main::auth->assert('config');
 
3528   AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
 
3531   $main::lxdebug->leave_sub();
 
3534 sub delete_warehouse {
 
3535   $main::lxdebug->enter_sub();
 
3537   my $form     = $main::form;
 
3538   my %myconfig = %main::myconfig;
 
3539   my $locale   = $main::locale;
 
3541   $main::auth->assert('config');
 
3543   if (!$form->{confirmed}) {
 
3544     $form->{title} = $locale->text('Confirmation');
 
3547     print $form->parse_html_template('am/confirm_delete_warehouse');
 
3551   if (AM->delete_warehouse(\%myconfig, $form)) {
 
3552     $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
 
3553     $form->redirect($locale->text('Warehouse deleted.'));
 
3556     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
 
3559   $main::lxdebug->leave_sub();
 
3563   $main::lxdebug->enter_sub();
 
3565   my $form     = $main::form;
 
3566   my %myconfig = %main::myconfig;
 
3567   my $locale   = $main::locale;
 
3569   $main::auth->assert('config');
 
3571   AM->save_bins(\%myconfig, $form);
 
3573   $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
 
3575   $form->redirect($locale->text('Bins saved.'));
 
3577   $main::lxdebug->leave_sub();