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 #======================================================================
 
  50 require "bin/mozilla/common.pl";
 
  58 sub add      { call_sub("add_$main::form->{type}"); }
 
  59 sub delete   { call_sub("delete_$main::form->{type}"); }
 
  60 sub save     { call_sub("save_$main::form->{type}"); }
 
  61 sub edit     { call_sub("edit_$main::form->{type}"); }
 
  62 sub continue { call_sub($main::form->{"nextsub"}); }
 
  63 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
  66   $main::lxdebug->enter_sub();
 
  68   my $form     = $main::form;
 
  69   my %myconfig = %main::myconfig;
 
  71   $main::auth->assert('config');
 
  73   $form->{title}     = "Add";
 
  74   $form->{charttype} = "A";
 
  75   AM->get_account(\%myconfig, \%$form);
 
  77   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
 
  82   $main::lxdebug->leave_sub();
 
  86   $main::lxdebug->enter_sub();
 
  88   my $form     = $main::form;
 
  89   my %myconfig = %main::myconfig;
 
  91   $main::auth->assert('config');
 
  93   $form->{title} = "Edit";
 
  94   AM->get_account(\%myconfig, \%$form);
 
  96   foreach my $item (split(/:/, $form->{link})) {
 
  97     $form->{$item} = "checked";
 
 103   $main::lxdebug->leave_sub();
 
 107   $main::lxdebug->enter_sub();
 
 109   my $form     = $main::form;
 
 110   my %myconfig = %main::myconfig;
 
 111   my $locale   = $main::locale;
 
 113   $main::auth->assert('config');
 
 115   if ( $form->{action} eq 'edit_account') {
 
 116     $form->{account_exists} = '1';
 
 119   $form->{title} = $locale->text("$form->{title} Account");
 
 121   $form->{"$form->{charttype}_checked"} = "checked";
 
 122   $form->{"$form->{category}_checked"}  = "checked";
 
 124   $form->{select_tax} = "";
 
 126   my @tax_report_pos = USTVA->report_variables({
 
 127       myconfig   => \%myconfig,
 
 130       attribute  => 'position',
 
 134   if (@{ $form->{TAXKEY} }) {
 
 135     foreach my $item (@{ $form->{TAXKEY} }) {
 
 136       $item->{rate} = $item->{rate} * 100 . '%';
 
 139     # Fill in empty row for new Taxkey
 
 140     my $newtaxkey_ref = {
 
 145       taxdescription => '',
 
 152     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 155     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 157       # Fill in a runningnumber
 
 158       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 160       # Fill in the Taxkeys as select options
 
 161       foreach my $item (@{ $form->{TAXKEY} }) {
 
 162         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 163           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 164             qq|<option value="$item->{id}" selected="selected">|
 
 165             . sprintf("%.2d", $item->{taxkey})
 
 166             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 167             . $locale->text('Tax-o-matic Account')
 
 168             . qq|: $item->{chart_accno}\n|;
 
 171           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 172             qq|<option value="$item->{id}">|
 
 173             . sprintf("%.2d", $item->{taxkey})
 
 174             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 175             . $locale->text('Tax-o-matic Account')
 
 176             . qq|: $item->{chart_accno}\n|;
 
 181       # Fill in the USTVA Numbers as select options
 
 182       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 184           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 186         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 187           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 190           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 199   # Newaccount Folgekonto
 
 200   if (@{ $form->{NEWACCOUNT} || [] }) {
 
 201     if (!$form->{new_chart_valid}) {
 
 202       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 204     foreach my $item (@{ $form->{NEWACCOUNT} }) {
 
 205       if ($item->{id} == $form->{new_chart_id}) {
 
 206         $form->{selectnewaccount} .=
 
 207           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 208       } elsif (!$form->{new_chart_valid}) {
 
 209         $form->{selectnewaccount} .=
 
 210           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 216   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 219           2  => "sonstige Erlöse",
 
 220           3  => "Privatanteile",
 
 222           5  => "Ausserordentliche Erträge",
 
 223           6  => "Vereinnahmte Umsatzst.",
 
 224           7  => "Umsatzsteuererstattungen",
 
 225           8  => "Wareneingänge",
 
 226           9  => "Löhne und Gehälter",
 
 227           10 => "Gesetzl. sozialer Aufw.",
 
 229           12 => "Gas, Strom, Wasser",
 
 230           13 => "Instandhaltung",
 
 231           14 => "Steuern, Versich., Beiträge",
 
 233           16 => "Kfz-Versicherungen",
 
 234           17 => "Sonst. Fahrzeugkosten",
 
 235           18 => "Werbe- und Reisekosten",
 
 236           19 => "Instandhaltung u. Werkzeuge",
 
 237           20 => "Fachzeitschriften, Bücher",
 
 238           21 => "Miete für Einrichtungen",
 
 239           22 => "Rechts- und Beratungskosten",
 
 240           23 => "Bürobedarf, Porto, Telefon",
 
 241           24 => "Sonstige Aufwendungen",
 
 242           25 => "Abschreibungen auf Anlagever.",
 
 243           26 => "Abschreibungen auf GWG",
 
 245           28 => "Umsatzsteuerzahlungen",
 
 247           30 => "Ausserordentlicher Aufwand",
 
 248           31 => "Betriebliche Steuern");
 
 249   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
 
 250     my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
 
 251     if ($item == $form->{pos_eur}) {
 
 252       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 254       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 259   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 263              2  => 'Best.Verdg.FE/UE',
 
 264              3  => 'Aktiv.Eigenleistung',
 
 265              4  => 'Mat./Wareneinkauf',
 
 266              5  => 'So.betr.Erlöse',
 
 267              10 => 'Personalkosten',
 
 269              12 => 'Betriebl.Steuern',
 
 270              13 => 'Vers./Beiträge',
 
 271              14 => 'Kfz.Kosten o.St.',
 
 272              15 => 'Werbe-Reisek.',
 
 273              16 => 'Kosten Warenabgabe',
 
 274              17 => 'Abschreibungen',
 
 275              18 => 'Rep./instandhlt.',
 
 276              19 => 'Übrige Steuern',
 
 277              20 => 'Sonst.Kosten',
 
 279              31 => 'Sonst.neutr.Aufw.',
 
 281              33 => 'Sonst.neutr.Ertrag',
 
 282              34 => 'Verr.kalk.Kosten',
 
 283              35 => 'Steuern Eink.u.Ertr.');
 
 284   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
 
 285     my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
 
 286     if ($item == $form->{pos_bwa}) {
 
 287       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 289       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 294 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 295   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 296   foreach my $item ((1, 2, 3, 4)) {
 
 297     if ($item == $form->{pos_bilanz}) {
 
 298       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 300       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 305   # this is for our parser only! Do not remove.
 
 306   # type=submit $locale->text('Add Account')
 
 307   # type=submit $locale->text('Edit Account')
 
 309   $form->{type} = "account";
 
 311   # preselections category
 
 313   my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 316       'A'  => $locale->text('Asset'),
 
 317       'L'  => $locale->text('Liability'),
 
 318       'Q'  => $locale->text('Equity'),
 
 319       'I'  => $locale->text('Revenue'),
 
 320       'E'  => $locale->text('Expense'),
 
 321       'C'  => $locale->text('Costs'),
 
 323   foreach my $item ( sort({ $a <=> $b } keys %category) ) {
 
 324     if ($item eq $form->{category}) {
 
 325       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 327       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 332   # preselection chart type
 
 333   my $select_charttype = q{};
 
 336       'A'  => $locale->text('Account'),
 
 337       'H'  => $locale->text('Heading'),
 
 340   foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
 
 341     if ($item eq $form->{charttype}) {
 
 342       $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
 
 345       $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
 
 350   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 354   my $parameters_ref = {
 
 355     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 356     select_category            => $select_category,
 
 357     select_charttype           => $select_charttype,
 
 358     select_bwa                 => $select_bwa,
 
 359     select_bilanz              => $select_bilanz,
 
 360     select_eur                 => $select_eur,
 
 363   # Ausgabe des Templates
 
 364   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 367   $main::lxdebug->leave_sub();
 
 371   $main::lxdebug->enter_sub();
 
 373   my $form     = $main::form;
 
 374   my $locale   = $main::locale;
 
 376   $main::auth->assert('config');
 
 380 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
 
 383   if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
 
 385 <input type=submit class=submit name=action value="|
 
 386     . $locale->text('Save') . qq|">
 
 390   if ($form->{id} && $form->{orphaned}) {
 
 391     print qq|<input type=submit class=submit name=action value="|
 
 392       . $locale->text('Delete') . qq|">|;
 
 395   if ($form->{id} && $form->{type} eq "account") {
 
 397     <input class=submit type=submit name=action value="|
 
 398       . $locale->text('Save as new') . qq|">|;
 
 408   $main::lxdebug->leave_sub();
 
 412   $main::lxdebug->enter_sub();
 
 414   my $form     = $main::form;
 
 415   my %myconfig = %main::myconfig;
 
 416   my $locale   = $main::locale;
 
 418   $main::auth->assert('config');
 
 420   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 421   $form->isblank("description", $locale->text('Account Description missing!'));
 
 423   if ($form->{charttype} eq 'A'){
 
 424     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 427   $form->redirect($locale->text('Account saved!'))
 
 428     if (AM->save_account(\%myconfig, \%$form));
 
 429   $form->error($locale->text('Cannot save account!'));
 
 431   $main::lxdebug->leave_sub();
 
 434 sub save_as_new_account {
 
 435   $main::lxdebug->enter_sub();
 
 437   my $form     = $main::form;
 
 438   my %myconfig = %main::myconfig;
 
 439   my $locale   = $main::locale;
 
 441   $main::auth->assert('config');
 
 443   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 444   $form->isblank("description", $locale->text('Account Description missing!'));
 
 446   if ($form->{charttype} eq 'A'){
 
 447     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 450   for my $taxkey (0 .. 9) {
 
 451     if ($form->{"taxkey_id_$taxkey"}) {
 
 452       $form->{"taxkey_id_$taxkey"} = "NEW";
 
 457   if ($form->{"original_accno"} &&
 
 458       ($form->{"accno"} eq $form->{"original_accno"})) {
 
 459     $form->error($locale->text('Account Number already used!'));
 
 461   $form->redirect($locale->text('Account saved!'))
 
 462     if (AM->save_account(\%myconfig, \%$form));
 
 463   $form->error($locale->text('Cannot save account!'));
 
 465   $main::lxdebug->leave_sub();
 
 469   $main::lxdebug->enter_sub();
 
 471   my $form     = $main::form;
 
 472   my %myconfig = %main::myconfig;
 
 473   my $locale   = $main::locale;
 
 475   $main::auth->assert('config');
 
 477   $form->{callback}     = build_std_url('action=list_account');
 
 478   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 480   CA->all_accounts(\%myconfig, \%$form);
 
 482   foreach my $ca (@{ $form->{CA} }) {
 
 487     if ($ca->{amount} > 0) {
 
 488       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 490     if ($ca->{amount} < 0) {
 
 491       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 493     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:'';
 
 494     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 498   my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
 
 500   # Eneable AJAX debuging
 
 504   push(@ { $form->{AJAX} }, $pjx);
 
 506   $form->{stylesheets} = "list_accounts.css";
 
 507   $form->{title}       = $locale->text('Chart of Accounts');
 
 512   my $parameters_ref = {
 
 513   #   hidden_variables                => $_hidden_variables_ref,
 
 516   # Ausgabe des Templates
 
 517   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
 519   $main::lxdebug->leave_sub();
 
 524 sub list_account_details {
 
 525 # Ajax Funktion aus list_account_details
 
 526   $main::lxdebug->enter_sub();
 
 528   my $form     = $main::form;
 
 529   my %myconfig = %main::myconfig;
 
 530   my $locale   = $main::locale;
 
 532   $main::auth->assert('config');
 
 534   my $chart_id = $form->{args};
 
 536   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 538   foreach my $ca (@{ $form->{CA} }) {
 
 540     $ca->{debit}  = " ";
 
 541     $ca->{credit} = " ";
 
 543     if ($ca->{amount} > 0) {
 
 545         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 547     if ($ca->{amount} < 0) {
 
 549         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 552     my @links = split( q{:}, $ca->{link});
 
 556     foreach my $link (@links){
 
 557       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 558                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 559                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 560                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 561                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 562                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 563                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 564                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 565                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 566                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 567                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 568                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 569                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 570                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 571                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 572 #               : ( $link eq 'CT_tax' )        ? $locale->text('Account Link CT_tax')
 
 573                : $locale->text('Unknown Link') . ': ' . $link;
 
 574       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 577     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 578                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 579                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 580                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 581                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 582                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 583                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 584                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 587   $form->{title} = $locale->text('Chart of Accounts');
 
 590   print $form->parse_html_template('am/list_account_details');
 
 592   $main::lxdebug->leave_sub();
 
 597   $main::lxdebug->enter_sub();
 
 599   my $form     = $main::form;
 
 600   my %myconfig = %main::myconfig;
 
 601   my $locale   = $main::locale;
 
 603   $main::auth->assert('config');
 
 605   $form->{title} = $locale->text('Delete Account');
 
 608     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
 
 610     if ($form->{id} == $form->{$id}) {
 
 611       $form->error($locale->text('Cannot delete default account!'));
 
 615   $form->redirect($locale->text('Account deleted!'))
 
 616     if (AM->delete_account(\%myconfig, \%$form));
 
 617   $form->error($locale->text('Cannot delete account!'));
 
 619   $main::lxdebug->leave_sub();
 
 623   $main::lxdebug->enter_sub();
 
 625   my $form     = $main::form;
 
 627   $main::auth->assert('config');
 
 629   $form->{title} = "Add";
 
 632   $form->{callback} = "am.pl?action=add_department" unless $form->{callback};
 
 637   $main::lxdebug->leave_sub();
 
 640 sub edit_department {
 
 641   $main::lxdebug->enter_sub();
 
 643   my $form     = $main::form;
 
 644   my %myconfig = %main::myconfig;
 
 646   $main::auth->assert('config');
 
 648   $form->{title} = "Edit";
 
 650   AM->get_department(\%myconfig, \%$form);
 
 655   $main::lxdebug->leave_sub();
 
 658 sub list_department {
 
 659   $main::lxdebug->enter_sub();
 
 661   my $form     = $main::form;
 
 662   my %myconfig = %main::myconfig;
 
 663   my $locale   = $main::locale;
 
 665   $main::auth->assert('config');
 
 667   AM->departments(\%myconfig, \%$form);
 
 669   $form->{callback} = "am.pl?action=list_department";
 
 671   my $callback = $form->escape($form->{callback});
 
 673   $form->{title} = $locale->text('Departments');
 
 675   my @column_index = qw(description cost profit);
 
 677   $column_header{description} =
 
 678       qq|<th class=listheading width=90%>|
 
 679     . $locale->text('Description')
 
 681   $column_header{cost} =
 
 682       qq|<th class=listheading nowrap>|
 
 683     . $locale->text('Cost Center')
 
 685   $column_header{profit} =
 
 686       qq|<th class=listheading nowrap>|
 
 687     . $locale->text('Profit Center')
 
 697     <th class=listtop>$form->{title}</th>
 
 703         <tr class=listheading>
 
 706   map { print "$column_header{$_}\n" } @column_index;
 
 712   my ($i, %column_data);
 
 713   foreach my $ref (@{ $form->{ALL} }) {
 
 719         <tr valign=top class=listrow$i>
 
 722     my $costcenter   = ($ref->{role} eq "C") ? "X" : "";
 
 723     my $profitcenter = ($ref->{role} eq "P") ? "X" : "";
 
 725     $column_data{description} =
 
 726       qq|<td><a href="am.pl?action=edit_department&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
 727     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
 
 728     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
 
 730     map { print "$column_data{$_}\n" } @column_index;
 
 742   <td><hr size=3 noshade></td>
 
 747 <form method=post action=am.pl>
 
 749 <input name=callback type=hidden value="$form->{callback}">
 
 751 <input type=hidden name=type value=department>
 
 753 <input class=submit type=submit name=action value="|
 
 754     . $locale->text('Add') . qq|">
 
 762   $main::lxdebug->leave_sub();
 
 765 sub department_header {
 
 766   $main::lxdebug->enter_sub();
 
 768   my $form     = $main::form;
 
 769   my $locale   = $main::locale;
 
 771   $main::auth->assert('config');
 
 773   $form->{title} = $locale->text("$form->{title} Department");
 
 775   # $locale->text('Add Department')
 
 776   # $locale->text('Edit Department')
 
 778   $form->{description} =~ s/\"/"/g;
 
 780   my ($rows, $description);
 
 781   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
 
 783       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
 
 786       qq|<input name=description size=60 value="$form->{description}">|;
 
 789   my $costcenter   = "checked" if $form->{role} eq "C";
 
 790   my $profitcenter = "checked" if $form->{role} eq "P";
 
 797 <form method=post action=am.pl>
 
 799 <input type=hidden name=id value=$form->{id}>
 
 800 <input type=hidden name=type value=department>
 
 804     <th class=listtop colspan=2>$form->{title}</th>
 
 808     <th align=right>| . $locale->text('Description') . qq|</th>
 
 809     <td>$description</td>
 
 813     <td><input type=radio style=radio name=role value="C" $costcenter> |
 
 814     . $locale->text('Cost Center') . qq|
 
 815         <input type=radio style=radio name=role value="P" $profitcenter> |
 
 816     . $locale->text('Profit Center') . qq|
 
 819     <td colspan=2><hr size=3 noshade></td>
 
 824   $main::lxdebug->leave_sub();
 
 827 sub save_department {
 
 828   $main::lxdebug->enter_sub();
 
 830   my $form     = $main::form;
 
 831   my %myconfig = %main::myconfig;
 
 832   my $locale   = $main::locale;
 
 834   $main::auth->assert('config');
 
 836   $form->isblank("description", $locale->text('Description missing!'));
 
 837   AM->save_department(\%myconfig, \%$form);
 
 838   $form->redirect($locale->text('Department saved!'));
 
 840   $main::lxdebug->leave_sub();
 
 843 sub delete_department {
 
 844   $main::lxdebug->enter_sub();
 
 846   my $form     = $main::form;
 
 847   my %myconfig = %main::myconfig;
 
 848   my $locale   = $main::locale;
 
 850   $main::auth->assert('config');
 
 852   AM->delete_department(\%myconfig, \%$form);
 
 853   $form->redirect($locale->text('Department deleted!'));
 
 855   $main::lxdebug->leave_sub();
 
 859   $main::lxdebug->enter_sub();
 
 861   my $form     = $main::form;
 
 863   $main::auth->assert('config');
 
 865   $form->{title} = "Add";
 
 867   $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
 
 872   $main::lxdebug->leave_sub();
 
 876   $main::lxdebug->enter_sub();
 
 878   my $form     = $main::form;
 
 879   my %myconfig = %main::myconfig;
 
 881   $main::auth->assert('config');
 
 883   $form->{title} = "Edit";
 
 885   AM->get_lead(\%myconfig, \%$form);
 
 889   $form->{orphaned} = 1;
 
 892   $main::lxdebug->leave_sub();
 
 896   $main::lxdebug->enter_sub();
 
 898   my $form     = $main::form;
 
 899   my %myconfig = %main::myconfig;
 
 900   my $locale   = $main::locale;
 
 902   $main::auth->assert('config');
 
 904   AM->lead(\%myconfig, \%$form);
 
 906   $form->{callback} = "am.pl?action=list_lead";
 
 908   my $callback = $form->escape($form->{callback});
 
 910   $form->{title} = $locale->text('Lead');
 
 912   my @column_index = qw(description cost profit);
 
 914   $column_header{description} =
 
 915       qq|<th class=listheading width=100%>|
 
 916     . $locale->text('Description')
 
 926     <th class=listtop>$form->{title}</th>
 
 929   <tr class=listheading>
 
 932   map { print "$column_header{$_}\n" } @column_index;
 
 938   my ($i, %column_data);
 
 939   foreach my $ref (@{ $form->{ALL} }) {
 
 945   <tr valign=top class=listrow$i>
 
 948 #    $lead = $ref->{lead};
 
 950     $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
 
 952     map { print "$column_data{$_}\n" } @column_index;
 
 961   <td><hr size=3 noshade></td>
 
 966 <form method=post action=am.pl>
 
 968 <input name=callback type=hidden value="$form->{callback}">
 
 970 <input type=hidden name=type value=lead>
 
 972 <input class=submit type=submit name=action value="|
 
 973     . $locale->text('Add') . qq|">
 
 981   $main::lxdebug->leave_sub();
 
 985   $main::lxdebug->enter_sub();
 
 987   my $form     = $main::form;
 
 988   my $locale   = $main::locale;
 
 990   $main::auth->assert('config');
 
 992   $form->{title} = $locale->text("$form->{title} Lead");
 
 994   # $locale->text('Add Lead')
 
 995   # $locale->text('Edit Lead')
 
 997   $form->{description} =~ s/\"/"/g;
 
1000       qq|<input name=description size=50 value="$form->{lead}">|;
 
1007 <form method=post action=am.pl>
 
1009 <input type=hidden name=id value=$form->{id}>
 
1010 <input type=hidden name=type value=lead>
 
1014     <th class=listtop colspan=2>$form->{title}</th>
 
1016   <tr height="5"></tr>
 
1018     <th align=right>| . $locale->text('Description') . qq|</th>
 
1019     <td>$description</td>
 
1021     <td colspan=2><hr size=3 noshade></td>
 
1026   $main::lxdebug->leave_sub();
 
1030   $main::lxdebug->enter_sub();
 
1032   my $form     = $main::form;
 
1033   my %myconfig = %main::myconfig;
 
1034   my $locale   = $main::locale;
 
1036   $main::auth->assert('config');
 
1038   $form->isblank("description", $locale->text('Description missing!'));
 
1039   AM->save_lead(\%myconfig, \%$form);
 
1040   $form->redirect($locale->text('lead saved!'));
 
1042   $main::lxdebug->leave_sub();
 
1046   $main::lxdebug->enter_sub();
 
1048   my $form     = $main::form;
 
1049   my %myconfig = %main::myconfig;
 
1050   my $locale   = $main::locale;
 
1052   $main::auth->assert('config');
 
1054   AM->delete_lead(\%myconfig, \%$form);
 
1055   $form->redirect($locale->text('lead deleted!'));
 
1057   $main::lxdebug->leave_sub();
 
1061   $main::lxdebug->enter_sub();
 
1063   my $form     = $main::form;
 
1065   $main::auth->assert('config');
 
1067   $form->{title} = "Add";
 
1069   $form->{callback} = "am.pl?action=add_business" unless $form->{callback};
 
1074   $main::lxdebug->leave_sub();
 
1078   $main::lxdebug->enter_sub();
 
1080   my $form     = $main::form;
 
1081   my %myconfig = %main::myconfig;
 
1083   $form->{title} = "Edit";
 
1085   AM->get_business(\%myconfig, \%$form);
 
1089   $form->{orphaned} = 1;
 
1092   $main::lxdebug->leave_sub();
 
1096   $main::lxdebug->enter_sub();
 
1098   my $form     = $main::form;
 
1099   my %myconfig = %main::myconfig;
 
1100   my $locale   = $main::locale;
 
1102   $main::auth->assert('config');
 
1104   AM->business(\%myconfig, \%$form);
 
1106   $form->{callback} = "am.pl?action=list_business";
 
1108   my $callback = $form->escape($form->{callback});
 
1110   $form->{title} = $locale->text('Type of Business');
 
1112   my @column_index = qw(description discount customernumberinit);
 
1113   push @column_index, 'salesman' if $::vertreter;
 
1115   $column_header{description} =
 
1116       qq|<th class=listheading width=60%>|
 
1117     . $locale->text('Description')
 
1119   $column_header{discount} =
 
1120       qq|<th class=listheading width=10%>|
 
1121     . $locale->text('Discount')
 
1123   $column_header{customernumberinit} =
 
1124       qq|<th class=listheading>|
 
1125     . $locale->text('Customernumberinit')
 
1127   $column_header{salesman} =
 
1128       qq|<th class=listheading>|
 
1129     . $locale->text('Representative')
 
1139     <th class=listtop>$form->{title}</th>
 
1141   <tr height="5"></tr>
 
1145         <tr class=listheading>
 
1148   map { print "$column_header{$_}\n" } @column_index;
 
1154   my ($i, %column_data);
 
1155   foreach my $ref (@{ $form->{ALL} }) {
 
1161         <tr valign=top class=listrow$i>
 
1164     my $discount    = $form->format_amount(\%myconfig, $ref->{discount} * 100);
 
1165     my $description = $ref->{description};
 
1166     $column_data{description} = qq|<td><a href="am.pl?action=edit_business&id=$ref->{id}&callback=$callback">$description</td>|;
 
1167     $column_data{discount}           = qq|<td align=right>$discount</td>|;
 
1168     $column_data{customernumberinit} =
 
1169       qq|<td align=right>$ref->{customernumberinit}</td>|;
 
1170     $column_data{salesman} = '<td>' . ($ref->{salesman} ? $::locale->text('Yes') : $::locale->text('No')) . '</td>';
 
1172     map { print "$column_data{$_}\n" } @column_index;
 
1184   <td><hr size=3 noshade></td>
 
1189 <form method=post action=am.pl>
 
1191 <input name=callback type=hidden value="$form->{callback}">
 
1193 <input type=hidden name=type value=business>
 
1195 <input class=submit type=submit name=action value="|
 
1196     . $locale->text('Add') . qq|">
 
1204   $main::lxdebug->leave_sub();
 
1207 sub business_header {
 
1208   $main::lxdebug->enter_sub();
 
1210   my $form     = $main::form;
 
1211   my %myconfig = %main::myconfig;
 
1212   my $locale   = $main::locale;
 
1214   $main::auth->assert('config');
 
1216   $form->{title}    = $locale->text("$form->{title} Business");
 
1218   # $locale->text('Add Business')
 
1219   # $locale->text('Edit Business')
 
1221   $form->{description} =~ s/\"/"/g;
 
1223     $form->format_amount(\%myconfig, $form->{discount} * 100);
 
1227     $salesman_code = qq|
 
1229     <th align="right">| . $locale->text('Representative') . qq|</th>
 
1230     <td>| . $::cgi->checkbox(-name => "salesman", -value => 1, -label => '', 'checked' => $form->{salesman} ? 1 : 0) . qq|</td>
 
1234     $salesman_code = $::cgi->hidden(-name => 'salesman', -value => $form->{salesman} ? 1 : 0);
 
1242 <form method=post action=am.pl>
 
1244 <input type=hidden name=id value=$form->{id}>
 
1245 <input type=hidden name=type value=business>
 
1249     <th class=listtop colspan=2>$form->{title}</th>
 
1251   <tr height="5"></tr>
 
1253     <th align=right>| . $locale->text('Type of Business') . qq|</th>
 
1254     <td><input name=description size=30 value="$form->{description}"></td>
 
1257     <th align=right>| . $locale->text('Discount') . qq| %</th>
 
1258     <td><input name=discount size=5 value=$form->{discount}></td>
 
1261     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
 
1262     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
 
1265   <td colspan=2><hr size=3 noshade></td>
 
1270   $main::lxdebug->leave_sub();
 
1274   $main::lxdebug->enter_sub();
 
1276   my $form     = $main::form;
 
1277   my %myconfig = %main::myconfig;
 
1278   my $locale   = $main::locale;
 
1280   $main::auth->assert('config');
 
1282   $form->isblank("description", $locale->text('Description missing!'));
 
1283   $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
 
1284   AM->save_business(\%myconfig, \%$form);
 
1285   $form->redirect($locale->text('Business saved!'));
 
1287   $main::lxdebug->leave_sub();
 
1290 sub delete_business {
 
1291   $main::lxdebug->enter_sub();
 
1293   my $form     = $main::form;
 
1294   my %myconfig = %main::myconfig;
 
1295   my $locale   = $main::locale;
 
1297   $main::auth->assert('config');
 
1299   AM->delete_business(\%myconfig, \%$form);
 
1300   $form->redirect($locale->text('Business deleted!'));
 
1302   $main::lxdebug->leave_sub();
 
1306   $main::lxdebug->enter_sub();
 
1308   my $form     = $main::form;
 
1310   $main::auth->assert('config');
 
1312   $form->{title} = "Add";
 
1314   $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
 
1319   $main::lxdebug->leave_sub();
 
1323   $main::lxdebug->enter_sub();
 
1325   my $form     = $main::form;
 
1326   my %myconfig = %main::myconfig;
 
1328   $main::auth->assert('config');
 
1330   $form->{title} = "Edit";
 
1332   AM->get_language(\%myconfig, \%$form);
 
1336   $form->{orphaned} = 1;
 
1339   $main::lxdebug->leave_sub();
 
1343   $main::lxdebug->enter_sub();
 
1345   my $form     = $main::form;
 
1346   my %myconfig = %main::myconfig;
 
1347   my $locale   = $main::locale;
 
1349   $main::auth->assert('config');
 
1351   AM->language(\%myconfig, \%$form);
 
1353   $form->{callback} = "am.pl?action=list_language";
 
1355   my $callback = $form->escape($form->{callback});
 
1357   $form->{title} = $locale->text('Languages');
 
1359   my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
 
1361   $column_header{description} =
 
1362       qq|<th class=listheading width=60%>|
 
1363     . $locale->text('Description')
 
1365   $column_header{template_code} =
 
1366       qq|<th class=listheading width=10%>|
 
1367     . $locale->text('Template Code')
 
1369   $column_header{article_code} =
 
1370       qq|<th class=listheading>|
 
1371     . $locale->text('Article Code')
 
1373   $column_header{output_numberformat} =
 
1374       qq|<th class=listheading>|
 
1375     . $locale->text('Number Format')
 
1377   $column_header{output_dateformat} =
 
1378       qq|<th class=listheading>|
 
1379     . $locale->text('Date Format')
 
1381   $column_header{output_longdates} =
 
1382       qq|<th class=listheading>|
 
1383     . $locale->text('Long Dates')
 
1393     <th class=listtop>$form->{title}</th>
 
1395   <tr height="5"></tr>
 
1399         <tr class=listheading>
 
1402   map { print "$column_header{$_}\n" } @column_index;
 
1408   my ($i, %column_data);
 
1409   foreach my $ref (@{ $form->{ALL} }) {
 
1415         <tr valign=top class=listrow$i>
 
1419     $column_data{description} =
 
1420       qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1421     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
 
1422     $column_data{article_code} =
 
1423       qq|<td align=right>$ref->{article_code}</td>|;
 
1424     $column_data{output_numberformat} =
 
1426       ($ref->{output_numberformat} ? $ref->{output_numberformat} :
 
1427        $locale->text("use program settings")) .
 
1429     $column_data{output_dateformat} =
 
1431       ($ref->{output_dateformat} ? $ref->{output_dateformat} :
 
1432        $locale->text("use program settings")) .
 
1434     $column_data{output_longdates} =
 
1436       ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
 
1439     map { print "$column_data{$_}\n" } @column_index;
 
1451   <td><hr size=3 noshade></td>
 
1456 <form method=post action=am.pl>
 
1458 <input name=callback type=hidden value="$form->{callback}">
 
1460 <input type=hidden name=type value=language>
 
1462 <input class=submit type=submit name=action value="|
 
1463     . $locale->text('Add') . qq|">
 
1471   $main::lxdebug->leave_sub();
 
1474 sub language_header {
 
1475   $main::lxdebug->enter_sub();
 
1477   my $form     = $main::form;
 
1478   my $locale   = $main::locale;
 
1480   $main::auth->assert('config');
 
1482   $form->{title}    = $locale->text("$form->{title} Language");
 
1484   # $locale->text('Add Language')
 
1485   # $locale->text('Edit Language')
 
1487   $form->{description} =~ s/\"/"/g;
 
1488   $form->{template_code} =~ s/\"/"/g;
 
1489   $form->{article_code} =~ s/\"/"/g;
 
1495     qq|<option value="">| . $locale->text("use program settings") .
 
1497   foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
 
1499       ($item eq $form->{output_numberformat})
 
1500       ? "<option selected>$item"
 
1506     qq|<option value="">| . $locale->text("use program settings") .
 
1508   foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
 
1510       ($item eq $form->{output_dateformat})
 
1511       ? "<option selected>$item"
 
1519 <form method=post action=am.pl>
 
1521 <input type=hidden name=id value=$form->{id}>
 
1522 <input type=hidden name=type value=language>
 
1526     <th class=listtop colspan=2>$form->{title}</th>
 
1528   <tr height="5"></tr>
 
1530     <th align=right>| . $locale->text('Language') . qq|</th>
 
1531     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1534     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1535     <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
 
1538     <th align=right>| . $locale->text('Article Code') . qq|</th>
 
1539     <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
 
1542     <th align=right>| . $locale->text('Number Format') . qq|</th>
 
1543     <td><select name="output_numberformat">$numberformat</select></td>
 
1546     <th align=right>| . $locale->text('Date Format') . qq|</th>
 
1547     <td><select name="output_dateformat">$dateformat</select></td>
 
1550     <th align=right>| . $locale->text('Long Dates') . qq|</th>
 
1551     <td><input type="radio" name="output_longdates" value="1"| .
 
1552     ($form->{output_longdates} ? " checked" : "") .
 
1553     qq|>| . $locale->text("Yes") .
 
1554     qq|<input type="radio" name="output_longdates" value="0"| .
 
1555     ($form->{output_longdates} ? "" : " checked") .
 
1556     qq|>| . $locale->text("No") .
 
1559   <td colspan=2><hr size=3 noshade></td>
 
1564   $main::lxdebug->leave_sub();
 
1568   $main::lxdebug->enter_sub();
 
1570   my $form     = $main::form;
 
1571   my %myconfig = %main::myconfig;
 
1572   my $locale   = $main::locale;
 
1574   $main::auth->assert('config');
 
1576   $form->isblank("description", $locale->text('Language missing!'));
 
1577   $form->isblank("template_code", $locale->text('Template Code missing!'));
 
1578   $form->isblank("article_code", $locale->text('Article Code missing!'));
 
1579   AM->save_language(\%myconfig, \%$form);
 
1580   $form->redirect($locale->text('Language saved!'));
 
1582   $main::lxdebug->leave_sub();
 
1585 sub delete_language {
 
1586   $main::lxdebug->enter_sub();
 
1588   my $form     = $main::form;
 
1589   my %myconfig = %main::myconfig;
 
1590   my $locale   = $main::locale;
 
1592   $main::auth->assert('config');
 
1594   AM->delete_language(\%myconfig, \%$form);
 
1595   $form->redirect($locale->text('Language deleted!'));
 
1597   $main::lxdebug->leave_sub();
 
1601 sub add_buchungsgruppe {
 
1602   $main::lxdebug->enter_sub();
 
1604   my $form     = $main::form;
 
1605   my %myconfig = %main::myconfig;
 
1606   my $locale   = $main::locale;
 
1608   $main::auth->assert('config');
 
1610   # $locale->text("Add Buchungsgruppe")
 
1611   # $locale->text("Edit Buchungsgruppe")
 
1612   $form->{title} = "Add";
 
1614   $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
 
1616   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1617   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
 
1618   for (my $i = 0; 4 > $i; $i++) {
 
1619     map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
 
1620         qw(income expense));
 
1623   &buchungsgruppe_header;
 
1626   $main::lxdebug->leave_sub();
 
1629 sub edit_buchungsgruppe {
 
1630   $main::lxdebug->enter_sub();
 
1632   my $form     = $main::form;
 
1633   my %myconfig = %main::myconfig;
 
1635   $main::auth->assert('config');
 
1637   $form->{title} = "Edit";
 
1639   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1641   &buchungsgruppe_header;
 
1645   $main::lxdebug->leave_sub();
 
1648 sub list_buchungsgruppe {
 
1649   $main::lxdebug->enter_sub();
 
1651   my $form     = $main::form;
 
1652   my %myconfig = %main::myconfig;
 
1653   my $locale   = $main::locale;
 
1655   $main::auth->assert('config');
 
1657   AM->buchungsgruppe(\%myconfig, \%$form);
 
1659   $form->{callback} = "am.pl?action=list_buchungsgruppe";
 
1661   my $callback = $form->escape($form->{callback});
 
1663   $form->{title} = $locale->text('Buchungsgruppen');
 
1665   my @column_index = qw(up down description inventory_accno
 
1666                      income_accno_0 expense_accno_0
 
1667                      income_accno_1 expense_accno_1
 
1668                      income_accno_2 expense_accno_2
 
1669                      income_accno_3 expense_accno_3 );
 
1671   $column_header{up} =
 
1672       qq|<th class="listheading" width="16">|
 
1673     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
1675   $column_header{down} =
 
1676       qq|<th class="listheading" width="16">|
 
1677     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
1679   $column_header{description} =
 
1680       qq|<th class="listheading" width="40%">|
 
1681     . $locale->text('Description')
 
1683   $column_header{inventory_accno} =
 
1684       qq|<th class=listheading>|
 
1685     . $locale->text('Bestandskonto')
 
1687   $column_header{income_accno_0} =
 
1688       qq|<th class=listheading>|
 
1689     . $locale->text('National Revenues')
 
1691   $column_header{expense_accno_0} =
 
1692       qq|<th class=listheading>|
 
1693     . $locale->text('National Expenses')
 
1695   $column_header{income_accno_1} =
 
1696       qq|<th class=listheading>|
 
1697     . $locale->text('Revenues EU with UStId')
 
1699   $column_header{expense_accno_1} =
 
1700       qq|<th class=listheading>|
 
1701     . $locale->text('Expenses EU with UStId')
 
1703   $column_header{income_accno_2} =
 
1704       qq|<th class=listheading>|
 
1705     . $locale->text('Revenues EU without UStId')
 
1707   $column_header{expense_accno_2} =
 
1708       qq|<th class=listheading>|
 
1709     . $locale->text('Expenses EU without UStId')
 
1711   $column_header{income_accno_3} =
 
1712       qq|<th class=listheading>|
 
1713     . $locale->text('Foreign Revenues')
 
1715   $column_header{expense_accno_3} =
 
1716       qq|<th class=listheading>|
 
1717     . $locale->text('Foreign Expenses')
 
1726     <th class=listtop>$form->{title}</th>
 
1728   <tr height="5"></tr>
 
1732         <tr class=listheading>
 
1735   map { print "$column_header{$_}\n" } @column_index;
 
1741   my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
 
1744   my ($i, %column_data);
 
1745   foreach my $ref (@{ $form->{ALL} }) {
 
1751         <tr valign=top class=listrow$i>
 
1755       my $pref = $form->{ALL}->[$row - 1];
 
1757         qq|<td align="center" valign="center" width="16">| .
 
1758         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
 
1759         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
1762       $column_data{up} = qq|<td width="16"> </td>|;
 
1765     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
1766       $column_data{down} = qq|<td width="16"> </td>|;
 
1768       my $nref = $form->{ALL}->[$row + 1];
 
1769       $column_data{down} =
 
1770         qq|<td align="center" valign="center" width="16">| .
 
1771         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
 
1772         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
1776     $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1777     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
 
1778     $column_data{income_accno_0} =
 
1779       qq|<td align=right>$ref->{income_accno_0}</td>|;
 
1780     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
 
1781     $column_data{income_accno_1} =
 
1782       qq|<td align=right>$ref->{income_accno_1}</td>|;
 
1783     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
 
1784     $column_data{income_accno_2} =
 
1785       qq|<td align=right>$ref->{income_accno_2}</td>|;
 
1786     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
 
1787     $column_data{income_accno_3} =
 
1788       qq|<td align=right>$ref->{income_accno_3}</td>|;
 
1789     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
 
1791     map { print "$column_data{$_}\n" } @column_index;
 
1805   <td><hr size=3 noshade></td>
 
1810 <form method=post action=am.pl>
 
1812 <input name=callback type=hidden value="$form->{callback}">
 
1814 <input type=hidden name=type value=buchungsgruppe>
 
1816 <input class=submit type=submit name=action value="|
 
1817     . $locale->text('Add') . qq|">
 
1825   $main::lxdebug->leave_sub();
 
1828 sub buchungsgruppe_header {
 
1829   $main::lxdebug->enter_sub();
 
1831   my $form     = $main::form;
 
1832   my $locale   = $main::locale;
 
1834   $main::auth->assert('config');
 
1836   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
 
1838   # $locale->text('Add Accounting Group')
 
1839   # $locale->text('Edit Accounting Group')
 
1841   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
 
1842   my %acc_type_map = (
 
1843     "IC" => $acc_inventory,
 
1844     "IC_income" => $acc_income,
 
1845     "IC_sale" => $acc_income,
 
1846     "IC_expense" => $acc_expense,
 
1847     "IC_cogs" => $acc_expense,
 
1850   foreach my $key (keys(%acc_type_map)) {
 
1851     foreach my $ref (@{ $form->{IC_links}{$key} }) {
 
1852       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
 
1856   foreach my $type (qw(IC IC_income IC_expense)) {
 
1857     $form->{"select$type"} =
 
1859            map({ "<option value=$_->{id} $_->{selected}>" .
 
1860                    "$_->{accno}--" . H($_->{description}) . "</option>" }
 
1861                sort({ $a->{"accno"} cmp $b->{"accno"} }
 
1862                     values(%{$acc_type_map{$type}}))));
 
1866     $form->{selectIC} =~ s/selected//g;
 
1867     $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/  value=$form->{inventory_accno_id} selected/;
 
1868     $form->{selectIC_income} =~ s/selected//g;
 
1869     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/  value=$form->{income_accno_id_0} selected/;
 
1870     $form->{selectIC_expense} =~ s/selected//g;
 
1871     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
 
1878                 <th align=right>| . $locale->text('Inventory') . qq|</th>
 
1879                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
 
1880                 <input name=selectIC type=hidden value="$form->{selectIC}">
 
1884                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
 
1888   $linkaccounts .= qq|
 
1890                 <th align=right>| . $locale->text('National Revenues') . qq|</th>
 
1891                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
 
1894                 <th align=right>| . $locale->text('National Expenses') . qq|</th>
 
1895                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
 
1898     $form->{selectIC_income} =~ s/selected//g;
 
1899     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/  value=$form->{income_accno_id_1} selected/;
 
1900     $form->{selectIC_expense} =~ s/selected//g;
 
1901     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/  value=$form->{expense_accno_id_1} selected/;
 
1903   $linkaccounts .= qq|              <tr>
 
1904                 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
 
1905                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
 
1908                 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
 
1909                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
 
1913     $form->{selectIC_income} =~ s/selected//g;
 
1914     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/  value=$form->{income_accno_id_2} selected/;
 
1915     $form->{selectIC_expense} =~ s/selected//g;
 
1916     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/  value=$form->{expense_accno_id_2} selected/;
 
1919   $linkaccounts .= qq|              <tr>
 
1920                 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
 
1921                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
 
1924                 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
 
1925                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
 
1929     $form->{selectIC_income} =~ s/selected//g;
 
1930     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/  value=$form->{income_accno_id_3} selected/;
 
1931     $form->{selectIC_expense} =~ s/selected//g;
 
1932     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/  value=$form->{expense_accno_id_3} selected/;
 
1935   $linkaccounts .= qq|              <tr>
 
1936                 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
 
1937                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
 
1940                 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
 
1941                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
 
1951 <form method=post action=am.pl>
 
1953 <input type=hidden name=id value=$form->{id}>
 
1954 <input type=hidden name=type value=buchungsgruppe>
 
1958     <th class=listtop colspan=2>$form->{title}</th>
 
1960   <tr height="5"></tr>
 
1962     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
 
1963     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1966   <td colspan=2><hr size=3 noshade></td>
 
1971   $main::lxdebug->leave_sub();
 
1974 sub save_buchungsgruppe {
 
1975   $main::lxdebug->enter_sub();
 
1977   my $form     = $main::form;
 
1978   my %myconfig = %main::myconfig;
 
1979   my $locale   = $main::locale;
 
1981   $main::auth->assert('config');
 
1983   $form->isblank("description", $locale->text('Description missing!'));
 
1985   AM->save_buchungsgruppe(\%myconfig, \%$form);
 
1986   $form->redirect($locale->text('Accounting Group saved!'));
 
1988   $main::lxdebug->leave_sub();
 
1991 sub delete_buchungsgruppe {
 
1992   $main::lxdebug->enter_sub();
 
1994   my $form     = $main::form;
 
1995   my %myconfig = %main::myconfig;
 
1996   my $locale   = $main::locale;
 
1998   $main::auth->assert('config');
 
2000   AM->delete_buchungsgruppe(\%myconfig, \%$form);
 
2001   $form->redirect($locale->text('Accounting Group deleted!'));
 
2003   $main::lxdebug->leave_sub();
 
2006 sub swap_buchungsgruppen {
 
2007   $main::lxdebug->enter_sub();
 
2009   my $form     = $main::form;
 
2010   my %myconfig = %main::myconfig;
 
2012   $main::auth->assert('config');
 
2014   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
 
2015   list_buchungsgruppe();
 
2017   $main::lxdebug->leave_sub();
 
2021   $main::lxdebug->enter_sub();
 
2023   my $form     = $main::form;
 
2024   my %myconfig = %main::myconfig;
 
2026   $main::auth->assert('config');
 
2028   $form->{title} = "Add";
 
2030   $form->{callback} = "am.pl?action=add_payment" unless $form->{callback};
 
2032   $form->{terms_netto} = 0;
 
2033   $form->{terms_skonto} = 0;
 
2034   $form->{percent_skonto} = 0;
 
2035   my @languages = AM->language(\%myconfig, $form, 1);
 
2036   map({ $_->{"language"} = $_->{"description"};
 
2037         $_->{"language_id"} = $_->{"id"}; } @languages);
 
2038   $form->{"TRANSLATION"} = \@languages;
 
2042   $main::lxdebug->leave_sub();
 
2046   $main::lxdebug->enter_sub();
 
2048   my $form     = $main::form;
 
2049   my %myconfig = %main::myconfig;
 
2051   $main::auth->assert('config');
 
2053   $form->{title} = "Edit";
 
2055   AM->get_payment(\%myconfig, $form);
 
2056   $form->{percent_skonto} =
 
2057     $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
 
2061   $form->{orphaned} = 1;
 
2064   $main::lxdebug->leave_sub();
 
2068   $main::lxdebug->enter_sub();
 
2070   my $form     = $main::form;
 
2071   my %myconfig = %main::myconfig;
 
2072   my $locale   = $main::locale;
 
2074   $main::auth->assert('config');
 
2076   AM->payment(\%myconfig, \%$form);
 
2078   $form->{callback} = build_std_url("action=list_payment");
 
2080   my $callback = $form->escape($form->{callback});
 
2082   $form->{title} = $locale->text('Payment Terms');
 
2084   my @column_index = qw(up down description description_long terms_netto
 
2085                      terms_skonto percent_skonto);
 
2087   $column_header{up} =
 
2088       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2089     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
2091   $column_header{down} =
 
2092       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2093     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
2095   $column_header{description} =
 
2096       qq|<th class=listheading>|
 
2097     . $locale->text('Description')
 
2099   $column_header{description_long} =
 
2100       qq|<th class=listheading>|
 
2101     . $locale->text('Long Description')
 
2103   $column_header{terms_netto} =
 
2104       qq|<th class=listheading>|
 
2105     . $locale->text('Netto Terms')
 
2107   $column_header{terms_skonto} =
 
2108       qq|<th class=listheading>|
 
2109     . $locale->text('Skonto Terms')
 
2111   $column_header{percent_skonto} =
 
2112       qq|<th class=listheading>|
 
2113     . $locale->text('Skonto')
 
2123     <th class=listtop>$form->{title}</th>
 
2125   <tr height="5"></tr>
 
2129         <tr class=listheading>
 
2132   map { print "$column_header{$_}\n" } @column_index;
 
2138   my $swap_link = build_std_url("action=swap_payment_terms");
 
2141   my ($i, %column_data);
 
2142   foreach my $ref (@{ $form->{ALL} }) {
 
2148         <tr valign=top class=listrow$i>
 
2152       my $pref = $form->{ALL}->[$row - 1];
 
2154         qq|<td align="center" valign="center" width="16">| .
 
2155         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
 
2156         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
2159       $column_data{up} = qq|<td width="16"> </td>|;
 
2162     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
2163       $column_data{down} = qq|<td width="16"> </td>|;
 
2165       my $nref = $form->{ALL}->[$row + 1];
 
2166       $column_data{down} =
 
2167         qq|<td align="center" valign="center" width="16">| .
 
2168         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
 
2169         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
2173     $column_data{description} =
 
2175       build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
 
2176       qq|">| . H($ref->{description}) . qq|</a></td>|;
 
2177     $column_data{description_long} =
 
2178       qq|<td>| . H($ref->{description_long}) . qq|</td>|;
 
2179     $column_data{terms_netto} =
 
2180       qq|<td align=right>$ref->{terms_netto}</td>|;
 
2181     $column_data{terms_skonto} =
 
2182       qq|<td align=right>$ref->{terms_skonto}</td>|;
 
2183     $column_data{percent_skonto} =
 
2184       qq|<td align=right>| .
 
2185       $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
 
2187     map { print "$column_data{$_}\n" } @column_index;
 
2200   <td><hr size=3 noshade></td>
 
2205 <form method=post action=am.pl>
 
2207 <input name=callback type=hidden value="$form->{callback}">
 
2209 <input type=hidden name=type value=payment>
 
2211 <input class=submit type=submit name=action value="|
 
2212     . $locale->text('Add') . qq|">
 
2220   $main::lxdebug->leave_sub();
 
2223 sub payment_header {
 
2224   $main::lxdebug->enter_sub();
 
2226   my $form     = $main::form;
 
2227   my $locale   = $main::locale;
 
2229   $main::auth->assert('config');
 
2231   $form->{title}    = $locale->text("$form->{title} Payment Terms");
 
2233   # $locale->text('Add Payment Terms')
 
2234   # $locale->text('Edit Payment Terms')
 
2236   $form->{description} =~ s/\"/"/g;
 
2245 <form method=post action=am.pl>
 
2247 <input type=hidden name=id value=$form->{id}>
 
2248 <input type=hidden name=type value=payment>
 
2252     <th class=listtop colspan=2>$form->{title}</th>
 
2254   <tr height="5"></tr>
 
2256     <th align=right>| . $locale->text('Description') . qq|</th>
 
2257     <td><input name=description size=30 value="$form->{description}"></td>
 
2260     <th align=right>| . $locale->text('Long Description') . qq|</th>
 
2261     <td><input name=description_long size=50 value="$form->{description_long}"></td>
 
2265   foreach my $language (@{ $form->{"TRANSLATION"} }) {
 
2268     <th align="right">| .
 
2269     sprintf($locale->text('Translation (%s)'),
 
2270             $language->{"language"})
 
2272     <td><input name="description_long_$language->{language_id}" size="50"
 
2273          value="| . Q($language->{"description_long"}) . qq|"></td>
 
2280     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
 
2281     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
 
2284     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
 
2285     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
 
2288     <th align=right>| . $locale->text('Skonto') . qq| %</th>
 
2289     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
 
2291   <td colspan=2><hr size=3 noshade></td>
 
2295 <p>| . $locale->text("You can use the following strings in the long " .
 
2296                      "description and all translations. They will be " .
 
2297                      "replaced by their actual values by Lx-Office " .
 
2298                      "before they're output.")
 
2302   <li>| . $locale->text("<%netto_date%> -- Date the payment is due in " .
 
2305   <li>| . $locale->text("<%skonto_date%> -- Date the payment is due " .
 
2308   <li>| . $locale->text("<%skonto_amount%> -- The deductible amount")
 
2310   <li>| . $locale->text("<%skonto_in_percent%> -- The discount in percent")
 
2312   <li>| . $locale->text("<%total%> -- Amount payable")
 
2314   <li>| . $locale->text("<%total_wo_skonto%> -- Amount payable less discount")
 
2316   <li>| . $locale->text("<%invtotal%> -- Invoice total")
 
2318   <li>| . $locale->text("<%invtotal_wo_skonto%> -- Invoice total less discount")
 
2320   <li>| . $locale->text("<%currency%> -- The selected currency")
 
2322   <li>| . $locale->text("<%terms_netto%> -- The number of days for " .
 
2325   <li>| . $locale->text("<%account_number%> -- Your account number")
 
2327   <li>| . $locale->text("<%bank%> -- Your bank")
 
2329   <li>| . $locale->text("<%bank_code%> -- Your bank code")
 
2333   $main::lxdebug->leave_sub();
 
2337   $main::lxdebug->enter_sub();
 
2339   my $form     = $main::form;
 
2340   my %myconfig = %main::myconfig;
 
2341   my $locale   = $main::locale;
 
2343   $main::auth->assert('config');
 
2345   $form->isblank("description", $locale->text('Description missing!'));
 
2346   $form->{"percent_skonto"} =
 
2347     $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
 
2348   AM->save_payment(\%myconfig, \%$form);
 
2349   $form->redirect($locale->text('Payment Terms saved!'));
 
2351   $main::lxdebug->leave_sub();
 
2354 sub delete_payment {
 
2355   $main::lxdebug->enter_sub();
 
2357   my $form     = $main::form;
 
2358   my %myconfig = %main::myconfig;
 
2359   my $locale   = $main::locale;
 
2361   $main::auth->assert('config');
 
2363   AM->delete_payment(\%myconfig, \%$form);
 
2364   $form->redirect($locale->text('Payment terms deleted!'));
 
2366   $main::lxdebug->leave_sub();
 
2369 sub swap_payment_terms {
 
2370   $main::lxdebug->enter_sub();
 
2372   my $form     = $main::form;
 
2373   my %myconfig = %main::myconfig;
 
2375   $main::auth->assert('config');
 
2377   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
 
2380   $main::lxdebug->leave_sub();
 
2384   $main::lxdebug->enter_sub();
 
2386   my $form     = $main::form;
 
2387   my %myconfig = %main::myconfig;
 
2388   my $locale   = $main::locale;
 
2390   # get defaults for account numbers and last numbers
 
2391   AM->defaultaccounts(\%myconfig, \%$form);
 
2392   $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
 
2394   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
 
2396   foreach my $key (keys %{ $form->{IC} }) {
 
2397     foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
 
2398       my $array = "ACCNOS_" . uc($key);
 
2399       $form->{$array} ||= [];
 
2401       my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
 
2402       push @{ $form->{$array} }, {
 
2405         'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
 
2410   $form->{title} = $locale->text('Ranges of numbers and default accounts');
 
2413   print $form->parse_html_template('am/edit_defaults');
 
2415   $main::lxdebug->leave_sub();
 
2419   $main::lxdebug->enter_sub();
 
2421   my $form     = $main::form;
 
2422   my $locale   = $main::locale;
 
2424   AM->save_defaults();
 
2426   $form->redirect($locale->text('Defaults saved.'));
 
2428   $main::lxdebug->leave_sub();
 
2431 sub _build_cfg_options {
 
2432   my $form     = $main::form;
 
2433   my %myconfig = %main::myconfig;
 
2436   my $array = uc($idx) . 'S';
 
2438   $form->{$array} = [];
 
2439   foreach my $item (@_) {
 
2440     push @{ $form->{$array} }, {
 
2443       'selected' => $item eq $myconfig{$idx},
 
2449   $main::lxdebug->enter_sub();
 
2451   my $form     = $main::form;
 
2452   my %myconfig = %main::myconfig;
 
2453   my $locale   = $main::locale;
 
2455   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
2456   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
2459   if ($main::opendocument_templates && $main::openofficeorg_writer_bin &&
 
2460       $main::xvfb_bin && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)) {
 
2461     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
2462                      "value" => "opendocument_pdf" });
 
2464   if ($main::latex_templates) {
 
2465     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
2467   push(@formats, { "name" => "HTML", "value" => "html" });
 
2468   if ($main::latex_templates) {
 
2469     push(@formats, { "name" => $locale->text("Postscript"),
 
2470                      "value" => "postscript" });
 
2472   if ($main::opendocument_templates) {
 
2473     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
2474                      "value" => "opendocument" });
 
2477   if (!$myconfig{"template_format"}) {
 
2478     $myconfig{"template_format"} = "pdf";
 
2480   $form->{TEMPLATE_FORMATS} = [];
 
2481   foreach my $item (@formats) {
 
2482     push @{ $form->{TEMPLATE_FORMATS} }, {
 
2483       'name'     => $item->{name},
 
2484       'value'    => $item->{value},
 
2485       'selected' => $item->{value} eq $myconfig{template_format},
 
2489   if (!$myconfig{"default_media"}) {
 
2490     $myconfig{"default_media"} = "screen";
 
2493   my %selected = ($myconfig{"default_media"} => "selected");
 
2495     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
2496     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
2497     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
2500   $form->{PRINTERS} = [];
 
2501   foreach my $printer (SL::Printer->all_printers(%::myconfig)) {
 
2502     push @{ $form->{PRINTERS} }, {
 
2503       'name'     => $printer->{printer_description},
 
2504       'value'    => $printer->{id},
 
2505       'selected' => $printer->{id} == $myconfig{default_printer_id},
 
2509   my %countrycodes = User->country_codes;
 
2511   $form->{COUNTRYCODES} = [];
 
2512   foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
2513     push @{ $form->{COUNTRYCODES} }, {
 
2514       'name'     => $countrycodes{$countrycode},
 
2515       'value'    => $countrycode,
 
2516       'selected' => $countrycode eq $myconfig{countrycode},
 
2520   $form->{STYLESHEETS} = [];
 
2521   foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
 
2522     push @{ $form->{STYLESHEETS} }, {
 
2525       'selected' => $item eq $myconfig{stylesheet},
 
2529   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
 
2530   $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
2531   $form->{todo_cfg}            = { TODO->get_user_config('login' => $form->{login}) };
 
2533   $form->{title}               = $locale->text('Edit Preferences for #1', $form->{login});
 
2536   print $form->parse_html_template('am/config');
 
2538   $main::lxdebug->leave_sub();
 
2541 sub save_preferences {
 
2542   $main::lxdebug->enter_sub();
 
2544   my $form     = $main::form;
 
2545   my %myconfig = %main::myconfig;
 
2546   my $locale   = $main::locale;
 
2548   $form->{stylesheet} = $form->{usestylesheet};
 
2550   TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
 
2552   $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, 0));
 
2553   $form->error($locale->text('Cannot save preferences!'));
 
2555   $main::lxdebug->leave_sub();
 
2559   $main::lxdebug->enter_sub();
 
2561   my $form     = $main::form;
 
2562   my %myconfig = %main::myconfig;
 
2563   my $locale   = $main::locale;
 
2565   $main::auth->assert('config');
 
2567   $form->{title} = $locale->text('Audit Control');
 
2569   AM->closedto(\%myconfig, \%$form);
 
2576 <form method=post action=am.pl>
 
2579   <tr><th class=listtop>$form->{title}</th></tr>
 
2580   <tr height="5"></tr>
 
2585           <th>| . $locale->text('Close Books up to') . qq|</th>
 
2586           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
 
2596 <input type=hidden name=nextsub value=doclose>
 
2598 <input type=submit class=submit name=action value="|
 
2599     . $locale->text('Continue') . qq|">
 
2607   $main::lxdebug->leave_sub();
 
2611   $main::lxdebug->enter_sub();
 
2613   my $form     = $main::form;
 
2614   my %myconfig = %main::myconfig;
 
2615   my $locale   = $main::locale;
 
2617   $main::auth->assert('config');
 
2619   AM->closebooks(\%myconfig, \%$form);
 
2621   if ($form->{closedto}) {
 
2623                     $locale->text('Books closed up to') . " "
 
2624                       . $locale->date(\%myconfig, $form->{closedto}, 1));
 
2626     $form->redirect($locale->text('Books are open'));
 
2629   $main::lxdebug->leave_sub();
 
2633   $main::lxdebug->enter_sub();
 
2635   my $form     = $main::form;
 
2636   my %myconfig = %main::myconfig;
 
2637   my $locale   = $main::locale;
 
2639   $main::auth->assert('config');
 
2641   my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
2642   AM->units_in_use(\%myconfig, $form, $units);
 
2643   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
2645   my @languages = AM->language(\%myconfig, $form, 1);
 
2647   my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
2650   foreach (@unit_list) {
 
2651     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
2652     $_->{"UNITLANGUAGES"} = [];
 
2653     foreach my $lang (@languages) {
 
2654       push(@{ $_->{"UNITLANGUAGES"} },
 
2656              "unit" => $_->{"name"},
 
2657              "language_id" => $lang->{"id"},
 
2658              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
2659              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
2665   $units = AM->retrieve_units(\%myconfig, $form);
 
2666   my $ddbox = AM->unit_select_data($units, undef, 1);
 
2668   my $updownlink = build_std_url("action=swap_units");
 
2670   $form->{"title"} = $locale->text("Add and edit units");
 
2672   print($form->parse_html_template("am/edit_units",
 
2673                                    { "UNITS"               => \@unit_list,
 
2674                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
2675                                      "LANGUAGES"           => \@languages,
 
2676                                      "updownlink"          => $updownlink }));
 
2678   $main::lxdebug->leave_sub();
 
2682   $main::lxdebug->enter_sub();
 
2684   my $form     = $main::form;
 
2685   my %myconfig = %main::myconfig;
 
2686   my $locale   = $main::locale;
 
2688   $main::auth->assert('config');
 
2690   $form->isblank("new_name", $locale->text("The name is missing."));
 
2691   my $units = AM->retrieve_units(\%myconfig, $form);
 
2692   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
2693   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
2695   my ($base_unit, $factor);
 
2696   if ($form->{"new_base_unit"}) {
 
2697     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
2699     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
2700     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
2701     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
2702     $base_unit = $form->{"new_base_unit"};
 
2706   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
2707     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
2708     push(@languages, { "id" => $lang->{"id"},
 
2709                        "localized" => $form->{"new_localized_$lang->{id}"},
 
2710                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
2714   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
2716   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
2720   $main::lxdebug->leave_sub();
 
2723 sub set_unit_languages {
 
2724   $main::lxdebug->enter_sub();
 
2726   my $form     = $main::form;
 
2728   $main::auth->assert('config');
 
2730   my ($unit, $languages, $idx) = @_;
 
2732   $unit->{"LANGUAGES"} = [];
 
2734   foreach my $lang (@{$languages}) {
 
2735     push(@{ $unit->{"LANGUAGES"} },
 
2736          { "id" => $lang->{"id"},
 
2737            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
2738            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
2742   $main::lxdebug->leave_sub();
 
2746   $main::lxdebug->enter_sub();
 
2748   my $form     = $main::form;
 
2749   my %myconfig = %main::myconfig;
 
2750   my $locale   = $main::locale;
 
2752   $main::auth->assert('config');
 
2754   my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
2755   AM->units_in_use(\%myconfig, $form, $old_units);
 
2757   my @languages = AM->language(\%myconfig, $form, 1);
 
2760   my @delete_units = ();
 
2761   foreach my $i (1..($form->{"rowcount"} * 1)) {
 
2762     my $old_unit = $old_units->{$form->{"old_name_$i"}};
 
2764       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
2767     if ($form->{"unchangeable_$i"}) {
 
2768       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
2769       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
2770       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2774     if ($old_unit->{"in_use"}) {
 
2775       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
2778     if ($form->{"delete_$i"}) {
 
2779       push(@delete_units, $old_unit->{"name"});
 
2783     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
2785     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
2786     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
2787     $new_units->{$form->{"name_$i"}} = \%h;
 
2788     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
2789     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2792   foreach my $unit (values(%{$new_units})) {
 
2793     next unless ($unit->{"old_name"});
 
2794     if ($unit->{"base_unit"}) {
 
2795       $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"}))
 
2796         unless (defined($new_units->{$unit->{"base_unit"}}));
 
2797       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
2798       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
2800       $unit->{"base_unit"} = undef;
 
2801       $unit->{"factor"} = undef;
 
2805   foreach my $unit (values(%{$new_units})) {
 
2806     next if ($unit->{"unchanged_unit"});
 
2808     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
2809     my $new_unit = $unit;
 
2810     while ($new_unit->{"base_unit"}) {
 
2811       $new_unit->{"seen"} = 1;
 
2812       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
2813       if ($new_unit->{"seen"}) {
 
2814         $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, " .
 
2815                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
2820   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
2822   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
2826   $main::lxdebug->leave_sub();
 
2829 sub show_history_search {
 
2830   $main::lxdebug->enter_sub();
 
2832   my $form     = $main::form;
 
2833   my $locale   = $main::locale;
 
2835   $main::auth->assert('config');
 
2837   $form->{title} = $locale->text("History Search");
 
2840   print $form->parse_html_template("common/search_history");
 
2842   $main::lxdebug->leave_sub();
 
2845 sub show_am_history {
 
2846   $main::lxdebug->enter_sub();
 
2848   my $form     = $main::form;
 
2849   my %myconfig = %main::myconfig;
 
2850   my $locale   = $main::locale;
 
2852   $main::auth->assert('config');
 
2854   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
 
2855   $form->{order} ||= 'h.itime--1';
 
2857   my %search = ( "Artikelnummer"          => "parts",
 
2858                  "Kundennummer"           => "customer",
 
2859                  "Lieferantennummer"      => "vendor",
 
2860                  "Projektnummer"          => "project",
 
2861                  "Buchungsnummer"         => "oe",
 
2862                  "Eingangsrechnungnummer" => "ap",
 
2863                  "Ausgangsrechnungnummer" => "ar",
 
2864                  "Mahnungsnummer"         => "dunning"
 
2866   my %searchNo = ( "Artikelnummer"          => "partnumber",
 
2867                    "Kundennummer"           => "customernumber",
 
2868                    "Lieferantennummer"      => "vendornumber",
 
2869                    "Projektnummer"          => "projectnumber",
 
2870                    "Buchungsnummer"         => "ordnumber",
 
2871                    "Eingangsrechnungnummer" => "invnumber",
 
2872                    "Ausgangsrechnungnummer" => "invnumber",
 
2873                    "Mahnungsnummer"         => "dunning_id"
 
2876   my $dbh = $form->dbconnect(\%myconfig);
 
2878   my $restriction  = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
 
2879   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
 
2880   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
 
2881   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
2882     $restriction  .= qq| AND employee_id = |    . $form->{mitarbeiter};
 
2883   } elsif ($form->{mitarbeiter}) {
 
2884     $restriction  .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
 
2887   my $query = qq|SELECT trans_id AS id FROM history_erp | .
 
2888     (  $form->{'searchid'} ? qq| WHERE snumbers = '|  . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
 
2889      :                       qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
2891   my @ids    = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
 
2892   my $daten .= shift @ids;
 
2893   $daten    .= join '', map { " OR trans_id = $_" } @ids;
 
2895   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
2896   $sort =~ s/.*\.(.*)$/$1/;
 
2898   $form->{title} = $locale->text("History Search");
 
2901   print $form->parse_html_template("common/show_history",
 
2902                                    { "DATEN"          => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
2903                                      "SUCCESS"        => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
2906                                      uc($sort) . "BY" => $sortby,
 
2907                                      'callback'       => $callback,
 
2911   $main::lxdebug->leave_sub();
 
2915   $main::lxdebug->enter_sub();
 
2917   my $form     = $main::form;
 
2918   my %myconfig = %main::myconfig;
 
2920   $main::auth->assert('config');
 
2922   my $dir = $form->{"dir"} eq "down" ? "down" : "up";
 
2923   AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
 
2927   $main::lxdebug->leave_sub();
 
2931   $main::lxdebug->enter_sub();
 
2933   my $form     = $main::form;
 
2934   my $locale   = $main::locale;
 
2936   $main::auth->assert('config');
 
2938   $form->{title} =  $locale->text('Add');
 
2940   $form->{callback} ||= "am.pl?action=add_tax";
 
2942   _get_taxaccount_selection();
 
2946   my $parameters_ref = {
 
2947 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
2950   # Ausgabe des Templates
 
2951   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
2953   $main::lxdebug->leave_sub();
 
2957   $main::lxdebug->enter_sub();
 
2959   my $form     = $main::form;
 
2960   my %myconfig = %main::myconfig;
 
2961   my $locale   = $main::locale;
 
2963   $main::auth->assert('config');
 
2965   $form->{title} =  $locale->text('Edit');
 
2967   AM->get_tax(\%myconfig, \%$form);
 
2968   _get_taxaccount_selection();
 
2970   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
2974   my $parameters_ref = {
 
2977   # Ausgabe des Templates
 
2978   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
2980   $main::lxdebug->leave_sub();
 
2984   $main::lxdebug->enter_sub();
 
2986   my $form     = $main::form;
 
2987   my %myconfig = %main::myconfig;
 
2988   my $locale   = $main::locale;
 
2990   $main::auth->assert('config');
 
2992   AM->taxes(\%myconfig, \%$form);
 
2994   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
2996   $form->{callback} = build_std_url('action=list_tax');
 
2998   $form->{title} = $locale->text('Tax-O-Matic');
 
3002   my $parameters_ref = {
 
3005   # Ausgabe des Templates
 
3006   print($form->parse_html_template('am/list_tax', $parameters_ref));
 
3008   $main::lxdebug->leave_sub();
 
3011 sub _get_taxaccount_selection{
 
3012   $main::lxdebug->enter_sub();
 
3014   my $form     = $main::form;
 
3015   my %myconfig = %main::myconfig;
 
3017   $main::auth->assert('config');
 
3019   AM->get_tax_accounts(\%myconfig, \%$form);
 
3021   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
3023   $main::lxdebug->leave_sub();
 
3027   $main::lxdebug->enter_sub();
 
3029   my $form     = $main::form;
 
3030   my %myconfig = %main::myconfig;
 
3031   my $locale   = $main::locale;
 
3033   $main::auth->assert('config');
 
3035   $form->isblank("rate", $locale->text('Taxrate missing!'));
 
3036   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
 
3037   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
 
3039   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
3041   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
3042     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
3045   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
3046     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
3049   AM->save_tax(\%myconfig, \%$form);
 
3050   $form->redirect($locale->text('Tax saved!'));
 
3052   $main::lxdebug->leave_sub();
 
3056   $main::lxdebug->enter_sub();
 
3058   my $form     = $main::form;
 
3059   my %myconfig = %main::myconfig;
 
3060   my $locale   = $main::locale;
 
3062   $main::auth->assert('config');
 
3064   AM->delete_tax(\%myconfig, \%$form);
 
3065   $form->redirect($locale->text('Tax deleted!'));
 
3067   $main::lxdebug->leave_sub();
 
3070 sub add_price_factor {
 
3071   $main::lxdebug->enter_sub();
 
3073   my $form     = $main::form;
 
3074   my $locale   = $main::locale;
 
3076   $main::auth->assert('config');
 
3078   $form->{title}      = $locale->text('Add Price Factor');
 
3079   $form->{callback} ||= build_std_url('action=add_price_factor');
 
3080   $form->{fokus}      = 'description';
 
3083   print $form->parse_html_template('am/edit_price_factor');
 
3085   $main::lxdebug->leave_sub();
 
3088 sub edit_price_factor {
 
3089   $main::lxdebug->enter_sub();
 
3091   my $form     = $main::form;
 
3092   my %myconfig = %main::myconfig;
 
3093   my $locale   = $main::locale;
 
3095   $main::auth->assert('config');
 
3097   $form->{title}      = $locale->text('Edit Price Factor');
 
3098   $form->{callback} ||= build_std_url('action=add_price_factor');
 
3099   $form->{fokus}      = 'description';
 
3101   AM->get_price_factor(\%myconfig, $form);
 
3103   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
 
3106   print $form->parse_html_template('am/edit_price_factor');
 
3108   $main::lxdebug->leave_sub();
 
3111 sub list_price_factors {
 
3112   $main::lxdebug->enter_sub();
 
3114   my $form     = $main::form;
 
3115   my %myconfig = %main::myconfig;
 
3116   my $locale   = $main::locale;
 
3118   $main::auth->assert('config');
 
3120   AM->get_all_price_factors(\%myconfig, \%$form);
 
3123   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
 
3125       $previous->{next_id}    = $current->{id};
 
3126       $current->{previous_id} = $previous->{id};
 
3129     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
 
3131     $previous = $current;
 
3134   $form->{callback} = build_std_url('action=list_price_factors');
 
3135   $form->{title}    = $locale->text('Price Factors');
 
3136   $form->{url_base} = build_std_url('callback');
 
3139   print $form->parse_html_template('am/list_price_factors');
 
3141   $main::lxdebug->leave_sub();
 
3144 sub save_price_factor {
 
3145   $main::lxdebug->enter_sub();
 
3147   my $form     = $main::form;
 
3148   my %myconfig = %main::myconfig;
 
3149   my $locale   = $main::locale;
 
3151   $main::auth->assert('config');
 
3153   $form->isblank("description", $locale->text('Description missing!'));
 
3154   $form->isblank("factor", $locale->text('Factor missing!'));
 
3156   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
 
3158   AM->save_price_factor(\%myconfig, $form);
 
3160   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
 
3162   $form->redirect($locale->text('Price factor saved!'));
 
3164   $main::lxdebug->leave_sub();
 
3167 sub delete_price_factor {
 
3168   $main::lxdebug->enter_sub();
 
3170   my $form     = $main::form;
 
3171   my %myconfig = %main::myconfig;
 
3172   my $locale   = $main::locale;
 
3174   $main::auth->assert('config');
 
3176   AM->delete_price_factor(\%myconfig, \%$form);
 
3178   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
 
3180   $form->redirect($locale->text('Price factor deleted!'));
 
3182   $main::lxdebug->leave_sub();
 
3185 sub swap_price_factors {
 
3186   $main::lxdebug->enter_sub();
 
3188   my $form     = $main::form;
 
3189   my %myconfig = %main::myconfig;
 
3191   $main::auth->assert('config');
 
3193   AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
 
3194   list_price_factors();
 
3196   $main::lxdebug->leave_sub();
 
3200   $main::lxdebug->enter_sub();
 
3202   my $form     = $main::form;
 
3203   my $locale   = $main::locale;
 
3205   $main::auth->assert('config');
 
3207   $form->{title}      = $locale->text('Add Warehouse');
 
3208   $form->{callback} ||= build_std_url('action=add_warehouse');
 
3209   $form->{fokus}      = 'description';
 
3212   print $form->parse_html_template('am/edit_warehouse');
 
3214   $main::lxdebug->leave_sub();
 
3217 sub edit_warehouse {
 
3218   $main::lxdebug->enter_sub();
 
3220   my $form     = $main::form;
 
3221   my %myconfig = %main::myconfig;
 
3222   my $locale   = $main::locale;
 
3224   $main::auth->assert('config');
 
3226   AM->get_warehouse(\%myconfig, $form);
 
3228   $form->get_lists('employees' => 'EMPLOYEES');
 
3230   $form->{title}      = $locale->text('Edit Warehouse');
 
3231   $form->{callback} ||= build_std_url('action=list_warehouses');
 
3232   $form->{fokus}      = 'description';
 
3235   print $form->parse_html_template('am/edit_warehouse');
 
3237   $main::lxdebug->leave_sub();
 
3240 sub list_warehouses {
 
3241   $main::lxdebug->enter_sub();
 
3243   my $form     = $main::form;
 
3244   my %myconfig = %main::myconfig;
 
3245   my $locale   = $main::locale;
 
3247   $main::auth->assert('config');
 
3249   AM->get_all_warehouses(\%myconfig, $form);
 
3252   foreach my $current (@{ $form->{WAREHOUSES} }) {
 
3254       $previous->{next_id}    = $current->{id};
 
3255       $current->{previous_id} = $previous->{id};
 
3258     $previous = $current;
 
3261   $form->{callback} = build_std_url('action=list_warehouses');
 
3262   $form->{title}    = $locale->text('Warehouses');
 
3263   $form->{url_base} = build_std_url('callback');
 
3266   print $form->parse_html_template('am/list_warehouses');
 
3268   $main::lxdebug->leave_sub();
 
3271 sub save_warehouse {
 
3272   $main::lxdebug->enter_sub();
 
3274   my $form     = $main::form;
 
3275   my %myconfig = %main::myconfig;
 
3276   my $locale   = $main::locale;
 
3278   $main::auth->assert('config');
 
3280   $form->isblank("description", $locale->text('Description missing!'));
 
3282   $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
 
3284   AM->save_warehouse(\%myconfig, $form);
 
3286   $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
 
3288   $form->redirect($locale->text('Warehouse saved.'));
 
3290   $main::lxdebug->leave_sub();
 
3293 sub swap_warehouses {
 
3294   $main::lxdebug->enter_sub();
 
3296   my $form     = $main::form;
 
3297   my %myconfig = %main::myconfig;
 
3299   $main::auth->assert('config');
 
3301   AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
 
3304   $main::lxdebug->leave_sub();
 
3307 sub delete_warehouse {
 
3308   $main::lxdebug->enter_sub();
 
3310   my $form     = $main::form;
 
3311   my %myconfig = %main::myconfig;
 
3312   my $locale   = $main::locale;
 
3314   $main::auth->assert('config');
 
3316   if (!$form->{confirmed}) {
 
3317     $form->{title} = $locale->text('Confirmation');
 
3320     print $form->parse_html_template('am/confirm_delete_warehouse');
 
3324   if (AM->delete_warehouse(\%myconfig, $form)) {
 
3325     $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
 
3326     $form->redirect($locale->text('Warehouse deleted.'));
 
3329     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
 
3332   $main::lxdebug->leave_sub();
 
3336   $main::lxdebug->enter_sub();
 
3338   my $form     = $main::form;
 
3339   my %myconfig = %main::myconfig;
 
3340   my $locale   = $main::locale;
 
3342   $main::auth->assert('config');
 
3344   AM->save_bins(\%myconfig, $form);
 
3346   $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
 
3348   $form->redirect($locale->text('Bins saved.'));
 
3350   $main::lxdebug->leave_sub();