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 #======================================================================
 
  37 use SL::Auth::PasswordPolicy;
 
  51 require "bin/mozilla/common.pl";
 
  59 sub add      { call_sub("add_$main::form->{type}"); }
 
  60 sub delete   { call_sub("delete_$main::form->{type}"); }
 
  61 sub save     { call_sub("save_$main::form->{type}"); }
 
  62 sub edit     { call_sub("edit_$main::form->{type}"); }
 
  63 sub continue { call_sub($main::form->{"nextsub"}); }
 
  64 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
  67   $main::lxdebug->enter_sub();
 
  69   my $form     = $main::form;
 
  70   my %myconfig = %main::myconfig;
 
  72   $main::auth->assert('config');
 
  74   $form->{title}     = "Add";
 
  75   $form->{charttype} = "A";
 
  76   AM->get_account(\%myconfig, \%$form);
 
  78   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
 
  83   $main::lxdebug->leave_sub();
 
  87   $main::lxdebug->enter_sub();
 
  89   my $form     = $main::form;
 
  90   my %myconfig = %main::myconfig;
 
  92   $main::auth->assert('config');
 
  94   $form->{title} = "Edit";
 
  95   AM->get_account(\%myconfig, \%$form);
 
  97   foreach my $item (split(/:/, $form->{link})) {
 
  98     $form->{$item} = "checked";
 
 104   $main::lxdebug->leave_sub();
 
 108   $main::lxdebug->enter_sub();
 
 110   my $form     = $main::form;
 
 111   my %myconfig = %main::myconfig;
 
 112   my $locale   = $main::locale;
 
 114   $main::auth->assert('config');
 
 116   if ( $form->{action} eq 'edit_account') {
 
 117     $form->{account_exists} = '1';
 
 120   $form->{title} = $locale->text("$form->{title} Account");
 
 122   $form->{"$form->{charttype}_checked"} = "checked";
 
 123   $form->{"$form->{category}_checked"}  = "checked";
 
 125   $form->{select_tax} = "";
 
 127   my @tax_report_pos = USTVA->report_variables({
 
 128       myconfig   => \%myconfig,
 
 131       attribute  => 'position',
 
 135   if (@{ $form->{TAXKEY} }) {
 
 136     foreach my $item (@{ $form->{TAXKEY} }) {
 
 137       $item->{rate} = $item->{rate} * 100 . '%';
 
 140     # Fill in empty row for new Taxkey
 
 141     my $newtaxkey_ref = {
 
 146       taxdescription => '',
 
 153     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 156     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 158       # Fill in a runningnumber
 
 159       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 161       # Fill in the Taxkeys as select options
 
 162       foreach my $item (@{ $form->{TAXKEY} }) {
 
 163         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 164           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 165             qq|<option value="$item->{id}" selected="selected">|
 
 166             . sprintf("%.2d", $item->{taxkey})
 
 167             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 168             . $locale->text('Tax-o-matic Account')
 
 169             . qq|: $item->{chart_accno}\n|;
 
 172           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 173             qq|<option value="$item->{id}">|
 
 174             . sprintf("%.2d", $item->{taxkey})
 
 175             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 176             . $locale->text('Tax-o-matic Account')
 
 177             . qq|: $item->{chart_accno}\n|;
 
 182       # Fill in the USTVA Numbers as select options
 
 183       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 185           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 187         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 188           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 191           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 200   # Newaccount Folgekonto
 
 201   if (@{ $form->{NEWACCOUNT} || [] }) {
 
 202     if (!$form->{new_chart_valid}) {
 
 203       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 205     foreach my $item (@{ $form->{NEWACCOUNT} }) {
 
 206       if ($item->{id} == $form->{new_chart_id}) {
 
 207         $form->{selectnewaccount} .=
 
 208           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 209       } elsif (!$form->{new_chart_valid}) {
 
 210         $form->{selectnewaccount} .=
 
 211           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 217   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 220           2  => "sonstige Erlöse",
 
 221           3  => "Privatanteile",
 
 223           5  => "Ausserordentliche Erträge",
 
 224           6  => "Vereinnahmte Umsatzst.",
 
 225           7  => "Umsatzsteuererstattungen",
 
 226           8  => "Wareneingänge",
 
 227           9  => "Löhne und Gehälter",
 
 228           10 => "Gesetzl. sozialer Aufw.",
 
 230           12 => "Gas, Strom, Wasser",
 
 231           13 => "Instandhaltung",
 
 232           14 => "Steuern, Versich., Beiträge",
 
 234           16 => "Kfz-Versicherungen",
 
 235           17 => "Sonst. Fahrzeugkosten",
 
 236           18 => "Werbe- und Reisekosten",
 
 237           19 => "Instandhaltung u. Werkzeuge",
 
 238           20 => "Fachzeitschriften, Bücher",
 
 239           21 => "Miete für Einrichtungen",
 
 240           22 => "Rechts- und Beratungskosten",
 
 241           23 => "Bürobedarf, Porto, Telefon",
 
 242           24 => "Sonstige Aufwendungen",
 
 243           25 => "Abschreibungen auf Anlagever.",
 
 244           26 => "Abschreibungen auf GWG",
 
 246           28 => "Umsatzsteuerzahlungen",
 
 248           30 => "Ausserordentlicher Aufwand",
 
 249           31 => "Betriebliche Steuern");
 
 250   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
 
 251     my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
 
 252     if ($item == $form->{pos_eur}) {
 
 253       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 255       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 260   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 264              2  => 'Best.Verdg.FE/UE',
 
 265              3  => 'Aktiv.Eigenleistung',
 
 266              4  => 'Mat./Wareneinkauf',
 
 267              5  => 'So.betr.Erlöse',
 
 268              10 => 'Personalkosten',
 
 270              12 => 'Betriebl.Steuern',
 
 271              13 => 'Vers./Beiträge',
 
 272              14 => 'Kfz.Kosten o.St.',
 
 273              15 => 'Werbe-Reisek.',
 
 274              16 => 'Kosten Warenabgabe',
 
 275              17 => 'Abschreibungen',
 
 276              18 => 'Rep./instandhlt.',
 
 277              19 => 'Übrige Steuern',
 
 278              20 => 'Sonst.Kosten',
 
 280              31 => 'Sonst.neutr.Aufw.',
 
 282              33 => 'Sonst.neutr.Ertrag',
 
 283              34 => 'Verr.kalk.Kosten',
 
 284              35 => 'Steuern Eink.u.Ertr.');
 
 285   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
 
 286     my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
 
 287     if ($item == $form->{pos_bwa}) {
 
 288       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 290       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 295 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 296   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 297   foreach my $item ((1, 2, 3, 4)) {
 
 298     if ($item == $form->{pos_bilanz}) {
 
 299       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 301       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 306   # this is for our parser only! Do not remove.
 
 307   # type=submit $locale->text('Add Account')
 
 308   # type=submit $locale->text('Edit Account')
 
 310   $form->{type} = "account";
 
 312   # preselections category
 
 314   my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 317       'A'  => $locale->text('Asset'),
 
 318       'L'  => $locale->text('Liability'),
 
 319       'Q'  => $locale->text('Equity'),
 
 320       'I'  => $locale->text('Revenue'),
 
 321       'E'  => $locale->text('Expense'),
 
 322       'C'  => $locale->text('Costs'),
 
 324   foreach my $item ( sort({ $a <=> $b } keys %category) ) {
 
 325     if ($item eq $form->{category}) {
 
 326       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 328       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 333   # preselection chart type
 
 334   my $select_charttype = q{};
 
 337       'A'  => $locale->text('Account'),
 
 338       'H'  => $locale->text('Heading'),
 
 341   foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
 
 342     if ($item eq $form->{charttype}) {
 
 343       $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
 
 346       $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
 
 351   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 355   my $parameters_ref = {
 
 356     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 357     select_category            => $select_category,
 
 358     select_charttype           => $select_charttype,
 
 359     select_bwa                 => $select_bwa,
 
 360     select_bilanz              => $select_bilanz,
 
 361     select_eur                 => $select_eur,
 
 364   # Ausgabe des Templates
 
 365   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 368   $main::lxdebug->leave_sub();
 
 372   $main::lxdebug->enter_sub();
 
 374   my $form     = $main::form;
 
 375   my $locale   = $main::locale;
 
 377   $main::auth->assert('config');
 
 381 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
 
 384   if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
 
 386 <input type=submit class=submit name=action value="|
 
 387     . $locale->text('Save') . qq|">
 
 391   if ($form->{id} && $form->{orphaned}) {
 
 392     print qq|<input type=submit class=submit name=action value="|
 
 393       . $locale->text('Delete') . qq|">|;
 
 396   if ($form->{id} && $form->{type} eq "account") {
 
 398     <input class=submit type=submit name=action value="|
 
 399       . $locale->text('Save as new') . qq|">|;
 
 409   $main::lxdebug->leave_sub();
 
 413   $main::lxdebug->enter_sub();
 
 415   my $form     = $main::form;
 
 416   my %myconfig = %main::myconfig;
 
 417   my $locale   = $main::locale;
 
 419   $main::auth->assert('config');
 
 421   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 422   $form->isblank("description", $locale->text('Account Description missing!'));
 
 424   if ($form->{charttype} eq 'A'){
 
 425     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 428   $form->redirect($locale->text('Account saved!'))
 
 429     if (AM->save_account(\%myconfig, \%$form));
 
 430   $form->error($locale->text('Cannot save account!'));
 
 432   $main::lxdebug->leave_sub();
 
 435 sub save_as_new_account {
 
 436   $main::lxdebug->enter_sub();
 
 438   my $form     = $main::form;
 
 439   my %myconfig = %main::myconfig;
 
 440   my $locale   = $main::locale;
 
 442   $main::auth->assert('config');
 
 444   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 445   $form->isblank("description", $locale->text('Account Description missing!'));
 
 447   if ($form->{charttype} eq 'A'){
 
 448     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 451   for my $taxkey (0 .. 9) {
 
 452     if ($form->{"taxkey_id_$taxkey"}) {
 
 453       $form->{"taxkey_id_$taxkey"} = "NEW";
 
 458   if ($form->{"original_accno"} &&
 
 459       ($form->{"accno"} eq $form->{"original_accno"})) {
 
 460     $form->error($locale->text('Account Number already used!'));
 
 462   $form->redirect($locale->text('Account saved!'))
 
 463     if (AM->save_account(\%myconfig, \%$form));
 
 464   $form->error($locale->text('Cannot save account!'));
 
 466   $main::lxdebug->leave_sub();
 
 470   $main::lxdebug->enter_sub();
 
 472   my $form     = $main::form;
 
 473   my %myconfig = %main::myconfig;
 
 474   my $locale   = $main::locale;
 
 476   $main::auth->assert('config');
 
 478   $form->{callback}     = build_std_url('action=list_account');
 
 479   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 481   CA->all_accounts(\%myconfig, \%$form);
 
 483   foreach my $ca (@{ $form->{CA} }) {
 
 488     if ($ca->{amount} > 0) {
 
 489       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 491     if ($ca->{amount} < 0) {
 
 492       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 494     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:'';
 
 495     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 499   my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
 
 501   # Eneable AJAX debuging
 
 505   push(@ { $form->{AJAX} }, $pjx);
 
 507   $form->{stylesheets} = "list_accounts.css";
 
 508   $form->{title}       = $locale->text('Chart of Accounts');
 
 513   my $parameters_ref = {
 
 514   #   hidden_variables                => $_hidden_variables_ref,
 
 517   # Ausgabe des Templates
 
 518   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
 520   $main::lxdebug->leave_sub();
 
 525 sub list_account_details {
 
 526 # Ajax Funktion aus list_account_details
 
 527   $main::lxdebug->enter_sub();
 
 529   my $form     = $main::form;
 
 530   my %myconfig = %main::myconfig;
 
 531   my $locale   = $main::locale;
 
 533   $main::auth->assert('config');
 
 535   my $chart_id = $form->{args};
 
 537   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 539   foreach my $ca (@{ $form->{CA} }) {
 
 541     $ca->{debit}  = " ";
 
 542     $ca->{credit} = " ";
 
 544     if ($ca->{amount} > 0) {
 
 546         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 548     if ($ca->{amount} < 0) {
 
 550         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 553     my @links = split( q{:}, $ca->{link});
 
 557     foreach my $link (@links){
 
 558       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 559                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 560                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 561                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 562                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 563                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 564                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 565                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 566                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 567                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 568                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 569                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 570                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 571                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 572                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 573 #               : ( $link eq 'CT_tax' )        ? $locale->text('Account Link CT_tax')
 
 574                : $locale->text('Unknown Link') . ': ' . $link;
 
 575       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 578     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 579                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 580                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 581                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 582                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 583                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 584                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 585                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 588   $form->{title} = $locale->text('Chart of Accounts');
 
 591   print $form->parse_html_template('am/list_account_details');
 
 593   $main::lxdebug->leave_sub();
 
 598   $main::lxdebug->enter_sub();
 
 600   my $form     = $main::form;
 
 601   my %myconfig = %main::myconfig;
 
 602   my $locale   = $main::locale;
 
 604   $main::auth->assert('config');
 
 606   $form->{title} = $locale->text('Delete Account');
 
 609     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
 
 611     if ($form->{id} == $form->{$id}) {
 
 612       $form->error($locale->text('Cannot delete default account!'));
 
 616   $form->redirect($locale->text('Account deleted!'))
 
 617     if (AM->delete_account(\%myconfig, \%$form));
 
 618   $form->error($locale->text('Cannot delete account!'));
 
 620   $main::lxdebug->leave_sub();
 
 624   $main::lxdebug->enter_sub();
 
 626   my $form     = $main::form;
 
 628   $main::auth->assert('config');
 
 630   $form->{title} = "Add";
 
 633   $form->{callback} = "am.pl?action=add_department" unless $form->{callback};
 
 638   $main::lxdebug->leave_sub();
 
 641 sub edit_department {
 
 642   $main::lxdebug->enter_sub();
 
 644   my $form     = $main::form;
 
 645   my %myconfig = %main::myconfig;
 
 647   $main::auth->assert('config');
 
 649   $form->{title} = "Edit";
 
 651   AM->get_department(\%myconfig, \%$form);
 
 656   $main::lxdebug->leave_sub();
 
 659 sub list_department {
 
 660   $main::lxdebug->enter_sub();
 
 662   my $form     = $main::form;
 
 663   my %myconfig = %main::myconfig;
 
 664   my $locale   = $main::locale;
 
 666   $main::auth->assert('config');
 
 668   AM->departments(\%myconfig, \%$form);
 
 670   $form->{callback} = "am.pl?action=list_department";
 
 672   my $callback = $form->escape($form->{callback});
 
 674   $form->{title} = $locale->text('Departments');
 
 676   my @column_index = qw(description cost profit);
 
 678   $column_header{description} =
 
 679       qq|<th class=listheading width=90%>|
 
 680     . $locale->text('Description')
 
 682   $column_header{cost} =
 
 683       qq|<th class=listheading nowrap>|
 
 684     . $locale->text('Cost Center')
 
 686   $column_header{profit} =
 
 687       qq|<th class=listheading nowrap>|
 
 688     . $locale->text('Profit Center')
 
 698     <th class=listtop>$form->{title}</th>
 
 704         <tr class=listheading>
 
 707   map { print "$column_header{$_}\n" } @column_index;
 
 713   my ($i, %column_data);
 
 714   foreach my $ref (@{ $form->{ALL} }) {
 
 720         <tr valign=top class=listrow$i>
 
 723     my $costcenter   = ($ref->{role} eq "C") ? "X" : "";
 
 724     my $profitcenter = ($ref->{role} eq "P") ? "X" : "";
 
 726     $column_data{description} =
 
 727       qq|<td><a href="am.pl?action=edit_department&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
 728     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
 
 729     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
 
 731     map { print "$column_data{$_}\n" } @column_index;
 
 743   <td><hr size=3 noshade></td>
 
 748 <form method=post action=am.pl>
 
 750 <input name=callback type=hidden value="$form->{callback}">
 
 752 <input type=hidden name=type value=department>
 
 754 <input class=submit type=submit name=action value="|
 
 755     . $locale->text('Add') . qq|">
 
 763   $main::lxdebug->leave_sub();
 
 766 sub department_header {
 
 767   $main::lxdebug->enter_sub();
 
 769   my $form     = $main::form;
 
 770   my $locale   = $main::locale;
 
 772   $main::auth->assert('config');
 
 774   $form->{title} = $locale->text("$form->{title} Department");
 
 776   # $locale->text('Add Department')
 
 777   # $locale->text('Edit Department')
 
 779   $form->{description} =~ s/\"/"/g;
 
 781   my ($rows, $description);
 
 782   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
 
 784       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
 
 787       qq|<input name=description size=60 value="$form->{description}">|;
 
 790   my $costcenter   = "checked" if $form->{role} eq "C";
 
 791   my $profitcenter = "checked" if $form->{role} eq "P";
 
 798 <form method=post action=am.pl>
 
 800 <input type=hidden name=id value=$form->{id}>
 
 801 <input type=hidden name=type value=department>
 
 805     <th class=listtop colspan=2>$form->{title}</th>
 
 809     <th align=right>| . $locale->text('Description') . qq|</th>
 
 810     <td>$description</td>
 
 814     <td><input type=radio style=radio name=role value="C" $costcenter> |
 
 815     . $locale->text('Cost Center') . qq|
 
 816         <input type=radio style=radio name=role value="P" $profitcenter> |
 
 817     . $locale->text('Profit Center') . qq|
 
 820     <td colspan=2><hr size=3 noshade></td>
 
 825   $main::lxdebug->leave_sub();
 
 828 sub save_department {
 
 829   $main::lxdebug->enter_sub();
 
 831   my $form     = $main::form;
 
 832   my %myconfig = %main::myconfig;
 
 833   my $locale   = $main::locale;
 
 835   $main::auth->assert('config');
 
 837   $form->isblank("description", $locale->text('Description missing!'));
 
 838   AM->save_department(\%myconfig, \%$form);
 
 839   $form->redirect($locale->text('Department saved!'));
 
 841   $main::lxdebug->leave_sub();
 
 844 sub delete_department {
 
 845   $main::lxdebug->enter_sub();
 
 847   my $form     = $main::form;
 
 848   my %myconfig = %main::myconfig;
 
 849   my $locale   = $main::locale;
 
 851   $main::auth->assert('config');
 
 853   AM->delete_department(\%myconfig, \%$form);
 
 854   $form->redirect($locale->text('Department deleted!'));
 
 856   $main::lxdebug->leave_sub();
 
 860   $main::lxdebug->enter_sub();
 
 862   my $form     = $main::form;
 
 864   $main::auth->assert('config');
 
 866   $form->{title} = "Add";
 
 868   $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
 
 873   $main::lxdebug->leave_sub();
 
 877   $main::lxdebug->enter_sub();
 
 879   my $form     = $main::form;
 
 880   my %myconfig = %main::myconfig;
 
 882   $main::auth->assert('config');
 
 884   $form->{title} = "Edit";
 
 886   AM->get_lead(\%myconfig, \%$form);
 
 890   $form->{orphaned} = 1;
 
 893   $main::lxdebug->leave_sub();
 
 897   $main::lxdebug->enter_sub();
 
 899   my $form     = $main::form;
 
 900   my %myconfig = %main::myconfig;
 
 901   my $locale   = $main::locale;
 
 903   $main::auth->assert('config');
 
 905   AM->lead(\%myconfig, \%$form);
 
 907   $form->{callback} = "am.pl?action=list_lead";
 
 909   my $callback = $form->escape($form->{callback});
 
 911   $form->{title} = $locale->text('Lead');
 
 913   my @column_index = qw(description cost profit);
 
 915   $column_header{description} =
 
 916       qq|<th class=listheading width=100%>|
 
 917     . $locale->text('Description')
 
 927     <th class=listtop>$form->{title}</th>
 
 930   <tr class=listheading>
 
 933   map { print "$column_header{$_}\n" } @column_index;
 
 939   my ($i, %column_data);
 
 940   foreach my $ref (@{ $form->{ALL} }) {
 
 946   <tr valign=top class=listrow$i>
 
 949 #    $lead = $ref->{lead};
 
 951     $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
 
 953     map { print "$column_data{$_}\n" } @column_index;
 
 962   <td><hr size=3 noshade></td>
 
 967 <form method=post action=am.pl>
 
 969 <input name=callback type=hidden value="$form->{callback}">
 
 971 <input type=hidden name=type value=lead>
 
 973 <input class=submit type=submit name=action value="|
 
 974     . $locale->text('Add') . qq|">
 
 982   $main::lxdebug->leave_sub();
 
 986   $main::lxdebug->enter_sub();
 
 988   my $form     = $main::form;
 
 989   my $locale   = $main::locale;
 
 991   $main::auth->assert('config');
 
 993   $form->{title} = $locale->text("$form->{title} Lead");
 
 995   # $locale->text('Add Lead')
 
 996   # $locale->text('Edit Lead')
 
 998   $form->{description} =~ s/\"/"/g;
 
1001       qq|<input name=description size=50 value="$form->{lead}">|;
 
1008 <form method=post action=am.pl>
 
1010 <input type=hidden name=id value=$form->{id}>
 
1011 <input type=hidden name=type value=lead>
 
1015     <th class=listtop colspan=2>$form->{title}</th>
 
1017   <tr height="5"></tr>
 
1019     <th align=right>| . $locale->text('Description') . qq|</th>
 
1020     <td>$description</td>
 
1022     <td colspan=2><hr size=3 noshade></td>
 
1027   $main::lxdebug->leave_sub();
 
1031   $main::lxdebug->enter_sub();
 
1033   my $form     = $main::form;
 
1034   my %myconfig = %main::myconfig;
 
1035   my $locale   = $main::locale;
 
1037   $main::auth->assert('config');
 
1039   $form->isblank("description", $locale->text('Description missing!'));
 
1040   AM->save_lead(\%myconfig, \%$form);
 
1041   $form->redirect($locale->text('lead saved!'));
 
1043   $main::lxdebug->leave_sub();
 
1047   $main::lxdebug->enter_sub();
 
1049   my $form     = $main::form;
 
1050   my %myconfig = %main::myconfig;
 
1051   my $locale   = $main::locale;
 
1053   $main::auth->assert('config');
 
1055   AM->delete_lead(\%myconfig, \%$form);
 
1056   $form->redirect($locale->text('lead deleted!'));
 
1058   $main::lxdebug->leave_sub();
 
1062   $main::lxdebug->enter_sub();
 
1064   my $form     = $main::form;
 
1066   $main::auth->assert('config');
 
1068   $form->{title} = "Add";
 
1070   $form->{callback} = "am.pl?action=add_business" unless $form->{callback};
 
1075   $main::lxdebug->leave_sub();
 
1079   $main::lxdebug->enter_sub();
 
1081   my $form     = $main::form;
 
1082   my %myconfig = %main::myconfig;
 
1084   $form->{title} = "Edit";
 
1086   AM->get_business(\%myconfig, \%$form);
 
1090   $form->{orphaned} = 1;
 
1093   $main::lxdebug->leave_sub();
 
1097   $main::lxdebug->enter_sub();
 
1099   my $form     = $main::form;
 
1100   my %myconfig = %main::myconfig;
 
1101   my $locale   = $main::locale;
 
1103   $main::auth->assert('config');
 
1105   AM->business(\%myconfig, \%$form);
 
1107   $form->{callback} = "am.pl?action=list_business";
 
1109   my $callback = $form->escape($form->{callback});
 
1111   $form->{title} = $locale->text('Type of Business');
 
1113   my @column_index = qw(description discount customernumberinit);
 
1114   push @column_index, 'salesman' if $::lx_office_conf{features}->{vertreter};
 
1116   $column_header{description} =
 
1117       qq|<th class=listheading width=60%>|
 
1118     . $locale->text('Description')
 
1120   $column_header{discount} =
 
1121       qq|<th class=listheading width=10%>|
 
1122     . $locale->text('Discount')
 
1124   $column_header{customernumberinit} =
 
1125       qq|<th class=listheading>|
 
1126     . $locale->text('Customernumberinit')
 
1128   $column_header{salesman} =
 
1129       qq|<th class=listheading>|
 
1130     . $locale->text('Representative')
 
1140     <th class=listtop>$form->{title}</th>
 
1142   <tr height="5"></tr>
 
1146         <tr class=listheading>
 
1149   map { print "$column_header{$_}\n" } @column_index;
 
1155   my ($i, %column_data);
 
1156   foreach my $ref (@{ $form->{ALL} }) {
 
1162         <tr valign=top class=listrow$i>
 
1165     my $discount    = $form->format_amount(\%myconfig, $ref->{discount} * 100);
 
1166     my $description = $ref->{description};
 
1167     $column_data{description} = qq|<td><a href="am.pl?action=edit_business&id=$ref->{id}&callback=$callback">$description</td>|;
 
1168     $column_data{discount}           = qq|<td align=right>$discount</td>|;
 
1169     $column_data{customernumberinit} =
 
1170       qq|<td align=right>$ref->{customernumberinit}</td>|;
 
1171     $column_data{salesman} = '<td>' . ($ref->{salesman} ? $::locale->text('Yes') : $::locale->text('No')) . '</td>';
 
1173     map { print "$column_data{$_}\n" } @column_index;
 
1185   <td><hr size=3 noshade></td>
 
1190 <form method=post action=am.pl>
 
1192 <input name=callback type=hidden value="$form->{callback}">
 
1194 <input type=hidden name=type value=business>
 
1196 <input class=submit type=submit name=action value="|
 
1197     . $locale->text('Add') . qq|">
 
1205   $main::lxdebug->leave_sub();
 
1208 sub business_header {
 
1209   $main::lxdebug->enter_sub();
 
1211   my $form     = $main::form;
 
1212   my %myconfig = %main::myconfig;
 
1213   my $locale   = $main::locale;
 
1215   $main::auth->assert('config');
 
1217   $form->{title}    = $locale->text("$form->{title} Business");
 
1219   # $locale->text('Add Business')
 
1220   # $locale->text('Edit Business')
 
1222   $form->{description} =~ s/\"/"/g;
 
1224     $form->format_amount(\%myconfig, $form->{discount} * 100);
 
1227   if ($::lx_office_conf{features}->{vertreter}) {
 
1228     $salesman_code = qq|
 
1230     <th align="right">| . $locale->text('Representative') . qq|</th>
 
1231     <td>| . $::cgi->checkbox(-name => "salesman", -value => 1, -label => '', 'checked' => $form->{salesman} ? 1 : 0) . qq|</td>
 
1235     $salesman_code = $::cgi->hidden(-name => 'salesman', -value => $form->{salesman} ? 1 : 0);
 
1243 <form method=post action=am.pl>
 
1245 <input type=hidden name=id value=$form->{id}>
 
1246 <input type=hidden name=type value=business>
 
1250     <th class=listtop colspan=2>$form->{title}</th>
 
1252   <tr height="5"></tr>
 
1254     <th align=right>| . $locale->text('Type of Business') . qq|</th>
 
1255     <td><input name=description size=30 value="$form->{description}"></td>
 
1258     <th align=right>| . $locale->text('Discount') . qq| %</th>
 
1259     <td><input name=discount size=5 value=$form->{discount}></td>
 
1262     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
 
1263     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
 
1266   <td colspan=2><hr size=3 noshade></td>
 
1271   $main::lxdebug->leave_sub();
 
1275   $main::lxdebug->enter_sub();
 
1277   my $form     = $main::form;
 
1278   my %myconfig = %main::myconfig;
 
1279   my $locale   = $main::locale;
 
1281   $main::auth->assert('config');
 
1283   $form->isblank("description", $locale->text('Description missing!'));
 
1284   $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
 
1285   AM->save_business(\%myconfig, \%$form);
 
1286   $form->redirect($locale->text('Business saved!'));
 
1288   $main::lxdebug->leave_sub();
 
1291 sub delete_business {
 
1292   $main::lxdebug->enter_sub();
 
1294   my $form     = $main::form;
 
1295   my %myconfig = %main::myconfig;
 
1296   my $locale   = $main::locale;
 
1298   $main::auth->assert('config');
 
1300   AM->delete_business(\%myconfig, \%$form);
 
1301   $form->redirect($locale->text('Business deleted!'));
 
1303   $main::lxdebug->leave_sub();
 
1307   $main::lxdebug->enter_sub();
 
1309   my $form     = $main::form;
 
1311   $main::auth->assert('config');
 
1313   $form->{title} = "Add";
 
1315   $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
 
1320   $main::lxdebug->leave_sub();
 
1324   $main::lxdebug->enter_sub();
 
1326   my $form     = $main::form;
 
1327   my %myconfig = %main::myconfig;
 
1329   $main::auth->assert('config');
 
1331   $form->{title} = "Edit";
 
1333   AM->get_language(\%myconfig, \%$form);
 
1337   $form->{orphaned} = 1;
 
1340   $main::lxdebug->leave_sub();
 
1344   $main::lxdebug->enter_sub();
 
1346   my $form     = $main::form;
 
1347   my %myconfig = %main::myconfig;
 
1348   my $locale   = $main::locale;
 
1350   $main::auth->assert('config');
 
1352   AM->language(\%myconfig, \%$form);
 
1354   $form->{callback} = "am.pl?action=list_language";
 
1356   my $callback = $form->escape($form->{callback});
 
1358   $form->{title} = $locale->text('Languages');
 
1360   my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
 
1362   $column_header{description} =
 
1363       qq|<th class=listheading width=60%>|
 
1364     . $locale->text('Description')
 
1366   $column_header{template_code} =
 
1367       qq|<th class=listheading width=10%>|
 
1368     . $locale->text('Template Code')
 
1370   $column_header{article_code} =
 
1371       qq|<th class=listheading>|
 
1372     . $locale->text('Article Code')
 
1374   $column_header{output_numberformat} =
 
1375       qq|<th class=listheading>|
 
1376     . $locale->text('Number Format')
 
1378   $column_header{output_dateformat} =
 
1379       qq|<th class=listheading>|
 
1380     . $locale->text('Date Format')
 
1382   $column_header{output_longdates} =
 
1383       qq|<th class=listheading>|
 
1384     . $locale->text('Long Dates')
 
1394     <th class=listtop>$form->{title}</th>
 
1396   <tr height="5"></tr>
 
1400         <tr class=listheading>
 
1403   map { print "$column_header{$_}\n" } @column_index;
 
1409   my ($i, %column_data);
 
1410   foreach my $ref (@{ $form->{ALL} }) {
 
1416         <tr valign=top class=listrow$i>
 
1420     $column_data{description} =
 
1421       qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1422     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
 
1423     $column_data{article_code} =
 
1424       qq|<td align=right>$ref->{article_code}</td>|;
 
1425     $column_data{output_numberformat} =
 
1427       ($ref->{output_numberformat} ? $ref->{output_numberformat} :
 
1428        $locale->text("use program settings")) .
 
1430     $column_data{output_dateformat} =
 
1432       ($ref->{output_dateformat} ? $ref->{output_dateformat} :
 
1433        $locale->text("use program settings")) .
 
1435     $column_data{output_longdates} =
 
1437       ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
 
1440     map { print "$column_data{$_}\n" } @column_index;
 
1452   <td><hr size=3 noshade></td>
 
1457 <form method=post action=am.pl>
 
1459 <input name=callback type=hidden value="$form->{callback}">
 
1461 <input type=hidden name=type value=language>
 
1463 <input class=submit type=submit name=action value="|
 
1464     . $locale->text('Add') . qq|">
 
1472   $main::lxdebug->leave_sub();
 
1475 sub language_header {
 
1476   $main::lxdebug->enter_sub();
 
1478   my $form     = $main::form;
 
1479   my $locale   = $main::locale;
 
1481   $main::auth->assert('config');
 
1483   $form->{title}    = $locale->text("$form->{title} Language");
 
1485   # $locale->text('Add Language')
 
1486   # $locale->text('Edit Language')
 
1488   $form->{description} =~ s/\"/"/g;
 
1489   $form->{template_code} =~ s/\"/"/g;
 
1490   $form->{article_code} =~ s/\"/"/g;
 
1496     qq|<option value="">| . $locale->text("use program settings") .
 
1498   foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
 
1500       ($item eq $form->{output_numberformat})
 
1501       ? "<option selected>$item"
 
1507     qq|<option value="">| . $locale->text("use program settings") .
 
1509   foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
 
1511       ($item eq $form->{output_dateformat})
 
1512       ? "<option selected>$item"
 
1520 <form method=post action=am.pl>
 
1522 <input type=hidden name=id value=$form->{id}>
 
1523 <input type=hidden name=type value=language>
 
1527     <th class=listtop colspan=2>$form->{title}</th>
 
1529   <tr height="5"></tr>
 
1531     <th align=right>| . $locale->text('Language') . qq|</th>
 
1532     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1535     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1536     <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
 
1539     <th align=right>| . $locale->text('Article Code') . qq|</th>
 
1540     <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
 
1543     <th align=right>| . $locale->text('Number Format') . qq|</th>
 
1544     <td><select name="output_numberformat">$numberformat</select></td>
 
1547     <th align=right>| . $locale->text('Date Format') . qq|</th>
 
1548     <td><select name="output_dateformat">$dateformat</select></td>
 
1551     <th align=right>| . $locale->text('Long Dates') . qq|</th>
 
1552     <td><input type="radio" name="output_longdates" value="1"| .
 
1553     ($form->{output_longdates} ? " checked" : "") .
 
1554     qq|>| . $locale->text("Yes") .
 
1555     qq|<input type="radio" name="output_longdates" value="0"| .
 
1556     ($form->{output_longdates} ? "" : " checked") .
 
1557     qq|>| . $locale->text("No") .
 
1560   <td colspan=2><hr size=3 noshade></td>
 
1565   $main::lxdebug->leave_sub();
 
1569   $main::lxdebug->enter_sub();
 
1571   my $form     = $main::form;
 
1572   my %myconfig = %main::myconfig;
 
1573   my $locale   = $main::locale;
 
1575   $main::auth->assert('config');
 
1577   $form->isblank("description", $locale->text('Language missing!'));
 
1578   $form->isblank("template_code", $locale->text('Template Code missing!'));
 
1579   $form->isblank("article_code", $locale->text('Article Code missing!'));
 
1580   AM->save_language(\%myconfig, \%$form);
 
1581   $form->redirect($locale->text('Language saved!'));
 
1583   $main::lxdebug->leave_sub();
 
1586 sub delete_language {
 
1587   $main::lxdebug->enter_sub();
 
1589   my $form     = $main::form;
 
1590   my %myconfig = %main::myconfig;
 
1591   my $locale   = $main::locale;
 
1593   $main::auth->assert('config');
 
1595   AM->delete_language(\%myconfig, \%$form);
 
1596   $form->redirect($locale->text('Language deleted!'));
 
1598   $main::lxdebug->leave_sub();
 
1602 sub add_buchungsgruppe {
 
1603   $main::lxdebug->enter_sub();
 
1605   my $form     = $main::form;
 
1606   my %myconfig = %main::myconfig;
 
1607   my $locale   = $main::locale;
 
1609   $main::auth->assert('config');
 
1611   # $locale->text("Add Buchungsgruppe")
 
1612   # $locale->text("Edit Buchungsgruppe")
 
1613   $form->{title} = "Add";
 
1615   $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
 
1617   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1618   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
 
1619   for (my $i = 0; 4 > $i; $i++) {
 
1620     map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
 
1621         qw(income expense));
 
1624   &buchungsgruppe_header;
 
1627   $main::lxdebug->leave_sub();
 
1630 sub edit_buchungsgruppe {
 
1631   $main::lxdebug->enter_sub();
 
1633   my $form     = $main::form;
 
1634   my %myconfig = %main::myconfig;
 
1636   $main::auth->assert('config');
 
1638   $form->{title} = "Edit";
 
1640   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1642   &buchungsgruppe_header;
 
1646   $main::lxdebug->leave_sub();
 
1649 sub list_buchungsgruppe {
 
1650   $main::lxdebug->enter_sub();
 
1652   my $form     = $main::form;
 
1653   my %myconfig = %main::myconfig;
 
1654   my $locale   = $main::locale;
 
1656   $main::auth->assert('config');
 
1658   AM->buchungsgruppe(\%myconfig, \%$form);
 
1660   $form->{callback} = "am.pl?action=list_buchungsgruppe";
 
1662   my $callback = $form->escape($form->{callback});
 
1664   $form->{title} = $locale->text('Buchungsgruppen');
 
1666   my @column_index = qw(up down description inventory_accno
 
1667                      income_accno_0 expense_accno_0
 
1668                      income_accno_1 expense_accno_1
 
1669                      income_accno_2 expense_accno_2
 
1670                      income_accno_3 expense_accno_3 );
 
1672   $column_header{up} =
 
1673       qq|<th class="listheading" width="16">|
 
1674     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
1676   $column_header{down} =
 
1677       qq|<th class="listheading" width="16">|
 
1678     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
1680   $column_header{description} =
 
1681       qq|<th class="listheading" width="40%">|
 
1682     . $locale->text('Description')
 
1684   $column_header{inventory_accno} =
 
1685       qq|<th class=listheading>|
 
1686     . $locale->text('Bestandskonto')
 
1688   $column_header{income_accno_0} =
 
1689       qq|<th class=listheading>|
 
1690     . $locale->text('National Revenues')
 
1692   $column_header{expense_accno_0} =
 
1693       qq|<th class=listheading>|
 
1694     . $locale->text('National Expenses')
 
1696   $column_header{income_accno_1} =
 
1697       qq|<th class=listheading>|
 
1698     . $locale->text('Revenues EU with UStId')
 
1700   $column_header{expense_accno_1} =
 
1701       qq|<th class=listheading>|
 
1702     . $locale->text('Expenses EU with UStId')
 
1704   $column_header{income_accno_2} =
 
1705       qq|<th class=listheading>|
 
1706     . $locale->text('Revenues EU without UStId')
 
1708   $column_header{expense_accno_2} =
 
1709       qq|<th class=listheading>|
 
1710     . $locale->text('Expenses EU without UStId')
 
1712   $column_header{income_accno_3} =
 
1713       qq|<th class=listheading>|
 
1714     . $locale->text('Foreign Revenues')
 
1716   $column_header{expense_accno_3} =
 
1717       qq|<th class=listheading>|
 
1718     . $locale->text('Foreign Expenses')
 
1727     <th class=listtop>$form->{title}</th>
 
1729   <tr height="5"></tr>
 
1733         <tr class=listheading>
 
1736   map { print "$column_header{$_}\n" } @column_index;
 
1742   my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
 
1745   my ($i, %column_data);
 
1746   foreach my $ref (@{ $form->{ALL} }) {
 
1752         <tr valign=top class=listrow$i>
 
1756       my $pref = $form->{ALL}->[$row - 1];
 
1758         qq|<td align="center" valign="center" width="16">| .
 
1759         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
 
1760         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
1763       $column_data{up} = qq|<td width="16"> </td>|;
 
1766     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
1767       $column_data{down} = qq|<td width="16"> </td>|;
 
1769       my $nref = $form->{ALL}->[$row + 1];
 
1770       $column_data{down} =
 
1771         qq|<td align="center" valign="center" width="16">| .
 
1772         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
 
1773         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
1777     $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1778     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
 
1779     $column_data{income_accno_0} =
 
1780       qq|<td align=right>$ref->{income_accno_0}</td>|;
 
1781     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
 
1782     $column_data{income_accno_1} =
 
1783       qq|<td align=right>$ref->{income_accno_1}</td>|;
 
1784     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
 
1785     $column_data{income_accno_2} =
 
1786       qq|<td align=right>$ref->{income_accno_2}</td>|;
 
1787     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
 
1788     $column_data{income_accno_3} =
 
1789       qq|<td align=right>$ref->{income_accno_3}</td>|;
 
1790     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
 
1792     map { print "$column_data{$_}\n" } @column_index;
 
1806   <td><hr size=3 noshade></td>
 
1811 <form method=post action=am.pl>
 
1813 <input name=callback type=hidden value="$form->{callback}">
 
1815 <input type=hidden name=type value=buchungsgruppe>
 
1817 <input class=submit type=submit name=action value="|
 
1818     . $locale->text('Add') . qq|">
 
1826   $main::lxdebug->leave_sub();
 
1829 sub buchungsgruppe_header {
 
1830   $main::lxdebug->enter_sub();
 
1832   my $form     = $main::form;
 
1833   my $locale   = $main::locale;
 
1835   $main::auth->assert('config');
 
1837   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
 
1839   # $locale->text('Add Accounting Group')
 
1840   # $locale->text('Edit Accounting Group')
 
1842   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
 
1843   my %acc_type_map = (
 
1844     "IC" => $acc_inventory,
 
1845     "IC_income" => $acc_income,
 
1846     "IC_sale" => $acc_income,
 
1847     "IC_expense" => $acc_expense,
 
1848     "IC_cogs" => $acc_expense,
 
1851   foreach my $key (keys(%acc_type_map)) {
 
1852     foreach my $ref (@{ $form->{IC_links}{$key} }) {
 
1853       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
 
1857   foreach my $type (qw(IC IC_income IC_expense)) {
 
1858     $form->{"select$type"} =
 
1860            map({ "<option value=$_->{id} $_->{selected}>" .
 
1861                    "$_->{accno}--" . H($_->{description}) . "</option>" }
 
1862                sort({ $a->{"accno"} cmp $b->{"accno"} }
 
1863                     values(%{$acc_type_map{$type}}))));
 
1867     $form->{selectIC} =~ s/selected//g;
 
1868     $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/  value=$form->{inventory_accno_id} selected/;
 
1869     $form->{selectIC_income} =~ s/selected//g;
 
1870     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/  value=$form->{income_accno_id_0} selected/;
 
1871     $form->{selectIC_expense} =~ s/selected//g;
 
1872     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
 
1876   if (!$::lx_office_conf{system}->{eur}) {
 
1879                 <th align=right>| . $locale->text('Inventory') . qq|</th>
 
1880                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
 
1881                 <input name=selectIC type=hidden value="$form->{selectIC}">
 
1885                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
 
1889   $linkaccounts .= qq|
 
1891                 <th align=right>| . $locale->text('National Revenues') . qq|</th>
 
1892                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
 
1895                 <th align=right>| . $locale->text('National Expenses') . qq|</th>
 
1896                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
 
1899     $form->{selectIC_income} =~ s/selected//g;
 
1900     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/  value=$form->{income_accno_id_1} selected/;
 
1901     $form->{selectIC_expense} =~ s/selected//g;
 
1902     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/  value=$form->{expense_accno_id_1} selected/;
 
1904   $linkaccounts .= qq|              <tr>
 
1905                 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
 
1906                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
 
1909                 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
 
1910                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
 
1914     $form->{selectIC_income} =~ s/selected//g;
 
1915     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/  value=$form->{income_accno_id_2} selected/;
 
1916     $form->{selectIC_expense} =~ s/selected//g;
 
1917     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/  value=$form->{expense_accno_id_2} selected/;
 
1920   $linkaccounts .= qq|              <tr>
 
1921                 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
 
1922                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
 
1925                 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
 
1926                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
 
1930     $form->{selectIC_income} =~ s/selected//g;
 
1931     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/  value=$form->{income_accno_id_3} selected/;
 
1932     $form->{selectIC_expense} =~ s/selected//g;
 
1933     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/  value=$form->{expense_accno_id_3} selected/;
 
1936   $linkaccounts .= qq|              <tr>
 
1937                 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
 
1938                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
 
1941                 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
 
1942                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
 
1952 <form method=post action=am.pl>
 
1954 <input type=hidden name=id value=$form->{id}>
 
1955 <input type=hidden name=type value=buchungsgruppe>
 
1959     <th class=listtop colspan=2>$form->{title}</th>
 
1961   <tr height="5"></tr>
 
1963     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
 
1964     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1967   <td colspan=2><hr size=3 noshade></td>
 
1972   $main::lxdebug->leave_sub();
 
1975 sub save_buchungsgruppe {
 
1976   $main::lxdebug->enter_sub();
 
1978   my $form     = $main::form;
 
1979   my %myconfig = %main::myconfig;
 
1980   my $locale   = $main::locale;
 
1982   $main::auth->assert('config');
 
1984   $form->isblank("description", $locale->text('Description missing!'));
 
1986   AM->save_buchungsgruppe(\%myconfig, \%$form);
 
1987   $form->redirect($locale->text('Accounting Group saved!'));
 
1989   $main::lxdebug->leave_sub();
 
1992 sub delete_buchungsgruppe {
 
1993   $main::lxdebug->enter_sub();
 
1995   my $form     = $main::form;
 
1996   my %myconfig = %main::myconfig;
 
1997   my $locale   = $main::locale;
 
1999   $main::auth->assert('config');
 
2001   AM->delete_buchungsgruppe(\%myconfig, \%$form);
 
2002   $form->redirect($locale->text('Accounting Group deleted!'));
 
2004   $main::lxdebug->leave_sub();
 
2007 sub swap_buchungsgruppen {
 
2008   $main::lxdebug->enter_sub();
 
2010   my $form     = $main::form;
 
2011   my %myconfig = %main::myconfig;
 
2013   $main::auth->assert('config');
 
2015   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
 
2016   list_buchungsgruppe();
 
2018   $main::lxdebug->leave_sub();
 
2022   $main::lxdebug->enter_sub();
 
2024   my $form     = $main::form;
 
2025   my %myconfig = %main::myconfig;
 
2027   $main::auth->assert('config');
 
2029   $form->{title} = "Add";
 
2031   $form->{callback} = "am.pl?action=add_payment" unless $form->{callback};
 
2033   $form->{terms_netto} = 0;
 
2034   $form->{terms_skonto} = 0;
 
2035   $form->{percent_skonto} = 0;
 
2036   my @languages = AM->language(\%myconfig, $form, 1);
 
2037   map({ $_->{"language"} = $_->{"description"};
 
2038         $_->{"language_id"} = $_->{"id"}; } @languages);
 
2039   $form->{"TRANSLATION"} = \@languages;
 
2043   $main::lxdebug->leave_sub();
 
2047   $main::lxdebug->enter_sub();
 
2049   my $form     = $main::form;
 
2050   my %myconfig = %main::myconfig;
 
2052   $main::auth->assert('config');
 
2054   $form->{title} = "Edit";
 
2056   AM->get_payment(\%myconfig, $form);
 
2057   $form->{percent_skonto} =
 
2058     $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
 
2062   $form->{orphaned} = 1;
 
2065   $main::lxdebug->leave_sub();
 
2069   $main::lxdebug->enter_sub();
 
2071   my $form     = $main::form;
 
2072   my %myconfig = %main::myconfig;
 
2073   my $locale   = $main::locale;
 
2075   $main::auth->assert('config');
 
2077   AM->payment(\%myconfig, \%$form);
 
2079   $form->{callback} = build_std_url("action=list_payment");
 
2081   my $callback = $form->escape($form->{callback});
 
2083   $form->{title} = $locale->text('Payment Terms');
 
2085   my @column_index = qw(up down description description_long terms_netto
 
2086                      terms_skonto percent_skonto);
 
2088   $column_header{up} =
 
2089       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2090     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
2092   $column_header{down} =
 
2093       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2094     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
2096   $column_header{description} =
 
2097       qq|<th class=listheading>|
 
2098     . $locale->text('Description')
 
2100   $column_header{description_long} =
 
2101       qq|<th class=listheading>|
 
2102     . $locale->text('Long Description')
 
2104   $column_header{terms_netto} =
 
2105       qq|<th class=listheading>|
 
2106     . $locale->text('Netto Terms')
 
2108   $column_header{terms_skonto} =
 
2109       qq|<th class=listheading>|
 
2110     . $locale->text('Skonto Terms')
 
2112   $column_header{percent_skonto} =
 
2113       qq|<th class=listheading>|
 
2114     . $locale->text('Skonto')
 
2124     <th class=listtop>$form->{title}</th>
 
2126   <tr height="5"></tr>
 
2130         <tr class=listheading>
 
2133   map { print "$column_header{$_}\n" } @column_index;
 
2139   my $swap_link = build_std_url("action=swap_payment_terms");
 
2142   my ($i, %column_data);
 
2143   foreach my $ref (@{ $form->{ALL} }) {
 
2149         <tr valign=top class=listrow$i>
 
2153       my $pref = $form->{ALL}->[$row - 1];
 
2155         qq|<td align="center" valign="center" width="16">| .
 
2156         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
 
2157         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
2160       $column_data{up} = qq|<td width="16"> </td>|;
 
2163     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
2164       $column_data{down} = qq|<td width="16"> </td>|;
 
2166       my $nref = $form->{ALL}->[$row + 1];
 
2167       $column_data{down} =
 
2168         qq|<td align="center" valign="center" width="16">| .
 
2169         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
 
2170         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
2174     $column_data{description} =
 
2176       build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
 
2177       qq|">| . H($ref->{description}) . qq|</a></td>|;
 
2178     $column_data{description_long} =
 
2179       qq|<td>| . H($ref->{description_long}) . qq|</td>|;
 
2180     $column_data{terms_netto} =
 
2181       qq|<td align=right>$ref->{terms_netto}</td>|;
 
2182     $column_data{terms_skonto} =
 
2183       qq|<td align=right>$ref->{terms_skonto}</td>|;
 
2184     $column_data{percent_skonto} =
 
2185       qq|<td align=right>| .
 
2186       $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
 
2188     map { print "$column_data{$_}\n" } @column_index;
 
2201   <td><hr size=3 noshade></td>
 
2206 <form method=post action=am.pl>
 
2208 <input name=callback type=hidden value="$form->{callback}">
 
2210 <input type=hidden name=type value=payment>
 
2212 <input class=submit type=submit name=action value="|
 
2213     . $locale->text('Add') . qq|">
 
2221   $main::lxdebug->leave_sub();
 
2224 sub payment_header {
 
2225   $main::lxdebug->enter_sub();
 
2227   my $form     = $main::form;
 
2228   my $locale   = $main::locale;
 
2230   $main::auth->assert('config');
 
2232   $form->{title}    = $locale->text("$form->{title} Payment Terms");
 
2234   # $locale->text('Add Payment Terms')
 
2235   # $locale->text('Edit Payment Terms')
 
2237   $form->{description} =~ s/\"/"/g;
 
2246 <form method=post action=am.pl>
 
2248 <input type=hidden name=id value=$form->{id}>
 
2249 <input type=hidden name=type value=payment>
 
2253     <th class=listtop colspan=2>$form->{title}</th>
 
2255   <tr height="5"></tr>
 
2257     <th align=right>| . $locale->text('Description') . qq|</th>
 
2258     <td><input name=description size=30 value="$form->{description}"></td>
 
2261     <th align=right>| . $locale->text('Long Description') . qq|</th>
 
2262     <td><input name=description_long size=50 value="$form->{description_long}"></td>
 
2266   foreach my $language (@{ $form->{"TRANSLATION"} }) {
 
2269     <th align="right">| .
 
2270     sprintf($locale->text('Translation (%s)'),
 
2271             $language->{"language"})
 
2273     <td><input name="description_long_$language->{language_id}" size="50"
 
2274          value="| . Q($language->{"description_long"}) . qq|"></td>
 
2281     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
 
2282     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
 
2285     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
 
2286     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
 
2289     <th align=right>| . $locale->text('Skonto') . qq| %</th>
 
2290     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
 
2292   <td colspan=2><hr size=3 noshade></td>
 
2296 <p>| . $locale->text("You can use the following strings in the long " .
 
2297                      "description and all translations. They will be " .
 
2298                      "replaced by their actual values by Lx-Office " .
 
2299                      "before they're output.")
 
2303   <li>| . $locale->text("<%netto_date%> -- Date the payment is due in " .
 
2306   <li>| . $locale->text("<%skonto_date%> -- Date the payment is due " .
 
2309   <li>| . $locale->text("<%skonto_amount%> -- The deductible amount")
 
2311   <li>| . $locale->text("<%skonto_in_percent%> -- The discount in percent")
 
2313   <li>| . $locale->text("<%total%> -- Amount payable")
 
2315   <li>| . $locale->text("<%total_wo_skonto%> -- Amount payable less discount")
 
2317   <li>| . $locale->text("<%invtotal%> -- Invoice total")
 
2319   <li>| . $locale->text("<%invtotal_wo_skonto%> -- Invoice total less discount")
 
2321   <li>| . $locale->text("<%currency%> -- The selected currency")
 
2323   <li>| . $locale->text("<%terms_netto%> -- The number of days for " .
 
2326   <li>| . $locale->text("<%account_number%> -- Your account number")
 
2328   <li>| . $locale->text("<%bank%> -- Your bank")
 
2330   <li>| . $locale->text("<%bank_code%> -- Your bank code")
 
2334   $main::lxdebug->leave_sub();
 
2338   $main::lxdebug->enter_sub();
 
2340   my $form     = $main::form;
 
2341   my %myconfig = %main::myconfig;
 
2342   my $locale   = $main::locale;
 
2344   $main::auth->assert('config');
 
2346   $form->isblank("description", $locale->text('Description missing!'));
 
2347   $form->{"percent_skonto"} =
 
2348     $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
 
2349   AM->save_payment(\%myconfig, \%$form);
 
2350   $form->redirect($locale->text('Payment Terms saved!'));
 
2352   $main::lxdebug->leave_sub();
 
2355 sub delete_payment {
 
2356   $main::lxdebug->enter_sub();
 
2358   my $form     = $main::form;
 
2359   my %myconfig = %main::myconfig;
 
2360   my $locale   = $main::locale;
 
2362   $main::auth->assert('config');
 
2364   AM->delete_payment(\%myconfig, \%$form);
 
2365   $form->redirect($locale->text('Payment terms deleted!'));
 
2367   $main::lxdebug->leave_sub();
 
2370 sub swap_payment_terms {
 
2371   $main::lxdebug->enter_sub();
 
2373   my $form     = $main::form;
 
2374   my %myconfig = %main::myconfig;
 
2376   $main::auth->assert('config');
 
2378   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
 
2381   $main::lxdebug->leave_sub();
 
2385   $main::lxdebug->enter_sub();
 
2387   my $form     = $main::form;
 
2388   my %myconfig = %main::myconfig;
 
2389   my $locale   = $main::locale;
 
2391   # get defaults for account numbers and last numbers
 
2392   AM->defaultaccounts(\%myconfig, \%$form);
 
2393   $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
 
2395   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
 
2397   foreach my $key (keys %{ $form->{IC} }) {
 
2398     foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
 
2399       my $array = "ACCNOS_" . uc($key);
 
2400       $form->{$array} ||= [];
 
2402       my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
 
2403       push @{ $form->{$array} }, {
 
2406         'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
 
2411   $form->{title} = $locale->text('Ranges of numbers and default accounts');
 
2414   print $form->parse_html_template('am/edit_defaults');
 
2416   $main::lxdebug->leave_sub();
 
2420   $main::lxdebug->enter_sub();
 
2422   my $form     = $main::form;
 
2423   my $locale   = $main::locale;
 
2425   AM->save_defaults();
 
2427   $form->redirect($locale->text('Defaults saved.'));
 
2429   $main::lxdebug->leave_sub();
 
2432 sub _build_cfg_options {
 
2433   my $form     = $main::form;
 
2434   my %myconfig = %main::myconfig;
 
2437   my $array = uc($idx) . 'S';
 
2439   $form->{$array} = [];
 
2440   foreach my $item (@_) {
 
2441     push @{ $form->{$array} }, {
 
2444       'selected' => $item eq $myconfig{$idx},
 
2450   $main::lxdebug->enter_sub();
 
2452   my $form     = $main::form;
 
2453   my %myconfig = %main::myconfig;
 
2454   my $locale   = $main::locale;
 
2456   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
2457   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
2460   if ($::lx_office_conf{print_templates}->{opendocument}
 
2461       && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
 
2462       && $::lx_office_conf{applications}->{xvfb}                 && (-x $::lx_office_conf{applications}->{xvfb})) {
 
2463     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
2464                      "value" => "opendocument_pdf" });
 
2466   if ($::lx_office_conf{print_templates}->{latex}) {
 
2467     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
2469   push(@formats, { "name" => "HTML", "value" => "html" });
 
2470   if ($::lx_office_conf{print_templates}->{latex}) {
 
2471     push(@formats, { "name" => $locale->text("Postscript"),
 
2472                      "value" => "postscript" });
 
2474   if ($::lx_office_conf{print_templates}->{opendocument}) {
 
2475     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
2476                      "value" => "opendocument" });
 
2479   if (!$myconfig{"template_format"}) {
 
2480     $myconfig{"template_format"} = "pdf";
 
2482   $form->{TEMPLATE_FORMATS} = [];
 
2483   foreach my $item (@formats) {
 
2484     push @{ $form->{TEMPLATE_FORMATS} }, {
 
2485       'name'     => $item->{name},
 
2486       'value'    => $item->{value},
 
2487       'selected' => $item->{value} eq $myconfig{template_format},
 
2491   if (!$myconfig{"default_media"}) {
 
2492     $myconfig{"default_media"} = "screen";
 
2495   my %selected = ($myconfig{"default_media"} => "selected");
 
2497     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
2498     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
2499     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
2502   $form->{PRINTERS} = [];
 
2503   foreach my $printer (SL::Printer->all_printers(%::myconfig)) {
 
2504     push @{ $form->{PRINTERS} }, {
 
2505       'name'     => $printer->{printer_description},
 
2506       'value'    => $printer->{id},
 
2507       'selected' => $printer->{id} == $myconfig{default_printer_id},
 
2511   my %countrycodes = User->country_codes;
 
2513   $form->{COUNTRYCODES} = [];
 
2514   foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
2515     push @{ $form->{COUNTRYCODES} }, {
 
2516       'name'     => $countrycodes{$countrycode},
 
2517       'value'    => $countrycode,
 
2518       'selected' => $countrycode eq $myconfig{countrycode},
 
2522   $form->{STYLESHEETS} = [];
 
2523   foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
 
2524     push @{ $form->{STYLESHEETS} }, {
 
2527       'selected' => $item eq $myconfig{stylesheet},
 
2531   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
 
2532   $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
2533   $form->{todo_cfg}            = { TODO->get_user_config('login' => $form->{login}) };
 
2535   $form->{title}               = $locale->text('Edit Preferences for #1', $form->{login});
 
2538   print $form->parse_html_template('am/config');
 
2540   $main::lxdebug->leave_sub();
 
2543 sub save_preferences {
 
2544   $main::lxdebug->enter_sub();
 
2546   my $form     = $main::form;
 
2547   my %myconfig = %main::myconfig;
 
2548   my $locale   = $main::locale;
 
2550   $form->{stylesheet} = $form->{usestylesheet};
 
2552   TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
 
2554   if (AM->save_preferences(\%myconfig, $form)) {
 
2555     if ($::auth->can_change_password()
 
2556         && defined $form->{new_password}
 
2557         && ($form->{new_password} ne '********')) {
 
2558       my $verifier = SL::Auth::PasswordPolicy->new;
 
2559       my $result   = $verifier->verify($form->{new_password});
 
2561       if ($result != SL::Auth::PasswordPolicy->OK()) {
 
2562         $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
 
2565       $::auth->change_password($form->{login}, $form->{new_password});
 
2567       $form->{password} = $form->{new_password};
 
2568       $::auth->set_session_value('password', $form->{password});
 
2569       $::auth->create_or_refresh_session();
 
2572     $form->redirect($locale->text('Preferences saved!'));
 
2575   $form->error($locale->text('Cannot save preferences!'));
 
2577   $main::lxdebug->leave_sub();
 
2581   $main::lxdebug->enter_sub();
 
2583   my $form     = $main::form;
 
2584   my %myconfig = %main::myconfig;
 
2585   my $locale   = $main::locale;
 
2587   $main::auth->assert('config');
 
2589   $form->{title} = $locale->text('Audit Control');
 
2591   AM->closedto(\%myconfig, \%$form);
 
2598 <form method=post action=am.pl>
 
2601   <tr><th class=listtop>$form->{title}</th></tr>
 
2602   <tr height="5"></tr>
 
2607           <th>| . $locale->text('Close Books up to') . qq|</th>
 
2608           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
 
2618 <input type=hidden name=nextsub value=doclose>
 
2620 <input type=submit class=submit name=action value="|
 
2621     . $locale->text('Continue') . qq|">
 
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   AM->closebooks(\%myconfig, \%$form);
 
2643   if ($form->{closedto}) {
 
2645                     $locale->text('Books closed up to') . " "
 
2646                       . $locale->date(\%myconfig, $form->{closedto}, 1));
 
2648     $form->redirect($locale->text('Books are open'));
 
2651   $main::lxdebug->leave_sub();
 
2655   $main::lxdebug->enter_sub();
 
2657   my $form     = $main::form;
 
2658   my %myconfig = %main::myconfig;
 
2659   my $locale   = $main::locale;
 
2661   $main::auth->assert('config');
 
2663   my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
2664   AM->units_in_use(\%myconfig, $form, $units);
 
2665   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
2667   my @languages = AM->language(\%myconfig, $form, 1);
 
2669   my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
2672   foreach (@unit_list) {
 
2673     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
2674     $_->{"UNITLANGUAGES"} = [];
 
2675     foreach my $lang (@languages) {
 
2676       push(@{ $_->{"UNITLANGUAGES"} },
 
2678              "unit" => $_->{"name"},
 
2679              "language_id" => $lang->{"id"},
 
2680              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
2681              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
2687   $units = AM->retrieve_units(\%myconfig, $form);
 
2688   my $ddbox = AM->unit_select_data($units, undef, 1);
 
2690   $form->{"title"} = $locale->text("Add and edit units");
 
2692   print($form->parse_html_template("am/edit_units",
 
2693                                    { "UNITS"               => \@unit_list,
 
2694                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
2695                                      "LANGUAGES"           => \@languages,
 
2698   $main::lxdebug->leave_sub();
 
2702   $main::lxdebug->enter_sub();
 
2704   my $form     = $main::form;
 
2705   my %myconfig = %main::myconfig;
 
2706   my $locale   = $main::locale;
 
2708   $main::auth->assert('config');
 
2710   $form->isblank("new_name", $locale->text("The name is missing."));
 
2711   my $units = AM->retrieve_units(\%myconfig, $form);
 
2712   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
2713   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
2715   my ($base_unit, $factor);
 
2716   if ($form->{"new_base_unit"}) {
 
2717     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
2719     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
2720     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
2721     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
2722     $base_unit = $form->{"new_base_unit"};
 
2726   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
2727     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
2728     push(@languages, { "id" => $lang->{"id"},
 
2729                        "localized" => $form->{"new_localized_$lang->{id}"},
 
2730                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
2734   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
2736   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
2740   $main::lxdebug->leave_sub();
 
2743 sub set_unit_languages {
 
2744   $main::lxdebug->enter_sub();
 
2746   my $form     = $main::form;
 
2748   $main::auth->assert('config');
 
2750   my ($unit, $languages, $idx) = @_;
 
2752   $unit->{"LANGUAGES"} = [];
 
2754   foreach my $lang (@{$languages}) {
 
2755     push(@{ $unit->{"LANGUAGES"} },
 
2756          { "id" => $lang->{"id"},
 
2757            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
2758            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
2762   $main::lxdebug->leave_sub();
 
2766   $main::lxdebug->enter_sub();
 
2768   my $form     = $main::form;
 
2769   my %myconfig = %main::myconfig;
 
2770   my $locale   = $main::locale;
 
2772   $main::auth->assert('config');
 
2774   my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
2775   AM->units_in_use(\%myconfig, $form, $old_units);
 
2777   my @languages = AM->language(\%myconfig, $form, 1);
 
2780   my @delete_units = ();
 
2781   foreach my $i (1..($form->{"rowcount"} * 1)) {
 
2782     my $old_unit = $old_units->{$form->{"old_name_$i"}};
 
2784       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
2787     if ($form->{"unchangeable_$i"}) {
 
2788       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
2789       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
2790       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2794     if ($old_unit->{"in_use"}) {
 
2795       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
2798     if ($form->{"delete_$i"}) {
 
2799       push(@delete_units, $old_unit->{"name"});
 
2803     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
2805     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
2806     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
2807     $new_units->{$form->{"name_$i"}} = \%h;
 
2808     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
2809     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2812   foreach my $unit (values(%{$new_units})) {
 
2813     next unless ($unit->{"old_name"});
 
2814     if ($unit->{"base_unit"}) {
 
2815       $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"}))
 
2816         unless (defined($new_units->{$unit->{"base_unit"}}));
 
2817       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
2818       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
2820       $unit->{"base_unit"} = undef;
 
2821       $unit->{"factor"} = undef;
 
2825   foreach my $unit (values(%{$new_units})) {
 
2826     next if ($unit->{"unchanged_unit"});
 
2828     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
2829     my $new_unit = $unit;
 
2830     while ($new_unit->{"base_unit"}) {
 
2831       $new_unit->{"seen"} = 1;
 
2832       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
2833       if ($new_unit->{"seen"}) {
 
2834         $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, " .
 
2835                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
2840   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
2842   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
2846   $main::lxdebug->leave_sub();
 
2849 sub show_history_search {
 
2850   $main::lxdebug->enter_sub();
 
2852   my $form     = $main::form;
 
2853   my $locale   = $main::locale;
 
2855   $main::auth->assert('config');
 
2857   $form->{title} = $locale->text("History Search");
 
2860   print $form->parse_html_template("common/search_history");
 
2862   $main::lxdebug->leave_sub();
 
2865 sub show_am_history {
 
2866   $main::lxdebug->enter_sub();
 
2868   my $form     = $main::form;
 
2869   my %myconfig = %main::myconfig;
 
2870   my $locale   = $main::locale;
 
2872   $main::auth->assert('config');
 
2874   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
 
2875   $form->{order} ||= 'h.itime--1';
 
2877   my %search = ( "Artikelnummer"          => "parts",
 
2878                  "Kundennummer"           => "customer",
 
2879                  "Lieferantennummer"      => "vendor",
 
2880                  "Projektnummer"          => "project",
 
2881                  "Buchungsnummer"         => "oe",
 
2882                  "Eingangsrechnungnummer" => "ap",
 
2883                  "Ausgangsrechnungnummer" => "ar",
 
2884                  "Mahnungsnummer"         => "dunning"
 
2886   my %searchNo = ( "Artikelnummer"          => "partnumber",
 
2887                    "Kundennummer"           => "customernumber",
 
2888                    "Lieferantennummer"      => "vendornumber",
 
2889                    "Projektnummer"          => "projectnumber",
 
2890                    "Buchungsnummer"         => "ordnumber",
 
2891                    "Eingangsrechnungnummer" => "invnumber",
 
2892                    "Ausgangsrechnungnummer" => "invnumber",
 
2893                    "Mahnungsnummer"         => "dunning_id"
 
2896   my $dbh = $form->dbconnect(\%myconfig);
 
2898   my $restriction  = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
 
2899   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
 
2900   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
 
2901   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
2902     $restriction  .= qq| AND employee_id = |    . $form->{mitarbeiter};
 
2903   } elsif ($form->{mitarbeiter}) {
 
2904     $restriction  .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
 
2907   my $query = qq|SELECT trans_id AS id FROM history_erp | .
 
2908     (  $form->{'searchid'} ? qq| WHERE snumbers = '|  . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
 
2909      :                       qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
2911   my @ids    = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
 
2912   my $daten .= shift @ids;
 
2913   $daten    .= join '', map { " OR trans_id = $_" } @ids;
 
2915   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
2916   $sort =~ s/.*\.(.*)$/$1/;
 
2918   $form->{title} = $locale->text("History Search");
 
2921   print $form->parse_html_template("common/show_history",
 
2922                                    { "DATEN"          => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
2923                                      "SUCCESS"        => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
2926                                      uc($sort) . "BY" => $sortby,
 
2927                                      'callback'       => $callback,
 
2931   $main::lxdebug->leave_sub();
 
2935   $main::lxdebug->enter_sub();
 
2937   my $form     = $main::form;
 
2938   my $locale   = $main::locale;
 
2940   $main::auth->assert('config');
 
2942   $form->{title} =  $locale->text('Add');
 
2944   $form->{callback} ||= "am.pl?action=add_tax";
 
2946   _get_taxaccount_selection();
 
2950   my $parameters_ref = {
 
2951 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
2954   # Ausgabe des Templates
 
2955   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
2957   $main::lxdebug->leave_sub();
 
2961   $main::lxdebug->enter_sub();
 
2963   my $form     = $main::form;
 
2964   my %myconfig = %main::myconfig;
 
2965   my $locale   = $main::locale;
 
2967   $main::auth->assert('config');
 
2969   $form->{title} =  $locale->text('Edit');
 
2971   AM->get_tax(\%myconfig, \%$form);
 
2972   _get_taxaccount_selection();
 
2974   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
2978   my $parameters_ref = {
 
2981   # Ausgabe des Templates
 
2982   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
2984   $main::lxdebug->leave_sub();
 
2988   $main::lxdebug->enter_sub();
 
2990   my $form     = $main::form;
 
2991   my %myconfig = %main::myconfig;
 
2992   my $locale   = $main::locale;
 
2994   $main::auth->assert('config');
 
2996   AM->taxes(\%myconfig, \%$form);
 
2998   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
3000   $form->{callback} = build_std_url('action=list_tax');
 
3002   $form->{title} = $locale->text('Tax-O-Matic');
 
3006   my $parameters_ref = {
 
3009   # Ausgabe des Templates
 
3010   print($form->parse_html_template('am/list_tax', $parameters_ref));
 
3012   $main::lxdebug->leave_sub();
 
3015 sub _get_taxaccount_selection{
 
3016   $main::lxdebug->enter_sub();
 
3018   my $form     = $main::form;
 
3019   my %myconfig = %main::myconfig;
 
3021   $main::auth->assert('config');
 
3023   AM->get_tax_accounts(\%myconfig, \%$form);
 
3025   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
3027   $main::lxdebug->leave_sub();
 
3031   $main::lxdebug->enter_sub();
 
3033   my $form     = $main::form;
 
3034   my %myconfig = %main::myconfig;
 
3035   my $locale   = $main::locale;
 
3037   $main::auth->assert('config');
 
3039   $form->isblank("rate", $locale->text('Taxrate missing!'));
 
3040   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
 
3041   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
 
3043   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
3045   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
3046     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
3049   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
3050     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
3053   AM->save_tax(\%myconfig, \%$form);
 
3054   $form->redirect($locale->text('Tax saved!'));
 
3056   $main::lxdebug->leave_sub();
 
3060   $main::lxdebug->enter_sub();
 
3062   my $form     = $main::form;
 
3063   my %myconfig = %main::myconfig;
 
3064   my $locale   = $main::locale;
 
3066   $main::auth->assert('config');
 
3068   AM->delete_tax(\%myconfig, \%$form);
 
3069   $form->redirect($locale->text('Tax deleted!'));
 
3071   $main::lxdebug->leave_sub();
 
3074 sub add_price_factor {
 
3075   $main::lxdebug->enter_sub();
 
3077   my $form     = $main::form;
 
3078   my $locale   = $main::locale;
 
3080   $main::auth->assert('config');
 
3082   $form->{title}      = $locale->text('Add Price Factor');
 
3083   $form->{callback} ||= build_std_url('action=add_price_factor');
 
3084   $form->{fokus}      = 'description';
 
3087   print $form->parse_html_template('am/edit_price_factor');
 
3089   $main::lxdebug->leave_sub();
 
3092 sub edit_price_factor {
 
3093   $main::lxdebug->enter_sub();
 
3095   my $form     = $main::form;
 
3096   my %myconfig = %main::myconfig;
 
3097   my $locale   = $main::locale;
 
3099   $main::auth->assert('config');
 
3101   $form->{title}      = $locale->text('Edit Price Factor');
 
3102   $form->{callback} ||= build_std_url('action=add_price_factor');
 
3103   $form->{fokus}      = 'description';
 
3105   AM->get_price_factor(\%myconfig, $form);
 
3107   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
 
3110   print $form->parse_html_template('am/edit_price_factor');
 
3112   $main::lxdebug->leave_sub();
 
3115 sub list_price_factors {
 
3116   $main::lxdebug->enter_sub();
 
3118   my $form     = $main::form;
 
3119   my %myconfig = %main::myconfig;
 
3120   my $locale   = $main::locale;
 
3122   $main::auth->assert('config');
 
3124   AM->get_all_price_factors(\%myconfig, \%$form);
 
3126   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
 
3127     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
 
3130   $form->{callback} = build_std_url('action=list_price_factors');
 
3131   $form->{title}    = $locale->text('Price Factors');
 
3132   $form->{url_base} = build_std_url('callback');
 
3135   print $form->parse_html_template('am/list_price_factors');
 
3137   $main::lxdebug->leave_sub();
 
3140 sub save_price_factor {
 
3141   $main::lxdebug->enter_sub();
 
3143   my $form     = $main::form;
 
3144   my %myconfig = %main::myconfig;
 
3145   my $locale   = $main::locale;
 
3147   $main::auth->assert('config');
 
3149   $form->isblank("description", $locale->text('Description missing!'));
 
3150   $form->isblank("factor", $locale->text('Factor missing!'));
 
3152   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
 
3154   AM->save_price_factor(\%myconfig, $form);
 
3156   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
 
3158   $form->redirect($locale->text('Price factor saved!'));
 
3160   $main::lxdebug->leave_sub();
 
3163 sub delete_price_factor {
 
3164   $main::lxdebug->enter_sub();
 
3166   my $form     = $main::form;
 
3167   my %myconfig = %main::myconfig;
 
3168   my $locale   = $main::locale;
 
3170   $main::auth->assert('config');
 
3172   AM->delete_price_factor(\%myconfig, \%$form);
 
3174   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
 
3176   $form->redirect($locale->text('Price factor deleted!'));
 
3178   $main::lxdebug->leave_sub();
 
3182   $main::lxdebug->enter_sub();
 
3184   my $form     = $main::form;
 
3185   my $locale   = $main::locale;
 
3187   $main::auth->assert('config');
 
3189   $form->{title}      = $locale->text('Add Warehouse');
 
3190   $form->{callback} ||= build_std_url('action=add_warehouse');
 
3191   $form->{fokus}      = 'description';
 
3194   print $form->parse_html_template('am/edit_warehouse');
 
3196   $main::lxdebug->leave_sub();
 
3199 sub edit_warehouse {
 
3200   $main::lxdebug->enter_sub();
 
3202   my $form     = $main::form;
 
3203   my %myconfig = %main::myconfig;
 
3204   my $locale   = $main::locale;
 
3206   $main::auth->assert('config');
 
3208   AM->get_warehouse(\%myconfig, $form);
 
3210   $form->get_lists('employees' => 'EMPLOYEES');
 
3212   $form->{title}      = $locale->text('Edit Warehouse');
 
3213   $form->{callback} ||= build_std_url('action=list_warehouses');
 
3214   $form->{fokus}      = 'description';
 
3217   print $form->parse_html_template('am/edit_warehouse');
 
3219   $main::lxdebug->leave_sub();
 
3222 sub list_warehouses {
 
3223   $main::lxdebug->enter_sub();
 
3225   my $form     = $main::form;
 
3226   my %myconfig = %main::myconfig;
 
3227   my $locale   = $main::locale;
 
3229   $main::auth->assert('config');
 
3231   AM->get_all_warehouses(\%myconfig, $form);
 
3233   $form->{callback} = build_std_url('action=list_warehouses');
 
3234   $form->{title}    = $locale->text('Warehouses');
 
3235   $form->{url_base} = build_std_url('callback');
 
3238   print $form->parse_html_template('am/list_warehouses');
 
3240   $main::lxdebug->leave_sub();
 
3243 sub save_warehouse {
 
3244   $main::lxdebug->enter_sub();
 
3246   my $form     = $main::form;
 
3247   my %myconfig = %main::myconfig;
 
3248   my $locale   = $main::locale;
 
3250   $main::auth->assert('config');
 
3252   $form->isblank("description", $locale->text('Description missing!'));
 
3254   $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
 
3256   AM->save_warehouse(\%myconfig, $form);
 
3258   $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
 
3260   $form->redirect($locale->text('Warehouse saved.'));
 
3262   $main::lxdebug->leave_sub();
 
3265 sub delete_warehouse {
 
3266   $main::lxdebug->enter_sub();
 
3268   my $form     = $main::form;
 
3269   my %myconfig = %main::myconfig;
 
3270   my $locale   = $main::locale;
 
3272   $main::auth->assert('config');
 
3274   if (!$form->{confirmed}) {
 
3275     $form->{title} = $locale->text('Confirmation');
 
3278     print $form->parse_html_template('am/confirm_delete_warehouse');
 
3282   if (AM->delete_warehouse(\%myconfig, $form)) {
 
3283     $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
 
3284     $form->redirect($locale->text('Warehouse deleted.'));
 
3287     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
 
3290   $main::lxdebug->leave_sub();
 
3294   $main::lxdebug->enter_sub();
 
3296   my $form     = $main::form;
 
3297   my %myconfig = %main::myconfig;
 
3298   my $locale   = $main::locale;
 
3300   $main::auth->assert('config');
 
3302   AM->save_bins(\%myconfig, $form);
 
3304   $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
 
3306   $form->redirect($locale->text('Bins saved.'));
 
3308   $main::lxdebug->leave_sub();