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;
 
  49 require "bin/mozilla/common.pl";
 
  57 sub add      { call_sub("add_$main::form->{type}"); }
 
  58 sub delete   { call_sub("delete_$main::form->{type}"); }
 
  59 sub save     { call_sub("save_$main::form->{type}"); }
 
  60 sub edit     { call_sub("edit_$main::form->{type}"); }
 
  61 sub continue { call_sub($main::form->{"nextsub"}); }
 
  62 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
  65   $main::lxdebug->enter_sub();
 
  67   my $form     = $main::form;
 
  68   my %myconfig = %main::myconfig;
 
  70   $main::auth->assert('config');
 
  72   $form->{title}     = "Add";
 
  73   $form->{charttype} = "A";
 
  74   AM->get_account(\%myconfig, \%$form);
 
  76   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
 
  81   $main::lxdebug->leave_sub();
 
  85   $main::lxdebug->enter_sub();
 
  87   my $form     = $main::form;
 
  88   my %myconfig = %main::myconfig;
 
  90   $main::auth->assert('config');
 
  92   $form->{title} = "Edit";
 
  93   AM->get_account(\%myconfig, \%$form);
 
  95   foreach my $item (split(/:/, $form->{link})) {
 
  96     $form->{$item} = "checked";
 
 102   $main::lxdebug->leave_sub();
 
 106   $main::lxdebug->enter_sub();
 
 108   my $form     = $main::form;
 
 109   my %myconfig = %main::myconfig;
 
 110   my $locale   = $main::locale;
 
 112   $main::auth->assert('config');
 
 114   if ( $form->{action} eq 'edit_account') {
 
 115     $form->{account_exists} = '1';
 
 118   $form->{title} = $locale->text("$form->{title} Account");
 
 120   $form->{"$form->{charttype}_checked"} = "checked";
 
 121   $form->{"$form->{category}_checked"}  = "checked";
 
 123   $form->{select_tax} = "";
 
 125   my @tax_report_pos = USTVA->report_variables({
 
 126       myconfig   => \%myconfig,
 
 129       attribute  => 'position',
 
 133   if (@{ $form->{TAXKEY} }) {
 
 134     foreach my $item (@{ $form->{TAXKEY} }) {
 
 135       $item->{rate} = $item->{rate} * 100 . '%';
 
 138     # Fill in empty row for new Taxkey
 
 139     my $newtaxkey_ref = {
 
 144       taxdescription => '',
 
 151     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 154     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 156       # Fill in a runningnumber
 
 157       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 159       # Fill in the Taxkeys as select options
 
 160       foreach my $item (@{ $form->{TAXKEY} }) {
 
 161         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 162           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 163             qq|<option value="$item->{id}" selected="selected">|
 
 164             . sprintf("%.2d", $item->{taxkey})
 
 165             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 166             . $locale->text('Tax-o-matic Account')
 
 167             . qq|: $item->{chart_accno}\n|;
 
 170           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 171             qq|<option value="$item->{id}">|
 
 172             . sprintf("%.2d", $item->{taxkey})
 
 173             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 174             . $locale->text('Tax-o-matic Account')
 
 175             . qq|: $item->{chart_accno}\n|;
 
 180       # Fill in the USTVA Numbers as select options
 
 181       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 183           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 185         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 186           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 189           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 198   # Newaccount Folgekonto
 
 199   if (@{ $form->{NEWACCOUNT} || [] }) {
 
 200     if (!$form->{new_chart_valid}) {
 
 201       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 203     foreach my $item (@{ $form->{NEWACCOUNT} }) {
 
 204       if ($item->{id} == $form->{new_chart_id}) {
 
 205         $form->{selectnewaccount} .=
 
 206           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 207       } elsif (!$form->{new_chart_valid}) {
 
 208         $form->{selectnewaccount} .=
 
 209           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 215   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 218           2  => "sonstige Erlöse",
 
 219           3  => "Privatanteile",
 
 221           5  => "Ausserordentliche Erträge",
 
 222           6  => "Vereinnahmte Umsatzst.",
 
 223           7  => "Umsatzsteuererstattungen",
 
 224           8  => "Wareneingänge",
 
 225           9  => "Löhne und Gehälter",
 
 226           10 => "Gesetzl. sozialer Aufw.",
 
 228           12 => "Gas, Strom, Wasser",
 
 229           13 => "Instandhaltung",
 
 230           14 => "Steuern, Versich., Beiträge",
 
 232           16 => "Kfz-Versicherungen",
 
 233           17 => "Sonst. Fahrzeugkosten",
 
 234           18 => "Werbe- und Reisekosten",
 
 235           19 => "Instandhaltung u. Werkzeuge",
 
 236           20 => "Fachzeitschriften, Bücher",
 
 237           21 => "Miete für Einrichtungen",
 
 238           22 => "Rechts- und Beratungskosten",
 
 239           23 => "Bürobedarf, Porto, Telefon",
 
 240           24 => "Sonstige Aufwendungen",
 
 241           25 => "Abschreibungen auf Anlagever.",
 
 242           26 => "Abschreibungen auf GWG",
 
 244           28 => "Umsatzsteuerzahlungen",
 
 246           30 => "Ausserordentlicher Aufwand",
 
 247           31 => "Betriebliche Steuern");
 
 248   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
 
 249     my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
 
 250     if ($item == $form->{pos_eur}) {
 
 251       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 253       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 258   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 262              2  => 'Best.Verdg.FE/UE',
 
 263              3  => 'Aktiv.Eigenleistung',
 
 264              4  => 'Mat./Wareneinkauf',
 
 265              5  => 'So.betr.Erlöse',
 
 266              10 => 'Personalkosten',
 
 268              12 => 'Betriebl.Steuern',
 
 269              13 => 'Vers./Beiträge',
 
 270              14 => 'Kfz.Kosten o.St.',
 
 271              15 => 'Werbe-Reisek.',
 
 272              16 => 'Kosten Warenabgabe',
 
 273              17 => 'Abschreibungen',
 
 274              18 => 'Rep./instandhlt.',
 
 275              19 => 'Übrige Steuern',
 
 276              20 => 'Sonst.Kosten',
 
 278              31 => 'Sonst.neutr.Aufw.',
 
 280              33 => 'Sonst.neutr.Ertrag',
 
 281              34 => 'Verr.kalk.Kosten',
 
 282              35 => 'Steuern Eink.u.Ertr.');
 
 283   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
 
 284     my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
 
 285     if ($item == $form->{pos_bwa}) {
 
 286       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 288       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 293 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 294   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 295   foreach my $item ((1, 2, 3, 4)) {
 
 296     if ($item == $form->{pos_bilanz}) {
 
 297       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 299       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 304   # this is for our parser only! Do not remove.
 
 305   # type=submit $locale->text('Add Account')
 
 306   # type=submit $locale->text('Edit Account')
 
 308   $form->{type} = "account";
 
 310   # preselections category
 
 312   my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 315       'A'  => $locale->text('Asset'),
 
 316       'L'  => $locale->text('Liability'),
 
 317       'Q'  => $locale->text('Equity'),
 
 318       'I'  => $locale->text('Revenue'),
 
 319       'E'  => $locale->text('Expense'),
 
 320       'C'  => $locale->text('Costs'),
 
 322   foreach my $item ( sort({ $a <=> $b } keys %category) ) {
 
 323     if ($item eq $form->{category}) {
 
 324       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 326       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 331   # preselection chart type
 
 332   my $select_charttype = q{};
 
 335       'A'  => $locale->text('Account'),
 
 336       'H'  => $locale->text('Heading'),
 
 339   foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
 
 340     if ($item eq $form->{charttype}) {
 
 341       $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
 
 344       $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
 
 349   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 353   my $parameters_ref = {
 
 354     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 355     select_category            => $select_category,
 
 356     select_charttype           => $select_charttype,
 
 357     select_bwa                 => $select_bwa,
 
 358     select_bilanz              => $select_bilanz,
 
 359     select_eur                 => $select_eur,
 
 362   # Ausgabe des Templates
 
 363   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 366   $main::lxdebug->leave_sub();
 
 370   $main::lxdebug->enter_sub();
 
 372   my $form     = $main::form;
 
 373   my $locale   = $main::locale;
 
 375   $main::auth->assert('config');
 
 379 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
 
 382   if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
 
 384 <input type=submit class=submit name=action value="|
 
 385     . $locale->text('Save') . qq|">
 
 389   if ($form->{id} && $form->{orphaned}) {
 
 390     print qq|<input type=submit class=submit name=action value="|
 
 391       . $locale->text('Delete') . qq|">|;
 
 394   if ($form->{id} && $form->{type} eq "account") {
 
 396     <input class=submit type=submit name=action value="|
 
 397       . $locale->text('Save as new') . qq|">|;
 
 407   $main::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!'));
 
 426   $form->redirect($locale->text('Account saved!'))
 
 427     if (AM->save_account(\%myconfig, \%$form));
 
 428   $form->error($locale->text('Cannot save account!'));
 
 430   $main::lxdebug->leave_sub();
 
 433 sub save_as_new_account {
 
 434   $main::lxdebug->enter_sub();
 
 436   my $form     = $main::form;
 
 437   my %myconfig = %main::myconfig;
 
 438   my $locale   = $main::locale;
 
 440   $main::auth->assert('config');
 
 442   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 443   $form->isblank("description", $locale->text('Account Description missing!'));
 
 445   if ($form->{charttype} eq 'A'){
 
 446     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 449   for my $taxkey (0 .. 9) {
 
 450     if ($form->{"taxkey_id_$taxkey"}) {
 
 451       $form->{"taxkey_id_$taxkey"} = "NEW";
 
 456   if ($form->{"original_accno"} &&
 
 457       ($form->{"accno"} eq $form->{"original_accno"})) {
 
 458     $form->error($locale->text('Account Number already used!'));
 
 460   $form->redirect($locale->text('Account saved!'))
 
 461     if (AM->save_account(\%myconfig, \%$form));
 
 462   $form->error($locale->text('Cannot save account!'));
 
 464   $main::lxdebug->leave_sub();
 
 468   $main::lxdebug->enter_sub();
 
 470   my $form     = $main::form;
 
 471   my %myconfig = %main::myconfig;
 
 472   my $locale   = $main::locale;
 
 474   $main::auth->assert('config');
 
 476   $form->{callback}     = build_std_url('action=list_account');
 
 477   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 479   CA->all_accounts(\%myconfig, \%$form);
 
 481   foreach my $ca (@{ $form->{CA} }) {
 
 486     if ($ca->{amount} > 0) {
 
 487       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 489     if ($ca->{amount} < 0) {
 
 490       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 492     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:'';
 
 493     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 497   my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
 
 499   # Eneable AJAX debuging
 
 503   push(@ { $form->{AJAX} }, $pjx);
 
 505   $form->use_stylesheet("list_accounts.css");
 
 506   $form->{title}       = $locale->text('Chart of Accounts');
 
 511   my $parameters_ref = {
 
 512   #   hidden_variables                => $_hidden_variables_ref,
 
 515   # Ausgabe des Templates
 
 516   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
 518   $main::lxdebug->leave_sub();
 
 523 sub list_account_details {
 
 524 # Ajax Funktion aus list_account_details
 
 525   $main::lxdebug->enter_sub();
 
 527   my $form     = $main::form;
 
 528   my %myconfig = %main::myconfig;
 
 529   my $locale   = $main::locale;
 
 531   $main::auth->assert('config');
 
 533   my $chart_id = $form->{args};
 
 535   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 537   foreach my $ca (@{ $form->{CA} }) {
 
 539     $ca->{debit}  = " ";
 
 540     $ca->{credit} = " ";
 
 542     if ($ca->{amount} > 0) {
 
 544         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 546     if ($ca->{amount} < 0) {
 
 548         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 551     my @links = split( q{:}, $ca->{link});
 
 555     foreach my $link (@links){
 
 556       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 557                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 558                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 559                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 560                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 561                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 562                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 563                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 564                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 565                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 566                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 567                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 568                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 569                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 570                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 571 #               : ( $link eq 'CT_tax' )        ? $locale->text('Account Link CT_tax')
 
 572                : $locale->text('Unknown Link') . ': ' . $link;
 
 573       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 576     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 577                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 578                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 579                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 580                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 581                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 582                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 583                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 586   $form->{title} = $locale->text('Chart of Accounts');
 
 589   print $form->parse_html_template('am/list_account_details');
 
 591   $main::lxdebug->leave_sub();
 
 596   $main::lxdebug->enter_sub();
 
 598   my $form     = $main::form;
 
 599   my %myconfig = %main::myconfig;
 
 600   my $locale   = $main::locale;
 
 602   $main::auth->assert('config');
 
 604   $form->{title} = $locale->text('Delete Account');
 
 607     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
 
 609     if ($form->{id} == $form->{$id}) {
 
 610       $form->error($locale->text('Cannot delete default account!'));
 
 614   $form->redirect($locale->text('Account deleted!'))
 
 615     if (AM->delete_account(\%myconfig, \%$form));
 
 616   $form->error($locale->text('Cannot delete account!'));
 
 618   $main::lxdebug->leave_sub();
 
 622   $main::lxdebug->enter_sub();
 
 624   my $form     = $main::form;
 
 626   $main::auth->assert('config');
 
 628   $form->{title} = "Add";
 
 630   $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
 
 635   $main::lxdebug->leave_sub();
 
 639   $main::lxdebug->enter_sub();
 
 641   my $form     = $main::form;
 
 642   my %myconfig = %main::myconfig;
 
 644   $main::auth->assert('config');
 
 646   $form->{title} = "Edit";
 
 648   AM->get_lead(\%myconfig, \%$form);
 
 652   $form->{orphaned} = 1;
 
 655   $main::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   AM->lead(\%myconfig, \%$form);
 
 669   $form->{callback} = "am.pl?action=list_lead";
 
 671   my $callback = $form->escape($form->{callback});
 
 673   $form->{title} = $locale->text('Lead');
 
 675   my @column_index = qw(description cost profit);
 
 677   $column_header{description} =
 
 678       qq|<th class=listheading width=100%>|
 
 679     . $locale->text('Description')
 
 689     <th class=listtop>$form->{title}</th>
 
 692   <tr class=listheading>
 
 695   map { print "$column_header{$_}\n" } @column_index;
 
 701   my ($i, %column_data);
 
 702   foreach my $ref (@{ $form->{ALL} }) {
 
 708   <tr valign=top class=listrow$i>
 
 711 #    $lead = $ref->{lead};
 
 713     $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
 
 715     map { print "$column_data{$_}\n" } @column_index;
 
 724   <td><hr size=3 noshade></td>
 
 729 <form method=post action=am.pl>
 
 731 <input name=callback type=hidden value="$form->{callback}">
 
 733 <input type=hidden name=type value=lead>
 
 735 <input class=submit type=submit name=action value="|
 
 736     . $locale->text('Add') . qq|">
 
 744   $main::lxdebug->leave_sub();
 
 748   $main::lxdebug->enter_sub();
 
 750   my $form     = $main::form;
 
 751   my $locale   = $main::locale;
 
 753   $main::auth->assert('config');
 
 755   $form->{title} = $locale->text("$form->{title} Lead");
 
 757   # $locale->text('Add Lead')
 
 758   # $locale->text('Edit Lead')
 
 760   $form->{description} =~ s/\"/"/g;
 
 763       qq|<input name=description size=50 value="$form->{lead}">|;
 
 770 <form method=post action=am.pl>
 
 772 <input type=hidden name=id value=$form->{id}>
 
 773 <input type=hidden name=type value=lead>
 
 777     <th class=listtop colspan=2>$form->{title}</th>
 
 781     <th align=right>| . $locale->text('Description') . qq|</th>
 
 782     <td>$description</td>
 
 784     <td colspan=2><hr size=3 noshade></td>
 
 789   $main::lxdebug->leave_sub();
 
 793   $main::lxdebug->enter_sub();
 
 795   my $form     = $main::form;
 
 796   my %myconfig = %main::myconfig;
 
 797   my $locale   = $main::locale;
 
 799   $main::auth->assert('config');
 
 801   $form->isblank("description", $locale->text('Description missing!'));
 
 802   AM->save_lead(\%myconfig, \%$form);
 
 803   $form->redirect($locale->text('lead saved!'));
 
 805   $main::lxdebug->leave_sub();
 
 809   $main::lxdebug->enter_sub();
 
 811   my $form     = $main::form;
 
 812   my %myconfig = %main::myconfig;
 
 813   my $locale   = $main::locale;
 
 815   $main::auth->assert('config');
 
 817   AM->delete_lead(\%myconfig, \%$form);
 
 818   $form->redirect($locale->text('lead deleted!'));
 
 820   $main::lxdebug->leave_sub();
 
 824   $main::lxdebug->enter_sub();
 
 826   my $form     = $main::form;
 
 828   $main::auth->assert('config');
 
 830   $form->{title} = "Add";
 
 832   $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
 
 837   $main::lxdebug->leave_sub();
 
 841   $main::lxdebug->enter_sub();
 
 843   my $form     = $main::form;
 
 844   my %myconfig = %main::myconfig;
 
 846   $main::auth->assert('config');
 
 848   $form->{title} = "Edit";
 
 850   AM->get_language(\%myconfig, \%$form);
 
 854   $form->{orphaned} = 1;
 
 857   $main::lxdebug->leave_sub();
 
 861   $main::lxdebug->enter_sub();
 
 863   my $form     = $main::form;
 
 864   my %myconfig = %main::myconfig;
 
 865   my $locale   = $main::locale;
 
 867   $main::auth->assert('config');
 
 869   AM->language(\%myconfig, \%$form);
 
 871   $form->{callback} = "am.pl?action=list_language";
 
 873   my $callback = $form->escape($form->{callback});
 
 875   $form->{title} = $locale->text('Languages');
 
 877   my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
 
 879   $column_header{description} =
 
 880       qq|<th class=listheading width=60%>|
 
 881     . $locale->text('Description')
 
 883   $column_header{template_code} =
 
 884       qq|<th class=listheading width=10%>|
 
 885     . $locale->text('Template Code')
 
 887   $column_header{article_code} =
 
 888       qq|<th class=listheading>|
 
 889     . $locale->text('Article Code')
 
 891   $column_header{output_numberformat} =
 
 892       qq|<th class=listheading>|
 
 893     . $locale->text('Number Format')
 
 895   $column_header{output_dateformat} =
 
 896       qq|<th class=listheading>|
 
 897     . $locale->text('Date Format')
 
 899   $column_header{output_longdates} =
 
 900       qq|<th class=listheading>|
 
 901     . $locale->text('Long Dates')
 
 911     <th class=listtop>$form->{title}</th>
 
 917         <tr class=listheading>
 
 920   map { print "$column_header{$_}\n" } @column_index;
 
 926   my ($i, %column_data);
 
 927   foreach my $ref (@{ $form->{ALL} }) {
 
 933         <tr valign=top class=listrow$i>
 
 937     $column_data{description} =
 
 938       qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
 939     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
 
 940     $column_data{article_code} =
 
 941       qq|<td align=right>$ref->{article_code}</td>|;
 
 942     $column_data{output_numberformat} =
 
 944       ($ref->{output_numberformat} ? $ref->{output_numberformat} :
 
 945        $locale->text("use program settings")) .
 
 947     $column_data{output_dateformat} =
 
 949       ($ref->{output_dateformat} ? $ref->{output_dateformat} :
 
 950        $locale->text("use program settings")) .
 
 952     $column_data{output_longdates} =
 
 954       ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
 
 957     map { print "$column_data{$_}\n" } @column_index;
 
 969   <td><hr size=3 noshade></td>
 
 974 <form method=post action=am.pl>
 
 976 <input name=callback type=hidden value="$form->{callback}">
 
 978 <input type=hidden name=type value=language>
 
 980 <input class=submit type=submit name=action value="|
 
 981     . $locale->text('Add') . qq|">
 
 989   $main::lxdebug->leave_sub();
 
 992 sub language_header {
 
 993   $main::lxdebug->enter_sub();
 
 995   my $form     = $main::form;
 
 996   my $locale   = $main::locale;
 
 998   $main::auth->assert('config');
 
1000   $form->{title}    = $locale->text("$form->{title} Language");
 
1002   # $locale->text('Add Language')
 
1003   # $locale->text('Edit Language')
 
1005   $form->{description} =~ s/\"/"/g;
 
1006   $form->{template_code} =~ s/\"/"/g;
 
1007   $form->{article_code} =~ s/\"/"/g;
 
1013     qq|<option value="">| . $locale->text("use program settings") .
 
1015   foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
 
1017       ($item eq $form->{output_numberformat})
 
1018       ? "<option selected>$item"
 
1024     qq|<option value="">| . $locale->text("use program settings") .
 
1026   foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
 
1028       ($item eq $form->{output_dateformat})
 
1029       ? "<option selected>$item"
 
1037 <form method=post action=am.pl>
 
1039 <input type=hidden name=id value=$form->{id}>
 
1040 <input type=hidden name=type value=language>
 
1044     <th class=listtop colspan=2>$form->{title}</th>
 
1046   <tr height="5"></tr>
 
1048     <th align=right>| . $locale->text('Language') . qq|</th>
 
1049     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1052     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1053     <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
 
1056     <th align=right>| . $locale->text('Article Code') . qq|</th>
 
1057     <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
 
1060     <th align=right>| . $locale->text('Number Format') . qq|</th>
 
1061     <td><select name="output_numberformat">$numberformat</select></td>
 
1064     <th align=right>| . $locale->text('Date Format') . qq|</th>
 
1065     <td><select name="output_dateformat">$dateformat</select></td>
 
1068     <th align=right>| . $locale->text('Long Dates') . qq|</th>
 
1069     <td><input type="radio" name="output_longdates" value="1"| .
 
1070     ($form->{output_longdates} ? " checked" : "") .
 
1071     qq|>| . $locale->text("Yes") .
 
1072     qq|<input type="radio" name="output_longdates" value="0"| .
 
1073     ($form->{output_longdates} ? "" : " checked") .
 
1074     qq|>| . $locale->text("No") .
 
1077   <td colspan=2><hr size=3 noshade></td>
 
1082   $main::lxdebug->leave_sub();
 
1086   $main::lxdebug->enter_sub();
 
1088   my $form     = $main::form;
 
1089   my %myconfig = %main::myconfig;
 
1090   my $locale   = $main::locale;
 
1092   $main::auth->assert('config');
 
1094   $form->isblank("description", $locale->text('Language missing!'));
 
1095   $form->isblank("template_code", $locale->text('Template Code missing!'));
 
1096   $form->isblank("article_code", $locale->text('Article Code missing!'));
 
1097   AM->save_language(\%myconfig, \%$form);
 
1098   $form->redirect($locale->text('Language saved!'));
 
1100   $main::lxdebug->leave_sub();
 
1103 sub delete_language {
 
1104   $main::lxdebug->enter_sub();
 
1106   my $form     = $main::form;
 
1107   my %myconfig = %main::myconfig;
 
1108   my $locale   = $main::locale;
 
1110   $main::auth->assert('config');
 
1112   AM->delete_language(\%myconfig, \%$form);
 
1113   $form->redirect($locale->text('Language deleted!'));
 
1115   $main::lxdebug->leave_sub();
 
1119 sub add_buchungsgruppe {
 
1120   $main::lxdebug->enter_sub();
 
1122   my $form     = $main::form;
 
1123   my %myconfig = %main::myconfig;
 
1124   my $locale   = $main::locale;
 
1126   $main::auth->assert('config');
 
1128   # $locale->text("Add Buchungsgruppe")
 
1129   # $locale->text("Edit Buchungsgruppe")
 
1130   $form->{title} = "Add";
 
1132   $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
 
1134   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1135   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
 
1136   for (my $i = 0; 4 > $i; $i++) {
 
1137     map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
 
1138         qw(income expense));
 
1141   &buchungsgruppe_header;
 
1144   $main::lxdebug->leave_sub();
 
1147 sub edit_buchungsgruppe {
 
1148   $main::lxdebug->enter_sub();
 
1150   my $form     = $main::form;
 
1151   my %myconfig = %main::myconfig;
 
1153   $main::auth->assert('config');
 
1155   $form->{title} = "Edit";
 
1157   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1159   &buchungsgruppe_header;
 
1163   $main::lxdebug->leave_sub();
 
1166 sub list_buchungsgruppe {
 
1167   $main::lxdebug->enter_sub();
 
1169   my $form     = $main::form;
 
1170   my %myconfig = %main::myconfig;
 
1171   my $locale   = $main::locale;
 
1173   $main::auth->assert('config');
 
1175   AM->buchungsgruppe(\%myconfig, \%$form);
 
1177   $form->{callback} = "am.pl?action=list_buchungsgruppe";
 
1179   my $callback = $form->escape($form->{callback});
 
1181   $form->{title} = $locale->text('Buchungsgruppen');
 
1183   my @column_index = qw(up down description inventory_accno
 
1184                      income_accno_0 expense_accno_0
 
1185                      income_accno_1 expense_accno_1
 
1186                      income_accno_2 expense_accno_2
 
1187                      income_accno_3 expense_accno_3 );
 
1189   $column_header{up} =
 
1190       qq|<th class="listheading" width="16">|
 
1191     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
1193   $column_header{down} =
 
1194       qq|<th class="listheading" width="16">|
 
1195     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
1197   $column_header{description} =
 
1198       qq|<th class="listheading" width="40%">|
 
1199     . $locale->text('Description')
 
1201   $column_header{inventory_accno} =
 
1202       qq|<th class=listheading>|
 
1203     . $locale->text('Bestandskonto')
 
1205   $column_header{income_accno_0} =
 
1206       qq|<th class=listheading>|
 
1207     . $locale->text('National Revenues')
 
1209   $column_header{expense_accno_0} =
 
1210       qq|<th class=listheading>|
 
1211     . $locale->text('National Expenses')
 
1213   $column_header{income_accno_1} =
 
1214       qq|<th class=listheading>|
 
1215     . $locale->text('Revenues EU with UStId')
 
1217   $column_header{expense_accno_1} =
 
1218       qq|<th class=listheading>|
 
1219     . $locale->text('Expenses EU with UStId')
 
1221   $column_header{income_accno_2} =
 
1222       qq|<th class=listheading>|
 
1223     . $locale->text('Revenues EU without UStId')
 
1225   $column_header{expense_accno_2} =
 
1226       qq|<th class=listheading>|
 
1227     . $locale->text('Expenses EU without UStId')
 
1229   $column_header{income_accno_3} =
 
1230       qq|<th class=listheading>|
 
1231     . $locale->text('Foreign Revenues')
 
1233   $column_header{expense_accno_3} =
 
1234       qq|<th class=listheading>|
 
1235     . $locale->text('Foreign Expenses')
 
1244     <th class=listtop>$form->{title}</th>
 
1246   <tr height="5"></tr>
 
1250         <tr class=listheading>
 
1253   map { print "$column_header{$_}\n" } @column_index;
 
1259   my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
 
1262   my ($i, %column_data);
 
1263   foreach my $ref (@{ $form->{ALL} }) {
 
1269         <tr valign=top class=listrow$i>
 
1273       my $pref = $form->{ALL}->[$row - 1];
 
1275         qq|<td align="center" valign="center" width="16">| .
 
1276         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
 
1277         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
1280       $column_data{up} = qq|<td width="16"> </td>|;
 
1283     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
1284       $column_data{down} = qq|<td width="16"> </td>|;
 
1286       my $nref = $form->{ALL}->[$row + 1];
 
1287       $column_data{down} =
 
1288         qq|<td align="center" valign="center" width="16">| .
 
1289         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
 
1290         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
1294     $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1295     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
 
1296     $column_data{income_accno_0} =
 
1297       qq|<td align=right>$ref->{income_accno_0}</td>|;
 
1298     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
 
1299     $column_data{income_accno_1} =
 
1300       qq|<td align=right>$ref->{income_accno_1}</td>|;
 
1301     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
 
1302     $column_data{income_accno_2} =
 
1303       qq|<td align=right>$ref->{income_accno_2}</td>|;
 
1304     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
 
1305     $column_data{income_accno_3} =
 
1306       qq|<td align=right>$ref->{income_accno_3}</td>|;
 
1307     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
 
1309     map { print "$column_data{$_}\n" } @column_index;
 
1323   <td><hr size=3 noshade></td>
 
1328 <form method=post action=am.pl>
 
1330 <input name=callback type=hidden value="$form->{callback}">
 
1332 <input type=hidden name=type value=buchungsgruppe>
 
1334 <input class=submit type=submit name=action value="|
 
1335     . $locale->text('Add') . qq|">
 
1343   $main::lxdebug->leave_sub();
 
1346 sub buchungsgruppe_header {
 
1347   $main::lxdebug->enter_sub();
 
1349   my $form     = $main::form;
 
1350   my $locale   = $main::locale;
 
1352   $main::auth->assert('config');
 
1354   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
 
1356   # $locale->text('Add Accounting Group')
 
1357   # $locale->text('Edit Accounting Group')
 
1359   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
 
1360   my %acc_type_map = (
 
1361     "IC" => $acc_inventory,
 
1362     "IC_income" => $acc_income,
 
1363     "IC_sale" => $acc_income,
 
1364     "IC_expense" => $acc_expense,
 
1365     "IC_cogs" => $acc_expense,
 
1368   foreach my $key (keys(%acc_type_map)) {
 
1369     foreach my $ref (@{ $form->{IC_links}{$key} }) {
 
1370       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
 
1374   foreach my $type (qw(IC IC_income IC_expense)) {
 
1375     $form->{"select$type"} =
 
1377            map({ "<option value=$_->{id} $_->{selected}>" .
 
1378                    "$_->{accno}--" . H($_->{description}) . "</option>" }
 
1379                sort({ $a->{"accno"} cmp $b->{"accno"} }
 
1380                     values(%{$acc_type_map{$type}}))));
 
1384     $form->{selectIC} =~ s/selected//g;
 
1385     $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/  value=$form->{inventory_accno_id} selected/;
 
1386     $form->{selectIC_income} =~ s/selected//g;
 
1387     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/  value=$form->{income_accno_id_0} selected/;
 
1388     $form->{selectIC_expense} =~ s/selected//g;
 
1389     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
 
1393   if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { # was !$::lx_office_conf{system}->{eur}) {
 
1396                 <th align=right>| . $locale->text('Inventory') . qq|</th>
 
1397                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
 
1398                 <input name=selectIC type=hidden value="$form->{selectIC}">
 
1400   } elsif ( $::instance_conf->get_inventory_system eq 'periodic' ) {
 
1401     # don't allow choice of inventory accno and don't show that line
 
1403                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
 
1407   $linkaccounts .= qq|
 
1409                 <th align=right>| . $locale->text('National Revenues') . qq|</th>
 
1410                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
 
1413                 <th align=right>| . $locale->text('National Expenses') . qq|</th>
 
1414                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
 
1417     $form->{selectIC_income} =~ s/selected//g;
 
1418     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/  value=$form->{income_accno_id_1} selected/;
 
1419     $form->{selectIC_expense} =~ s/selected//g;
 
1420     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/  value=$form->{expense_accno_id_1} selected/;
 
1422   $linkaccounts .= qq|              <tr>
 
1423                 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
 
1424                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
 
1427                 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
 
1428                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
 
1432     $form->{selectIC_income} =~ s/selected//g;
 
1433     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/  value=$form->{income_accno_id_2} selected/;
 
1434     $form->{selectIC_expense} =~ s/selected//g;
 
1435     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/  value=$form->{expense_accno_id_2} selected/;
 
1438   $linkaccounts .= qq|              <tr>
 
1439                 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
 
1440                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
 
1443                 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
 
1444                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
 
1448     $form->{selectIC_income} =~ s/selected//g;
 
1449     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/  value=$form->{income_accno_id_3} selected/;
 
1450     $form->{selectIC_expense} =~ s/selected//g;
 
1451     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/  value=$form->{expense_accno_id_3} selected/;
 
1454   $linkaccounts .= qq|              <tr>
 
1455                 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
 
1456                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
 
1459                 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
 
1460                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
 
1470 <form method=post action=am.pl>
 
1472 <input type=hidden name=id value=$form->{id}>
 
1473 <input type=hidden name=type value=buchungsgruppe>
 
1477     <th class=listtop colspan=2>$form->{title}</th>
 
1479   <tr height="5"></tr>
 
1481     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
 
1482     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1485   <td colspan=2><hr size=3 noshade></td>
 
1490   $main::lxdebug->leave_sub();
 
1493 sub save_buchungsgruppe {
 
1494   $main::lxdebug->enter_sub();
 
1496   my $form     = $main::form;
 
1497   my %myconfig = %main::myconfig;
 
1498   my $locale   = $main::locale;
 
1500   $main::auth->assert('config');
 
1502   $form->isblank("description", $locale->text('Description missing!'));
 
1504   AM->save_buchungsgruppe(\%myconfig, \%$form);
 
1505   $form->redirect($locale->text('Accounting Group saved!'));
 
1507   $main::lxdebug->leave_sub();
 
1510 sub delete_buchungsgruppe {
 
1511   $main::lxdebug->enter_sub();
 
1513   my $form     = $main::form;
 
1514   my %myconfig = %main::myconfig;
 
1515   my $locale   = $main::locale;
 
1517   $main::auth->assert('config');
 
1519   AM->delete_buchungsgruppe(\%myconfig, \%$form);
 
1520   $form->redirect($locale->text('Accounting Group deleted!'));
 
1522   $main::lxdebug->leave_sub();
 
1525 sub swap_buchungsgruppen {
 
1526   $main::lxdebug->enter_sub();
 
1528   my $form     = $main::form;
 
1529   my %myconfig = %main::myconfig;
 
1531   $main::auth->assert('config');
 
1533   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
 
1534   list_buchungsgruppe();
 
1536   $main::lxdebug->leave_sub();
 
1540   $main::lxdebug->enter_sub();
 
1542   my $form     = $main::form;
 
1543   my %myconfig = %main::myconfig;
 
1544   my $locale   = $main::locale;
 
1546   # get defaults for account numbers and last numbers
 
1547   AM->defaultaccounts(\%myconfig, \%$form);
 
1548   $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
 
1550   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
 
1552 # EÜR = cash, Bilanzierung = accrual 
 
1554   foreach my $key (keys %{ $form->{IC} }) {
 
1555     foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
 
1556       my $array = "ACCNOS_" . uc($key);
 
1557       $form->{$array} ||= [];
 
1559       my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
 
1560       push @{ $form->{$array} }, {
 
1563         'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
 
1568   $form->{title} = $locale->text('Ranges of numbers and default accounts');
 
1571   print $form->parse_html_template('am/edit_defaults');
 
1573   $main::lxdebug->leave_sub();
 
1577   $main::lxdebug->enter_sub();
 
1579   my $form     = $main::form;
 
1580   my $locale   = $main::locale;
 
1582   AM->save_defaults();
 
1584   $form->redirect($locale->text('Defaults saved.'));
 
1586   $main::lxdebug->leave_sub();
 
1589 sub _build_cfg_options {
 
1590   my $form     = $main::form;
 
1591   my %myconfig = %main::myconfig;
 
1594   my $array = uc($idx) . 'S';
 
1596   $form->{$array} = [];
 
1597   foreach my $item (@_) {
 
1598     push @{ $form->{$array} }, {
 
1601       'selected' => $item eq $myconfig{$idx},
 
1607   $main::lxdebug->enter_sub();
 
1609   my $form     = $main::form;
 
1610   my %myconfig = %main::myconfig;
 
1611   my $locale   = $main::locale;
 
1613   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
1614   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
1617   if ($::lx_office_conf{print_templates}->{opendocument}
 
1618       && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
 
1619       && $::lx_office_conf{applications}->{xvfb}                 && (-x $::lx_office_conf{applications}->{xvfb})) {
 
1620     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
1621                      "value" => "opendocument_pdf" });
 
1623   if ($::lx_office_conf{print_templates}->{latex}) {
 
1624     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
1626   push(@formats, { "name" => "HTML", "value" => "html" });
 
1627   if ($::lx_office_conf{print_templates}->{latex}) {
 
1628     push(@formats, { "name" => $locale->text("Postscript"),
 
1629                      "value" => "postscript" });
 
1631   if ($::lx_office_conf{print_templates}->{opendocument}) {
 
1632     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
1633                      "value" => "opendocument" });
 
1636   if (!$myconfig{"template_format"}) {
 
1637     $myconfig{"template_format"} = "pdf";
 
1639   $form->{TEMPLATE_FORMATS} = [];
 
1640   foreach my $item (@formats) {
 
1641     push @{ $form->{TEMPLATE_FORMATS} }, {
 
1642       'name'     => $item->{name},
 
1643       'value'    => $item->{value},
 
1644       'selected' => $item->{value} eq $myconfig{template_format},
 
1648   if (!$myconfig{"default_media"}) {
 
1649     $myconfig{"default_media"} = "screen";
 
1652   my %selected = ($myconfig{"default_media"} => "selected");
 
1654     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
1655     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
1656     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
1659   $form->{PRINTERS} = [];
 
1660   foreach my $printer (SL::Printer->all_printers(%::myconfig)) {
 
1661     push @{ $form->{PRINTERS} }, {
 
1662       'name'     => $printer->{printer_description},
 
1663       'value'    => $printer->{id},
 
1664       'selected' => $printer->{id} == $myconfig{default_printer_id},
 
1668   my %countrycodes = User->country_codes;
 
1670   $form->{COUNTRYCODES} = [];
 
1671   foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
1672     push @{ $form->{COUNTRYCODES} }, {
 
1673       'name'     => $countrycodes{$countrycode},
 
1674       'value'    => $countrycode,
 
1675       'selected' => $countrycode eq $myconfig{countrycode},
 
1679   $form->{STYLESHEETS} = [];
 
1680   foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
 
1681     push @{ $form->{STYLESHEETS} }, {
 
1684       'selected' => $item eq $myconfig{stylesheet},
 
1688   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
 
1689   $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
1690   $form->{todo_cfg}            = { TODO->get_user_config('login' => $form->{login}) };
 
1692   $form->{title}               = $locale->text('Edit Preferences for #1', $form->{login});
 
1695   print $form->parse_html_template('am/config');
 
1697   $main::lxdebug->leave_sub();
 
1700 sub save_preferences {
 
1701   $main::lxdebug->enter_sub();
 
1703   my $form     = $main::form;
 
1704   my %myconfig = %main::myconfig;
 
1705   my $locale   = $main::locale;
 
1707   $form->{stylesheet} = $form->{usestylesheet};
 
1709   TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
 
1711   if (AM->save_preferences(\%myconfig, $form)) {
 
1712     if ($::auth->can_change_password()
 
1713         && defined $form->{new_password}
 
1714         && ($form->{new_password} ne '********')) {
 
1715       my $verifier = SL::Auth::PasswordPolicy->new;
 
1716       my $result   = $verifier->verify($form->{new_password});
 
1718       if ($result != SL::Auth::PasswordPolicy->OK()) {
 
1719         $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
 
1722       $::auth->change_password($form->{login}, $form->{new_password});
 
1724       $form->{password} = $form->{new_password};
 
1725       $::auth->set_session_value('password', $form->{password});
 
1726       $::auth->create_or_refresh_session();
 
1729     $form->redirect($locale->text('Preferences saved!'));
 
1732   $form->error($locale->text('Cannot save preferences!'));
 
1734   $main::lxdebug->leave_sub();
 
1738   $main::lxdebug->enter_sub();
 
1740   my $form     = $main::form;
 
1741   my %myconfig = %main::myconfig;
 
1742   my $locale   = $main::locale;
 
1744   $main::auth->assert('config');
 
1746   $form->{title} = $locale->text('Audit Control');
 
1748   AM->closedto(\%myconfig, \%$form);
 
1755 <form method=post action=am.pl>
 
1758   <tr><th class=listtop>$form->{title}</th></tr>
 
1759   <tr height="5"></tr>
 
1764           <th>| . $locale->text('Close Books up to') . qq|</th>
 
1765           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
 
1775 <input type=hidden name=nextsub value=doclose>
 
1777 <input type=submit class=submit name=action value="|
 
1778     . $locale->text('Continue') . qq|">
 
1786   $main::lxdebug->leave_sub();
 
1790   $main::lxdebug->enter_sub();
 
1792   my $form     = $main::form;
 
1793   my %myconfig = %main::myconfig;
 
1794   my $locale   = $main::locale;
 
1796   $main::auth->assert('config');
 
1798   AM->closebooks(\%myconfig, \%$form);
 
1800   if ($form->{closedto}) {
 
1802                     $locale->text('Books closed up to') . " "
 
1803                       . $locale->date(\%myconfig, $form->{closedto}, 1));
 
1805     $form->redirect($locale->text('Books are open'));
 
1808   $main::lxdebug->leave_sub();
 
1812   $main::lxdebug->enter_sub();
 
1814   my $form     = $main::form;
 
1815   my %myconfig = %main::myconfig;
 
1816   my $locale   = $main::locale;
 
1818   $main::auth->assert('config');
 
1820   my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
1821   AM->units_in_use(\%myconfig, $form, $units);
 
1822   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
1824   my @languages = AM->language(\%myconfig, $form, 1);
 
1826   my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
1829   foreach (@unit_list) {
 
1830     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
1831     $_->{"UNITLANGUAGES"} = [];
 
1832     foreach my $lang (@languages) {
 
1833       push(@{ $_->{"UNITLANGUAGES"} },
 
1835              "unit" => $_->{"name"},
 
1836              "language_id" => $lang->{"id"},
 
1837              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
1838              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
1844   $units = AM->retrieve_units(\%myconfig, $form);
 
1845   my $ddbox = AM->unit_select_data($units, undef, 1);
 
1847   $form->{"title"} = $locale->text("Add and edit units");
 
1849   print($form->parse_html_template("am/edit_units",
 
1850                                    { "UNITS"               => \@unit_list,
 
1851                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
1852                                      "LANGUAGES"           => \@languages,
 
1855   $main::lxdebug->leave_sub();
 
1859   $main::lxdebug->enter_sub();
 
1861   my $form     = $main::form;
 
1862   my %myconfig = %main::myconfig;
 
1863   my $locale   = $main::locale;
 
1865   $main::auth->assert('config');
 
1867   $form->isblank("new_name", $locale->text("The name is missing."));
 
1868   my $units = AM->retrieve_units(\%myconfig, $form);
 
1869   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
1870   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
1872   my ($base_unit, $factor);
 
1873   if ($form->{"new_base_unit"}) {
 
1874     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
1876     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
1877     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
1878     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
1879     $base_unit = $form->{"new_base_unit"};
 
1883   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
1884     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
1885     push(@languages, { "id" => $lang->{"id"},
 
1886                        "localized" => $form->{"new_localized_$lang->{id}"},
 
1887                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
1891   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
1893   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
1897   $main::lxdebug->leave_sub();
 
1900 sub set_unit_languages {
 
1901   $main::lxdebug->enter_sub();
 
1903   my $form     = $main::form;
 
1905   $main::auth->assert('config');
 
1907   my ($unit, $languages, $idx) = @_;
 
1909   $unit->{"LANGUAGES"} = [];
 
1911   foreach my $lang (@{$languages}) {
 
1912     push(@{ $unit->{"LANGUAGES"} },
 
1913          { "id" => $lang->{"id"},
 
1914            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
1915            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
1919   $main::lxdebug->leave_sub();
 
1923   $main::lxdebug->enter_sub();
 
1925   my $form     = $main::form;
 
1926   my %myconfig = %main::myconfig;
 
1927   my $locale   = $main::locale;
 
1929   $main::auth->assert('config');
 
1931   my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
1932   AM->units_in_use(\%myconfig, $form, $old_units);
 
1934   my @languages = AM->language(\%myconfig, $form, 1);
 
1937   my @delete_units = ();
 
1938   foreach my $i (1..($form->{"rowcount"} * 1)) {
 
1939     my $old_unit = $old_units->{$form->{"old_name_$i"}};
 
1941       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
1944     if ($form->{"unchangeable_$i"}) {
 
1945       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
1946       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
1947       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
1951     if ($old_unit->{"in_use"}) {
 
1952       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
1955     if ($form->{"delete_$i"}) {
 
1956       push(@delete_units, $old_unit->{"name"});
 
1960     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
1962     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
1963     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
1964     $new_units->{$form->{"name_$i"}} = \%h;
 
1965     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
1966     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
1969   foreach my $unit (values(%{$new_units})) {
 
1970     next unless ($unit->{"old_name"});
 
1971     if ($unit->{"base_unit"}) {
 
1972       $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"}))
 
1973         unless (defined($new_units->{$unit->{"base_unit"}}));
 
1974       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
1975       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
1977       $unit->{"base_unit"} = undef;
 
1978       $unit->{"factor"} = undef;
 
1982   foreach my $unit (values(%{$new_units})) {
 
1983     next if ($unit->{"unchanged_unit"});
 
1985     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
1986     my $new_unit = $unit;
 
1987     while ($new_unit->{"base_unit"}) {
 
1988       $new_unit->{"seen"} = 1;
 
1989       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
1990       if ($new_unit->{"seen"}) {
 
1991         $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, " .
 
1992                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
1997   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
1999   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
2003   $main::lxdebug->leave_sub();
 
2006 sub show_history_search {
 
2007   $main::lxdebug->enter_sub();
 
2009   my $form     = $main::form;
 
2010   my $locale   = $main::locale;
 
2012   $main::auth->assert('config');
 
2014   $form->{title} = $locale->text("History Search");
 
2017   print $form->parse_html_template("common/search_history");
 
2019   $main::lxdebug->leave_sub();
 
2022 sub show_am_history {
 
2023   $main::lxdebug->enter_sub();
 
2025   my $form     = $main::form;
 
2026   my %myconfig = %main::myconfig;
 
2027   my $locale   = $main::locale;
 
2029   $main::auth->assert('config');
 
2031   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
 
2032   $form->{order} ||= 'h.itime--1';
 
2034   my %search = ( "Artikelnummer"          => "parts",
 
2035                  "Kundennummer"           => "customer",
 
2036                  "Lieferantennummer"      => "vendor",
 
2037                  "Projektnummer"          => "project",
 
2038                  "Buchungsnummer"         => "oe",
 
2039                  "Eingangsrechnungnummer" => "ap",
 
2040                  "Ausgangsrechnungnummer" => "ar",
 
2041                  "Mahnungsnummer"         => "dunning"
 
2043   my %searchNo = ( "Artikelnummer"          => "partnumber",
 
2044                    "Kundennummer"           => "customernumber",
 
2045                    "Lieferantennummer"      => "vendornumber",
 
2046                    "Projektnummer"          => "projectnumber",
 
2047                    "Buchungsnummer"         => "ordnumber",
 
2048                    "Eingangsrechnungnummer" => "invnumber",
 
2049                    "Ausgangsrechnungnummer" => "invnumber",
 
2050                    "Mahnungsnummer"         => "dunning_id"
 
2053   my $dbh = $form->dbconnect(\%myconfig);
 
2055   my $restriction  = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
 
2056   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
 
2057   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
 
2058   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
2059     $restriction  .= qq| AND employee_id = |    . $form->{mitarbeiter};
 
2060   } elsif ($form->{mitarbeiter}) {
 
2061     $restriction  .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
 
2064   my $query = qq|SELECT trans_id AS id FROM history_erp | .
 
2065     (  $form->{'searchid'} ? qq| WHERE snumbers = '|  . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
 
2066      :                       qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
2068   my @ids    = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
 
2069   my $daten .= shift @ids;
 
2070   $daten    .= join '', map { " OR trans_id = $_" } @ids;
 
2072   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
2073   $sort =~ s/.*\.(.*)$/$1/;
 
2075   $form->{title} = $locale->text("History Search");
 
2078   print $form->parse_html_template("common/show_history",
 
2079                                    { "DATEN"          => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
2080                                      "SUCCESS"        => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
2083                                      uc($sort) . "BY" => $sortby,
 
2084                                      'callback'       => $callback,
 
2088   $main::lxdebug->leave_sub();
 
2092   $main::lxdebug->enter_sub();
 
2094   my $form     = $main::form;
 
2095   my $locale   = $main::locale;
 
2097   $main::auth->assert('config');
 
2099   $form->{title} =  $locale->text('Add');
 
2101   $form->{callback} ||= "am.pl?action=add_tax";
 
2103   _get_taxaccount_selection();
 
2107   my $parameters_ref = {
 
2108 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
2111   # Ausgabe des Templates
 
2112   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
2114   $main::lxdebug->leave_sub();
 
2118   $main::lxdebug->enter_sub();
 
2120   my $form     = $main::form;
 
2121   my %myconfig = %main::myconfig;
 
2122   my $locale   = $main::locale;
 
2124   $main::auth->assert('config');
 
2126   $form->{title} =  $locale->text('Edit');
 
2128   AM->get_tax(\%myconfig, \%$form);
 
2129   _get_taxaccount_selection();
 
2131   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
2135   my $parameters_ref = {
 
2138   # Ausgabe des Templates
 
2139   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
2141   $main::lxdebug->leave_sub();
 
2145   $main::lxdebug->enter_sub();
 
2147   my $form     = $main::form;
 
2148   my %myconfig = %main::myconfig;
 
2149   my $locale   = $main::locale;
 
2151   $main::auth->assert('config');
 
2153   AM->taxes(\%myconfig, \%$form);
 
2155   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
2157   $form->{callback} = build_std_url('action=list_tax');
 
2159   $form->{title} = $locale->text('Tax-O-Matic');
 
2163   my $parameters_ref = {
 
2166   # Ausgabe des Templates
 
2167   print($form->parse_html_template('am/list_tax', $parameters_ref));
 
2169   $main::lxdebug->leave_sub();
 
2172 sub _get_taxaccount_selection{
 
2173   $main::lxdebug->enter_sub();
 
2175   my $form     = $main::form;
 
2176   my %myconfig = %main::myconfig;
 
2178   $main::auth->assert('config');
 
2180   AM->get_tax_accounts(\%myconfig, \%$form);
 
2182   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
2184   $main::lxdebug->leave_sub();
 
2188   $main::lxdebug->enter_sub();
 
2190   my $form     = $main::form;
 
2191   my %myconfig = %main::myconfig;
 
2192   my $locale   = $main::locale;
 
2194   $main::auth->assert('config');
 
2196   $form->isblank("rate", $locale->text('Taxrate missing!'));
 
2197   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
 
2198   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
 
2200   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
2202   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
2203     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
2206   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
2207     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
2210   AM->save_tax(\%myconfig, \%$form);
 
2211   $form->redirect($locale->text('Tax saved!'));
 
2213   $main::lxdebug->leave_sub();
 
2217   $main::lxdebug->enter_sub();
 
2219   my $form     = $main::form;
 
2220   my %myconfig = %main::myconfig;
 
2221   my $locale   = $main::locale;
 
2223   $main::auth->assert('config');
 
2225   AM->delete_tax(\%myconfig, \%$form);
 
2226   $form->redirect($locale->text('Tax deleted!'));
 
2228   $main::lxdebug->leave_sub();
 
2231 sub add_price_factor {
 
2232   $main::lxdebug->enter_sub();
 
2234   my $form     = $main::form;
 
2235   my $locale   = $main::locale;
 
2237   $main::auth->assert('config');
 
2239   $form->{title}      = $locale->text('Add Price Factor');
 
2240   $form->{callback} ||= build_std_url('action=add_price_factor');
 
2241   $form->{fokus}      = 'description';
 
2244   print $form->parse_html_template('am/edit_price_factor');
 
2246   $main::lxdebug->leave_sub();
 
2249 sub edit_price_factor {
 
2250   $main::lxdebug->enter_sub();
 
2252   my $form     = $main::form;
 
2253   my %myconfig = %main::myconfig;
 
2254   my $locale   = $main::locale;
 
2256   $main::auth->assert('config');
 
2258   $form->{title}      = $locale->text('Edit Price Factor');
 
2259   $form->{callback} ||= build_std_url('action=add_price_factor');
 
2260   $form->{fokus}      = 'description';
 
2262   AM->get_price_factor(\%myconfig, $form);
 
2264   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
 
2267   print $form->parse_html_template('am/edit_price_factor');
 
2269   $main::lxdebug->leave_sub();
 
2272 sub list_price_factors {
 
2273   $main::lxdebug->enter_sub();
 
2275   my $form     = $main::form;
 
2276   my %myconfig = %main::myconfig;
 
2277   my $locale   = $main::locale;
 
2279   $main::auth->assert('config');
 
2281   AM->get_all_price_factors(\%myconfig, \%$form);
 
2283   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
 
2284     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
 
2287   $form->{callback} = build_std_url('action=list_price_factors');
 
2288   $form->{title}    = $locale->text('Price Factors');
 
2289   $form->{url_base} = build_std_url('callback');
 
2292   print $form->parse_html_template('am/list_price_factors');
 
2294   $main::lxdebug->leave_sub();
 
2297 sub save_price_factor {
 
2298   $main::lxdebug->enter_sub();
 
2300   my $form     = $main::form;
 
2301   my %myconfig = %main::myconfig;
 
2302   my $locale   = $main::locale;
 
2304   $main::auth->assert('config');
 
2306   $form->isblank("description", $locale->text('Description missing!'));
 
2307   $form->isblank("factor", $locale->text('Factor missing!'));
 
2309   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
 
2311   AM->save_price_factor(\%myconfig, $form);
 
2313   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
 
2315   $form->redirect($locale->text('Price factor saved!'));
 
2317   $main::lxdebug->leave_sub();
 
2320 sub delete_price_factor {
 
2321   $main::lxdebug->enter_sub();
 
2323   my $form     = $main::form;
 
2324   my %myconfig = %main::myconfig;
 
2325   my $locale   = $main::locale;
 
2327   $main::auth->assert('config');
 
2329   AM->delete_price_factor(\%myconfig, \%$form);
 
2331   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
 
2333   $form->redirect($locale->text('Price factor deleted!'));
 
2335   $main::lxdebug->leave_sub();
 
2339   $main::lxdebug->enter_sub();
 
2341   my $form     = $main::form;
 
2342   my $locale   = $main::locale;
 
2344   $main::auth->assert('config');
 
2346   $form->{title}      = $locale->text('Add Warehouse');
 
2347   $form->{callback} ||= build_std_url('action=add_warehouse');
 
2348   $form->{fokus}      = 'description';
 
2351   print $form->parse_html_template('am/edit_warehouse');
 
2353   $main::lxdebug->leave_sub();
 
2356 sub edit_warehouse {
 
2357   $main::lxdebug->enter_sub();
 
2359   my $form     = $main::form;
 
2360   my %myconfig = %main::myconfig;
 
2361   my $locale   = $main::locale;
 
2363   $main::auth->assert('config');
 
2365   AM->get_warehouse(\%myconfig, $form);
 
2367   $form->get_lists('employees' => 'EMPLOYEES');
 
2369   $form->{title}      = $locale->text('Edit Warehouse');
 
2370   $form->{callback} ||= build_std_url('action=list_warehouses');
 
2371   $form->{fokus}      = 'description';
 
2374   print $form->parse_html_template('am/edit_warehouse');
 
2376   $main::lxdebug->leave_sub();
 
2379 sub list_warehouses {
 
2380   $main::lxdebug->enter_sub();
 
2382   my $form     = $main::form;
 
2383   my %myconfig = %main::myconfig;
 
2384   my $locale   = $main::locale;
 
2386   $main::auth->assert('config');
 
2388   AM->get_all_warehouses(\%myconfig, $form);
 
2390   $form->{callback} = build_std_url('action=list_warehouses');
 
2391   $form->{title}    = $locale->text('Warehouses');
 
2392   $form->{url_base} = build_std_url('callback');
 
2395   print $form->parse_html_template('am/list_warehouses');
 
2397   $main::lxdebug->leave_sub();
 
2400 sub save_warehouse {
 
2401   $main::lxdebug->enter_sub();
 
2403   my $form     = $main::form;
 
2404   my %myconfig = %main::myconfig;
 
2405   my $locale   = $main::locale;
 
2407   $main::auth->assert('config');
 
2409   $form->isblank("description", $locale->text('Description missing!'));
 
2411   $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
 
2413   AM->save_warehouse(\%myconfig, $form);
 
2415   $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
 
2417   $form->redirect($locale->text('Warehouse saved.'));
 
2419   $main::lxdebug->leave_sub();
 
2422 sub delete_warehouse {
 
2423   $main::lxdebug->enter_sub();
 
2425   my $form     = $main::form;
 
2426   my %myconfig = %main::myconfig;
 
2427   my $locale   = $main::locale;
 
2429   $main::auth->assert('config');
 
2431   if (!$form->{confirmed}) {
 
2432     $form->{title} = $locale->text('Confirmation');
 
2435     print $form->parse_html_template('am/confirm_delete_warehouse');
 
2439   if (AM->delete_warehouse(\%myconfig, $form)) {
 
2440     $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
 
2441     $form->redirect($locale->text('Warehouse deleted.'));
 
2444     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
 
2447   $main::lxdebug->leave_sub();
 
2451   $main::lxdebug->enter_sub();
 
2453   my $form     = $main::form;
 
2454   my %myconfig = %main::myconfig;
 
2455   my $locale   = $main::locale;
 
2457   $main::auth->assert('config');
 
2459   AM->save_bins(\%myconfig, $form);
 
2461   $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
 
2463   $form->redirect($locale->text('Bins saved.'));
 
2465   $main::lxdebug->leave_sub();