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., 51 Franklin Street, Fifth Floor, Boston,
 
  29 #======================================================================
 
  33 #======================================================================
 
  37 use List::MoreUtils qw(any);
 
  40 use SL::Auth::PasswordPolicy;
 
  44 use SL::Helper::Flash;
 
  45 use SL::Helper::UserPreferences;
 
  49 use SL::Locale::String qw(t8);
 
  55 use SL::DBUtils qw(selectall_array_query conv_dateq);
 
  58 require "bin/mozilla/common.pl";
 
  66 sub add      { call_sub("add_$main::form->{type}"); }
 
  67 sub delete   { call_sub("delete_$main::form->{type}"); }
 
  68 sub save     { call_sub("save_$main::form->{type}"); }
 
  69 sub edit     { call_sub("edit_$main::form->{type}"); }
 
  70 sub continue { call_sub($main::form->{"nextsub"}); }
 
  71 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
  74   $main::lxdebug->enter_sub();
 
  76   my $form     = $main::form;
 
  77   my %myconfig = %main::myconfig;
 
  79   $main::auth->assert('config');
 
  81   $form->{title}     = "Add";
 
  82   $form->{charttype} = "A";
 
  83   AM->get_account(\%myconfig, \%$form);
 
  85   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
 
  89   $main::lxdebug->leave_sub();
 
  93   $main::lxdebug->enter_sub();
 
  95   my $form     = $main::form;
 
  96   my %myconfig = %main::myconfig;
 
  97   my $defaults = SL::DB::Default->get;
 
  99   $main::auth->assert('config');
 
 101   $form->{title} = "Edit";
 
 102   $form->{feature_balance} = $defaults->feature_balance;
 
 103   $form->{feature_datev} = $defaults->feature_datev;
 
 104   $form->{feature_erfolgsrechnung} = $defaults->feature_erfolgsrechnung;
 
 105   $form->{feature_eurechnung} = $defaults->feature_eurechnung;
 
 106   $form->{feature_ustva} = $defaults->feature_ustva;
 
 108   AM->get_account(\%myconfig, \%$form);
 
 110   foreach my $item (split(/:/, $form->{link})) {
 
 111     $form->{$item} = "checked";
 
 116   $main::lxdebug->leave_sub();
 
 120   $main::lxdebug->enter_sub();
 
 122   my $form     = $main::form;
 
 123   my %myconfig = %main::myconfig;
 
 124   my $locale   = $main::locale;
 
 126   $main::auth->assert('config');
 
 128   if ( $form->{action} eq 'edit_account') {
 
 129     $form->{account_exists} = '1';
 
 132   $form->{title} = $locale->text("$form->{title} Account");
 
 134   $form->{"$form->{charttype}_checked"} = "checked";
 
 135   $form->{"$form->{category}_checked"}  = "checked";
 
 137   $form->{select_tax} = "";
 
 139   my @tax_report_pos = USTVA->report_variables({
 
 140       myconfig   => \%myconfig,
 
 143       attribute  => 'position',
 
 147   if (@{ $form->{TAXKEY} }) {
 
 148     foreach my $item (@{ $form->{TAXKEY} }) {
 
 149       $item->{rate} = $item->{rate} * 100 . '%';
 
 152     # Fill in empty row for new Taxkey
 
 153     my $newtaxkey_ref = {
 
 158       taxdescription => '',
 
 162       startdate      => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
 
 165     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 168     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 170       # Fill in a runningnumber
 
 171       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 173       # Fill in the Taxkeys as select options
 
 174       foreach my $item (@{ $form->{TAXKEY} }) {
 
 175         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 176           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 177             qq|<option value="$item->{id}" selected="selected">|
 
 178             . sprintf("%.2d", $item->{taxkey})
 
 179             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 180             . $locale->text('Tax-o-matic Account')
 
 181             . qq|: $item->{chart_accno}\n|;
 
 184           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 185             qq|<option value="$item->{id}">|
 
 186             . sprintf("%.2d", $item->{taxkey})
 
 187             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 188             . $locale->text('Tax-o-matic Account')
 
 189             . qq|: $item->{chart_accno}\n|;
 
 194       # Fill in the USTVA Numbers as select options
 
 195       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 197           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 199         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 200           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 203           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 212   # Newaccount Folgekonto
 
 213   if (@{ $form->{NEWACCOUNT} || [] }) {
 
 214     if (!$form->{new_chart_valid}) {
 
 215       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 217     foreach my $item (@{ $form->{NEWACCOUNT} }) {
 
 218       if ($item->{id} == $form->{new_chart_id}) {
 
 219         $form->{selectnewaccount} .=
 
 220           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 221       } elsif (!$form->{new_chart_valid}) {
 
 222         $form->{selectnewaccount} .=
 
 223           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 229   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 230   my %eur = %{ AM->get_eur_categories(\%myconfig, $form) };
 
 231   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
 
 232     my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
 
 233     if ($item == $form->{pos_eur}) {
 
 234       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 236       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 241   my $select_er = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 245   foreach my $item (sort({ $a <=> $b } keys(%er))) {
 
 246     my $text = H($::locale->{iconv_utf8}->convert($er{$item}));
 
 247     if ($item == $form->{pos_er}) {
 
 248       $select_er .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 250       $select_er .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 255   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 257   my %bwapos = %{ AM->get_bwa_categories(\%myconfig, $form) };
 
 258   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
 
 259     my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
 
 260     if ($item == $form->{pos_bwa}) {
 
 261       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 263       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 268 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 269   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 270   foreach my $item ((1, 2, 3, 4)) {
 
 271     if ($item == $form->{pos_bilanz}) {
 
 272       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 274       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 279   # this is for our parser only! Do not remove.
 
 280   # type=submit $locale->text('Add Account')
 
 281   # type=submit $locale->text('Edit Account')
 
 283   $form->{type} = "account";
 
 285   # preselections category
 
 287   my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 290       'A'  => $locale->text('Asset'),
 
 291       'L'  => $locale->text('Liability'),
 
 292       'Q'  => $locale->text('Equity'),
 
 293       'I'  => $locale->text('Revenue'),
 
 294       'E'  => $locale->text('Expense'),
 
 295       'C'  => $locale->text('Costs'),
 
 297   foreach my $item ( sort({ $a <=> $b } keys %category) ) {
 
 298     if ($item eq $form->{category}) {
 
 299       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 301       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 306   # preselection chart type
 
 307   my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
 
 308                         {'name' => $locale->text('Heading'), 'value' => 'H'},
 
 310   my $selected_charttype = $form->{charttype};
 
 313   # account where AR_tax or AP_tax is set are not orphaned if they are used as
 
 314   # tax-o-matic account
 
 315   if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
 
 316     if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
 
 317       $form->{orphaned} = 0;
 
 321   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 322   my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
 
 324   setup_am_edit_account_action_bar();
 
 328   my $parameters_ref = {
 
 329     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 330     AccountIsPosted            => $AccountIsPosted,
 
 331     select_category            => $select_category,
 
 332     all_charttypes             => \@all_charttypes,
 
 333     selected_charttype         => $selected_charttype,
 
 334     select_bwa                 => $select_bwa,
 
 335     select_bilanz              => $select_bilanz,
 
 336     select_eur                 => $select_eur,
 
 337     select_er                  => $select_er,
 
 340   # Ausgabe des Templates
 
 341   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 344   $main::lxdebug->leave_sub();
 
 348   $main::lxdebug->enter_sub();
 
 350   my $form     = $main::form;
 
 351   my %myconfig = %main::myconfig;
 
 352   my $locale   = $main::locale;
 
 354   $main::auth->assert('config');
 
 356   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 357   $form->isblank("description", $locale->text('Account Description missing!'));
 
 359   if ($form->{charttype} eq 'A'){
 
 360     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 362     my $found_valid_taxkey = 0;
 
 363     foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
 
 364       if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
 
 365         $found_valid_taxkey = 1;
 
 369     if ($found_valid_taxkey == 0) {
 
 370       $form->error($locale->text('A valid taxkey is missing!'));
 
 374   $form->redirect($locale->text('Account saved!'))
 
 375     if (AM->save_account(\%myconfig, \%$form));
 
 376   $form->error($locale->text('Cannot save account!'));
 
 378   $main::lxdebug->leave_sub();
 
 381 sub save_as_new_account {
 
 382   $main::lxdebug->enter_sub();
 
 384   my $form     = $main::form;
 
 385   my %myconfig = %main::myconfig;
 
 386   my $locale   = $main::locale;
 
 388   $main::auth->assert('config');
 
 390   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 391   $form->isblank("description", $locale->text('Account Description missing!'));
 
 393   if ($form->{charttype} eq 'A'){
 
 394     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 397   for my $taxkey (0 .. 9) {
 
 398     if ($form->{"taxkey_id_$taxkey"}) {
 
 399       $form->{"taxkey_id_$taxkey"} = "NEW";
 
 404   $form->redirect($locale->text('Account saved!'))
 
 405     if (AM->save_account(\%myconfig, \%$form));
 
 406   $form->error($locale->text('Cannot save account!'));
 
 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->{callback}     = build_std_url('action=list_account');
 
 421   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 423   CA->all_accounts(\%myconfig, \%$form);
 
 425   foreach my $ca (@{ $form->{CA} }) {
 
 430     if ($ca->{amount} > 0) {
 
 431       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 433     if ($ca->{amount} < 0) {
 
 434       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 436     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:'';
 
 437     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 440   $::request->{layout}->use_stylesheet("list_accounts.css");
 
 441   $form->{title}       = $locale->text('Chart of Accounts');
 
 446   my $parameters_ref = {
 
 447   #   hidden_variables                => $_hidden_variables_ref,
 
 450   # Ausgabe des Templates
 
 451   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
 453   $main::lxdebug->leave_sub();
 
 458 sub list_account_details {
 
 459 # Ajax Funktion aus list_account_details
 
 460   $main::lxdebug->enter_sub();
 
 462   my $form     = $main::form;
 
 463   my %myconfig = %main::myconfig;
 
 464   my $locale   = $main::locale;
 
 466   $main::auth->assert('config');
 
 468   my $chart_id = $form->{args};
 
 470   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 472   foreach my $ca (@{ $form->{CA} }) {
 
 474     $ca->{debit}  = " ";
 
 475     $ca->{credit} = " ";
 
 477     if ($ca->{amount} > 0) {
 
 479         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 481     if ($ca->{amount} < 0) {
 
 483         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 486     my @links = split( q{:}, $ca->{link});
 
 490     foreach my $link (@links){
 
 491       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 492                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 493                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 494                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 495                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 496                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 497                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 498                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 499                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 500                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 501                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 502                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 503                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 504                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 505                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 506                : $locale->text('Unknown Link') . ': ' . $link;
 
 507       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 510     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 511                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 512                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 513                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 514                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 515                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 516                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 517                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 520   $form->{title} = $locale->text('Chart of Accounts');
 
 522   print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
 
 524   $main::lxdebug->leave_sub();
 
 529   $main::lxdebug->enter_sub();
 
 531   my $form     = $main::form;
 
 532   my %myconfig = %main::myconfig;
 
 533   my $locale   = $main::locale;
 
 535   $main::auth->assert('config');
 
 537   $form->{title} = $locale->text('Delete Account');
 
 540     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id rndgain_accno_id rndloss_accno_id)
 
 542     if ($form->{id} == $form->{$id}) {
 
 543       $form->error($locale->text('Cannot delete default account!'));
 
 547   $form->redirect($locale->text('Account deleted!'))
 
 548     if (AM->delete_account(\%myconfig, \%$form));
 
 549   $form->error($locale->text('Cannot delete account!'));
 
 551   $main::lxdebug->leave_sub();
 
 554 sub _build_cfg_options {
 
 555   my $form     = $main::form;
 
 556   my %myconfig = %main::myconfig;
 
 559   my $array = uc($idx) . 'S';
 
 561   $form->{$array} = [];
 
 562   foreach my $item (@_) {
 
 563     push @{ $form->{$array} }, {
 
 566       'selected' => $item eq $myconfig{$idx},
 
 572   $main::lxdebug->enter_sub();
 
 574   my $form     = $main::form;
 
 575   my %myconfig = %main::myconfig;
 
 576   my $locale   = $main::locale;
 
 577   my $defaults = SL::DB::Default->get;
 
 579   _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
 580   _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
 
 581   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00"));
 
 584   if ($::lx_office_conf{print_templates}->{opendocument}
 
 585       && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
 
 586       && $::lx_office_conf{applications}->{xvfb}                 && (-x $::lx_office_conf{applications}->{xvfb})) {
 
 587     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
 588                      "value" => "opendocument_pdf" });
 
 590   if ($::lx_office_conf{print_templates}->{latex}) {
 
 591     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
 593   push(@formats, { "name" => "HTML", "value" => "html" });
 
 594   if ($::lx_office_conf{print_templates}->{latex}) {
 
 595     push(@formats, { "name" => $locale->text("Postscript"),
 
 596                      "value" => "postscript" });
 
 598   if ($::lx_office_conf{print_templates}->{opendocument}) {
 
 599     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
 600                      "value" => "opendocument" });
 
 603   if (!$myconfig{"template_format"}) {
 
 604     $myconfig{"template_format"} = "pdf";
 
 606   $form->{TEMPLATE_FORMATS} = [];
 
 607   foreach my $item (@formats) {
 
 608     push @{ $form->{TEMPLATE_FORMATS} }, {
 
 609       'name'     => $item->{name},
 
 610       'value'    => $item->{value},
 
 611       'selected' => $item->{value} eq $myconfig{template_format},
 
 615   if (!$myconfig{"default_media"}) {
 
 616     $myconfig{"default_media"} = "screen";
 
 619   my %selected = ($myconfig{"default_media"} => "selected");
 
 621     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
 622     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
 623     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
 626   $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
 
 628   my %countrycodes = User->country_codes;
 
 630   $form->{COUNTRYCODES} = [];
 
 631   foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
 632     push @{ $form->{COUNTRYCODES} }, {
 
 633       'name'     => $countrycodes{$countrycode},
 
 634       'value'    => $countrycode,
 
 635       'selected' => $countrycode eq $myconfig{countrycode},
 
 639   $form->{STYLESHEETS} = [];
 
 640   foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
 
 641     push @{ $form->{STYLESHEETS} }, {
 
 644       'selected' => $item eq $myconfig{stylesheet},
 
 648   my $user_prefs = SL::Helper::UserPreferences->new(
 
 649     namespace         => 'TopQuickSearch',
 
 652   my @quick_search_modules;
 
 654     $prefs_val            = $user_prefs->get('quick_search_modules');
 
 655     @quick_search_modules = split ',', $prefs_val;
 
 658   my $enabled_quick_search = [ SL::Controller::TopQuickSearch->new->available_modules ];
 
 659   $form->{enabled_quick_searchmodules} = \@{$enabled_quick_search};
 
 660   $form->{default_quick_searchmodules} = \@quick_search_modules;
 
 662   $form->{displayable_name_specs_by_module}       = AM->displayable_name_specs_by_module();
 
 663   $form->{positions_scrollbar_height}             = AM->positions_scrollbar_height();
 
 664   $form->{purchase_search_makemodel}              = AM->purchase_search_makemodel();
 
 665   $form->{sales_search_customer_partnumber}       = AM->sales_search_customer_partnumber();
 
 666   $form->{positions_show_update_button}           = AM->positions_show_update_button();
 
 667   $form->{time_recording_use_duration}            = AM->time_recording_use_duration();
 
 668   $form->{longdescription_dialog_size_percentage} = AM->longdescription_dialog_size_percentage();
 
 670   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
 
 671   $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
 672   $form->{todo_cfg}            = { TODO->get_user_config('login' => $::myconfig{login}) };
 
 673   $form->{title}               = $locale->text('Edit Preferences for #1', $::myconfig{login});
 
 675   $::request->{layout}->use_javascript("${_}.js") for qw(jquery.multiselect2side ckeditor/ckeditor ckeditor/adapters/jquery);
 
 677   setup_am_config_action_bar();
 
 680   $form->{company_signature} = SL::DB::Default->get->signature;
 
 682   print $form->parse_html_template('am/config');
 
 684   $main::lxdebug->leave_sub();
 
 687 sub save_preferences {
 
 688   $main::lxdebug->enter_sub();
 
 690   my $form     = $main::form;
 
 691   my %myconfig = %main::myconfig;
 
 692   my $locale   = $main::locale;
 
 694   $form->{stylesheet} = $form->{usestylesheet};
 
 696   TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
 
 698   if ($form->{quick_search_modules}) {
 
 699     my $user_prefs = SL::Helper::UserPreferences->new( namespace => 'TopQuickSearch',);
 
 700     my $quick_search_modules = join ',', @{$form->{quick_search_modules}};
 
 701     $user_prefs->store('quick_search_modules', $quick_search_modules);
 
 703   if (AM->save_preferences($form)) {
 
 704     if ($::auth->can_change_password()
 
 705         && defined $form->{new_password}
 
 706         && ($form->{new_password} ne '********')) {
 
 707       my $verifier = SL::Auth::PasswordPolicy->new;
 
 708       my $result   = $verifier->verify($form->{new_password});
 
 710       if ($result != SL::Auth::PasswordPolicy->OK()) {
 
 711         $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
 
 714       $::auth->change_password($::myconfig{login}, $form->{new_password});
 
 717     $form->redirect($locale->text('Preferences saved!'));
 
 720   $form->error($locale->text('Cannot save preferences!'));
 
 722   $main::lxdebug->leave_sub();
 
 726   $::lxdebug->enter_sub;
 
 727   $::auth->assert('config');
 
 729   $::form->{title} = $::locale->text('Audit Control');
 
 731   AM->closedto(\%::myconfig, $::form);
 
 733   setup_am_audit_control_action_bar();
 
 736   print $::form->parse_html_template('am/audit_control');
 
 738   $::lxdebug->leave_sub;
 
 742   $main::lxdebug->enter_sub();
 
 744   my $form     = $main::form;
 
 745   my %myconfig = %main::myconfig;
 
 746   my $locale   = $main::locale;
 
 748   $main::auth->assert('config');
 
 750   AM->closebooks(\%myconfig, \%$form);
 
 752   if ($form->{closedto}) {
 
 754                     $locale->text('Books closed up to') . " "
 
 755                       . $locale->date(\%myconfig, $form->{closedto}, 1));
 
 757     $form->redirect($locale->text('Books are open'));
 
 760   $main::lxdebug->leave_sub();
 
 764   $::auth->assert('config');
 
 766   # my $units = AM->retrieve_units(\%::myconfig, $::form, "resolved_");
 
 767   # # AM->units_in_use(\%::myconfig, $::form, $units);
 
 769   # $units->{$_}->{BASE_UNIT_DDBOX} = AM->unit_select_data($units, $units->{$_}->{base_unit}, 1) for keys %{$units};
 
 771   my @languages = @{ SL::DB::Manager::Language->get_all_sorted };
 
 773   my $units = AM->retrieve_units(\%::myconfig, $::form);
 
 774   my $ddbox = AM->unit_select_data($units, undef, 1);
 
 776   setup_am_add_unit_action_bar();
 
 778   $::form->{title} = $::locale->text("Add unit");
 
 780   print($::form->parse_html_template("am/add_unit", {
 
 781     NEW_BASE_UNIT_DDBOX => $ddbox,
 
 782     LANGUAGES           => \@languages,
 
 787   $main::lxdebug->enter_sub();
 
 789   my $form     = $main::form;
 
 790   my %myconfig = %main::myconfig;
 
 791   my $locale   = $main::locale;
 
 793   $main::auth->assert('config');
 
 795   my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
 796   AM->units_in_use(\%myconfig, $form, $units);
 
 797   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
 799   my @languages = @{ SL::DB::Manager::Language->get_all_sorted };
 
 801   my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
 804   foreach (@unit_list) {
 
 805     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
 806     $_->{"UNITLANGUAGES"} = [];
 
 807     foreach my $lang (@languages) {
 
 808       push(@{ $_->{"UNITLANGUAGES"} },
 
 810              "unit"             => $_->{"name"},
 
 811              "language_id"      => $lang->id,
 
 812              "localized"        => $_->{"LANGUAGES"}->{$lang->template_code}->{"localized"},
 
 813              "localized_plural" => $_->{"LANGUAGES"}->{$lang->template_code}->{"localized_plural"},
 
 819   $units = AM->retrieve_units(\%myconfig, $form);
 
 820   my $ddbox = AM->unit_select_data($units, undef, 1);
 
 822   setup_am_edit_units_action_bar();
 
 824   $form->{"title"} = $locale->text("Edit units");
 
 826   print($form->parse_html_template("am/edit_units",
 
 827                                    { "UNITS"               => \@unit_list,
 
 828                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
 829                                      "LANGUAGES"           => \@languages,
 
 832   $main::lxdebug->leave_sub();
 
 836   $main::lxdebug->enter_sub();
 
 838   my $form     = $main::form;
 
 839   my %myconfig = %main::myconfig;
 
 840   my $locale   = $main::locale;
 
 842   $main::auth->assert('config');
 
 844   $form->isblank("new_name", $locale->text("The name is missing."));
 
 845   my $units = AM->retrieve_units(\%myconfig, $form);
 
 846   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
 847   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
 849   my ($base_unit, $factor);
 
 850   if ($form->{"new_base_unit"}) {
 
 851     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
 853     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
 854     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
 855     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
 856     $base_unit = $form->{"new_base_unit"};
 
 860   foreach my $lang (@{ SL::DB::Manager::Language->get_all_sorted }) {
 
 861     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
 862     push(@languages, { "id"               => $lang->id,
 
 863                        "localized"        => $form->{"new_localized_" . $lang->id},
 
 864                        "localized_plural" => $form->{"new_localized_plural_" . $lang->id},
 
 868   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
 870   flash_later('info', $locale->text("The unit has been added."));
 
 872   print $form->redirect_header('am.pl?action=edit_units');
 
 874   $main::lxdebug->leave_sub();
 
 877 sub set_unit_languages {
 
 878   $main::lxdebug->enter_sub();
 
 880   my $form     = $main::form;
 
 882   $main::auth->assert('config');
 
 884   my ($unit, $languages, $idx) = @_;
 
 886   $unit->{"LANGUAGES"} = [];
 
 888   foreach my $lang (@{$languages}) {
 
 889     push(@{ $unit->{"LANGUAGES"} },
 
 891            "localized"        => $form->{"localized_${idx}_" . $lang->id},
 
 892            "localized_plural" => $form->{"localized_plural_${idx}_" . $lang->id},
 
 896   $main::lxdebug->leave_sub();
 
 900   $main::lxdebug->enter_sub();
 
 902   my $form     = $main::form;
 
 903   my %myconfig = %main::myconfig;
 
 904   my $locale   = $main::locale;
 
 906   $main::auth->assert('config');
 
 908   my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
 909   AM->units_in_use(\%myconfig, $form, $old_units);
 
 911   my @languages = @{ SL::DB::Manager::Language->get_all_sorted };
 
 914   my @delete_units = ();
 
 915   foreach my $i (1..($form->{"rowcount"} * 1)) {
 
 916     my $old_unit = $old_units->{$form->{"old_name_$i"}};
 
 918       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
 921     if ($form->{"unchangeable_$i"}) {
 
 922       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
 923       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
 924       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
 928     if ($old_unit->{"in_use"}) {
 
 929       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
 932     if ($form->{"delete_$i"}) {
 
 933       push(@delete_units, $old_unit->{"name"});
 
 937     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
 939     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
 940     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
 941     $new_units->{$form->{"name_$i"}} = \%h;
 
 942     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
 943     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
 946   foreach my $unit (values(%{$new_units})) {
 
 947     next unless ($unit->{"old_name"});
 
 948     if ($unit->{"base_unit"}) {
 
 949       $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"}))
 
 950         unless (defined($new_units->{$unit->{"base_unit"}}));
 
 951       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
 952       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
 954       $unit->{"base_unit"} = undef;
 
 955       $unit->{"factor"} = undef;
 
 959   foreach my $unit (values(%{$new_units})) {
 
 960     next if ($unit->{"unchanged_unit"});
 
 962     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
 963     my $new_unit = $unit;
 
 964     while ($new_unit->{"base_unit"}) {
 
 965       $new_unit->{"seen"} = 1;
 
 966       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
 967       if ($new_unit->{"seen"}) {
 
 968         $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, " .
 
 969                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
 974   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
 976   flash_later('info', $locale->text("The units have been saved."));
 
 978   print $form->redirect_header('am.pl?action=edit_units');
 
 980   $main::lxdebug->leave_sub();
 
 983 sub show_history_search {
 
 984   $main::lxdebug->enter_sub();
 
 986   my $form     = $main::form;
 
 987   my $locale   = $main::locale;
 
 989   $main::auth->assert('config');
 
 991   setup_am_show_history_search_action_bar();
 
 993   $form->{title} = $locale->text("History Search");
 
 996   print $form->parse_html_template("common/search_history");
 
 998   $main::lxdebug->leave_sub();
 
1001 sub show_am_history {
 
1002   $main::lxdebug->enter_sub();
 
1004   my $form     = $main::form;
 
1005   my %myconfig = %main::myconfig;
 
1006   my $locale   = $main::locale;
 
1008   $main::auth->assert('config');
 
1010   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
 
1011   $form->{order} ||= 'h.itime--1';
 
1013   # my %search = ( "Artikelnummer"          => "parts",
 
1014   #                "Kundennummer"           => "customer",
 
1015   #                "Lieferantennummer"      => "vendor",
 
1016   #                "Projektnummer"          => "project",
 
1017   #                "Auftragsnummer"         => "oe",
 
1018   #                "Angebotsnummer"         => "oe",
 
1019   #                "Eingangsrechnungnummer" => "ap",
 
1020   #                "Ausgangsrechnungnummer" => "ar",
 
1021   #                "Mahnungsnummer"         => "dunning",
 
1022   #                "Buchungsnummer"         => "gl",
 
1025   my %searchNo = ( "Artikelnummer"          => "partnumber",
 
1026                    "Kundennummer"           => "customernumber",
 
1027                    "Lieferantennummer"      => "vendornumber",
 
1028                    "Projektnummer"          => "projectnumber",
 
1029                    "Auftragsnummer"         => "ordnumber",
 
1030                    "Angebotsnummer"         => "quonumber",
 
1031                    "Eingangsrechnungnummer" => "invnumber",
 
1032                    "Ausgangsrechnungnummer" => "invnumber",
 
1033                    "Mahnungsnummer"         => "dunning_id",
 
1034                    "Buchungsnummer"         => "gltransaction"
 
1037   my $dbh = $form->dbconnect(\%myconfig);
 
1040   $restriction     = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
 
1041   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
 
1042   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
 
1043   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
1044     $restriction  .= qq| AND employee_id = |    . $form->{mitarbeiter};
 
1045   } elsif ($form->{mitarbeiter}) {
 
1046     $restriction  .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
 
1049   my $snumbers_where = '';
 
1051   if ($form->{'searchid'}) {
 
1052     $snumbers_where = ' WHERE snumbers = ?';
 
1053     $snumbers_value = $searchNo{$form->{'what2search'}} . '_' . $form->{'searchid'};
 
1055     $snumbers_where = ' WHERE snumbers ~ ?';
 
1056     $snumbers_value = '^' . $searchNo{$form->{'what2search'}};
 
1058   my $query = qq|SELECT trans_id AS id FROM history_erp $snumbers_where|;
 
1060   my @ids    = grep { $_ * 1 } selectall_array_query($form, $dbh, $query, $snumbers_value);
 
1061   my $daten .= shift @ids;
 
1062   if (scalar(@ids) > 0 ) {
 
1063     $daten  .= ' OR trans_id IN (' . join(',', @ids) . ')';
 
1065   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
1066   $sort =~ s/.*\.(.*)$/$1/;
 
1068   setup_am_show_am_history_action_bar();
 
1070   $form->{title} = $locale->text("History Search");
 
1073   print $form->parse_html_template("common/show_history",
 
1074                                    { "DATEN"          => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
1075                                      "SUCCESS"        => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
1078                                      uc($sort) . "BY" => $sortby,
 
1079                                      'callback'       => $callback,
 
1083   $main::lxdebug->leave_sub();
 
1087   $main::lxdebug->enter_sub();
 
1089   my $form     = $main::form;
 
1090   my $locale   = $main::locale;
 
1092   $main::auth->assert('config');
 
1094   $form->{title} =  $locale->text('Add');
 
1096   $form->{callback} ||= "am.pl?action=add_tax";
 
1098   _get_taxaccount_selection();
 
1101   $form->{liability}  = 1;
 
1102   $form->{equity}     = 1;
 
1103   $form->{revenue}    = 1;
 
1104   $form->{expense}    = 1;
 
1107   setup_am_edit_tax_action_bar();
 
1110   my $parameters_ref = {
 
1111     LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
 
1114   # Ausgabe des Templates
 
1115   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
1117   $main::lxdebug->leave_sub();
 
1121   $main::lxdebug->enter_sub();
 
1123   my $form     = $main::form;
 
1124   my %myconfig = %main::myconfig;
 
1125   my $locale   = $main::locale;
 
1127   $main::auth->assert('config');
 
1129   $form->{title} =  $locale->text('Edit');
 
1131   AM->get_tax(\%myconfig, \%$form);
 
1133   _get_taxaccount_selection();
 
1135   $form->{asset}      = $form->{chart_categories} =~ 'A' ? 1 : 0;
 
1136   $form->{liability}  = $form->{chart_categories} =~ 'L' ? 1 : 0;
 
1137   $form->{equity}     = $form->{chart_categories} =~ 'Q' ? 1 : 0;
 
1138   $form->{revenue}    = $form->{chart_categories} =~ 'I' ? 1 : 0;
 
1139   $form->{expense}    = $form->{chart_categories} =~ 'E' ? 1 : 0;
 
1140   $form->{costs}      = $form->{chart_categories} =~ 'C' ? 1 : 0;
 
1142   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
1144   setup_am_edit_tax_action_bar();
 
1147   my $parameters_ref = {
 
1148     LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
 
1149     TAX       => SL::DB::Manager::Tax->find_by(id => $form->{id}),
 
1152   # Ausgabe des Templates
 
1153   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
1155   $main::lxdebug->leave_sub();
 
1159   $main::lxdebug->enter_sub();
 
1161   my $form     = $main::form;
 
1162   my %myconfig = %main::myconfig;
 
1163   my $locale   = $main::locale;
 
1165   $main::auth->assert('config');
 
1167   AM->taxes(\%myconfig, \%$form);
 
1169   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
1171   $form->{callback} = build_std_url('action=list_tax');
 
1173   $form->{title} = $locale->text('Tax-O-Matic');
 
1175   setup_am_list_tax_action_bar();
 
1178   # Ausgabe des Templates
 
1179   print($form->parse_html_template('am/list_tax'));
 
1181   $main::lxdebug->leave_sub();
 
1184 sub _get_taxaccount_selection{
 
1185   $main::lxdebug->enter_sub();
 
1187   my $form     = $main::form;
 
1188   my %myconfig = %main::myconfig;
 
1190   $main::auth->assert('config');
 
1192   AM->get_tax_accounts(\%myconfig, \%$form);
 
1194   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
1196   $main::lxdebug->leave_sub();
 
1200   $main::lxdebug->enter_sub();
 
1202   my $form     = $main::form;
 
1203   my %myconfig = %main::myconfig;
 
1204   my $locale   = $main::locale;
 
1206   $main::auth->assert('config');
 
1208   $form->error($locale->text('Taxkey  missing!')) unless length($form->{taxkey}) != 0;
 
1209   $form->error($locale->text('Taxdescription  missing!')) unless length($form->{taxdescription}) != 0;
 
1210   $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
 
1212   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
1214   if ($form->{taxkey} == 0 and $form->{rate} > 0) {
 
1215     $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
 
1218   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
1219     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
1222   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
1223     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
1226   my @translation_keys  =  grep { $_ =~ '^translation_\d+' } keys %$form;
 
1227   $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
 
1229   AM->save_tax(\%myconfig, \%$form);
 
1230   flash_later('info', $locale->text("Tax saved!"));
 
1232   print $form->redirect_header('am.pl?action=list_tax');
 
1234   $main::lxdebug->leave_sub();
 
1238   $main::lxdebug->enter_sub();
 
1240   my $form     = $main::form;
 
1241   my %myconfig = %main::myconfig;
 
1242   my $locale   = $main::locale;
 
1244   $main::auth->assert('config');
 
1246   AM->delete_tax(\%myconfig, \%$form);
 
1247   $form->redirect($locale->text('Tax deleted!'));
 
1249   $main::lxdebug->leave_sub();
 
1253   $main::lxdebug->enter_sub();
 
1255   my $form     = $main::form;
 
1256   my $locale   = $main::locale;
 
1258   $main::auth->assert('config');
 
1260   $form->{title}      = $locale->text('Add Warehouse');
 
1261   $form->{callback} ||= build_std_url('action=add_warehouse');
 
1263   setup_am_edit_warehouse_action_bar();
 
1266   print $form->parse_html_template('am/edit_warehouse');
 
1268   $main::lxdebug->leave_sub();
 
1271 sub edit_warehouse {
 
1272   $main::lxdebug->enter_sub();
 
1274   my $form     = $main::form;
 
1275   my %myconfig = %main::myconfig;
 
1276   my $locale   = $main::locale;
 
1278   $main::auth->assert('config');
 
1280   AM->get_warehouse(\%myconfig, $form);
 
1282   $form->get_lists('employees' => 'EMPLOYEES');
 
1284   $form->{title}      = $locale->text('Edit Warehouse');
 
1285   $form->{callback} ||= build_std_url('action=list_warehouses');
 
1287   setup_am_edit_warehouse_action_bar(id => $::form->{id}, in_use => any { $_->{in_use} } @{ $::form->{BINS} });
 
1290   print $form->parse_html_template('am/edit_warehouse');
 
1292   $main::lxdebug->leave_sub();
 
1296   $::auth->assert('config');
 
1298   AM->get_warehouse(\%::myconfig, $::form);
 
1300   $::form->{title}      = $::locale->text('Edit Bins for Warehouse \'#1\'', $::form->{description});
 
1301   $::form->{callback} ||= build_std_url('action=list_warehouses');
 
1303   setup_am_edit_bins_action_bar(id => $::form->{id});
 
1306   print $::form->parse_html_template('am/edit_bins');
 
1309 sub list_warehouses {
 
1310   $main::lxdebug->enter_sub();
 
1312   my $form     = $main::form;
 
1313   my %myconfig = %main::myconfig;
 
1314   my $locale   = $main::locale;
 
1316   $main::auth->assert('config');
 
1318   AM->get_all_warehouses(\%myconfig, $form);
 
1320   $form->{callback} = build_std_url('action=list_warehouses');
 
1321   $form->{title}    = $locale->text('Warehouses');
 
1322   $form->{url_base} = build_std_url('callback');
 
1324   setup_am_list_warehouses_action_bar();
 
1327   print $form->parse_html_template('am/list_warehouses');
 
1329   $main::lxdebug->leave_sub();
 
1332 sub save_warehouse {
 
1333   $main::lxdebug->enter_sub();
 
1335   my $form     = $main::form;
 
1336   my %myconfig = %main::myconfig;
 
1337   my $locale   = $main::locale;
 
1339   $main::auth->assert('config');
 
1341   $form->isblank("description", $locale->text('Description missing!'));
 
1342   $form->isblank("number_of_new_bins", $locale->text('Number')  . $locale->text(' missing!'));
 
1344   $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
 
1346   AM->save_warehouse(\%myconfig, $form);
 
1348   $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
 
1350   $form->redirect($locale->text('Warehouse saved.'));
 
1352   $main::lxdebug->leave_sub();
 
1355 sub delete_warehouse {
 
1356   $main::lxdebug->enter_sub();
 
1358   my $form     = $main::form;
 
1359   my %myconfig = %main::myconfig;
 
1360   my $locale   = $main::locale;
 
1362   $main::auth->assert('config');
 
1364   if (AM->delete_warehouse(\%myconfig, $form)) {
 
1365     $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
 
1366     $form->redirect($locale->text('Warehouse deleted.'));
 
1369     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
 
1372   $main::lxdebug->leave_sub();
 
1376   $main::lxdebug->enter_sub();
 
1378   my $form     = $main::form;
 
1379   my %myconfig = %main::myconfig;
 
1380   my $locale   = $main::locale;
 
1382   $main::auth->assert('config');
 
1384   AM->save_bins(\%myconfig, $form);
 
1386   $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
 
1388   $form->redirect($locale->text('Bins saved.'));
 
1390   $main::lxdebug->leave_sub();
 
1393 sub setup_am_config_action_bar {
 
1396   for my $bar ($::request->layout->get('actionbar')) {
 
1400         submit    => [ '#form', { action => "save_preferences" } ],
 
1401         accesskey => 'enter',
 
1407 sub setup_am_edit_account_action_bar {
 
1410   for my $bar ($::request->layout->get('actionbar')) {
 
1415           submit    => [ '#form', { action => "save_account" } ],
 
1416           accesskey => 'enter',
 
1421           submit   => [ '#form', { action => "save_as_new_account" } ],
 
1422           disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
 
1428         submit   => [ '#form', { action => "delete_account" } ],
 
1429         disabled => !$::form->{id}                         ? t8('The object has not been saved yet.')
 
1430                   :  $::form->{id} && !$::form->{orphaned} ? t8('The object is in use and cannot be deleted.')
 
1432         confirm  => t8('Do you really want to delete this object?'),
 
1438 sub setup_am_list_tax_action_bar {
 
1441   for my $bar ($::request->layout->get('actionbar')) {
 
1445         link => 'am.pl?action=add_tax',
 
1451 sub setup_am_edit_tax_action_bar {
 
1454   for my $bar ($::request->layout->get('actionbar')) {
 
1458         submit    => [ '#form', { action => "save_tax" } ],
 
1459         accesskey => 'enter',
 
1464         submit   => [ '#form', { action => "delete_tax" } ],
 
1465         disabled => !$::form->{id}                                      ? t8('The object has not been saved yet.')
 
1466                   : !$::form->{orphaned} || $::form->{tax_already_used} ? t8('The object is in use and cannot be deleted.')
 
1468         confirm  => t8('Do you really want to delete this object?'),
 
1474 sub setup_am_add_unit_action_bar {
 
1477   for my $bar ($::request->layout->get('actionbar')) {
 
1481         submit    => [ '#form', { action => "create_unit" } ],
 
1482         accesskey => 'enter',
 
1489         link => 'am.pl?action=edit_units',
 
1495 sub setup_am_edit_units_action_bar {
 
1498   for my $bar ($::request->layout->get('actionbar')) {
 
1502         submit    => [ '#form', { action => "save_unit" } ],
 
1503         accesskey => 'enter',
 
1510         link => 'am.pl?action=add_unit',
 
1516 sub setup_am_list_warehouses_action_bar {
 
1519   for my $bar ($::request->layout->get('actionbar')) {
 
1523         link      => 'am.pl?action=add&type=warehouse&callback=' . E($::form->{callback}),
 
1524         accesskey => 'enter',
 
1530 sub setup_am_edit_warehouse_action_bar {
 
1533   for my $bar ($::request->layout->get('actionbar')) {
 
1537         submit    => [ '#form', { action => 'save_warehouse' } ],
 
1538         accesskey => 'enter',
 
1543         submit   => [ '#form', { action => 'delete_warehouse' } ],
 
1544         disabled => !$params{id}    ? t8('The object has not been saved yet.')
 
1545                   : $params{in_use} ? t8('The object is in use and cannot be deleted.')
 
1547         confirm  => t8('Do you really want to delete this object?'),
 
1554         link    => 'am.pl?action=edit_bins&id=' . E($params{id}),
 
1555         only_if => $params{id},
 
1560         link => $::form->{callback} || 'am.pl?action=list_warehouses',
 
1566 sub setup_am_edit_bins_action_bar {
 
1569   for my $bar ($::request->layout->get('actionbar')) {
 
1573         submit    => [ '#form', { action => 'save_bin' } ],
 
1574         accesskey => 'enter',
 
1581         link => 'am.pl?action=edit_warehouse&id=' . E($params{id}),
 
1587 sub setup_am_audit_control_action_bar {
 
1590   for my $bar ($::request->layout->get('actionbar')) {
 
1594         submit    => [ '#form', { action => 'doclose' } ],
 
1595         accesskey => 'enter',
 
1601 sub setup_am_show_history_search_action_bar {
 
1604   for my $bar ($::request->layout->get('actionbar')) {
 
1608         submit    => [ '#form' ],
 
1609         accesskey => 'enter',
 
1615 sub setup_am_show_am_history_action_bar {
 
1618   for my $bar ($::request->layout->get('actionbar')) {
 
1622         call => [ 'kivi.history_back' ],