1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
   9 # Copyright (c) 1998-2002
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  16 # This program is free software; you can redistribute it and/or modify
 
  17 # it under the terms of the GNU General Public License as published by
 
  18 # the Free Software Foundation; either version 2 of the License, or
 
  19 # (at your option) any later version.
 
  21 # This program is distributed in the hope that it will be useful,
 
  22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  24 # GNU General Public License for more details.
 
  25 # You should have received a copy of the GNU General Public License
 
  26 # along with this program; if not, write to the Free Software
 
  27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  28 #======================================================================
 
  32 #======================================================================
 
  37 use SL::Auth::PasswordPolicy;
 
  50 require "bin/mozilla/common.pl";
 
  58 sub add      { call_sub("add_$main::form->{type}"); }
 
  59 sub delete   { call_sub("delete_$main::form->{type}"); }
 
  60 sub save     { call_sub("save_$main::form->{type}"); }
 
  61 sub edit     { call_sub("edit_$main::form->{type}"); }
 
  62 sub continue { call_sub($main::form->{"nextsub"}); }
 
  63 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
  66   $main::lxdebug->enter_sub();
 
  68   my $form     = $main::form;
 
  69   my %myconfig = %main::myconfig;
 
  71   $main::auth->assert('config');
 
  73   $form->{title}     = "Add";
 
  74   $form->{charttype} = "A";
 
  75   AM->get_account(\%myconfig, \%$form);
 
  77   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
 
  82   $main::lxdebug->leave_sub();
 
  86   $main::lxdebug->enter_sub();
 
  88   my $form     = $main::form;
 
  89   my %myconfig = %main::myconfig;
 
  91   $main::auth->assert('config');
 
  93   $form->{title} = "Edit";
 
  94   AM->get_account(\%myconfig, \%$form);
 
  96   foreach my $item (split(/:/, $form->{link})) {
 
  97     $form->{$item} = "checked";
 
 103   $main::lxdebug->leave_sub();
 
 107   $main::lxdebug->enter_sub();
 
 109   my $form     = $main::form;
 
 110   my %myconfig = %main::myconfig;
 
 111   my $locale   = $main::locale;
 
 113   $main::auth->assert('config');
 
 115   if ( $form->{action} eq 'edit_account') {
 
 116     $form->{account_exists} = '1';
 
 119   $form->{title} = $locale->text("$form->{title} Account");
 
 121   $form->{"$form->{charttype}_checked"} = "checked";
 
 122   $form->{"$form->{category}_checked"}  = "checked";
 
 124   $form->{select_tax} = "";
 
 126   my @tax_report_pos = USTVA->report_variables({
 
 127       myconfig   => \%myconfig,
 
 130       attribute  => 'position',
 
 134   if (@{ $form->{TAXKEY} }) {
 
 135     foreach my $item (@{ $form->{TAXKEY} }) {
 
 136       $item->{rate} = $item->{rate} * 100 . '%';
 
 139     # Fill in empty row for new Taxkey
 
 140     my $newtaxkey_ref = {
 
 145       taxdescription => '',
 
 149       startdate      => $form->{account_exists} ? '' : DateTime->new(year => 1970, month => 1, day => 1)->to_lxoffice,
 
 152     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 155     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 157       # Fill in a runningnumber
 
 158       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 160       # Fill in the Taxkeys as select options
 
 161       foreach my $item (@{ $form->{TAXKEY} }) {
 
 162         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 163           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 164             qq|<option value="$item->{id}" selected="selected">|
 
 165             . sprintf("%.2d", $item->{taxkey})
 
 166             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 167             . $locale->text('Tax-o-matic Account')
 
 168             . qq|: $item->{chart_accno}\n|;
 
 171           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 172             qq|<option value="$item->{id}">|
 
 173             . sprintf("%.2d", $item->{taxkey})
 
 174             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 175             . $locale->text('Tax-o-matic Account')
 
 176             . qq|: $item->{chart_accno}\n|;
 
 181       # Fill in the USTVA Numbers as select options
 
 182       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 184           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 186         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 187           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 190           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 199   # Newaccount Folgekonto
 
 200   if (@{ $form->{NEWACCOUNT} || [] }) {
 
 201     if (!$form->{new_chart_valid}) {
 
 202       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 204     foreach my $item (@{ $form->{NEWACCOUNT} }) {
 
 205       if ($item->{id} == $form->{new_chart_id}) {
 
 206         $form->{selectnewaccount} .=
 
 207           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 208       } elsif (!$form->{new_chart_valid}) {
 
 209         $form->{selectnewaccount} .=
 
 210           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 216   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 219           2  => "sonstige Erlöse",
 
 220           3  => "Privatanteile",
 
 222           5  => "Ausserordentliche Erträge",
 
 223           6  => "Vereinnahmte Umsatzst.",
 
 224           7  => "Umsatzsteuererstattungen",
 
 225           8  => "Wareneingänge",
 
 226           9  => "Löhne und Gehälter",
 
 227           10 => "Gesetzl. sozialer Aufw.",
 
 229           12 => "Gas, Strom, Wasser",
 
 230           13 => "Instandhaltung",
 
 231           14 => "Steuern, Versich., Beiträge",
 
 233           16 => "Kfz-Versicherungen",
 
 234           17 => "Sonst. Fahrzeugkosten",
 
 235           18 => "Werbe- und Reisekosten",
 
 236           19 => "Instandhaltung u. Werkzeuge",
 
 237           20 => "Fachzeitschriften, Bücher",
 
 238           21 => "Miete für Einrichtungen",
 
 239           22 => "Rechts- und Beratungskosten",
 
 240           23 => "Bürobedarf, Porto, Telefon",
 
 241           24 => "Sonstige Aufwendungen",
 
 242           25 => "Abschreibungen auf Anlagever.",
 
 243           26 => "Abschreibungen auf GWG",
 
 245           28 => "Umsatzsteuerzahlungen",
 
 247           30 => "Ausserordentlicher Aufwand",
 
 248           31 => "Betriebliche Steuern");
 
 249   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
 
 250     my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
 
 251     if ($item == $form->{pos_eur}) {
 
 252       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 254       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 259   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 263              2  => 'Best.Verdg.FE/UE',
 
 264              3  => 'Aktiv.Eigenleistung',
 
 265              4  => 'Mat./Wareneinkauf',
 
 266              5  => 'So.betr.Erlöse',
 
 267              10 => 'Personalkosten',
 
 269              12 => 'Betriebl.Steuern',
 
 270              13 => 'Vers./Beiträge',
 
 271              14 => 'Kfz.Kosten o.St.',
 
 272              15 => 'Werbe-Reisek.',
 
 273              16 => 'Kosten Warenabgabe',
 
 274              17 => 'Abschreibungen',
 
 275              18 => 'Rep./instandhlt.',
 
 276              19 => 'Übrige Steuern',
 
 277              20 => 'Sonst.Kosten',
 
 279              31 => 'Sonst.neutr.Aufw.',
 
 281              33 => 'Sonst.neutr.Ertrag',
 
 282              34 => 'Verr.kalk.Kosten',
 
 283              35 => 'Steuern Eink.u.Ertr.');
 
 284   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
 
 285     my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
 
 286     if ($item == $form->{pos_bwa}) {
 
 287       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 289       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 294 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 295   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 296   foreach my $item ((1, 2, 3, 4)) {
 
 297     if ($item == $form->{pos_bilanz}) {
 
 298       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 300       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 305   # this is for our parser only! Do not remove.
 
 306   # type=submit $locale->text('Add Account')
 
 307   # type=submit $locale->text('Edit Account')
 
 309   $form->{type} = "account";
 
 311   # preselections category
 
 313   my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 316       'A'  => $locale->text('Asset'),
 
 317       'L'  => $locale->text('Liability'),
 
 318       'Q'  => $locale->text('Equity'),
 
 319       'I'  => $locale->text('Revenue'),
 
 320       'E'  => $locale->text('Expense'),
 
 321       'C'  => $locale->text('Costs'),
 
 323   foreach my $item ( sort({ $a <=> $b } keys %category) ) {
 
 324     if ($item eq $form->{category}) {
 
 325       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 327       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 332   # preselection chart type
 
 333   my @all_charttypes = ({'name' => $locale->text('Account'), 'value' => 'A'},
 
 334                         {'name' => $locale->text('Heading'), 'value' => 'H'},
 
 336   my $selected_charttype = $form->{charttype};
 
 339   # account where AR_tax or AP_tax is set are not orphaned if they are used as
 
 340   # tax-o-matic account
 
 341   if ( $form->{id} && $form->{orphaned} && ($form->{link} =~ m/(AP_tax|AR_tax)/) ) {
 
 342     if (SL::DB::Manager::Tax->find_by(chart_id => $form->{id})) {
 
 343       $form->{orphaned} = 0;
 
 347   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 348   my $AccountIsPosted = ($form->{orphaned} ) ? "":"1";
 
 352   my $parameters_ref = {
 
 353     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 354     AccountIsPosted            => $AccountIsPosted,
 
 355     select_category            => $select_category,
 
 356     all_charttypes             => \@all_charttypes,
 
 357     selected_charttype         => $selected_charttype,
 
 358     select_bwa                 => $select_bwa,
 
 359     select_bilanz              => $select_bilanz,
 
 360     select_eur                 => $select_eur,
 
 363   # Ausgabe des Templates
 
 364   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 367   $main::lxdebug->leave_sub();
 
 371   $::lxdebug->enter_sub;
 
 372   $::auth->assert('config');
 
 374   print $::form->parse_html_template('am/form_footer', {
 
 375     show_save        => !$::form->{id}
 
 376                      || ($::form->{id} && $::form->{orphaned})
 
 377                      || ($::form->{type} eq "account" && !$::form->{new_chart_valid}),
 
 378     show_delete      => $::form->{id} && $::form->{orphaned},
 
 379     show_save_as_new => $::form->{id} && $::form->{type} eq "account",
 
 382   $::lxdebug->leave_sub;
 
 386   $main::lxdebug->enter_sub();
 
 388   my $form     = $main::form;
 
 389   my %myconfig = %main::myconfig;
 
 390   my $locale   = $main::locale;
 
 392   $main::auth->assert('config');
 
 394   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 395   $form->isblank("description", $locale->text('Account Description missing!'));
 
 397   if ($form->{charttype} eq 'A'){
 
 398     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 400     my $found_valid_taxkey = 0;
 
 401     foreach my $i (0 .. 10) { # 10 is maximum count of taxkeys in form
 
 402       if ($form->{"taxkey_startdate_$i"} and !$form->{"taxkey_del_$i"}) {
 
 403         $found_valid_taxkey = 1;
 
 407     if ($found_valid_taxkey == 0) {
 
 408       $form->error($locale->text('A valid taxkey is missing!'));
 
 412   $form->redirect($locale->text('Account saved!'))
 
 413     if (AM->save_account(\%myconfig, \%$form));
 
 414   $form->error($locale->text('Cannot save account!'));
 
 416   $main::lxdebug->leave_sub();
 
 419 sub save_as_new_account {
 
 420   $main::lxdebug->enter_sub();
 
 422   my $form     = $main::form;
 
 423   my %myconfig = %main::myconfig;
 
 424   my $locale   = $main::locale;
 
 426   $main::auth->assert('config');
 
 428   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 429   $form->isblank("description", $locale->text('Account Description missing!'));
 
 431   if ($form->{charttype} eq 'A'){
 
 432     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 435   for my $taxkey (0 .. 9) {
 
 436     if ($form->{"taxkey_id_$taxkey"}) {
 
 437       $form->{"taxkey_id_$taxkey"} = "NEW";
 
 442   $form->redirect($locale->text('Account saved!'))
 
 443     if (AM->save_account(\%myconfig, \%$form));
 
 444   $form->error($locale->text('Cannot save account!'));
 
 446   $main::lxdebug->leave_sub();
 
 450   $main::lxdebug->enter_sub();
 
 452   my $form     = $main::form;
 
 453   my %myconfig = %main::myconfig;
 
 454   my $locale   = $main::locale;
 
 456   $main::auth->assert('config');
 
 458   $form->{callback}     = build_std_url('action=list_account');
 
 459   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 461   CA->all_accounts(\%myconfig, \%$form);
 
 463   foreach my $ca (@{ $form->{CA} }) {
 
 468     if ($ca->{amount} > 0) {
 
 469       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 471     if ($ca->{amount} < 0) {
 
 472       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 474     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:'';
 
 475     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 478   $::request->{layout}->use_stylesheet("list_accounts.css");
 
 479   $form->{title}       = $locale->text('Chart of Accounts');
 
 484   my $parameters_ref = {
 
 485   #   hidden_variables                => $_hidden_variables_ref,
 
 488   # Ausgabe des Templates
 
 489   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
 491   $main::lxdebug->leave_sub();
 
 496 sub list_account_details {
 
 497 # Ajax Funktion aus list_account_details
 
 498   $main::lxdebug->enter_sub();
 
 500   my $form     = $main::form;
 
 501   my %myconfig = %main::myconfig;
 
 502   my $locale   = $main::locale;
 
 504   $main::auth->assert('config');
 
 506   my $chart_id = $form->{args};
 
 508   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 510   foreach my $ca (@{ $form->{CA} }) {
 
 512     $ca->{debit}  = " ";
 
 513     $ca->{credit} = " ";
 
 515     if ($ca->{amount} > 0) {
 
 517         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 519     if ($ca->{amount} < 0) {
 
 521         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 524     my @links = split( q{:}, $ca->{link});
 
 528     foreach my $link (@links){
 
 529       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 530                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 531                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 532                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 533                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 534                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 535                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 536                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 537                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 538                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 539                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 540                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 541                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 542                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 543                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 544                : $locale->text('Unknown Link') . ': ' . $link;
 
 545       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 548     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 549                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 550                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 551                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 552                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 553                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 554                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 555                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 558   $form->{title} = $locale->text('Chart of Accounts');
 
 560   print $form->ajax_response_header, $form->parse_html_template('am/list_account_details');
 
 562   $main::lxdebug->leave_sub();
 
 567   $main::lxdebug->enter_sub();
 
 569   my $form     = $main::form;
 
 570   my %myconfig = %main::myconfig;
 
 571   my $locale   = $main::locale;
 
 573   $main::auth->assert('config');
 
 575   $form->{title} = $locale->text('Delete Account');
 
 578     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
 
 580     if ($form->{id} == $form->{$id}) {
 
 581       $form->error($locale->text('Cannot delete default account!'));
 
 585   $form->redirect($locale->text('Account deleted!'))
 
 586     if (AM->delete_account(\%myconfig, \%$form));
 
 587   $form->error($locale->text('Cannot delete account!'));
 
 589   $main::lxdebug->leave_sub();
 
 593   $main::lxdebug->enter_sub();
 
 595   my $form     = $main::form;
 
 597   $main::auth->assert('config');
 
 599   $form->{title} = "Add";
 
 601   $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
 
 606   $main::lxdebug->leave_sub();
 
 610   $main::lxdebug->enter_sub();
 
 612   my $form     = $main::form;
 
 613   my %myconfig = %main::myconfig;
 
 615   $main::auth->assert('config');
 
 617   $form->{title} = "Edit";
 
 619   AM->get_lead(\%myconfig, \%$form);
 
 623   $form->{orphaned} = 1;
 
 626   $main::lxdebug->leave_sub();
 
 630   $::lxdebug->enter_sub;
 
 631   $::auth->assert('config');
 
 633   AM->lead(\%::myconfig, $::form);
 
 635   $::form->{callback} = "am.pl?action=list_lead";
 
 636   $::form->{title}    = $::locale->text('Lead');
 
 639   print $::form->parse_html_template('am/lead_list');
 
 641   $::lxdebug->leave_sub;
 
 645   $::lxdebug->enter_sub;
 
 646   $::auth->assert('config');
 
 648   # $locale->text('Add Lead')
 
 649   # $locale->text('Edit Lead')
 
 650   $::form->{title} = $::locale->text("$::form->{title} Lead");
 
 653   print $::form->parse_html_template('am/lead_header');
 
 655   $::lxdebug->leave_sub;
 
 659   $main::lxdebug->enter_sub();
 
 661   my $form     = $main::form;
 
 662   my %myconfig = %main::myconfig;
 
 663   my $locale   = $main::locale;
 
 665   $main::auth->assert('config');
 
 667   $form->isblank("description", $locale->text('Description missing!'));
 
 668   AM->save_lead(\%myconfig, \%$form);
 
 669   $form->redirect($locale->text('lead saved!'));
 
 671   $main::lxdebug->leave_sub();
 
 675   $main::lxdebug->enter_sub();
 
 677   my $form     = $main::form;
 
 678   my %myconfig = %main::myconfig;
 
 679   my $locale   = $main::locale;
 
 681   $main::auth->assert('config');
 
 683   AM->delete_lead(\%myconfig, \%$form);
 
 684   $form->redirect($locale->text('lead deleted!'));
 
 686   $main::lxdebug->leave_sub();
 
 690   $main::lxdebug->enter_sub();
 
 692   my $form     = $main::form;
 
 694   $main::auth->assert('config');
 
 696   $form->{title} = "Add";
 
 698   $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
 
 703   $main::lxdebug->leave_sub();
 
 707   $main::lxdebug->enter_sub();
 
 709   my $form     = $main::form;
 
 710   my %myconfig = %main::myconfig;
 
 712   $main::auth->assert('config');
 
 714   $form->{title} = "Edit";
 
 716   AM->get_language(\%myconfig, \%$form);
 
 720   $form->{orphaned} = 1;
 
 723   $main::lxdebug->leave_sub();
 
 727   $::lxdebug->enter_sub;
 
 728   $::auth->assert('config');
 
 730   AM->language(\%::myconfig, $::form);
 
 732   $::form->{callback} = "am.pl?action=list_language";
 
 733   $::form->{title}   = $::locale->text('Languages');
 
 737   print $::form->parse_html_template('am/language_list');
 
 739   $::lxdebug->leave_sub;
 
 742 sub language_header {
 
 743   $::lxdebug->enter_sub;
 
 744   $::auth->assert('config');
 
 746   # $locale->text('Add Language')
 
 747   # $locale->text('Edit Language')
 
 748   $::form->{title} = $::locale->text("$::form->{title} Language");
 
 752   print $::form->parse_html_template('am/language_header', {
 
 753     numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00' ],
 
 754     dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ],
 
 757   $::lxdebug->leave_sub;
 
 761   $main::lxdebug->enter_sub();
 
 763   my $form     = $main::form;
 
 764   my %myconfig = %main::myconfig;
 
 765   my $locale   = $main::locale;
 
 767   $main::auth->assert('config');
 
 769   $form->isblank("description", $locale->text('Language missing!'));
 
 770   $form->isblank("template_code", $locale->text('Template Code missing!'));
 
 771   $form->isblank("article_code", $locale->text('Article Code missing!'));
 
 772   AM->save_language(\%myconfig, \%$form);
 
 773   $form->redirect($locale->text('Language saved!'));
 
 775   $main::lxdebug->leave_sub();
 
 778 sub delete_language {
 
 779   $main::lxdebug->enter_sub();
 
 781   my $form     = $main::form;
 
 782   my %myconfig = %main::myconfig;
 
 783   my $locale   = $main::locale;
 
 785   $main::auth->assert('config');
 
 787   AM->delete_language(\%myconfig, \%$form);
 
 788   $form->redirect($locale->text('Language deleted!'));
 
 790   $main::lxdebug->leave_sub();
 
 793 sub _build_cfg_options {
 
 794   my $form     = $main::form;
 
 795   my %myconfig = %main::myconfig;
 
 798   my $array = uc($idx) . 'S';
 
 800   $form->{$array} = [];
 
 801   foreach my $item (@_) {
 
 802     push @{ $form->{$array} }, {
 
 805       'selected' => $item eq $myconfig{$idx},
 
 811   $main::lxdebug->enter_sub();
 
 813   my $form     = $main::form;
 
 814   my %myconfig = %main::myconfig;
 
 815   my $locale   = $main::locale;
 
 817   _build_cfg_options('dateformat', qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
 818   _build_cfg_options('timeformat', qw(hh:mm hh:mm:ss));
 
 819   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
 822   if ($::lx_office_conf{print_templates}->{opendocument}
 
 823       && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
 
 824       && $::lx_office_conf{applications}->{xvfb}                 && (-x $::lx_office_conf{applications}->{xvfb})) {
 
 825     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
 826                      "value" => "opendocument_pdf" });
 
 828   if ($::lx_office_conf{print_templates}->{latex}) {
 
 829     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
 831   push(@formats, { "name" => "HTML", "value" => "html" });
 
 832   if ($::lx_office_conf{print_templates}->{latex}) {
 
 833     push(@formats, { "name" => $locale->text("Postscript"),
 
 834                      "value" => "postscript" });
 
 836   if ($::lx_office_conf{print_templates}->{opendocument}) {
 
 837     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
 838                      "value" => "opendocument" });
 
 841   if (!$myconfig{"template_format"}) {
 
 842     $myconfig{"template_format"} = "pdf";
 
 844   $form->{TEMPLATE_FORMATS} = [];
 
 845   foreach my $item (@formats) {
 
 846     push @{ $form->{TEMPLATE_FORMATS} }, {
 
 847       'name'     => $item->{name},
 
 848       'value'    => $item->{value},
 
 849       'selected' => $item->{value} eq $myconfig{template_format},
 
 853   if (!$myconfig{"default_media"}) {
 
 854     $myconfig{"default_media"} = "screen";
 
 857   my %selected = ($myconfig{"default_media"} => "selected");
 
 859     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
 860     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
 861     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
 864   $form->{PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
 
 866   my %countrycodes = User->country_codes;
 
 868   $form->{COUNTRYCODES} = [];
 
 869   foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
 870     push @{ $form->{COUNTRYCODES} }, {
 
 871       'name'     => $countrycodes{$countrycode},
 
 872       'value'    => $countrycode,
 
 873       'selected' => $countrycode eq $myconfig{countrycode},
 
 877   $form->{STYLESHEETS} = [];
 
 878   foreach my $item (qw(lx-office-erp.css kivitendo.css)) {
 
 879     push @{ $form->{STYLESHEETS} }, {
 
 882       'selected' => $item eq $myconfig{stylesheet},
 
 886   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
 
 887   $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
 888   $form->{todo_cfg}            = { TODO->get_user_config('login' => $::myconfig{login}) };
 
 890   $form->{title}               = $locale->text('Edit Preferences for #1', $::myconfig{login});
 
 894   $form->{full_signature} = $form->create_email_signature();
 
 896   print $form->parse_html_template('am/config');
 
 898   $main::lxdebug->leave_sub();
 
 901 sub save_preferences {
 
 902   $main::lxdebug->enter_sub();
 
 904   my $form     = $main::form;
 
 905   my %myconfig = %main::myconfig;
 
 906   my $locale   = $main::locale;
 
 908   $form->{stylesheet} = $form->{usestylesheet};
 
 910   TODO->save_user_config('login' => $::myconfig{login}, %{ $form->{todo_cfg} || { } });
 
 912   if (AM->save_preferences($form)) {
 
 913     if ($::auth->can_change_password()
 
 914         && defined $form->{new_password}
 
 915         && ($form->{new_password} ne '********')) {
 
 916       my $verifier = SL::Auth::PasswordPolicy->new;
 
 917       my $result   = $verifier->verify($form->{new_password});
 
 919       if ($result != SL::Auth::PasswordPolicy->OK()) {
 
 920         $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
 
 923       $::auth->change_password($::myconfig{login}, $form->{new_password});
 
 926     $form->redirect($locale->text('Preferences saved!'));
 
 929   $form->error($locale->text('Cannot save preferences!'));
 
 931   $main::lxdebug->leave_sub();
 
 935   $::lxdebug->enter_sub;
 
 936   $::auth->assert('config');
 
 938   $::form->{title} = $::locale->text('Audit Control');
 
 940   AM->closedto(\%::myconfig, $::form);
 
 943   print $::form->parse_html_template('am/audit_control');
 
 945   $::lxdebug->leave_sub;
 
 949   $main::lxdebug->enter_sub();
 
 951   my $form     = $main::form;
 
 952   my %myconfig = %main::myconfig;
 
 953   my $locale   = $main::locale;
 
 955   $main::auth->assert('config');
 
 957   AM->closebooks(\%myconfig, \%$form);
 
 959   if ($form->{closedto}) {
 
 961                     $locale->text('Books closed up to') . " "
 
 962                       . $locale->date(\%myconfig, $form->{closedto}, 1));
 
 964     $form->redirect($locale->text('Books are open'));
 
 967   $main::lxdebug->leave_sub();
 
 971   $main::lxdebug->enter_sub();
 
 973   my $form     = $main::form;
 
 974   my %myconfig = %main::myconfig;
 
 975   my $locale   = $main::locale;
 
 977   $main::auth->assert('config');
 
 979   my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
 980   AM->units_in_use(\%myconfig, $form, $units);
 
 981   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
 983   my @languages = AM->language(\%myconfig, $form, 1);
 
 985   my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
 988   foreach (@unit_list) {
 
 989     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
 990     $_->{"UNITLANGUAGES"} = [];
 
 991     foreach my $lang (@languages) {
 
 992       push(@{ $_->{"UNITLANGUAGES"} },
 
 994              "unit" => $_->{"name"},
 
 995              "language_id" => $lang->{"id"},
 
 996              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
 997              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
1003   $units = AM->retrieve_units(\%myconfig, $form);
 
1004   my $ddbox = AM->unit_select_data($units, undef, 1);
 
1006   $form->{"title"} = $locale->text("Add and edit units");
 
1008   print($form->parse_html_template("am/edit_units",
 
1009                                    { "UNITS"               => \@unit_list,
 
1010                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
1011                                      "LANGUAGES"           => \@languages,
 
1014   $main::lxdebug->leave_sub();
 
1018   $main::lxdebug->enter_sub();
 
1020   my $form     = $main::form;
 
1021   my %myconfig = %main::myconfig;
 
1022   my $locale   = $main::locale;
 
1024   $main::auth->assert('config');
 
1026   $form->isblank("new_name", $locale->text("The name is missing."));
 
1027   my $units = AM->retrieve_units(\%myconfig, $form);
 
1028   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
1029   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
1031   my ($base_unit, $factor);
 
1032   if ($form->{"new_base_unit"}) {
 
1033     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
1035     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
1036     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
1037     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
1038     $base_unit = $form->{"new_base_unit"};
 
1042   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
1043     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
1044     push(@languages, { "id" => $lang->{"id"},
 
1045                        "localized" => $form->{"new_localized_$lang->{id}"},
 
1046                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
1050   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
1052   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
1056   $main::lxdebug->leave_sub();
 
1059 sub set_unit_languages {
 
1060   $main::lxdebug->enter_sub();
 
1062   my $form     = $main::form;
 
1064   $main::auth->assert('config');
 
1066   my ($unit, $languages, $idx) = @_;
 
1068   $unit->{"LANGUAGES"} = [];
 
1070   foreach my $lang (@{$languages}) {
 
1071     push(@{ $unit->{"LANGUAGES"} },
 
1072          { "id" => $lang->{"id"},
 
1073            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
1074            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
1078   $main::lxdebug->leave_sub();
 
1082   $main::lxdebug->enter_sub();
 
1084   my $form     = $main::form;
 
1085   my %myconfig = %main::myconfig;
 
1086   my $locale   = $main::locale;
 
1088   $main::auth->assert('config');
 
1090   my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
1091   AM->units_in_use(\%myconfig, $form, $old_units);
 
1093   my @languages = AM->language(\%myconfig, $form, 1);
 
1096   my @delete_units = ();
 
1097   foreach my $i (1..($form->{"rowcount"} * 1)) {
 
1098     my $old_unit = $old_units->{$form->{"old_name_$i"}};
 
1100       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
1103     if ($form->{"unchangeable_$i"}) {
 
1104       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
1105       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
1106       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
1110     if ($old_unit->{"in_use"}) {
 
1111       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
1114     if ($form->{"delete_$i"}) {
 
1115       push(@delete_units, $old_unit->{"name"});
 
1119     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
1121     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
1122     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
1123     $new_units->{$form->{"name_$i"}} = \%h;
 
1124     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
1125     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
1128   foreach my $unit (values(%{$new_units})) {
 
1129     next unless ($unit->{"old_name"});
 
1130     if ($unit->{"base_unit"}) {
 
1131       $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"}))
 
1132         unless (defined($new_units->{$unit->{"base_unit"}}));
 
1133       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
1134       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
1136       $unit->{"base_unit"} = undef;
 
1137       $unit->{"factor"} = undef;
 
1141   foreach my $unit (values(%{$new_units})) {
 
1142     next if ($unit->{"unchanged_unit"});
 
1144     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
1145     my $new_unit = $unit;
 
1146     while ($new_unit->{"base_unit"}) {
 
1147       $new_unit->{"seen"} = 1;
 
1148       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
1149       if ($new_unit->{"seen"}) {
 
1150         $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, " .
 
1151                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
1156   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
1158   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
1162   $main::lxdebug->leave_sub();
 
1165 sub show_history_search {
 
1166   $main::lxdebug->enter_sub();
 
1168   my $form     = $main::form;
 
1169   my $locale   = $main::locale;
 
1171   $main::auth->assert('config');
 
1173   $form->{title} = $locale->text("History Search");
 
1176   print $form->parse_html_template("common/search_history");
 
1178   $main::lxdebug->leave_sub();
 
1181 sub show_am_history {
 
1182   $main::lxdebug->enter_sub();
 
1184   my $form     = $main::form;
 
1185   my %myconfig = %main::myconfig;
 
1186   my $locale   = $main::locale;
 
1188   $main::auth->assert('config');
 
1190   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
 
1191   $form->{order} ||= 'h.itime--1';
 
1193   # my %search = ( "Artikelnummer"          => "parts",
 
1194   #                "Kundennummer"           => "customer",
 
1195   #                "Lieferantennummer"      => "vendor",
 
1196   #                "Projektnummer"          => "project",
 
1197   #                "Auftragsnummer"         => "oe",
 
1198   #                "Angebotsnummer"         => "oe",
 
1199   #                "Eingangsrechnungnummer" => "ap",
 
1200   #                "Ausgangsrechnungnummer" => "ar",
 
1201   #                "Mahnungsnummer"         => "dunning",
 
1202   #                "Buchungsnummer"         => "gl",
 
1205   my %searchNo = ( "Artikelnummer"          => "partnumber",
 
1206                    "Kundennummer"           => "customernumber",
 
1207                    "Lieferantennummer"      => "vendornumber",
 
1208                    "Projektnummer"          => "projectnumber",
 
1209                    "Auftragsnummer"         => "ordnumber",
 
1210                    "Angebotsnummer"         => "quonumber",
 
1211                    "Eingangsrechnungnummer" => "invnumber",
 
1212                    "Ausgangsrechnungnummer" => "invnumber",
 
1213                    "Mahnungsnummer"         => "dunning_id",
 
1214                    "Buchungsnummer"         => "gltransaction"
 
1217   my $dbh = $form->dbconnect(\%myconfig);
 
1220   $restriction     = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
 
1221   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
 
1222   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
 
1223   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
1224     $restriction  .= qq| AND employee_id = |    . $form->{mitarbeiter};
 
1225   } elsif ($form->{mitarbeiter}) {
 
1226     $restriction  .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
 
1229   my $query = qq|SELECT trans_id AS id FROM history_erp | .
 
1230     (  $form->{'searchid'} ? qq| WHERE snumbers = '|  . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
 
1231      :                       qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
1233   my @ids    = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
 
1234   my $daten .= shift @ids;
 
1235   $daten    .= join '', map { " OR trans_id = $_" } @ids;
 
1237   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
1238   $sort =~ s/.*\.(.*)$/$1/;
 
1240   $form->{title} = $locale->text("History Search");
 
1243   print $form->parse_html_template("common/show_history",
 
1244                                    { "DATEN"          => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
1245                                      "SUCCESS"        => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
1248                                      uc($sort) . "BY" => $sortby,
 
1249                                      'callback'       => $callback,
 
1253   $main::lxdebug->leave_sub();
 
1257   $main::lxdebug->enter_sub();
 
1259   my $form     = $main::form;
 
1260   my $locale   = $main::locale;
 
1262   $main::auth->assert('config');
 
1264   $form->{title} =  $locale->text('Add');
 
1266   $form->{callback} ||= "am.pl?action=add_tax";
 
1268   _get_taxaccount_selection();
 
1271   $form->{liability}  = 1;
 
1272   $form->{equity}     = 1;
 
1273   $form->{revenue}    = 1;
 
1274   $form->{expense}    = 1;
 
1279   my $parameters_ref = {
 
1280 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
1281     LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
 
1284   # Ausgabe des Templates
 
1285   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
1287   $main::lxdebug->leave_sub();
 
1291   $main::lxdebug->enter_sub();
 
1293   my $form     = $main::form;
 
1294   my %myconfig = %main::myconfig;
 
1295   my $locale   = $main::locale;
 
1297   $main::auth->assert('config');
 
1299   $form->{title} =  $locale->text('Edit');
 
1301   AM->get_tax(\%myconfig, \%$form);
 
1303   _get_taxaccount_selection();
 
1305   $form->{asset}      = $form->{chart_categories} =~ 'A' ? 1 : 0;
 
1306   $form->{liability}  = $form->{chart_categories} =~ 'L' ? 1 : 0;
 
1307   $form->{equity}     = $form->{chart_categories} =~ 'Q' ? 1 : 0;
 
1308   $form->{revenue}    = $form->{chart_categories} =~ 'I' ? 1 : 0;
 
1309   $form->{expense}    = $form->{chart_categories} =~ 'E' ? 1 : 0;
 
1310   $form->{costs}      = $form->{chart_categories} =~ 'C' ? 1 : 0;
 
1312   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
1316   my $parameters_ref = {
 
1317     LANGUAGES => SL::DB::Manager::Language->get_all_sorted,
 
1318     TAX       => SL::DB::Manager::Tax->find_by(id => $form->{id}),
 
1321   # Ausgabe des Templates
 
1322   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
1324   $main::lxdebug->leave_sub();
 
1328   $main::lxdebug->enter_sub();
 
1330   my $form     = $main::form;
 
1331   my %myconfig = %main::myconfig;
 
1332   my $locale   = $main::locale;
 
1334   $main::auth->assert('config');
 
1336   AM->taxes(\%myconfig, \%$form);
 
1338   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
1340   $form->{callback} = build_std_url('action=list_tax');
 
1342   $form->{title} = $locale->text('Tax-O-Matic');
 
1346   my $parameters_ref = {
 
1349   # Ausgabe des Templates
 
1350   print($form->parse_html_template('am/list_tax', $parameters_ref));
 
1352   $main::lxdebug->leave_sub();
 
1355 sub _get_taxaccount_selection{
 
1356   $main::lxdebug->enter_sub();
 
1358   my $form     = $main::form;
 
1359   my %myconfig = %main::myconfig;
 
1361   $main::auth->assert('config');
 
1363   AM->get_tax_accounts(\%myconfig, \%$form);
 
1365   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
1367   $main::lxdebug->leave_sub();
 
1371   $main::lxdebug->enter_sub();
 
1373   my $form     = $main::form;
 
1374   my %myconfig = %main::myconfig;
 
1375   my $locale   = $main::locale;
 
1377   $main::auth->assert('config');
 
1379   $form->error($locale->text('Taxkey  missing!')) unless length($form->{taxkey}) != 0;
 
1380   $form->error($locale->text('Taxdescription  missing!')) unless length($form->{taxdescription}) != 0;
 
1381   $form->error($locale->text('Taxrate missing!')) unless length($form->{rate}) != 0;
 
1383   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
1385   if ($form->{taxkey} == 0 and $form->{rate} > 0) {
 
1386     $form->error($locale->text('Taxkey 0 is reserved for rate 0'));
 
1389   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
1390     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
1393   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
1394     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
1397   my @translation_keys  =  grep { $_ =~ '^translation_\d+' } keys %$form;
 
1398   $form->{translations} = { map { $_ =~ '^translation_(\d+)'; $1 => $form->{$_} } @translation_keys };
 
1400   AM->save_tax(\%myconfig, \%$form);
 
1401   $form->redirect($locale->text('Tax saved!'));
 
1403   $main::lxdebug->leave_sub();
 
1407   $main::lxdebug->enter_sub();
 
1409   my $form     = $main::form;
 
1410   my %myconfig = %main::myconfig;
 
1411   my $locale   = $main::locale;
 
1413   $main::auth->assert('config');
 
1415   AM->delete_tax(\%myconfig, \%$form);
 
1416   $form->redirect($locale->text('Tax deleted!'));
 
1418   $main::lxdebug->leave_sub();
 
1421 sub add_price_factor {
 
1422   $main::lxdebug->enter_sub();
 
1424   my $form     = $main::form;
 
1425   my $locale   = $main::locale;
 
1427   $main::auth->assert('config');
 
1429   $form->{title}      = $locale->text('Add Price Factor');
 
1430   $form->{callback} ||= build_std_url('action=add_price_factor');
 
1433   print $form->parse_html_template('am/edit_price_factor');
 
1435   $main::lxdebug->leave_sub();
 
1438 sub edit_price_factor {
 
1439   $main::lxdebug->enter_sub();
 
1441   my $form     = $main::form;
 
1442   my %myconfig = %main::myconfig;
 
1443   my $locale   = $main::locale;
 
1445   $main::auth->assert('config');
 
1447   $form->{title}      = $locale->text('Edit Price Factor');
 
1448   $form->{callback} ||= build_std_url('action=add_price_factor');
 
1450   AM->get_price_factor(\%myconfig, $form);
 
1452   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
 
1455   print $form->parse_html_template('am/edit_price_factor');
 
1457   $main::lxdebug->leave_sub();
 
1460 sub list_price_factors {
 
1461   $main::lxdebug->enter_sub();
 
1463   my $form     = $main::form;
 
1464   my %myconfig = %main::myconfig;
 
1465   my $locale   = $main::locale;
 
1467   $main::auth->assert('config');
 
1469   AM->get_all_price_factors(\%myconfig, \%$form);
 
1471   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
 
1472     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
 
1475   $form->{callback} = build_std_url('action=list_price_factors');
 
1476   $form->{title}    = $locale->text('Price Factors');
 
1477   $form->{url_base} = build_std_url('callback');
 
1480   print $form->parse_html_template('am/list_price_factors');
 
1482   $main::lxdebug->leave_sub();
 
1485 sub save_price_factor {
 
1486   $main::lxdebug->enter_sub();
 
1488   my $form     = $main::form;
 
1489   my %myconfig = %main::myconfig;
 
1490   my $locale   = $main::locale;
 
1492   $main::auth->assert('config');
 
1494   $form->isblank("description", $locale->text('Description missing!'));
 
1495   $form->isblank("factor", $locale->text('Factor missing!'));
 
1497   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
 
1499   AM->save_price_factor(\%myconfig, $form);
 
1501   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
 
1503   $form->redirect($locale->text('Price factor saved!'));
 
1505   $main::lxdebug->leave_sub();
 
1508 sub delete_price_factor {
 
1509   $main::lxdebug->enter_sub();
 
1511   my $form     = $main::form;
 
1512   my %myconfig = %main::myconfig;
 
1513   my $locale   = $main::locale;
 
1515   $main::auth->assert('config');
 
1517   AM->delete_price_factor(\%myconfig, \%$form);
 
1519   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
 
1521   $form->redirect($locale->text('Price factor deleted!'));
 
1523   $main::lxdebug->leave_sub();
 
1527   $main::lxdebug->enter_sub();
 
1529   my $form     = $main::form;
 
1530   my $locale   = $main::locale;
 
1532   $main::auth->assert('config');
 
1534   $form->{title}      = $locale->text('Add Warehouse');
 
1535   $form->{callback} ||= build_std_url('action=add_warehouse');
 
1538   print $form->parse_html_template('am/edit_warehouse');
 
1540   $main::lxdebug->leave_sub();
 
1543 sub edit_warehouse {
 
1544   $main::lxdebug->enter_sub();
 
1546   my $form     = $main::form;
 
1547   my %myconfig = %main::myconfig;
 
1548   my $locale   = $main::locale;
 
1550   $main::auth->assert('config');
 
1552   AM->get_warehouse(\%myconfig, $form);
 
1554   $form->get_lists('employees' => 'EMPLOYEES');
 
1556   $form->{title}      = $locale->text('Edit Warehouse');
 
1557   $form->{callback} ||= build_std_url('action=list_warehouses');
 
1560   print $form->parse_html_template('am/edit_warehouse');
 
1562   $main::lxdebug->leave_sub();
 
1565 sub list_warehouses {
 
1566   $main::lxdebug->enter_sub();
 
1568   my $form     = $main::form;
 
1569   my %myconfig = %main::myconfig;
 
1570   my $locale   = $main::locale;
 
1572   $main::auth->assert('config');
 
1574   AM->get_all_warehouses(\%myconfig, $form);
 
1576   $form->{callback} = build_std_url('action=list_warehouses');
 
1577   $form->{title}    = $locale->text('Warehouses');
 
1578   $form->{url_base} = build_std_url('callback');
 
1581   print $form->parse_html_template('am/list_warehouses');
 
1583   $main::lxdebug->leave_sub();
 
1586 sub save_warehouse {
 
1587   $main::lxdebug->enter_sub();
 
1589   my $form     = $main::form;
 
1590   my %myconfig = %main::myconfig;
 
1591   my $locale   = $main::locale;
 
1593   $main::auth->assert('config');
 
1595   $form->isblank("description", $locale->text('Description missing!'));
 
1597   $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
 
1599   AM->save_warehouse(\%myconfig, $form);
 
1601   $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
 
1603   $form->redirect($locale->text('Warehouse saved.'));
 
1605   $main::lxdebug->leave_sub();
 
1608 sub delete_warehouse {
 
1609   $main::lxdebug->enter_sub();
 
1611   my $form     = $main::form;
 
1612   my %myconfig = %main::myconfig;
 
1613   my $locale   = $main::locale;
 
1615   $main::auth->assert('config');
 
1617   if (!$form->{confirmed}) {
 
1618     $form->{title} = $locale->text('Confirmation');
 
1621     print $form->parse_html_template('am/confirm_delete_warehouse');
 
1625   if (AM->delete_warehouse(\%myconfig, $form)) {
 
1626     $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
 
1627     $form->redirect($locale->text('Warehouse deleted.'));
 
1630     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
 
1633   $main::lxdebug->leave_sub();
 
1637   $main::lxdebug->enter_sub();
 
1639   my $form     = $main::form;
 
1640   my %myconfig = %main::myconfig;
 
1641   my $locale   = $main::locale;
 
1643   $main::auth->assert('config');
 
1645   AM->save_bins(\%myconfig, $form);
 
1647   $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
 
1649   $form->redirect($locale->text('Bins saved.'));
 
1651   $main::lxdebug->leave_sub();