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 #======================================================================
 
  47 require "bin/mozilla/common.pl";
 
  55 sub add      { call_sub("add_$main::form->{type}"); }
 
  56 sub delete   { call_sub("delete_$main::form->{type}"); }
 
  57 sub save     { call_sub("save_$main::form->{type}"); }
 
  58 sub edit     { call_sub("edit_$main::form->{type}"); }
 
  59 sub continue { call_sub($main::form->{"nextsub"}); }
 
  60 sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
  63   $main::lxdebug->enter_sub();
 
  65   my $form     = $main::form;
 
  66   my %myconfig = %main::myconfig;
 
  68   $main::auth->assert('config');
 
  70   $form->{title}     = "Add";
 
  71   $form->{charttype} = "A";
 
  72   AM->get_account(\%myconfig, \%$form);
 
  74   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
 
  79   $main::lxdebug->leave_sub();
 
  83   $main::lxdebug->enter_sub();
 
  85   my $form     = $main::form;
 
  86   my %myconfig = %main::myconfig;
 
  88   $main::auth->assert('config');
 
  90   $form->{title} = "Edit";
 
  91   AM->get_account(\%myconfig, \%$form);
 
  93   foreach my $item (split(/:/, $form->{link})) {
 
  94     $form->{$item} = "checked";
 
 100   $main::lxdebug->leave_sub();
 
 104   $main::lxdebug->enter_sub();
 
 106   my $form     = $main::form;
 
 107   my %myconfig = %main::myconfig;
 
 108   my $locale   = $main::locale;
 
 110   $main::auth->assert('config');
 
 112   if ( $form->{action} eq 'edit_account') {
 
 113     $form->{account_exists} = '1';
 
 116   $form->{title} = $locale->text("$form->{title} Account");
 
 118   $form->{"$form->{charttype}_checked"} = "checked";
 
 119   $form->{"$form->{category}_checked"}  = "checked";
 
 121   $form->{select_tax} = "";
 
 123   my @tax_report_pos = USTVA->report_variables({
 
 124       myconfig   => \%myconfig,
 
 127       attribute  => 'position',
 
 131   if (@{ $form->{TAXKEY} }) {
 
 132     foreach my $item (@{ $form->{TAXKEY} }) {
 
 133       $item->{rate} = $item->{rate} * 100 . '%';
 
 136     # Fill in empty row for new Taxkey
 
 137     my $newtaxkey_ref = {
 
 142       taxdescription => '',
 
 149     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
 
 152     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
 
 154       # Fill in a runningnumber
 
 155       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
 
 157       # Fill in the Taxkeys as select options
 
 158       foreach my $item (@{ $form->{TAXKEY} }) {
 
 159         if ($item->{id} == $taxkey_used->{tax_id}) {
 
 160           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 161             qq|<option value="$item->{id}" selected="selected">|
 
 162             . sprintf("%.2d", $item->{taxkey})
 
 163             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 164             . $locale->text('Tax-o-matic Account')
 
 165             . qq|: $item->{chart_accno}\n|;
 
 168           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
 
 169             qq|<option value="$item->{id}">|
 
 170             . sprintf("%.2d", $item->{taxkey})
 
 171             . qq|. $item->{taxdescription} ($item->{rate}) |
 
 172             . $locale->text('Tax-o-matic Account')
 
 173             . qq|: $item->{chart_accno}\n|;
 
 178       # Fill in the USTVA Numbers as select options
 
 179       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
 
 181           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
 
 183         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
 
 184           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
 
 187           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
 
 196   # Newaccount Folgekonto
 
 197   if (@{ $form->{NEWACCOUNT} || [] }) {
 
 198     if (!$form->{new_chart_valid}) {
 
 199       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
 
 201     foreach my $item (@{ $form->{NEWACCOUNT} }) {
 
 202       if ($item->{id} == $form->{new_chart_id}) {
 
 203         $form->{selectnewaccount} .=
 
 204           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
 
 205       } elsif (!$form->{new_chart_valid}) {
 
 206         $form->{selectnewaccount} .=
 
 207           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
 
 213   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 216           2  => "sonstige Erlöse",
 
 217           3  => "Privatanteile",
 
 219           5  => "Ausserordentliche Erträge",
 
 220           6  => "Vereinnahmte Umsatzst.",
 
 221           7  => "Umsatzsteuererstattungen",
 
 222           8  => "Wareneingänge",
 
 223           9  => "Löhne und Gehälter",
 
 224           10 => "Gesetzl. sozialer Aufw.",
 
 226           12 => "Gas, Strom, Wasser",
 
 227           13 => "Instandhaltung",
 
 228           14 => "Steuern, Versich., Beiträge",
 
 230           16 => "Kfz-Versicherungen",
 
 231           17 => "Sonst. Fahrzeugkosten",
 
 232           18 => "Werbe- und Reisekosten",
 
 233           19 => "Instandhaltung u. Werkzeuge",
 
 234           20 => "Fachzeitschriften, Bücher",
 
 235           21 => "Miete für Einrichtungen",
 
 236           22 => "Rechts- und Beratungskosten",
 
 237           23 => "Bürobedarf, Porto, Telefon",
 
 238           24 => "Sonstige Aufwendungen",
 
 239           25 => "Abschreibungen auf Anlagever.",
 
 240           26 => "Abschreibungen auf GWG",
 
 242           28 => "Umsatzsteuerzahlungen",
 
 244           30 => "Ausserordentlicher Aufwand",
 
 245           31 => "Betriebliche Steuern");
 
 246   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
 
 247     my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $eur{$item}));
 
 248     if ($item == $form->{pos_eur}) {
 
 249       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 251       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
 
 256   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 260              2  => 'Best.Verdg.FE/UE',
 
 261              3  => 'Aktiv.Eigenleistung',
 
 262              4  => 'Mat./Wareneinkauf',
 
 263              5  => 'So.betr.Erlöse',
 
 264              10 => 'Personalkosten',
 
 266              12 => 'Betriebl.Steuern',
 
 267              13 => 'Vers./Beiträge',
 
 268              14 => 'Kfz.Kosten o.St.',
 
 269              15 => 'Werbe-Reisek.',
 
 270              16 => 'Kosten Warenabgabe',
 
 271              17 => 'Abschreibungen',
 
 272              18 => 'Rep./instandhlt.',
 
 273              19 => 'Übrige Steuern',
 
 274              20 => 'Sonst.Kosten',
 
 276              31 => 'Sonst.neutr.Aufw.',
 
 278              33 => 'Sonst.neutr.Ertrag',
 
 279              34 => 'Verr.kalk.Kosten',
 
 280              35 => 'Steuern Eink.u.Ertr.');
 
 281   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
 
 282     my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $bwapos{$item}));
 
 283     if ($item == $form->{pos_bwa}) {
 
 284       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 286       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
 
 291 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
 
 292   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 293   foreach my $item ((1, 2, 3, 4)) {
 
 294     if ($item == $form->{pos_bilanz}) {
 
 295       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
 
 297       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
 
 302   # this is for our parser only! Do not remove.
 
 303   # type=submit $locale->text('Add Account')
 
 304   # type=submit $locale->text('Edit Account')
 
 306   $form->{type} = "account";
 
 308   # preselections category
 
 310   my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
 313       'A'  => $locale->text('Asset'),
 
 314       'L'  => $locale->text('Liability'),
 
 315       'Q'  => $locale->text('Equity'),
 
 316       'I'  => $locale->text('Revenue'),
 
 317       'E'  => $locale->text('Expense'),
 
 318       'C'  => $locale->text('Costs'),
 
 320   foreach my $item ( sort({ $a <=> $b } keys %category) ) {
 
 321     if ($item eq $form->{category}) {
 
 322       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 324       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
 
 329   # preselection chart type
 
 330   my $select_charttype = q{};
 
 333       'A'  => $locale->text('Account'),
 
 334       'H'  => $locale->text('Header'),
 
 337   foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
 
 338     if ($item eq $form->{charttype}) {
 
 339       $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
 
 342       $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
 
 347   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
 
 351   my $parameters_ref = {
 
 352     ChartTypeIsAccount         => $ChartTypeIsAccount,
 
 353     select_category            => $select_category,
 
 354     select_charttype           => $select_charttype,
 
 355     select_bwa                 => $select_bwa,
 
 356     select_bilanz              => $select_bilanz,
 
 357     select_eur                 => $select_eur,
 
 360   # Ausgabe des Templates
 
 361   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 364   $main::lxdebug->leave_sub();
 
 368   $main::lxdebug->enter_sub();
 
 370   my $form     = $main::form;
 
 371   my $locale   = $main::locale;
 
 373   $main::auth->assert('config');
 
 377 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
 
 380   if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
 
 382 <input type=submit class=submit name=action value="|
 
 383     . $locale->text('Save') . qq|">
 
 387   if ($form->{id} && $form->{orphaned}) {
 
 388     print qq|<input type=submit class=submit name=action value="|
 
 389       . $locale->text('Delete') . qq|">|;
 
 392   if ($form->{id} && $form->{type} eq "account") {
 
 394     <input class=submit type=submit name=action value="|
 
 395       . $locale->text('Save as new') . qq|">|;
 
 405   $main::lxdebug->leave_sub();
 
 409   $main::lxdebug->enter_sub();
 
 411   my $form     = $main::form;
 
 412   my %myconfig = %main::myconfig;
 
 413   my $locale   = $main::locale;
 
 415   $main::auth->assert('config');
 
 417   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 418   $form->isblank("description", $locale->text('Account Description missing!'));
 
 420   if ($form->{charttype} eq 'A'){
 
 421     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 424   $form->redirect($locale->text('Account saved!'))
 
 425     if (AM->save_account(\%myconfig, \%$form));
 
 426   $form->error($locale->text('Cannot save account!'));
 
 428   $main::lxdebug->leave_sub();
 
 431 sub save_as_new_account {
 
 432   $main::lxdebug->enter_sub();
 
 434   my $form     = $main::form;
 
 435   my %myconfig = %main::myconfig;
 
 436   my $locale   = $main::locale;
 
 438   $main::auth->assert('config');
 
 440   $form->isblank("accno",       $locale->text('Account Number missing!'));
 
 441   $form->isblank("description", $locale->text('Account Description missing!'));
 
 443   if ($form->{charttype} eq 'A'){
 
 444     $form->isblank("category",  $locale->text('Account Type missing!'));
 
 447   for my $taxkey (0 .. 9) {
 
 448     if ($form->{"taxkey_id_$taxkey"}) {
 
 449       $form->{"taxkey_id_$taxkey"} = "NEW";
 
 454   if ($form->{"original_accno"} &&
 
 455       ($form->{"accno"} eq $form->{"original_accno"})) {
 
 456     $form->error($locale->text('Account Number already used!'));
 
 458   $form->redirect($locale->text('Account saved!'))
 
 459     if (AM->save_account(\%myconfig, \%$form));
 
 460   $form->error($locale->text('Cannot save account!'));
 
 462   $main::lxdebug->leave_sub();
 
 466   $main::lxdebug->enter_sub();
 
 468   my $form     = $main::form;
 
 469   my %myconfig = %main::myconfig;
 
 470   my $locale   = $main::locale;
 
 472   $main::auth->assert('config');
 
 474   $form->{callback}     = build_std_url('action=list_account');
 
 475   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
 477   CA->all_accounts(\%myconfig, \%$form);
 
 479   foreach my $ca (@{ $form->{CA} }) {
 
 484     if ($ca->{amount} > 0) {
 
 485       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
 
 487     if ($ca->{amount} < 0) {
 
 488       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
 
 490     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:'';
 
 491     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
 
 495   my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
 
 497   # Eneable AJAX debuging
 
 501   push(@ { $form->{AJAX} }, $pjx);
 
 503   $form->{stylesheets} = "list_accounts.css";
 
 504   $form->{title}       = $locale->text('Chart of Accounts');
 
 509   my $parameters_ref = {
 
 510   #   hidden_variables                => $_hidden_variables_ref,
 
 513   # Ausgabe des Templates
 
 514   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
 516   $main::lxdebug->leave_sub();
 
 521 sub list_account_details {
 
 522 # Ajax Funktion aus list_account_details
 
 523   $main::lxdebug->enter_sub();
 
 525   my $form     = $main::form;
 
 526   my %myconfig = %main::myconfig;
 
 527   my $locale   = $main::locale;
 
 529   $main::auth->assert('config');
 
 531   my $chart_id = $form->{args};
 
 533   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
 535   foreach my $ca (@{ $form->{CA} }) {
 
 537     $ca->{debit}  = " ";
 
 538     $ca->{credit} = " ";
 
 540     if ($ca->{amount} > 0) {
 
 542         $form->format_amount(\%myconfig, $ca->{amount}, 2, " ");
 
 544     if ($ca->{amount} < 0) {
 
 546         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, " ");
 
 549     my @links = split( q{:}, $ca->{link});
 
 553     foreach my $link (@links){
 
 554       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
 
 555                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
 
 556                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
 
 557                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
 
 558                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
 
 559                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
 
 560                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
 
 561                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
 
 562                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
 
 563                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
 
 564                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
 
 565                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
 
 566                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
 
 567                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
 
 568                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
 
 569 #               : ( $link eq 'CT_tax' )        ? $locale->text('Account Link CT_tax')
 
 570                : $locale->text('Unknown Link') . ': ' . $link;
 
 571       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
 
 574     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
 
 575                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
 
 576                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
 
 577                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
 
 578                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
 
 579                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
 
 580                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
 
 581                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
 
 584   $form->{title} = $locale->text('Chart of Accounts');
 
 587   print $form->parse_html_template('am/list_account_details');
 
 589   $main::lxdebug->leave_sub();
 
 594   $main::lxdebug->enter_sub();
 
 596   my $form     = $main::form;
 
 597   my %myconfig = %main::myconfig;
 
 598   my $locale   = $main::locale;
 
 600   $main::auth->assert('config');
 
 602   $form->{title} = $locale->text('Delete Account');
 
 605     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
 
 607     if ($form->{id} == $form->{$id}) {
 
 608       $form->error($locale->text('Cannot delete default account!'));
 
 612   $form->redirect($locale->text('Account deleted!'))
 
 613     if (AM->delete_account(\%myconfig, \%$form));
 
 614   $form->error($locale->text('Cannot delete account!'));
 
 616   $main::lxdebug->leave_sub();
 
 620   $main::lxdebug->enter_sub();
 
 622   my $form     = $main::form;
 
 624   $main::auth->assert('config');
 
 626   $form->{title} = "Add";
 
 629   $form->{callback} = "am.pl?action=add_department" unless $form->{callback};
 
 634   $main::lxdebug->leave_sub();
 
 637 sub edit_department {
 
 638   $main::lxdebug->enter_sub();
 
 640   my $form     = $main::form;
 
 641   my %myconfig = %main::myconfig;
 
 643   $main::auth->assert('config');
 
 645   $form->{title} = "Edit";
 
 647   AM->get_department(\%myconfig, \%$form);
 
 652   $main::lxdebug->leave_sub();
 
 655 sub list_department {
 
 656   $main::lxdebug->enter_sub();
 
 658   my $form     = $main::form;
 
 659   my %myconfig = %main::myconfig;
 
 660   my $locale   = $main::locale;
 
 662   $main::auth->assert('config');
 
 664   AM->departments(\%myconfig, \%$form);
 
 666   $form->{callback} = "am.pl?action=list_department";
 
 668   my $callback = $form->escape($form->{callback});
 
 670   $form->{title} = $locale->text('Departments');
 
 672   my @column_index = qw(description cost profit);
 
 674   $column_header{description} =
 
 675       qq|<th class=listheading width=90%>|
 
 676     . $locale->text('Description')
 
 678   $column_header{cost} =
 
 679       qq|<th class=listheading nowrap>|
 
 680     . $locale->text('Cost Center')
 
 682   $column_header{profit} =
 
 683       qq|<th class=listheading nowrap>|
 
 684     . $locale->text('Profit Center')
 
 694     <th class=listtop>$form->{title}</th>
 
 700         <tr class=listheading>
 
 703   map { print "$column_header{$_}\n" } @column_index;
 
 709   my ($i, %column_data);
 
 710   foreach my $ref (@{ $form->{ALL} }) {
 
 716         <tr valign=top class=listrow$i>
 
 719     my $costcenter   = ($ref->{role} eq "C") ? "X" : "";
 
 720     my $profitcenter = ($ref->{role} eq "P") ? "X" : "";
 
 722     $column_data{description} =
 
 723       qq|<td><a href="am.pl?action=edit_department&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
 724     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
 
 725     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
 
 727     map { print "$column_data{$_}\n" } @column_index;
 
 739   <td><hr size=3 noshade></td>
 
 744 <form method=post action=am.pl>
 
 746 <input name=callback type=hidden value="$form->{callback}">
 
 748 <input type=hidden name=type value=department>
 
 750 <input class=submit type=submit name=action value="|
 
 751     . $locale->text('Add') . qq|">
 
 759   $main::lxdebug->leave_sub();
 
 762 sub department_header {
 
 763   $main::lxdebug->enter_sub();
 
 765   my $form     = $main::form;
 
 766   my $locale   = $main::locale;
 
 768   $main::auth->assert('config');
 
 770   $form->{title} = $locale->text("$form->{title} Department");
 
 772   # $locale->text('Add Department')
 
 773   # $locale->text('Edit Department')
 
 775   $form->{description} =~ s/\"/"/g;
 
 777   my ($rows, $description);
 
 778   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
 
 780       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
 
 783       qq|<input name=description size=60 value="$form->{description}">|;
 
 786   my $costcenter   = "checked" if $form->{role} eq "C";
 
 787   my $profitcenter = "checked" if $form->{role} eq "P";
 
 794 <form method=post action=am.pl>
 
 796 <input type=hidden name=id value=$form->{id}>
 
 797 <input type=hidden name=type value=department>
 
 801     <th class=listtop colspan=2>$form->{title}</th>
 
 805     <th align=right>| . $locale->text('Description') . qq|</th>
 
 806     <td>$description</td>
 
 810     <td><input type=radio style=radio name=role value="C" $costcenter> |
 
 811     . $locale->text('Cost Center') . qq|
 
 812         <input type=radio style=radio name=role value="P" $profitcenter> |
 
 813     . $locale->text('Profit Center') . qq|
 
 816     <td colspan=2><hr size=3 noshade></td>
 
 821   $main::lxdebug->leave_sub();
 
 824 sub save_department {
 
 825   $main::lxdebug->enter_sub();
 
 827   my $form     = $main::form;
 
 828   my %myconfig = %main::myconfig;
 
 829   my $locale   = $main::locale;
 
 831   $main::auth->assert('config');
 
 833   $form->isblank("description", $locale->text('Description missing!'));
 
 834   AM->save_department(\%myconfig, \%$form);
 
 835   $form->redirect($locale->text('Department saved!'));
 
 837   $main::lxdebug->leave_sub();
 
 840 sub delete_department {
 
 841   $main::lxdebug->enter_sub();
 
 843   my $form     = $main::form;
 
 844   my %myconfig = %main::myconfig;
 
 845   my $locale   = $main::locale;
 
 847   $main::auth->assert('config');
 
 849   AM->delete_department(\%myconfig, \%$form);
 
 850   $form->redirect($locale->text('Department deleted!'));
 
 852   $main::lxdebug->leave_sub();
 
 856   $main::lxdebug->enter_sub();
 
 858   my $form     = $main::form;
 
 860   $main::auth->assert('config');
 
 862   $form->{title} = "Add";
 
 864   $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
 
 869   $main::lxdebug->leave_sub();
 
 873   $main::lxdebug->enter_sub();
 
 875   my $form     = $main::form;
 
 876   my %myconfig = %main::myconfig;
 
 878   $main::auth->assert('config');
 
 880   $form->{title} = "Edit";
 
 882   AM->get_lead(\%myconfig, \%$form);
 
 886   $form->{orphaned} = 1;
 
 889   $main::lxdebug->leave_sub();
 
 893   $main::lxdebug->enter_sub();
 
 895   my $form     = $main::form;
 
 896   my %myconfig = %main::myconfig;
 
 897   my $locale   = $main::locale;
 
 899   $main::auth->assert('config');
 
 901   AM->lead(\%myconfig, \%$form);
 
 903   $form->{callback} = "am.pl?action=list_lead";
 
 905   my $callback = $form->escape($form->{callback});
 
 907   $form->{title} = $locale->text('Lead');
 
 909   my @column_index = qw(description cost profit);
 
 911   $column_header{description} =
 
 912       qq|<th class=listheading width=100%>|
 
 913     . $locale->text('Description')
 
 923     <th class=listtop>$form->{title}</th>
 
 926   <tr class=listheading>
 
 929   map { print "$column_header{$_}\n" } @column_index;
 
 935   my ($i, %column_data);
 
 936   foreach my $ref (@{ $form->{ALL} }) {
 
 942   <tr valign=top class=listrow$i>
 
 945 #    $lead = $ref->{lead};
 
 947     $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
 
 949     map { print "$column_data{$_}\n" } @column_index;
 
 958   <td><hr size=3 noshade></td>
 
 963 <form method=post action=am.pl>
 
 965 <input name=callback type=hidden value="$form->{callback}">
 
 967 <input type=hidden name=type value=lead>
 
 969 <input class=submit type=submit name=action value="|
 
 970     . $locale->text('Add') . qq|">
 
 978   $main::lxdebug->leave_sub();
 
 982   $main::lxdebug->enter_sub();
 
 984   my $form     = $main::form;
 
 985   my $locale   = $main::locale;
 
 987   $main::auth->assert('config');
 
 989   $form->{title} = $locale->text("$form->{title} Lead");
 
 991   # $locale->text('Add Lead')
 
 992   # $locale->text('Edit Lead')
 
 994   $form->{description} =~ s/\"/"/g;
 
 997       qq|<input name=description size=50 value="$form->{lead}">|;
 
1004 <form method=post action=am.pl>
 
1006 <input type=hidden name=id value=$form->{id}>
 
1007 <input type=hidden name=type value=lead>
 
1011     <th class=listtop colspan=2>$form->{title}</th>
 
1013   <tr height="5"></tr>
 
1015     <th align=right>| . $locale->text('Description') . qq|</th>
 
1016     <td>$description</td>
 
1018     <td colspan=2><hr size=3 noshade></td>
 
1023   $main::lxdebug->leave_sub();
 
1027   $main::lxdebug->enter_sub();
 
1029   my $form     = $main::form;
 
1030   my %myconfig = %main::myconfig;
 
1031   my $locale   = $main::locale;
 
1033   $main::auth->assert('config');
 
1035   $form->isblank("description", $locale->text('Description missing!'));
 
1036   AM->save_lead(\%myconfig, \%$form);
 
1037   $form->redirect($locale->text('lead saved!'));
 
1039   $main::lxdebug->leave_sub();
 
1043   $main::lxdebug->enter_sub();
 
1045   my $form     = $main::form;
 
1046   my %myconfig = %main::myconfig;
 
1047   my $locale   = $main::locale;
 
1049   $main::auth->assert('config');
 
1051   AM->delete_lead(\%myconfig, \%$form);
 
1052   $form->redirect($locale->text('lead deleted!'));
 
1054   $main::lxdebug->leave_sub();
 
1058   $main::lxdebug->enter_sub();
 
1060   my $form     = $main::form;
 
1062   $main::auth->assert('config');
 
1064   $form->{title} = "Add";
 
1066   $form->{callback} = "am.pl?action=add_business" unless $form->{callback};
 
1071   $main::lxdebug->leave_sub();
 
1075   $main::lxdebug->enter_sub();
 
1077   my $form     = $main::form;
 
1078   my %myconfig = %main::myconfig;
 
1080   $form->{title} = "Edit";
 
1082   AM->get_business(\%myconfig, \%$form);
 
1086   $form->{orphaned} = 1;
 
1089   $main::lxdebug->leave_sub();
 
1093   $main::lxdebug->enter_sub();
 
1095   my $form     = $main::form;
 
1096   my %myconfig = %main::myconfig;
 
1097   my $locale   = $main::locale;
 
1099   $main::auth->assert('config');
 
1101   AM->business(\%myconfig, \%$form);
 
1103   $form->{callback} = "am.pl?action=list_business";
 
1105   my $callback = $form->escape($form->{callback});
 
1107   $form->{title} = $locale->text('Type of Business');
 
1109   my @column_index = qw(description discount customernumberinit);
 
1111   $column_header{description} =
 
1112       qq|<th class=listheading width=60%>|
 
1113     . $locale->text('Description')
 
1115   $column_header{discount} =
 
1116       qq|<th class=listheading width=10%>|
 
1117     . $locale->text('Discount')
 
1119   $column_header{customernumberinit} =
 
1120       qq|<th class=listheading>|
 
1121     . $locale->text('Customernumberinit')
 
1131     <th class=listtop>$form->{title}</th>
 
1133   <tr height="5"></tr>
 
1137         <tr class=listheading>
 
1140   map { print "$column_header{$_}\n" } @column_index;
 
1146   my ($i, %column_data);
 
1147   foreach my $ref (@{ $form->{ALL} }) {
 
1153         <tr valign=top class=listrow$i>
 
1156     my $discount    = $form->format_amount(\%myconfig, $ref->{discount} * 100);
 
1157     my $description = $ref->{description};
 
1158     $column_data{description} = qq|<td><a href="am.pl?action=edit_business&id=$ref->{id}&callback=$callback">$description</td>|;
 
1159     $column_data{discount}           = qq|<td align=right>$discount</td>|;
 
1160     $column_data{customernumberinit} =
 
1161       qq|<td align=right>$ref->{customernumberinit}</td>|;
 
1163     map { print "$column_data{$_}\n" } @column_index;
 
1175   <td><hr size=3 noshade></td>
 
1180 <form method=post action=am.pl>
 
1182 <input name=callback type=hidden value="$form->{callback}">
 
1184 <input type=hidden name=type value=business>
 
1186 <input class=submit type=submit name=action value="|
 
1187     . $locale->text('Add') . qq|">
 
1195   $main::lxdebug->leave_sub();
 
1198 sub business_header {
 
1199   $main::lxdebug->enter_sub();
 
1201   my $form     = $main::form;
 
1202   my %myconfig = %main::myconfig;
 
1203   my $locale   = $main::locale;
 
1205   $main::auth->assert('config');
 
1207   $form->{title}    = $locale->text("$form->{title} Business");
 
1209   # $locale->text('Add Business')
 
1210   # $locale->text('Edit Business')
 
1212   $form->{description} =~ s/\"/"/g;
 
1214     $form->format_amount(\%myconfig, $form->{discount} * 100);
 
1221 <form method=post action=am.pl>
 
1223 <input type=hidden name=id value=$form->{id}>
 
1224 <input type=hidden name=type value=business>
 
1228     <th class=listtop colspan=2>$form->{title}</th>
 
1230   <tr height="5"></tr>
 
1232     <th align=right>| . $locale->text('Type of Business') . qq|</th>
 
1233     <td><input name=description size=30 value="$form->{description}"></td>
 
1236     <th align=right>| . $locale->text('Discount') . qq| %</th>
 
1237     <td><input name=discount size=5 value=$form->{discount}></td>
 
1240     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
 
1241     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
 
1243   <td colspan=2><hr size=3 noshade></td>
 
1248   $main::lxdebug->leave_sub();
 
1252   $main::lxdebug->enter_sub();
 
1254   my $form     = $main::form;
 
1255   my %myconfig = %main::myconfig;
 
1256   my $locale   = $main::locale;
 
1258   $main::auth->assert('config');
 
1260   $form->isblank("description", $locale->text('Description missing!'));
 
1261   $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
 
1262   AM->save_business(\%myconfig, \%$form);
 
1263   $form->redirect($locale->text('Business saved!'));
 
1265   $main::lxdebug->leave_sub();
 
1268 sub delete_business {
 
1269   $main::lxdebug->enter_sub();
 
1271   my $form     = $main::form;
 
1272   my %myconfig = %main::myconfig;
 
1273   my $locale   = $main::locale;
 
1275   $main::auth->assert('config');
 
1277   AM->delete_business(\%myconfig, \%$form);
 
1278   $form->redirect($locale->text('Business deleted!'));
 
1280   $main::lxdebug->leave_sub();
 
1284   $main::lxdebug->enter_sub();
 
1286   my $form     = $main::form;
 
1288   $main::auth->assert('config');
 
1290   $form->{title} = "Add";
 
1292   $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
 
1297   $main::lxdebug->leave_sub();
 
1301   $main::lxdebug->enter_sub();
 
1303   my $form     = $main::form;
 
1304   my %myconfig = %main::myconfig;
 
1306   $main::auth->assert('config');
 
1308   $form->{title} = "Edit";
 
1310   AM->get_language(\%myconfig, \%$form);
 
1314   $form->{orphaned} = 1;
 
1317   $main::lxdebug->leave_sub();
 
1321   $main::lxdebug->enter_sub();
 
1323   my $form     = $main::form;
 
1324   my %myconfig = %main::myconfig;
 
1325   my $locale   = $main::locale;
 
1327   $main::auth->assert('config');
 
1329   AM->language(\%myconfig, \%$form);
 
1331   $form->{callback} = "am.pl?action=list_language";
 
1333   my $callback = $form->escape($form->{callback});
 
1335   $form->{title} = $locale->text('Languages');
 
1337   my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
 
1339   $column_header{description} =
 
1340       qq|<th class=listheading width=60%>|
 
1341     . $locale->text('Description')
 
1343   $column_header{template_code} =
 
1344       qq|<th class=listheading width=10%>|
 
1345     . $locale->text('Template Code')
 
1347   $column_header{article_code} =
 
1348       qq|<th class=listheading>|
 
1349     . $locale->text('Article Code')
 
1351   $column_header{output_numberformat} =
 
1352       qq|<th class=listheading>|
 
1353     . $locale->text('Number Format')
 
1355   $column_header{output_dateformat} =
 
1356       qq|<th class=listheading>|
 
1357     . $locale->text('Date Format')
 
1359   $column_header{output_longdates} =
 
1360       qq|<th class=listheading>|
 
1361     . $locale->text('Long Dates')
 
1371     <th class=listtop>$form->{title}</th>
 
1373   <tr height="5"></tr>
 
1377         <tr class=listheading>
 
1380   map { print "$column_header{$_}\n" } @column_index;
 
1386   my ($i, %column_data);
 
1387   foreach my $ref (@{ $form->{ALL} }) {
 
1393         <tr valign=top class=listrow$i>
 
1397     $column_data{description} =
 
1398       qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1399     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
 
1400     $column_data{article_code} =
 
1401       qq|<td align=right>$ref->{article_code}</td>|;
 
1402     $column_data{output_numberformat} =
 
1404       ($ref->{output_numberformat} ? $ref->{output_numberformat} :
 
1405        $locale->text("use program settings")) .
 
1407     $column_data{output_dateformat} =
 
1409       ($ref->{output_dateformat} ? $ref->{output_dateformat} :
 
1410        $locale->text("use program settings")) .
 
1412     $column_data{output_longdates} =
 
1414       ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
 
1417     map { print "$column_data{$_}\n" } @column_index;
 
1429   <td><hr size=3 noshade></td>
 
1434 <form method=post action=am.pl>
 
1436 <input name=callback type=hidden value="$form->{callback}">
 
1438 <input type=hidden name=type value=language>
 
1440 <input class=submit type=submit name=action value="|
 
1441     . $locale->text('Add') . qq|">
 
1449   $main::lxdebug->leave_sub();
 
1452 sub language_header {
 
1453   $main::lxdebug->enter_sub();
 
1455   my $form     = $main::form;
 
1456   my $locale   = $main::locale;
 
1458   $main::auth->assert('config');
 
1460   $form->{title}    = $locale->text("$form->{title} Language");
 
1462   # $locale->text('Add Language')
 
1463   # $locale->text('Edit Language')
 
1465   $form->{description} =~ s/\"/"/g;
 
1466   $form->{template_code} =~ s/\"/"/g;
 
1467   $form->{article_code} =~ s/\"/"/g;
 
1473     qq|<option value="">| . $locale->text("use program settings") .
 
1475   foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
 
1477       ($item eq $form->{output_numberformat})
 
1478       ? "<option selected>$item"
 
1484     qq|<option value="">| . $locale->text("use program settings") .
 
1486   foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
 
1488       ($item eq $form->{output_dateformat})
 
1489       ? "<option selected>$item"
 
1497 <form method=post action=am.pl>
 
1499 <input type=hidden name=id value=$form->{id}>
 
1500 <input type=hidden name=type value=language>
 
1504     <th class=listtop colspan=2>$form->{title}</th>
 
1506   <tr height="5"></tr>
 
1508     <th align=right>| . $locale->text('Language') . qq|</th>
 
1509     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1512     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
1513     <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
 
1516     <th align=right>| . $locale->text('Article Code') . qq|</th>
 
1517     <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
 
1520     <th align=right>| . $locale->text('Number Format') . qq|</th>
 
1521     <td><select name="output_numberformat">$numberformat</select></td>
 
1524     <th align=right>| . $locale->text('Date Format') . qq|</th>
 
1525     <td><select name="output_dateformat">$dateformat</select></td>
 
1528     <th align=right>| . $locale->text('Long Dates') . qq|</th>
 
1529     <td><input type="radio" name="output_longdates" value="1"| .
 
1530     ($form->{output_longdates} ? " checked" : "") .
 
1531     qq|>| . $locale->text("Yes") .
 
1532     qq|<input type="radio" name="output_longdates" value="0"| .
 
1533     ($form->{output_longdates} ? "" : " checked") .
 
1534     qq|>| . $locale->text("No") .
 
1537   <td colspan=2><hr size=3 noshade></td>
 
1542   $main::lxdebug->leave_sub();
 
1546   $main::lxdebug->enter_sub();
 
1548   my $form     = $main::form;
 
1549   my %myconfig = %main::myconfig;
 
1550   my $locale   = $main::locale;
 
1552   $main::auth->assert('config');
 
1554   $form->isblank("description", $locale->text('Language missing!'));
 
1555   $form->isblank("template_code", $locale->text('Template Code missing!'));
 
1556   $form->isblank("article_code", $locale->text('Article Code missing!'));
 
1557   AM->save_language(\%myconfig, \%$form);
 
1558   $form->redirect($locale->text('Language saved!'));
 
1560   $main::lxdebug->leave_sub();
 
1563 sub delete_language {
 
1564   $main::lxdebug->enter_sub();
 
1566   my $form     = $main::form;
 
1567   my %myconfig = %main::myconfig;
 
1568   my $locale   = $main::locale;
 
1570   $main::auth->assert('config');
 
1572   AM->delete_language(\%myconfig, \%$form);
 
1573   $form->redirect($locale->text('Language deleted!'));
 
1575   $main::lxdebug->leave_sub();
 
1579 sub add_buchungsgruppe {
 
1580   $main::lxdebug->enter_sub();
 
1582   my $form     = $main::form;
 
1583   my %myconfig = %main::myconfig;
 
1584   my $locale   = $main::locale;
 
1586   $main::auth->assert('config');
 
1588   # $locale->text("Add Buchungsgruppe")
 
1589   # $locale->text("Edit Buchungsgruppe")
 
1590   $form->{title} = "Add";
 
1592   $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
 
1594   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1595   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
 
1596   for (my $i = 0; 4 > $i; $i++) {
 
1597     map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
 
1598         qw(income expense));
 
1601   &buchungsgruppe_header;
 
1604   $main::lxdebug->leave_sub();
 
1607 sub edit_buchungsgruppe {
 
1608   $main::lxdebug->enter_sub();
 
1610   my $form     = $main::form;
 
1611   my %myconfig = %main::myconfig;
 
1613   $main::auth->assert('config');
 
1615   $form->{title} = "Edit";
 
1617   AM->get_buchungsgruppe(\%myconfig, \%$form);
 
1619   &buchungsgruppe_header;
 
1623   $main::lxdebug->leave_sub();
 
1626 sub list_buchungsgruppe {
 
1627   $main::lxdebug->enter_sub();
 
1629   my $form     = $main::form;
 
1630   my %myconfig = %main::myconfig;
 
1631   my $locale   = $main::locale;
 
1633   $main::auth->assert('config');
 
1635   AM->buchungsgruppe(\%myconfig, \%$form);
 
1637   $form->{callback} = "am.pl?action=list_buchungsgruppe";
 
1639   my $callback = $form->escape($form->{callback});
 
1641   $form->{title} = $locale->text('Buchungsgruppen');
 
1643   my @column_index = qw(up down description inventory_accno
 
1644                      income_accno_0 expense_accno_0
 
1645                      income_accno_1 expense_accno_1
 
1646                      income_accno_2 expense_accno_2
 
1647                      income_accno_3 expense_accno_3 );
 
1649   $column_header{up} =
 
1650       qq|<th class="listheading" width="16">|
 
1651     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
1653   $column_header{down} =
 
1654       qq|<th class="listheading" width="16">|
 
1655     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
1657   $column_header{description} =
 
1658       qq|<th class="listheading" width="40%">|
 
1659     . $locale->text('Description')
 
1661   $column_header{inventory_accno} =
 
1662       qq|<th class=listheading>|
 
1663     . $locale->text('Bestandskonto')
 
1665   $column_header{income_accno_0} =
 
1666       qq|<th class=listheading>|
 
1667     . $locale->text('National Revenues')
 
1669   $column_header{expense_accno_0} =
 
1670       qq|<th class=listheading>|
 
1671     . $locale->text('National Expenses')
 
1673   $column_header{income_accno_1} =
 
1674       qq|<th class=listheading>|
 
1675     . $locale->text('Revenues EU with UStId')
 
1677   $column_header{expense_accno_1} =
 
1678       qq|<th class=listheading>|
 
1679     . $locale->text('Expenses EU with UStId')
 
1681   $column_header{income_accno_2} =
 
1682       qq|<th class=listheading>|
 
1683     . $locale->text('Revenues EU without UStId')
 
1685   $column_header{expense_accno_2} =
 
1686       qq|<th class=listheading>|
 
1687     . $locale->text('Expenses EU without UStId')
 
1689   $column_header{income_accno_3} =
 
1690       qq|<th class=listheading>|
 
1691     . $locale->text('Foreign Revenues')
 
1693   $column_header{expense_accno_3} =
 
1694       qq|<th class=listheading>|
 
1695     . $locale->text('Foreign Expenses')
 
1704     <th class=listtop>$form->{title}</th>
 
1706   <tr height="5"></tr>
 
1710         <tr class=listheading>
 
1713   map { print "$column_header{$_}\n" } @column_index;
 
1719   my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
 
1722   my ($i, %column_data);
 
1723   foreach my $ref (@{ $form->{ALL} }) {
 
1729         <tr valign=top class=listrow$i>
 
1733       my $pref = $form->{ALL}->[$row - 1];
 
1735         qq|<td align="center" valign="center" width="16">| .
 
1736         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
 
1737         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
1740       $column_data{up} = qq|<td width="16"> </td>|;
 
1743     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
1744       $column_data{down} = qq|<td width="16"> </td>|;
 
1746       my $nref = $form->{ALL}->[$row + 1];
 
1747       $column_data{down} =
 
1748         qq|<td align="center" valign="center" width="16">| .
 
1749         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
 
1750         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
1754     $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
 
1755     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
 
1756     $column_data{income_accno_0} =
 
1757       qq|<td align=right>$ref->{income_accno_0}</td>|;
 
1758     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
 
1759     $column_data{income_accno_1} =
 
1760       qq|<td align=right>$ref->{income_accno_1}</td>|;
 
1761     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
 
1762     $column_data{income_accno_2} =
 
1763       qq|<td align=right>$ref->{income_accno_2}</td>|;
 
1764     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
 
1765     $column_data{income_accno_3} =
 
1766       qq|<td align=right>$ref->{income_accno_3}</td>|;
 
1767     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
 
1769     map { print "$column_data{$_}\n" } @column_index;
 
1783   <td><hr size=3 noshade></td>
 
1788 <form method=post action=am.pl>
 
1790 <input name=callback type=hidden value="$form->{callback}">
 
1792 <input type=hidden name=type value=buchungsgruppe>
 
1794 <input class=submit type=submit name=action value="|
 
1795     . $locale->text('Add') . qq|">
 
1803   $main::lxdebug->leave_sub();
 
1806 sub buchungsgruppe_header {
 
1807   $main::lxdebug->enter_sub();
 
1809   my $form     = $main::form;
 
1810   my $locale   = $main::locale;
 
1812   $main::auth->assert('config');
 
1814   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
 
1816   # $locale->text('Add Accounting Group')
 
1817   # $locale->text('Edit Accounting Group')
 
1819   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
 
1820   my %acc_type_map = (
 
1821     "IC" => $acc_inventory,
 
1822     "IC_income" => $acc_income,
 
1823     "IC_sale" => $acc_income,
 
1824     "IC_expense" => $acc_expense,
 
1825     "IC_cogs" => $acc_expense,
 
1828   foreach my $key (keys(%acc_type_map)) {
 
1829     foreach my $ref (@{ $form->{IC_links}{$key} }) {
 
1830       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
 
1834   foreach my $type (qw(IC IC_income IC_expense)) {
 
1835     $form->{"select$type"} =
 
1837            map({ "<option value=$_->{id} $_->{selected}>" .
 
1838                    "$_->{accno}--" . H($_->{description}) . "</option>" }
 
1839                sort({ $a->{"accno"} cmp $b->{"accno"} }
 
1840                     values(%{$acc_type_map{$type}}))));
 
1844     $form->{selectIC} =~ s/selected//g;
 
1845     $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/  value=$form->{inventory_accno_id} selected/;
 
1846     $form->{selectIC_income} =~ s/selected//g;
 
1847     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/  value=$form->{income_accno_id_0} selected/;
 
1848     $form->{selectIC_expense} =~ s/selected//g;
 
1849     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
 
1856                 <th align=right>| . $locale->text('Inventory') . qq|</th>
 
1857                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
 
1858                 <input name=selectIC type=hidden value="$form->{selectIC}">
 
1862                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
 
1866   $linkaccounts .= qq|
 
1868                 <th align=right>| . $locale->text('National Revenues') . qq|</th>
 
1869                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
 
1872                 <th align=right>| . $locale->text('National Expenses') . qq|</th>
 
1873                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
 
1876     $form->{selectIC_income} =~ s/selected//g;
 
1877     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/  value=$form->{income_accno_id_1} selected/;
 
1878     $form->{selectIC_expense} =~ s/selected//g;
 
1879     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/  value=$form->{expense_accno_id_1} selected/;
 
1881   $linkaccounts .= qq|              <tr>
 
1882                 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
 
1883                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
 
1886                 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
 
1887                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
 
1891     $form->{selectIC_income} =~ s/selected//g;
 
1892     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/  value=$form->{income_accno_id_2} selected/;
 
1893     $form->{selectIC_expense} =~ s/selected//g;
 
1894     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/  value=$form->{expense_accno_id_2} selected/;
 
1897   $linkaccounts .= qq|              <tr>
 
1898                 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
 
1899                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
 
1902                 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
 
1903                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
 
1907     $form->{selectIC_income} =~ s/selected//g;
 
1908     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/  value=$form->{income_accno_id_3} selected/;
 
1909     $form->{selectIC_expense} =~ s/selected//g;
 
1910     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/  value=$form->{expense_accno_id_3} selected/;
 
1913   $linkaccounts .= qq|              <tr>
 
1914                 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
 
1915                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
 
1918                 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
 
1919                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
 
1929 <form method=post action=am.pl>
 
1931 <input type=hidden name=id value=$form->{id}>
 
1932 <input type=hidden name=type value=buchungsgruppe>
 
1936     <th class=listtop colspan=2>$form->{title}</th>
 
1938   <tr height="5"></tr>
 
1940     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
 
1941     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
 
1944   <td colspan=2><hr size=3 noshade></td>
 
1949   $main::lxdebug->leave_sub();
 
1952 sub save_buchungsgruppe {
 
1953   $main::lxdebug->enter_sub();
 
1955   my $form     = $main::form;
 
1956   my %myconfig = %main::myconfig;
 
1957   my $locale   = $main::locale;
 
1959   $main::auth->assert('config');
 
1961   $form->isblank("description", $locale->text('Description missing!'));
 
1963   AM->save_buchungsgruppe(\%myconfig, \%$form);
 
1964   $form->redirect($locale->text('Accounting Group saved!'));
 
1966   $main::lxdebug->leave_sub();
 
1969 sub delete_buchungsgruppe {
 
1970   $main::lxdebug->enter_sub();
 
1972   my $form     = $main::form;
 
1973   my %myconfig = %main::myconfig;
 
1974   my $locale   = $main::locale;
 
1976   $main::auth->assert('config');
 
1978   AM->delete_buchungsgruppe(\%myconfig, \%$form);
 
1979   $form->redirect($locale->text('Accounting Group deleted!'));
 
1981   $main::lxdebug->leave_sub();
 
1984 sub swap_buchungsgruppen {
 
1985   $main::lxdebug->enter_sub();
 
1987   my $form     = $main::form;
 
1988   my %myconfig = %main::myconfig;
 
1990   $main::auth->assert('config');
 
1992   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
 
1993   list_buchungsgruppe();
 
1995   $main::lxdebug->leave_sub();
 
2000   $main::lxdebug->enter_sub();
 
2002   my $form     = $main::form;
 
2004   $main::auth->assert('config');
 
2006   $form->{title} = "Add";
 
2008   $form->{callback} = "am.pl?action=add_printer" unless $form->{callback};
 
2013   $main::lxdebug->leave_sub();
 
2017   $main::lxdebug->enter_sub();
 
2019   my $form     = $main::form;
 
2020   my %myconfig = %main::myconfig;
 
2022   $main::auth->assert('config');
 
2024   $form->{title} = "Edit";
 
2026   AM->get_printer(\%myconfig, \%$form);
 
2030   $form->{orphaned} = 1;
 
2033   $main::lxdebug->leave_sub();
 
2037   $main::lxdebug->enter_sub();
 
2039   my $form     = $main::form;
 
2040   my %myconfig = %main::myconfig;
 
2041   my $locale   = $main::locale;
 
2043   $main::auth->assert('config');
 
2045   AM->printer(\%myconfig, \%$form);
 
2047   $form->{callback} = "am.pl?action=list_printer";
 
2049   my $callback = $form->escape($form->{callback});
 
2051   $form->{title} = $locale->text('Printer');
 
2053   my @column_index = qw(printer_description printer_command template_code);
 
2055   $column_header{printer_description} =
 
2056       qq|<th class=listheading width=60%>|
 
2057     . $locale->text('Printer Description')
 
2059   $column_header{printer_command} =
 
2060       qq|<th class=listheading width=10%>|
 
2061     . $locale->text('Printer Command')
 
2063   $column_header{template_code} =
 
2064       qq|<th class=listheading>|
 
2065     . $locale->text('Template Code')
 
2075     <th class=listtop>$form->{title}</th>
 
2077   <tr height="5"></tr>
 
2081         <tr class=listheading>
 
2084   map { print "$column_header{$_}\n" } @column_index;
 
2090   my ($i, %column_data);
 
2091   foreach my $ref (@{ $form->{ALL} }) {
 
2097         <tr valign=top class=listrow$i>
 
2101     $column_data{printer_description} = qq|<td><a href="am.pl?action=edit_printer&id=$ref->{id}&callback=$callback">$ref->{printer_description}</td>|;
 
2102     $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
 
2103     $column_data{template_code} =
 
2104       qq|<td align=right>$ref->{template_code}</td>|;
 
2106     map { print "$column_data{$_}\n" } @column_index;
 
2118   <td><hr size=3 noshade></td>
 
2123 <form method=post action=am.pl>
 
2125 <input name=callback type=hidden value="$form->{callback}">
 
2127 <input type=hidden name=type value=printer>
 
2129 <input class=submit type=submit name=action value="|
 
2130     . $locale->text('Add') . qq|">
 
2138   $main::lxdebug->leave_sub();
 
2141 sub printer_header {
 
2142   $main::lxdebug->enter_sub();
 
2144   my $form     = $main::form;
 
2145   my $locale   = $main::locale;
 
2147   $main::auth->assert('config');
 
2149   $form->{title}    = $locale->text("$form->{title} Printer");
 
2151   # $locale->text('Add Printer')
 
2152   # $locale->text('Edit Printer')
 
2154   $form->{printer_description} =~ s/\"/"/g;
 
2155   $form->{template_code} =~ s/\"/"/g;
 
2156   $form->{printer_command} =~ s/\"/"/g;
 
2164 <form method=post action=am.pl>
 
2166 <input type=hidden name=id value=$form->{id}>
 
2167 <input type=hidden name=type value=printer>
 
2171     <th class=listtop colspan=2>$form->{title}</th>
 
2173   <tr height="5"></tr>
 
2175     <th align=right>| . $locale->text('Printer') . qq|</th>
 
2176     <td><input name=printer_description size=30 value="$form->{printer_description}"></td>
 
2179     <th align=right>| . $locale->text('Printer Command') . qq|</th>
 
2180     <td><input name=printer_command size=30 value="$form->{printer_command}"></td>
 
2183     <th align=right>| . $locale->text('Template Code') . qq|</th>
 
2184     <td><input name=template_code size=5 value="$form->{template_code}"></td>
 
2186   <td colspan=2><hr size=3 noshade></td>
 
2191   $main::lxdebug->leave_sub();
 
2195   $main::lxdebug->enter_sub();
 
2197   my $form     = $main::form;
 
2198   my %myconfig = %main::myconfig;
 
2199   my $locale   = $main::locale;
 
2201   $main::auth->assert('config');
 
2203   $form->isblank("printer_description", $locale->text('Description missing!'));
 
2204   $form->isblank("printer_command", $locale->text('Printer Command missing!'));
 
2205   AM->save_printer(\%myconfig, \%$form);
 
2206   $form->redirect($locale->text('Printer saved!'));
 
2208   $main::lxdebug->leave_sub();
 
2211 sub delete_printer {
 
2212   $main::lxdebug->enter_sub();
 
2214   my $form     = $main::form;
 
2215   my %myconfig = %main::myconfig;
 
2216   my $locale   = $main::locale;
 
2218   $main::auth->assert('config');
 
2220   AM->delete_printer(\%myconfig, \%$form);
 
2221   $form->redirect($locale->text('Printer deleted!'));
 
2223   $main::lxdebug->leave_sub();
 
2227   $main::lxdebug->enter_sub();
 
2229   my $form     = $main::form;
 
2230   my %myconfig = %main::myconfig;
 
2232   $main::auth->assert('config');
 
2234   $form->{title} = "Add";
 
2236   $form->{callback} = "am.pl?action=add_payment" unless $form->{callback};
 
2238   $form->{terms_netto} = 0;
 
2239   $form->{terms_skonto} = 0;
 
2240   $form->{percent_skonto} = 0;
 
2241   my @languages = AM->language(\%myconfig, $form, 1);
 
2242   map({ $_->{"language"} = $_->{"description"};
 
2243         $_->{"language_id"} = $_->{"id"}; } @languages);
 
2244   $form->{"TRANSLATION"} = \@languages;
 
2248   $main::lxdebug->leave_sub();
 
2252   $main::lxdebug->enter_sub();
 
2254   my $form     = $main::form;
 
2255   my %myconfig = %main::myconfig;
 
2257   $main::auth->assert('config');
 
2259   $form->{title} = "Edit";
 
2261   AM->get_payment(\%myconfig, $form);
 
2262   $form->{percent_skonto} =
 
2263     $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
 
2267   $form->{orphaned} = 1;
 
2270   $main::lxdebug->leave_sub();
 
2274   $main::lxdebug->enter_sub();
 
2276   my $form     = $main::form;
 
2277   my %myconfig = %main::myconfig;
 
2278   my $locale   = $main::locale;
 
2280   $main::auth->assert('config');
 
2282   AM->payment(\%myconfig, \%$form);
 
2284   $form->{callback} = build_std_url("action=list_payment");
 
2286   my $callback = $form->escape($form->{callback});
 
2288   $form->{title} = $locale->text('Payment Terms');
 
2290   my @column_index = qw(up down description description_long terms_netto
 
2291                      terms_skonto percent_skonto);
 
2293   $column_header{up} =
 
2294       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2295     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
 
2297   $column_header{down} =
 
2298       qq|<th class="listheading" align="center" valign="center" width="16">|
 
2299     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
 
2301   $column_header{description} =
 
2302       qq|<th class=listheading>|
 
2303     . $locale->text('Description')
 
2305   $column_header{description_long} =
 
2306       qq|<th class=listheading>|
 
2307     . $locale->text('Long Description')
 
2309   $column_header{terms_netto} =
 
2310       qq|<th class=listheading>|
 
2311     . $locale->text('Netto Terms')
 
2313   $column_header{terms_skonto} =
 
2314       qq|<th class=listheading>|
 
2315     . $locale->text('Skonto Terms')
 
2317   $column_header{percent_skonto} =
 
2318       qq|<th class=listheading>|
 
2319     . $locale->text('Skonto')
 
2329     <th class=listtop>$form->{title}</th>
 
2331   <tr height="5"></tr>
 
2335         <tr class=listheading>
 
2338   map { print "$column_header{$_}\n" } @column_index;
 
2344   my $swap_link = build_std_url("action=swap_payment_terms");
 
2347   my ($i, %column_data);
 
2348   foreach my $ref (@{ $form->{ALL} }) {
 
2354         <tr valign=top class=listrow$i>
 
2358       my $pref = $form->{ALL}->[$row - 1];
 
2360         qq|<td align="center" valign="center" width="16">| .
 
2361         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
 
2362         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
 
2365       $column_data{up} = qq|<td width="16"> </td>|;
 
2368     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
 
2369       $column_data{down} = qq|<td width="16"> </td>|;
 
2371       my $nref = $form->{ALL}->[$row + 1];
 
2372       $column_data{down} =
 
2373         qq|<td align="center" valign="center" width="16">| .
 
2374         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
 
2375         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
 
2379     $column_data{description} =
 
2381       build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
 
2382       qq|">| . H($ref->{description}) . qq|</a></td>|;
 
2383     $column_data{description_long} =
 
2384       qq|<td>| . H($ref->{description_long}) . qq|</td>|;
 
2385     $column_data{terms_netto} =
 
2386       qq|<td align=right>$ref->{terms_netto}</td>|;
 
2387     $column_data{terms_skonto} =
 
2388       qq|<td align=right>$ref->{terms_skonto}</td>|;
 
2389     $column_data{percent_skonto} =
 
2390       qq|<td align=right>| .
 
2391       $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
 
2393     map { print "$column_data{$_}\n" } @column_index;
 
2406   <td><hr size=3 noshade></td>
 
2411 <form method=post action=am.pl>
 
2413 <input name=callback type=hidden value="$form->{callback}">
 
2415 <input type=hidden name=type value=payment>
 
2417 <input class=submit type=submit name=action value="|
 
2418     . $locale->text('Add') . qq|">
 
2426   $main::lxdebug->leave_sub();
 
2429 sub payment_header {
 
2430   $main::lxdebug->enter_sub();
 
2432   my $form     = $main::form;
 
2433   my $locale   = $main::locale;
 
2435   $main::auth->assert('config');
 
2437   $form->{title}    = $locale->text("$form->{title} Payment Terms");
 
2439   # $locale->text('Add Payment Terms')
 
2440   # $locale->text('Edit Payment Terms')
 
2442   $form->{description} =~ s/\"/"/g;
 
2451 <form method=post action=am.pl>
 
2453 <input type=hidden name=id value=$form->{id}>
 
2454 <input type=hidden name=type value=payment>
 
2458     <th class=listtop colspan=2>$form->{title}</th>
 
2460   <tr height="5"></tr>
 
2462     <th align=right>| . $locale->text('Description') . qq|</th>
 
2463     <td><input name=description size=30 value="$form->{description}"></td>
 
2466     <th align=right>| . $locale->text('Long Description') . qq|</th>
 
2467     <td><input name=description_long size=50 value="$form->{description_long}"></td>
 
2471   foreach my $language (@{ $form->{"TRANSLATION"} }) {
 
2474     <th align="right">| .
 
2475     sprintf($locale->text('Translation (%s)'),
 
2476             $language->{"language"})
 
2478     <td><input name="description_long_$language->{language_id}" size="50"
 
2479          value="| . Q($language->{"description_long"}) . qq|"></td>
 
2486     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
 
2487     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
 
2490     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
 
2491     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
 
2494     <th align=right>| . $locale->text('Skonto') . qq| %</th>
 
2495     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
 
2497   <td colspan=2><hr size=3 noshade></td>
 
2501 <p>| . $locale->text("You can use the following strings in the long " .
 
2502                      "description and all translations. They will be " .
 
2503                      "replaced by their actual values by Lx-Office " .
 
2504                      "before they're output.")
 
2508   <li>| . $locale->text("<%netto_date%> -- Date the payment is due in " .
 
2511   <li>| . $locale->text("<%skonto_date%> -- Date the payment is due " .
 
2514   <li>| . $locale->text("<%skonto_amount%> -- The deductible amount")
 
2516   <li>| . $locale->text("<%total%> -- Amount payable")
 
2518   <li>| . $locale->text("<%total_wo_skonto%> -- Amount payable less discount")
 
2520   <li>| . $locale->text("<%invtotal%> -- Invoice total")
 
2522   <li>| . $locale->text("<%invtotal_wo_skonto%> -- Invoice total less discount")
 
2524   <li>| . $locale->text("<%currency%> -- The selected currency")
 
2526   <li>| . $locale->text("<%terms_netto%> -- The number of days for " .
 
2529   <li>| . $locale->text("<%account_number%> -- Your account number")
 
2531   <li>| . $locale->text("<%bank%> -- Your bank")
 
2533   <li>| . $locale->text("<%bank_code%> -- Your bank code")
 
2537   $main::lxdebug->leave_sub();
 
2541   $main::lxdebug->enter_sub();
 
2543   my $form     = $main::form;
 
2544   my %myconfig = %main::myconfig;
 
2545   my $locale   = $main::locale;
 
2547   $main::auth->assert('config');
 
2549   $form->isblank("description", $locale->text('Description missing!'));
 
2550   $form->{"percent_skonto"} =
 
2551     $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
 
2552   AM->save_payment(\%myconfig, \%$form);
 
2553   $form->redirect($locale->text('Payment Terms saved!'));
 
2555   $main::lxdebug->leave_sub();
 
2558 sub delete_payment {
 
2559   $main::lxdebug->enter_sub();
 
2561   my $form     = $main::form;
 
2562   my %myconfig = %main::myconfig;
 
2563   my $locale   = $main::locale;
 
2565   $main::auth->assert('config');
 
2567   AM->delete_payment(\%myconfig, \%$form);
 
2568   $form->redirect($locale->text('Payment terms deleted!'));
 
2570   $main::lxdebug->leave_sub();
 
2573 sub swap_payment_terms {
 
2574   $main::lxdebug->enter_sub();
 
2576   my $form     = $main::form;
 
2577   my %myconfig = %main::myconfig;
 
2579   $main::auth->assert('config');
 
2581   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
 
2584   $main::lxdebug->leave_sub();
 
2588   $main::lxdebug->enter_sub();
 
2590   my $form     = $main::form;
 
2591   my %myconfig = %main::myconfig;
 
2592   my $locale   = $main::locale;
 
2594   # get defaults for account numbers and last numbers
 
2595   AM->defaultaccounts(\%myconfig, \%$form);
 
2596   $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
 
2598   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
 
2600   foreach my $key (keys %{ $form->{IC} }) {
 
2601     foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
 
2602       my $array = "ACCNOS_" . uc($key);
 
2603       $form->{$array} ||= [];
 
2605       my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
 
2606       push @{ $form->{$array} }, {
 
2609         'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
 
2614   $form->{title} = $locale->text('Ranges of numbers and default accounts');
 
2617   print $form->parse_html_template('am/edit_defaults');
 
2619   $main::lxdebug->leave_sub();
 
2623   $main::lxdebug->enter_sub();
 
2625   my $form     = $main::form;
 
2626   my $locale   = $main::locale;
 
2628   AM->save_defaults();
 
2630   $form->redirect($locale->text('Defaults saved.'));
 
2632   $main::lxdebug->leave_sub();
 
2635 sub _build_cfg_options {
 
2636   my $form     = $main::form;
 
2637   my %myconfig = %main::myconfig;
 
2640   my $array = uc($idx) . 'S';
 
2642   $form->{$array} = [];
 
2643   foreach my $item (@_) {
 
2644     push @{ $form->{$array} }, {
 
2647       'selected' => $item eq $myconfig{$idx},
 
2653   $main::lxdebug->enter_sub();
 
2655   my $form     = $main::form;
 
2656   my %myconfig = %main::myconfig;
 
2657   my $locale   = $main::locale;
 
2659   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
 
2660   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
2663   if ($main::opendocument_templates && $main::openofficeorg_writer_bin &&
 
2664       $main::xvfb_bin && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)) {
 
2665     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
 
2666                      "value" => "opendocument_pdf" });
 
2668   if ($main::latex_templates) {
 
2669     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
 
2671   push(@formats, { "name" => "HTML", "value" => "html" });
 
2672   if ($main::latex_templates) {
 
2673     push(@formats, { "name" => $locale->text("Postscript"),
 
2674                      "value" => "postscript" });
 
2676   if ($main::opendocument_templates) {
 
2677     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
 
2678                      "value" => "opendocument" });
 
2681   if (!$myconfig{"template_format"}) {
 
2682     $myconfig{"template_format"} = "pdf";
 
2684   $form->{TEMPLATE_FORMATS} = [];
 
2685   foreach my $item (@formats) {
 
2686     push @{ $form->{TEMPLATE_FORMATS} }, {
 
2687       'name'     => $item->{name},
 
2688       'value'    => $item->{value},
 
2689       'selected' => $item->{value} eq $myconfig{template_format},
 
2693   if (!$myconfig{"default_media"}) {
 
2694     $myconfig{"default_media"} = "screen";
 
2697   my %selected = ($myconfig{"default_media"} => "selected");
 
2699     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
 
2700     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
 
2701     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
 
2704   AM->printer(\%myconfig, $form);
 
2706   $form->{PRINTERS} = [];
 
2707   foreach my $printer (@{$form->{"ALL"}}) {
 
2708     push @{ $form->{PRINTERS} }, {
 
2709       'name'     => $printer->{printer_description},
 
2710       'value'    => $printer->{id},
 
2711       'selected' => $printer->{id} == $myconfig{default_printer_id},
 
2715   my %countrycodes = User->country_codes;
 
2717   $form->{COUNTRYCODES} = [];
 
2718   foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
 
2719     push @{ $form->{COUNTRYCODES} }, {
 
2720       'name'     => $countrycodes{$countrycode},
 
2721       'value'    => $countrycode,
 
2722       'selected' => $countrycode eq $myconfig{countrycode},
 
2726   $form->{STYLESHEETS} = [];
 
2727   foreach my $item (qw(lx-office-erp.css Win2000.css)) {
 
2728     push @{ $form->{STYLESHEETS} }, {
 
2731       'selected' => $item eq $myconfig{stylesheet},
 
2735   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
 
2736   $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
2737   $form->{todo_cfg}            = { TODO->get_user_config('login' => $form->{login}) };
 
2739   $form->{title}               = $locale->text('Edit Preferences for #1', $form->{login});
 
2742   print $form->parse_html_template('am/config');
 
2744   $main::lxdebug->leave_sub();
 
2747 sub save_preferences {
 
2748   $main::lxdebug->enter_sub();
 
2750   my $form     = $main::form;
 
2751   my %myconfig = %main::myconfig;
 
2752   my $locale   = $main::locale;
 
2754   $form->{stylesheet} = $form->{usestylesheet};
 
2756   TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
 
2758   $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, 0));
 
2759   $form->error($locale->text('Cannot save preferences!'));
 
2761   $main::lxdebug->leave_sub();
 
2765   $main::lxdebug->enter_sub();
 
2767   my $form     = $main::form;
 
2768   my %myconfig = %main::myconfig;
 
2769   my $locale   = $main::locale;
 
2771   $main::auth->assert('config');
 
2773   $form->{title} = $locale->text('Audit Control');
 
2775   AM->closedto(\%myconfig, \%$form);
 
2782 <form method=post action=am.pl>
 
2785   <tr><th class=listtop>$form->{title}</th></tr>
 
2786   <tr height="5"></tr>
 
2791           <th>| . $locale->text('Close Books up to') . qq|</th>
 
2792           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
 
2802 <input type=hidden name=nextsub value=doclose>
 
2804 <input type=submit class=submit name=action value="|
 
2805     . $locale->text('Continue') . qq|">
 
2813   $main::lxdebug->leave_sub();
 
2817   $main::lxdebug->enter_sub();
 
2819   my $form     = $main::form;
 
2820   my %myconfig = %main::myconfig;
 
2821   my $locale   = $main::locale;
 
2823   $main::auth->assert('config');
 
2825   AM->closebooks(\%myconfig, \%$form);
 
2827   if ($form->{closedto}) {
 
2829                     $locale->text('Books closed up to') . " "
 
2830                       . $locale->date(\%myconfig, $form->{closedto}, 1));
 
2832     $form->redirect($locale->text('Books are open'));
 
2835   $main::lxdebug->leave_sub();
 
2839   $main::lxdebug->enter_sub();
 
2841   my $form     = $main::form;
 
2842   my %myconfig = %main::myconfig;
 
2843   my $locale   = $main::locale;
 
2845   $main::auth->assert('config');
 
2847   my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
2848   AM->units_in_use(\%myconfig, $form, $units);
 
2849   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
2851   my @languages = AM->language(\%myconfig, $form, 1);
 
2853   my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
2856   foreach (@unit_list) {
 
2857     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
 
2858     $_->{"UNITLANGUAGES"} = [];
 
2859     foreach my $lang (@languages) {
 
2860       push(@{ $_->{"UNITLANGUAGES"} },
 
2862              "unit" => $_->{"name"},
 
2863              "language_id" => $lang->{"id"},
 
2864              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
 
2865              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
 
2871   $units = AM->retrieve_units(\%myconfig, $form);
 
2872   my $ddbox = AM->unit_select_data($units, undef, 1);
 
2874   my $updownlink = build_std_url("action=swap_units");
 
2876   $form->{"title"} = $locale->text("Add and edit units");
 
2878   print($form->parse_html_template("am/edit_units",
 
2879                                    { "UNITS"               => \@unit_list,
 
2880                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
 
2881                                      "LANGUAGES"           => \@languages,
 
2882                                      "updownlink"          => $updownlink }));
 
2884   $main::lxdebug->leave_sub();
 
2888   $main::lxdebug->enter_sub();
 
2890   my $form     = $main::form;
 
2891   my %myconfig = %main::myconfig;
 
2892   my $locale   = $main::locale;
 
2894   $main::auth->assert('config');
 
2896   $form->isblank("new_name", $locale->text("The name is missing."));
 
2897   my $units = AM->retrieve_units(\%myconfig, $form);
 
2898   my $all_units = AM->retrieve_units(\%myconfig, $form);
 
2899   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
2901   my ($base_unit, $factor);
 
2902   if ($form->{"new_base_unit"}) {
 
2903     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
 
2905     $form->isblank("new_factor", $locale->text("The factor is missing."));
 
2906     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
 
2907     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
 
2908     $base_unit = $form->{"new_base_unit"};
 
2912   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
 
2913     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
 
2914     push(@languages, { "id" => $lang->{"id"},
 
2915                        "localized" => $form->{"new_localized_$lang->{id}"},
 
2916                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
 
2920   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
 
2922   $form->{"saved_message"} = $locale->text("The unit has been saved.");
 
2926   $main::lxdebug->leave_sub();
 
2929 sub set_unit_languages {
 
2930   $main::lxdebug->enter_sub();
 
2932   my $form     = $main::form;
 
2934   $main::auth->assert('config');
 
2936   my ($unit, $languages, $idx) = @_;
 
2938   $unit->{"LANGUAGES"} = [];
 
2940   foreach my $lang (@{$languages}) {
 
2941     push(@{ $unit->{"LANGUAGES"} },
 
2942          { "id" => $lang->{"id"},
 
2943            "localized" => $form->{"localized_${idx}_$lang->{id}"},
 
2944            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
 
2948   $main::lxdebug->leave_sub();
 
2952   $main::lxdebug->enter_sub();
 
2954   my $form     = $main::form;
 
2955   my %myconfig = %main::myconfig;
 
2956   my $locale   = $main::locale;
 
2958   $main::auth->assert('config');
 
2960   my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
 
2961   AM->units_in_use(\%myconfig, $form, $old_units);
 
2963   my @languages = AM->language(\%myconfig, $form, 1);
 
2966   my @delete_units = ();
 
2967   foreach my $i (1..($form->{"rowcount"} * 1)) {
 
2968     my $old_unit = $old_units->{$form->{"old_name_$i"}};
 
2970       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
 
2973     if ($form->{"unchangeable_$i"}) {
 
2974       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
 
2975       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
 
2976       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2980     if ($old_unit->{"in_use"}) {
 
2981       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
 
2984     if ($form->{"delete_$i"}) {
 
2985       push(@delete_units, $old_unit->{"name"});
 
2989     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
 
2991     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
 
2992     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
 
2993     $new_units->{$form->{"name_$i"}} = \%h;
 
2994     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
 
2995     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
 
2998   foreach my $unit (values(%{$new_units})) {
 
2999     next unless ($unit->{"old_name"});
 
3000     if ($unit->{"base_unit"}) {
 
3001       $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"}))
 
3002         unless (defined($new_units->{$unit->{"base_unit"}}));
 
3003       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
 
3004       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
 
3006       $unit->{"base_unit"} = undef;
 
3007       $unit->{"factor"} = undef;
 
3011   foreach my $unit (values(%{$new_units})) {
 
3012     next if ($unit->{"unchanged_unit"});
 
3014     map({ $_->{"seen"} = 0; } values(%{$new_units}));
 
3015     my $new_unit = $unit;
 
3016     while ($new_unit->{"base_unit"}) {
 
3017       $new_unit->{"seen"} = 1;
 
3018       $new_unit = $new_units->{$new_unit->{"base_unit"}};
 
3019       if ($new_unit->{"seen"}) {
 
3020         $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, " .
 
3021                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
 
3026   AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
 
3028   $form->{"saved_message"} = $locale->text("The units have been saved.");
 
3032   $main::lxdebug->leave_sub();
 
3035 sub show_history_search {
 
3036   $main::lxdebug->enter_sub();
 
3038   my $form     = $main::form;
 
3039   my $locale   = $main::locale;
 
3041   $main::auth->assert('config');
 
3043   $form->{title} = $locale->text("History Search");
 
3046   print $form->parse_html_template("common/search_history");
 
3048   $main::lxdebug->leave_sub();
 
3051 sub show_am_history {
 
3052   $main::lxdebug->enter_sub();
 
3054   my $form     = $main::form;
 
3055   my %myconfig = %main::myconfig;
 
3056   my $locale   = $main::locale;
 
3058   $main::auth->assert('config');
 
3060   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
 
3061   $form->{order} ||= 'h.itime--1';
 
3063   my %search = ( "Artikelnummer"          => "parts",
 
3064                  "Kundennummer"           => "customer",
 
3065                  "Lieferantennummer"      => "vendor",
 
3066                  "Projektnummer"          => "project",
 
3067                  "Buchungsnummer"         => "oe",
 
3068                  "Eingangsrechnungnummer" => "ap",
 
3069                  "Ausgangsrechnungnummer" => "ar",
 
3070                  "Mahnungsnummer"         => "dunning"
 
3072   my %searchNo = ( "Artikelnummer"          => "partnumber",
 
3073                    "Kundennummer"           => "customernumber",
 
3074                    "Lieferantennummer"      => "vendornumber",
 
3075                    "Projektnummer"          => "projectnummer",
 
3076                    "Buchungsnummer"         => "ordnumber",
 
3077                    "Eingangsrechnungnummer" => "invnumber",
 
3078                    "Ausgangsrechnungnummer" => "invnumber",
 
3079                    "Mahnungsnummer"         => "dunning_id"
 
3082   my $dbh = $form->dbconnect(\%myconfig);
 
3084   my $restriction  = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
 
3085   $restriction    .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate})                                                          if $form->{fromdate};
 
3086   $restriction    .= qq| AND h.itime::date <= | . conv_dateq($form->{todate})                                                            if $form->{todate};
 
3087   if ($form->{mitarbeiter} =~ m/^\d+$/) {
 
3088     $restriction  .= qq| AND employee_id = |    . $form->{mitarbeiter};
 
3089   } elsif ($form->{mitarbeiter}) {
 
3090     $restriction  .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
 
3093   my $query = qq|SELECT trans_id AS id FROM history_erp | .
 
3094     (  $form->{'searchid'} ? qq| WHERE snumbers = '|  . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
 
3095      :                       qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
3097   my @ids    = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
 
3098   my $daten .= shift @ids;
 
3099   $daten    .= join '', map { " OR trans_id = $_" } @ids;
 
3101   my ($sort, $sortby) = split(/\-\-/, $form->{order});
 
3102   $sort =~ s/.*\.(.*)$/$1/;
 
3104   $form->{title} = $locale->text("History Search");
 
3107   print $form->parse_html_template("common/show_history",
 
3108                                    { "DATEN"          => $form->get_history($dbh, $daten, $restriction, $form->{order}),
 
3109                                      "SUCCESS"        => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
 
3112                                      uc($sort) . "BY" => $sortby,
 
3113                                      'callback'       => $callback,
 
3117   $main::lxdebug->leave_sub();
 
3121   $main::lxdebug->enter_sub();
 
3123   my $form     = $main::form;
 
3124   my %myconfig = %main::myconfig;
 
3126   $main::auth->assert('config');
 
3128   my $dir = $form->{"dir"} eq "down" ? "down" : "up";
 
3129   AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
 
3133   $main::lxdebug->leave_sub();
 
3137   $main::lxdebug->enter_sub();
 
3139   my $form     = $main::form;
 
3140   my $locale   = $main::locale;
 
3142   $main::auth->assert('config');
 
3144   $form->{title} =  $locale->text('Add');
 
3146   $form->{callback} ||= "am.pl?action=add_tax";
 
3148   _get_taxaccount_selection();
 
3152   my $parameters_ref = {
 
3153 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
 
3156   # Ausgabe des Templates
 
3157   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
3159   $main::lxdebug->leave_sub();
 
3163   $main::lxdebug->enter_sub();
 
3165   my $form     = $main::form;
 
3166   my %myconfig = %main::myconfig;
 
3167   my $locale   = $main::locale;
 
3169   $main::auth->assert('config');
 
3171   $form->{title} =  $locale->text('Edit');
 
3173   AM->get_tax(\%myconfig, \%$form);
 
3174   _get_taxaccount_selection();
 
3176   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
 
3180   my $parameters_ref = {
 
3183   # Ausgabe des Templates
 
3184   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
3186   $main::lxdebug->leave_sub();
 
3190   $main::lxdebug->enter_sub();
 
3192   my $form     = $main::form;
 
3193   my %myconfig = %main::myconfig;
 
3194   my $locale   = $main::locale;
 
3196   $main::auth->assert('config');
 
3198   AM->taxes(\%myconfig, \%$form);
 
3200   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
 
3202   $form->{callback} = build_std_url('action=list_tax');
 
3204   $form->{title} = $locale->text('Tax-O-Matic');
 
3208   my $parameters_ref = {
 
3211   # Ausgabe des Templates
 
3212   print($form->parse_html_template('am/list_tax', $parameters_ref));
 
3214   $main::lxdebug->leave_sub();
 
3217 sub _get_taxaccount_selection{
 
3218   $main::lxdebug->enter_sub();
 
3220   my $form     = $main::form;
 
3221   my %myconfig = %main::myconfig;
 
3223   $main::auth->assert('config');
 
3225   AM->get_tax_accounts(\%myconfig, \%$form);
 
3227   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
3229   $main::lxdebug->leave_sub();
 
3233   $main::lxdebug->enter_sub();
 
3235   my $form     = $main::form;
 
3236   my %myconfig = %main::myconfig;
 
3237   my $locale   = $main::locale;
 
3239   $main::auth->assert('config');
 
3241   $form->isblank("rate", $locale->text('Taxrate missing!'));
 
3242   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
 
3243   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
 
3245   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
 
3247   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
 
3248     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
3251   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
 
3252     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
 
3255   AM->save_tax(\%myconfig, \%$form);
 
3256   $form->redirect($locale->text('Tax saved!'));
 
3258   $main::lxdebug->leave_sub();
 
3262   $main::lxdebug->enter_sub();
 
3264   my $form     = $main::form;
 
3265   my %myconfig = %main::myconfig;
 
3266   my $locale   = $main::locale;
 
3268   $main::auth->assert('config');
 
3270   AM->delete_tax(\%myconfig, \%$form);
 
3271   $form->redirect($locale->text('Tax deleted!'));
 
3273   $main::lxdebug->leave_sub();
 
3276 sub add_price_factor {
 
3277   $main::lxdebug->enter_sub();
 
3279   my $form     = $main::form;
 
3280   my $locale   = $main::locale;
 
3282   $main::auth->assert('config');
 
3284   $form->{title}      = $locale->text('Add Price Factor');
 
3285   $form->{callback} ||= build_std_url('action=add_price_factor');
 
3286   $form->{fokus}      = 'description';
 
3289   print $form->parse_html_template('am/edit_price_factor');
 
3291   $main::lxdebug->leave_sub();
 
3294 sub edit_price_factor {
 
3295   $main::lxdebug->enter_sub();
 
3297   my $form     = $main::form;
 
3298   my %myconfig = %main::myconfig;
 
3299   my $locale   = $main::locale;
 
3301   $main::auth->assert('config');
 
3303   $form->{title}      = $locale->text('Edit Price Factor');
 
3304   $form->{callback} ||= build_std_url('action=add_price_factor');
 
3305   $form->{fokus}      = 'description';
 
3307   AM->get_price_factor(\%myconfig, $form);
 
3309   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
 
3312   print $form->parse_html_template('am/edit_price_factor');
 
3314   $main::lxdebug->leave_sub();
 
3317 sub list_price_factors {
 
3318   $main::lxdebug->enter_sub();
 
3320   my $form     = $main::form;
 
3321   my %myconfig = %main::myconfig;
 
3322   my $locale   = $main::locale;
 
3324   $main::auth->assert('config');
 
3326   AM->get_all_price_factors(\%myconfig, \%$form);
 
3329   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
 
3331       $previous->{next_id}    = $current->{id};
 
3332       $current->{previous_id} = $previous->{id};
 
3335     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
 
3337     $previous = $current;
 
3340   $form->{callback} = build_std_url('action=list_price_factors');
 
3341   $form->{title}    = $locale->text('Price Factors');
 
3342   $form->{url_base} = build_std_url('callback');
 
3345   print $form->parse_html_template('am/list_price_factors');
 
3347   $main::lxdebug->leave_sub();
 
3350 sub save_price_factor {
 
3351   $main::lxdebug->enter_sub();
 
3353   my $form     = $main::form;
 
3354   my %myconfig = %main::myconfig;
 
3355   my $locale   = $main::locale;
 
3357   $main::auth->assert('config');
 
3359   $form->isblank("description", $locale->text('Description missing!'));
 
3360   $form->isblank("factor", $locale->text('Factor missing!'));
 
3362   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
 
3364   AM->save_price_factor(\%myconfig, $form);
 
3366   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
 
3368   $form->redirect($locale->text('Price factor saved!'));
 
3370   $main::lxdebug->leave_sub();
 
3373 sub delete_price_factor {
 
3374   $main::lxdebug->enter_sub();
 
3376   my $form     = $main::form;
 
3377   my %myconfig = %main::myconfig;
 
3378   my $locale   = $main::locale;
 
3380   $main::auth->assert('config');
 
3382   AM->delete_price_factor(\%myconfig, \%$form);
 
3384   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
 
3386   $form->redirect($locale->text('Price factor deleted!'));
 
3388   $main::lxdebug->leave_sub();
 
3391 sub swap_price_factors {
 
3392   $main::lxdebug->enter_sub();
 
3394   my $form     = $main::form;
 
3395   my %myconfig = %main::myconfig;
 
3397   $main::auth->assert('config');
 
3399   AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
 
3400   list_price_factors();
 
3402   $main::lxdebug->leave_sub();
 
3406   $main::lxdebug->enter_sub();
 
3408   my $form     = $main::form;
 
3409   my $locale   = $main::locale;
 
3411   $main::auth->assert('config');
 
3413   $form->{title}      = $locale->text('Add Warehouse');
 
3414   $form->{callback} ||= build_std_url('action=add_warehouse');
 
3415   $form->{fokus}      = 'description';
 
3418   print $form->parse_html_template('am/edit_warehouse');
 
3420   $main::lxdebug->leave_sub();
 
3423 sub edit_warehouse {
 
3424   $main::lxdebug->enter_sub();
 
3426   my $form     = $main::form;
 
3427   my %myconfig = %main::myconfig;
 
3428   my $locale   = $main::locale;
 
3430   $main::auth->assert('config');
 
3432   AM->get_warehouse(\%myconfig, $form);
 
3434   $form->get_lists('employees' => 'EMPLOYEES');
 
3436   $form->{title}      = $locale->text('Edit Warehouse');
 
3437   $form->{callback} ||= build_std_url('action=list_warehouses');
 
3438   $form->{fokus}      = 'description';
 
3441   print $form->parse_html_template('am/edit_warehouse');
 
3443   $main::lxdebug->leave_sub();
 
3446 sub list_warehouses {
 
3447   $main::lxdebug->enter_sub();
 
3449   my $form     = $main::form;
 
3450   my %myconfig = %main::myconfig;
 
3451   my $locale   = $main::locale;
 
3453   $main::auth->assert('config');
 
3455   AM->get_all_warehouses(\%myconfig, $form);
 
3458   foreach my $current (@{ $form->{WAREHOUSES} }) {
 
3460       $previous->{next_id}    = $current->{id};
 
3461       $current->{previous_id} = $previous->{id};
 
3464     $previous = $current;
 
3467   $form->{callback} = build_std_url('action=list_warehouses');
 
3468   $form->{title}    = $locale->text('Warehouses');
 
3469   $form->{url_base} = build_std_url('callback');
 
3472   print $form->parse_html_template('am/list_warehouses');
 
3474   $main::lxdebug->leave_sub();
 
3477 sub save_warehouse {
 
3478   $main::lxdebug->enter_sub();
 
3480   my $form     = $main::form;
 
3481   my %myconfig = %main::myconfig;
 
3482   my $locale   = $main::locale;
 
3484   $main::auth->assert('config');
 
3486   $form->isblank("description", $locale->text('Description missing!'));
 
3488   $form->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
 
3490   AM->save_warehouse(\%myconfig, $form);
 
3492   $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
 
3494   $form->redirect($locale->text('Warehouse saved.'));
 
3496   $main::lxdebug->leave_sub();
 
3499 sub swap_warehouses {
 
3500   $main::lxdebug->enter_sub();
 
3502   my $form     = $main::form;
 
3503   my %myconfig = %main::myconfig;
 
3505   $main::auth->assert('config');
 
3507   AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
 
3510   $main::lxdebug->leave_sub();
 
3513 sub delete_warehouse {
 
3514   $main::lxdebug->enter_sub();
 
3516   my $form     = $main::form;
 
3517   my %myconfig = %main::myconfig;
 
3518   my $locale   = $main::locale;
 
3520   $main::auth->assert('config');
 
3522   if (!$form->{confirmed}) {
 
3523     $form->{title} = $locale->text('Confirmation');
 
3526     print $form->parse_html_template('am/confirm_delete_warehouse');
 
3530   if (AM->delete_warehouse(\%myconfig, $form)) {
 
3531     $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
 
3532     $form->redirect($locale->text('Warehouse deleted.'));
 
3535     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
 
3538   $main::lxdebug->leave_sub();
 
3542   $main::lxdebug->enter_sub();
 
3544   my $form     = $main::form;
 
3545   my %myconfig = %main::myconfig;
 
3546   my $locale   = $main::locale;
 
3548   $main::auth->assert('config');
 
3550   AM->save_bins(\%myconfig, $form);
 
3552   $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
 
3554   $form->redirect($locale->text('Bins saved.'));
 
3556   $main::lxdebug->leave_sub();