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 #======================================================================
 
  38 use SL::Auth::PasswordPolicy;
 
  50 use SL::DBUtils qw(selectall_array_query conv_dateq);
 
  53 require "bin/mozilla/common.pl";
 
  61 sub add      { call_sub("add_$main::form->{type}"); }
 
  62 sub delete   { call_sub("delete_$main::form->{type}"); }
 
  63 sub save     { call_sub("save_$main::form->{type}"); }
 
  64 sub edit     { call_sub("edit_$main::form->{type}"); }
 
  65 sub continue { call_sub($main::form->{"nextsub"}); }
 
  66 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
  69   $main::lxdebug->enter_sub();
 
  71   my $form     = $main::form;
 
  72   my %myconfig = %main::myconfig;
 
  74   $main::auth->assert('config');
 
  76   $form->{title}     = "Add";
 
  77   $form->{charttype} = "A";
 
  78   AM->get_account(\%myconfig, \%$form);
 
  80   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
 
  85   $main::lxdebug->leave_sub();
 
  89   $main::lxdebug->enter_sub();
 
  91   my $form     = $main::form;
 
  92   my %myconfig = %main::myconfig;
 
  93   my $defaults = SL::DB::Default->get;
 
  95   $main::auth->assert('config');
 
  97   $form->{title} = "Edit";
 
  98   $form->{feature_balance} = $defaults->feature_balance;
 
  99   $form->{feature_datev} = $defaults->feature_datev;
 
 100   $form->{feature_erfolgsrechnung} = $defaults->feature_erfolgsrechnung;
 
 101   $form->{feature_eurechnung} = $defaults->feature_eurechnung;
 
 102   $form->{feature_ustva} = $defaults->feature_ustva;
 
 104   AM->get_account(\%myconfig, \%$form);
 
 106   foreach my $item (split(/:/, $form->{link})) {
 
 107     $form->{$item} = "checked";
 
 113   $main::lxdebug->leave_sub();
 
 117   $main::lxdebug->enter_sub();
 
 119   my $form     = $main::form;
 
 120   my %myconfig = %main::myconfig;
 
 121   my $locale   = $main::locale;
 
 123   $main::auth->assert('config');
 
 125   if ( $form->{action} eq 'edit_account') {
 
 126     $form->{account_exists} = '1';
 
 129   $form->{title} = $locale->text("$form->{title} Account");
 
 131   $form->{"$form->{charttype}_checked"} = "checked";
 
 132   $form->{"$form->{category}_checked"}  = "checked";
 
 134   $form->{select_tax} = "";
 
 136   my @tax_report_pos = USTVA->report_variables({
 
 137       myconfig   => \%myconfig,
 
 140       attribute  => 'position',
 
 144   if (@{ $form->{TAXKEY} }) {
 
 145     foreach my $item (@{ $form->{TAXKEY} }) {
 
 146       $item->{rate} = $item->{rate} * 100 . '%';
 
 149     # Fill in empty row for new Taxkey
 
 150     my $newtaxkey_ref = {
 
 155       taxdescription => '',
 
 159       startdate      => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
 
 162     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 165     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 167       # Fill in a runningnumber
 
 168       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 170       # Fill in the Taxkeys as select options
 
 171       foreach my $item (@{ $form->{TAXKEY} }) {
 
 172         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 173           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 174             qq|<option value="$item->{id}" selected="selected">|
 
 175             . sprintf("%.2d", $item->{taxkey})
 
 176             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 177             . $locale->text('Tax-o-matic Account')
 
 178             . qq|: $item->{chart_accno}\n|;
 
 181           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 182             qq|<option value="$item->{id}">|
 
 183             . sprintf("%.2d", $item->{taxkey})
 
 184             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 185             . $locale->text('Tax-o-matic Account')
 
 186             . qq|: $item->{chart_accno}\n|;
 
 191       # Fill in the USTVA Numbers as select options
 
 192       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 194           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 196         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 197           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 200           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 209   # Newaccount Folgekonto
 
 210   if (@{ $form->{NEWACCOUNT} || [] }) {
 
 211     if (!$form->{new_chart_valid}) {
 
 212       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 214     foreach my $item (@{ $form->{NEWACCOUNT} }) {
 
 215       if ($item->{id} == $form->{new_chart_id}) {
 
 216         $form->{selectnewaccount} .=
 
 217           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 218       } elsif (!$form->{new_chart_valid}) {
 
 219         $form->{selectnewaccount} .=
 
 220           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 226   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 229           2  => "sonstige Erlöse",
 
 230           3  => "Privatanteile",
 
 232           5  => "Ausserordentliche Erträge",
 
 233           6  => "Vereinnahmte Umsatzst.",
 
 234           7  => "Umsatzsteuererstattungen",
 
 235           8  => "Wareneingänge",
 
 236           9  => "Löhne und Gehälter",
 
 237           10 => "Gesetzl. sozialer Aufw.",
 
 239           12 => "Gas, Strom, Wasser",
 
 240           13 => "Instandhaltung",
 
 241           14 => "Steuern, Versich., Beiträge",
 
 243           16 => "Kfz-Versicherungen",
 
 244           17 => "Sonst. Fahrzeugkosten",
 
 245           18 => "Werbe- und Reisekosten",
 
 246           19 => "Instandhaltung u. Werkzeuge",
 
 247           20 => "Fachzeitschriften, Bücher",
 
 248           21 => "Miete für Einrichtungen",
 
 249           22 => "Rechts- und Beratungskosten",
 
 250           23 => "Bürobedarf, Porto, Telefon",
 
 251           24 => "Sonstige Aufwendungen",
 
 252           25 => "Abschreibungen auf Anlagever.",
 
 253           26 => "Abschreibungen auf GWG",
 
 255           28 => "Umsatzsteuerzahlungen",
 
 257           30 => "Ausserordentlicher Aufwand",
 
 258           31 => "Betriebliche Steuern");
 
 259   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
 
 260     my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
 
 261     if ($item == $form->{pos_eur}) {
 
 262       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 264       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 269   my $select_er = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 273   foreach my $item (sort({ $a <=> $b } keys(%er))) {
 
 274     my $text = H($::locale->{iconv_utf8}->convert($er{$item}));
 
 275     if ($item == $form->{pos_er}) {
 
 276       $select_er .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 278       $select_er .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 283   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 287              2  => 'Best.Verdg.FE/UE',
 
 288              3  => 'Aktiv.Eigenleistung',
 
 289              4  => 'Mat./Wareneinkauf',
 
 290              5  => 'So.betr.Erlöse',
 
 291              10 => 'Personalkosten',
 
 293              12 => 'Betriebl.Steuern',
 
 294              13 => 'Vers./Beiträge',
 
 295              14 => 'Kfz.Kosten o.St.',
 
 296              15 => 'Werbe-Reisek.',
 
 297              16 => 'Kosten Warenabgabe',
 
 298              17 => 'Abschreibungen',
 
 299              18 => 'Rep./instandhlt.',
 
 300              19 => 'Übrige Steuern',
 
 301              20 => 'Sonst.Kosten',
 
 303              31 => 'Sonst.neutr.Aufw.',
 
 305              33 => 'Sonst.neutr.Ertrag',
 
 306              34 => 'Verr.kalk.Kosten',
 
 307              35 => 'Steuern Eink.u.Ertr.');
 
 308   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
 
 309     my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
 
 310     if ($item == $form->{pos_bwa}) {
 
 311       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 313       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 318 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 319   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 320   foreach my $item ((1, 2, 3, 4)) {
 
 321     if ($item == $form->{pos_bilanz}) {
 
 322       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 324       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 329   # this is for our parser only! Do not remove.
 
 330   # type=submit $locale->text('Add Account')
 
 331   # type=submit $locale->text('Edit Account')
 
 333   $form->{type} = "account";
 
 335   # preselections category
 
 337   my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 340       'A'  => $locale->text('Asset'),
 
 341       'L'  => $locale->text('Liability'),
 
 342       'Q'  => $locale->text('Equity'),
 
 343       'I'  => $locale->text('Revenue'),
 
 344       'E'  => $locale->text('Expense'),
 
 345       'C'  => $locale->text('Costs'),
 
 347   foreach my $item ( sort({ $a <=> $b } keys %category) ) {
 
 348     if ($item eq $form->{category}) {
 
 349       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 351       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 356   # preselection chart type
 
 357   my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
 
 358                         {'name' => $locale->text('Heading'), 'value' => 'H'},
 
 360   my $selected_charttype = $form->{charttype};
 
 363   # account where AR_tax or AP_tax is set are not orphaned if they are used as
 
 364   # tax-o-matic account
 
 365   if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
 
 366     if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
 
 367       $form->{orphaned} = 0;
 
 371   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 372   my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
 
 376   my $parameters_ref = {
 
 377     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 378     AccountIsPosted            => $AccountIsPosted,
 
 379     select_category            => $select_category,
 
 380     all_charttypes             => \@all_charttypes,
 
 381     selected_charttype         => $selected_charttype,
 
 382     select_bwa                 => $select_bwa,
 
 383     select_bilanz              => $select_bilanz,
 
 384     select_eur                 => $select_eur,
 
 385     select_er                  => $select_er,
 
 388   # Ausgabe des Templates
 
 389   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 392   $main::lxdebug->leave_sub();
 
 396   $::lxdebug->enter_sub;
 
 397   $::auth->assert('config');
 
 399   print $::form->parse_html_template('am/form_footer', {
 
 400     show_save        => !$::form->{id}
 
 401                      || ($::form->{id} && $::form->{orphaned})
 
 402                      || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
 
 403     show_delete      => $::form->{id} && $::form->{orphaned},
 
 404     show_save_as_new => $::form->{id} && $::form->{type} eq "account",
 
 407   $::lxdebug->leave_sub;
 
 411   $main::lxdebug->enter_sub();
 
 413   my $form     = $main::form;
 
 414   my %myconfig = %main::myconfig;
 
 415   my $locale   = $main::locale;
 
 417   $main::auth->assert('config');
 
 419   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 420   $form->isblank("description", $locale->text('Account Description missing!'));
 
 422   if ($form->{charttype} eq 'A'){
 
 423     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 425     my $found_valid_taxkey = 0;
 
 426     foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
 
 427       if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
 
 428         $found_valid_taxkey = 1;
 
 432     if ($found_valid_taxkey == 0) {
 
 433       $form->error($locale->text('A valid taxkey is missing!'));
 
 437   $form->redirect($locale->text('Account saved!'))
 
 438     if (AM->save_account(\%myconfig, \%$form));
 
 439   $form->error($locale->text('Cannot save account!'));
 
 441   $main::lxdebug->leave_sub();
 
 444 sub save_as_new_account {
 
 445   $main::lxdebug->enter_sub();
 
 447   my $form     = $main::form;
 
 448   my %myconfig = %main::myconfig;
 
 449   my $locale   = $main::locale;
 
 451   $main::auth->assert('config');
 
 453   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 454   $form->isblank("description", $locale->text('Account Description missing!'));
 
 456   if ($form->{charttype} eq 'A'){
 
 457     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 460   for my $taxkey (0 .. 9) {
 
 461     if ($form->{"taxkey_id_$taxkey"}) {
 
 462       $form->{"taxkey_id_$taxkey"} = "NEW";
 
 467   $form->redirect($locale->text('Account saved!'))
 
 468     if (AM->save_account(\%myconfig, \%$form));
 
 469   $form->error($locale->text('Cannot save account!'));
 
 471   $main::lxdebug->leave_sub();
 
 475   $main::lxdebug->enter_sub();
 
 477   my $form     = $main::form;
 
 478   my %myconfig = %main::myconfig;
 
 479   my $locale   = $main::locale;
 
 481   $main::auth->assert('config');
 
 483   $form->{callback}     = build_std_url('action=list_account');
 
 484   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 486   CA->all_accounts(\%myconfig, \%$form);
 
 488   foreach my $ca (@{ $form->{CA} }) {
 
 493     if ($ca->{amount} > 0) {
 
 494       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 496     if ($ca->{amount} < 0) {
 
 497       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 499     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:'';
 
 500     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 503   $::request->{layout}->use_stylesheet("list_accounts.css");
 
 504   $form->{title}       = $locale->text('Chart of Accounts');
 
 509   my $parameters_ref = {
 
 510   #   hidden_variables                => $_hidden_variables_ref,
 
 513   # Ausgabe des Templates
 
 514   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
 516   $main::lxdebug->leave_sub();
 
 521 sub list_account_details {
 
 522 # Ajax Funktion aus list_account_details
 
 523   $main::lxdebug->enter_sub();
 
 525   my $form     = $main::form;
 
 526   my %myconfig = %main::myconfig;
 
 527   my $locale   = $main::locale;
 
 529   $main::auth->assert('config');
 
 531   my $chart_id = $form->{args};
 
 533   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 535   foreach my $ca (@{ $form->{CA} }) {
 
 537     $ca->{debit}  = " ";
 
 538     $ca->{credit} = " ";
 
 540     if ($ca->{amount} > 0) {
 
 542         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 544     if ($ca->{amount} < 0) {
 
 546         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 549     my @links = split( q{:}, $ca->{link});
 
 553     foreach my $link (@links){
 
 554       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 555                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 556                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 557                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 558                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 559                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 560                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 561                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 562                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 563                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 564                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 565                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 566                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 567                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 568                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 569                : $locale->text('Unknown Link') . ': ' . $link;
 
 570       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 573     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 574                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 575                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 576                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 577                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 578                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 579                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 580                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 583   $form->{title} = $locale->text('Chart of Accounts');
 
 585   print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
 
 587   $main::lxdebug->leave_sub();
 
 592   $main::lxdebug->enter_sub();
 
 594   my $form     = $main::form;
 
 595   my %myconfig = %main::myconfig;
 
 596   my $locale   = $main::locale;
 
 598   $main::auth->assert('config');
 
 600   $form->{title} = $locale->text('Delete Account');
 
 603     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id rndgain_accno_id rndloss_accno_id)
 
 605     if ($form->{id} == $form->{$id}) {
 
 606       $form->error($locale->text('Cannot delete default account!'));
 
 610   $form->redirect($locale->text('Account deleted!'))
 
 611     if (AM->delete_account(\%myconfig, \%$form));
 
 612   $form->error($locale->text('Cannot delete account!'));
 
 614   $main::lxdebug->leave_sub();
 
 617 sub _build_cfg_options {
 
 618   my $form     = $main::form;
 
 619   my %myconfig = %main::myconfig;
 
 622   my $array = uc($idx) . 'S';
 
 624   $form->{$array} = [];
 
 625   foreach my $item (@_) {
 
 626     push @{ $form->{$array} }, {
 
 629       'selected' => $item eq $myconfig{$idx},
 
 635   $main::lxdebug->enter_sub();
 
 637   my $form     = $main::form;
 
 638   my %myconfig = %main::myconfig;
 
 639   my $locale   = $main::locale;
 
 641   _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
 642   _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
 
 643   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00"));
 
 646   if ($::lx_office_conf{print_templates}->{opendocument}
 
 647       && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
 
 648       && $::lx_office_conf{applications}->{xvfb}                 && (-x $::lx_office_conf{applications}->{xvfb})) {
 
 649     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
 650                      "value" => "opendocument_pdf" });
 
 652   if ($::lx_office_conf{print_templates}->{latex}) {
 
 653     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
 655   push(@formats, { "name" => "HTML", "value" => "html" });
 
 656   if ($::lx_office_conf{print_templates}->{latex}) {
 
 657     push(@formats, { "name" => $locale->text("Postscript"),
 
 658                      "value" => "postscript" });
 
 660   if ($::lx_office_conf{print_templates}->{opendocument}) {
 
 661     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
 662                      "value" => "opendocument" });
 
 665   if (!$myconfig{"template_format"}) {
 
 666     $myconfig{"template_format"} = "pdf";
 
 668   $form->{TEMPLATE_FORMATS} = [];
 
 669   foreach my $item (@formats) {
 
 670     push @{ $form->{TEMPLATE_FORMATS} }, {
 
 671       'name'     => $item->{name},
 
 672       'value'    => $item->{value},
 
 673       'selected' => $item->{value} eq $myconfig{template_format},
 
 677   if (!$myconfig{"default_media"}) {
 
 678     $myconfig{"default_media"} = "screen";
 
 681   my %selected = ($myconfig{"default_media"} => "selected");
 
 683     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
 684     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
 685     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
 688   $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
 
 690   my %countrycodes = User->country_codes;
 
 692   $form->{COUNTRYCODES} = [];
 
 693   foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
 694     push @{ $form->{COUNTRYCODES} }, {
 
 695       'name'     => $countrycodes{$countrycode},
 
 696       'value'    => $countrycode,
 
 697       'selected' => $countrycode eq $myconfig{countrycode},
 
 701   $form->{STYLESHEETS} = [];
 
 702   foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
 
 703     push @{ $form->{STYLESHEETS} }, {
 
 706       'selected' => $item eq $myconfig{stylesheet},
 
 710   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
 
 711   $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
 712   $form->{todo_cfg}            = { TODO->get_user_config('login' => $::myconfig{login}) };
 
 714   $form->{title}               = $locale->text('Edit Preferences for #1', $::myconfig{login});
 
 718   $form->{full_signature} = $form->create_email_signature();
 
 720   print $form->parse_html_template('am/config');
 
 722   $main::lxdebug->leave_sub();
 
 725 sub save_preferences {
 
 726   $main::lxdebug->enter_sub();
 
 728   my $form     = $main::form;
 
 729   my %myconfig = %main::myconfig;
 
 730   my $locale   = $main::locale;
 
 732   $form->{stylesheet} = $form->{usestylesheet};
 
 734   TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
 
 736   if (AM->save_preferences($form)) {
 
 737     if ($::auth->can_change_password()
 
 738         && defined $form->{new_password}
 
 739         && ($form->{new_password} ne '********')) {
 
 740       my $verifier = SL::Auth::PasswordPolicy->new;
 
 741       my $result   = $verifier->verify($form->{new_password});
 
 743       if ($result != SL::Auth::PasswordPolicy->OK()) {
 
 744         $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
 
 747       $::auth->change_password($::myconfig{login}, $form->{new_password});
 
 750     $form->redirect($locale->text('Preferences saved!'));
 
 753   $form->error($locale->text('Cannot save preferences!'));
 
 755   $main::lxdebug->leave_sub();
 
 759   $::lxdebug->enter_sub;
 
 760   $::auth->assert('config');
 
 762   $::form->{title} = $::locale->text('Audit Control');
 
 764   AM->closedto(\%::myconfig, $::form);
 
 767   print $::form->parse_html_template('am/audit_control');
 
 769   $::lxdebug->leave_sub;
 
 773   $main::lxdebug->enter_sub();
 
 775   my $form     = $main::form;
 
 776   my %myconfig = %main::myconfig;
 
 777   my $locale   = $main::locale;
 
 779   $main::auth->assert('config');
 
 781   AM->closebooks(\%myconfig, \%$form);
 
 783   if ($form->{closedto}) {
 
 785                     $locale->text('Books closed up to') . " "
 
 786                       . $locale->date(\%myconfig, $form->{closedto}, 1));
 
 788     $form->redirect($locale->text('Books are open'));
 
 791   $main::lxdebug->leave_sub();
 
 795   $main::lxdebug->enter_sub();
 
 797   my $form     = $main::form;
 
 798   my %myconfig = %main::myconfig;
 
 799   my $locale   = $main::locale;
 
 801   $main::auth->assert('config');
 
 803   my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
 804   AM->units_in_use(\%myconfig, $form, $units);
 
 805   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
 807   my @languages = AM->language(\%myconfig, $form, 1);
 
 809   my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
 812   foreach (@unit_list) {
 
 813     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
 814     $_->{"UNITLANGUAGES"} = [];
 
 815     foreach my $lang (@languages) {
 
 816       push(@{ $_->{"UNITLANGUAGES"} },
 
 818              "unit" => $_->{"name"},
 
 819              "language_id" => $lang->{"id"},
 
 820              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
 821              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
 827   $units = AM->retrieve_units(\%myconfig, $form);
 
 828   my $ddbox = AM->unit_select_data($units, undef, 1);
 
 830   $form->{"title"} = $locale->text("Add and edit units");
 
 832   print($form->parse_html_template("am/edit_units",
 
 833                                    { "UNITS"               => \@unit_list,
 
 834                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
 835                                      "LANGUAGES"           => \@languages,
 
 838   $main::lxdebug->leave_sub();
 
 842   $main::lxdebug->enter_sub();
 
 844   my $form     = $main::form;
 
 845   my %myconfig = %main::myconfig;
 
 846   my $locale   = $main::locale;
 
 848   $main::auth->assert('config');
 
 850   $form->isblank("new_name", $locale->text("The name is missing."));
 
 851   my $units = AM->retrieve_units(\%myconfig, $form);
 
 852   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
 853   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
 855   my ($base_unit, $factor);
 
 856   if ($form->{"new_base_unit"}) {
 
 857     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
 859     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
 860     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
 861     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
 862     $base_unit = $form->{"new_base_unit"};
 
 866   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
 867     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
 868     push(@languages, { "id" => $lang->{"id"},
 
 869                        "localized" => $form->{"new_localized_$lang->{id}"},
 
 870                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
 874   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
 876   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
 880   $main::lxdebug->leave_sub();
 
 883 sub set_unit_languages {
 
 884   $main::lxdebug->enter_sub();
 
 886   my $form     = $main::form;
 
 888   $main::auth->assert('config');
 
 890   my ($unit, $languages, $idx) = @_;
 
 892   $unit->{"LANGUAGES"} = [];
 
 894   foreach my $lang (@{$languages}) {
 
 895     push(@{ $unit->{"LANGUAGES"} },
 
 896          { "id" => $lang->{"id"},
 
 897            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
 898            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
 902   $main::lxdebug->leave_sub();
 
 906   $main::lxdebug->enter_sub();
 
 908   my $form     = $main::form;
 
 909   my %myconfig = %main::myconfig;
 
 910   my $locale   = $main::locale;
 
 912   $main::auth->assert('config');
 
 914   my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
 915   AM->units_in_use(\%myconfig, $form, $old_units);
 
 917   my @languages = AM->language(\%myconfig, $form, 1);
 
 920   my @delete_units = ();
 
 921   foreach my $i (1..($form->{"rowcount"} * 1)) {
 
 922     my $old_unit = $old_units->{$form->{"old_name_$i"}};
 
 924       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
 927     if ($form->{"unchangeable_$i"}) {
 
 928       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
 929       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
 930       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
 934     if ($old_unit->{"in_use"}) {
 
 935       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
 938     if ($form->{"delete_$i"}) {
 
 939       push(@delete_units, $old_unit->{"name"});
 
 943     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
 945     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
 946     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
 947     $new_units->{$form->{"name_$i"}} = \%h;
 
 948     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
 949     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
 952   foreach my $unit (values(%{$new_units})) {
 
 953     next unless ($unit->{"old_name"});
 
 954     if ($unit->{"base_unit"}) {
 
 955       $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"}))
 
 956         unless (defined($new_units->{$unit->{"base_unit"}}));
 
 957       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
 958       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
 960       $unit->{"base_unit"} = undef;
 
 961       $unit->{"factor"} = undef;
 
 965   foreach my $unit (values(%{$new_units})) {
 
 966     next if ($unit->{"unchanged_unit"});
 
 968     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
 969     my $new_unit = $unit;
 
 970     while ($new_unit->{"base_unit"}) {
 
 971       $new_unit->{"seen"} = 1;
 
 972       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
 973       if ($new_unit->{"seen"}) {
 
 974         $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, " .
 
 975                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
 980   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
 982   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
 986   $main::lxdebug->leave_sub();
 
 989 sub show_history_search {
 
 990   $main::lxdebug->enter_sub();
 
 992   my $form     = $main::form;
 
 993   my $locale   = $main::locale;
 
 995   $main::auth->assert('config');
 
 997   $form->{title} = $locale->text("History Search");
 
1000   print $form->parse_html_template("common/search_history");
 
1002   $main::lxdebug->leave_sub();
 
1005 sub show_am_history {
 
1006   $main::lxdebug->enter_sub();
 
1008   my $form     = $main::form;
 
1009   my %myconfig = %main::myconfig;
 
1010   my $locale   = $main::locale;
 
1012   $main::auth->assert('config');
 
1014   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
 
1015   $form->{order} ||= 'h.itime--1';
 
1017   # my %search = ( "Artikelnummer"          => "parts",
 
1018   #                "Kundennummer"           => "customer",
 
1019   #                "Lieferantennummer"      => "vendor",
 
1020   #                "Projektnummer"          => "project",
 
1021   #                "Auftragsnummer"         => "oe",
 
1022   #                "Angebotsnummer"         => "oe",
 
1023   #                "Eingangsrechnungnummer" => "ap",
 
1024   #                "Ausgangsrechnungnummer" => "ar",
 
1025   #                "Mahnungsnummer"         => "dunning",
 
1026   #                "Buchungsnummer"         => "gl",
 
1029   my %searchNo = ( "Artikelnummer"          => "partnumber",
 
1030                    "Kundennummer"           => "customernumber",
 
1031                    "Lieferantennummer"      => "vendornumber",
 
1032                    "Projektnummer"          => "projectnumber",
 
1033                    "Auftragsnummer"         => "ordnumber",
 
1034                    "Angebotsnummer"         => "quonumber",
 
1035                    "Eingangsrechnungnummer" => "invnumber",
 
1036                    "Ausgangsrechnungnummer" => "invnumber",
 
1037                    "Mahnungsnummer"         => "dunning_id",
 
1038                    "Buchungsnummer"         => "gltransaction"
 
1041   my $dbh = $form->dbconnect(\%myconfig);
 
1044   $restriction     = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
 
1045   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
 
1046   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
 
1047   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
1048     $restriction  .= qq| AND employee_id = |    . $form->{mitarbeiter};
 
1049   } elsif ($form->{mitarbeiter}) {
 
1050     $restriction  .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
 
1053   my $snumbers_where = '';
 
1055   if ($form->{'searchid'}) {
 
1056     $snumbers_where = ' WHERE snumbers = ?';
 
1057     $snumbers_value = $searchNo{$form->{'what2search'}} . '_' . $form->{'searchid'};
 
1059     $snumbers_where = ' WHERE snumbers ~ ?';
 
1060     $snumbers_value = '^' . $searchNo{$form->{'what2search'}};
 
1062   my $query = qq|SELECT trans_id AS id FROM history_erp $snumbers_where|;
 
1064   my @ids    = grep { $_ * 1 } selectall_array_query($form, $dbh, $query, $snumbers_value);
 
1065   my $daten .= shift @ids;
 
1066   if (scalar(@ids) > 0 ) {
 
1067     $daten  .= ' OR trans_id IN (' . join(',', @ids) . ')';
 
1069   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
1070   $sort =~ s/.*\.(.*)$/$1/;
 
1072   $form->{title} = $locale->text("History Search");
 
1075   print $form->parse_html_template("common/show_history",
 
1076                                    { "DATEN"          => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
1077                                      "SUCCESS"        => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
1080                                      uc($sort) . "BY" => $sortby,
 
1081                                      'callback'       => $callback,
 
1085   $main::lxdebug->leave_sub();
 
1089   $main::lxdebug->enter_sub();
 
1091   my $form     = $main::form;
 
1092   my $locale   = $main::locale;
 
1094   $main::auth->assert('config');
 
1096   $form->{title} =  $locale->text('Add');
 
1098   $form->{callback} ||= "am.pl?action=add_tax";
 
1100   _get_taxaccount_selection();
 
1103   $form->{liability}  = 1;
 
1104   $form->{equity}     = 1;
 
1105   $form->{revenue}    = 1;
 
1106   $form->{expense}    = 1;
 
1111   my $parameters_ref = {
 
1112 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
1113     LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
 
1116   # Ausgabe des Templates
 
1117   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
1119   $main::lxdebug->leave_sub();
 
1123   $main::lxdebug->enter_sub();
 
1125   my $form     = $main::form;
 
1126   my %myconfig = %main::myconfig;
 
1127   my $locale   = $main::locale;
 
1129   $main::auth->assert('config');
 
1131   $form->{title} =  $locale->text('Edit');
 
1133   AM->get_tax(\%myconfig, \%$form);
 
1135   _get_taxaccount_selection();
 
1137   $form->{asset}      = $form->{chart_categories} =~ 'A' ? 1 : 0;
 
1138   $form->{liability}  = $form->{chart_categories} =~ 'L' ? 1 : 0;
 
1139   $form->{equity}     = $form->{chart_categories} =~ 'Q' ? 1 : 0;
 
1140   $form->{revenue}    = $form->{chart_categories} =~ 'I' ? 1 : 0;
 
1141   $form->{expense}    = $form->{chart_categories} =~ 'E' ? 1 : 0;
 
1142   $form->{costs}      = $form->{chart_categories} =~ 'C' ? 1 : 0;
 
1144   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
1148   my $parameters_ref = {
 
1149     LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
 
1150     TAX       => SL::DB::Manager::Tax->find_by(id => $form->{id}),
 
1153   # Ausgabe des Templates
 
1154   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
1156   $main::lxdebug->leave_sub();
 
1160   $main::lxdebug->enter_sub();
 
1162   my $form     = $main::form;
 
1163   my %myconfig = %main::myconfig;
 
1164   my $locale   = $main::locale;
 
1166   $main::auth->assert('config');
 
1168   AM->taxes(\%myconfig, \%$form);
 
1170   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
1172   $form->{callback} = build_std_url('action=list_tax');
 
1174   $form->{title} = $locale->text('Tax-O-Matic');
 
1178   my $parameters_ref = {
 
1181   # Ausgabe des Templates
 
1182   print($form->parse_html_template('am/list_tax', $parameters_ref));
 
1184   $main::lxdebug->leave_sub();
 
1187 sub _get_taxaccount_selection{
 
1188   $main::lxdebug->enter_sub();
 
1190   my $form     = $main::form;
 
1191   my %myconfig = %main::myconfig;
 
1193   $main::auth->assert('config');
 
1195   AM->get_tax_accounts(\%myconfig, \%$form);
 
1197   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
1199   $main::lxdebug->leave_sub();
 
1203   $main::lxdebug->enter_sub();
 
1205   my $form     = $main::form;
 
1206   my %myconfig = %main::myconfig;
 
1207   my $locale   = $main::locale;
 
1209   $main::auth->assert('config');
 
1211   $form->error($locale->text('Taxkey  missing!')) unless length($form->{taxkey}) != 0;
 
1212   $form->error($locale->text('Taxdescription  missing!')) unless length($form->{taxdescription}) != 0;
 
1213   $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
 
1215   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
1217   if ($form->{taxkey} == 0 and $form->{rate} > 0) {
 
1218     $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
 
1221   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
1222     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
1225   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
1226     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
1229   my @translation_keys  =  grep { $_ =~ '^translation_\d+' } keys %$form;
 
1230   $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
 
1232   AM->save_tax(\%myconfig, \%$form);
 
1233   $form->redirect($locale->text('Tax saved!'));
 
1235   $main::lxdebug->leave_sub();
 
1239   $main::lxdebug->enter_sub();
 
1241   my $form     = $main::form;
 
1242   my %myconfig = %main::myconfig;
 
1243   my $locale   = $main::locale;
 
1245   $main::auth->assert('config');
 
1247   AM->delete_tax(\%myconfig, \%$form);
 
1248   $form->redirect($locale->text('Tax deleted!'));
 
1250   $main::lxdebug->leave_sub();
 
1254   $main::lxdebug->enter_sub();
 
1256   my $form     = $main::form;
 
1257   my $locale   = $main::locale;
 
1259   $main::auth->assert('config');
 
1261   $form->{title}      = $locale->text('Add Warehouse');
 
1262   $form->{callback} ||= build_std_url('action=add_warehouse');
 
1265   print $form->parse_html_template('am/edit_warehouse');
 
1267   $main::lxdebug->leave_sub();
 
1270 sub edit_warehouse {
 
1271   $main::lxdebug->enter_sub();
 
1273   my $form     = $main::form;
 
1274   my %myconfig = %main::myconfig;
 
1275   my $locale   = $main::locale;
 
1277   $main::auth->assert('config');
 
1279   AM->get_warehouse(\%myconfig, $form);
 
1281   $form->get_lists('employees' => 'EMPLOYEES');
 
1283   $form->{title}      = $locale->text('Edit Warehouse');
 
1284   $form->{callback} ||= build_std_url('action=list_warehouses');
 
1287   print $form->parse_html_template('am/edit_warehouse');
 
1289   $main::lxdebug->leave_sub();
 
1292 sub list_warehouses {
 
1293   $main::lxdebug->enter_sub();
 
1295   my $form     = $main::form;
 
1296   my %myconfig = %main::myconfig;
 
1297   my $locale   = $main::locale;
 
1299   $main::auth->assert('config');
 
1301   AM->get_all_warehouses(\%myconfig, $form);
 
1303   $form->{callback} = build_std_url('action=list_warehouses');
 
1304   $form->{title}    = $locale->text('Warehouses');
 
1305   $form->{url_base} = build_std_url('callback');
 
1308   print $form->parse_html_template('am/list_warehouses');
 
1310   $main::lxdebug->leave_sub();
 
1313 sub save_warehouse {
 
1314   $main::lxdebug->enter_sub();
 
1316   my $form     = $main::form;
 
1317   my %myconfig = %main::myconfig;
 
1318   my $locale   = $main::locale;
 
1320   $main::auth->assert('config');
 
1322   $form->isblank("description", $locale->text('Description missing!'));
 
1324   $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
 
1326   AM->save_warehouse(\%myconfig, $form);
 
1328   $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
 
1330   $form->redirect($locale->text('Warehouse saved.'));
 
1332   $main::lxdebug->leave_sub();
 
1335 sub delete_warehouse {
 
1336   $main::lxdebug->enter_sub();
 
1338   my $form     = $main::form;
 
1339   my %myconfig = %main::myconfig;
 
1340   my $locale   = $main::locale;
 
1342   $main::auth->assert('config');
 
1344   if (!$form->{confirmed}) {
 
1345     $form->{title} = $locale->text('Confirmation');
 
1348     print $form->parse_html_template('am/confirm_delete_warehouse');
 
1349     $::dispatcher->end_request;
 
1352   if (AM->delete_warehouse(\%myconfig, $form)) {
 
1353     $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
 
1354     $form->redirect($locale->text('Warehouse deleted.'));
 
1357     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
 
1360   $main::lxdebug->leave_sub();
 
1364   $main::lxdebug->enter_sub();
 
1366   my $form     = $main::form;
 
1367   my %myconfig = %main::myconfig;
 
1368   my $locale   = $main::locale;
 
1370   $main::auth->assert('config');
 
1372   AM->save_bins(\%myconfig, $form);
 
1374   $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
 
1376   $form->redirect($locale->text('Bins saved.'));
 
1378   $main::lxdebug->leave_sub();